Beispiel #1
0
    def test_one_repo_save_and_load(self):
        """
        Tests the normal flow of saving and loading, using only one repo to
        minimize complications.
        """

        # Setup
        add_me = Repo('test-repo-1')
        add_me['baseurl'] = 'http://localhost/repo'
        add_me['enabled'] = 1
        add_me['gpgkey'] = '/tmp/key'
        add_me['sslverify'] = 1
        add_me['gpgcheck'] = 0
        add_me['sslcacert'] = '/tmp/sslcacert'
        add_me['sslclientcert'] = '/tmp/clientcert'

        repo_file = RepoFile(TEST_REPO_FILENAME)

        # Test Save
        repo_file.add_repo(add_me)
        repo_file.save()

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

        # Test Load
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()

        # Verify Load
        self.assertEqual(1, len(loaded.all_repos()))

        found_repo = loaded.get_repo('test-repo-1')
        self.assertTrue(found_repo is not None)
        self.assertTrue(_repo_eq(add_me, found_repo))
Beispiel #2
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.
        """

        # 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')
Beispiel #3
0
 def test_clear_clientcert(self):
     # setup
     repolib.bind(
         TEST_REPO_FILENAME,
         TEST_MIRROR_LIST_FILENAME,
         TEST_KEYS_DIR,
         TEST_CERT_DIR,
         REPO_ID,
         REPO_NAME,
         ['http://pulp'],
         [],
         CLIENTCERT,
         ENABLED,
         LOCK)
     repolib.bind(
         TEST_REPO_FILENAME,
         TEST_MIRROR_LIST_FILENAME,
         TEST_KEYS_DIR,
         TEST_CERT_DIR,
         REPO_ID,
         REPO_NAME,
         ['http://pulp'],
         [],
         None,
         ENABLED,
         LOCK,
         verify_ssl=True)
     repo_file = RepoFile(TEST_REPO_FILENAME)
     repo_file.load()
     loaded = repo_file.get_repo(REPO_ID)
     certdir = os.path.join(TEST_CERT_DIR, REPO_ID)
     self.assertFalse(os.path.exists(certdir))
     self.assertTrue(loaded['sslverify'], '1')
Beispiel #4
0
    def test_bind_new_file(self):
        """
        Tests binding a repo when the underlying .repo file does not exist.
        """
        url_list = ['http://pulpserver']

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

        self.assertTrue(os.path.exists(TEST_REPO_FILENAME))
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()

        self.assertEqual(1, len(repo_file.all_repos()))

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue(loaded is not None)
        self.assertEqual(loaded['name'], REPO_NAME)
        self.assertTrue(loaded['enabled'])
        self.assertEqual(loaded['gpgcheck'], '0')
        self.assertEqual(loaded['gpgkey'], None)

        self.assertEqual(loaded['baseurl'], url_list[0])
        self.assertTrue('mirrorlist' not in loaded)

        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(CLIENTCERT, content)
        # verify_ssl defaults to True
        self.assertTrue(loaded['sslverify'], '1')
        self.assertEqual(loaded['sslcacert'], DEFAULT_CA_PATH)
Beispiel #5
0
    def test_bind_update_keys(self):
        """
        Tests changing the GPG keys on a previously bound repo.
        """
        keys = {'key1' : 'KEY1', 'key2' : 'KEY2'}
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, ['http://pulp'], keys, None, ENABLED, LOCK)
        new_keys = {'key1' : 'KEYX'}

        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                     REPO_ID, None, None, new_keys, None, ENABLED, LOCK)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()

        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['gpgcheck'], '1')
        self.assertEqual(1, len(loaded['gpgkey'].split('\n')))
        self.assertEqual(1, len(os.listdir(os.path.join(TEST_KEYS_DIR, REPO_ID))))

        key_file = open(loaded['gpgkey'].split('\n')[0][5:], 'r')
        contents = key_file.read()
        key_file.close()

        self.assertEqual(contents, 'KEYX')
Beispiel #6
0
    def test_bind_update_keys(self):
        """
        Tests changing the GPG keys on a previously bound repo.
        """
        keys = {'key1': 'KEY1', 'key2': 'KEY2'}
        repolib.bind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                     self.TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, ['http://pulp'], keys, None, ENABLED, self.LOCK)
        new_keys = {'key1': 'KEYX'}

        repolib.bind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                     self.TEST_CERT_DIR,
                     REPO_ID, None, None, new_keys, None, ENABLED, self.LOCK)

        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()

        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['gpgcheck'], '1')
        self.assertEqual(1, len(loaded['gpgkey'].split('\n')))
        self.assertEqual(1, len(os.listdir(os.path.join(self.TEST_KEYS_DIR, REPO_ID))))

        key_file = open(loaded['gpgkey'].split('\n')[0][5:], 'r')
        contents = key_file.read()
        key_file.close()

        self.assertEqual(contents, 'KEYX')
Beispiel #7
0
    def test_bind_ssl_verify_false(self):
        """
        Tests binding a repo with verify_ssl set explicitly to False.
        """
        url_list = ['http://pulpserver']

        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, url_list, {}, CLIENTCERT, ENABLED, LOCK, verify_ssl=False)

        self.assertTrue(os.path.exists(TEST_REPO_FILENAME))
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()

        self.assertEqual(1, len(repo_file.all_repos()))

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue(loaded is not None)
        self.assertEqual(loaded['name'], REPO_NAME)
        self.assertTrue(loaded['enabled'])
        self.assertEqual(loaded['gpgcheck'], '0')
        self.assertEqual(loaded['gpgkey'], None)

        self.assertEqual(loaded['baseurl'], url_list[0])
        self.assertTrue('mirrorlist' not in loaded)

        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(CLIENTCERT, content)
        self.assertTrue(loaded['sslverify'], '0')
        # No CA path should have been used
        self.assertEqual(loaded['sslcacert'], None)
Beispiel #8
0
 def test_clear_clientcert(self):
     # setup
     repolib.bind(
         self.TEST_REPO_FILENAME,
         self.TEST_MIRROR_LIST_FILENAME,
         self.TEST_KEYS_DIR,
         self.TEST_CERT_DIR,
         REPO_ID,
         REPO_NAME,
         ['http://pulp'],
         [],
         CLIENTCERT,
         ENABLED,
         self.LOCK)
     repolib.bind(
         self.TEST_REPO_FILENAME,
         self.TEST_MIRROR_LIST_FILENAME,
         self.TEST_KEYS_DIR,
         self.TEST_CERT_DIR,
         REPO_ID,
         REPO_NAME,
         ['http://pulp'],
         [],
         None,
         ENABLED,
         self.LOCK,
         verify_ssl=True)
     repo_file = RepoFile(self.TEST_REPO_FILENAME)
     repo_file.load()
     loaded = repo_file.get_repo(REPO_ID)
     certdir = os.path.join(self.TEST_CERT_DIR, REPO_ID)
     self.assertFalse(os.path.exists(certdir))
     self.assertTrue(loaded['sslverify'], '1')
Beispiel #9
0
    def test_clear_ca_path(self):
        repolib.bind(TEST_REPO_FILENAME,
                     TEST_MIRROR_LIST_FILENAME,
                     TEST_KEYS_DIR,
                     TEST_CERT_DIR,
                     REPO_ID,
                     REPO_NAME, ['http://pulp'], [],
                     CLIENTCERT,
                     ENABLED,
                     LOCK,
                     verify_ssl=True,
                     ca_path='/some/path')

        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME,
                     TEST_KEYS_DIR, TEST_CERT_DIR, REPO_ID, REPO_NAME,
                     ['http://pulp'], [], CLIENTCERT, ENABLED, LOCK)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        certdir = os.path.join(TEST_CERT_DIR, REPO_ID)
        self.assertTrue(len(os.listdir(certdir)), 1)
        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(CLIENTCERT, content)
        self.assertTrue(loaded['sslverify'], '0')
Beispiel #10
0
    def test_broken_load_allow_missing(self):
        """
        Tests that an exception is raised when the file cannot be loaded because it is not
        found.
        """

        # Test
        repo_file = RepoFile('/a/b/c/d')
        repo_file.load(allow_missing=True)
Beispiel #11
0
    def test_broken_load_allow_missing(self):
        """
        Tests that an exception is raised when the file cannot be loaded because it is not
        found.
        """

        # Test
        repo_file = RepoFile('/a/b/c/d')
        repo_file.load(allow_missing=True)
Beispiel #12
0
    def test_unbind_repo_exists(self):
        """
        Tests the normal case of unbinding a repo that exists in the repo file.
        """

        # Setup
        repoid = 'test-unbind-repo'
        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.add_repo(Repo(repoid))
        repo_file.save()

        # Test
        repolib.unbind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                       self.TEST_CERT_DIR,
                       'test-unbind-repo', self.LOCK)

        # verify
        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load(
            allow_missing=False)  # the file should still be there, so error if it doesn't

        self.assertEqual(0, len(repo_file.all_repos()))

        certdir = os.path.join(self.TEST_CERT_DIR, repoid)
        self.assertFalse(os.path.exists(certdir))
Beispiel #13
0
    def test_add_duplicate(self):
        """
        Tests that adding a repo that already exists throws a duplication error.
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(Repo('foo'))

        # Test
        self.assertRaises(DuplicateSectionError, repo_file.add_repo, Repo('foo'))
