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


Python MachineStateManager.add_machine_state方法代码示例

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


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

示例1: test_watch_machine_changes_ignores_running_machine

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_watch_machine_changes_ignores_running_machine(self):
        """
        If there is an existing machine instance and state, when a
        new machine state is added, the existing instance is preserved,
        and a new instance is created.
        """
        manager = MachineStateManager(self.client)
        machine_state0 = yield manager.add_machine_state()
        machines = yield self.agent.provider.start_machine(
            {"machine-id": machine_state0.id})
        machine = machines.pop()
        yield machine_state0.set_instance_id(machine.instance_id)

        machine_state1 = yield manager.add_machine_state()

        machines = yield self.agent.provider.get_machines()
        self.assertEquals(len(machines), 1)

        yield self.agent.watch_machine_changes(
            None, [machine_state0.id, machine_state1.id])

        machines = yield self.agent.provider.get_machines()
        self.assertEquals(len(machines), 2)

        instance_id = yield machine_state1.get_instance_id()
        self.assertEqual(instance_id, 1)
开发者ID:mcclurmc,项目名称:juju,代码行数:28,代码来源:test_provision.py

示例2: test_open_close_ports_on_machine

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_open_close_ports_on_machine(self):
        """Verify opening/closing ports on a machine works properly.

        In particular this is done without watch support."""
        manager = MachineStateManager(self.client)
        machine = yield manager.add_machine_state()
        yield self.firewall_manager.process_machine(machine)

        # Expose a service
        wordpress = yield self.add_service("wordpress")
        yield wordpress.set_exposed_flag()
        wordpress_0 = yield wordpress.add_unit_state()
        yield wordpress_0.open_port(80, "tcp")
        yield wordpress_0.open_port(443, "tcp")
        yield wordpress_0.assign_to_machine(machine)
        yield self.firewall_manager.open_close_ports_on_machine(machine.id)
        self.assertEqual((yield self.get_provider_ports(machine)),
                         set([(80, "tcp"), (443, "tcp")]))
        self.assertIn("Opened 80/tcp on provider machine 0",
                      self.output.getvalue())
        self.assertIn("Opened 443/tcp on provider machine 0",
                      self.output.getvalue())

        # Now change port setup
        yield wordpress_0.open_port(8080, "tcp")
        yield wordpress_0.close_port(443, "tcp")
        yield self.firewall_manager.open_close_ports_on_machine(machine.id)
        self.assertEqual((yield self.get_provider_ports(machine)),
                         set([(80, "tcp"), (8080, "tcp")]))
        self.assertIn("Opened 8080/tcp on provider machine 0",
                      self.output.getvalue())
        self.assertIn("Closed 443/tcp on provider machine 0",
                      self.output.getvalue())
开发者ID:mcclurmc,项目名称:juju,代码行数:35,代码来源:test_firewall.py

示例3: test_open_close_ports_on_machine_not_yet_provided

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_open_close_ports_on_machine_not_yet_provided(self):
        """Verify that opening/closing ports will eventually succeed
        once a machine is provided.
        """
        manager = MachineStateManager(self.client)
        machine = yield manager.add_machine_state()
        wordpress = yield self.add_service("wordpress")
        yield wordpress.set_exposed_flag()
        wordpress_0 = yield wordpress.add_unit_state()
        yield wordpress_0.open_port(80, "tcp")
        yield wordpress_0.open_port(443, "tcp")
        yield wordpress_0.assign_to_machine(machine)

        # First attempt to open ports quietly fails (except for
        # logging) because the machine has not yet been provisioned
        yield self.firewall_manager.open_close_ports_on_machine(machine.id)
        self.assertIn("No provisioned machine for machine 0",
                      self.output.getvalue())

        yield self.provide_machine(machine)
        # Machine is now provisioned (normally visible in the
        # provisioning agent through periodic rescan and corresponding
        # watches)
        yield self.firewall_manager.open_close_ports_on_machine(machine.id)
        self.assertEqual((yield self.get_provider_ports(machine)),
                         set([(80, "tcp"), (443, "tcp")]))
开发者ID:mcclurmc,项目名称:juju,代码行数:28,代码来源:test_firewall.py

