diff options
| author | Jenkins <jenkins@review.openstack.org> | 2014-08-01 20:08:43 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2014-08-01 20:08:43 +0000 |
| commit | f0402709fbfaf2c6df67efc4865b8b6c9081457d (patch) | |
| tree | 1e26a6cc46d389d79d041c582b87b4307c4ba5fe | |
| parent | 2081cc8665727a914246d13f6f89b70fd94a3ab7 (diff) | |
| parent | 31ac1c9f82a2cf016b29628935f31395f58419b5 (diff) | |
| download | python-ironicclient-0.1.5.tar.gz | |
| -rw-r--r-- | ironicclient/tests/v1/test_node.py | 54 | ||||
| -rw-r--r-- | ironicclient/tests/v1/test_node_shell.py | 28 | ||||
| -rw-r--r-- | ironicclient/v1/node.py | 13 | ||||
| -rw-r--r-- | ironicclient/v1/node_shell.py | 33 |
4 files changed, 128 insertions, 0 deletions
diff --git a/ironicclient/tests/v1/test_node.py b/ironicclient/tests/v1/test_node.py index e13b90f..4f9a57e 100644 --- a/ironicclient/tests/v1/test_node.py +++ b/ironicclient/tests/v1/test_node.py @@ -64,6 +64,9 @@ CONSOLE_DATA_ENABLED = {'console_enabled': True, 'console_info': {'test-console': 'test-console-data'}} CONSOLE_DATA_DISABLED = {'console_enabled': False, 'console_info': None} +BOOT_DEVICE = {'boot_device': 'pxe', 'persistent': False} +SUPPORTED_BOOT_DEVICE = {'supported_boot_devices': ['pxe']} + CREATE_NODE = copy.deepcopy(NODE1) del CREATE_NODE['id'] del CREATE_NODE['uuid'] @@ -202,6 +205,24 @@ fake_responses = { CONSOLE_DATA_DISABLED, ), }, + '/v1/nodes/%s/management/boot_device' % NODE1['uuid']: + { + 'GET': ( + {}, + BOOT_DEVICE, + ), + 'PUT': ( + {}, + None, + ), + }, + '/v1/nodes/%s/management/boot_device/supported' % NODE1['uuid']: + { + 'GET': ( + {}, + SUPPORTED_BOOT_DEVICE, + ), + }, } fake_responses_pagination = { @@ -494,3 +515,36 @@ class NodeManagerTest(testtools.TestCase): update_mock.assert_once_called_with(final_path, vendor_passthru_args, method='POST') + + def _test_node_set_boot_device(self, boot_device, persistent=False): + self.mgr.set_boot_device(NODE1['uuid'], boot_device, persistent) + body = {'boot_device': boot_device, 'persistent': persistent} + expect = [ + ('PUT', '/v1/nodes/%s/management/boot_device' % NODE1['uuid'], + {}, body), + ] + self.assertEqual(expect, self.api.calls) + + def test_node_set_boot_device(self): + self._test_node_set_boot_device('pxe') + + def test_node_set_boot_device_persistent(self): + self._test_node_set_boot_device('pxe', persistent=True) + + def test_node_get_boot_device(self): + boot_device = self.mgr.get_boot_device(NODE1['uuid']) + expect = [ + ('GET', '/v1/nodes/%s/management/boot_device' % NODE1['uuid'], + {}, None), + ] + self.assertEqual(expect, self.api.calls) + self.assertEqual(BOOT_DEVICE, boot_device) + + def test_node_get_supported_boot_devices(self): + boot_device = self.mgr.get_supported_boot_devices(NODE1['uuid']) + expect = [ + ('GET', '/v1/nodes/%s/management/boot_device/supported' % + NODE1['uuid'], {}, None), + ] + self.assertEqual(expect, self.api.calls) + self.assertEqual(SUPPORTED_BOOT_DEVICE, boot_device) diff --git a/ironicclient/tests/v1/test_node_shell.py b/ironicclient/tests/v1/test_node_shell.py index 3494a0c..5185c4e 100644 --- a/ironicclient/tests/v1/test_node_shell.py +++ b/ironicclient/tests/v1/test_node_shell.py @@ -78,3 +78,31 @@ class NodeShellTest(utils.BaseTestCase): 'args': {} } client_mock.node.vendor_passthru.assert_called_once_with(**kwargs) + + def test_do_node_set_boot_device(self): + client_mock = mock.MagicMock() + args = mock.MagicMock() + args.node = 'node_uuid' + args.persistent = False + args.device = 'pxe' + + n_shell.do_node_set_boot_device(client_mock, args) + client_mock.node.set_boot_device.assert_called_once_with( + 'node_uuid', 'pxe', False) + + def test_do_node_get_boot_device(self): + client_mock = mock.MagicMock() + args = mock.MagicMock() + args.node = 'node_uuid' + + n_shell.do_node_get_boot_device(client_mock, args) + client_mock.node.get_boot_device.assert_called_once_with('node_uuid') + + def test_do_node_get_supported_boot_devices(self): + client_mock = mock.MagicMock() + args = mock.MagicMock() + args.node = 'node_uuid' + + n_shell.do_node_get_supported_boot_devices(client_mock, args) + client_mock.node.get_supported_boot_devices.assert_called_once_with( + 'node_uuid') diff --git a/ironicclient/v1/node.py b/ironicclient/v1/node.py index 13d3c80..5e168fd 100644 --- a/ironicclient/v1/node.py +++ b/ironicclient/v1/node.py @@ -190,3 +190,16 @@ class NodeManager(base.Manager): path = "%s/states/console" % node_uuid target = {'enabled': enabled} return self._update(self._path(path), target, method='PUT') + + def set_boot_device(self, node_uuid, boot_device, persistent=False): + path = "%s/management/boot_device" % node_uuid + target = {'boot_device': boot_device, 'persistent': persistent} + return self._update(self._path(path), target, method='PUT') + + def get_boot_device(self, node_uuid): + path = "%s/management/boot_device" % node_uuid + return self.get(path).to_dict() + + def get_supported_boot_devices(self, node_uuid): + path = "%s/management/boot_device/supported" % node_uuid + return self.get(path).to_dict() diff --git a/ironicclient/v1/node_shell.py b/ironicclient/v1/node_shell.py index fbee6bc..4782438 100644 --- a/ironicclient/v1/node_shell.py +++ b/ironicclient/v1/node_shell.py @@ -271,3 +271,36 @@ def do_node_get_console(cc, args): def do_node_set_console_mode(cc, args): """Enable or disable serial console access for this node.""" cc.node.set_console_mode(args.node, args.enabled) + + +@cliutils.arg('node', metavar='<node uuid>', help="UUID of node") +@cliutils.arg( + 'device', + metavar='<boot device>', + choices=['pxe', 'disk', 'cdrom', 'bios', 'safe'], + help="Supported boot devices: 'pxe', 'disk', 'cdrom', 'bios', 'safe'") +@cliutils.arg( + '--persistent', + dest='persistent', + action='store_true', + default=False, + help="Make changes persistent for all future boots") +def do_node_set_boot_device(cc, args): + """Set the boot device for a node.""" + cc.node.set_boot_device(args.node, args.device, args.persistent) + + +@cliutils.arg('node', metavar='<node uuid>', help="UUID of node") +def do_node_get_boot_device(cc, args): + """Get the current boot device.""" + boot_device = cc.node.get_boot_device(args.node) + cliutils.print_dict(boot_device, wrap=72) + + +@cliutils.arg('node', metavar='<node uuid>', help="UUID of node") +def do_node_get_supported_boot_devices(cc, args): + """Get the supported boot devices.""" + boot_devices = cc.node.get_supported_boot_devices(args.node) + boot_device_list = boot_devices.get('supported_boot_devices', []) + boot_devices['supported_boot_devices'] = ', '.join(boot_device_list) + cliutils.print_dict(boot_devices, wrap=72) |
