def test_import_host_collections_default(self, test_data): """@test: Import all System Groups from the default data set (predefined source) as the Host Collections. @feature: Import Host-Collections @assert: 3 Host Collections created """ files = dict(self.default_dataset[1]) for file_ in zip( ['users', 'system-groups'], [u'organization_id', u'org_id'], [u'orgs', u'hcs'] ): files[file_[0]] = update_csv_values( files[file_[0]], file_[1], test_data[file_[2]], self.default_dataset[0] ) # import the prerequisities import_org = Import.organization_with_tr_data( {'csv-file': files['users']} ) import_hc = Import.host_collection_with_tr_data( {'csv-file': files['system-groups']} ) for result in (import_org, import_hc): self.assertEqual(result[0].return_code, 0) # now to check whether the all HC from csv appeared in satellite imp_orgs = get_sat6_id(csv_to_dataset([files['users']]), import_org[1]) for imp_org in imp_orgs: self.assertNotEqual( HostCollection.list( {'organization-id': imp_org['sat6']} ).stdout, [] )
def test_import_host_collections_recovery(self, test_data): """@test: Try to Import Collections with the same name to invoke usage of a recovery strategy (rename, map, none) @feature: Import HostCollection Recover @assert: 2nd Import will rename the new collections, 3nd import will result in No Action Taken and the 4th one will map them """ # prepare the data files = dict(self.default_dataset[1]) for file_ in zip( ['users', 'system-groups'], [u'organization_id', u'org_id'], [u'orgs', u'hcs'] ): files[file_[0]] = update_csv_values( files[file_[0]], file_[1], test_data[file_[2]], self.default_dataset[0] ) # initial import import_org = Import.organization_with_tr_data( {'csv-file': files['users']} ) for result in ( import_org, Import.host_collection_with_tr_data( {'csv-file': files['system-groups']} ), ): self.assertEqual(result[0].return_code, 0) # clear the .transition_data to clear the transition mapping ssh.command('rm -rf "${HOME}"/.transition_data/host_collections*') # use the default (rename) strategy import_hc_rename = Import.host_collection_with_tr_data( {'csv-file': files['system-groups'], 'verbose': True} ) self.assertEqual(import_hc_rename[0].return_code, 0) for record in import_hc_rename[1]: self.assertEqual( HostCollection.info({'id': record['sat6']}).return_code, 0 ) Import.host_collection( {'csv-file': files['system-groups'], 'delete': True} ) # use the 'none' strategy hc_before = [ HostCollection.list({'organization-id': tr['sat6']}).stdout for tr in import_org[1] ] Import.host_collection( {'csv-file': files['system-groups'], 'recover': 'none'} ) hc_after = [ HostCollection.list({'organization-id': tr['sat6']}).stdout for tr in import_org[1] ] self.assertEqual(hc_before, hc_after) # use the 'map' strategy import_hc_map = Import.host_collection_with_tr_data({ 'csv-file': files['system-groups'], 'recover': 'map', 'verbose': True, }) self.assertEqual(import_hc_map[0].return_code, 0) for record in import_hc_map[1]: self.assertEqual( HostCollection.info({'id': record['sat6']}).return_code, 0 )