Beispiel #14
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_REPO_FILENAME))

        # Test
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.delete()
Beispiel #15
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_REPO_FILENAME))

        # Test
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.delete()
Beispiel #16
0
    def test_add_duplicate(self):
        """
        Tests that adding a repo that already exists throws a duplication error.
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(Repo('foo'))

        # Test
        self.assertRaises(DuplicateSectionError, repo_file.add_repo,
                          Repo('foo'))
Beispiel #17
0
    def test_get_invalid_repo(self):
        """
        Makes sure None is returned when requesting a repo that doesn't exist
        instead of throwing an error.
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)

        # Test
        found = repo_file.get_repo('foo')

        # Verify
        self.assertTrue(found is None)
Beispiel #18
0
    def test_get_invalid_repo(self):
        """
        Makes sure None is returned when requesting a repo that doesn't exist
        instead of throwing an error.
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)

        # Test
        found = repo_file.get_repo('foo')

        # Verify
        self.assertTrue(found is None)
Beispiel #19
0
    def test_header(self):
        """
        Tests that the pulp header is properly written in the generated file.
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.save()

        # Test
        f = open(TEST_REPO_FILENAME, 'r')
        contents = f.read()
        f.close()

        # Verify
        self.assertTrue(contents.startswith(RepoFile.FILE_HEADER))
