Example #1
0
    def test_positive_update_1(self, test_data):
        """@Test: Check if syncplan description can be updated

        @Feature: Sync Plan

        @Assert: Sync plan is created and description is updated

        """
        new_sync_plan = self._make_sync_plan()
        # Assert that description matches data passed
        self.assertNotEqual(
            new_sync_plan['description'],
            test_data['description'],
        )
        # Update sync plan
        SyncPlan.update({
            u'description': test_data['description'],
            u'id': new_sync_plan['id'],
        })
        # Fetch it
        result = SyncPlan.info({u'id': new_sync_plan['id']})
        # Assert that description matches new value
        self.assertEqual(result['description'], test_data['description'])
        # Assert that description does not matches original value
        self.assertNotEqual(
            new_sync_plan['description'],
            result['description'],
        )
Example #2
0
    def test_positive_update_2(self, test_data):
        """@Test: Check if syncplan interval be updated

        @Feature: Sync Plan

        @Assert: Sync plan interval is updated

        """
        new_sync_plan = self._make_sync_plan({
            u'interval': test_data['interval'],
            u'name': test_data['name'],
        })
        # Assert that name and interval matches data passed
        self.assertEqual(new_sync_plan['name'], test_data['name'])
        self.assertEqual(new_sync_plan['interval'], test_data['interval'])
        # Update sync interval
        SyncPlan.update({
            u'id': new_sync_plan['id'],
            u'interval': test_data['new-interval'],
        })
        # Fetch it
        result = SyncPlan.info({u'id': new_sync_plan['id']})
        # Assert that interval was updated
        self.assertEqual(result['interval'], test_data['new-interval'])
        self.assertNotEqual(new_sync_plan['interval'], result['interval'])
Example #3
0
    def test_positive_update_1(self, test_data):
        """@Test: Check if syncplan description can be updated

        @Feature: Sync Plan

        @Assert: Sync plan is created and description is updated

        """

        new_sync_plan = self._make_sync_plan()
        # Assert that description matches data passed
        self.assertNotEqual(
            new_sync_plan['description'],
            test_data['description'],
            "Descriptions don't match"
        )

        # Update sync plan
        result = SyncPlan.update(
            {
                u'id': new_sync_plan['id'],
                u'description': test_data['description']
            }
        )
        self.assertEqual(
            result.return_code,
            0,
            "Sync plan was not updated")
        self.assertEqual(
            len(result.stderr), 0, "No error was expected")

        # Fetch it
        result = SyncPlan.info(
            {
                u'id': new_sync_plan['id'],
            }
        )
        self.assertEqual(
            result.return_code,
            0,
            "Sync plan was not updated")
        self.assertEqual(
            len(result.stderr), 0, "No error was expected")
        # Assert that description matches new value
        self.assertIsNotNone(
            result.stdout.get('description', None),
            "The description field was not returned"
        )
        self.assertEqual(
            result.stdout['description'],
            test_data['description'],
            "Descriptions should match"
        )
        # Assert that description does not matches original value
        self.assertNotEqual(
            new_sync_plan['description'],
            result.stdout['description'],
            "Descriptions should not match"
        )
Example #4
0
    def test_positive_update_3(self, test_data):
        """@Test: Check if syncplan sync date can be updated

        @Feature: Sync Plan

        @Assert: Sync plan is created and sync plan is updated

        """

        # Set the sync date to today/right now
        today = datetime.now()
        new_sync_plan = self._make_sync_plan({
            u'name': test_data['name'],
            u'sync-date': today.strftime("%Y-%m-%d %H:%M:%S"),
        })
        # Assert that sync date matches data passed
        self.assertEqual(
            new_sync_plan['start-date'],
            today.strftime("%Y/%m/%d %H:%M:%S"),
        )

        # Set sync date 5 days in the future
        future_date = today + timedelta(days=5)
        # Update sync interval
        result = SyncPlan.update({
            u'id': new_sync_plan['id'],
            u'sync-date': future_date.strftime("%Y-%m-%d %H:%M:%S"),
        })
        self.assertEqual(
            result.return_code,
            0,
            "Sync plan was not updated")
        self.assertEqual(
            len(result.stderr), 0, "No error was expected")

        # Fetch it
        result = SyncPlan.info({
            u'id': new_sync_plan['id'],
        })
        self.assertEqual(
            result.return_code,
            0,
            "Sync plan was not updated")
        self.assertEqual(
            len(result.stderr), 0, "No error was expected")
        self.assertNotEqual(
            result.stdout['start-date'],
            new_sync_plan['start-date'],
            "Sync date was not updated"
        )
        self.assertGreater(
            datetime.strptime(
                result.stdout['start-date'],
                "%Y/%m/%d %H:%M:%S"),
            datetime.strptime(
                new_sync_plan['start-date'],
                "%Y/%m/%d %H:%M:%S"),
            "Sync date was not updated"
        )
