本文整理汇总了Python中yum_importer.importer.YumImporter.cancel_sync_repo方法的典型用法代码示例。如果您正苦于以下问题:Python YumImporter.cancel_sync_repo方法的具体用法?Python YumImporter.cancel_sync_repo怎么用?Python YumImporter.cancel_sync_repo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yum_importer.importer.YumImporter
的用法示例。
在下文中一共展示了YumImporter.cancel_sync_repo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cancel_sync
# 需要导入模块: from yum_importer.importer import YumImporter [as 别名]
# 或者: from yum_importer.importer.YumImporter import cancel_sync_repo [as 别名]
def test_cancel_sync(self):
global updated_progress
updated_progress = None
def set_progress(progress):
global updated_progress
updated_progress = progress
class SyncThread(threading.Thread):
def __init__(self, importer, repo, sync_conduit, config):
threading.Thread.__init__(self)
self.importer = importer
self.repo = repo
self.sync_conduit = sync_conduit
self.config = config
self.status = None
self.summary = None
self.details = None
self.finished = False
def run(self):
status, summary, details = self.importer._sync_repo(self.repo, self.sync_conduit, self.config)
self.status = status
self.summary = summary
self.details = details
self.finished = True
feed_url = "http://repos.fedorapeople.org/repos/pulp/pulp/v1/testing/6Server/x86_64/"
repo = mock.Mock(spec=Repository)
repo.working_dir = self.working_dir
repo.id = "test_cancel_sync"
sync_conduit = importer_mocks.get_sync_conduit(existing_units=[], pkg_dir=self.pkg_dir)
sync_conduit.set_progress = mock.Mock()
sync_conduit.set_progress.side_effect = set_progress
config = importer_mocks.get_basic_config(feed_url=feed_url, num_threads=1, max_speed=25)
importer = YumImporter()
sync_thread = SyncThread(importer, repo, sync_conduit, config)
sync_thread.start()
# Wait to confirm that sync has started and we are downloading packages
# We are intentionally setting the 'config' to use 1 thread and max_speed to be low so we will
# have a chance to cancel the sync before it completes
for i in range(30):
if updated_progress and updated_progress.has_key("content") and updated_progress["content"].has_key("state") \
and updated_progress["content"]["state"] == "IN_PROGRESS":
break
time.sleep(1)
self.assertEquals(updated_progress["metadata"]["state"], "FINISHED")
self.assertEquals(updated_progress["content"]["state"], "IN_PROGRESS")
###
### Issue Cancel
###
importer.cancel_sync_repo(None, None)
# Wait for cancel of sync
for i in range(45):
if sync_thread.finished:
break
time.sleep(1)
self.assertEquals(updated_progress["content"]["state"], "CANCELED")
self.assertFalse(sync_thread.status)