Beispiel #20
0
    def test_header(self):
        """
        Tests that the pulp header is properly written in the generated file.
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.save()

        # Test
        f = open(TEST_REPO_FILENAME, 'r')
        contents = f.read()
        f.close()

        # Verify
        self.assertTrue(contents.startswith(RepoFile.FILE_HEADER))
Beispiel #21
0
    def test_bind_single_url(self):
        """
        Tests that binding with a single URL will produce a baseurl in the repo.
        """
        url_list = ['http://pulpserver']

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

        self.assertTrue(os.path.exists(TEST_REPO_FILENAME))
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['baseurl'], url_list[0])
        self.assertTrue('mirrorlist' not in loaded)
Beispiel #22
0
    def test_bind_multiple_keys(self):
        """
        Tests that binding with multiple key URLs correctly stores the repo entry.
        """
        url_list = ['http://pulpserver']
        keys = {'key1' : 'KEY1', 'key2' : 'KEY2'}

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

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['gpgcheck'], '1')
        self.assertEqual(2, len(loaded['gpgkey'].split('\n')))
        self.assertEqual(2, len(os.listdir(os.path.join(TEST_KEYS_DIR, REPO_ID))))
Beispiel #23
0
    def test_bind_single_url(self):
        """
        Tests that binding with a single URL will produce a baseurl in the repo.
        """
        url_list = ['http://pulpserver']

        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(not 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.assertEqual(loaded['baseurl'], url_list[0])
        self.assertTrue('mirrorlist' not in loaded)
Beispiel #24
0
    def test_unbind_repo_with_mirrorlist(self):
        """
        Tests that unbinding a repo that had a mirror list deletes the mirror list
        file.
        """
        url_list = ['http://pulp1', 'http://pulp2', 'http://pulp3']
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, url_list, {}, None, ENABLED, LOCK)
        self.assertTrue(os.path.exists(TEST_MIRROR_LIST_FILENAME))

        repolib.unbind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                       REPO_ID, LOCK)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        self.assertEqual(0, len(repo_file.all_repos()))
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))
Beispiel #25
0
    def test_bind_multiple_keys(self):
        """
        Tests that binding with multiple key URLs correctly stores the repo entry.
        """
        url_list = ['http://pulpserver']
        keys = {'key1': 'KEY1', 'key2': 'KEY2'}

        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, keys, None, ENABLED, self.LOCK)

        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['gpgcheck'], '1')
        self.assertEqual(2, len(loaded['gpgkey'].split('\n')))
        self.assertEqual(2, len(os.listdir(os.path.join(self.TEST_KEYS_DIR, REPO_ID))))
Beispiel #26
0
    def test_bind_update_repo(self):
        """
        Tests calling bind on an existing repo with new repo data. The host URL and key data
        remain unchanged.
        """
        url_list = ['http://pulp1', 'http://pulp2']
        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)
        updated_name = 'Updated'

        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                     REPO_ID, updated_name, None, None, None, ENABLED, LOCK)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['name'], updated_name)
Beispiel #27
0
 def test_update_clientcert(self):
     # setup
     NEWCLIENTCRT = 'THE-NEW-CLIENT-CERT'
     repolib.bind(
         TEST_REPO_FILENAME,
         TEST_MIRROR_LIST_FILENAME,
         TEST_KEYS_DIR,
         TEST_CERT_DIR,
         REPO_ID,
         REPO_NAME,
         ['http://pulp'],
         [],
         CACERT,
         CLIENTCERT,
         ENABLED,
         LOCK)
     repolib.bind(
         TEST_REPO_FILENAME,
         TEST_MIRROR_LIST_FILENAME,
         TEST_KEYS_DIR,
         TEST_CERT_DIR,
         REPO_ID,
         REPO_NAME,
         ['http://pulp'],
         [],
         CACERT,
         NEWCLIENTCRT,
         ENABLED,
         LOCK)
     repo_file = RepoFile(TEST_REPO_FILENAME)
     repo_file.load()
     loaded = repo_file.get_repo(REPO_ID)
     # verify
     certdir = os.path.join(TEST_CERT_DIR, REPO_ID)
     self.assertTrue(len(os.listdir(certdir)), 2)
     path = loaded['sslcacert']
     f = open(path)
     content = f.read()
     f.close()
     self.assertEqual(CACERT, content)
     path = loaded['sslclientcert']
     f = open(path)
     content = f.read()
     f.close()
     self.assertEqual(NEWCLIENTCRT, content)
     self.assertTrue(loaded['sslverify'], '1')
Beispiel #28
0
    def test_update_ca_path(self):
        NEW_PATH = '/new/path/'
        repolib.bind(
            TEST_REPO_FILENAME,
            TEST_MIRROR_LIST_FILENAME,
            TEST_KEYS_DIR,
            TEST_CERT_DIR,
            REPO_ID,
            REPO_NAME,
            ['http://pulp'],
            [],
            CLIENTCERT,
            ENABLED,
            LOCK,
            verify_ssl=True,
            ca_path='/some/path/')

        repolib.bind(
            TEST_REPO_FILENAME,
            TEST_MIRROR_LIST_FILENAME,
            TEST_KEYS_DIR,
            TEST_CERT_DIR,
            REPO_ID,
            REPO_NAME,
            ['http://pulp'],
            [],
            CLIENTCERT,
            ENABLED,
            LOCK,
            verify_ssl=True,
            ca_path=NEW_PATH)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        certdir = os.path.join(TEST_CERT_DIR, REPO_ID)
        self.assertTrue(len(os.listdir(certdir)), 1)
        path = loaded['sslcacert']
        self.assertEqual(path, NEW_PATH)
        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(CLIENTCERT, content)
        self.assertTrue(loaded['sslverify'], '1')
Beispiel #29
0
    def test_update_ca_path(self):
        NEW_PATH = '/new/path/'
        repolib.bind(
            self.TEST_REPO_FILENAME,
            self.TEST_MIRROR_LIST_FILENAME,
            self.TEST_KEYS_DIR,
            self.TEST_CERT_DIR,
            REPO_ID,
            REPO_NAME,
            ['http://pulp'],
            [],
            CLIENTCERT,
            ENABLED,
            self.LOCK,
            verify_ssl=True,
            ca_path='/some/path/')

        repolib.bind(
            self.TEST_REPO_FILENAME,
            self.TEST_MIRROR_LIST_FILENAME,
            self.TEST_KEYS_DIR,
            self.TEST_CERT_DIR,
            REPO_ID,
            REPO_NAME,
            ['http://pulp'],
            [],
            CLIENTCERT,
            ENABLED,
            self.LOCK,
            verify_ssl=True,
            ca_path=NEW_PATH)

        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        certdir = os.path.join(self.TEST_CERT_DIR, REPO_ID)
        self.assertTrue(len(os.listdir(certdir)), 1)
        path = loaded['sslcacert']
        self.assertEqual(path, NEW_PATH)
        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(CLIENTCERT, content)
        self.assertTrue(loaded['sslverify'], '1')
Beispiel #30
0
    def test_bind_update_remove_keys(self):
        """
        Tests that updating a previously bound repo by removing its keys correctly
        configures the repo and deletes the key files.
        """
        keys = {'key1' : 'KEY1', 'key2' : 'KEY2'}
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, ['http://pulp'], keys, None, ENABLED, LOCK)

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

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['gpgcheck'], '0')
        self.assertEqual(loaded['gpgkey'], None)
        self.assertTrue(not os.path.exists(os.path.join(TEST_KEYS_DIR, REPO_ID)))
Beispiel #31
0
    def test_unbind_repo_with_mirrorlist(self):
        """
        Tests that unbinding a repo that had a mirror list deletes the mirror list
        file.
        """
        url_list = ['http://pulp1', 'http://pulp2', 'http://pulp3']
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME,
                     TEST_KEYS_DIR, TEST_CERT_DIR, REPO_ID, REPO_NAME,
                     url_list, {}, None, ENABLED, LOCK)
        self.assertTrue(os.path.exists(TEST_MIRROR_LIST_FILENAME))

        repolib.unbind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME,
                       TEST_KEYS_DIR, TEST_CERT_DIR, REPO_ID, LOCK)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        self.assertEqual(0, len(repo_file.all_repos()))
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))
Beispiel #32
0
    def test_delete_repofile(self):
        """
        Tests that deleting a RepoFile correctly deletes the file on disk.
        """

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

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.save()

        self.assertTrue(os.path.exists(TEST_REPO_FILENAME))

        # Test
        repo_file.delete()

        # Verify
        self.assertTrue(not os.path.exists(TEST_REPO_FILENAME))
Beispiel #33
0
    def test_bind_host_urls_one_to_many(self):
        """
        Tests that changing from a single URL to many properly updates the baseurl and
        mirrorlist entries of the repo.
        """
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, ['https://pulpx'], None, None, ENABLED, LOCK)
        url_list = ['http://pulp1', 'http://pulp2']

        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)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue('baseurl' not in loaded)
        self.assertTrue('mirrorlist' in loaded)
Beispiel #34
0
    def test_no_repos_save_load(self):
        """
        Tests that saving and loading a file with no repos is successful.
        """

        # Test
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.save()

        # Verify
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()

        # Verify
        self.assertEqual(0, len(loaded.all_repos()))
Beispiel #35
0
    def test_bind_update_repo(self):
        """
        Tests calling bind on an existing repo with new repo data. The host URL and key data
        remain unchanged.
        """
        url_list = ['http://pulp1', 'http://pulp2']
        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, None, ENABLED, self.LOCK)
        updated_name = 'Updated'

        repolib.bind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                     self.TEST_CERT_DIR,
                     REPO_ID, updated_name, None, None, None, ENABLED, self.LOCK)

        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['name'], updated_name)
Beispiel #36
0
    def test_bind_host_urls_many_to_one(self):
        """
        Tests that changing from multiple URLs (mirrorlist usage) to a single URL
        properly sets the repo metadata.
        """
        # Setup
        url_list = ['http://pulp1', 'http://pulp2']
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR, REPO_ID, REPO_NAME, url_list, None, None, None, ENABLED, LOCK)

        # Test
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR, REPO_ID, REPO_NAME, ['http://pulpx'], None, None, None, ENABLED, LOCK)

        # Verify
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue('baseurl' in loaded)
        self.assertTrue('mirrorlist' not in loaded)
Beispiel #37
0
    def test_bind_update_host_urls(self):
        """
        Tests calling bind on an existing repo with new repo data. This test will test
        the more complex case where a mirror list existed in the original repo but is
        not necessary in the updated repo.
        """
        url_list = ['http://pulp1', 'http://pulp2']
        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)
        self.assertTrue(os.path.exists(TEST_MIRROR_LIST_FILENAME))

        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME, TEST_KEYS_DIR, TEST_CERT_DIR,
                     REPO_ID, None, ['http://pulpx'], None, None, ENABLED, LOCK)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['baseurl'], 'http://pulpx')
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))
Beispiel #38
0
    def test_broken_load(self):
        """
        Tests that an exception is raised when the file cannot be loaded because it is not
        found.
        """

        # Test
        repo_file = RepoFile('/a/b/c/d')

        self.assertRaises(IOError, repo_file.load, allow_missing=False)
Beispiel #39
0
    def test_bind_update_remove_keys(self):
        """
        Tests that updating a previously bound repo by removing its keys correctly
        configures the repo and deletes the key files.
        """
        keys = {'key1': 'KEY1', 'key2': 'KEY2'}
        repolib.bind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                     self.TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, ['http://pulp'], keys, None, ENABLED, self.LOCK)

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

        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['gpgcheck'], '0')
        self.assertEqual(loaded['gpgkey'], None)
        self.assertTrue(not os.path.exists(os.path.join(self.TEST_KEYS_DIR, REPO_ID)))
Beispiel #40
0
    def test_bind_host_urls_one_to_many(self):
        """
        Tests that changing from a single URL to many properly updates the baseurl and
        mirrorlist entries of the repo.
        """
        repolib.bind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                     self.TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, ['https://pulpx'], None, None, ENABLED, self.LOCK)
        url_list = ['http://pulp1', 'http://pulp2']

        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, None, ENABLED, self.LOCK)

        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue('baseurl' not in loaded)
        self.assertTrue('mirrorlist' in loaded)
Beispiel #41
0
def delete_repo_file(repo_filename, lock=None):
    """
    Delete the repo file.

    @param repo_filename: full path to the location of the repo file which
                          will be deleted; if this file does not exist
                          this call has no effect
    @type  repo_filename: string

    @param lock: if the default lock is unacceptable, it may be overridden in this variable
    @type  lock: L{Lock}
    """
    if not lock:
        lock = Lock(LOCK_FILE)

    lock.acquire()
    try:
        repo_file = RepoFile(repo_filename)
        repo_file.delete()
    finally:
        lock.release()
Beispiel #42
0
    def test_update_clientcert(self):
        NEWCLIENTCRT = 'THE-NEW-CLIENT-CERT'
        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME,
                     TEST_KEYS_DIR, TEST_CERT_DIR, REPO_ID, REPO_NAME,
                     ['http://pulp'], [], CLIENTCERT, ENABLED, LOCK)

        repolib.bind(TEST_REPO_FILENAME, TEST_MIRROR_LIST_FILENAME,
                     TEST_KEYS_DIR, TEST_CERT_DIR, REPO_ID, REPO_NAME,
                     ['http://pulp'], [], NEWCLIENTCRT, ENABLED, LOCK)

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        certdir = os.path.join(TEST_CERT_DIR, REPO_ID)
        self.assertTrue(len(os.listdir(certdir)), 1)
        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(NEWCLIENTCRT, content)
        self.assertTrue(loaded['sslverify'], '1')
Beispiel #43
0
    def test_bind_update_host_urls(self):
        """
        Tests calling bind on an existing repo with new repo data. This test will test
        the more complex case where a mirror list existed in the original repo but is
        not necessary in the updated repo.
        """
        url_list = ['http://pulp1', 'http://pulp2']
        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, None, ENABLED, self.LOCK)
        self.assertTrue(os.path.exists(self.TEST_MIRROR_LIST_FILENAME))

        repolib.bind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                     self.TEST_CERT_DIR,
                     REPO_ID, None, ['http://pulpx'], None, None, ENABLED, self.LOCK)

        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        self.assertEqual(loaded['baseurl'], 'http://pulpx')
        self.assertTrue(not os.path.exists(self.TEST_MIRROR_LIST_FILENAME))
Beispiel #44
0
    def test_broken_save(self):
        """
        Tests that an exception is raised when the file cannot be saved.
        """

        # Test

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

        self.assertRaises(IOError, repo_file.save)
Beispiel #45
0
def delete_repo_file(repo_filename, lock=None):
    """
    Delete the repo file.

    @param repo_filename: full path to the location of the repo file which
                          will be deleted; if this file does not exist
                          this call has no effect
    @type  repo_filename: string

    @param lock: if the default lock is unacceptable, it may be overridden in this variable
    @type  lock: L{Lock}
    """
    if not lock:
        lock = Lock(LOCK_FILE)

    lock.acquire()
    try:
        repo_file = RepoFile(repo_filename)
        repo_file.delete()
    finally:
        lock.release()
Beispiel #46
0
    def test_bind_new_repo_no_name(self):
        """
        Tests binding a repository that doesn't exist without providing a name.
        """
        url_list = ['http://pulpserver']

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

        self.assertTrue(os.path.exists(self.TEST_REPO_FILENAME))
        self.assertTrue(not os.path.exists(self.TEST_MIRROR_LIST_FILENAME))
        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()

        self.assertEqual(1, len(repo_file.all_repos()))

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue(loaded is not None)
        self.assertEqual(loaded['name'], REPO_ID)
        self.assertTrue(loaded['enabled'])
        self.assertEqual(loaded['gpgcheck'], '0')
        self.assertEqual(loaded['gpgkey'], None)

        self.assertEqual(loaded['baseurl'], url_list[0])
        self.assertTrue('mirrorlist' not in loaded)
Beispiel #47
0
    def test_bind_new_file(self):
        """
        Tests binding a repo when the underlying .repo file does not exist.
        """
        url_list = ['http://pulpserver']

        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, {}, CLIENTCERT, ENABLED, self.LOCK)

        self.assertTrue(os.path.exists(self.TEST_REPO_FILENAME))
        self.assertTrue(not os.path.exists(self.TEST_MIRROR_LIST_FILENAME))
        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()

        self.assertEqual(1, len(repo_file.all_repos()))

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue(loaded is not None)
        self.assertEqual(loaded['name'], REPO_NAME)
        self.assertTrue(loaded['enabled'])
        self.assertEqual(loaded['gpgcheck'], '0')
        self.assertEqual(loaded['gpgkey'], None)

        self.assertEqual(loaded['baseurl'], url_list[0])
        self.assertTrue('mirrorlist' not in loaded)

        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(CLIENTCERT, content)
        # verify_ssl defaults to True
        self.assertTrue(loaded['sslverify'], '1')
        self.assertEqual(loaded['sslcacert'], DEFAULT_CA_PATH)
Beispiel #48
0
    def test_clear_ca_path(self):
        repolib.bind(
            self.TEST_REPO_FILENAME,
            self.TEST_MIRROR_LIST_FILENAME,
            self.TEST_KEYS_DIR,
            self.TEST_CERT_DIR,
            REPO_ID,
            REPO_NAME,
            ['http://pulp'],
            [],
            CLIENTCERT,
            ENABLED,
            self.LOCK,
            verify_ssl=True,
            ca_path='/some/path')

        repolib.bind(
            self.TEST_REPO_FILENAME,
            self.TEST_MIRROR_LIST_FILENAME,
            self.TEST_KEYS_DIR,
            self.TEST_CERT_DIR,
            REPO_ID,
            REPO_NAME,
            ['http://pulp'],
            [],
            CLIENTCERT,
            ENABLED,
            self.LOCK)

        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()
        loaded = repo_file.get_repo(REPO_ID)
        certdir = os.path.join(self.TEST_CERT_DIR, REPO_ID)
        self.assertTrue(len(os.listdir(certdir)), 1)
        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(CLIENTCERT, content)
        self.assertTrue(loaded['sslverify'], '0')
Beispiel #49
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')
Beispiel #50
0
    def test_broken_load_invalid_data(self):
        """
        Tests that an exception is raised when the file contains non-parsable data.
        """

        # Setup
        f = open(TEST_REPO_FILENAME, 'w')
        f.write('This is not parsable.')
        f.close()

        # Test
        repo_file = RepoFile(TEST_REPO_FILENAME)

        self.assertRaises(Exception, repo_file.load)
Beispiel #51
0
    def test_bind_host_urls_many_to_one(self):
        """
        Tests that changing from multiple URLs (mirrorlist usage) to a single URL
        properly sets the repo metadata.
        """
        # Setup
        url_list = ['http://pulp1', 'http://pulp2']
        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, None, ENABLED, self.LOCK)

        # Test
        repolib.bind(self.TEST_REPO_FILENAME, self.TEST_MIRROR_LIST_FILENAME, self.TEST_KEYS_DIR,
                     self.TEST_CERT_DIR,
                     REPO_ID, REPO_NAME, ['http://pulpx'], None, None, ENABLED, self.LOCK)

        # Verify
        repo_file = RepoFile(self.TEST_REPO_FILENAME)
        repo_file.load()

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue('baseurl' in loaded)
        self.assertTrue('mirrorlist' not in loaded)
Beispiel #52
0
    def test_mirrorlist_not_baseurl(self):
        """
        Tests that if a mirrorlist is specified, a baseurl entry isn't written to the
        saved repo file.
        """

        # Setup
        repo = Repo('test-repo-1')
        repo['mirrorlist'] = 'file://etc/pulp/mirrorlist'

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(repo)
        repo_file.save()

        # Test
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()

        loaded_repo = loaded.get_repo('test-repo-1')
        self.assertEqual(loaded_repo['mirrorlist'], 'file://etc/pulp/mirrorlist')
        self.assertTrue('baseurl' not in loaded_repo)
Beispiel #53
0
    def test_bind_existing_file(self):
        """
        Tests binding a new repo when the underlying file exists and has repos in it
        (the existing repo shouldn't be deleted).
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(Repo('existing-repo-1'))
        repo_file.save()

        # Test
        url_list = ['http://pulpserver']
        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))

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()

        self.assertEqual(2, len(repo_file.all_repos()))