示例4: test_transient_provider_error_on_get_machines

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_transient_provider_error_on_get_machines(self):
        manager = MachineStateManager(self.client)
        machine_state0 = yield manager.add_machine_state()

        mock_provider = self.mocker.patch(self.agent.provider)
        mock_provider.get_machines()
        self.mocker.result(fail(ProviderInteractionError()))

        mock_provider.get_machines()
        self.mocker.passthrough()

        self.mocker.replay()
        try:
            yield self.agent.process_machines([machine_state0.id])
        except:
            self.fail("Should not raise")

        instance_id = yield machine_state0.get_instance_id()
        self.assertEqual(instance_id, None)

        yield self.agent.process_machines(
            [machine_state0.id])

        instance_id = yield machine_state0.get_instance_id()
        self.assertEqual(instance_id, 0)
        self.assertIn(
            "Cannot get machine list",
            self.output.getvalue())
开发者ID:mcclurmc,项目名称:juju,代码行数:30,代码来源:test_provision.py

示例5: test_transient_provider_error_on_start_machine

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_transient_provider_error_on_start_machine(self):
        """
        If there's an error when processing changes, the agent should log
        the error and continue.
        """
        manager = MachineStateManager(self.client)
        machine_state0 = yield manager.add_machine_state()
        machine_state1 = yield manager.add_machine_state()

        mock_provider = self.mocker.patch(self.agent.provider)
        mock_provider.start_machine({"machine-id": 0})
        self.mocker.result(fail(ProviderInteractionError()))

        mock_provider.start_machine({"machine-id": 1})
        self.mocker.passthrough()
        self.mocker.replay()

        yield self.agent.watch_machine_changes(
            [], [machine_state0.id, machine_state1.id])

        machine1_instance_id = yield machine_state1.get_instance_id()
        self.assertEqual(machine1_instance_id, 0)
        self.assertIn(
            "Cannot process machine 0",
            self.output.getvalue())
开发者ID:mcclurmc,项目名称:juju,代码行数:27,代码来源:test_provision.py

示例6: test_process_machines_non_concurrency

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_process_machines_non_concurrency(self):
        """
        Process machines should only be executed serially by an
        agent.
        """
        manager = MachineStateManager(self.client)
        machine_state0 = yield manager.add_machine_state()
        machine_state1 = yield manager.add_machine_state()

        call_1 = self.agent.process_machines([machine_state0.id])

        # The second call should return immediately due to the
        # instance attribute guard.
        call_2 = self.agent.process_machines([machine_state1.id])
        self.assertEqual(call_2.called, True)
        self.assertEqual(call_2.result, False)

        # The first call should have started a provider machine
        yield call_1

        machines = yield self.agent.provider.get_machines()
        self.assertEquals(len(machines), 1)

        instance_id_0 = yield machine_state0.get_instance_id()
        self.assertEqual(instance_id_0, 0)

        instance_id_1 = yield machine_state1.get_instance_id()
        self.assertEqual(instance_id_1, None)
开发者ID:mcclurmc,项目名称:juju,代码行数:30,代码来源:test_provision.py

示例7: test_open_close_ports_on_unassigned_machine

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
 def test_open_close_ports_on_unassigned_machine(self):
     """Verify corner case that nothing happens on an unassigned machine."""
     manager = MachineStateManager(self.client)
     machine = yield manager.add_machine_state()
     yield self.provide_machine(machine)
     yield self.firewall_manager.process_machine(machine)
     yield self.firewall_manager.open_close_ports_on_machine(machine.id)
     self.assertEqual((yield self.get_provider_ports(machine)),
                      set())
开发者ID:mcclurmc,项目名称:juju,代码行数:11,代码来源:test_firewall.py

示例8: test_machine_state_reflects_invalid_provider_state

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_machine_state_reflects_invalid_provider_state(self):
        """
        If a machine state has an invalid instance_id, it should be detected,
        and a new machine started and the machine state updated with the
        new instance_id.
        """
        machine_manager = MachineStateManager(self.client)
        m1 = yield machine_manager.add_machine_state()
        yield m1.set_instance_id("zebra")

        m2 = yield machine_manager.add_machine_state()
        yield self.agent.watch_machine_changes(None, [m1.id, m2.id])

        m1_instance_id = yield m1.get_instance_id()
        self.assertEqual(m1_instance_id, 0)

        m2_instance_id = yield m2.get_instance_id()
        self.assertEqual(m2_instance_id, 1)
开发者ID:mcclurmc,项目名称:juju,代码行数:20,代码来源:test_provision.py

示例9: ProvisioningTestBase

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
class ProvisioningTestBase(AgentTestBase):

    agent_class = ProvisioningAgent

    @inlineCallbacks
    def setUp(self):
        yield super(ProvisioningTestBase, self).setUp()
        self.machine_manager = MachineStateManager(self.client)

    def add_machine_state(self, constraints=None):
        return self.machine_manager.add_machine_state(
            constraints or series_constraints)
