本文整理匯總了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)