Beispiel #54
0
    def test_no_repos_save_load(self):
        """
        Tests that saving and loading a file with no repos is successful.
        """

        # Test
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.save()

        # Verify
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()

        # Verify
        self.assertEqual(0, len(loaded.all_repos()))
Beispiel #55
0
    def test_delete_repo_no_repo(self):
        """
        Ensures that an error is not thrown when a repo that does not exist is
        deleted from the repo file.
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(Repo('test-repo-1'))

        # Test
        repo_file.remove_repo_by_name('foo')

        # Verify
        self.assertTrue(repo_file.get_repo('test-repo-1') is not None)
Beispiel #56
0
    def test_delete_repo_no_repo(self):
        """
        Ensures that an error is not thrown when a repo that does not exist is
        deleted from the repo file.
        """

        # Setup
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(Repo('test-repo-1'))

        # Test
        repo_file.remove_repo_by_name('foo')

        # Verify
        self.assertTrue(repo_file.get_repo('test-repo-1') is not None)
Beispiel #57
0
    def test_bind_ssl_verify_true_explicit_ca_path(self):
        """
        Tests binding a repo with verify_ssl set explicitly to True and an explicit ca_path.
        """
        url_list = ['http://pulpserver']
        ca_path = '/some/path'

        repolib.bind(TEST_REPO_FILENAME,
                     TEST_MIRROR_LIST_FILENAME,
                     TEST_KEYS_DIR,
                     TEST_CERT_DIR,
                     REPO_ID,
                     REPO_NAME,
                     url_list, {},
                     CLIENTCERT,
                     ENABLED,
                     LOCK,
                     verify_ssl=True,
                     ca_path=ca_path)

        self.assertTrue(os.path.exists(TEST_REPO_FILENAME))
        self.assertTrue(not os.path.exists(TEST_MIRROR_LIST_FILENAME))
        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.load()

        self.assertEqual(1, len(repo_file.all_repos()))

        loaded = repo_file.get_repo(REPO_ID)
        self.assertTrue(loaded is not None)
        self.assertEqual(loaded['name'], REPO_NAME)
        self.assertTrue(loaded['enabled'])
        self.assertEqual(loaded['gpgcheck'], '0')
        self.assertEqual(loaded['gpgkey'], None)

        self.assertEqual(loaded['baseurl'], url_list[0])
        self.assertTrue('mirrorlist' not in loaded)

        path = loaded['sslclientcert']
        f = open(path)
        content = f.read()
        f.close()
        self.assertEqual(CLIENTCERT, content)
        self.assertTrue(loaded['sslverify'], '1')
        # The default CA path should have been used
        self.assertEqual(loaded['sslcacert'], ca_path)
Beispiel #58
0
    def test_delete_repofile(self):
        """
        Tests that deleting a RepoFile correctly deletes the file on disk.
        """

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

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.save()

        self.assertTrue(os.path.exists(TEST_REPO_FILENAME))

        # Test
        repo_file.delete()

        # Verify
        self.assertTrue(not os.path.exists(TEST_REPO_FILENAME))
Beispiel #59
0
def bind(repo_filename,
         mirror_list_filename,
         keys_root_dir,
         cert_root_dir,
         repo_id,
         repo_name,
         url_list,
         gpg_keys,
         clientcert,
         enabled,
         lock=None,
         verify_ssl=True,
         ca_path=DEFAULT_CA_PATH):
    """
    Uses the given data to safely bind a repo to a repo file. This call will
    determine the best method for representing the repo given the data in the
    repo object as well as the list of URLs where the repo can be found.

    The default lock is defined at the module level and is
    used to ensure that concurrent access to the give files is prevented. Specific
    locks can be passed in for testing purposes to circumvent the default
    location of the lock which requires root access.

    :param repo_filename:        full path to the location of the repo file in which
                                 the repo will be bound; this file does not need to
                                 exist prior to this call
    :type  repo_filename:        string
    :param mirror_list_filename: full path to the location of the mirror list file
                                 that should be written for the given repo if
                                 necessary; this should be unique for the given repo
    :type  mirror_list_filename: string
    :param keys_root_dir:        absolute path to the root directory in which the keys for
                                 all repos will be stored
    :type  keys_root_dir:        string
    :param cert_root_dir:        absolute path to the root directory in which the certs for
                                 all repos will be stored
    :type  cert_root_dir:        string
    :param repo_id:              uniquely identifies the repo being updated
    :type  repo_id:              string
    :param repo_name:            the repo name
    :type  repo_name:            str
    :param url_list:             list of URLs that will be used to access the repo; this call
                                 will determine the best way to represent the URL list in
                                 the repo definition
    :type  url_list:             list of strings
    :param gpg_keys:             mapping of key name to contents for GPG keys to be used when
                                 verifying packages from this repo
    :type  gpg_keys:             dict {string: string}
    :param clientcert:           The client certificate (PEM).
    :type  clientcert:           str
    :param enabled:              Whether or not the repository is set to 'enabled'
    :type  enabled:              bool
    :param lock:                 if the default lock is unacceptble, it may be overridden in this
                                 variable
    :type  lock:                 L{Lock}
    :param verify_ssl:           Whether the repo file should be configured to validate CA trust.
                                 Defaults to True.
    :type  verify_ssl:           bool
    :param ca_path:              Absolute path to a directory that contains trusted CA certificates.
                                 Defaults to pulp.bindings.server.DEFAULT_CA_PATH.
    :type  ca_path:              basestring
    """

    if not lock:
        lock = Lock(LOCK_FILE)

    lock.acquire()
    try:
        log.info('Binding repo [%s]' % repo_id)

        repo_file = RepoFile(repo_filename)
        repo_file.load()

        # In the case of an update, only the changed values will have been sent.
        # Therefore, any of the major data components (repo data, url list, keys)
        # may be None.

        repo = repo_file.get_repo(repo_id)
        if not repo:
            # if no repo name is provided for a new repo, use the id for the name
            repo = Repo(repo_id)
            if repo_name is None:
                repo['name'] = repo_id
            else:
                repo['name'] = repo_name

        repo['enabled'] = str(int(enabled))

        if repo_name:
            repo['name'] = repo_name

        if gpg_keys is not None:
            _handle_gpg_keys(repo, gpg_keys, keys_root_dir)

        _handle_client_cert(repo, cert_root_dir, clientcert)

        if verify_ssl:
            repo['sslverify'] = '1'
            repo['sslcacert'] = ca_path
        else:
            repo['sslverify'] = '0'

        if url_list is not None:
            _handle_host_urls(repo, url_list, mirror_list_filename)

        if repo_file.get_repo(repo.id):
            log.info('Updating existing repo [%s]' % repo.id)
            repo_file.update_repo(repo)
        else:
            log.info('Adding new repo [%s]' % repo.id)
            repo_file.add_repo(repo)

        repo_file.save()
    finally:
        lock.release()