コード例 #1
0
ファイル: repolib.py プロジェクト: asmacdo/pulp_rpm
def _handle_host_urls(repo, url_list, mirror_list_filename):
    """
    Handles the processing of the host URLs sent for a repo. If a mirror list file is
    needed, it will be created and saved to disk as part of this call. The repo
    object will be updated with the appropriate parameter for the repo URL.
    """

    if len(url_list) > 1:

        # The mirror list file isn't loaded; if this call was made as part of a
        # repo update the file should be written new given the URLs passed in
        mirror_list_file = MirrorListFile(mirror_list_filename)
        mirror_list_file.add_entries(url_list)
        mirror_list_file.save()

        repo['mirrorlist'] = 'file:' + mirror_list_filename
        repo['baseurl'] = None # make sure to zero this out in case of an update

        log.info('Created mirrorlist for repo [%s] at [%s]' % (repo.id, mirror_list_filename))
    else:

        # On a repo update, the mirror list may have existed but is no longer used.
        # If we're in this block there shouldn't be a mirror list file for the repo,
        # so delete it if it's there.
        if os.path.exists(mirror_list_filename):
            os.remove(mirror_list_filename)

        repo['baseurl'] = url_list[0]
        repo['mirrorlist'] = None # make sure to zero this out in case of an update

        log.info('Configuring repo [%s] to use baseurl [%s]' % (decode_unicode(repo.id), url_list[0]))
コード例 #2
0
ファイル: test_repolib.py プロジェクト: beav/pulp_rpm
    def test_bind_multiple_url(self):
        """
        Tests that binding with a list of URLs will produce a mirror list and the
        correct mirrorlist entry in the repo entry.
        """

        # Test
        url_list = ['http://pulpserver', 'http://otherserver']
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR, REPO_ID, REPO_NAME, url_list, {}, None, None, ENABLED, LOCK)

        # Verify
        self.assertTrue(os.path.exists(TEST_REPO_FILENAME))
        self.assertTrue(os.path.exists(TEST_MIRROR_LIST_FILENAME))

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue('baseurl' not in loaded)
        self.assertEqual(loaded['mirrorlist'], 'file:' + TEST_MIRROR_LIST_FILENAME)

        mirror_list_file = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        mirror_list_file.load()

        self.assertEqual(mirror_list_file.entries[0], 'http://pulpserver')
        self.assertEqual(mirror_list_file.entries[1], 'http://otherserver')
コード例 #3
0
ファイル: test_repo_file.py プロジェクト: ulif/pulp_rpm
    def test_multiple_entries_save_load(self):
        """
        Tests creating a new mirror list file with multiple entries, saving it, and then
        loading it back from disk.
        """

        # Test Save
        mirror_list = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        mirror_list.add_entry('http://cds-01')
        mirror_list.add_entry('http://cds-02')

        mirror_list.save()

        # Verify Save
        self.assertTrue(os.path.exists(TEST_MIRROR_LIST_FILENAME))

        # Test Load
        loaded = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        loaded.load()

        # Verify Load
        self.assertEqual(2, len(loaded.entries))

        # Make sure the entries are returned in the correct order
        self.assertEqual('http://cds-01', loaded.entries[0])
        self.assertEqual('http://cds-02', loaded.entries[1])
コード例 #4
0
ファイル: test_repo_file.py プロジェクト: asmacdo/pulp_rpm
    def test_delete_file_doesnt_exist(self):
        """
        Tests that deleting when the file doesn't exist does *not* throw an error.
        """

        # Setup
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))

        # Test
        mirror_list = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        mirror_list.delete()
コード例 #5
0
ファイル: test_repo_file.py プロジェクト: ulif/pulp_rpm
    def test_delete_file_doesnt_exist(self):
        """
        Tests that deleting when the file doesn't exist does *not* throw an error.
        """

        # Setup
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))

        # Test
        mirror_list = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        mirror_list.delete()
コード例 #6
0
ファイル: test_repo_file.py プロジェクト: asmacdo/pulp_rpm
    def test_multiple_entries_save_load(self):
        """
        Tests creating a new mirror list file with multiple entries, saving it, and then
        loading it back from disk.
        """

        # Test Save
        mirror_list = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        mirror_list.add_entry('http://cds-01')
        mirror_list.add_entry('http://cds-02')

        mirror_list.save()

        # Verify Save
        self.assertTrue(os.path.exists(TEST_MIRROR_LIST_FILENAME))

        # Test Load
        loaded = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        loaded.load()

        # Verify Load
        self.assertEqual(2, len(loaded.entries))

        #   Make sure the entries are returned in the correct order
        self.assertEqual('http://cds-01', loaded.entries[0])
        self.assertEqual('http://cds-02', loaded.entries[1])
