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_positive_package_count(self): """Check that packages count is correctly filtered by product id :id: 151f60a3-0b94-4658-8b0d-0d022f4f1d8f :expectedresults: Packages only from synced product returned :BZ: 1422552 :CaseLevel: Integration """ org = make_org() for _ in range(3): product = make_product({'organization-id': org['id']}) repo = make_repository({ 'product-id': product['id'], 'url': FAKE_0_YUM_REPO, }) Product.synchronize({ 'id': product['id'], 'organization-id': 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)
def test_product_synchronize_by_label(self): """@Test: Check if product can be synchronized. Searches for organization by its label @Feature: Product @Assert: Product was synchronized """ try: org = make_org() product = make_product({'organization-id': org['id']}) make_repository({'product-id': product['id']}) except CLIFactoryError as err: self.fail(err) result = Product.synchronize({ 'id': product['id'], 'organization-label': org['label'], }) self.assertEqual(result.return_code, 0) result = Product.info({ 'id': product['id'], 'organization-id': org['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(u'Syncing Complete.', result.stdout['sync-state'])
def test_positive_update_gpg_key(self): """Update product's gpg keys @Feature: Product @Assert: Product gpg key is updated """ first_gpg_key = make_gpg_key({u'organization-id': self.org['id']}) second_gpg_key = make_gpg_key({u'organization-id': self.org['id']}) product = make_product({ u'gpg-key-id': first_gpg_key['id'], u'organization-id': self.org['id'], }) # Update the Descriptions Product.update({ u'gpg-key-id': second_gpg_key['id'], u'id': product['id'], }) # Fetch it product = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key-id'], second_gpg_key['id']) self.assertNotEqual(product['gpg']['gpg-key-id'], first_gpg_key['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_info_with_assigned_product(self): """Verify that sync plan info command returns list of products which are assigned to that sync plan :id: 7a7e5e40-7776-4d26-9173-73f00de6e8e9 :expectedresults: Expected product information is returned in info command :BZ: 1390545 """ prod1 = gen_string('alpha') prod2 = gen_string('alpha') sync_plan = self._make_sync_plan({ 'enabled': 'false', 'organization-id': self.org['id'], 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), }) for prod_name in [prod1, prod2]: product = make_product({ 'organization-id': self.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']}) self.assertEqual(len(updated_plan['products']), 2) self.assertEqual( set(prod['name'] for prod in updated_plan['products']), set([prod1, prod2]) )
def test_positive_delete_1(self): """@Test: Check if product can be deleted @Feature: Product @Assert: Product is deleted """ new_product = make_product({ u'organization-id': self.org['id'] }) # Delete it result = Product.delete({u'id': new_product['id']}) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) # Fetch it result = Product.info({ u'id': new_product['id'], u'organization-id': self.org['id'], }) if bz_bug_is_open(1219490): for _ in range(5): if result.return_code == 0: time.sleep(5) result = Product.info({ u'id': new_product['id'], u'organization-id': self.org['id'], }) else: break self.assertNotEqual(result.return_code, 0) self.assertGreater(len(result.stderr), 0)
def test_positive_add_product_with_repos(self): """@test: Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository @feature: GPG Keys @assert: gpg key is associated with product as well as with the repositories """ product = make_product({'organization-id': self.org['id']}) repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] gpg_key = make_gpg_key({'organization-id': self.org['id']}) Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key-id'], gpg_key['id']) for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key']['id'], gpg_key['id'])
def test_positive_add_product_with_repos(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository :id: b05c5223-44d5-4a48-9d99-18ca351c84a5 :expectedresults: gpg key is associated with product as well as with the repositories :CaseLevel: Integration """ product = make_product({'organization-id': self.org['id']}) repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] gpg_key = make_gpg_key({'organization-id': self.org['id']}) Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key-id'], gpg_key['id']) for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key']['id'], gpg_key['id'])
def test_positive_info_with_assigned_product(self): """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 """ prod1 = gen_string('alpha') prod2 = gen_string('alpha') sync_plan = self._make_sync_plan({ 'enabled': 'false', 'organization-id': self.org['id'], 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), }) for prod_name in [prod1, prod2]: product = make_product({ 'organization-id': self.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']}) self.assertEqual(len(updated_plan['products']), 2) self.assertEqual( set(prod['name'] for prod in updated_plan['products']), set([prod1, prod2]) )
def test_positive_synchronize_custom_product_future_sync_date(self): """Create a sync plan with sync date in a future and sync one custom product with it automatically. @Assert: Product is synchronized successfully. @Feature: SyncPlan """ delay = 10 * 60 # delay for sync date in seconds sync_plan = self._make_sync_plan({ 'enabled': 'true', 'organization-id': self.org['id'], 'sync-date': (datetime.utcnow() + timedelta(seconds=delay)) .strftime("%Y-%m-%d %H:%M:%S"), }) product = make_product({'organization-id': self.org['id']}) repo = make_repository({'product-id': product['id']}) # Verify product is not synced and doesn't have any content self.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 half of expected time sleep(delay/2) # Verify product has not been synced yet self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(delay/2) # Verify product was synced successfully self.validate_repo_content( repo, ['errata', 'package-groups', 'packages'])
def test_positive_add_product_with_repo(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has one repository @id: 5529a852-9ef6-48f8-b2bc-2bbf463657dd @assert: gpg key is associated with product as well as with the repository @CaseLevel: Integration """ product = make_product({'organization-id': self.org['id']}) repo = make_repository({'product-id': product['id']}) gpg_key = make_gpg_key({'organization-id': self.org['id']}) Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) repo = Repository.info({'id': repo['id']}) self.assertEqual(product['gpg']['gpg-key-id'], gpg_key['id']) self.assertEqual(repo['gpg-key']['id'], gpg_key['id'])
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_positive_add_product_with_repo(module_org): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has one repository :id: f315eadd-e65b-4952-912f-f640867ad656 :expectedresults: gpg key is associated with product as well as with the repository :CaseLevel: Integration """ product = make_product({'organization-id': module_org.id}) repo = make_repository({'product-id': product['id']}) gpg_key = make_content_credential({'organization-id': module_org.id}) Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': module_org.id }) product = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) repo = Repository.info({'id': repo['id']}) assert product['gpg']['gpg-key-id'] == gpg_key['id'] assert repo['gpg-key']['id'] == gpg_key['id']
def test_positive_add_product_with_repos(module_org): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository :id: 76683f3e-7705-4719-996e-c026839053bb :expectedresults: gpg key is associated with product as well as with the repositories :CaseLevel: Integration """ product = make_product({'organization-id': module_org.id}) repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] gpg_key = make_content_credential({'organization-id': module_org.id}) Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': module_org.id }) product = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) assert product['gpg']['gpg-key-id'] == gpg_key['id'] for repo in repos: repo = Repository.info({'id': repo['id']}) assert repo['gpg-key']['id'] == gpg_key['id']
def test_positive_add_product_with_repo(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has one repository :id: 5529a852-9ef6-48f8-b2bc-2bbf463657dd :expectedresults: gpg key is associated with product as well as with the repository :CaseLevel: Integration """ product = make_product({'organization-id': self.org['id']}) repo = make_repository({'product-id': product['id']}) gpg_key = make_gpg_key({'organization-id': self.org['id']}) Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) repo = Repository.info({'id': repo['id']}) self.assertEqual(product['gpg']['gpg-key-id'], gpg_key['id']) self.assertEqual(repo['gpg-key']['id'], gpg_key['id'])
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_update_gpg_key(self): """Update product's gpg keys :id: e7febd14-ac8b-424e-9ddf-bf0f63ebe430 :expectedresults: Product gpg key is updated :CaseImportance: Critical """ first_gpg_key = make_gpg_key({u'organization-id': self.org['id']}) second_gpg_key = make_gpg_key({u'organization-id': self.org['id']}) product = make_product({ u'gpg-key-id': first_gpg_key['id'], u'organization-id': self.org['id'], }) # Update the Descriptions Product.update({ u'gpg-key-id': second_gpg_key['id'], u'id': product['id'], }) # Fetch it product = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key-id'], second_gpg_key['id']) self.assertNotEqual(product['gpg']['gpg-key-id'], first_gpg_key['id'])
def test_positive_synchronize_rh_product_future_sync_date(self): """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 """ delay = 10 * 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'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'organization-id': org['id'], 'sync-date': (datetime.utcnow() + timedelta(seconds=delay)).strftime("%Y-%m-%d %H:%M:%S"), }) 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'], }) # Verify product is not synced and doesn't have any content self.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 half of expected time sleep(delay / 2) # Verify product has not been synced yet self.validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(delay / 2) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
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_synchronize_custom_product_current_sync_date(self): """Create a sync plan with current datetime as a sync date, add a custom product and verify the product gets synchronized on the next sync occurrence @Assert: Product is synchronized successfully. @Feature: SyncPlan @BZ: 1279539 """ interval = 60 * 60 # 'hourly' sync interval in seconds sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': self.org['id'], 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), }) product = make_product({'organization-id': self.org['id']}) repo = make_repository({'product-id': product['id']}) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Wait half of expected time sleep(interval / 2) # Verify product has not been synced yet self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(interval / 2) # Verify product was synced successfully self.validate_repo_content( repo, ['errata', 'package-groups', 'packages'])
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_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_positive_package_count(self): """Check that packages count is correctly filtered by product id :id: 151f60a3-0b94-4658-8b0d-0d022f4f1d8f :expectedresults: Packages only from synced product returned :BZ: 1422552 :CaseLevel: Integration """ org = make_org() for _ in range(3): product = make_product({'organization-id': org['id']}) repo = make_repository({ 'product-id': product['id'], 'url': FAKE_0_YUM_REPO, }) Product.synchronize({ 'id': product['id'], 'organization-id': 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)
def test_positive_update_1(self, test_data): """@Test: Update the description of a product @Feature: Product @Assert: Product description is updated """ product = make_product({ u'organization-id': self.org['id'], }) # Update the Descriptions result = Product.update({ u'id': product['id'], u'description': test_data['description'], }) # Fetch it result = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) self.assertEqual( result.stdout['description'], test_data['description']) self.assertNotEqual( product['description'], result.stdout['description'])
def test_negative_synchronize_custom_product_current_sync_date(self): """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 = self._make_sync_plan({ 'enabled': 'true', 'organization-id': self.org['id'], 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), }) product = make_product({'organization-id': self.org['id']}) repo = make_repository({'product-id': product['id']}) Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) with self.assertRaises(AssertionError): self.validate_repo_content( repo, ['errata', 'package-groups', 'packages'], max_attempts=5, )
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_2(self): """@Test: Update product's gpg keys @Feature: Product @Assert: Product gpg key is updated """ first_gpg_key = make_gpg_key({u'organization-id': self.org['id']}) second_gpg_key = make_gpg_key({u'organization-id': self.org['id']}) product = make_product({ u'gpg-key-id': first_gpg_key['id'], u'organization-id': self.org['id'], }) # Update the Descriptions Product.update({ u'gpg-key-id': second_gpg_key['id'], u'id': product['id'], }) # Fetch it product = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key-id'], second_gpg_key['id']) self.assertNotEqual(product['gpg']['gpg-key-id'], first_gpg_key['id'])
def test_positive_update_gpg_key(self): """Update product's gpg keys @id: e7febd14-ac8b-424e-9ddf-bf0f63ebe430 @Assert: Product gpg key is updated """ first_gpg_key = make_gpg_key({u'organization-id': self.org['id']}) second_gpg_key = make_gpg_key({u'organization-id': self.org['id']}) product = make_product({ u'gpg-key-id': first_gpg_key['id'], u'organization-id': self.org['id'], }) # Update the Descriptions Product.update({ u'gpg-key-id': second_gpg_key['id'], u'id': product['id'], }) # Fetch it product = Product.info({ u'id': product['id'], u'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key-id'], second_gpg_key['id']) self.assertNotEqual(product['gpg']['gpg-key-id'], first_gpg_key['id'])
def test_positive_synchronize_rh_product_current_sync_date(self): """Create a sync plan with current datetime as a sync date, add a RH product and verify the product gets synchronized on the next sync occurrence @Assert: Product is synchronized successfully. @Feature: SyncPlan @BZ: 1279539 """ interval = 60 * 60 # 'hourly' sync interval 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'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': org['id'], 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), }) 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'], }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Wait half of expected time sleep(interval / 2) # Verify product has not been synced yet self.validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(interval / 2) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
def test_positive_product_sync_state(module_org): """hammer product info shows correct sync state. :id: 58af6239-85d7-4b8b-bd2d-ab4cd4f29840 :BZ: 1803207,1999541 :customerscenario: true :Steps: 1. Sync a custom repository that fails. 2. Run `hammer product info --product-id <id>`. 3. Successfully sync another repository under the same product. 4. Run `hammer product info --product-id <id>` again. :expectedresults: hammer should show 'Sync Incomplete' in both cases. """ product = make_product({'organization-id': module_org.id}) repo_a1 = make_repository({ 'organization-id': module_org.id, 'product-id': product['id'], 'name': gen_string('alpha'), 'url': f'{gen_url(scheme="https")}:{gen_integer(min_value=10, max_value=9999)}', }) with pytest.raises(CLIReturnCodeError): Repository.synchronize({'id': repo_a1['id']}) product_info = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) product_list = Product.list({'organization-id': module_org.id}) assert product_info['sync-state-(last)'] in [ p.get('sync-state') for p in product_list ] repo_a2 = make_repository( { 'organization-id': module_org.id, 'product-id': product['id'], 'name': gen_string('alpha'), 'url': settings.repos.yum_0.url, }, ) Repository.synchronize({'id': repo_a2['id']}) product_info = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) product_list = Product.list({'organization-id': module_org.id}) assert product_info['sync-state-(last)'] in [ p.get('sync-state') for p in product_list ]
def test_positive_synchronize_rh_product_past_sync_date(self): """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 = 80 org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': org['id'], 'sync-date': ( datetime.utcnow() - timedelta(interval - delay/2) ).strftime("%Y-%m-%d %H:%M:%S"), }) 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'], }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Verify product has not been synced yet sleep(delay/4) self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(delay) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
def test_positive_synchronize_custom_products_future_sync_date(self): """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 """ delay = 6 * 60 # delay for sync date in seconds sync_plan = self._make_sync_plan({ 'enabled': 'true', 'organization-id': self.org['id'], 'sync-date': (datetime.utcnow() + timedelta(seconds=delay)) .strftime("%Y-%m-%d %H:%M:%S"), }) products = [ make_product({'organization-id': self.org['id']}) for _ in range(3) ] repos = [ make_repository({'product-id': product['id']}) for product in products for _ in range(2) ] # Verify products have not been synced yet for repo in repos: with self.assertRaises(AssertionError): self.validate_task_status(repo['id'], max_tries=2) # Associate sync plan with products for product in products: Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Wait half of expected time self.logger.info('Waiting {0} seconds to check products' ' were not synced'.format(delay/2)) sleep(delay/4) # Verify products has not been synced yet for repo in repos: with self.assertRaises(AssertionError): self.validate_task_status(repo['id'], max_tries=2) # Wait the rest of expected time self.logger.info('Waiting {0} seconds to check products' ' were synced'.format(delay/2)) sleep(delay * 3/4) # Re-calculate and Update with the current UTC time SyncPlan.update({ u'id': sync_plan['id'], u'sync-date': (datetime.utcnow() + timedelta(seconds=delay)) .strftime("%Y-%m-%d %H:%M:%S"), }) # Verify product was synced successfully for repo in repos: self.validate_task_status(repo['id'], repo_name=repo['name']) self.validate_repo_content( repo, ['errata', 'package-groups', 'packages'])
def test_positive_update_key_for_product_with_repos(module_org): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository then update the key :id: 8aa3dc75-6257-48ae-b3f9-c617e323b47a :expectedresults: gpg key is associated with product before/after update as well as with the repositories :CaseLevel: Integration """ # Create a product and a gpg key product = make_product({'organization-id': module_org.id}) gpg_key = make_content_credential({'organization-id': module_org.id}) # Create repositories and assign them to the product repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': module_org.id }) # Verify gpg key was associated product = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) assert product['gpg']['gpg-key'] == gpg_key['name'] for repo in repos: repo = Repository.info({'id': repo['id']}) assert repo['gpg-key'].get('name') == gpg_key['name'] # Update the gpg key new_name = gen_choice(list(valid_data_list().values())) ContentCredential.update({ 'name': gpg_key['name'], 'new-name': new_name, 'organization-id': module_org.id }) # Verify changes are reflected in the gpg key gpg_key = ContentCredential.info({ 'id': gpg_key['id'], 'organization-id': module_org.id }) assert gpg_key['name'] == new_name # Verify changes are reflected in the product product = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) assert product['gpg']['gpg-key'] == new_name # Verify changes are reflected in the repositories for repo in repos: repo = Repository.info({'id': repo['id']}) assert repo['gpg-key'].get('name') == new_name
def test_positive_update_key_for_product_with_repos(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository then update the key :id: a95eb51b-4b6b-4c04-bb4d-cbe600431850 :expectedresults: gpg key is associated with product before/after update as well as with the repositories :CaseLevel: Integration """ # Create a product and a gpg key product = make_product({'organization-id': self.org['id']}) gpg_key = make_gpg_key({'organization-id': self.org['id']}) # Create repositories and assign them to the product repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) # Verify gpg key was associated product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key'], gpg_key['name']) for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key'].get('name'), gpg_key['name']) # Update the gpg key new_name = gen_choice(valid_data_list()) GPGKey.update({ 'name': gpg_key['name'], 'new-name': new_name, 'organization-id': self.org['id'], }) # Verify changes are reflected in the gpg key gpg_key = GPGKey.info({ 'id': gpg_key['id'], 'organization-id': self.org['id'], }) self.assertEqual(gpg_key['name'], new_name) # Verify changes are reflected in the product product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key'], new_name) # Verify changes are reflected in the repositories for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key'].get('name'), new_name)
def test_positive_update_key_for_product_with_repos(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository then update the key @id: a95eb51b-4b6b-4c04-bb4d-cbe600431850 @assert: gpg key is associated with product before/after update as well as with the repositories @CaseLevel: Integration """ # Create a product and a gpg key product = make_product({'organization-id': self.org['id']}) gpg_key = make_gpg_key({'organization-id': self.org['id']}) # Create repositories and assign them to the product repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) # Verify gpg key was associated product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key'], gpg_key['name']) for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key'].get('name'), gpg_key['name']) # Update the gpg key new_name = gen_choice(valid_data_list()) GPGKey.update({ 'name': gpg_key['name'], 'new-name': new_name, 'organization-id': self.org['id'], }) # Verify changes are reflected in the gpg key gpg_key = GPGKey.info({ 'id': gpg_key['id'], 'organization-id': self.org['id'], }) self.assertEqual(gpg_key['name'], new_name) # Verify changes are reflected in the product product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key'], new_name) # Verify changes are reflected in the repositories for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key'].get('name'), new_name)
def test_positive_synchronize_rh_product_future_sync_date(self): """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 """ delay = 10 * 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'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'organization-id': org['id'], 'sync-date': (datetime.utcnow() + timedelta(seconds=delay)) .strftime("%Y-%m-%d %H:%M:%S"), }) 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'], }) # Verify product is not synced and doesn't have any content self.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 half of expected time sleep(delay/2) # Verify product has not been synced yet self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(delay/2) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
def test_positive_synchronize_custom_product_past_sync_date(self): """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': self.org['id']}) repo = make_repository({'product-id': product['id']}) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': self.org['id'], 'sync-date': (datetime.utcnow() - timedelta(seconds=interval - delay) ).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'], }) # Verify product has not been synced yet self.logger.info('Waiting {0} seconds to check product {1}' ' was not synced'.format(delay / 4, product['name'])) sleep(delay / 4) with self.assertRaises(AssertionError): self.validate_task_status(repo['id'], max_tries=2) self.validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait until the first recurrence self.logger.info('Waiting {0} seconds to check product {1}' ' was synced'.format(delay, product['name'])) sleep(delay * 3 / 4) # Re-calculate and Update with the current UTC time SyncPlan.update({ u'id': sync_plan['id'], u'sync-date': (datetime.utcnow() - timedelta(seconds=interval - delay) ).strftime("%Y-%m-%d %H:%M:%S"), }) # Verify product was synced successfully self.validate_task_status(repo['id'], repo_name=repo['name']) self.validate_repo_content(repo, ['errata', 'package-groups', 'packages'])
def test_positive_delete_key_for_product_with_repos(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository then delete it @id: f92d4643-1892-4f95-ae6b-fcea8e726946 @assert: gpg key is associated with product and its repositories during creation but removed from the product and the repositories after deletion @CaseLevel: Integration """ # Create product, repositories and gpg key product = make_product({'organization-id': self.org['id']}) repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] gpg_key = make_gpg_key({'organization-id': self.org['id']}) # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) # Verify gpg key was associated with product and its repositories product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key'], gpg_key['name']) for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key'].get('name'), gpg_key['name']) # Delete the gpg key GPGKey.delete({ 'name': gpg_key['name'], 'organization-id': self.org['id'], }) # Verify gpg key was actually deleted with self.assertRaises(CLIReturnCodeError): GPGKey.info({ 'id': gpg_key['id'], 'organization-id': self.org['id'], }) # Verify gpg key was disassociated from the product and its # repositories product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertNotEqual(product['gpg']['gpg-key'], gpg_key['name']) for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertNotEqual(repo['gpg-key'].get('name'), gpg_key['name'])
def test_positive_synchronize_custom_product_weekly_recurrence(self): """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 = 5 * 60 product = make_product({'organization-id': self.org['id']}) repo = make_repository({'product-id': product['id']}) start_date = datetime.utcnow() - timedelta(weeks=1)\ + timedelta(seconds=delay) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'weekly', 'organization-id': self.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'], }) # Verify product has not been synced yet self.logger.info('Waiting {0} seconds to check product {1}' ' was not synced'.format(delay / 4, product['name'])) sleep(delay / 4) with self.assertRaises(AssertionError): self.validate_task_status(repo['id'], max_tries=2) self.validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait until the first recurrence self.logger.info('Waiting {0} seconds to check product {1}' ' was synced'.format(delay, product['name'])) sleep(delay * 3 / 4) # Re-calculate and Update with the current UTC time start_date = datetime.utcnow() - timedelta(weeks=1)\ + timedelta(seconds=delay) SyncPlan.update({ u'id': sync_plan['id'], u'sync-date': start_date.strftime("%Y-%m-%d %H:%M:%S"), }) # Verify product was synced successfully self.validate_task_status(repo['id'], repo_name=repo['name']) self.validate_repo_content(repo, ['errata', 'package-groups', 'packages'])
def test_positive_delete_key_for_product_with_repos(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository then delete it :id: f92d4643-1892-4f95-ae6b-fcea8e726946 :expectedresults: gpg key is associated with product and its repositories during creation but removed from the product and the repositories after deletion :CaseLevel: Integration """ # Create product, repositories and gpg key product = make_product({'organization-id': self.org['id']}) repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] gpg_key = make_gpg_key({'organization-id': self.org['id']}) # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) # Verify gpg key was associated with product and its repositories product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key'], gpg_key['name']) for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key'].get('name'), gpg_key['name']) # Delete the gpg key GPGKey.delete({ 'name': gpg_key['name'], 'organization-id': self.org['id'], }) # Verify gpg key was actually deleted with self.assertRaises(CLIReturnCodeError): GPGKey.info({ 'id': gpg_key['id'], 'organization-id': self.org['id'], }) # Verify gpg key was disassociated from the product and its # repositories product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertNotEqual(product['gpg']['gpg-key'], gpg_key['name']) for repo in repos: repo = Repository.info({'id': repo['id']}) self.assertNotEqual(repo['gpg-key'].get('name'), gpg_key['name'])
def test_positive_delete_key_for_product_with_repos(module_org): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has more than one repository then delete it :id: 3848441f-746a-424c-afc3-4d5a15888af8 :expectedresults: gpg key is associated with product and its repositories during creation but removed from the product and the repositories after deletion :CaseLevel: Integration """ # Create product, repositories and gpg key product = make_product({'organization-id': module_org.id}) repos = [ make_repository({'product-id': product['id']}) for _ in range(gen_integer(2, 5)) ] gpg_key = make_content_credential({'organization-id': module_org.id}) # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': module_org.id }) # Verify gpg key was associated with product and its repositories product = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) assert product['gpg']['gpg-key'] == gpg_key['name'] for repo in repos: repo = Repository.info({'id': repo['id']}) assert repo['gpg-key'].get('name') == gpg_key['name'] # Delete the gpg key ContentCredential.delete({ 'name': gpg_key['name'], 'organization-id': module_org.id }) # Verify gpg key was actually deleted with pytest.raises(CLIReturnCodeError): ContentCredential.info({ 'id': gpg_key['id'], 'organization-id': module_org.id }) # Verify gpg key was disassociated from the product and its # repositories product = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) assert product['gpg']['gpg-key'] != gpg_key['name'] for repo in repos: repo = Repository.info({'id': repo['id']}) assert repo['gpg-key'].get('name') != gpg_key['name']
def test_positive_synchronize_custom_product_future_sync_date(self): """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 """ delay = 5 * 60 # delay for sync date in seconds sync_plan = self._make_sync_plan({ 'enabled': 'true', 'organization-id': self.org['id'], 'sync-date': (datetime.utcnow() + timedelta(seconds=delay)).strftime("%Y-%m-%d %H:%M:%S"), }) product = make_product({'organization-id': self.org['id']}) repo = make_repository({'product-id': product['id']}) # Verify product is not synced and doesn't have any content self.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 half of expected time self.logger.info('Waiting {0} seconds to check product {1}' ' was not synced'.format(delay / 2, product['name'])) sleep(delay / 4) # Verify product has not been synced yet with self.assertRaises(AssertionError): self.validate_task_status(repo['id'], max_tries=2) self.validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time self.logger.info('Waiting {0} seconds to check product {1}' ' was synced'.format(delay / 2, product['name'])) sleep(delay * 3 / 4) # Re-calculate and Update with the current UTC time SyncPlan.update({ u'id': sync_plan['id'], u'sync-date': (datetime.utcnow() + timedelta(seconds=delay)).strftime("%Y-%m-%d %H:%M:%S"), }) # Verify product was synced successfully self.validate_task_status(repo['id'], repo_name=repo['name']) self.validate_repo_content(repo, ['errata', 'package-groups', 'packages'])
def test_positive_synchronize_rh_product_current_sync_date(self): """Create a sync plan with current datetime as a sync date, add a RH product and verify the product gets synchronized on the next sync occurrence @Assert: Product is synchronized successfully. @Feature: SyncPlan @BZ: 1279539 """ interval = 60 * 60 # 'hourly' sync interval 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'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': org['id'], 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), }) 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'], }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Wait half of expected time sleep(interval / 2) # Verify product has not been synced yet self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(interval / 2) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', '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 """ 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_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_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_positive_update_key_for_product_with_repo(module_org): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has one repository then update the key :id: 1f8f943c-a611-4ed2-9d8a-770f60a549a7 :expectedresults: gpg key is associated with product before/after update as well as with the repository :CaseLevel: Integration """ # Create a product and a gpg key product = make_product({'organization-id': module_org.id}) gpg_key = make_content_credential({'organization-id': module_org.id}) # Create a repository and assign it to the product repo = make_repository({'product-id': product['id']}) # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': module_org.id }) # Verify gpg key was associated product = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) repo = Repository.info({'id': repo['id']}) assert product['gpg']['gpg-key'] == gpg_key['name'] assert repo['gpg-key'].get('name') == gpg_key['name'] # Update the gpg key new_name = gen_choice(list(valid_data_list().values())) ContentCredential.update({ 'name': gpg_key['name'], 'new-name': new_name, 'organization-id': module_org.id }) # Verify changes are reflected in the gpg key gpg_key = ContentCredential.info({ 'id': gpg_key['id'], 'organization-id': module_org.id }) assert gpg_key['name'] == new_name # Verify changes are reflected in the product product = Product.info({ 'id': product['id'], 'organization-id': module_org.id }) assert product['gpg']['gpg-key'] == new_name # Verify changes are reflected in the repository repo = Repository.info({'id': repo['id']}) assert repo['gpg-key'].get('id') == gpg_key['id']
def test_positive_update_key_for_product_with_repo(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has one repository then update the key @id: 3fb550a7-507e-4988-beb6-35bdfc2e99a8 @assert: gpg key is associated with product before/after update as well as with the repository @CaseLevel: Integration """ # Create a product and a gpg key product = make_product({'organization-id': self.org['id']}) gpg_key = make_gpg_key({'organization-id': self.org['id']}) # Create a repository and assign it to the product repo = make_repository({'product-id': product['id']}) # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) # Verify gpg key was associated product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) repo = Repository.info({'id': repo['id']}) self.assertEqual(product['gpg']['gpg-key'], gpg_key['name']) self.assertEqual(repo['gpg-key'].get('name'), gpg_key['name']) # Update the gpg key new_name = gen_choice(valid_data_list()) GPGKey.update({ 'name': gpg_key['name'], 'new-name': new_name, 'organization-id': self.org['id'], }) # Verify changes are reflected in the gpg key gpg_key = GPGKey.info({ 'id': gpg_key['id'], 'organization-id': self.org['id'], }) self.assertEqual(gpg_key['name'], new_name) # Verify changes are reflected in the product product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key'], new_name) # Verify changes are reflected in the repository repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key'].get('id'), gpg_key['id'])
def test_positive_update_key_for_product_with_repo(self): """Create gpg key with valid name and valid gpg key via file import then associate it with custom product that has one repository then update the key :id: 3fb550a7-507e-4988-beb6-35bdfc2e99a8 :expectedresults: gpg key is associated with product before/after update as well as with the repository :CaseLevel: Integration """ # Create a product and a gpg key product = make_product({'organization-id': self.org['id']}) gpg_key = make_gpg_key({'organization-id': self.org['id']}) # Create a repository and assign it to the product repo = make_repository({'product-id': product['id']}) # Associate gpg key with a product Product.update({ 'gpg-key': gpg_key['name'], 'id': product['id'], 'organization-id': self.org['id'], }) # Verify gpg key was associated product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) repo = Repository.info({'id': repo['id']}) self.assertEqual(product['gpg']['gpg-key'], gpg_key['name']) self.assertEqual(repo['gpg-key'].get('name'), gpg_key['name']) # Update the gpg key new_name = gen_choice(valid_data_list()) GPGKey.update({ 'name': gpg_key['name'], 'new-name': new_name, 'organization-id': self.org['id'], }) # Verify changes are reflected in the gpg key gpg_key = GPGKey.info({ 'id': gpg_key['id'], 'organization-id': self.org['id'], }) self.assertEqual(gpg_key['name'], new_name) # Verify changes are reflected in the product product = Product.info({ 'id': product['id'], 'organization-id': self.org['id'], }) self.assertEqual(product['gpg']['gpg-key'], new_name) # Verify changes are reflected in the repository repo = Repository.info({'id': repo['id']}) self.assertEqual(repo['gpg-key'].get('id'), gpg_key['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_synchronize_custom_product_past_sync_date(self): """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': self.org['id']}) repo = make_repository({'product-id': product['id']}) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': self.org['id'], 'sync-date': ( datetime.utcnow() - timedelta(seconds=interval - delay) ).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'], }) # Verify product has not been synced yet self.logger.info('Waiting {0} seconds to check product {1}' ' was not synced'.format(delay/4, product['name'])) sleep(delay/4) with self.assertRaises(AssertionError): self.validate_task_status(repo['id'], max_tries=2) self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait until the first recurrence self.logger.info('Waiting {0} seconds to check product {1}' ' was synced'.format(delay, product['name'])) sleep(delay * 3/4) # Re-calculate and Update with the current UTC time SyncPlan.update({ u'id': sync_plan['id'], u'sync-date': ( datetime.utcnow() - timedelta(seconds=interval - delay) ).strftime("%Y-%m-%d %H:%M:%S"), }) # Verify product was synced successfully self.validate_task_status(repo['id'], repo_name=repo['name']) self.validate_repo_content( repo, ['errata', 'package-groups', 'packages'])
def test_positive_synchronize_custom_product_weekly_recurrence(self): """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 = 5 * 60 product = make_product({'organization-id': self.org['id']}) repo = make_repository({'product-id': product['id']}) start_date = datetime.utcnow() - timedelta(weeks=1)\ + timedelta(seconds=delay) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'weekly', 'organization-id': self.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'], }) # Verify product has not been synced yet self.logger.info('Waiting {0} seconds to check product {1}' ' was not synced'.format(delay/4, product['name'])) sleep(delay/4) with self.assertRaises(AssertionError): self.validate_task_status(repo['id'], max_tries=2) self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait until the first recurrence self.logger.info('Waiting {0} seconds to check product {1}' ' was synced'.format(delay, product['name'])) sleep(delay * 3/4) # Re-calculate and Update with the current UTC time start_date = datetime.utcnow() - timedelta(weeks=1)\ + timedelta(seconds=delay) SyncPlan.update({ u'id': sync_plan['id'], u'sync-date': start_date.strftime("%Y-%m-%d %H:%M:%S"), }) # Verify product was synced successfully self.validate_task_status(repo['id'], repo_name=repo['name']) self.validate_repo_content( repo, ['errata', 'package-groups', 'packages'])
def test_positive_update_1(self, test_data): """@Test: Update the description of a product @Feature: Product @Assert: Product description is updated @BZ: 1096320 """ new_product = make_product( { 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") # Update the Descriptions result = Product.update( {u'id': new_product['id'], u'description': test_data['description']} ) # 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['description'], test_data['description'], "Description was not updated" ) self.assertNotEqual( result.stdout['description'], new_product['description'], "Descriptions should not match" )
def test_positive_update_1(self): """@Test: Update the description of a product @Feature: Product @Assert: Product description is updated """ product = make_product({u"organization-id": self.org["id"]}) for desc in valid_data_list(): with self.subTest(desc): Product.update({u"description": desc, u"id": product["id"]}) result = Product.info({u"id": product["id"], u"organization-id": self.org["id"]}) self.assertEqual(result["description"], desc)
def test_positive_delete_1(self, test_name): """@Test: Check if product can be deleted @Feature: Product @Assert: Product is deleted @BZ: 1096320 """ 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") self.assertEqual( result.stdout['name'], new_product['name'], "Names don't match") self.assertGreater( len(result.stdout['label']), 0, "Label not automatically created" ) # Delete it result = Product.delete({u'id': new_product['id']}) self.assertEqual( result.return_code, 0, "Product was not deleted") self.assertEqual( len(result.stderr), 0, "No error was expected") # Fetch it result = Product.info( {u'id': new_product['id'], u'organization-id': self.org['id']}) self.assertNotEqual( result.return_code, 0, "Product should not be found") self.assertGreater( len(result.stderr), 0, "Error was expected")
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'])