Exemplo n.º 1
0
    def test_get_repositories(self):
        """ Test the get_repositories function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(
            results[0].name, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results[0].arch.name, 'x86_64')

        self.assertEqual(
            results[1].name, 'pub/fedora/linux/updates/testing/20/x86_64')
        self.assertEqual(results[1].arch.name, 'x86_64')

        self.assertEqual(
            results[2].name, 'pub/fedora/linux/updates/testing/21/x86_64')
        self.assertEqual(results[2].arch.name, 'x86_64')
Exemplo n.º 2
0
    def test_get_repo_by_name(self):
        """ Test the get_repo_by_name function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results, None)

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(
            results.name, 'pub/fedora/linux/updates/testing/19/x86_64')

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/20/x86_64')
        self.assertEqual(
            results.name, 'pub/fedora/linux/updates/testing/20/x86_64')

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/i386')
        self.assertEqual(results, None)
Exemplo n.º 3
0
    def test_get_repo_by_name(self):
        """ Test the get_repo_by_name function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results, None)

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results.name,
                         'pub/fedora/linux/updates/testing/19/x86_64')

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/20/x86_64')
        self.assertEqual(results.name,
                         'pub/fedora/linux/updates/testing/20/x86_64')

        results = mirrormanager2.lib.get_repo_by_name(
            self.session, 'pub/fedora/linux/updates/testing/19/i386')
        self.assertEqual(results, None)
Exemplo n.º 4
0
    def test_get_version_by_name_version(self):
        """ Test the get_version_by_name_version function of
        mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_version_by_name_version(
            self.session, 'Fedora', '21')
        self.assertEqual(results, None)

        tests.create_base_items(self.session)
        tests.create_version(self.session)

        results = mirrormanager2.lib.get_version_by_name_version(
            self.session, 'Fedora', 21)
        self.assertEqual(results.product.name, 'Fedora')
        self.assertEqual(results.name, '21')

        results = mirrormanager2.lib.get_version_by_name_version(
            self.session, 'Fedora', '21-alpha')
        self.assertEqual(results.product.name, 'Fedora')
        self.assertEqual(results.name, '21-alpha')
        self.assertEqual(results.is_test, True)

        results = mirrormanager2.lib.get_session_by_visitkey(
                self.session, 'bar')
        self.assertEqual(results, None)
Exemplo n.º 5
0
    def test_get_repo_prefix_arch(self):
        """ Test the get_repo_prefix_arch function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repo_prefix_arch(
            self.session, 'updates-testing-f20', 'x86_64')
        self.assertEqual(results, None)

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repo_prefix_arch(
            self.session, 'updates-testing-f26', 'x86_64')
        self.assertEqual(results.name,
                         'pub/fedora/linux/updates/testing/26/x86_64')

        results = mirrormanager2.lib.get_repo_prefix_arch(
            self.session, 'updates-testing-f27', 'x86_64')
        self.assertEqual(results.name,
                         'pub/fedora/linux/updates/testing/27/x86_64')

        results = mirrormanager2.lib.get_repo_prefix_arch(
            self.session, 'updates-testing-f20', 'i386')
        self.assertEqual(results, None)
Exemplo n.º 6
0
    def setUp(self):
        """ Set up the environnment, ran before every test. """
        super(FlaskUiAdminTest, self).setUp()

        mirrormanager2.app.APP.config['TESTING'] = True
        mirrormanager2.app.SESSION = self.session
        mirrormanager2.app.ADMIN.SESSION = self.session
        mirrormanager2.app.APP.SESSION = self.session
        mirrormanager2.admin.SESSION = self.session
        mirrormanager2.admin.ADMIN.SESSION = self.session
        mirrormanager2.admin.APP.SESSION = self.session
        for view in mirrormanager2.admin.VIEWS:
            view.session = self.session
        self.app = mirrormanager2.app.APP.test_client()

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_site(self.session)
        tests.create_site_admin(self.session)
        tests.create_hosts(self.session)
        tests.create_location(self.session)
        tests.create_netblockcountry(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_hostcategory(self.session)
        tests.create_hostcategoryurl(self.session)
        tests.create_hostcategorydir(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)
        tests.create_repository(self.session)
        tests.create_repositoryredirect(self.session)
Exemplo n.º 7
0
    def setUp(self):
        """ Set up the environnment, ran before every test. """
        super(FlaskUiAdminTest, self).setUp()

        mirrormanager2.app.APP.config['TESTING'] = True
        mirrormanager2.app.SESSION = self.session
        mirrormanager2.app.ADMIN.SESSION = self.session
        mirrormanager2.app.APP.SESSION = self.session
        mirrormanager2.admin.SESSION = self.session
        mirrormanager2.admin.ADMIN.SESSION = self.session
        mirrormanager2.admin.APP.SESSION = self.session
        for view in mirrormanager2.admin.VIEWS:
            view.session = self.session
        self.app = mirrormanager2.app.APP.test_client()

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_site(self.session)
        tests.create_site_admin(self.session)
        tests.create_hosts(self.session)
        tests.create_location(self.session)
        tests.create_netblockcountry(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_hostcategory(self.session)
        tests.create_hostcategoryurl(self.session)
        tests.create_hostcategorydir(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)
        tests.create_repository(self.session)
        tests.create_repositoryredirect(self.session)
Exemplo n.º 8
0
    def test_get_version_by_name_version(self):
        """ Test the get_version_by_name_version function of
        mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_version_by_name_version(
            self.session, 'Fedora', '21')
        self.assertEqual(results, None)

        tests.create_base_items(self.session)
        tests.create_version(self.session)

        results = mirrormanager2.lib.get_version_by_name_version(
            self.session, 'Fedora', 21)
        self.assertEqual(results.product.name, 'Fedora')
        self.assertEqual(results.name, '21')

        results = mirrormanager2.lib.get_version_by_name_version(
            self.session, 'Fedora', '21-alpha')
        self.assertEqual(results.product.name, 'Fedora')
        self.assertEqual(results.name, '21-alpha')
        self.assertEqual(results.is_test, True)

        results = mirrormanager2.lib.get_session_by_visitkey(
            self.session, 'bar')
        self.assertEqual(results, None)
