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


Python Service.stop方法代码示例

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


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

示例1: WhenAgentRunsAsRabbitGoesUpAndDown

# 需要导入模块: from tests.util.services import Service [as 别名]
# 或者: from tests.util.services.Service import stop [as 别名]
class WhenAgentRunsAsRabbitGoesUpAndDown(object):
    """Tests the agent is ok when Rabbit
    """

    def __init__(self):
        self.rabbit = Rabbit()
        self.send_after_reconnect_errors = 0
        self.tolerated_send_errors = 0

    @after_class
    def stop_agent(self):
        self.agent.stop()

    def _send(self):
        original_queue_count = self.rabbit.get_queue_items()
        @time_out(5)
        def send_msg_with_timeout():
            self.rabbit.declare_queue(topic_name())
            version = rpc.call(context.get_admin_context(),
                               topic_name(),
                    {"method": "version",
                     "args": {"package_name": "dpkg"}
                })
            return { "status":"good", "version": version }
        try:
            return send_msg_with_timeout()
        except Exception as e:
            # If the Python side works, we should at least see an item waiting
            # in the queue.
            # Whether we see this determines if the failure to send is Nova's
            # fault or Sneaky Petes.
            print("Error making RPC call: %s" % e)
            print("Original queue count = %d, "
                  "current count = %d" % (original_queue_count,
                                          self.rabbit.get_queue_items()))

            # In the Kombu driver there is a bug where after restarting rabbit
            # the first message to be sent fails with a broken pipe. So here we
            # tolerate one such bug but no more.
            if not isinstance(e, TimeoutError):
                self.send_after_reconnect_errors += 1
                if self.send_after_reconnect_errors > self.tolerated_send_errors:
                    fail("Exception while making RPC call: %s" % e)
            if self.rabbit.get_queue_items() > original_queue_count:
                return { "status":"bad", "blame":"agent"}
            else:
                return { "status":"bad", "blame":"host"}

    def _send_allow_for_host_bug(self):
        while True:
            result = self._send()
            if result['status'] == "good":
                return result["version"]
            else:
                if result['blame'] == "agent":
                    fail("Nova Host put a message on the queue but the agent "
                         "never responded.")

    @test
    def check_agent_path_is_correct(self):
        """Make sure the agent binary listed in the config is correct."""
        self.agent_bin = str(test_config.values["agent_bin"])
        nova_conf = str(test_config.values["nova_conf"])
        assert_true(path.exists(self.agent_bin),
                    "Agent not found at path: %s" % self.agent_bin)
        self.agent = Service(cmd=[self.agent_bin,  "--flagfile=%s" % nova_conf,
                                  "--rabbit_reconnect_wait_time=1",
                                  "--preset_instance_id=-99"])

    @test(depends_on=[check_agent_path_is_correct])
    @time_out(60)
    def send_agent_a_message(self):
        self.rabbit.start()
        self.agent.start(time_out=30)
        result = self._send()
        print("RESULT:%s" % result)
        assert_equal(result['status'], "good")

    @test(depends_on=[send_agent_a_message])
    @time_out(30)
    def make_sure_we_can_identify_an_agent_failure(self):
        # This is so confusing, but it has to be, so listen up:
        # Nova code has issues sending messages so we either don't test this
        # or make allowances for Kombu's bad behavior. This test runs before
        # we start the agent and makes sure if Nova successfully sends a
        # message and the agent never answers it this test can identify that
        # and fail.
        self.agent.stop()
        result = self._send()
        assert_equal(result['status'], 'bad')
        assert_equal(result['blame'], 'agent')

    @test(depends_on=[make_sure_we_can_identify_an_agent_failure])
    def stop_rabbit(self):
        if self.rabbit.is_alive:
            self.rabbit.stop()
        assert_false(self.rabbit.is_alive)
        self.rabbit.reset()

    @test(depends_on=[check_agent_path_is_correct, stop_rabbit])
#.........这里部分代码省略.........
开发者ID:TimSimpsonR,项目名称:reddwarf_lite-integration,代码行数:103,代码来源:amqp_restarts.py


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