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.
        """
        machine_state0 = yield self.add_machine_state(
            dummy_cs.parse(["cpu=10"]).with_series("series"))
        machine_state1 = yield self.add_machine_state(
            dummy_cs.parse(["cpu=20"]).with_series("series"))

        mock_provider = self.mocker.patch(self.agent.provider)
        mock_provider.start_machine({
            "machine-id": 0, "constraints": {
                "arch": "amd64", "cpu": 10, "mem": 512,
                "provider-type": "dummy", "ubuntu-series": "series"}})
        self.mocker.result(fail(ProviderInteractionError()))

        mock_provider.start_machine({
            "machine-id": 1, "constraints": {
                "arch": "amd64", "cpu": 20, "mem": 512,
                "provider-type": "dummy", "ubuntu-series": "series"}})
        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())
    def setUp(self):
        yield super(ConstraintsGetTest, self).setUp()
        env_constraints = dummy_cs.parse(["mem=1024"])
        esm = EnvironmentStateManager(self.client)
        yield esm.set_constraints(env_constraints)
        self.expect_env = {
            "arch": "amd64", "cpu": 1.0, "mem": 1024.0,
            "provider-type": "dummy", "ubuntu-series": None}

        service_constraints = dummy_cs.parse(["cpu=10"])
        service = yield self.add_service_from_charm(
            "mysql", constraints=service_constraints)
        # unit will snapshot the state of service when added
        unit = yield service.add_unit_state()
        self.expect_unit = {
            "arch": "amd64", "cpu": 10.0, "mem": 1024.0,
            "provider-type": "dummy", "ubuntu-series": "series"}

        # machine gets its own constraints
        machine_constraints = dummy_cs.parse(["cpu=15", "mem=8G"])
        machine = yield self.add_machine_state(
            constraints=machine_constraints.with_series("series"))
        self.expect_machine = {
            "arch": "amd64", "cpu": 15.0, "mem": 8192.0,
            "provider-type": "dummy", "ubuntu-series": "series"}
        yield unit.assign_to_machine(machine)

        # service gets new constraints, leaves unit untouched
        yield service.set_constraints(dummy_cs.parse(["mem=16G"]))
        self.expect_service = {
            "arch": "amd64", "cpu": 1.0, "mem": 16384.0,
            "provider-type": "dummy", "ubuntu-series": "series"}

        self.log = self.capture_logging()
        self.stdout = self.capture_stream("stdout")
        self.finished = self.setup_cli_reactor()
        self.setup_exit(0)
        self.mocker.replay()
 def construct_bootstrap(self, with_zookeepers=False):
     cloud_init = CloudInit()
     cloud_init.enable_bootstrap()
     cloud_init.add_ssh_key("chubb")
     cloud_init.set_machine_id("passport")
     cloud_init.set_provider_type("dummy")
     cloud_init.set_instance_id_accessor("token")
     cloud_init.set_zookeeper_secret("seekrit")
     cloud_init.set_constraints(
         dummy_cs.parse(["cpu=20"]).with_series("astonishing"))
     cloud_init.set_juju_source(distro=True)
     if with_zookeepers:
         cloud_init.set_zookeeper_machines([
             DummyMachine("blah", "blah", "cotswold"),
             DummyMachine("blah", "blah", "longleat")])
     return cloud_init
 def test_set_constraints(self):
     yield self.push_default_config()
     constraints = dummy_cs.parse(["cpu=any", "mem=32T"])
     yield self.environment_state_manager.set_constraints(constraints)
     roundtrip = yield self.environment_state_manager.get_constraints()
     self.assertEquals(roundtrip, constraints)
 def setUp(self):
     yield super(BootstrapTest, self).setUp()
     self.constraints = dummy_cs.parse(["arch=arm"]).with_series("splendid")