本文整理匯總了Python中yum_distributor.distributor.YumDistributor.publish_repo方法的典型用法代碼示例。如果您正苦於以下問題:Python YumDistributor.publish_repo方法的具體用法?Python YumDistributor.publish_repo怎麽用?Python YumDistributor.publish_repo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yum_distributor.distributor.YumDistributor
的用法示例。
在下文中一共展示了YumDistributor.publish_repo方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_publish
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import publish_repo [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_custom_metadata_publish
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import publish_repo [as 別名]
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))
示例3: test_distributor_removed
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import publish_repo [as 別名]
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_progress
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import publish_repo [as 別名]
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")
示例5: TestPublishThread
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import publish_repo [as 別名]
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)
示例6: test_empty_publish
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import publish_repo [as 別名]
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)
示例7: test_publish_comps
# 需要導入模塊: from yum_distributor.distributor import YumDistributor [as 別名]
# 或者: from yum_distributor.distributor.YumDistributor import publish_repo [as 別名]
def test_publish_comps(self):
repo = mock.Mock(spec=Repository)
repo.id = "test_publish_comps"
repo.working_dir = self.working_dir
# Create 2 pkg groups
grp_a = self.create_dummy_pkg_group_unit(repo.id, "group_a")
grp_b = self.create_dummy_pkg_group_unit(repo.id, "group_b")
# Create 2 pkg categories
cat_a = self.create_dummy_pkg_category_unit(repo.id, "cat_a", ["group_a"])
cat_b = self.create_dummy_pkg_category_unit(repo.id, "cat_b", ["group_b"])
# Add the grps/cats to the publish_conduit
publish_conduit = distributor_mocks.get_publish_conduit(
existing_units=[grp_a, grp_b, cat_a, cat_b])
config = distributor_mocks.get_basic_config(relative_url=repo.id,
http=True, https=True, generate_metadata=True)
# Publish the repo, be sure 'generate_metadata' is True
yum_distributor = YumDistributor()
report = yum_distributor.publish_repo(repo, publish_conduit, config)
self.assertTrue(report.success_flag)
self.assertEqual(report.summary["num_package_groups_published"], 2)
self.assertEqual(report.summary["num_package_categories_published"], 2)
expected_comps_xml = os.path.join(repo.working_dir, "comps.xml")
self.assertTrue(os.path.exists(expected_comps_xml))
#
# Find the path that createrepo added the comps.xml as
#
repomd_xml = os.path.join(repo.working_dir, "repodata", "repomd.xml")
self.assertTrue(os.path.exists(repomd_xml))
md_types = util.get_repomd_filetypes(repomd_xml)
self.assertTrue('group' in md_types)
groups_path = util.get_repomd_filetype_path(repomd_xml, "group")
self.assertTrue(groups_path)
groups_path = os.path.join(repo.working_dir, groups_path)
self.assertTrue(os.path.exists(groups_path))
#
# Use yum to read the repodata and verify the info written matches
# our dummy data
#
yc = yum.comps.Comps()
yc.add(groups_path)
self.assertEqual(len(yc.groups), 2)
self.assertEqual(len(yc.categories), 2)
for g in yc.groups:
eg = None
if g.groupid == "group_a":
eg = grp_a
elif g.groupid == "group_b":
eg = grp_b
else:
# Unexpected error
self.assertTrue(False)
self.assertEqual(g.name, eg.metadata["name"])
self.assertEqual(g.description, eg.metadata["description"])
self.assertEqual(g.user_visible, eg.metadata["user_visible"])
self.assertEqual(g.display_order, eg.metadata["display_order"])
self.assertEqual(g.default, eg.metadata["default"])
self.assertEqual(g.langonly, eg.metadata["langonly"])
for pkg_name in g.mandatory_packages:
self.assertTrue(pkg_name in eg.metadata["mandatory_package_names"])
for pkg_name in g.optional_packages:
self.assertTrue(pkg_name in eg.metadata["optional_package_names"])
for pkg_name in g.default_packages:
self.assertTrue(pkg_name in eg.metadata["default_package_names"])
#
# Below is related to pymongo not liking dots in a pkg_name
# We are storing conditional_package_names as a list of tuples, (name, values)
# convert to a dictionary to make it easier to compare against yum's data
#
cond_lookup = {}
for expected_name, expected_values in eg.metadata["conditional_package_names"]:
cond_lookup[expected_name] = expected_values
for pkg_name in g.conditional_packages:
# We are converting our expected value to a str below to match the behavior
# we see from yum
self.assertEqual(g.conditional_packages[pkg_name], str(cond_lookup[pkg_name]))
for c in yc.categories:
ec = None
if c.categoryid == "cat_a":
ec = cat_a
elif c.categoryid == "cat_b":
ec = cat_b
else:
# Unexpected error
self.assertTrue(False)
self.assertEqual(c.name, ec.metadata["name"])
self.assertEqual(c.description, ec.metadata["description"])
self.assertEqual(c.display_order, ec.metadata["display_order"])
self.assertEqual(len(c._groups), len(ec.metadata["packagegroupids"]))
for grpid in c._groups:
self.assertTrue(grpid in ec.metadata["packagegroupids"])