diff --git a/suse_migration_services/units/prepare.py b/suse_migration_services/units/prepare.py index fc4e4f6..7b46fa3 100644 --- a/suse_migration_services/units/prepare.py +++ b/suse_migration_services/units/prepare.py @@ -67,9 +67,7 @@ def main(): '/etc/pki/trust/anchors/' ] cache_cloudregister_path = '/var/cache/cloudregister' - cloud_register_certs_path = '/var/lib/regionService/certs' - cloud_register_certs_bind_mount_path = \ - root_path + cloud_register_certs_path + cloud_register_certs_path_fallback = '/var/lib/regionService/certs' cloud_register_metadata = "" @@ -85,6 +83,10 @@ def main(): update_regionsrv_setup( root_path, migration_suse_cloud_regionsrv_setup ) + cloud_register_certs_path = get_regionsrv_certs_path( + root_path, migration_suse_cloud_regionsrv_setup, + cloud_register_certs_path_fallback + ) if os.path.exists(hosts_setup): shutil.copy( hosts_setup, '/etc/hosts' @@ -196,6 +198,8 @@ def main(): cache_cloudregister_path ] ) + cloud_register_certs_bind_mount_path = \ + root_path + cloud_register_certs_path if os.path.exists(cloud_register_certs_bind_mount_path): log.info( 'Bind mounting {0} from {1}'.format( @@ -243,6 +247,19 @@ def main(): ) +def get_regionsrv_certs_path(root_path, regionsrv_client_config, fallback): + """ + Note: This method is specific to the SUSE Public Cloud Infrastructure + + Retrieve the certlocation specified in the to be migrated system's + regionsrv_client_config, defaulting to the client config if not found. + """ + regionsrv_config = ConfigParser() + regionsrv_config.read(root_path + regionsrv_client_config) + + return regionsrv_config.get('server', 'certlocation', fallback=fallback) + + def update_regionsrv_setup(root_path, suse_cloud_regionsrv_setup): """ Note: This method is specific to the SUSE Public Cloud Infrastructure diff --git a/test/unit/units/prepare_test.py b/test/unit/units/prepare_test.py index 41c7297..a26bd79 100644 --- a/test/unit/units/prepare_test.py +++ b/test/unit/units/prepare_test.py @@ -46,17 +46,22 @@ def test_main_raises_on_zypp_bind( with raises(DistMigrationZypperMetaDataException): main() + @patch('suse_migration_services.units.prepare.get_regionsrv_certs_path') @patch('suse_migration_services.units.prepare.get_regionsrv_client_file_location') @patch('shutil.copy') @patch('os.listdir') @patch('os.path.exists') def test_main_raises_on_get_regionsrv_client_file_location( self, mock_os_path_exists, mock_os_listdir, mock_shutil_copy, - mock_get_regionsrv_client_file_location, mock_Command_run, + mock_get_regionsrv_client_file_location, + mock_get_regionsrv_certs_path, + mock_Command_run, mock_Fstab, mock_logger_setup, mock_update_regionsrv_setup ): mock_os_listdir.return_value = None + mock_get_regionsrv_certs_path.return_value = \ + '/var/lib/regionService/certs' mock_get_regionsrv_client_file_location.side_effect = \ [DistMigrationZypperMetaDataException('foo')] mock_os_path_exists.return_value = True @@ -124,6 +129,7 @@ def test_main_raises_and_umount_file_system( call(['umount', '/system-root/dev'], raise_on_error=False) ] + @patch('suse_migration_services.units.prepare.get_regionsrv_certs_path') @patch('os.path.isfile') @patch.object(SUSEConnect, 'is_registered') @patch('suse_migration_services.units.prepare.MigrationConfig') @@ -138,7 +144,9 @@ def test_main( self, mock_os_path_exists, mock_readlink, mock_os_path_islink, mock_path_isdir, mock_os_listdir, mock_shutil_copy, mock_Path, mock_MigrationConfig, - mock_is_registered, mock_is_file, mock_Command_run, + mock_is_registered, mock_is_file, + mock_get_regionsrv_certs_path, + mock_Command_run, mock_Fstab, mock_logger_setup, mock_update_regionsrv_setup ): @@ -188,6 +196,8 @@ def test_main( FileNotFoundError('cert copy failed') ] mock_is_file.return_value = True + mock_get_regionsrv_certs_path.return_value = \ + '/var/lib/regionService/certs' with patch('builtins.open', mock_open(read_data='foo.susecloud.net')): main() assert mock_shutil_copy.call_args_list == [ @@ -289,6 +299,7 @@ def test_main( ['cat', '/proc/net/bonding/bond*'], raise_on_error=False ) + @patch('suse_migration_services.units.prepare.get_regionsrv_certs_path') @patch('suse_migration_services.units.prepare.get_regionsrv_client_file_location') @patch.object(SUSEConnect, 'is_registered') @patch('suse_migration_services.units.prepare.MigrationConfig') @@ -299,7 +310,8 @@ def test_main( def test_main_no_registered_instance( self, mock_os_path_exists, mock_os_listdir, mock_shutil_copy, mock_Path, mock_MigrationConfig, mock_is_registered, - mock_get_regionsrv_client_file_location, mock_Command_run, + mock_get_regionsrv_client_file_location, + mock_get_regionsrv_certs_path, mock_Command_run, mock_Fstab, mock_logger_setup, mock_update_regionsrv_setup ): migration_config = Mock() @@ -308,6 +320,8 @@ def test_main_no_registered_instance( mock_MigrationConfig.return_value = migration_config fstab = Mock() mock_Fstab.return_value = fstab + mock_get_regionsrv_certs_path.return_value = \ + '/var/lib/regionService/certs' mock_os_listdir.return_value = ['foo', 'bar'] mock_os_path_exists.return_value = True mock_is_registered.return_value = False