Example #5
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'])
Example #6
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'])
Example #7
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'])
Example #8
0
    def test_positive_delete_by_id(self):
        """Check if syncplan can be created and deleted

        @Feature: Sync Plan

        @Assert: Sync plan is created and then deleted
        """
        for name in valid_data_list():
            with self.subTest(name):
                new_sync_plan = self._make_sync_plan({u'name': name})
                SyncPlan.delete({u'id': new_sync_plan['id']})
                with self.assertRaises(CLIReturnCodeError):
                    SyncPlan.info({'id': new_sync_plan['id']})
Example #9
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'])
Example #10
0
    def test_positive_delete_by_id(self):
        """Check if syncplan can be created and deleted

        :id: b5d97c6b-aead-422b-8d9f-4a192bbe4a3b

        :expectedresults: Sync plan is created and then deleted

        :CaseImportance: Critical
        """
        for name in valid_data_list():
            with self.subTest(name):
                new_sync_plan = self._make_sync_plan({u'name': name})
                SyncPlan.delete({u'id': new_sync_plan['id']})
                with self.assertRaises(CLIReturnCodeError):
                    SyncPlan.info({'id': new_sync_plan['id']})
Example #11
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])
        )
Example #12
0
    def test_positive_update_description(self):
        """Check if syncplan description can be updated

        @Feature: Sync Plan

        @Assert: Sync plan is created and description is updated
        """
        new_sync_plan = self._make_sync_plan()
        for new_desc in valid_data_list():
            with self.subTest(new_desc):
                SyncPlan.update({
                    u'description': new_desc,
                    u'id': new_sync_plan['id'],
                })
                result = SyncPlan.info({u'id': new_sync_plan['id']})
                self.assertEqual(result['description'], new_desc)
Example #13
0
    def test_positive_delete_1(self, test_data):
        """@Test: Check if syncplan can be created and deleted

        @Feature: Sync Plan

        @Assert: Sync plan is created and then deleted

        """
        new_sync_plan = self._make_sync_plan({u'name': test_data['name']})
        # Assert that name matches data passed
        self.assertEqual(new_sync_plan['name'], test_data['name'])
        # Delete it
        SyncPlan.delete({u'id': new_sync_plan['id']})
        # Fetch it
        with self.assertRaises(CLIReturnCodeError):
            SyncPlan.info({'id': new_sync_plan['id']})
Example #14
0
    def _make_sync_plan(self, options=None):
        """
        Make a sync plan and asserts its success
        """

        if options is None:
            options = {}

        if not options.get('organization-id', None):
            options[u'organization-id'] = self.org['id']

        new_sync_plan = make_sync_plan(options)

        # Fetch it
        result = SyncPlan.info(
            {
                u'id': new_sync_plan['id']
            }
        )

        self.assertEqual(
            result.return_code,
            0,
            "Sync plan was not found")
        self.assertEqual(
            len(result.stderr), 0, "No error was expected")

        # Return the sync plan dictionary
        return new_sync_plan
