本文整理汇总了Python中pulp_rpm.handlers.repo_file.RepoFile类的典型用法代码示例。如果您正苦于以下问题:Python RepoFile类的具体用法?Python RepoFile怎么用?Python RepoFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RepoFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_clear_clientcert
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')
示例2: test_bind_ssl_verify_false
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)
示例3: test_bind_new_file
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)
示例4: test_bind_new_repo_no_name
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)
示例5: test_bind_multiple_url
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')
示例6: test_bind_update_keys
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')
示例7: test_one_repo_save_and_load
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))
示例8: test_broken_load_allow_missing
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)
示例9: test_unbind_repo_exists
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))
示例10: test_add_duplicate
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'))
示例11: test_delete_file_doesnt_exist
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()
示例12: test_get_invalid_repo
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)
示例13: test_bind_single_url
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)
示例14: test_bind_multiple_keys
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))))
示例15: test_header
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))