开发者ID:anbangr,项目名称:trusted-juju,代码行数:14,代码来源:test_provision.py

示例10: test_transient_unhandled_error_in_process_machines

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_transient_unhandled_error_in_process_machines(self):
        """Verify that watch_machine_changes handles the exception.

        Provider implementations may use libraries like txaws that do
        not handle every error. However, this should not stop the
        watch from re-establishing itself, as will be the case if the
        exception is not caught.
        """
        manager = MachineStateManager(self.client)
        machine_state0 = yield manager.add_machine_state()
        machine_state1 = yield manager.add_machine_state()

        # Simulate a failure scenario seen occasionally when working
        # with OpenStack and txaws
        mock_agent = self.mocker.patch(self.agent)

        # Simulate transient error
        mock_agent.process_machines([machine_state0.id])
        self.mocker.result(fail(
                TypeError("'NoneType' object is not iterable")))

        # Let it succeed on second try. In this case, the scenario is
        # that the watch triggered before the periodic_machine_check
        # was run again
        mock_agent.process_machines([machine_state0.id, machine_state1.id])
        self.mocker.passthrough()
        self.mocker.replay()

        # Verify that watch_machine_changes does not fail even in the case of
        # the transient error, although no work was done
        try:
            yield self.agent.watch_machine_changes([], [machine_state0.id])
        except:
            self.fail("Should not raise")

        instance_id = yield machine_state0.get_instance_id()
        self.assertEqual(instance_id, None)

        # Second attempt, verifiy it did in fact process the machine
        yield self.agent.watch_machine_changes(
            [machine_state0.id], [machine_state0.id, machine_state1.id])
        self.assertEqual((yield machine_state0.get_instance_id()), 0)
        self.assertEqual((yield machine_state1.get_instance_id()), 1)

        # But only after attempting and failing the first time
        self.assertIn(
            "Got unexpected exception in processing machines, will retry",
            self.output.getvalue())
        self.assertIn(
            "'NoneType' object is not iterable",
            self.output.getvalue())
开发者ID:mcclurmc,项目名称:juju,代码行数:53,代码来源:test_provision.py

示例11: get_agent_config

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def get_agent_config(self):
        # gets invoked by AgentTestBase.setUp
        options = yield super(MachineAgentTest, self).get_agent_config()
        machine_state_manager = MachineStateManager(self.client)

        self.machine_state = yield machine_state_manager.add_machine_state()

        self.change_environment(
            JUJU_MACHINE_ID="0",
            JUJU_HOME=self.juju_directory)
        options["machine_id"] = str(self.machine_state.id)

        # Start the agent with watching enabled
        returnValue(options)
开发者ID:mcclurmc,项目名称:juju,代码行数:16,代码来源:test_machine.py

示例12: test_open_close_ports_on_machine_will_retry

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_open_close_ports_on_machine_will_retry(self):
        """Verify port mgmt for a machine will retry if there's a failure."""
        mock_provider = self.mocker.patch(MachineProvider)
        mock_provider.open_port(MATCH_MACHINE, 0, 80, "tcp")
        self.mocker.result(fail(
                TypeError("'NoneType' object is not iterable")))
        mock_provider.open_port(MATCH_MACHINE, 0, 80, "tcp")
        self.mocker.result(fail(
                ProviderInteractionError("Some sort of EC2 problem")))
        mock_provider.open_port(MATCH_MACHINE, 0, 80, "tcp")
        self.mocker.passthrough()
        self.mocker.replay()

        manager = MachineStateManager(self.client)
        machine = yield manager.add_machine_state()
        yield self.provide_machine(machine)

        # Expose a service and attempt to open/close ports. The first
        # attempt will see the simulated failure.
        wordpress = yield self.add_service("wordpress")
        yield wordpress.set_exposed_flag()
        wordpress_0 = yield wordpress.add_unit_state()
        yield wordpress_0.assign_to_machine(machine)
        yield self.firewall_manager.process_machine(machine)

        yield wordpress_0.open_port(80, "tcp")
        yield self.firewall_manager.open_close_ports_on_machine(machine.id)
        self.assertEqual((yield self.get_provider_ports(machine)),
                         set())
        self.assertIn(
            "Got exception in opening/closing ports, will retry",
            self.output.getvalue())
        self.assertIn("TypeError: 'NoneType' object is not iterable",
                      self.output.getvalue())

        # Retries will now happen in the periodic recheck. First one
        # still fails due to simulated error.
        yield self.firewall_manager.process_machine(machine)
        self.assertEqual((yield self.get_provider_ports(machine)),
                         set())
        self.assertIn("ProviderInteractionError: Some sort of EC2 problem",
                      self.output.getvalue())

        # Third time is the charm in the mock setup, the recheck succeeds
        yield self.firewall_manager.process_machine(machine)
        self.assertEqual((yield self.get_provider_ports(machine)),
                         set([(80, "tcp")]))
        self.assertIn("Opened 80/tcp on provider machine 0",
                      self.output.getvalue())
