def test_positive_update_sync_plan(self): """Update product's sync plan @id: 78cbde49-b6c8-41ab-8991-fcb4b648e79b @Assert: Product sync plan is updated """ first_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) second_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) product = make_product({ u'organization-id': self.org['id'], u'sync-plan-id': first_sync_plan['id'], }) # Update the Descriptions Product.update({ u'id': product['id'], u'sync-plan-id': second_sync_plan['id'], }) # Fetch it product = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], second_sync_plan['id']) self.assertNotEqual(product['sync-plan-id'], first_sync_plan['id'])
def test_positive_update_3(self): """@Test: Update product's sync plan @Feature: Product @Assert: Product sync plan is updated """ first_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) second_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) product = make_product({ u'organization-id': self.org['id'], u'sync-plan-id': first_sync_plan['id'], }) # Update the Descriptions Product.update({ u'id': product['id'], u'sync-plan-id': second_sync_plan['id'], }) # Fetch it product = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], second_sync_plan['id']) self.assertNotEqual(product['sync-plan-id'], first_sync_plan['id'])
def test_positive_update_sync_plan(self): """Update product's sync plan :id: 78cbde49-b6c8-41ab-8991-fcb4b648e79b :expectedresults: Product sync plan is updated :CaseImportance: Critical """ first_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) second_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) product = make_product({ u'organization-id': self.org['id'], u'sync-plan-id': first_sync_plan['id'], }) # Update the Descriptions Product.update({ u'id': product['id'], u'sync-plan-id': second_sync_plan['id'], }) # Fetch it product = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], second_sync_plan['id']) self.assertNotEqual(product['sync-plan-id'], first_sync_plan['id'])
def test_positive_update_sync_plan(self): """Update product's sync plan @Feature: Product @Assert: Product sync plan is updated """ first_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) second_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) product = make_product({ u'organization-id': self.org['id'], u'sync-plan-id': first_sync_plan['id'], }) # Update the Descriptions Product.update({ u'id': product['id'], u'sync-plan-id': second_sync_plan['id'], }) # Fetch it product = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], second_sync_plan['id']) self.assertNotEqual(product['sync-plan-id'], first_sync_plan['id'])
def test_negative_create_with_name(module_org, name): """Check if syncplan can be created with random invalid names :id: 4c1aee35-271e-4ed8-9369-d2abfea8cfd9 :parametrized: yes :expectedresults: Sync plan is not created :CaseImportance: Critical """ with pytest.raises(CLIFactoryError, match='Could not create the sync plan:'): make_sync_plan({'name': name, 'organization-id': module_org.id})
def test_positive_create_5(self, test_name): """@Test: Check if product can be created with sync plan @Feature: Product @Assert: Product is created and has random sync plan """ new_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) new_product = make_product( { u'name': test_name['name'], u'organization-id': self.org['id'], u'sync-plan-id': new_sync_plan['id'], } ) # Fetch it result = Product.info( {u'id': new_product['id'], u'organization-id': self.org['id']}) self.assertEqual( result.return_code, 0, "Product was not found") self.assertEqual( len(result.stderr), 0, "No error was expected") self.assertEqual( result.stdout['name'], new_product['name'], "Names don't match") self.assertEqual( result.stdout['sync-plan-id'], new_sync_plan['id'], "Sync plans don't match")
def test_positive_create_5(self, test_name): """ @Test: Check if product can be created with sync plan @Feature: Product @Assert: Product is created and has random sync plan @BZ: 1096320 """ new_sync_plan = make_sync_plan({u'organization-id': self.org['id']}) new_product = make_product( { u'name': test_name['name'], u'organization-id': self.org['id'], u'sync-plan-id': new_sync_plan['id'], } ) # Fetch it result = Product.info( {u'id': new_product['id'], u'organization-id': self.org['id']}) self.assertEqual( result.return_code, 0, "Product was not found") self.assertEqual( len(result.stderr), 0, "No error was expected") self.assertEqual( result.stdout['name'], new_product['name'], "Names don't match") self.assertEqual( result.stdout['sync-plan-id'], new_sync_plan['id'], "Sync plans don't match")
def test_positive_synchronize_custom_products_future_sync_date(module_org): """Create a sync plan with sync date in a future and sync multiple custom products with multiple repos automatically. :id: dd262cf3-b836-422c-baca-b3adbc532478 :expectedresults: Products are synchronized successfully. :CaseLevel: System :BZ: 1655595 """ delay = 4 * 60 # delay for sync date in seconds products = [ make_product({'organization-id': module_org.id}) for _ in range(3) ] repos = [ make_repository({'product-id': product['id']}) for product in products for _ in range(2) ] sync_plan = make_sync_plan({ 'enabled': 'true', 'organization-id': module_org.id, 'sync-date': (datetime.utcnow().replace(second=0) + timedelta(seconds=delay)).strftime(SYNC_DATE_FMT), 'cron-expression': ["*/4 * * * *"], }) # Verify products have not been synced yet logger.info( f"Check products {products[0]['name']} and {products[1]['name']}" f" were not synced before sync plan created in org {module_org.label}") for repo in repos: with pytest.raises(AssertionError): validate_task_status(repo['id'], module_org.id, max_tries=1) # Associate sync plan with products for product in products: Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'] }) # Wait quarter of expected time logger.info( f"Waiting {(delay / 4)} seconds to check products {products[0]['name']}" f" and {products[1]['name']} were not synced by {sync_plan['name']} ") sleep(delay / 4) # Verify products have not been synced yet for repo in repos: with pytest.raises(AssertionError): validate_task_status(repo['id'], module_org.id, max_tries=1) # Wait the rest of expected time logger.info( f"Waiting {(delay * 3 / 4)} seconds to check product {products[0]['name']}" f" and {products[1]['name']} were synced by {sync_plan['name']}") sleep(delay * 3 / 4) # Verify products were synced successfully for repo in repos: validate_task_status(repo['id'], module_org.id) validate_repo_content(repo, ['errata', 'package-groups', 'packages'])
def test_positive_remove_sync_plan_by_id(self): """Check if a sync plan can be removed from a product :id: 0df2005c-158a-48cb-8a16-9a63923699fc :expectedresults: Product has sync plan :CaseLevel: Integration """ product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], sync_plan['id']) Product.remove_sync_plan({'id': product['id']}) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(len(product['sync-plan-id']), 0)
def test_negative_synchronize_custom_product_past_sync_date(module_org): """Verify product won't get synced immediately after adding association with a sync plan which has already been started :id: c80f5c0c-3863-47da-8d7b-7d65c73664b0 :expectedresults: Repository was not synchronized :BZ: 1279539 :CaseLevel: System """ sync_plan = make_sync_plan({ 'enabled': 'true', 'organization-id': module_org.id, 'sync-date': datetime.utcnow().strftime(SYNC_DATE_FMT), }) product = make_product({'organization-id': module_org.id}) repo = make_repository({'product-id': product['id']}) Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'] }) with pytest.raises(AssertionError): validate_task_status(repo['id'], max_tries=2)
def test_positive_remove_sync_plan_by_id(self): """Check if a sync plan can be removed from a product @id: 0df2005c-158a-48cb-8a16-9a63923699fc @Assert: Product has sync plan @CaseLevel: Integration """ product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], sync_plan['id']) Product.remove_sync_plan({'id': product['id']}) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(len(product['sync-plan-id']), 0)
def _make_sync_plan(self, options=None): """ Make a sync plan and asserts its success """ if options is None: options = {} if not options.get('organization-id', None): options[u'organization-id'] = self.org['id'] new_sync_plan = make_sync_plan(options) # Fetch it result = SyncPlan.info( { u'id': new_sync_plan['id'] } ) self.assertEqual( result.return_code, 0, "Sync plan was not found") self.assertEqual( len(result.stderr), 0, "No error was expected") # Return the sync plan dictionary return new_sync_plan
def test_positive_info_with_assigned_product(module_org): """Verify that sync plan info command returns list of products which are assigned to that sync plan :id: 7a7e5e40-7776-4d26-9173-73f00de6e8e9 :customerscenario: true :expectedresults: Expected product information is returned in info command :BZ: 1390545 :CaseImportance: Critical :CaseLevel: Integration """ prod1 = gen_string('alpha') prod2 = gen_string('alpha') sync_plan = make_sync_plan( { 'enabled': 'false', 'organization-id': module_org.id, 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), } ) for prod_name in [prod1, prod2]: product = make_product({'organization-id': module_org.id, 'name': prod_name}) Product.set_sync_plan({'id': product['id'], 'sync-plan-id': sync_plan['id']}) updated_plan = SyncPlan.info({'id': sync_plan['id']}) assert len(updated_plan['products']) == 2 assert {prod['name'] for prod in updated_plan['products']} == {prod1, prod2}
def test_add_syncplan_1(self): """@Test: Check if product can be assigned a syncplan @Feature: Product @Assert: Product has syncplan """ try: new_product = make_product({ u'organization-id': self.org['id'] }) sync_plan = make_sync_plan({'organization-id': self.org['id']}) except CLIFactoryError as err: self.fail(err) result = Product.set_sync_plan({ 'sync-plan-id': sync_plan['id'], 'id': new_product['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) result = Product.info({ 'id': new_product['id'], 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) self.assertEqual(result.stdout['sync-plan-id'], sync_plan['id'])
def test_remove_syncplan_1(self): """@Test: Check if product can be assigned a syncplan @Feature: Product @Assert: Product has syncplan """ product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], sync_plan['id']) Product.remove_sync_plan({'id': product['id']}) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(len(product['sync-plan-id']), 0)
def test_positive_update_sync_date(module_org): """Check if syncplan sync date can be updated :id: f0c17d7d-3e86-4b64-9747-6cba6809815e :expectedresults: Sync plan is created and sync plan is updated :BZ: 1336790 :CaseImportance: Critical """ # Set the sync date to today/right now today = datetime.now() sync_plan_name = gen_string('alphanumeric') new_sync_plan = make_sync_plan({ 'name': sync_plan_name, 'sync-date': today.strftime(SYNC_DATE_FMT), 'organization-id': module_org.id, }) # Assert that sync date matches data passed assert new_sync_plan['start-date'] == today.strftime("%Y/%m/%d %H:%M:%S") # Set sync date 5 days in the future future_date = today + timedelta(days=5) # Update sync interval SyncPlan.update({ 'id': new_sync_plan['id'], 'sync-date': future_date.strftime(SYNC_DATE_FMT) }) # Fetch it result = SyncPlan.info({'id': new_sync_plan['id']}) assert result['start-date'] != new_sync_plan['start-date'] assert datetime.strptime( result['start-date'], '%Y/%m/%d %H:%M:%S') > datetime.strptime( new_sync_plan['start-date'], '%Y/%m/%d %H:%M:%S'), 'Sync date was not updated'
def _make_sync_plan(self, options=None): """Make a sync plan and asserts its success""" if options is None: options = {} if not options.get('organization-id', None): options[u'organization-id'] = self.org['id'] return make_sync_plan(options)
def test_remove_syncplan_1(self): """@Test: Check if product can be assigned a syncplan @Feature: Product @Assert: Product has syncplan @BZ: 1121136 """ try: new_product = make_product( { u'organization-id': self.org['id'] } ) s = make_sync_plan({'organization-id': self.org['id']}) s_result = Product.set_sync_plan( { 'sync-plan-id': s['id'], 'id': new_product['id'] } ) except CLIFactoryError as err: self.fail(err) self.assertEqual( s_result.stderr, [], "Running set_sync_plan should cause no errors.") i_result = Product.info({'id': new_product['id'], 'organization-id': self.org['id']}) self.assertEqual( i_result.stderr, [], "Running product info should cause no errors.") self.assertEqual( i_result.stdout['sync-plan-id'], s['id'], "Info should have consistent sync ids.") r_result = Product.remove_sync_plan( { 'sync-plan-id': s['id'], 'id': new_product['id'] } ) self.assertEqual( r_result.stderr, [], "Running product remove_sync_plan should cause no errors.") i_result = Product.info({'id': new_product['id'], 'organization-id': self.org['id']}) self.assertEqual( i_result.stderr, [], "Running product info should cause no errors.") self.assertEqual( len(i_result.stdout['sync-plan-id']), 0, "Info should have no sync ids.")
def test_positive_synchronize_custom_product_future_sync_date(module_org): """Create a sync plan with sync date in a future and sync one custom product with it automatically. :id: 635bffe2-df98-4971-8950-40edc89e479e :expectedresults: Product is synchronized successfully. :CaseLevel: System :BZ: 1655595 """ cron_multiple = 5 # sync event is on every multiple of this value, starting from 00 mins delay = (cron_multiple) * 60 # delay for sync date in seconds guardtime = 180 # do not start test less than 3 mins before the next sync event product = make_product({'organization-id': module_org.id}) repo = make_repository({'product-id': product['id']}) # if < 3 mins before the target event rather wait 3 mins for the next test window if int(datetime.utcnow().strftime('%M')) % (cron_multiple) > int( guardtime / 60): sleep(guardtime) sync_plan = make_sync_plan({ 'enabled': 'true', 'organization-id': module_org.id, 'sync-date': (datetime.utcnow().replace(second=0) + timedelta(seconds=delay)).strftime(SYNC_DATE_FMT), 'cron-expression': [f'*/{cron_multiple} * * * *'], }) # Verify product is not synced and doesn't have any content validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'] }) # Wait quarter of expected time logger.info( f"Waiting {(delay / 4)} seconds to check product {product['name']}" f" was not synced by {sync_plan['name']}") sleep(delay / 4) # Verify product has not been synced yet with pytest.raises(AssertionError): validate_task_status(repo['id'], module_org.id, max_tries=1) validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time logger.info( f"Waiting {(delay * 3 / 4)} seconds to check product {product['name']}" f" was synced by {sync_plan['name']}") sleep(delay * 3 / 4) # Verify product was synced successfully validate_task_status(repo['id'], module_org.id) validate_repo_content(repo, ['errata', 'package-groups', 'packages'])
def test_add_syncplan_1(self): """@Test: Check if product can be assigned a syncplan @Feature: Product @Assert: Product has syncplan """ new_product = make_product({u"organization-id": self.org["id"]}) sync_plan = make_sync_plan({"organization-id": self.org["id"]}) Product.set_sync_plan({"id": new_product["id"], "sync-plan-id": sync_plan["id"]}) new_product = Product.info({"id": new_product["id"], "organization-id": self.org["id"]}) self.assertEqual(new_product["sync-plan-id"], sync_plan["id"])
def test_remove_syncplan_1(self): """@Test: Check if product can be assigned a syncplan @Feature: Product @Assert: Product has syncplan """ try: product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) result = Product.set_sync_plan({ 'sync-plan-id': sync_plan['id'], 'id': product['id'], }) except CLIFactoryError as err: self.fail(err) self.assertEqual( result.stderr, [], 'Running set_sync_plan should cause no errors.' ) result = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual( result.stderr, [], 'Running product info should cause no errors.' ) self.assertEqual( result.stdout['sync-plan-id'], sync_plan['id'], 'Info should have consistent sync ids.' ) r_result = Product.remove_sync_plan({ 'id': product['id'], }) self.assertEqual( r_result.stderr, [], 'Running product remove_sync_plan should cause no errors.' ) result = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual( result.stderr, [], 'Running product info should cause no errors.' ) self.assertEqual( len(result.stdout['sync-plan-id']), 0, 'Info should have no sync id.' )
def test_positive_info_enabled_field_is_displayed(module_org): """Check if Enabled field is displayed in sync-plan info output :id: 54e3a4ea-315c-4026-8101-c4605ca6b874 :expectedresults: Sync plan Enabled state is displayed :CaseImportance: Critical """ new_sync_plan = make_sync_plan({'organization-id': module_org.id}) result = SyncPlan.info({'id': new_sync_plan['id']}) assert result.get('enabled') is not None
def test_positive_update_description(module_org, new_desc): """Check if syncplan description can be updated :id: 00a279cd-1f49-4ebb-a59a-6f0b4e4cb83c :parametrized: yes :expectedresults: Sync plan is created and description is updated """ new_sync_plan = make_sync_plan({'organization-id': module_org.id}) SyncPlan.update({'description': new_desc, 'id': new_sync_plan['id']}) result = SyncPlan.info({'id': new_sync_plan['id']}) assert result['description'] == new_desc
def test_positive_create_with_description(module_org, desc): """Check if syncplan can be created with random description :id: a1bbe81b-60f5-4a19-b400-a02a23fa1dfa :parametrized: yes :expectedresults: Sync plan is created and has random description :CaseImportance: Critical """ new_sync_plan = make_sync_plan({'description': desc, 'organization-id': module_org.id}) result = SyncPlan.info({'id': new_sync_plan['id']}) assert result['description'] == desc
def test_positive_create_with_name(module_org, name): """Check if syncplan can be created with random names :id: dc0a86f7-4219-427e-92fd-29352dbdbfce :parametrized: yes :expectedresults: Sync plan is created and has random name :CaseImportance: Critical """ sync_plan = make_sync_plan({'name': name, 'organization-id': module_org.id}) result = SyncPlan.info({'id': sync_plan['id']}) assert result['name'] == name
def test_positive_synchronize_custom_product_past_sync_date(module_org): """Create a sync plan with a past datetime as a sync date, add a custom product and verify the product gets synchronized on the next sync occurrence :id: 21efdd08-698c-443c-a681-edce19a4c83a :expectedresults: Product is synchronized successfully. :BZ: 1279539 :CaseLevel: System """ interval = 60 * 60 # 'hourly' sync interval in seconds delay = 2 * 60 product = make_product({'organization-id': module_org.id}) repo = make_repository({'product-id': product['id']}) sync_plan = make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': module_org.id, 'sync-date': (datetime.utcnow() - timedelta(seconds=interval - delay)).strftime(SYNC_DATE_FMT), }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'] }) # Wait quarter of expected time logger.info( f"Waiting {(delay / 4)} seconds to check product {product['name']}" f" was not synced by {sync_plan['name']}") sleep(delay / 4) # Verify product has not been synced yet with pytest.raises(AssertionError): validate_task_status(repo['id'], module_org.id, max_tries=1) validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait until the first recurrence logger.info( f"Waiting {(delay * 3 / 4)} seconds to check product {product['name']}" f" was synced by {sync_plan['name']}") sleep(delay * 3 / 4) # Verify product was synced successfully validate_task_status(repo['id'], module_org.id) validate_repo_content(repo, ['errata', 'package-groups', 'packages'])
def test_positive_delete_by_id(module_org, name): """Check if syncplan can be created and deleted :id: b5d97c6b-aead-422b-8d9f-4a192bbe4a3b :parametrized: yes :expectedresults: Sync plan is created and then deleted :CaseImportance: Critical """ new_sync_plan = make_sync_plan({'name': name, 'organization-id': module_org.id}) SyncPlan.delete({'id': new_sync_plan['id']}) with pytest.raises(CLIReturnCodeError): SyncPlan.info({'id': new_sync_plan['id']})
def test_positive_create_5(self): """@Test: Check if product can be created with sync plan @Feature: Product @Assert: Product is created and has random sync plan """ sync_plan = make_sync_plan({u"organization-id": self.org["id"]}) for name in valid_data_list(): with self.subTest(name): product = make_product( {u"name": name, u"organization-id": self.org["id"], u"sync-plan-id": sync_plan["id"]} ) self.assertEqual(product["name"], name) self.assertEqual(product["sync-plan-id"], sync_plan["id"])
def test_positive_synchronize_custom_product_weekly_recurrence(module_org): """Create a weekly sync plan with a past datetime as a sync date, add a custom product and verify the product gets synchronized on the next sync occurrence :id: 1079a66d-7c23-44f6-a4a0-47f4c74d92a4 :expectedresults: Product is synchronized successfully. :BZ: 1396647 :CaseLevel: System """ delay = 2 * 60 product = make_product({'organization-id': module_org.id}) repo = make_repository({'product-id': product['id']}) start_date = datetime.utcnow() - timedelta(weeks=1) + timedelta( seconds=delay) sync_plan = make_sync_plan({ 'enabled': 'true', 'interval': 'weekly', 'organization-id': module_org.id, 'sync-date': start_date.strftime("%Y-%m-%d %H:%M:%S"), }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'] }) # Wait quarter of expected time logger.info('Waiting {} seconds to check product {}' ' was not synced'.format(delay / 4, product['name'])) sleep(delay / 4) # Verify product has not been synced yet with pytest.raises(AssertionError): validate_task_status(repo['id'], max_tries=1) validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait until the first recurrence logger.info('Waiting {} seconds to check product {}' ' was synced'.format((delay * 3 / 4), product['name'])) sleep(delay * 3 / 4) # Verify product was synced successfully validate_task_status(repo['id'], repo_name=repo['name']) validate_repo_content(repo, ['errata', 'package-groups', 'packages'])
def test_positive_synchronize_custom_product_future_sync_date(module_org): """Create a sync plan with sync date in a future and sync one custom product with it automatically. :id: 635bffe2-df98-4971-8950-40edc89e479e :expectedresults: Product is synchronized successfully. :CaseLevel: System :BZ: 1655595 """ delay = 2 * 60 # delay for sync date in seconds product = make_product({'organization-id': module_org.id}) repo = make_repository({'product-id': product['id']}) sync_plan = make_sync_plan( { 'enabled': 'true', 'organization-id': module_org.id, 'sync-date': (datetime.utcnow().replace(second=0) + timedelta(seconds=delay)).strftime( "%Y-%m-%d %H:%M:%S" ), 'cron-expression': ["*/4 * * * *"], } ) # Verify product is not synced and doesn't have any content validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Associate sync plan with product Product.set_sync_plan({'id': product['id'], 'sync-plan-id': sync_plan['id']}) # Wait quarter of expected time logger.info( 'Waiting {} seconds to check product {}' ' was not synced'.format(delay / 4, product['name']) ) sleep(delay / 4) # Verify product has not been synced yet with pytest.raises(AssertionError): validate_task_status(repo['id'], max_tries=1) validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time logger.info( 'Waiting {} seconds to check product {}' ' was synced'.format((delay * 3 / 4), product['name']) ) sleep(delay * 3 / 4) # Verify product was synced successfully validate_task_status(repo['id'], repo_name=repo['name']) validate_repo_content(repo, ['errata', 'package-groups', 'packages'])
def test_positive_create_5(self, test_data): """@Test: Check if product can be created with sync plan @Feature: Product @Assert: Product is created and has random sync plan """ sync_plan = make_sync_plan({u'organization-id': self.org['id']}) product = make_product({ u'name': test_data['name'], u'organization-id': self.org['id'], u'sync-plan-id': sync_plan['id'], }) self.assertEqual(product['name'], test_data['name']) self.assertEqual(product['sync-plan-id'], sync_plan['id'])
def test_positive_create_with_sync_plan(self): """Check if product can be created with sync plan @id: c54ff608-9f59-4fd6-a45c-bd70ce656023 @Assert: Product is created and has random sync plan """ sync_plan = make_sync_plan({u'organization-id': self.org['id']}) for name in valid_data_list(): with self.subTest(name): product = make_product({ u'name': name, u'organization-id': self.org['id'], u'sync-plan-id': sync_plan['id'], }) self.assertEqual(product['name'], name) self.assertEqual(product['sync-plan-id'], sync_plan['id'])
def test_positive_add_sync_plan_by_id(self): """@Test: Check if a sync plan can be added to a product @Feature: Product @Assert: Product has sync plan """ new_product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': new_product['id'], 'sync-plan-id': sync_plan['id'], }) new_product = Product.info({ 'id': new_product['id'], 'organization-id': self.org['id'], }) self.assertEqual(new_product['sync-plan-id'], sync_plan['id'])
def test_positive_add_sync_plan_by_id(self): """Check if a sync plan can be added to a product @Feature: Product @Assert: Product has sync plan """ new_product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': new_product['id'], 'sync-plan-id': sync_plan['id'], }) new_product = Product.info({ 'id': new_product['id'], 'organization-id': self.org['id'], }) self.assertEqual(new_product['sync-plan-id'], sync_plan['id'])
def _make_sync_plan(self, options=None): """Make a sync plan and asserts its success""" if options is None: options = {} if not options.get('organization-id', None): options[u'organization-id'] = self.org['id'] new_sync_plan = make_sync_plan(options) # Fetch it result = SyncPlan.info({u'id': new_sync_plan['id']}) self.assertEqual(result.return_code, 0, "Sync plan was not found") self.assertEqual(len(result.stderr), 0, "No error was expected") # Return the sync plan dictionary return new_sync_plan
def test_positive_create_with_interval(module_org, test_data): """Check if syncplan can be created with varied intervals :id: 32eb0c1d-0c9a-4fb5-a185-68d0d705fbce :parametrized: yes :expectedresults: Sync plan is created and has selected interval :CaseImportance: Critical """ new_sync_plan = make_sync_plan({ 'interval': test_data['interval'], 'name': test_data['name'], 'organization-id': module_org.id, }) result = SyncPlan.info({'id': new_sync_plan['id']}) assert result['name'] == test_data['name'] assert result['interval'] == test_data['interval']
def test_positive_create_with_sync_plan(self): """Check if product can be created with sync plan @id: c54ff608-9f59-4fd6-a45c-bd70ce656023 @Assert: Product is created and has random sync plan """ sync_plan = make_sync_plan({ u'organization-id': self.org['id'] }) for name in valid_data_list(): with self.subTest(name): product = make_product({ u'name': name, u'organization-id': self.org['id'], u'sync-plan-id': sync_plan['id'], }) self.assertEqual(product['name'], name) self.assertEqual(product['sync-plan-id'], sync_plan['id'])
def test_positive_add_sync_plan_by_id(self): """Check if a sync plan can be added to a product :id: 1517bc4b-5474-41c1-bc96-6e2130a2c2f4 :expectedresults: Product has sync plan :CaseLevel: Integration """ new_product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': new_product['id'], 'sync-plan-id': sync_plan['id'], }) new_product = Product.info({ 'id': new_product['id'], 'organization-id': self.org['id'], }) self.assertEqual(new_product['sync-plan-id'], sync_plan['id'])
def test_positive_add_sync_plan_by_id(self): """Check if a sync plan can be added to a product @id: 1517bc4b-5474-41c1-bc96-6e2130a2c2f4 @Assert: Product has sync plan @CaseLevel: Integration """ new_product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': new_product['id'], 'sync-plan-id': sync_plan['id'], }) new_product = Product.info({ 'id': new_product['id'], 'organization-id': self.org['id'], }) self.assertEqual(new_product['sync-plan-id'], sync_plan['id'])
def test_positive_update_interval(module_org, test_data): """Check if syncplan interval can be updated :id: d676d7f3-9f7c-4375-bb8b-277d71af94b4 :parametrized: yes :expectedresults: Sync plan interval is updated :CaseImportance: Critical """ new_sync_plan = make_sync_plan( { 'interval': test_data['interval'], 'name': test_data['name'], 'organization-id': module_org.id, } ) SyncPlan.update({'id': new_sync_plan['id'], 'interval': test_data['new-interval']}) result = SyncPlan.info({'id': new_sync_plan['id']}) assert result['interval'] == test_data['new-interval']
def test_positive_remove_sync_plan_by_id(self): """@Test: Check if a sync plan can be removed from a product @Feature: Product @Assert: Product has sync plan """ product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], sync_plan['id']) Product.remove_sync_plan({'id': product['id']}) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(len(product['sync-plan-id']), 0)
def test_positive_remove_sync_plan_by_id(self): """Check if a sync plan can be removed from a product @Feature: Product @Assert: Product has sync plan """ product = make_product({u'organization-id': self.org['id']}) sync_plan = make_sync_plan({'organization-id': self.org['id']}) Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['sync-plan-id'], sync_plan['id']) Product.remove_sync_plan({'id': product['id']}) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(len(product['sync-plan-id']), 0)
def test_positive_CRUD(self): """Check if product can be created, updated, synchronized and deleted :id: 9d7b5ec8-59d0-4371-b5d2-d43145e4e2db :expectedresults: Product is created, updated, synchronized and deleted :BZ: 1422552 :CaseImportance: Critical """ desc = list(valid_data_list().values())[0] gpg_key = make_gpg_key({'organization-id': self.org['id']}) name = list(valid_data_list().values())[0] label = valid_labels_list()[0] sync_plan = make_sync_plan({'organization-id': self.org['id']}) product = make_product({ 'description': desc, 'gpg-key-id': gpg_key['id'], 'label': label, 'name': name, 'organization-id': self.org['id'], 'sync-plan-id': sync_plan['id'], }) self.assertEqual(product['name'], name) self.assertGreater(len(product['label']), 0) self.assertEqual(product['label'], label) self.assertEqual(product['description'], desc) self.assertEqual(product['gpg']['gpg-key-id'], gpg_key['id']) self.assertEqual(product['sync-plan-id'], sync_plan['id']) # update desc = list(valid_data_list().values())[0] new_gpg_key = make_gpg_key({'organization-id': self.org['id']}) new_sync_plan = make_sync_plan({'organization-id': self.org['id']}) new_prod_name = gen_string('alpha', 8) Product.update({ 'description': desc, 'id': product['id'], 'gpg-key-id': new_gpg_key['id'], 'sync-plan-id': new_sync_plan['id'], 'name': new_prod_name, }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'] }) self.assertEqual(product['name'], new_prod_name) self.assertEqual(product['description'], desc) self.assertEqual(product['gpg']['gpg-key-id'], new_gpg_key['id']) self.assertNotEqual(product['gpg']['gpg-key-id'], gpg_key['id']) self.assertEqual(product['sync-plan-id'], new_sync_plan['id']) self.assertNotEqual(product['sync-plan-id'], sync_plan['id']) # synchronize repo = make_repository({ 'product-id': product['id'], 'url': FAKE_0_YUM_REPO }) Product.synchronize({ 'id': product['id'], 'organization-id': self.org['id'] }) packages = Package.list({'product-id': product['id']}) repo = Repository.info({'id': repo['id']}) self.assertEqual(int(repo['content-counts']['packages']), len(packages)) self.assertEqual(len(packages), FAKE_0_YUM_REPO_PACKAGES_COUNT) # delete Product.remove_sync_plan({'id': product['id']}) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'] }) self.assertEqual(len(product['sync-plan-id']), 0) Product.delete({'id': product['id']}) wait_for_tasks( search_query='label = Actions::Katello::Product::Destroy' ' and resource_id = {}'.format(product['id']), max_tries=10, ) with self.assertRaises(CLIReturnCodeError): Product.info({ 'id': product['id'], 'organization-id': self.org['id'] })
def test_positive_synchronize_rh_product_future_sync_date(module_org): """Create a sync plan with sync date in a future and sync one RH product with it automatically. :id: 6ce2f777-f230-4bb8-9822-2cf3580c21aa :expectedresults: Product is synchronized successfully. :CaseLevel: System :BZ: 1655595 """ delay = 2 * 60 # delay for sync date in seconds org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'] }) RepositorySet.enable({ 'name': REPOSET['rhva6'], 'organization-id': org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', 'basearch': 'x86_64', }) product = Product.info({ 'name': PRDS['rhel'], 'organization-id': org['id'] }) repo = Repository.info({ 'name': REPOS['rhva6']['name'], 'product': product['name'], 'organization-id': org['id'] }) sync_plan = make_sync_plan({ 'enabled': 'true', 'organization-id': module_org.id, 'sync-date': (datetime.utcnow().replace(second=0) + timedelta(seconds=delay)).strftime(SYNC_DATE_FMT), 'cron-expression': ["*/4 * * * *"], }) # Verify product is not synced and doesn't have any content with pytest.raises(AssertionError): validate_task_status(repo['id'], max_tries=1) validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'] }) # Wait quarter of expected time logger.info('Waiting {} seconds to check product {}' ' was not synced'.format(delay / 4, product['name'])) sleep(delay / 4) # Verify product has not been synced yet with pytest.raises(AssertionError): validate_task_status(repo['id'], max_tries=1) validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time logger.info('Waiting {} seconds to check product {}' ' was synced'.format((delay * 3 / 4), product['name'])) sleep(delay * 3 / 4) # Verify product was synced successfully validate_task_status(repo['id'], repo_name=repo['name']) validate_repo_content(repo, ['errata', 'packages'])
def test_positive_synchronize_rh_product_past_sync_date(module_org): """Create a sync plan with past datetime as a sync date, add a RH product and verify the product gets synchronized on the next sync occurrence :id: 47280ef4-3936-4dbc-8ed0-1076aa8d40df :expectedresults: Product is synchronized successfully. :BZ: 1279539 :CaseLevel: System """ interval = 60 * 60 # 'hourly' sync interval in seconds delay = 2 * 60 org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'] }) RepositorySet.enable({ 'name': REPOSET['rhva6'], 'organization-id': org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', 'basearch': 'x86_64', }) product = Product.info({ 'name': PRDS['rhel'], 'organization-id': org['id'] }) repo = Repository.info({ 'name': REPOS['rhva6']['name'], 'product': product['name'], 'organization-id': org['id'] }) sync_plan = make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': module_org.id, 'sync-date': (datetime.utcnow() - timedelta(seconds=interval - delay)).strftime(SYNC_DATE_FMT), }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'] }) # Wait quarter of expected time logger.info('Waiting {} seconds to check product {}' ' was not synced'.format(delay / 4, product['name'])) sleep(delay / 4) # Verify product has not been synced yet with pytest.raises(AssertionError): validate_task_status(repo['id'], max_tries=1) validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time logger.info('Waiting {} seconds to check product {}' ' was synced'.format((delay * 3 / 4), product['name'])) sleep(delay * 3 / 4) # Verify product was synced successfully validate_task_status(repo['id'], repo_name=repo['name']) validate_repo_content(repo, ['errata', 'packages'])
def test_positive_update_3(self, test_name): """ @Test: Update product's sync plan @Feature: Product @Assert: Product sync plan is updated @BZ: 1096320 """ first_sync_plan = make_sync_plan( {u'organization-id': self.org['id']} ) second_sync_plan = make_sync_plan( {u'organization-id': self.org['id']} ) new_product = make_product( { u'name': test_name['name'], u'organization-id': self.org['id'], } ) # Fetch it result = Product.info( {u'id': new_product['id'], u'organization-id': self.org['id']}) self.assertEqual( result.return_code, 0, "Product was not found") self.assertEqual( len(result.stderr), 0, "No error was expected") # No sync plan yet self.assertEqual( len(result.stdout['sync-plan-id']), 0, "No sync plan expected" ) # Add first sync plan to product result = Product.update( {u'id': new_product['id'], u'sync-plan-id': first_sync_plan['id']} ) # Fetch it result = Product.info( {u'id': new_product['id'], u'organization-id': self.org['id']}) self.assertEqual( result.return_code, 0, "Product was not found") self.assertEqual( len(result.stderr), 0, "No error was expected") self.assertEqual( result.stdout['sync-plan-id'], first_sync_plan['id'], "Sync plans don't match") self.assertNotEqual( result.stdout['sync-plan-id'], second_sync_plan['id'], "Sync plans should not match") # Remove first sync plan by updating product to use second plan result = Product.update( {u'id': new_product['id'], u'name': new_product['name'], u'sync-plan-id': second_sync_plan['id']} ) # Fetch it result = Product.info( {u'id': new_product['id'], u'organization-id': self.org['id']}) self.assertEqual( result.return_code, 0, "Product was not found") self.assertEqual( len(result.stderr), 0, "No error was expected") self.assertEqual( result.stdout['sync-plan-id'], second_sync_plan['id'], "Sync plans don't match" ) self.assertNotEqual( result.stdout['sync-plan-id'], first_sync_plan['id'], "Sync plans should not match")