コード例 #7
0
ファイル: test_repo_file.py プロジェクト: asmacdo/pulp_rpm
    def test_add_entries(self):
        """
        Tests the ability to add a list of entries in a single operation.
        """

        # Setup
        mirror_list = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        mirror_list.add_entry('http://cds-01')

        add_us = ['http://cds-02', 'http://cds-03']

        # Test
        mirror_list.add_entries(add_us)

        # Verify
        self.assertEqual(3, len(mirror_list.entries))
コード例 #8
0
ファイル: test_repo_file.py プロジェクト: ulif/pulp_rpm
    def test_broken_load(self):
        """
        Tests that an exception is raised when the file cannot be loaded because it is not
        found.
        """

        # Test
        mirror_list = MirrorListFile('/a/b/c/d')

        self.assertRaises(IOError, mirror_list.load)
コード例 #9
0
ファイル: test_repo_file.py プロジェクト: ulif/pulp_rpm
    def test_broken_save(self):
        """
        Tests that an exception is raised when the file cannot be saved.
        """

        # Test

        # MirrorListFile will not create these directories so it should fail if this structure
        # does not exist.
        mirror_list = MirrorListFile('/a/b/c/d')

        self.assertRaises(IOError, mirror_list.save)
コード例 #10
0
ファイル: repolib.py プロジェクト: ulif/pulp_rpm
def _handle_host_urls(repo, url_list, mirror_list_filename):
    """
    Handles the processing of the host URLs sent for a repo. If a mirror list file is
    needed, it will be created and saved to disk as part of this call. The repo
    object will be updated with the appropriate parameter for the repo URL.
    """

    if len(url_list) > 1:

        # The mirror list file isn't loaded; if this call was made as part of a
        # repo update the file should be written new given the URLs passed in
        mirror_list_file = MirrorListFile(mirror_list_filename)
        mirror_list_file.add_entries(url_list)
        mirror_list_file.save()

        repo['mirrorlist'] = 'file:' + mirror_list_filename
        repo['baseurl'] = None  # make sure to zero this out in case of an update

        log.info('Created mirrorlist for repo [%s] at [%s]' % (repo.id, mirror_list_filename))
    else:

        # On a repo update, the mirror list may have existed but is no longer used.
        # If we're in this block there shouldn't be a mirror list file for the repo,
        # so delete it if it's there.
        if os.path.exists(mirror_list_filename):
            os.remove(mirror_list_filename)

        repo['baseurl'] = url_list[0]
        repo['mirrorlist'] = None  # make sure to zero this out in case of an update

        log.info(
            'Configuring repo [%s] to use baseurl [%s]' % (decode_unicode(repo.id), url_list[0]))
コード例 #11
0
    def test_bind_multiple_url(self):
        """
        Tests that binding with a list of URLs will produce a mirror list and the
        correct mirrorlist entry in the repo entry.
        """
        url_list = ['http://pulpserver', 'http://otherserver']

        repolib.bind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                     self.TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, url_list, {}, None, ENABLED, self.LOCK)

        self.assertTrue(os.path.exists(self.TEST_REPO_FILENAME))
        self.assertTrue(os.path.exists(self.TEST_MIRROR_LIST_FILENAME))
        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue('baseurl' not in loaded)
        self.assertEqual(loaded['mirrorlist'], 'file:' + self.TEST_MIRROR_LIST_FILENAME)
        mirror_list_file = MirrorListFile(self.TEST_MIRROR_LIST_FILENAME)
        mirror_list_file.load()
        self.assertEqual(mirror_list_file.entries[0], 'http://pulpserver')
        self.assertEqual(mirror_list_file.entries[1], 'http://otherserver')
コード例 #12
0
ファイル: test_repo_file.py プロジェクト: ulif/pulp_rpm
    def test_add_entries(self):
        """
        Tests the ability to add a list of entries in a single operation.
        """

        # Setup
        mirror_list = MirrorListFile(TEST_MIRROR_LIST_FILENAME)
        mirror_list.add_entry('http://cds-01')

        add_us = ['http://cds-02', 'http://cds-03']

        # Test
        mirror_list.add_entries(add_us)

        # Verify
        self.assertEqual(3, len(mirror_list.entries))