Example #15
0
    def test_positive_update_sync_date(self):
        """Check if syncplan sync date can be updated

        :id: f0c17d7d-3e86-4b64-9747-6cba6809815e

        :expectedresults: Sync plan is created and sync plan is updated

        :BZ: 1336790

        :CaseImportance: Critical
        """
        # Set the sync date to today/right now
        today = datetime.now()
        sync_plan_name = gen_string('alphanumeric')
        new_sync_plan = self._make_sync_plan({
            u'name': sync_plan_name,
            u'sync-date': today.strftime("%Y-%m-%d %H:%M:%S"),
        })
        # Assert that sync date matches data passed
        self.assertEqual(
            new_sync_plan['start-date'],
            today.strftime("%Y/%m/%d %H:%M:%S"),
        )
        # Set sync date 5 days in the future
        future_date = today + timedelta(days=5)
        # Update sync interval
        SyncPlan.update({
            u'id': new_sync_plan['id'],
            u'sync-date': future_date.strftime("%Y-%m-%d %H:%M:%S"),
        })
        # Fetch it
        result = SyncPlan.info({
            u'id': new_sync_plan['id'],
        })
        self.assertNotEqual(result['start-date'], new_sync_plan['start-date'])
        self.assertGreater(
            datetime.strptime(
                result['start-date'],
                '%Y/%m/%d %H:%M:%S',
            ),
            datetime.strptime(
                new_sync_plan['start-date'],
                '%Y/%m/%d %H:%M:%S',
            ),
            'Sync date was not updated',
        )
Example #16
0
    def test_positive_update_description(self):
        """Check if syncplan description can be updated

        :id: 00a279cd-1f49-4ebb-a59a-6f0b4e4cb83c

        :expectedresults: Sync plan is created and description is updated

        :CaseImportance: Critical
        """
        new_sync_plan = self._make_sync_plan()
        for new_desc in valid_data_list():
            with self.subTest(new_desc):
                SyncPlan.update({
                    u'description': new_desc,
                    u'id': new_sync_plan['id'],
                })
                result = SyncPlan.info({u'id': new_sync_plan['id']})
                self.assertEqual(result['description'], new_desc)
Example #17
0
    def test_positive_update_interval(self):
        """Check if syncplan interval be updated

        @Feature: Sync Plan

        @Assert: Sync plan interval is updated
        """
        for test_data in valid_name_interval_update_tests():
            with self.subTest(test_data):
                new_sync_plan = self._make_sync_plan({
                    u'interval': test_data['interval'],
                    u'name': test_data['name'],
                })
                SyncPlan.update({
                    u'id': new_sync_plan['id'],
                    u'interval': test_data['new-interval'],
                })
                result = SyncPlan.info({u'id': new_sync_plan['id']})
                self.assertEqual(result['interval'], test_data['new-interval'])
Example #18
0
    def test_positive_info_enabled_field_is_displayed(self):
        """Check if Enabled field is displayed in sync-plan info output

        @id: 54e3a4ea-315c-4026-8101-c4605ca6b874

        @Assert: Sync plan Enabled state is displayed
        """
        new_sync_plan = self._make_sync_plan()
        result = SyncPlan.info({'id': new_sync_plan['id']})
        self.assertIsNotNone(result.get('enabled'))
Example #19
0
    def test_positive_info_enabled_field_is_displayed(self):
        """Check if Enabled field is displayed in sync-plan info output

        @Feature: Sync Plan Info

        @Assert: Sync plan Enabled state is displayed
        """
        new_sync_plan = self._make_sync_plan()
        result = SyncPlan.info({'id': new_sync_plan['id']})
        self.assertIsNotNone(result.get('enabled'))
Example #20
0
    def test_positive_delete_1(self, test_data):
        """@Test: Check if syncplan can be created and deleted

        @Feature: Sync Plan

        @Assert: Sync plan is created and then deleted

        """

        new_sync_plan = self._make_sync_plan({u'name': test_data['name']})
        # Assert that name matches data passed
        self.assertEqual(
            new_sync_plan['name'],
            test_data['name'],
            "Names don't match"
        )

        # Delete it
        result = SyncPlan.delete({u'id': new_sync_plan['id']})
        self.assertEqual(
            result.return_code,
            0,
            "Sync plan was not deleted")
        self.assertEqual(
            len(result.stderr), 0, "No error was expected")

        # Fetch it
        result = SyncPlan.info(
            {
                'id': new_sync_plan['id'],
            }
        )
        self.assertNotEqual(
            result.return_code,
            0,
            "Sync plan should not be found"
        )
        self.assertGreater(
            len(result.stderr),
            0,
            "Expected an error here"
        )