Exemplo n.º 9
0
    def test_get_repositories(self):
        """ Test the get_repositories function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name,
                         'pub/fedora/linux/updates/testing/19/x86_64')
        self.assertEqual(results[0].arch.name, 'x86_64')

        self.assertEqual(results[1].name,
                         'pub/fedora/linux/updates/testing/20/x86_64')
        self.assertEqual(results[1].arch.name, 'x86_64')

        self.assertEqual(results[2].name,
                         'pub/fedora/linux/updates/testing/21/x86_64')
        self.assertEqual(results[2].arch.name, 'x86_64')
Exemplo n.º 10
0
    def test_version_repr(self):
        """ Test the Version.__repr__ object of mirrormanager2.lib.model.
        """
        tests.create_base_items(self.session)
        tests.create_version(self.session)

        item = model.Version.get(self.session, 1)
        self.assertEqual(str(item), '<Version(1 - 26)>')
        item = model.Version.get(self.session, 2)
        self.assertEqual(str(item), '<Version(2 - 27-alpha)>')
    def test_version_repr(self):
        """ Test the Version.__repr__ object of mirrormanager2.lib.model.
        """
        tests.create_base_items(self.session)
        tests.create_version(self.session)

        item = model.Version.get(self.session, 1)
        self.assertEqual(str(item), '<Version(1 - 20)>')
        item = model.Version.get(self.session, 2)
        self.assertEqual(str(item), '<Version(2 - 21-alpha)>')
Exemplo n.º 12
0
    def test_version_arches(self):
        """ Test the Version.arches object of mirrormanager2.lib.model.
        """
        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        item = model.Version.get(self.session, 1)
        self.assertEqual(item.arches, set([u'x86_64']))
        item = model.Version.get(self.session, 2)
        self.assertEqual(item.arches, set([]))
        item = model.Version.get(self.session, 3)
        self.assertEqual(item.arches, set([u'x86_64']))
    def test_version_arches(self):
        """ Test the Version.arches object of mirrormanager2.lib.model.
        """
        tests.create_base_items(self.session)
        tests.create_version(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_repository(self.session)

        item = model.Version.get(self.session, 1)
        self.assertEqual(item.arches, set([u'x86_64']))
        item = model.Version.get(self.session, 2)
        self.assertEqual(item.arches, set([]))
        item = model.Version.get(self.session, 3)
        self.assertEqual(item.arches, set([u'x86_64']))
Exemplo n.º 14
0
    def test_product_displayed_versions(self):
        """ Test the Product.displayed_versions object of mirrormanager2.lib.model.
        """
        tests.create_base_items(self.session)

        item = model.Product.get(self.session, 1)
        self.assertEqual(item.displayed_versions, [])

        tests.create_version(self.session)

        item = model.Product.get(self.session, 1)
        self.assertEqual(item.displayed_versions[0].name, '7')

        item = model.Product.get(self.session, 2)
        for index, string in enumerate(['development', '27', '26', '25']):
            self.assertEqual(item.displayed_versions[index].name, string)
    def test_product_displayed_versions(self):
        """ Test the Product.displayed_versions object of mirrormanager2.lib.model.
        """
        tests.create_base_items(self.session)

        item = model.Product.get(self.session, 1)
        self.assertEqual(item.displayed_versions, [])

        tests.create_version(self.session)

        item = model.Product.get(self.session, 1)
        self.assertEqual(item.displayed_versions[0].name, '7')

        item = model.Product.get(self.session, 2)
        for index, string in enumerate(['development', '21', '20', '19']):
            self.assertEqual(item.displayed_versions[index].name, string)
Exemplo n.º 16
0
    def test_get_versions(self):
        """ Test the get_versions function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_versions(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_version(self.session)

        results = mirrormanager2.lib.get_versions(self.session)
        self.assertEqual(len(results), 6)
        self.assertEqual(results[0].product.name, 'Fedora')
        self.assertEqual(results[0].name, '20')
        self.assertEqual(results[1].product.name, 'Fedora')
        self.assertEqual(results[1].name, '21-alpha')
        self.assertEqual(results[2].product.name, 'Fedora')
        self.assertEqual(results[2].name, '21')
Exemplo n.º 17
0
    def test_get_versions(self):
        """ Test the get_versions function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_versions(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_version(self.session)

        results = mirrormanager2.lib.get_versions(self.session)
        self.assertEqual(len(results), 6)
        self.assertEqual(results[0].product.name, 'Fedora')
        self.assertEqual(results[0].name, '20')
        self.assertEqual(results[1].product.name, 'Fedora')
        self.assertEqual(results[1].name, '21-alpha')
        self.assertEqual(results[2].product.name, 'Fedora')
        self.assertEqual(results[2].name, '21')
Exemplo n.º 18
0
    def test_mdtr_no_data(self):
        """ Test the mdtr script without the appropriate data in the
        database.
        """
        command = self.command[:]

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stderr, '')
        self.assertEqual(
            stdout,
            "Category 'Fedora Linux' not found, exiting\n"
            "Available categories:\n")

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stdout, 'Version 27 not found for product Fedora\n')
        self.assertEqual(stderr, '')

        # One step further
        tests.create_version(self.session)

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stdout, '')
        self.assertEqual(stderr, '')
Exemplo n.º 19
0
    def test_mdtr_no_data(self):
        """ Test the mdtr script without the appropriate data in the
        database.
        """
        command = self.command[:]

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stderr, '')
        self.assertEqual(
            stdout, "Category 'Fedora Linux' not found, exiting\n"
            "Available categories:\n")

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stdout, 'Version 27 not found for product Fedora\n')
        self.assertEqual(stderr, '')

        # One step further
        tests.create_version(self.session)

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stdout, '')
        self.assertEqual(stderr, '')
Exemplo n.º 20
0
    def test_mdtr(self):
        """ Test the mdtr script. """
        command = self.command[:]

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)

        item = model.Directory(
            name='pub/fedora/linux/releases/26/Everything/x86_64/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/releases/26/Everything/armhfp/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora-secondary/releases/26/Everything/ppc64le/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora-secondary/releases/26/Everything/sources/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/development/27/Everything/x86_64/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/releases/27/Everything/x86_64/os',
            readable=True,
        )
        self.session.add(item)

        item = model.Repository(
            name='pub/fedora/linux/development/27/Everything/x86_64/os',
            prefix='fedora-27',
            version_id=3,
            arch_id=3,
            directory_id=14,
            category_id=1,
        )
        self.session.add(item)
        item = model.Repository(
            name='pub/fedora/linux/releases/26/Everything/x86_64/os',
            prefix=None,
            version_id=1,
            arch_id=3,
            directory_id=10,
            category_id=1,
        )
        self.session.add(item)

        item = model.Category(
            name='Fedora Secondary Arches',
            product_id=2,
            canonicalhost='http://download.fedora.redhat.com',
            topdir_id=1,
            publiclist=True)
        self.session.add(item)

        self.session.commit()

        # Check before running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 2)

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 6 more here, 9+6=15
        self.assertEqual(len(results), 15)
        self.assertEqual(results[9].name,
                         'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(results[10].name,
                         'pub/fedora/linux/releases/26/Everything/armhfp/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/26/Everything/ppc64le/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/26/Everything/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/27/Everything/x86_64/os')
        self.assertEqual(results[14].name,
                         'pub/fedora/linux/releases/27/Everything/x86_64/os')

        # Run the script

        process = subprocess.Popen(args=command[:],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout, 'pub/fedora/linux/development/27/Everything/x86_64/os '
            '=> pub/fedora/linux/releases/27/Everything/x86_64/os\n')
        self.assertEqual(stderr, '')

        # Check after running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 2)

        res = results[0]
        self.assertEqual(res.prefix, 'fedora-27')
        self.assertEqual(res.name,
                         'pub/fedora/linux/releases/27/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '27')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(res.directory.name,
                         'pub/fedora/linux/releases/27/Everything/x86_64/os')

        res = results[1]
        self.assertEqual(res.prefix, None)
        self.assertEqual(res.name,
                         'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '26')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(res.directory.name,
                         'pub/fedora/linux/releases/26/Everything/x86_64/os')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 6 more here, 9+6=15
        self.assertEqual(len(results), 15)
        self.assertEqual(results[9].name,
                         'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(results[10].name,
                         'pub/fedora/linux/releases/26/Everything/armhfp/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/26/Everything/ppc64le/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/26/Everything/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/27/Everything/x86_64/os')
        self.assertEqual(results[14].name,
                         'pub/fedora/linux/releases/27/Everything/x86_64/os')

        # Check non-existing version

        command = ('%s -c %s --version=24 '
                   '--category=' % (self.script, self.configfile)).split()
        command[-1] += 'Fedora Linux'

        process = subprocess.Popen(args=command[:],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stdout, 'Version 24 not found for product Fedora\n')
        self.assertEqual(stderr, '')

        # Check after running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 2)

        res = results[0]
        self.assertEqual(res.prefix, 'fedora-27')
        self.assertEqual(res.name,
                         'pub/fedora/linux/releases/27/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '27')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(res.directory.name,
                         'pub/fedora/linux/releases/27/Everything/x86_64/os')

        res = results[1]
        self.assertEqual(res.prefix, None)
        self.assertEqual(res.name,
                         'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '26')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(res.directory.name,
                         'pub/fedora/linux/releases/26/Everything/x86_64/os')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 6 more here, 9+6=15
        self.assertEqual(len(results), 15)
        self.assertEqual(results[9].name,
                         'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(results[10].name,
                         'pub/fedora/linux/releases/26/Everything/armhfp/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/26/Everything/ppc64le/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/26/Everything/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/27/Everything/x86_64/os')
        self.assertEqual(results[14].name,
                         'pub/fedora/linux/releases/27/Everything/x86_64/os')
Exemplo n.º 21
0
    def test_mdtr(self):
        """ Test the mdtr script. """
        command = self.command[:]

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)

        item = model.Directory(
            name='pub/fedora/linux/releases/26/Everything/x86_64/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/releases/26/Everything/armhfp/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora-secondary/releases/26/Everything/ppc64le/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora-secondary/releases/26/Everything/sources/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/development/27/Everything/x86_64/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/releases/27/Everything/x86_64/os',
            readable=True,
        )
        self.session.add(item)

        item = model.Repository(
            name='pub/fedora/linux/development/27/Everything/x86_64/os',
            prefix='fedora-27',
            version_id=3,
            arch_id=3,
            directory_id=14,
            category_id=1,
        )
        self.session.add(item)
        item = model.Repository(
            name='pub/fedora/linux/releases/26/Everything/x86_64/os',
            prefix=None,
            version_id=1,
            arch_id=3,
            directory_id=10,
            category_id=1,
        )
        self.session.add(item)

        item = model.Category(
            name='Fedora Secondary Arches',
            product_id=2,
            canonicalhost='http://download.fedora.redhat.com',
            topdir_id=1,
            publiclist=True
        )
        self.session.add(item)

        self.session.commit()

        # Check before running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 2)

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 6 more here, 9+6=15
        self.assertEqual(len(results), 15)
        self.assertEqual(
            results[9].name,
            'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(
            results[10].name,
            'pub/fedora/linux/releases/26/Everything/armhfp/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/26/Everything/ppc64le/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/26/Everything/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/27/Everything/x86_64/os')
        self.assertEqual(
            results[14].name,
            'pub/fedora/linux/releases/27/Everything/x86_64/os')

        # Run the script

        process = subprocess.Popen(
            args=command[:],
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'pub/fedora/linux/development/27/Everything/x86_64/os '
            '=> pub/fedora/linux/releases/27/Everything/x86_64/os\n'
        )
        self.assertEqual(stderr, '')

        # Check after running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 2)

        res = results[0]
        self.assertEqual(res.prefix, 'fedora-27')
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/27/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '27')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/27/Everything/x86_64/os')

        res = results[1]
        self.assertEqual(res.prefix, None)
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '26')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/26/Everything/x86_64/os')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 6 more here, 9+6=15
        self.assertEqual(len(results), 15)
        self.assertEqual(
            results[9].name,
            'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(
            results[10].name,
            'pub/fedora/linux/releases/26/Everything/armhfp/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/26/Everything/ppc64le/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/26/Everything/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/27/Everything/x86_64/os')
        self.assertEqual(
            results[14].name,
            'pub/fedora/linux/releases/27/Everything/x86_64/os')

        # Check non-existing version

        command = ('%s -c %s --version=24 '
                   '--category=' % (self.script, self.configfile)).split()
        command[-1] += 'Fedora Linux'

        process = subprocess.Popen(
            args=command[:],
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'Version 24 not found for product Fedora\n'
        )
        self.assertEqual(stderr, '')

        # Check after running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 2)

        res = results[0]
        self.assertEqual(res.prefix, 'fedora-27')
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/27/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '27')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/27/Everything/x86_64/os')

        res = results[1]
        self.assertEqual(res.prefix, None)
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '26')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/26/Everything/x86_64/os')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 6 more here, 9+6=15
        self.assertEqual(len(results), 15)
        self.assertEqual(
            results[9].name,
            'pub/fedora/linux/releases/26/Everything/x86_64/os')
        self.assertEqual(
            results[10].name,
            'pub/fedora/linux/releases/26/Everything/armhfp/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/26/Everything/ppc64le/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/26/Everything/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/27/Everything/x86_64/os')
        self.assertEqual(
            results[14].name,
            'pub/fedora/linux/releases/27/Everything/x86_64/os')
Exemplo n.º 22
0
    def test_mdtr_no_data(self):
        """ Test the mdtr script without the appropriate data in the
        database.
        """
        command = self.command[:]

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()

        self.assertEqual(stderr, '')
        self.assertEqual(
            stdout,
            "Category 'Fedora Linux' not found, exiting\n"
            "Available categories:\n")

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()

        self.assertEqual(stdout, 'Version 20 not found for product Fedora\n')
        self.assertEqual(stderr, '')

        # One step further
        tests.create_version(self.session)

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()

        self.assertEqual(stdout,
            'directory pub/fedora/linux/releases/20/Fedora/i386/os does not '
            'exist on disk, skipping creation of a repository there\n'
            'directory pub/fedora-secondary/releases/20/Fedora/ppc/os does '
            'not exist on disk, skipping creation of a repository there\n'
            'directory pub/fedora/linux/releases/20/Fedora/x86_64/os does '
            'not exist on disk, skipping creation of a repository there\n')
        self.assertEqual(stderr, '')

        process = subprocess.Popen(
            args=command[:] + ['--test'],
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()

        self.assertEqual(stdout,
            'directory pub/fedora/linux/releases/20/Fedora/i386/os exists on'
            ' disk, but not in the database yet, skipping creation of a '
            'repository there until after the next UMDL run.\n'
            'directory pub/fedora-secondary/releases/20/Fedora/ppc/os exists '
            'on disk, but not in the database yet, skipping creation of a '
            'repository there until after the next UMDL run.\n'
            'directory pub/fedora/linux/releases/20/Fedora/x86_64/os exists '
            'on disk, but not in the database yet, skipping creation of a '
            'repository there until after the next UMDL run.\n')
        self.assertEqual(stderr, '')
Exemplo n.º 23
0
    def test_mta(self):
        """ Test the mta script. """
        command = self.command[:]

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stderr, '')
        self.assertEqual(
            stdout, "No category could be found by the name: Fedora Linux\n")

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)
        tests.create_repository(self.session)

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout, 'No category could be found by the name: Fedora Archive\n')
        self.assertEqual(stderr, '')

        # One step further
        item = model.Directory(
            name='pub/archive',
            readable=True,
        )
        self.session.add(item)
        self.session.flush()
        item = model.Category(name='Fedora Archive',
                              product_id=1,
                              canonicalhost='http://archive.fedoraproject.org',
                              topdir_id=10,
                              publiclist=True)
        self.session.add(item)

        item = model.CategoryDirectory(
            directory_id=6,
            category_id=1,
        )
        self.session.add(item)
        item = model.CategoryDirectory(
            directory_id=8,
            category_id=1,
        )
        self.session.add(item)

        self.session.commit()

        # Before the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 4)
        self.assertEqual(results[0].prefix, 'updates-testing-f25')
        self.assertEqual(results[0].directory.name,
                         'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[1].prefix, 'updates-testing-f26')
        self.assertEqual(results[1].directory.name,
                         'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[2].prefix, 'updates-testing-f27')
        self.assertEqual(results[2].directory.name,
                         'pub/fedora/linux/updates/testing/27/x86_64')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 1 more here, 9+1=10
        self.assertEqual(len(results), 10)
        self.assertEqual(results[0].name, 'pub/fedora/linux')
        self.assertEqual(results[1].name, 'pub/fedora/linux/extras')
        self.assertEqual(results[2].name, 'pub/epel')
        self.assertEqual(results[3].name, 'pub/fedora/linux/releases/26')
        self.assertEqual(results[4].name, 'pub/fedora/linux/releases/27')
        self.assertEqual(
            results[5].name,
            'pub/archive/fedora/linux/releases/26/Everything/source')
        self.assertEqual(results[6].name,
                         'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[7].name,
                         'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[8].name,
                         'pub/fedora/linux/updates/testing/27/x86_64')
        self.assertEqual(results[9].name, 'pub/archive')

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout, 'trying to find pub/archive/fedora/linux/updates/testing/'
            '26/x86_64\n'
            'Unable to find a directory in [Fedora Archive] for pub/fedora/'
            'linux/updates/testing/26/x86_64\n')
        self.assertEqual(stderr, '')

        # Run the script so that it works

        item = model.Directory(
            name='pub/archive/fedora/linux/updates/testing/26/x86_64',
            readable=True,
        )
        self.session.add(item)
        self.session.commit()

        process = subprocess.Popen(args=command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout, 'trying to find pub/archive/fedora/'
            'linux/updates/testing/26/x86_64\n'
            'pub/fedora/linux/updates/testing/26/x86_64 => '
            'pub/archive/fedora/linux/updates/testing/26/x86_64\n')
        self.assertEqual(stderr, '')

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 4)
        self.assertEqual(results[0].prefix, 'updates-testing-f25')
        self.assertEqual(results[0].directory.name,
                         'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[1].prefix, 'updates-testing-f26')
        self.assertEqual(results[1].directory.name,
                         'pub/archive/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[2].prefix, 'updates-testing-f27')
        self.assertEqual(results[2].directory.name,
                         'pub/fedora/linux/updates/testing/27/x86_64')

        # After the script

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 1 more here, 9+1=10
        self.assertEqual(len(results), 11)
        self.assertEqual(results[0].name, 'pub/fedora/linux')
        self.assertEqual(results[1].name, 'pub/fedora/linux/extras')
        self.assertEqual(results[2].name, 'pub/epel')
        self.assertEqual(results[3].name, 'pub/fedora/linux/releases/26')
        self.assertEqual(results[4].name, 'pub/fedora/linux/releases/27')
        self.assertEqual(
            results[5].name,
            'pub/archive/fedora/linux/releases/26/Everything/source')
        self.assertEqual(results[6].name,
                         'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[7].name,
                         'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[8].name,
                         'pub/fedora/linux/updates/testing/27/x86_64')
        self.assertEqual(results[9].name, 'pub/archive')
        self.assertEqual(results[10].name,
                         'pub/archive/fedora/linux/updates/testing/26/x86_64')
Exemplo n.º 24
0
    def test_mdtr(self):
        """ Test the mdtr script. """
        command = self.command[:]

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)

        item = model.Directory(
            name='pub/fedora/linux/releases/20/Fedora/x86_64/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/releases/20/Fedora/i386/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora-secondary/releases/20/Fedora/ppc/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora-secondary/releases/20/Fedora/sources/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/development/21/x86_64/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/releases/21/Fedora/x86_64/os',
            readable=True,
        )
        self.session.add(item)
        item = model.Directory(
            name='pub/fedora/linux/releases/21/Everything/x86_64/os',
            readable=True,
        )
        self.session.add(item)

        item = model.Repository(
            name='pub/fedora/linux/development/21/x86_64/os',
            prefix='fedora-21',
            version_id=3,
            arch_id=3,
            directory_id=14,
            category_id=1,
        )
        self.session.add(item)
        item = model.Repository(
            name='pub/fedora/linux/releases/21/Everything/x86_64/os',
            prefix=None,
            version_id=3,
            arch_id=3,
            directory_id=16,
            category_id=1,
        )
        self.session.add(item)

        item = model.Category(
            name='Fedora Secondary Arches',
            product_id=2,
            canonicalhost='http://download.fedora.redhat.com',
            topdir_id=1,
            publiclist=True
        )
        self.session.add(item)

        self.session.commit()

        # Check before running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 2)

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 7 more here, 9+7=16
        self.assertEqual(len(results), 16)
        self.assertEqual(
            results[9].name,
            'pub/fedora/linux/releases/20/Fedora/x86_64/os')
        self.assertEqual(
            results[10].name,
            'pub/fedora/linux/releases/20/Fedora/i386/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/20/Fedora/ppc/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/20/Fedora/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/21/x86_64/os')
        self.assertEqual(
            results[14].name,
            'pub/fedora/linux/releases/21/Fedora/x86_64/os')
        self.assertEqual(
            results[15].name,
            'pub/fedora/linux/releases/21/Everything/x86_64/os')

        # Run the script

        process = subprocess.Popen(
            args=command[:] + ['--test'],
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'updating fedora-install-20 repo for arch i386\n'
            'updating fedora-install-20 repo for arch ppc\n'
            'updating fedora-install-20 repo for arch x86_64\n'
        )
        self.assertEqual(stderr, '')

        # Check after running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 5)

        res = results[0]
        self.assertEqual(res.prefix, 'fedora-21')
        self.assertEqual(
            res.name, 'pub/fedora/linux/development/21/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '21')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/development/21/x86_64/os')

        res = results[1]
        self.assertEqual(res.prefix, None)
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/21/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '21')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/21/Everything/x86_64/os')

        res = results[2]
        self.assertEqual(res.prefix, 'fedora-install-20')
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/20/Fedora/i386/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '20')
        self.assertEqual(res.arch.name, 'i386')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/20/Fedora/i386/os')

        res = results[3]
        self.assertEqual(res.prefix, 'fedora-install-20')
        self.assertEqual(
            res.name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os')
        self.assertEqual(res.category.name, 'Fedora Secondary Arches')
        self.assertEqual(res.version.name, '20')
        self.assertEqual(res.arch.name, 'ppc')
        self.assertEqual(
            res.directory.name,
            'pub/fedora-secondary/releases/20/Fedora/ppc/os')

        res = results[4]
        self.assertEqual(res.prefix, 'fedora-install-20')
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '20')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/20/Fedora/x86_64/os')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 7 more here, 9+7=16
        self.assertEqual(len(results), 16)
        self.assertEqual(
            results[9].name,
            'pub/fedora/linux/releases/20/Fedora/x86_64/os')
        self.assertEqual(
            results[10].name,
            'pub/fedora/linux/releases/20/Fedora/i386/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/20/Fedora/ppc/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/20/Fedora/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/21/x86_64/os')
        self.assertEqual(
            results[14].name,
            'pub/fedora/linux/releases/21/Fedora/x86_64/os')
        self.assertEqual(
            results[15].name,
            'pub/fedora/linux/releases/21/Everything/x86_64/os')

        # Update F21

        command = ('%s -c %s --version=21 '\
            '--category=' % (self.script, self.configfile)).split()
        command[-1] += 'Fedora Linux'

        process = subprocess.Popen(
            args=command[:] + ['--test'],
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()
        print stdout

        self.assertEqual(
            stdout,
            'pub/fedora/linux/development/21/x86_64/os => '
            'pub/fedora/linux/releases/21/Everything/x86_64/os\n'
            'directory pub/fedora/linux/releases/21/Fedora/i386/os exists '
            'on disk, but not in the database yet, skipping creation of a '
            'repository there until after the next UMDL run.\n'
            'directory pub/fedora-secondary/releases/21/Fedora/ppc/os exists '
            'on disk, but not in the database yet, skipping creation of a '
            'repository there until after the next UMDL run.\n'
            'updating fedora-install-21 repo for arch x86_64\n'
        )
        self.assertEqual(stderr, '')

        # Check after running the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 6)

        res = results[0]
        self.assertEqual(res.prefix, 'fedora-21')
        self.assertEqual(
            res.name, 'pub/fedora/linux/development/21/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '21')
        self.assertEqual(res.arch, None)
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/development/21/x86_64/os')

        res = results[1]
        self.assertEqual(res.prefix, 'fedora-21')
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/21/Everything/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '21')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/21/Everything/x86_64/os')

        res = results[2]
        self.assertEqual(res.prefix, 'fedora-install-20')
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/20/Fedora/i386/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '20')
        self.assertEqual(res.arch.name, 'i386')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/20/Fedora/i386/os')

        res = results[3]
        self.assertEqual(res.prefix, 'fedora-install-20')
        self.assertEqual(
            res.name, 'pub/fedora-secondary/releases/20/Fedora/ppc/os')
        self.assertEqual(res.category.name, 'Fedora Secondary Arches')
        self.assertEqual(res.version.name, '20')
        self.assertEqual(res.arch.name, 'ppc')
        self.assertEqual(
            res.directory.name,
            'pub/fedora-secondary/releases/20/Fedora/ppc/os')

        res = results[4]
        self.assertEqual(res.prefix, 'fedora-install-20')
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/20/Fedora/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '20')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/20/Fedora/x86_64/os')

        res = results[5]
        self.assertEqual(res.prefix, 'fedora-install-21')
        self.assertEqual(
            res.name, 'pub/fedora/linux/releases/21/Fedora/x86_64/os')
        self.assertEqual(res.category.name, 'Fedora Linux')
        self.assertEqual(res.version.name, '21')
        self.assertEqual(res.arch.name, 'x86_64')
        self.assertEqual(
            res.directory.name,
            'pub/fedora/linux/releases/21/Fedora/x86_64/os')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 7 more here, 9+7=16
        self.assertEqual(len(results), 16)
        self.assertEqual(
            results[9].name,
            'pub/fedora/linux/releases/20/Fedora/x86_64/os')
        self.assertEqual(
            results[10].name,
            'pub/fedora/linux/releases/20/Fedora/i386/os')
        self.assertEqual(
            results[11].name,
            'pub/fedora-secondary/releases/20/Fedora/ppc/os')
        self.assertEqual(
            results[12].name,
            'pub/fedora-secondary/releases/20/Fedora/sources/os')
        self.assertEqual(
            results[13].name,
            'pub/fedora/linux/development/21/x86_64/os')
        self.assertEqual(
            results[14].name,
            'pub/fedora/linux/releases/21/Fedora/x86_64/os')
        self.assertEqual(
            results[15].name,
            'pub/fedora/linux/releases/21/Everything/x86_64/os')
Exemplo n.º 25
0
    def test_mta(self):
        """ Test the mta script. """
        command = self.command[:]

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(stderr, '')
        self.assertEqual(
            stdout,
            "No category could be found by the name: Fedora Linux\n")

        # Fill the DB a little bit
        tests.create_base_items(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_version(self.session)
        tests.create_repository(self.session)

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'No category could be found by the name: Fedora Archive\n')
        self.assertEqual(stderr, '')

        # One step further
        item = model.Directory(
            name='pub/archive',
            readable=True,
        )
        self.session.add(item)
        self.session.flush()
        item = model.Category(
            name='Fedora Archive',
            product_id=1,
            canonicalhost='http://archive.fedoraproject.org',
            topdir_id=10,
            publiclist=True
        )
        self.session.add(item)

        item = model.CategoryDirectory(
            directory_id=6,
            category_id=1,
        )
        self.session.add(item)
        item = model.CategoryDirectory(
            directory_id=8,
            category_id=1,
        )
        self.session.add(item)

        self.session.commit()

        # Before the script

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].prefix, 'updates-testing-f25')
        self.assertEqual(
            results[0].directory.name,
            'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[1].prefix, 'updates-testing-f26')
        self.assertEqual(
            results[1].directory.name,
            'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[2].prefix, 'updates-testing-f27')
        self.assertEqual(
            results[2].directory.name,
            'pub/fedora/linux/updates/testing/27/x86_64')

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 1 more here, 9+1=10
        self.assertEqual(len(results), 10)
        self.assertEqual(results[0].name, 'pub/fedora/linux')
        self.assertEqual(results[1].name, 'pub/fedora/linux/extras')
        self.assertEqual(results[2].name, 'pub/epel')
        self.assertEqual(results[3].name, 'pub/fedora/linux/releases/26')
        self.assertEqual(results[4].name, 'pub/fedora/linux/releases/27')
        self.assertEqual(
            results[5].name,
            'pub/archive/fedora/linux/releases/26/Everything/source')
        self.assertEqual(
            results[6].name,
            'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(
            results[7].name,
            'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(
            results[8].name,
            'pub/fedora/linux/updates/testing/27/x86_64')
        self.assertEqual(results[9].name, 'pub/archive')

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'trying to find pub/archive/fedora/linux/updates/testing/'
            '26/x86_64\n'
            'Unable to find a directory in [Fedora Archive] for pub/fedora/'
            'linux/updates/testing/26/x86_64\n')
        self.assertEqual(stderr, '')

        # Run the script so that it works

        item = model.Directory(
            name='pub/archive/fedora/linux/updates/testing/26/x86_64',
            readable=True,
        )
        self.session.add(item)
        self.session.commit()

        process = subprocess.Popen(
            args=command,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            universal_newlines=True)
        stdout, stderr = process.communicate()

        self.assertEqual(
            stdout,
            'trying to find pub/archive/fedora/'
            'linux/updates/testing/26/x86_64\n'
            'pub/fedora/linux/updates/testing/26/x86_64 => '
            'pub/archive/fedora/linux/updates/testing/26/x86_64\n')
        self.assertEqual(stderr, '')

        results = mirrormanager2.lib.get_repositories(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].prefix, 'updates-testing-f25')
        self.assertEqual(
            results[0].directory.name,
            'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(results[1].prefix, 'updates-testing-f26')
        self.assertEqual(
            results[1].directory.name,
            'pub/archive/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(results[2].prefix, 'updates-testing-f27')
        self.assertEqual(
            results[2].directory.name,
            'pub/fedora/linux/updates/testing/27/x86_64')

        # After the script

        results = mirrormanager2.lib.get_directories(self.session)
        # create_directory creates 9 directories
        # we create 1 more here, 9+1=10
        self.assertEqual(len(results), 11)
        self.assertEqual(results[0].name, 'pub/fedora/linux')
        self.assertEqual(results[1].name, 'pub/fedora/linux/extras')
        self.assertEqual(results[2].name, 'pub/epel')
        self.assertEqual(results[3].name, 'pub/fedora/linux/releases/26')
        self.assertEqual(results[4].name, 'pub/fedora/linux/releases/27')
        self.assertEqual(
            results[5].name,
            'pub/archive/fedora/linux/releases/26/Everything/source')
        self.assertEqual(
            results[6].name,
            'pub/fedora/linux/updates/testing/25/x86_64')
        self.assertEqual(
            results[7].name,
            'pub/fedora/linux/updates/testing/26/x86_64')
        self.assertEqual(
            results[8].name,
            'pub/fedora/linux/updates/testing/27/x86_64')
        self.assertEqual(results[9].name, 'pub/archive')
        self.assertEqual(
            results[10].name,
            'pub/archive/fedora/linux/updates/testing/26/x86_64')
Exemplo n.º 26
0
    def test_get_mirrors(self):
        """ Test the get_mirrors function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_mirrors(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_site(self.session)
        tests.create_hosts(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_hostcategory(self.session)
        tests.create_hostcategoryurl(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_netblockcountry(self.session)

        results = mirrormanager2.lib.get_mirrors(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, private=True)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'private.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, internet2=True)
        self.assertEqual(len(results), 0)

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 internet2_clients=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 internet2_clients=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 asn_clients=True)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 asn_clients=False)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'private.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 admin_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 admin_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 user_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 user_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, host_category_url_private=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, host_category_url_private=False)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_crawl_duration=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_crawl_duration=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_crawled=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_crawled=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_checked_in=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 last_checked_in=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_private=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_private=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_user_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_user_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_admin_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session,
                                                 site_admin_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, up2date=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session, up2date=False)
        self.assertEqual(len(results), 0)

        results = mirrormanager2.lib.get_mirrors(self.session, version_id=1)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session, version_id=3)

        tests.create_version(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_mirrors(self.session, version_id=1)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')
        results = mirrormanager2.lib.get_mirrors(self.session, version_id=3)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, arch_id=1)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(self.session, arch_id=3)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')
