Beispiel #1
0
    def setUp(self):
        super(CloneHandlingTests, self).setUp()

        # Create two repositories, a parent and a child
        v1_parent_repo = {'id' : 'parent',
                          'clone_ids' : ['child'],
                          'relative_path' : 'parent',
                          'content_types' : ['yum'],
                          'last_sync' : None,
                          'feed_ca' : None,
                          'feed_cert' : None,
                          'source' : {'url' : 'parent-feed'}}
        v1_child_repo = {'id' : 'child',
                         'clone_ids' : [],
                         'relative_path' : 'child-feed',
                         'content_types' : ['yum'],
                         'last_sync' : None,
                         'feed_ca' : None,
                         'feed_cert' : None,
                         'source' : {'url' : 'child-feed'}}

        self.v1_test_db.database.repos.insert(v1_parent_repo, safe=True)
        self.v1_test_db.database.repos.insert(v1_child_repo, safe=True)

        # This step runs after the yum repos step in the main script, so simulate that here
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
Beispiel #2
0
    def test_repos_idempotency(self):
        # Setup
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Test
        report = yum_repos.upgrade(self.v1_test_db.database,
                                   self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        v1_repos = self.v1_test_db.database.repos.find(
            {'content_types': yum_repos.V1_YUM_REPO})
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            v2_repo = self.tmp_test_db.database.repos.find_one({'id': repo_id})
            self.assertTrue(v2_repo is not None)

            v2_importer = self.tmp_test_db.database.repo_importers.find_one(
                {'repo_id': repo_id})
            self.assertTrue(v2_importer is not None)

            v2_distributor = self.tmp_test_db.database.repo_distributors.find_one(
                {'repo_id': repo_id})
            self.assertTrue(v2_distributor is not None)
Beispiel #3
0
    def setUp(self):
        super(WorkingDirUpgradeTests, self).setUp()

        # This script occurs after the DB is upgraded, so simulate the
        # necessary preconditions
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        iso_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        all_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        self.tmp_dir = tempfile.mkdtemp(prefix='working-dir-unit-test')
        repos.WORKING_DIR_ROOT = self.tmp_dir
Beispiel #4
0
    def setUp(self):
        super(WorkingDirUpgradeTests, self).setUp()

        # This script occurs after the DB is upgraded, so simulate the
        # necessary preconditions
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        iso_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        all_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        self.tmp_dir = tempfile.mkdtemp(prefix='working-dir-unit-test')
        repos.WORKING_DIR_ROOT = self.tmp_dir
Beispiel #5
0
    def test_upgrade(self):
        if not self.ENABLED:
            return

        # Test
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        v2_repo_importers = self.tmp_test_db.database.repo_importers.find()
        for v2_repo_importer in v2_repo_importers:
            self.assertEqual(self.ca_cert_contents, v2_repo_importer['config']['ssl_ca_cert'])
            self.assertEqual(self.client_cert_contents, v2_repo_importer['config']['ssl_client_cert'])
Beispiel #6
0
    def setUp(self):
        super(NoFeedCertificateTests, self).setUp()

        # This script occurs after the DB is upgraded, so simulate the
        # necessary preconditions
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        iso_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        all_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # This script also relies on the working directories to be created
        self.tmp_dir = tempfile.mkdtemp(prefix='no-feeds-fs-unit-test')
        repos.WORKING_DIR_ROOT = self.tmp_dir
        repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
Beispiel #7
0
    def test_upgrade(self):
        if not self.ENABLED:
            return

        # Test
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        v2_repo_importers = self.tmp_test_db.database.repo_importers.find()
        for v2_repo_importer in v2_repo_importers:
            self.assertEqual(self.ca_cert_contents,
                             v2_repo_importer['config']['ssl_ca_cert'])
            self.assertEqual(self.client_cert_contents,
                             v2_repo_importer['config']['ssl_client_cert'])
Beispiel #8
0
    def test_upgrade(self):
        if not self.ENABLED:
            return

        # Test
        report = yum_repos.upgrade(self.v1_test_db.database,
                                   self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        gpg_key_filename = os.path.join(DATA_DIR, 'gpg_keys', 'repo-1',
                                        'gpg.key')
        f = open(gpg_key_filename, 'r')
        contents = f.read()
        f.close()

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        v1_repos = self.v1_test_db.database.repos.find(
            {'content_types': yum_repos.V1_YUM_REPO})
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            v2_distributor = self.tmp_test_db.database.repo_distributors.find_one(
                {'repo_id': repo_id})
            config = v2_distributor['config']
            self.assertEqual(config['gpgkey'], contents)
Beispiel #9
0
    def test_upgrade(self):
        # Test
        report = yum_repos.upgrade(self.v1_test_db.database,
                                   self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        v1_repos = self.v1_test_db.database.repos.find(
            {'content_types': 'yum'})

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            v2_importer = self.tmp_test_db.database.repo_importers.find_one(
                {'repo_id': repo_id})
            self.assertTrue(v2_importer is not None,
                            msg='Missing importer for repo: %s' % repo_id)
            config = v2_importer['config']

            # Values taken from the with-proxy.conf file
            self.assertEqual(config['proxy_url'], 'http://localhost')
            self.assertEqual(config['proxy_port'], '8080')
            self.assertEqual(config['proxy_user'], 'admin')
            self.assertEqual(config['proxy_pass'], 'admin')
Beispiel #10
0
    def test_repos(self):
        # Test
        report = yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        v1_repos = self.v1_test_db.database.repos.find({'content_types' : yum_repos.V1_YUM_REPO})
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            # Repo
            v2_repo = self.tmp_test_db.database.repos.find_one({'id' : repo_id})
            self.assertTrue(v2_repo is not None)
            self.assertTrue(isinstance(v2_repo['_id'], ObjectId))
            self.assertEqual(v2_repo['id'], v1_repo['id'])
            self.assertEqual(v2_repo['display_name'], v1_repo['name'])
            self.assertEqual(v2_repo['description'], None)
            self.assertEqual(v2_repo['scratchpad'], {})
            self.assertEqual(v2_repo['content_unit_count'], 0)
            notes = v2_repo['notes']
            self.assertTrue(notes is not None)
            self.assertEqual(notes[yum_repos.REPO_NOTE_KEY], yum_repos.REPO_NOTE_RPM)

            # Importer
            v2_importer = self.tmp_test_db.database.repo_importers.find_one({'repo_id' : repo_id})
            self.assertTrue(v2_importer is not None)
            self.assertTrue(isinstance(v2_importer['_id'], ObjectId))
            self.assertEqual(v2_importer['id'], yum_repos.YUM_IMPORTER_ID)
            self.assertEqual(v2_importer['importer_type_id'], yum_repos.YUM_IMPORTER_TYPE_ID)
            self.assertEqual(v2_importer['last_sync'], v1_repo['last_sync'])

            config = v2_importer['config']
            self.assertEqual(config['feed_url'], v1_repo['source']['url'])
            self.assertEqual(config['ssl_ca_cert'], v1_repo['feed_ca'])
            self.assertEqual(config['ssl_client_cert'], v1_repo['feed_cert'])
            self.assertTrue('skip' not in config)
            self.assertTrue('proxy_url' not in config)
            self.assertTrue('proxy_port' not in config)
            self.assertTrue('proxy_user' not in config)
            self.assertTrue('proxy_pass' not in config)

            # Distributor
            v2_distributor = self.tmp_test_db.database.repo_distributors.find_one({'repo_id' : repo_id})
            self.assertTrue(v2_distributor is not None)
            self.assertTrue(isinstance(v2_distributor['_id'], ObjectId))
            self.assertEqual(v2_distributor['id'], yum_repos.YUM_DISTRIBUTOR_ID)
            self.assertEqual(v2_distributor['distributor_type_id'], yum_repos.YUM_DISTRIBUTOR_TYPE_ID)
            self.assertEqual(v2_distributor['auto_publish'], True)
            self.assertEqual(v2_distributor['scratchpad'], None)
            self.assertEqual(v2_distributor['last_publish'], v1_repo['last_sync'])

            config = v2_distributor['config']
            self.assertEqual(config['relative_url'], v1_repo['relative_path'])
            self.assertEqual(config['http'], False)
            self.assertEqual(config['https'], True)
            self.assertTrue('https_ca' not in config)
            self.assertTrue('gpgkey' not in config)
Beispiel #11
0
    def test_repos_failed_distributor_step(self, mock_distributor_call):
        # Setup
        mock_distributor_call.return_value = False

        # Test
        report = yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(not report.success)
Beispiel #12
0
    def test_repos_failed_distributor_step(self, mock_distributor_call):
        # Setup
        mock_distributor_call.return_value = False

        # Test
        report = yum_repos.upgrade(self.v1_test_db.database,
                                   self.tmp_test_db.database)

        # Verify
        self.assertTrue(not report.success)
Beispiel #13
0
    def test_upgrade(self):
        # Setup
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        iso_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        units.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Test
        report = unit_count.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        ass_coll = self.tmp_test_db.database.repo_content_units
        v2_repos = self.tmp_test_db.database.repos.find()
        for v2_repo in v2_repos:
            expected = ass_coll.find({'repo_id' : v2_repo['id']}).count()
            found = v2_repo['content_unit_count']

            self.assertEqual(expected, found,
                             msg='Repository [%s] Found [%s] Expected [%s]' %
                             (v2_repo['id'], found, expected))
Beispiel #14
0
    def setUp(self):
        super(FeedCertificateTests, self).setUp()

        # Munge each repo to point to a sample cert and CA
        ca_cert_path = os.path.join(DATA_DIR, 'repo_related_files', 'feed_ca.crt')
        client_cert_path = os.path.join(DATA_DIR, 'repo_related_files', 'feed_cert.crt')

        v1_repos = self.v1_test_db.database.repos.find()
        for v1_repo in v1_repos:
            v1_repo['feed_ca'] = ca_cert_path
            v1_repo['feed_cert'] = client_cert_path
            self.v1_test_db.database.repos.save(v1_repo)

        # This script occurs after the DB is upgraded, so simulate the
        # necessary preconditions
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        iso_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        all_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # This script also relies on the working directories to be created
        self.tmp_dir = tempfile.mkdtemp(prefix='feeds-fs-unit-test')
        repos.WORKING_DIR_ROOT = self.tmp_dir
        repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
Beispiel #15
0
    def test_repos_idempotency(self):
        # Setup
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Test
        report = yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        v1_repos = self.v1_test_db.database.repos.find({'content_types' : yum_repos.V1_YUM_REPO})
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            v2_repo = self.tmp_test_db.database.repos.find_one({'id' : repo_id})
            self.assertTrue(v2_repo is not None)

            v2_importer = self.tmp_test_db.database.repo_importers.find_one({'repo_id' : repo_id})
            self.assertTrue(v2_importer is not None)

            v2_distributor = self.tmp_test_db.database.repo_distributors.find_one({'repo_id' : repo_id})
            self.assertTrue(v2_distributor is not None)
Beispiel #16
0
    def test_upgrade(self):
        # Setup
        yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        iso_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)
        units.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Test
        report = unit_count.upgrade(self.v1_test_db.database,
                                    self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        ass_coll = self.tmp_test_db.database.repo_content_units
        v2_repos = self.tmp_test_db.database.repos.find()
        for v2_repo in v2_repos:
            expected = ass_coll.find({'repo_id': v2_repo['id']}).count()
            found = v2_repo['content_unit_count']

            self.assertEqual(expected,
                             found,
                             msg='Repository [%s] Found [%s] Expected [%s]' %
                             (v2_repo['id'], found, expected))
Beispiel #17
0
    def test_upgrade(self):
        # Test
        report = yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        f = open(self.test_cert, 'r')
        contents = f.read()
        f.close()

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        v1_repos = self.v1_test_db.database.repos.find({'content_types' : yum_repos.V1_YUM_REPO})
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            v2_distributor = self.tmp_test_db.database.repo_distributors.find_one({'repo_id' : repo_id})
            config = v2_distributor['config']
            self.assertEqual(contents, config['https_ca'])
Beispiel #18
0
    def test_upgrade(self):
        # Test
        report = yum_repos.upgrade(self.v1_test_db.database,
                                   self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        f = open(self.test_cert, 'r')
        contents = f.read()
        f.close()

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        v1_repos = self.v1_test_db.database.repos.find(
            {'content_types': yum_repos.V1_YUM_REPO})
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            v2_distributor = self.tmp_test_db.database.repo_distributors.find_one(
                {'repo_id': repo_id})
            config = v2_distributor['config']
            self.assertEqual(contents, config['https_ca'])
Beispiel #19
0
    def test_upgrade(self):
        # Test
        report = yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        v1_repos = self.v1_test_db.database.repos.find({'content_types' : 'yum'})

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            v2_importer = self.tmp_test_db.database.repo_importers.find_one({'repo_id' : repo_id})
            self.assertTrue(v2_importer is not None, msg='Missing importer for repo: %s' % repo_id)
            config = v2_importer['config']

            # Values taken from the with-proxy.conf file
            self.assertEqual(config['proxy_url'], 'http://localhost')
            self.assertEqual(config['proxy_port'], '8080')
            self.assertEqual(config['proxy_user'], 'admin')
            self.assertEqual(config['proxy_pass'], 'admin')
Beispiel #20
0
    def test_upgrade(self):
        if not self.ENABLED:
            return

        # Test
        report = yum_repos.upgrade(self.v1_test_db.database, self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        gpg_key_filename = os.path.join(DATA_DIR, 'gpg_keys', 'repo-1', 'gpg.key')
        f = open(gpg_key_filename, 'r')
        contents = f.read()
        f.close()

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        v1_repos = self.v1_test_db.database.repos.find({'content_types' : yum_repos.V1_YUM_REPO})
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            v2_distributor = self.tmp_test_db.database.repo_distributors.find_one({'repo_id' : repo_id})
            config = v2_distributor['config']
            self.assertEqual(config['gpgkey'], contents)
Beispiel #21
0
    def test_repos(self):
        # Test
        report = yum_repos.upgrade(self.v1_test_db.database,
                                   self.tmp_test_db.database)

        # Verify
        self.assertTrue(isinstance(report, UpgradeStepReport))
        self.assertTrue(report.success)

        self.assertTrue(self.v1_test_db.database.repos.count() > 0)
        v1_repos = self.v1_test_db.database.repos.find(
            {'content_types': yum_repos.V1_YUM_REPO})
        for v1_repo in v1_repos:
            repo_id = v1_repo['id']

            # Repo
            v2_repo = self.tmp_test_db.database.repos.find_one({'id': repo_id})
            self.assertTrue(v2_repo is not None)
            self.assertTrue(isinstance(v2_repo['_id'], ObjectId))
            self.assertEqual(v2_repo['id'], v1_repo['id'])
            self.assertEqual(v2_repo['display_name'], v1_repo['name'])
            self.assertEqual(v2_repo['description'], None)
            self.assertEqual(v2_repo['scratchpad'], {})
            self.assertEqual(v2_repo['content_unit_count'], 0)
            notes = v2_repo['notes']
            self.assertTrue(notes is not None)
            self.assertEqual(notes[yum_repos.REPO_NOTE_KEY],
                             yum_repos.REPO_NOTE_RPM)

            # Importer
            v2_importer = self.tmp_test_db.database.repo_importers.find_one(
                {'repo_id': repo_id})
            self.assertTrue(v2_importer is not None)
            self.assertTrue(isinstance(v2_importer['_id'], ObjectId))
            self.assertEqual(v2_importer['id'], yum_repos.YUM_IMPORTER_ID)
            self.assertEqual(v2_importer['importer_type_id'],
                             yum_repos.YUM_IMPORTER_TYPE_ID)
            self.assertEqual(v2_importer['last_sync'], v1_repo['last_sync'])

            config = v2_importer['config']
            self.assertEqual(config['feed_url'], v1_repo['source']['url'])
            self.assertTrue('skip' not in config)
            self.assertTrue('proxy_url' not in config)
            self.assertTrue('proxy_port' not in config)
            self.assertTrue('proxy_user' not in config)
            self.assertTrue('proxy_pass' not in config)

            # Distributor
            v2_distributor = self.tmp_test_db.database.repo_distributors.find_one(
                {'repo_id': repo_id})
            self.assertTrue(v2_distributor is not None)
            self.assertTrue(isinstance(v2_distributor['_id'], ObjectId))
            self.assertEqual(v2_distributor['id'],
                             yum_repos.YUM_DISTRIBUTOR_ID)
            self.assertEqual(v2_distributor['distributor_type_id'],
                             yum_repos.YUM_DISTRIBUTOR_TYPE_ID)
            self.assertEqual(v2_distributor['auto_publish'], True)
            self.assertEqual(v2_distributor['scratchpad'], None)
            self.assertEqual(v2_distributor['last_publish'],
                             v1_repo['last_sync'])

            config = v2_distributor['config']
            self.assertEqual(config['relative_url'], v1_repo['relative_path'])
            self.assertEqual(config['http'], False)
            self.assertEqual(config['https'], True)
            self.assertTrue('https_ca' not in config)
            self.assertTrue('gpgkey' not in config)