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


Python EtcdAPI._periodically_resync方法代码示例

本文整理汇总了Python中calico.felix.fetcd.EtcdAPI._periodically_resync方法的典型用法代码示例。如果您正苦于以下问题:Python EtcdAPI._periodically_resync方法的具体用法?Python EtcdAPI._periodically_resync怎么用?Python EtcdAPI._periodically_resync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在calico.felix.fetcd.EtcdAPI的用法示例。


在下文中一共展示了EtcdAPI._periodically_resync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_periodic_resync_disabled

# 需要导入模块: from calico.felix.fetcd import EtcdAPI [as 别名]
# 或者: from calico.felix.fetcd.EtcdAPI import _periodically_resync [as 别名]
 def test_periodic_resync_disabled(self, m_sleep, m_spawn, m_etcd_watcher):
     m_etcd_watcher.return_value.configured = Mock(spec=Event)
     m_config = Mock(spec=Config)
     m_hosts_ipset = Mock(spec=IpsetActor)
     api = EtcdAPI(m_config, m_hosts_ipset)
     m_config.RESYNC_INTERVAL = 0
     with patch.object(api, "force_resync") as m_force_resync:
         m_force_resync.side_effect = Exception()
         api._periodically_resync()
开发者ID:nikolayvoronchikhin,项目名称:calico,代码行数:11,代码来源:test_fetcd.py

示例2: TestEtcdAPI

# 需要导入模块: from calico.felix.fetcd import EtcdAPI [as 别名]
# 或者: from calico.felix.fetcd.EtcdAPI import _periodically_resync [as 别名]
class TestEtcdAPI(BaseTestCase):
    def setUp(self):
        super(TestEtcdAPI, self).setUp()
        self.m_config = Mock(spec=Config)
        self.m_config.ETCD_ADDRS = [ETCD_ADDRESS]
        self.m_config.ETCD_SCHEME = "http"
        self.m_config.ETCD_KEY_FILE = None
        self.m_config.ETCD_CERT_FILE = None
        self.m_config.ETCD_CA_FILE = None
        self.m_hosts_ipset = Mock(spec=IpsetActor)
        with patch("calico.felix.fetcd._FelixEtcdWatcher",
                   autospec=True) as m_etcd_watcher:
            with patch("gevent.spawn", autospec=True) as m_spawn:
                self.api = EtcdAPI(self.m_config, self.m_hosts_ipset)
        self.m_spawn = m_spawn
        self.m_etcd_watcher = m_etcd_watcher.return_value
        self.m_etcd_watcher.load_config = Mock(spec=Event)
        self.m_etcd_watcher.begin_polling = Mock(spec=Event)
        self.m_etcd_watcher.configured = Mock(spec=Event)

    def test_create(self):
        self.m_etcd_watcher.assert_has_calls([
            call.link(self.api._on_worker_died),
        ])
        self.assertFalse(self.m_spawn.called)

    def test_on_start(self):
        with patch.object(self.api._resync_greenlet, "start") as m_resync_st, \
                patch.object(self.api._status_reporting_greenlet, "start") as m_stat_start, \
                patch.object(self.api.status_reporter, "start") as m_sr_start:
            self.api._on_actor_started()
        m_resync_st.assert_called_once_with()
        m_stat_start.assert_called_once_with()
        m_sr_start.assert_called_once_with()
        self.m_etcd_watcher.start.assert_called_once_with()

    @patch("gevent.sleep", autospec=True)
    def test_periodic_resync_mainline(self, m_sleep):
        self.m_config.RESYNC_INTERVAL = 10
        m_configured = Mock(spec=Event)
        self.m_etcd_watcher.configured = m_configured
        with patch.object(self.api, "force_resync") as m_force_resync:
            m_force_resync.side_effect = ExpectedException()
            self.assertRaises(ExpectedException,
                              self.api._periodically_resync)
        m_configured.wait.assert_called_once_with()
        m_sleep.assert_called_once_with(ANY)
        sleep_time = m_sleep.call_args[0][0]
        self.assertTrue(sleep_time >= 10)
        self.assertTrue(sleep_time <= 12)

    @patch("gevent.sleep", autospec=True)
    def test_periodic_resync_disabled(self, m_sleep):
        self.m_config.RESYNC_INTERVAL = 0
        self.m_etcd_watcher.configured = Mock(spec=Event)
        with patch.object(self.api, "force_resync") as m_force_resync:
            m_force_resync.side_effect = Exception()
            self.api._periodically_resync()

    def test_force_resync(self):
        self.m_config.REPORT_ENDPOINT_STATUS = True
        with patch.object(self.api, "status_reporter") as m_status_rep:
            self.api.force_resync(async=True)
            self.step_actor(self.api)
        m_status_rep.resync.assert_called_once_with(async=True)
        self.assertTrue(self.m_etcd_watcher.resync_requested)

    def test_load_config(self):
        result = self.api.load_config(async=True)
        self.step_actor(self.api)
        conf = result.get()
        self.assertEqual(conf, self.m_etcd_watcher.configured)
        self.m_etcd_watcher.load_config.set.assert_called_once_with()

    def test_start_watch(self):
        m_splitter = Mock()
        self.api.load_config(async=True)
        result = self.api.start_watch(m_splitter, async=True)
        self.step_actor(self.api)
        self.m_etcd_watcher.load_config.set.assert_called_once_with()
        self.assertEqual(self.m_etcd_watcher.splitter, m_splitter)
        self.m_etcd_watcher.begin_polling.set.assert_called_once_with()

    @patch("sys.exit", autospec=True)
    def test_on_worker_died(self, m_exit):
        glet = gevent.spawn(lambda: None)
        glet.link(self.api._on_worker_died)
        glet.join(1)
        m_exit.assert_called_once_with(1)
开发者ID:is00hcw,项目名称:calico,代码行数:91,代码来源:test_fetcd.py


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