本文整理匯總了Python中yum_distributor.distributor.YumDistributor.validate_config方法的典型用法代碼示例。如果您正苦於以下問題:Python YumDistributor.validate_config方法的具體用法?Python YumDistributor.validate_config怎麽用?Python YumDistributor.validate_config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yum_distributor.distributor.YumDistributor
的用法示例。
在下文中一共展示了YumDistributor.validate_config方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_publish
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import validate_config [as 別名]
def test_publish(self):
repo = mock.Mock(spec=Repository)
repo.working_dir = self.repo_working_dir
repo.id = "test_publish"
num_units = 10
relative_url = "rel_a/rel_b/rel_c/"
existing_units = self.get_units(count=num_units)
publish_conduit = distributor_mocks.get_publish_conduit(existing_units=existing_units, pkg_dir=self.pkg_dir)
config = distributor_mocks.get_basic_config(https_publish_dir=self.https_publish_dir, relative_url=relative_url,
http=False, https=True)
distributor = YumDistributor()
distributor.process_repo_auth_certificate_bundle = mock.Mock()
status, msg = distributor.validate_config(repo, config, None)
self.assertTrue(status)
report = distributor.publish_repo(repo, publish_conduit, config)
self.assertTrue(report.success_flag)
summary = report.summary
self.assertEqual(summary["num_package_units_attempted"], num_units)
self.assertEqual(summary["num_package_units_published"], num_units)
self.assertEqual(summary["num_package_units_errors"], 0)
# Verify we did not attempt to publish to http
expected_repo_http_publish_dir = os.path.join(self.http_publish_dir, relative_url)
self.assertFalse(os.path.exists(expected_repo_http_publish_dir))
expected_repo_https_publish_dir = os.path.join(self.https_publish_dir, relative_url).rstrip('/')
self.assertEqual(summary["https_publish_dir"], expected_repo_https_publish_dir)
self.assertTrue(os.path.exists(expected_repo_https_publish_dir))
details = report.details
self.assertEqual(len(details["errors"]), 0)
#
# Add a verification of the publish directory
#
self.assertTrue(os.path.exists(summary["https_publish_dir"]))
self.assertTrue(os.path.islink(summary["https_publish_dir"].rstrip("/")))
source_of_link = os.readlink(expected_repo_https_publish_dir.rstrip("/"))
self.assertEquals(source_of_link, repo.working_dir)
#
# Verify the expected units
#
for u in existing_units:
expected_link = os.path.join(expected_repo_https_publish_dir, u.metadata["relativepath"])
self.assertTrue(os.path.exists(expected_link))
actual_target = os.readlink(expected_link)
expected_target = u.storage_path
self.assertEqual(actual_target, expected_target)
#
# Now test flipping so https is disabled and http is enabled
#
config = distributor_mocks.get_basic_config(https_publish_dir=self.https_publish_dir,
http_publish_dir=self.http_publish_dir, relative_url=relative_url, http=True, https=False)
report = distributor.publish_repo(repo, publish_conduit, config)
self.assertTrue(report.success_flag)
# Verify we did publish to http
self.assertTrue(os.path.exists(expected_repo_http_publish_dir))
# Verify we did not publish to https
self.assertFalse(os.path.exists(expected_repo_https_publish_dir))
# Verify we cleaned up the misc dirs under the https dir
self.assertEquals(len(os.listdir(self.https_publish_dir)), 0)
示例2: test_basic_repo_publish_rel_path_conflict
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import validate_config [as 別名]
def test_basic_repo_publish_rel_path_conflict(self):
repo = mock.Mock(spec=Repository)
repo.working_dir = self.repo_working_dir
repo.id = "test_basic_repo_publish_rel_path_conflict"
num_units = 10
relative_url = "rel_a/rel_b/rel_a/"
config = distributor_mocks.get_basic_config(https_publish_dir=self.https_publish_dir,
relative_url=relative_url, http=False, https=True)
url_a = relative_url
config_a = PluginCallConfiguration({"relative_url":url_a}, {})
repo_a = RelatedRepository("repo_a_id", [config_a])
config_conduit = mock.Mock(spec=RepoConfigConduit)
conduit_return_cursor = MockCursor([{'repo_id': 'repo_a_id', 'config': {'relative_url': "rel_a/rel_b/rel_a/"}}])
config_conduit.get_repo_distributors_by_relative_url.return_value = conduit_return_cursor
# Simple check of direct conflict of a duplicate - varieties of duplicates are tested via the conduit tests
related_repos = [repo_a]
distributor = YumDistributor()
distributor.process_repo_auth_certificate_bundle = mock.Mock()
status, msg = distributor.validate_config(repo, config, config_conduit)
self.assertFalse(status)
expected_msg = "Relative url '%s' conflicts with existing relative_url of '%s' from repo '%s'" % \
(relative_url, url_a, repo_a.id)
self.assertEqual(expected_msg, msg)
# Ensure this test can handle a large number of repos
"""
示例3: test_validate_config
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import validate_config [as 別名]
def test_validate_config(self):
repo = mock.Mock(spec=Repository)
repo.id = "testrepo"
distributor = YumDistributor()
distributor.process_repo_auth_certificate_bundle = mock.Mock()
# Confirm that required keys are successful
req_kwargs = {}
req_kwargs['http'] = True
req_kwargs['https'] = False
req_kwargs['relative_url'] = "sample_value"
config = distributor_mocks.get_basic_config(**req_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertTrue(state)
# Confirm required and optional are successful
optional_kwargs = dict(req_kwargs)
optional_kwargs['auth_ca'] = open(os.path.join(self.data_dir, "valid_ca.crt")).read()
optional_kwargs['https_ca'] = open(os.path.join(self.data_dir, "valid_ca.crt")).read()
optional_kwargs['protected'] = True
optional_kwargs['generate_metadata'] = True
optional_kwargs['checksum_type'] = "sha"
optional_kwargs['skip'] = []
optional_kwargs['auth_cert'] = open(os.path.join(self.data_dir, "cert.crt")).read()
config = distributor_mocks.get_basic_config(**optional_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertTrue(state)
# Test that config fails when a bad value for non_existing_dir is used
optional_kwargs["http_publish_dir"] = "non_existing_dir"
config = distributor_mocks.get_basic_config(**optional_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertFalse(state)
# Test config succeeds with a good value of https_publish_dir
optional_kwargs["http_publish_dir"] = self.temp_dir
config = distributor_mocks.get_basic_config(**optional_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertTrue(state)
del optional_kwargs["http_publish_dir"]
# Test that config fails when a bad value for non_existing_dir is used
optional_kwargs["https_publish_dir"] = "non_existing_dir"
config = distributor_mocks.get_basic_config(**optional_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertFalse(state)
# Test config succeeds with a good value of https_publish_dir
optional_kwargs["https_publish_dir"] = self.temp_dir
config = distributor_mocks.get_basic_config(**optional_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertTrue(state)
del optional_kwargs["https_publish_dir"]
# Confirm an extra key fails
optional_kwargs["extra_arg_not_used"] = "sample_value"
config = distributor_mocks.get_basic_config(**optional_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertFalse(state)
self.assertTrue("extra_arg_not_used" in msg)
# Confirm missing a required fails
del optional_kwargs["extra_arg_not_used"]
config = distributor_mocks.get_basic_config(**optional_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertTrue(state)
del optional_kwargs["relative_url"]
config = distributor_mocks.get_basic_config(**optional_kwargs)
state, msg = distributor.validate_config(repo, config, [])
self.assertFalse(state)
self.assertTrue("relative_url" in msg)
示例4: test_basic_repo_publish_rel_path_conflict
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import validate_config [as 別名]
def test_basic_repo_publish_rel_path_conflict(self):
repo = mock.Mock(spec=Repository)
repo.working_dir = self.repo_working_dir
repo.id = "test_basic_repo_publish_rel_path_conflict"
num_units = 10
relative_url = "rel_a/rel_b/rel_a/"
config = distributor_mocks.get_basic_config(https_publish_dir=self.https_publish_dir,
relative_url=relative_url, http=False, https=True)
url_a = relative_url
config_a = PluginCallConfiguration({"relative_url":url_a}, {})
repo_a = RelatedRepository("repo_a_id", [config_a])
# Simple check of direct conflict of a duplicate
related_repos = [repo_a]
distributor = YumDistributor()
distributor.process_repo_auth_certificate_bundle = mock.Mock()
status, msg = distributor.validate_config(repo, config, related_repos)
self.assertFalse(status)
expected_msg = "Relative url '%s' conflicts with existing relative_url of '%s' from repo '%s'" % (relative_url, url_a, repo_a.id)
self.assertEqual(expected_msg, msg)
# Check conflict with a subdir
url_b = "rel_a/rel_b/"
config_b = PluginCallConfiguration({"relative_url":url_b}, {})
repo_b = RelatedRepository("repo_b_id", [config_b])
related_repos = [repo_b]
distributor = YumDistributor()
distributor.process_repo_auth_certificate_bundle = mock.Mock()
status, msg = distributor.validate_config(repo, config, related_repos)
self.assertFalse(status)
expected_msg = "Relative url '%s' conflicts with existing relative_url of '%s' from repo '%s'" % (relative_url, url_b, repo_b.id)
self.assertEqual(expected_msg, msg)
# Check no conflict with a pieces of a common subdir
url_c = "rel_a/rel_b/rel_c"
config_c = PluginCallConfiguration({"relative_url":url_c}, {})
repo_c = RelatedRepository("repo_c_id", [config_c])
url_d = "rel_a/rel_b/rel_d"
config_d = PluginCallConfiguration({"relative_url":url_d}, {})
repo_d = RelatedRepository("repo_d_id", [config_d])
url_e = "rel_a/rel_b/rel_e/rel_e"
config_e = PluginCallConfiguration({"relative_url":url_e}, {})
repo_e = RelatedRepository("repo_e_id", [config_e])
# Add a repo with no relative_url
config_f = PluginCallConfiguration({"relative_url":None}, {})
repo_f = RelatedRepository("repo_f_id", [config_f])
related_repos = [repo_c, repo_d, repo_e, repo_f]
distributor = YumDistributor()
distributor.process_repo_auth_certificate_bundle = mock.Mock()
status, msg = distributor.validate_config(repo, config, related_repos)
self.assertTrue(status)
self.assertEqual(msg, None)
# Test with 2 repos and no relative_url
config_h = PluginCallConfiguration({}, {})
repo_h = RelatedRepository("repo_h_id", [config_h])
config_i = PluginCallConfiguration({}, {})
repo_i = RelatedRepository("repo_i_id", [config_i])
status, msg = distributor.validate_config(repo_i, config, [repo_h])
self.assertTrue(status)
self.assertEqual(msg, None)
# TODO: Test, repo_1 has no rel url, so repo_1_id is used
# Then 2nd repo is configured with rel_url of repo_1_id
# should result in a conflict
# Ensure this test can handle a large number of repos
test_repos = []
for index in range(0,10000):
test_url = "rel_a/rel_b/rel_e/repo_%s" % (index)
test_config = PluginCallConfiguration({"relative_url":test_url}, {})
r = RelatedRepository("repo_%s_id" % (index), [test_config])
test_repos.append(r)
related_repos = test_repos
distributor = YumDistributor()
distributor.process_repo_auth_certificate_bundle = mock.Mock()
status, msg = distributor.validate_config(repo, config, related_repos)
self.assertTrue(status)
self.assertEqual(msg, None)
示例5: TestValidateConfig
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import validate_config [as 別名]
class TestValidateConfig(rpm_support_base.PulpRPMTests):
def setUp(self):
super(TestValidateConfig, self).setUp()
self.repo = mock.Mock(spec=Repository)
self.repo.id = "testrepo"
self.distributor = YumDistributor()
self.distributor.process_repo_auth_certificate_bundle = mock.Mock()
self.init()
def tearDown(self):
super(TestValidateConfig, self).tearDown()
def init(self):
self.data_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "./data"))
def test_config_relative_path(self):
http = True
https = False
relative_url = 123
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertFalse(state)
relative_url = "test_path"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertTrue(state)
def test_config_http(self):
http = "true"
https = False
relative_url = "test_path"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertFalse(state)
http = True
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertTrue(state)
def test_config_https(self):
http = True
https = "False"
relative_url = "test_path"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertFalse(state)
https = True
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertTrue(state)
def test_config_protected(self):
http = True
https = False
relative_url = "test_path"
protected = "false"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https, protected=protected)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertFalse(state)
protected = True
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https, protected=protected)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertTrue(state)
def test_config_checksum_type(self):
http = True
https = False
relative_url = "test_path"
checksum_type = "fake"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https,
checksum_type=checksum_type)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertFalse(state)
checksum_type = "sha"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https,
checksum_type=checksum_type)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertTrue(state)
def test_config_skip_content_types(self):
http = True
https = False
relative_url = "test_path"
skip_content_types = "fake"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https,
skip=skip_content_types)
state, msg = self.distributor.validate_config(self.repo, config, [])
self.assertFalse(state)
skip_content_types = []
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https,
#.........這裏部分代碼省略.........
示例6: TestValidateConfig
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import validate_config [as 別名]
class TestValidateConfig(rpm_support_base.PulpRPMTests):
def setUp(self):
super(TestValidateConfig, self).setUp()
self.repo = mock.Mock(spec=Repository)
self.repo.id = "testrepo"
self.distributor = YumDistributor()
self.distributor.process_repo_auth_certificate_bundle = mock.Mock()
self.config_conduit = RepoConfigConduit(TYPE_ID_RPM)
self.init()
def tearDown(self):
super(TestValidateConfig, self).tearDown()
def init(self):
self.data_dir = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "../data"))
def test_config_relative_path(self):
http = True
https = False
relative_url = 123
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertFalse(state)
relative_url = "test_path"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertTrue(state)
# For https://bugzilla.redhat.com/show_bug.cgi?id=874241 we will assert that crazy characters don't validate
relative_url = '@#%^&*()'
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertFalse(state)
self.assertEqual(msg, 'relative_url must contain only alphanumerics, underscores, and dashes.')
# relative_url should be allowed to be empty string
relative_url = ""
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertTrue(state)
# relative_url should be allowed to have a forward slash character
relative_url = "/jdob/repos/awesome-repo"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertTrue(state)
def test_config_http(self):
http = "true"
https = False
relative_url = "test_path"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertFalse(state)
http = True
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertTrue(state)
def test_config_https(self):
http = True
https = "False"
relative_url = "test_path"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertFalse(state)
https = True
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertTrue(state)
def test_config_protected(self):
http = True
https = False
relative_url = "test_path"
protected = "false"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https, protected=protected)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertFalse(state)
protected = True
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https, protected=protected)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertTrue(state)
def test_config_checksum_type(self):
http = True
https = False
relative_url = "test_path"
checksum_type = "fake"
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https,
checksum_type=checksum_type)
state, msg = self.distributor.validate_config(self.repo, config, self.config_conduit)
self.assertFalse(state)
#.........這裏部分代碼省略.........