@@ -819,57 +819,56 @@ def opm_registry_add_fbc_fragment(
819819 """
820820 set_request_state (request_id , 'in_progress' , 'Extracting operator package from fbc_fragment' )
821821 # fragment path will look like /tmp/iib-**/fbc-fragment
822- fragment_path , fragment_operator = extract_fbc_fragment (
822+ fragment_path , fragment_operators = extract_fbc_fragment (
823823 temp_dir = temp_dir , fbc_fragment = fbc_fragment
824824 )
825825
826- is_operator_in_db , index_db_path = verify_operator_exists (
826+ # the dir where all the configs from from_index are stored
827+ # this will look like /tmp/iib-**/configs
828+ from_index_configs_dir = get_catalog_dir (from_index = from_index , base_dir = temp_dir )
829+ log .info ("The content of from_index configs located at %s" , from_index_configs_dir )
830+
831+ operators_in_db , index_db_path = verify_operators_exists (
827832 from_index = from_index ,
828833 base_dir = temp_dir ,
829- operator_package = fragment_operator ,
834+ operator_packages = fragment_operators ,
830835 overwrite_from_index_token = overwrite_from_index_token ,
831836 )
832837
833- # the dir where all the configs from from_index is stored
834- # this will look like /tmp/iib-**/configs
835- from_index_configs_dir = get_catalog_dir (from_index = from_index , base_dir = temp_dir )
836-
837- log .info ("The content of from_index configs located at %s" , from_index_configs_dir )
838+ if operators_in_db :
839+ log .info ('Removing %s from %s index.db ' , operators_in_db , from_index )
840+ _opm_registry_rm (index_db_path = index_db_path , operators = operators_in_db , base_dir = temp_dir )
838841
839- if is_operator_in_db :
840- log .info ('Removing %s from %s index.db ' , fragment_operator , from_index )
841- _opm_registry_rm (
842- index_db_path = index_db_path , operators = [fragment_operator ], base_dir = temp_dir
843- )
844- # migated_catalog_dir path will look like /tmp/iib-**/catalog
845- migated_catalog_dir , _ = opm_migrate (
842+ # migrated_catalog_dir path will look like /tmp/iib-**/catalog
843+ migrated_catalog_dir , _ = opm_migrate (
846844 index_db = index_db_path ,
847845 base_dir = temp_dir ,
848846 generate_cache = False ,
849847 )
850- log .info ("Migated catalog after removing from db at %s" , migated_catalog_dir )
848+ log .info ("Migrated catalog after removing from db at %s" , migrated_catalog_dir )
851849
852850 # copy the content of migrated_catalog to from_index's config
853- log .info ("Copying content of %s to %s" , migated_catalog_dir , from_index_configs_dir )
854- for operator_package in os .listdir (migated_catalog_dir ):
851+ log .info ("Copying content of %s to %s" , migrated_catalog_dir , from_index_configs_dir )
852+ for operator_package in os .listdir (migrated_catalog_dir ):
855853 shutil .copytree (
856- os .path .join (migated_catalog_dir , operator_package ),
854+ os .path .join (migrated_catalog_dir , operator_package ),
857855 os .path .join (from_index_configs_dir , operator_package ),
858856 dirs_exist_ok = True ,
859857 )
860858
861- # copy fragment_operator to from_index configs
862- set_request_state (request_id , 'in_progress' , 'Adding fbc_fragment to from_index' )
863- fragment_opr_src_path = os .path .join (fragment_path , fragment_operator )
864- fragment_opr_dest_path = os .path .join (from_index_configs_dir , fragment_operator )
865- if os .path .exists (fragment_opr_dest_path ):
866- shutil .rmtree (fragment_opr_dest_path )
867- log .info (
868- "Copying content of %s to %s" ,
869- fragment_opr_src_path ,
870- fragment_opr_dest_path ,
871- )
872- shutil .copytree (fragment_opr_src_path , fragment_opr_dest_path )
859+ for fragment_operator in fragment_operators :
860+ # copy fragment_operator to from_index configs
861+ set_request_state (request_id , 'in_progress' , 'Adding fbc_fragment to from_index' )
862+ fragment_opr_src_path = os .path .join (fragment_path , fragment_operator )
863+ fragment_opr_dest_path = os .path .join (from_index_configs_dir , fragment_operator )
864+ if os .path .exists (fragment_opr_dest_path ):
865+ shutil .rmtree (fragment_opr_dest_path )
866+ log .info (
867+ "Copying content of %s to %s" ,
868+ fragment_opr_src_path ,
869+ fragment_opr_dest_path ,
870+ )
871+ shutil .copytree (fragment_opr_src_path , fragment_opr_dest_path )
873872
874873 local_cache_path = os .path .join (temp_dir , 'cache' )
875874 generate_cache_locally (
@@ -886,32 +885,32 @@ def opm_registry_add_fbc_fragment(
886885 )
887886
888887
889- def verify_operator_exists (
888+ def verify_operators_exists (
890889 from_index : str ,
891890 base_dir : str ,
892- operator_package : str ,
891+ operator_packages : List [ str ] ,
893892 overwrite_from_index_token : Optional [str ],
894893):
895894 """
896- Check if operator exists in index image.
895+ Check if operators exists in index image.
897896
898897 :param str from_index: index in which operator existence is checked
899898 :param str base_dir: base temp directory for IIB request
900- :param str operator_package : operator_package to check
899+ :param list( str) operator_packages : operator_package to check
901900 :param str overwrite_from_index_token: token used to access the image
902- :return: is_package_in_index , index_db_path
903- :rtype: (str , str)
901+ :return: packages_in_index , index_db_path
902+ :rtype: (list , str)
904903 """
905904 from iib .workers .tasks .build import terminate_process , get_bundle_json
906905 from iib .workers .tasks .iib_static_types import BundleImage
907906 from iib .workers .tasks .utils import run_cmd
908907 from iib .workers .tasks .utils import set_registry_token
909908
910- is_package_in_index = False
909+ packages_in_index : List [ str ] = []
911910
912- log .info ("Verifying if operator package %s exists in index %s" , operator_package , from_index )
911+ log .info ("Verifying if operator packages %s exists in index %s" , operator_packages , from_index )
913912
914- # check if operater package exists in hidden index.db
913+ # check if operator packages exists in hidden index.db
915914 with set_registry_token (overwrite_from_index_token , from_index , append = True ):
916915 index_db_path = get_hidden_index_database (from_index = from_index , base_dir = base_dir )
917916
@@ -924,10 +923,13 @@ def verify_operator_exists(
924923 present_bundles : List [BundleImage ] = get_bundle_json (bundles )
925924
926925 for bundle in present_bundles :
927- if bundle ['packageName' ] == operator_package :
928- is_package_in_index = True
929- log .info ("operator package %s found in index_db %s" , operator_package , index_db_path )
930- return is_package_in_index , index_db_path
926+ if bundle ['packageName' ] in operator_packages :
927+ packages_in_index .append (bundle ['packageName' ])
928+
929+ if packages_in_index :
930+ log .info ("operator packages found in index_db %s: %s" , index_db_path , packages_in_index )
931+
932+ return packages_in_index , index_db_path
931933
932934
933935@retry (
0 commit comments