Exemplo n.º 27
0
    def test_get_mirrors(self):
        """ Test the get_mirrors function of mirrormanager2.lib.
        """
        results = mirrormanager2.lib.get_mirrors(self.session)
        self.assertEqual(results, [])

        tests.create_base_items(self.session)
        tests.create_site(self.session)
        tests.create_hosts(self.session)
        tests.create_directory(self.session)
        tests.create_category(self.session)
        tests.create_hostcategory(self.session)
        tests.create_hostcategoryurl(self.session)
        tests.create_categorydirectory(self.session)
        tests.create_netblockcountry(self.session)

        results = mirrormanager2.lib.get_mirrors(self.session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, private=True)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'private.localhost')

        results = mirrormanager2.lib.get_mirrors(self.session, internet2=True)
        self.assertEqual(len(results), 0)

        results = mirrormanager2.lib.get_mirrors(
            self.session, internet2_clients=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, internet2_clients=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, asn_clients=True)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        results = mirrormanager2.lib.get_mirrors(
            self.session, asn_clients=False)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'private.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, admin_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, admin_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, user_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, user_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, host_category_url_private=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, host_category_url_private=False)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, last_crawl_duration=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, last_crawl_duration=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, last_crawled=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, last_crawled=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, last_checked_in=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, last_checked_in=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, site_private=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, site_private=False)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, site_user_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, site_user_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, site_admin_active=False)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, site_admin_active=True)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'private.localhost')
        self.assertEqual(results[2].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, up2date=True)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, up2date=False)
        self.assertEqual(len(results), 0)

        results = mirrormanager2.lib.get_mirrors(
            self.session, version_id=1)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, version_id=3)

        tests.create_version(self.session)
        tests.create_repository(self.session)

        results = mirrormanager2.lib.get_mirrors(
            self.session, version_id=1)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')
        results = mirrormanager2.lib.get_mirrors(
            self.session, version_id=3)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')

        results = mirrormanager2.lib.get_mirrors(
            self.session, arch_id=1)
        self.assertEqual(len(results), 0)
        results = mirrormanager2.lib.get_mirrors(
            self.session, arch_id=3)
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0].name, 'mirror2.localhost')
        self.assertEqual(results[1].name, 'mirror.localhost')