Example #1
0
    def test_multiple_repos(self):
        """
        Tests saving and loading multiple repos.
        """

        # Setup
        repo1 = Repo('test-repo-1')
        repo1['baseurl'] = 'http://localhost/repo1'

        repo2 = Repo('test-repo-2')
        repo2['baseurl'] = 'http://localhost/repo2'

        repo_file = RepoFile(TEST_REPO_FILENAME)

        # Test
        repo_file.add_repo(repo1)
        repo_file.add_repo(repo2)
        repo_file.save()

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

        self.assertEqual(2, len(loaded.all_repos()))

        found_repo1 = loaded.get_repo('test-repo-1')
        self.assertTrue(found_repo1 is not None)
        self.assertTrue(_repo_eq(repo1, found_repo1))

        found_repo2 = loaded.get_repo('test-repo-2')
        self.assertTrue(found_repo2 is not None)
        self.assertTrue(_repo_eq(repo2, found_repo2))
Example #2
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))
Example #3
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))
Example #4
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)
Example #5
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)
Example #6
0
    def test_delete_repo(self):
        """
        Tests removing an existing repo is correctly saved and loaded
        """

        # Setup
        repo1 = Repo('test-repo-1')
        repo2 = Repo('test-repo-2')

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(repo1)
        repo_file.add_repo(repo2)
        repo_file.save()

        # Test
        repo_file.remove_repo_by_name('test-repo-1')
        repo_file.save()

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

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

        self.assertTrue(loaded.get_repo('test-repo-1') is None)
        self.assertTrue(loaded.get_repo('test-repo-2') is not None)
Example #7
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))
Example #8
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)
Example #9
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))
Example #10
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)
Example #11
0
    def test_delete_repo(self):
        """
        Tests removing an existing repo is correctly saved and loaded
        """

        # Setup
        repo1 = Repo('test-repo-1')
        repo2 = Repo('test-repo-2')

        repo_file = RepoFile(TEST_REPO_FILENAME)
        repo_file.add_repo(repo1)
        repo_file.add_repo(repo2)
        repo_file.save()
        
        # Test
        repo_file.remove_repo_by_name('test-repo-1')
        repo_file.save()

        # Verify
        loaded = RepoFile(TEST_REPO_FILENAME)
        loaded.load()
        
        self.assertEqual(1, len(loaded.all_repos()))

        self.assertTrue(loaded.get_repo('test-repo-1') is None)
        self.assertTrue(loaded.get_repo('test-repo-2') is not None)
Example #12
0
    def test_multiple_repos(self):
        """
        Tests saving and loading multiple repos.
        """

        # Setup
        repo1 = Repo('test-repo-1')
        repo1['baseurl'] = 'http://localhost/repo1'

        repo2 = Repo('test-repo-2')
        repo2['baseurl'] = 'http://localhost/repo2'

        repo_file = RepoFile(TEST_REPO_FILENAME)

        # Test
        repo_file.add_repo(repo1)
        repo_file.add_repo(repo2)
        repo_file.save()

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

        self.assertEqual(2, len(loaded.all_repos()))

        found_repo1 = loaded.get_repo('test-repo-1')
        self.assertTrue(found_repo1 is not None)
        self.assertTrue(_repo_eq(repo1, found_repo1))

        found_repo2 = loaded.get_repo('test-repo-2')
        self.assertTrue(found_repo2 is not None)
        self.assertTrue(_repo_eq(repo2, found_repo2))
Example #13
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()))
Example #14
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()))
Example #15
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))
Example #16
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)
Example #17
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))
Example #18
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()))
Example #19
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(self.TEST_REPO_FILENAME)
        repo_file.add_repo(Repo('existing-repo-1'))
        repo_file.save()

        # Test
        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)

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

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

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