开发者ID:mcclurmc,项目名称:juju,代码行数:51,代码来源:test_firewall.py

示例13: test_process_machine_is_called

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_process_machine_is_called(self):
        """Verify FirewallManager is called when machines are processed"""
        from juju.state.firewall import FirewallManager
        mock_manager = self.mocker.patch(FirewallManager)

        seen = []

        def record_machine(machine):
            seen.append(machine)
            return succeed(True)

        mock_manager.process_machine(MATCH_MACHINE_STATE)
        self.mocker.call(record_machine)
        self.mocker.replay()

        machine_manager = MachineStateManager(self.client)
        machine_state = yield machine_manager.add_machine_state()
        yield self.agent.process_machines([machine_state.id])
        self.assertEqual(seen, [machine_state])
开发者ID:mcclurmc,项目名称:juju,代码行数:21,代码来源:test_provision.py

示例14: test_process_machine_ignores_stop_watcher

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_process_machine_ignores_stop_watcher(self):
        """Verify that process machine catches `StopWatcher`.

        `process_machine` calls `open_close_ports_on_machine`, which
        as verified in an earlier test, raises a `StopWatcher`
        exception to shutdown watches that use it in the event of
        agent shutdown. Verify this dual usage does not cause issues
        while the agent is being stopped for this usage.
        """
        mock_provider = self.mocker.patch(MachineProvider)
        mock_provider.open_port(MATCH_MACHINE, 0, 80, "tcp")
        self.mocker.result(fail(
                TypeError("'NoneType' object is not iterable")))
        self.mocker.replay()

        manager = MachineStateManager(self.client)
        machine = yield manager.add_machine_state()
        yield self.provide_machine(machine)

        # Expose a service and attempt to open/close ports. The first
        # attempt will see the simulated failure.
        wordpress = yield self.add_service("wordpress")
        yield wordpress.set_exposed_flag()
        wordpress_0 = yield wordpress.add_unit_state()
        yield wordpress_0.assign_to_machine(machine)
        yield self.firewall_manager.process_machine(machine)

        yield wordpress_0.open_port(80, "tcp")
        yield self.firewall_manager.open_close_ports_on_machine(machine.id)
        self.assertEqual((yield self.get_provider_ports(machine)),
                         set())
        self.assertIn(
            "Got exception in opening/closing ports, will retry",
            self.output.getvalue())
        self.assertIn("TypeError: 'NoneType' object is not iterable",
                      self.output.getvalue())

        # Stop the provisioning agent
        self.stop()

        # But retries can potentially still happening anyway, just
        # make certain nothing bad happens.
        yield self.firewall_manager.process_machine(machine)
开发者ID:mcclurmc,项目名称:juju,代码行数:45,代码来源:test_firewall.py

示例15: test_start_agent_with_watch

# 需要导入模块: from juju.state.machine import MachineStateManager [as 别名]
# 或者: from juju.state.machine.MachineStateManager import add_machine_state [as 别名]
    def test_start_agent_with_watch(self):
        mock_reactor = self.mocker.patch(reactor)
        mock_reactor.callLater(
            self.agent.machine_check_period,
            self.agent.periodic_machine_check)
        self.mocker.replay()

        self.agent.set_watch_enabled(True)
        yield self.agent.start()

        manager = MachineStateManager(self.client)
        machine_state0 = yield manager.add_machine_state()
        exists_d, watch_d = self.client.exists_and_watch(
            "/machines/%s" % machine_state0.internal_id)
        yield exists_d
        # Wait for the provisioning agent to wake and modify
        # the machine id.
        yield watch_d
        instance_id = yield machine_state0.get_instance_id()
        self.assertEqual(instance_id, 0)
开发者ID:mcclurmc,项目名称:juju,代码行数:22,代码来源:test_provision.py


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