本文整理匯總了Python中yum_distributor.distributor.YumDistributor類的典型用法代碼示例。如果您正苦於以下問題:Python YumDistributor類的具體用法?Python YumDistributor怎麽用?Python YumDistributor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了YumDistributor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_yum_plugin_generate_yum_metadata_checksum_default
def test_yum_plugin_generate_yum_metadata_checksum_default(self, mock_YumMetadataGenerator,
mock_distributor_manager):
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(type_id="rpm",
existing_units=existing_units,
checksum_type=None,
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()
config_conduit = mock.Mock(spec=RepoConfigConduit)
config_conduit.get_repo_distributors_by_relative_url.return_value = MockCursor([])
metadata.generate_yum_metadata(repo.id, repo.working_dir, publish_conduit, config)
mock_YumMetadataGenerator.assert_called_with(ANY, checksum_type=metadata.DEFAULT_CHECKSUM,
skip_metadata_types=ANY, is_cancelled=ANY,
group_xml_path=ANY,
updateinfo_xml_path=ANY,
custom_metadata_dict=ANY)
self.assertFalse(mock_distributor_manager.called)
示例2: test_consumer_payload
def test_consumer_payload(self):
PAYLOAD_FIELDS = [
"server_name",
"relative_path",
"protocols",
"gpg_keys",
"client_cert",
"ca_cert",
"repo_name",
]
http = True
https = True
relative_url = "/pub/content/"
gpgkey = ["test_gpg_key"]
auth_cert = open(os.path.join(self.data_dir, "cert.crt")).read()
auth_ca = open(os.path.join(self.data_dir, "ca.key")).read()
config = distributor_mocks.get_basic_config(
relative_url=relative_url, http=http, https=https, auth_cert=auth_cert, auth_ca=auth_ca, gpgkey=gpgkey
)
distributor = YumDistributor()
repo = mock.Mock(spec=Repository)
repo.working_dir = self.repo_working_dir
repo.id = "test_payload"
repo.display_name = "Nice Repo"
payload = distributor.create_consumer_payload(repo, config)
for field in PAYLOAD_FIELDS:
print field
self.assertTrue(field in payload)
self.assertTrue("http" in payload["protocols"])
self.assertTrue("https" in payload["protocols"])
print payload
示例3: test_distributor_removed
def test_distributor_removed(self, delete_protected_repo, mock_factory):
"""
Make sure the distributor_removed() method cleans up the published files.
"""
# Create and publish repo to both http and https directories
repo = mock.Mock(spec=Repository)
repo.id = 'about_to_be_removed'
repo.working_dir = self.repo_working_dir
existing_units = self.get_units(count=5)
publish_conduit = distributor_mocks.get_publish_conduit(type_id="rpm",
existing_units=existing_units,
pkg_dir=self.pkg_dir)
config = distributor_mocks.get_basic_config(http_publish_dir=self.http_publish_dir,
https_publish_dir=self.https_publish_dir,
http=True,
https=True)
distributor = YumDistributor()
publish_conduit.repo_id = repo.id
publish_conduit.distributor_id = 'foo'
report = distributor.publish_repo(repo, publish_conduit, config)
publishing_paths = [os.path.join(directory, repo.id) \
for directory in [self.http_publish_dir, self.https_publish_dir]]
# The publishing paths should exist
self.assertTrue(all([os.path.exists(directory) for directory in publishing_paths]))
delete_protected_repo.reset_mock()
distributor.distributor_removed(repo, config)
# Neither publishing path should exist now
self.assertFalse(all([os.path.exists(directory) for directory in publishing_paths]))
# delete_protected_repo should have been called
delete_protected_repo.assert_called_once_with(repo.id)
示例4: test_publish
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)
示例5: test_basic_repo_publish_rel_path_conflict
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
"""
示例6: test_custom_metadata_publish
def test_custom_metadata_publish(self):
distributor = YumDistributor()
repo = self._mock_repo('test-presto-delta-metadata')
repo_units = self._test_drpm_repo_units()
publish_conduit = mock_conduits.repo_publish_conduit(existing_units=repo_units)
config = mock_conduits.plugin_call_config(http_publish_dir=self.content_dir, relative_url='', http=True, https=False)
distributor.publish_repo(repo, publish_conduit, config)
# make sure the metadata unit was published
criteria = UnitAssociationCriteria(type_ids=[TYPE_ID_YUM_REPO_METADATA_FILE])
metadata_units = publish_conduit.get_units(criteria)
self.assertEqual(len(metadata_units), 1)
unit = metadata_units[0]
self.assertEqual(unit.type_id, TYPE_ID_YUM_REPO_METADATA_FILE)
self.assertEqual(unit.unit_key['data_type'], 'prestodelta')
# make sure the file was copied into place
repodata_path = os.path.join(self.content_dir, repo.id, 'repodata')
prestodelta_files = glob.glob(repodata_path + '/*prestodelta*')
self.assertEqual(len(prestodelta_files), 1)
prestodelta_path = os.path.join(repodata_path, prestodelta_files[0])
self.assertTrue(os.path.exists(prestodelta_path))
示例7: test_yum_plugin_generate_yum_metadata_checksum_from_conduit_sha1_conversion
def test_yum_plugin_generate_yum_metadata_checksum_from_conduit_sha1_conversion(self,
mock_YumMetadataGenerator,
mock_distributor_manager):
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(type_id="rpm", existing_units=existing_units, pkg_dir=self.pkg_dir)
publish_conduit.repo_id = 'foo'
publish_conduit.distributor_id = TYPE_ID_DISTRIBUTOR_YUM
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()
config_conduit = mock.Mock(spec=RepoConfigConduit)
config_conduit.get_repo_distributors_by_relative_url.return_value = MockCursor([])
metadata.generate_yum_metadata(repo.id, repo.working_dir, publish_conduit, config,
repo_scratchpad={'checksum_type': 'sha'})
mock_YumMetadataGenerator.assert_called_with(ANY, checksum_type='sha1',
skip_metadata_types=ANY, is_cancelled=ANY,
group_xml_path=ANY,
updateinfo_xml_path=ANY,
custom_metadata_dict=ANY)
mock_distributor_manager.return_value.update_distributor_config.\
assert_called_with(ANY, ANY, {'checksum_type': 'sha1'})
示例8: setUp
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()
示例9: test_publish_progress
def test_publish_progress(self):
global progress_status
progress_status = None
def set_progress(progress):
global progress_status
progress_status = progress
PROGRESS_FIELDS = ["num_success", "num_error", "items_left", "items_total", "error_details"]
publish_conduit = distributor_mocks.get_publish_conduit(pkg_dir=self.pkg_dir)
config = distributor_mocks.get_basic_config(
https_publish_dir=self.https_publish_dir,
http_publish_dir=self.http_publish_dir,
relative_url="rel_temp/",
generate_metadata=True,
http=True,
https=False,
)
distributor = YumDistributor()
repo = mock.Mock(spec=Repository)
repo.working_dir = self.repo_working_dir
repo.id = "test_progress_sync"
publish_conduit.set_progress = mock.Mock()
publish_conduit.set_progress.side_effect = set_progress
distributor.publish_repo(repo, publish_conduit, config)
self.assertTrue(progress_status is not None)
self.assertTrue("packages" in progress_status)
self.assertTrue(progress_status["packages"].has_key("state"))
self.assertEqual(progress_status["packages"]["state"], "FINISHED")
for field in PROGRESS_FIELDS:
self.assertTrue(field in progress_status["packages"])
self.assertTrue("distribution" in progress_status)
self.assertTrue(progress_status["distribution"].has_key("state"))
self.assertEqual(progress_status["distribution"]["state"], "FINISHED")
for field in PROGRESS_FIELDS:
self.assertTrue(field in progress_status["distribution"])
self.assertTrue("metadata" in progress_status)
self.assertTrue(progress_status["metadata"].has_key("state"))
self.assertEqual(progress_status["metadata"]["state"], "FINISHED")
self.assertTrue("publish_http" in progress_status)
self.assertEqual(progress_status["publish_http"]["state"], "FINISHED")
self.assertTrue("publish_https" in progress_status)
self.assertEqual(progress_status["publish_https"]["state"], "SKIPPED")
示例10: TestPublishThread
class TestPublishThread(threading.Thread):
def __init__(self, working_dir, pkg_dir, config):
threading.Thread.__init__(self)
self.repo = mock.Mock(spec=Repository)
self.repo.working_dir = working_dir
self.repo.id = "test_cancel_publish"
self.publish_conduit = distributor_mocks.get_publish_conduit(pkg_dir=pkg_dir)
self.publish_conduit.set_progress = mock.Mock()
self.publish_conduit.set_progress.side_effect = set_progress
self.config = config
self.distributor = YumDistributor()
def run(self):
self.distributor.publish_repo(self.repo, self.publish_conduit, self.config)
def cancel(self):
return self.distributor.cancel_publish_repo(None, None)
示例11: __init__
def __init__(self, working_dir, pkg_dir, config):
threading.Thread.__init__(self)
self.repo = mock.Mock(spec=Repository)
self.repo.working_dir = working_dir
self.repo.id = "test_cancel_publish"
self.publish_conduit = distributor_mocks.get_publish_conduit(pkg_dir=pkg_dir)
self.publish_conduit.set_progress = mock.Mock()
self.publish_conduit.set_progress.side_effect = set_progress
self.config = config
self.distributor = YumDistributor()
示例12: test_consumer_payload
def test_consumer_payload(self):
PAYLOAD_FIELDS = [ 'server_name', 'relative_path',
'protocols', 'gpg_keys', 'client_cert', 'ca_cert', 'repo_name']
http = True
https = True
relative_url = "/pub/content/"
gpgkey = ["test_gpg_key",]
auth_cert = open(os.path.join(self.data_dir, "cert.crt")).read()
auth_ca = open(os.path.join(self.data_dir, "ca.key")).read()
config = distributor_mocks.get_basic_config(relative_url=relative_url, http=http, https=https, auth_cert=auth_cert, auth_ca=auth_ca, gpgkey=gpgkey)
distributor = YumDistributor()
repo = mock.Mock(spec=Repository)
repo.working_dir = self.repo_working_dir
repo.id = "test_payload"
repo.display_name = 'Nice Repo'
payload = distributor.create_consumer_payload(repo, config, None)
for field in PAYLOAD_FIELDS:
self.assertTrue(field in payload)
self.assertTrue('http' in payload['protocols'])
self.assertTrue('https' in payload['protocols'])
示例13: test_empty_publish
def test_empty_publish(self):
repo = mock.Mock(spec=Repository)
repo.working_dir = self.repo_working_dir
repo.id = "test_empty_publish"
existing_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, http_publish_dir=self.http_publish_dir,
http=True, https=True)
distributor = YumDistributor()
report = distributor.publish_repo(repo, publish_conduit, config)
self.assertTrue(report.success_flag)
summary = report.summary
self.assertEqual(summary["num_package_units_attempted"], 0)
self.assertEqual(summary["num_package_units_published"], 0)
self.assertEqual(summary["num_package_units_errors"], 0)
expected_repo_https_publish_dir = os.path.join(self.https_publish_dir, repo.id).rstrip('/')
expected_repo_http_publish_dir = os.path.join(self.http_publish_dir, repo.id).rstrip('/')
self.assertEqual(summary["https_publish_dir"], expected_repo_https_publish_dir)
self.assertEqual(summary["http_publish_dir"], expected_repo_http_publish_dir)
details = report.details
self.assertEqual(len(details["errors"]), 0)
示例14: test_handle_symlinks
def test_handle_symlinks(self):
distributor = YumDistributor()
units = []
symlink_dir = os.path.join(self.temp_dir, "symlinks")
num_links = 5
for index in range(0,num_links):
relpath = "file_%s.rpm" % (index)
sp = os.path.join(self.pkg_dir, relpath)
open(sp, "a") # Create an empty file
if index % 2 == 0:
# Ensure we can support symlinks in subdirs
relpath = os.path.join("a", "b", "c", relpath)
u = Unit("rpm", "unit_key_%s" % (index), {"relativepath":relpath}, sp)
units.append(u)
status, errors = distributor.handle_symlinks(units, symlink_dir)
self.assertTrue(status)
self.assertEqual(len(errors), 0)
for u in units:
symlink_path = os.path.join(symlink_dir, u.metadata["relativepath"])
self.assertTrue(os.path.exists(symlink_path))
self.assertTrue(os.path.islink(symlink_path))
target = os.readlink(symlink_path)
self.assertEqual(target, u.storage_path)
# Test republish is successful
status, errors = distributor.handle_symlinks(units, symlink_dir)
self.assertTrue(status)
self.assertEqual(len(errors), 0)
for u in units:
symlink_path = os.path.join(symlink_dir, u.metadata["relativepath"])
self.assertTrue(os.path.exists(symlink_path))
self.assertTrue(os.path.islink(symlink_path))
target = os.readlink(symlink_path)
self.assertEqual(target, u.storage_path)
# Simulate a package is deleted
os.unlink(units[0].storage_path)
status, errors = distributor.handle_symlinks(units, symlink_dir)
self.assertFalse(status)
self.assertEqual(len(errors), 1)
示例15: test_split_path
def test_split_path(self):
distributor = YumDistributor()
test_path = "/a"
pieces = distributor.split_path(test_path)
self.assertEqual(len(pieces), 1)
self.assertTrue(pieces[0], test_path)
test_path = "/a/"
pieces = distributor.split_path(test_path)
self.assertEqual(len(pieces), 1)
self.assertTrue(pieces[0], test_path)
test_path = "/a"
pieces = distributor.split_path(test_path)
self.assertEqual(len(pieces), 1)
self.assertTrue(pieces[0], test_path)
test_path = "a/"
pieces = distributor.split_path(test_path)
self.assertEqual(len(pieces), 1)
self.assertTrue(pieces[0], test_path)
test_path = "/a/bcde/f/ghi/j"
pieces = distributor.split_path(test_path)
self.assertEqual(len(pieces), 5)
self.assertTrue(os.path.join(*pieces), test_path)
test_path = "a/bcde/f/ghi/j"
pieces = distributor.split_path(test_path)
self.assertEqual(len(pieces), 5)
self.assertTrue(os.path.join(*pieces), test_path)
test_path = "a/bcde/f/ghi/j/"
pieces = distributor.split_path(test_path)
self.assertEqual(len(pieces), 5)
self.assertTrue(os.path.join(*pieces), test_path)
test_path = "/a/bcde/f/ghi/j/"
pieces = distributor.split_path(test_path)
self.assertEqual(len(pieces), 5)
self.assertTrue(os.path.join(*pieces), test_path)