Example #21
0
    def test_positive_update_3(self):
        """@Test: Check if syncplan sync date can be updated

        @Feature: Sync Plan

        @Assert: Sync plan is created and sync plan is updated
        """
        # Set the sync date to today/right now
        today = datetime.now()
        sync_plan_name = gen_string('alphanumeric')
        new_sync_plan = self._make_sync_plan({
            u'name': sync_plan_name,
            u'sync-date': today.strftime("%Y-%m-%d %H:%M:%S"),
        })
        # Assert that sync date matches data passed
        self.assertEqual(
            new_sync_plan['start-date'],
            today.strftime("%Y/%m/%d %H:%M:%S"),
        )
        # Set sync date 5 days in the future
        future_date = today + timedelta(days=5)
        # Update sync interval
        SyncPlan.update({
            u'id': new_sync_plan['id'],
            u'sync-date': future_date.strftime("%Y-%m-%d %H:%M:%S"),
        })
        # Fetch it
        result = SyncPlan.info({
            u'id': new_sync_plan['id'],
        })
        self.assertNotEqual(result['start-date'], new_sync_plan['start-date'])
        self.assertGreater(
            datetime.strptime(
                result['start-date'],
                '%Y/%m/%d %H:%M:%S',
            ),
            datetime.strptime(
                new_sync_plan['start-date'],
                '%Y/%m/%d %H:%M:%S',
            ),
            'Sync date was not updated',
        )
Example #22
0
    def test_positive_update_interval(self):
        """Check if syncplan interval be updated

        :id: d676d7f3-9f7c-4375-bb8b-277d71af94b4

        :expectedresults: Sync plan interval is updated

        :CaseImportance: Critical
        """
        for test_data in valid_name_interval_update_tests():
            with self.subTest(test_data):
                new_sync_plan = self._make_sync_plan({
                    u'interval': test_data['interval'],
                    u'name': test_data['name'],
                })
                SyncPlan.update({
                    u'id': new_sync_plan['id'],
                    u'interval': test_data['new-interval'],
                })
                result = SyncPlan.info({u'id': new_sync_plan['id']})
                self.assertEqual(result['interval'], test_data['new-interval'])
Example #23
0
    def test_bz1261122_enabled_state_visible(self):
        """@Test: Check if Enabled field is displayed in sync-plan info output

        @Feature: Sync Plan Info

        @Assert: Sync plan Enabled state is displayed

        @BZ: 1261122
        """
        new_sync_plan = self._make_sync_plan()
        result = SyncPlan.info({'id': new_sync_plan['id']})
        self.assertIsNotNone(result.get('enabled'))
Example #24
0
    def test_verify_bugzilla_1261122(self):
        """Check if Enabled field is displayed in sync-plan info output

        @Feature: Sync Plan Info

        @Assert: Sync plan Enabled state is displayed

        @BZ: 1261122
        """
        new_sync_plan = self._make_sync_plan()
        result = SyncPlan.info({'id': new_sync_plan['id']})
        self.assertIsNotNone(result.get('enabled'))
Example #25
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'])
Example #26
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 = 5 * 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
        with self.assertRaises(AssertionError):
            self.validate_task_status(repo['id'], max_tries=2)
        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', 'packages'])
Example #27
0
    def test_positive_update_2(self, test_data):
        """
        @Test: Check if syncplan interval be updated
        @Feature: Sync Plan
        @Assert: Sync plan interval is updated
        """

        new_sync_plan = self._make_sync_plan(
            {
                u'name': test_data['name'],
                u'interval': test_data['interval']
            })
        # Assert that name and interval matches data passed
        self.assertEqual(
            new_sync_plan['name'],
            test_data['name'],
            "Descriptions don't match"
        )
        self.assertEqual(
            new_sync_plan['interval'],
            test_data['interval'],
            "Intervals don't match"
        )

        # Update sync interval
        result = SyncPlan.update(
            {
                u'id': new_sync_plan['id'],
                u'interval': test_data['new-interval']
            }
        )
        self.assertEqual(
            result.return_code,
            0,
            "Sync plan was not updated")
        self.assertEqual(
            len(result.stderr), 0, "No error was expected")

        # Fetch it
        result = SyncPlan.info(
            {
                u'id': new_sync_plan['id'],
            }
        )
        self.assertEqual(
            result.return_code,
            0,
            "Sync plan was not updated")
        self.assertEqual(
            len(result.stderr), 0, "No error was expected")
        # Assert that interval was updated
        self.assertEqual(
            result.stdout['interval'],
            test_data['new-interval'],
            "Intervals don't match"
        )
        self.assertNotEqual(
            new_sync_plan['interval'],
            result.stdout['interval'],
            "Intervals don't match"
        )