示例#1
0
 def test_get_machines_too_many(self):
     """
     :exc:`juju.errors.ProviderError` is raised when a machine not
     requested is returned by `get_machines`.
     """
     self.setup_connection(MAASClient, FakeMAASHTTPConnection)
     provider = MachineProvider("blah", CONFIG)
     instance_id = NODE_JSON[1]["resource_uri"]
     d = provider.get_machines([instance_id])
     d = self.assertFailure(d, ProviderError)
     d.addCallback(
         lambda error: self.assertEqual(
             "Cannot find machine: %s" % instance_id,
             str(error)))
     return d
示例#2
0
 def test_get_machines_too_few(self):
     """
     :exc:`juju.errors.MachinesNotFound` is raised when a requested machine
     is not found by `get_machines`. The error contains a list of instance
     IDs that were missing.
     """
     self.setup_connection(MAASClient, FakeMAASHTTPConnection)
     provider = MachineProvider("blah", CONFIG)
     instance_id = "/api/123/nodes/fred"
     d = provider.get_machines([instance_id])
     d = self.assertFailure(d, MachinesNotFound)
     d.addCallback(
         lambda error: self.assertEqual(
             [instance_id], error.instance_ids))
     return d
示例#3
0
    def test_shutdown_machines(self):
        self.setup_connection(MAASClient, FakeMAASHTTPConnection)
        client = MAASClient(CONFIG)

        # Patch the client to demonstrate that the node is stopped and
        # released when shutting down.
        mocker = self.mocker
        mock_client = mocker.patch(client)
        mocker.order()
        mock_client.stop_node(ANY)
        mocker.result(None)
        mock_client.release_node(ANY)
        mocker.result(None)
        mocker.replay()

        provider = MachineProvider("blah", CONFIG)
        provider.maas_client = mock_client
        machines = yield provider.get_machines()
        machine_to_shutdown = machines[0]
        machines_terminated = (
            yield provider.shutdown_machines([machine_to_shutdown]))
        self.assertEqual(
            [machines[0].instance_id],
            [machine.instance_id for machine in machines_terminated])
示例#4
0
 def test_get_machines(self):
     self.setup_connection(MAASClient, FakeMAASHTTPConnection)
     provider = MachineProvider("blah", CONFIG)
     machines = yield provider.get_machines()
     self.assertNotEqual([], machines)