예제 #1
0
    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'])
예제 #2
0
    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)
예제 #3
0
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}
예제 #4
0
    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'])
예제 #5
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)
예제 #6
0
    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'])
예제 #7
0
    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])
        )
예제 #8
0
    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])
        )
예제 #9
0
    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)
예제 #10
0
    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,
            )
예제 #11
0
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'])
예제 #12
0
    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)
예제 #13
0
    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'])
예제 #14
0
    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'])
예제 #15
0
    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'])
예제 #16
0
    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'])
예제 #17
0
    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'])
예제 #18
0
    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'])
예제 #19
0
    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'])
예제 #20
0
    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'])
예제 #21
0
    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'])
예제 #22
0
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'])
예제 #23
0
    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"])
예제 #24
0
    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'])
예제 #25
0
    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'])
예제 #26
0
    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 = 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"),
        })
        products = [
            make_product({'organization-id': self.org['id']})
            for _ in range(randint(3, 5))
        ]
        repos = [
            make_repository({'product-id': product['id']})
            for product in products for _ in range(randint(2, 3))
        ]
        # Verify products have not been synced yet
        for repo in repos:
            self.validate_repo_content(repo, ['errata', 'packages'],
                                       after_sync=False)
        # 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
        sleep(delay / 2)
        # Verify products has not been synced yet
        for repo in repos:
            self.validate_repo_content(repo, ['errata', 'packages'],
                                       after_sync=False)
        # Wait the rest of expected time
        sleep(delay / 2)
        # Verify product was synced successfully
        for repo in repos:
            self.validate_repo_content(
                repo, ['errata', 'package-groups', 'packages'])
예제 #27
0
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'])
예제 #28
0
    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'])
예제 #29
0
    def test_positive_synchronize_custom_product_daily_recurrence(self):
        """Create a daily 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: 8d882e8b-b5c1-4449-81c6-0efd31ad75a7

        :expectedresults: Product is synchronized successfully.

        :CaseLevel: System
        """
        delay = 2 * 60
        product = make_product({'organization-id': self.org['id']})
        repo = make_repository({'product-id': product['id']})
        start_date = datetime.utcnow() - timedelta(days=1) + timedelta(
            seconds=delay)
        sync_plan = self._make_sync_plan({
            'enabled':
            'true',
            'interval':
            'daily',
            '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']
        })
        # Wait quarter of expected time
        self.logger.info('Waiting {0} seconds to check product {1}'
                         ' was not synced'.format(delay / 4, product['name']))
        sleep(delay / 4)
        # Verify product has not been synced yet
        with self.assertRaises(AssertionError):
            self.validate_task_status(repo['id'], max_tries=1)
        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 * 3 / 4),
                                              product['name']))
        sleep(delay * 3 / 4)
        # Verify product was synced successfully
        self.validate_task_status(repo['id'], repo_name=repo['name'])
        self.validate_repo_content(repo,
                                   ['errata', 'package-groups', 'packages'])
예제 #30
0
    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 = 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"),
        })
        products = [
            make_product({'organization-id': self.org['id']})
            for _ in range(randint(3, 5))
        ]
        repos = [
            make_repository({'product-id': product['id']})
            for product in products
            for _ in range(randint(2, 3))
        ]
        # Verify products have not been synced yet
        for repo in repos:
            self.validate_repo_content(
                repo, ['errata', 'packages'], after_sync=False)
        # 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
        sleep(delay/2)
        # Verify products has not been synced yet
        for repo in repos:
            self.validate_repo_content(
                repo, ['errata', 'packages'], after_sync=False)
        # Wait the rest of expected time
        sleep(delay/2)
        # Verify product was synced successfully
        for repo in repos:
            self.validate_repo_content(
                repo, ['errata', 'package-groups', 'packages'])
예제 #31
0
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'])
예제 #32
0
    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'])
예제 #33
0
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(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'])
예제 #34
0
    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'])
예제 #35
0
    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'])
예제 #36
0
    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 = 300
        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/2)
        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
        sleep(delay / 4)
        self.validate_repo_content(repo, ['errata', 'packages'],
                                   after_sync=False)
        # Wait until the first recurrence
        sleep(delay)
        # Verify product was synced successfully
        self.validate_repo_content(repo,
                                   ['errata', 'package-groups', 'packages'])
예제 #37
0
    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 = 80
        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(interval - delay / 2)).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
        sleep(delay / 4)
        self.validate_repo_content(repo, ['errata', 'packages'],
                                   after_sync=False)
        # Wait until the first recurrence
        sleep(delay)
        # Verify product was synced successfully
        self.validate_repo_content(repo,
                                   ['errata', 'package-groups', 'packages'])
예제 #38
0
    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'])
예제 #39
0
    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'])
예제 #40
0
    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.")
예제 #41
0
    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.'
        )
예제 #42
0
    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 = 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'])
예제 #43
0
    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 = 80
        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(interval - delay/2)
            ).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
        sleep(delay/4)
        self.validate_repo_content(
            repo, ['errata', 'packages'], after_sync=False)
        # Wait until the first recurrence
        sleep(delay)
        # Verify product was synced successfully
        self.validate_repo_content(
            repo, ['errata', 'package-groups', 'packages'])
예제 #44
0
    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'])
예제 #45
0
    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 = 300
        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/2)
        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
        sleep(delay/4)
        self.validate_repo_content(
            repo, ['errata', 'packages'], after_sync=False)
        # Wait until the first recurrence
        sleep(delay)
        # Verify product was synced successfully
        self.validate_repo_content(
            repo, ['errata', 'package-groups', 'packages'])
예제 #46
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)
예제 #47
0
    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)
예제 #48
0
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
    """
    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 = 210  # do not start test less than 3.5 mins before the next sync event
    products = [
        make_product({'organization-id': module_org.id}) for _ in range(2)
    ]
    repos = [
        make_repository({'product-id': product['id']}) for product in products
        for _ in range(2)
    ]
    # 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 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 fifth of expected time
    logger.info(
        f"Waiting {(delay / 5)} seconds to check products {products[0]['name']}"
        f" and {products[1]['name']} were not synced by {sync_plan['name']} ")
    sleep(delay / 5)
    # 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 * 4 / 5)} seconds to check product {products[0]['name']}"
        f" and {products[1]['name']} were synced by {sync_plan['name']}")
    sleep(delay * 4 / 5)
    # 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'])
예제 #49
0
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'])
예제 #50
0
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'])
예제 #51
0
    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 = 3 * 60
        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(seconds=interval - 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'],
        })
        # 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 the rest of expected time
        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', 'packages'])
예제 #52
0
def test_positive_synchronize_rh_product_future_sync_date(target_sat):
    """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
    """
    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 2 mins before the next sync event
    org = make_org()
    with manifests.clone() as manifest:
        target_sat.put(manifest, 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']
    })
    # 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':
        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
    with pytest.raises(AssertionError):
        validate_task_status(repo['id'], org['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 fifth of expected time
    logger.info(
        f"Waiting {(delay / 5)} seconds to check product {product['name']}"
        f" was not synced by {sync_plan['name']}")
    sleep(delay / 5)
    # Verify product has not been synced yet
    with pytest.raises(AssertionError):
        validate_task_status(repo['id'], 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 * 4 / 5)} seconds to check product {product['name']}"
        f" was synced by {sync_plan['name']}")
    sleep(delay * 4 / 5)
    # Verify product was synced successfully
    validate_task_status(repo['id'], org['id'])
    validate_repo_content(repo, ['errata', 'packages'])