Example #1
0
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]))
Example #2
0
    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()
Example #3
0
    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])
Example #4
0
    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))