当前位置: 首页>>代码示例>>Python>>正文


Python YumImporter.cancel_sync_repo方法代码示例

本文整理汇总了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)
开发者ID:jessegonzalez,项目名称:pulp_rpm,代码行数:61,代码来源:test_rpms.py


注:本文中的yum_importer.importer.YumImporter.cancel_sync_repo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。