Merge "Set/unset node's target RAID config via OSC command"
This commit is contained in:
@@ -641,6 +641,14 @@ class SetBaremetalNode(command.Command):
|
||||
metavar='<resource_class>',
|
||||
help='Set the resource class for the node',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--target-raid-config',
|
||||
metavar='<target_raid_config>',
|
||||
help='Set the target RAID configuration (JSON) for the node. This '
|
||||
'can be one of: 1. a file containing JSON data of the RAID '
|
||||
'configuration; 2. "-" to read the contents from standard '
|
||||
'input; or 3. a valid JSON string.',
|
||||
)
|
||||
parser.add_argument(
|
||||
"--property",
|
||||
metavar="<key=value>",
|
||||
@@ -677,6 +685,17 @@ class SetBaremetalNode(command.Command):
|
||||
|
||||
baremetal_client = self.app.client_manager.baremetal
|
||||
|
||||
# NOTE(rloo): Do this before updating the rest. Otherwise, it won't
|
||||
# work if parsed_args.node is the name and the name is
|
||||
# also being modified.
|
||||
if parsed_args.target_raid_config:
|
||||
raid_config = parsed_args.target_raid_config
|
||||
if raid_config == '-':
|
||||
raid_config = utils.get_from_stdin('target_raid_config')
|
||||
raid_config = utils.handle_json_or_file_arg(raid_config)
|
||||
baremetal_client.node.set_target_raid_config(parsed_args.node,
|
||||
raid_config)
|
||||
|
||||
properties = []
|
||||
if parsed_args.instance_uuid:
|
||||
instance_uuid = ["instance_uuid=%s" % parsed_args.instance_uuid]
|
||||
@@ -713,6 +732,7 @@ class SetBaremetalNode(command.Command):
|
||||
properties.extend(utils.args_array_to_patch(
|
||||
'add', ['instance_info/' + x for x
|
||||
in parsed_args.instance_info]))
|
||||
if properties:
|
||||
baremetal_client.node.update(parsed_args.node, properties)
|
||||
|
||||
|
||||
@@ -823,6 +843,11 @@ class UnsetBaremetalNode(command.Command):
|
||||
action='store_true',
|
||||
help="Unset the resource class of the node",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--target-raid-config",
|
||||
action='store_true',
|
||||
help="Unset the target RAID configuration of the node",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--property',
|
||||
metavar='<key>',
|
||||
@@ -859,6 +884,12 @@ class UnsetBaremetalNode(command.Command):
|
||||
|
||||
baremetal_client = self.app.client_manager.baremetal
|
||||
|
||||
# NOTE(rloo): Do this before removing the rest. Otherwise, it won't
|
||||
# work if parsed_args.node is the name and the name is
|
||||
# also being removed.
|
||||
if parsed_args.target_raid_config:
|
||||
baremetal_client.node.set_target_raid_config(parsed_args.node, {})
|
||||
|
||||
properties = []
|
||||
if parsed_args.instance_uuid:
|
||||
properties.extend(utils.args_array_to_patch('remove',
|
||||
@@ -884,7 +915,7 @@ class UnsetBaremetalNode(command.Command):
|
||||
properties.extend(utils.args_array_to_patch('remove',
|
||||
['instance_info/' + x for x
|
||||
in parsed_args.instance_info]))
|
||||
|
||||
if properties:
|
||||
baremetal_client.node.update(parsed_args.node, properties)
|
||||
|
||||
|
||||
|
@@ -19,6 +19,7 @@ import mock
|
||||
|
||||
from osc_lib.tests import utils as oscutils
|
||||
|
||||
from ironicclient.common import utils as commonutils
|
||||
from ironicclient import exc
|
||||
from ironicclient.osc.v1 import baremetal_node
|
||||
from ironicclient.tests.unit.osc.v1 import fakes as baremetal_fakes
|
||||
@@ -1016,6 +1017,99 @@ class TestBaremetalSet(TestBaremetal):
|
||||
[{'path': '/instance_info/foo', 'value': 'bar', 'op': 'add'}]
|
||||
)
|
||||
|
||||
@mock.patch.object(commonutils, 'get_from_stdin', autospec=True)
|
||||
@mock.patch.object(commonutils, 'handle_json_or_file_arg', autospec=True)
|
||||
def test_baremetal_set_target_raid_config(self, mock_handle, mock_stdin):
|
||||
target_raid_config_string = '{"raid": "config"}'
|
||||
expected_target_raid_config = {'raid': 'config'}
|
||||
mock_handle.return_value = expected_target_raid_config.copy()
|
||||
|
||||
arglist = ['node_uuid',
|
||||
'--target-raid-config', target_raid_config_string]
|
||||
verifylist = [('node', 'node_uuid'),
|
||||
('target_raid_config', target_raid_config_string)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertFalse(mock_stdin.called)
|
||||
mock_handle.assert_called_once_with(target_raid_config_string)
|
||||
self.baremetal_mock.node.set_target_raid_config.\
|
||||
assert_called_once_with('node_uuid', expected_target_raid_config)
|
||||
self.assertFalse(self.baremetal_mock.node.update.called)
|
||||
|
||||
@mock.patch.object(commonutils, 'get_from_stdin', autospec=True)
|
||||
@mock.patch.object(commonutils, 'handle_json_or_file_arg', autospec=True)
|
||||
def test_baremetal_set_target_raid_config_and_name(
|
||||
self, mock_handle, mock_stdin):
|
||||
target_raid_config_string = '{"raid": "config"}'
|
||||
expected_target_raid_config = {'raid': 'config'}
|
||||
mock_handle.return_value = expected_target_raid_config.copy()
|
||||
|
||||
arglist = ['node_uuid',
|
||||
'--name', 'xxxxx',
|
||||
'--target-raid-config', target_raid_config_string]
|
||||
verifylist = [('node', 'node_uuid'),
|
||||
('name', 'xxxxx'),
|
||||
('target_raid_config', target_raid_config_string)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertFalse(mock_stdin.called)
|
||||
mock_handle.assert_called_once_with(target_raid_config_string)
|
||||
self.baremetal_mock.node.set_target_raid_config.\
|
||||
assert_called_once_with('node_uuid', expected_target_raid_config)
|
||||
self.baremetal_mock.node.update.assert_called_once_with(
|
||||
'node_uuid',
|
||||
[{'path': '/name', 'value': 'xxxxx', 'op': 'add'}])
|
||||
|
||||
@mock.patch.object(commonutils, 'get_from_stdin', autospec=True)
|
||||
@mock.patch.object(commonutils, 'handle_json_or_file_arg', autospec=True)
|
||||
def test_baremetal_set_target_raid_config_stdin(self, mock_handle,
|
||||
mock_stdin):
|
||||
target_value = '-'
|
||||
target_raid_config_string = '{"raid": "config"}'
|
||||
expected_target_raid_config = {'raid': 'config'}
|
||||
mock_stdin.return_value = target_raid_config_string
|
||||
mock_handle.return_value = expected_target_raid_config.copy()
|
||||
|
||||
arglist = ['node_uuid',
|
||||
'--target-raid-config', target_value]
|
||||
verifylist = [('node', 'node_uuid'),
|
||||
('target_raid_config', target_value)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
mock_stdin.assert_called_once_with('target_raid_config')
|
||||
mock_handle.assert_called_once_with(target_raid_config_string)
|
||||
self.baremetal_mock.node.set_target_raid_config.\
|
||||
assert_called_once_with('node_uuid', expected_target_raid_config)
|
||||
self.assertFalse(self.baremetal_mock.node.update.called)
|
||||
|
||||
@mock.patch.object(commonutils, 'get_from_stdin', autospec=True)
|
||||
@mock.patch.object(commonutils, 'handle_json_or_file_arg', autospec=True)
|
||||
def test_baremetal_set_target_raid_config_stdin_exception(
|
||||
self, mock_handle, mock_stdin):
|
||||
target_value = '-'
|
||||
mock_stdin.side_effect = exc.InvalidAttribute('bad')
|
||||
|
||||
arglist = ['node_uuid',
|
||||
'--target-raid-config', target_value]
|
||||
verifylist = [('node', 'node_uuid'),
|
||||
('target_raid_config', target_value)]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(exc.InvalidAttribute,
|
||||
self.cmd.take_action, parsed_args)
|
||||
|
||||
mock_stdin.assert_called_once_with('target_raid_config')
|
||||
self.assertFalse(mock_handle.called)
|
||||
self.assertFalse(
|
||||
self.baremetal_mock.node.set_target_raid_config.called)
|
||||
self.assertFalse(self.baremetal_mock.node.update.called)
|
||||
|
||||
|
||||
class TestBaremetalShow(TestBaremetal):
|
||||
def setUp(self):
|
||||
@@ -1331,3 +1425,44 @@ class TestBaremetalUnset(TestBaremetal):
|
||||
'node_uuid',
|
||||
[{'path': '/instance_info/foo', 'op': 'remove'}]
|
||||
)
|
||||
|
||||
def test_baremetal_unset_target_raid_config(self):
|
||||
arglist = [
|
||||
'node_uuid',
|
||||
'--target-raid-config',
|
||||
]
|
||||
verifylist = [
|
||||
('node', 'node_uuid'),
|
||||
('target_raid_config', True)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertFalse(self.baremetal_mock.node.update.called)
|
||||
self.baremetal_mock.node.set_target_raid_config.\
|
||||
assert_called_once_with('node_uuid', {})
|
||||
|
||||
def test_baremetal_unset_target_raid_config_and_name(self):
|
||||
arglist = [
|
||||
'node_uuid',
|
||||
'--name',
|
||||
'--target-raid-config',
|
||||
]
|
||||
verifylist = [
|
||||
('node', 'node_uuid'),
|
||||
('name', True),
|
||||
('target_raid_config', True)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.baremetal_mock.node.set_target_raid_config.\
|
||||
assert_called_once_with('node_uuid', {})
|
||||
self.baremetal_mock.node.update.assert_called_once_with(
|
||||
'node_uuid',
|
||||
[{'path': '/name', 'op': 'remove'}]
|
||||
)
|
||||
|
@@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Allows setting and unsetting (clearing) the node's target
|
||||
RAID configuration via the OpenStackClient plugin commands
|
||||
'openstack baremetal node set --target-raid-config' and
|
||||
'openstack baremetal node unset --target-raid-config'
|
||||
respectively.
|
Reference in New Issue
Block a user