Add management of automated_clean field

Modify api to manage the new automated_clean field.
Also bump last known version to 47

Change-Id: I790c762083c2c1b6cbdde4b21434c56bb99236dd
Story: #2002161
Task: #23252
This commit is contained in:
Yolanda Robla 2018-07-27 12:54:25 +02:00
parent fb94fb825c
commit dfd341585b
7 changed files with 92 additions and 18 deletions

View File

@ -43,7 +43,7 @@ from ironicclient import exc
# http://specs.openstack.org/openstack/ironic-specs/specs/kilo/api-microversions.html # noqa # http://specs.openstack.org/openstack/ironic-specs/specs/kilo/api-microversions.html # noqa
# for full details. # for full details.
DEFAULT_VER = '1.9' DEFAULT_VER = '1.9'
LAST_KNOWN_API_VERSION = 46 LAST_KNOWN_API_VERSION = 47
LATEST_VERSION = '1.{}'.format(LAST_KNOWN_API_VERSION) LATEST_VERSION = '1.{}'.format(LAST_KNOWN_API_VERSION)
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)

View File

@ -432,6 +432,11 @@ class CreateBaremetalNode(command.ShowOne):
'--conductor-group', '--conductor-group',
metavar='<conductor_group>', metavar='<conductor_group>',
help=_('Conductor group the node will belong to')) help=_('Conductor group the node will belong to'))
parser.add_argument(
'--automated-clean',
action='store_true',
default=None,
help=_('Enable automated cleaning for the node'))
return parser return parser
@ -440,8 +445,9 @@ class CreateBaremetalNode(command.ShowOne):
baremetal_client = self.app.client_manager.baremetal baremetal_client = self.app.client_manager.baremetal
field_list = ['chassis_uuid', 'driver', 'driver_info', field_list = ['automated_clean', 'chassis_uuid', 'driver',
'properties', 'extra', 'uuid', 'name', 'conductor_group', 'driver_info', 'properties', 'extra', 'uuid', 'name',
'conductor_group',
'resource_class'] + ['%s_interface' % iface 'resource_class'] + ['%s_interface' % iface
for iface in SUPPORTED_INTERFACES] for iface in SUPPORTED_INTERFACES]
fields = dict((k, v) for (k, v) in vars(parsed_args).items() fields = dict((k, v) for (k, v) in vars(parsed_args).items()
@ -1105,6 +1111,11 @@ class SetBaremetalNode(command.Command):
metavar='<conductor_group>', metavar='<conductor_group>',
help=_('Set the conductor group for the node'), help=_('Set the conductor group for the node'),
) )
parser.add_argument(
'--automated-clean',
action='store_true',
help=_('Enable automated cleaning for the node'),
)
parser.add_argument( parser.add_argument(
'--target-raid-config', '--target-raid-config',
metavar='<target_raid_config>', metavar='<target_raid_config>',
@ -1161,8 +1172,9 @@ class SetBaremetalNode(command.Command):
raid_config) raid_config)
properties = [] properties = []
for field in ['instance_uuid', 'name', 'chassis_uuid', 'driver', for field in ['automated_clean', 'instance_uuid', 'name',
'resource_class', 'conductor_group']: 'chassis_uuid', 'driver', 'resource_class',
'conductor_group']:
value = getattr(parsed_args, field) value = getattr(parsed_args, field)
if value: if value:
properties.extend(utils.args_array_to_patch( properties.extend(utils.args_array_to_patch(
@ -1418,6 +1430,12 @@ class UnsetBaremetalNode(command.Command):
help=_('Unset conductor group for this baremetal node (the ' help=_('Unset conductor group for this baremetal node (the '
'default group will be used)'), 'default group will be used)'),
) )
parser.add_argument(
"--automated-clean",
action="store_true",
help=_('Unset automated clean option on this baremetal node '
'(the value from configuration will be used)'),
)
return parser return parser
@ -1434,7 +1452,7 @@ class UnsetBaremetalNode(command.Command):
properties = [] properties = []
for field in ['instance_uuid', 'name', 'chassis_uuid', for field in ['instance_uuid', 'name', 'chassis_uuid',
'resource_class', 'conductor_group', 'resource_class', 'conductor_group', 'automated_clean',
'bios_interface', 'boot_interface', 'console_interface', 'bios_interface', 'boot_interface', 'console_interface',
'deploy_interface', 'inspect_interface', 'deploy_interface', 'inspect_interface',
'management_interface', 'network_interface', 'management_interface', 'network_interface',

View File

@ -287,7 +287,7 @@ class TestBaremetalCreate(TestBaremetal):
baremetal_fakes.baremetal_uuid, baremetal_fakes.baremetal_uuid,
) )
self.actual_kwargs = { self.actual_kwargs = {
'driver': 'fake_driver', 'driver': 'fake_driver'
} }
def check_with_options(self, addl_arglist, addl_verifylist, addl_kwargs): def check_with_options(self, addl_arglist, addl_verifylist, addl_kwargs):
@ -455,6 +455,11 @@ class TestBaremetalCreate(TestBaremetal):
[('conductor_group', 'conductor_group')], [('conductor_group', 'conductor_group')],
{'conductor_group': 'conductor_group'}) {'conductor_group': 'conductor_group'})
def test_baremetal_create_with_automated_clean(self):
self.check_with_options(['--automated-clean'],
[('automated_clean', True)],
{'automated_clean': True})
class TestBaremetalDelete(TestBaremetal): class TestBaremetalDelete(TestBaremetal):
def setUp(self): def setUp(self):
@ -598,14 +603,15 @@ class TestBaremetalList(TestBaremetal):
**kwargs **kwargs
) )
collist = ('Chassis UUID', 'Created At', 'Clean Step', collist = ('Automated clean', 'Chassis UUID', 'Created At',
'Conductor Group', 'Console Enabled', 'Deploy Step', 'Clean Step', 'Conductor Group', 'Console Enabled',
'Driver', 'Driver Info', 'Driver Internal Info', 'Extra', 'Deploy Step', 'Driver', 'Driver Info',
'Instance Info', 'Instance UUID', 'Last Error', 'Driver Internal Info', 'Extra', 'Instance Info',
'Maintenance', 'Maintenance Reason', 'Fault', 'Instance UUID', 'Last Error', 'Maintenance',
'Power State', 'Properties', 'Provisioning State', 'Maintenance Reason', 'Fault', 'Power State', 'Properties',
'Provision Updated At', 'Current RAID configuration', 'Provisioning State', 'Provision Updated At',
'Reservation', 'Resource Class', 'Target Power State', 'Current RAID configuration', 'Reservation',
'Resource Class', 'Target Power State',
'Target Provision State', 'Target RAID configuration', 'Target Provision State', 'Target RAID configuration',
'Traits', 'Updated At', 'Inspection Finished At', 'Traits', 'Updated At', 'Inspection Finished At',
'Inspection Started At', 'UUID', 'Name', 'Inspection Started At', 'UUID', 'Name',
@ -628,6 +634,7 @@ class TestBaremetalList(TestBaremetal):
'', '',
'', '',
'', '',
'',
baremetal_fakes.baremetal_instance_uuid, baremetal_fakes.baremetal_instance_uuid,
'', '',
baremetal_fakes.baremetal_maintenance, baremetal_fakes.baremetal_maintenance,
@ -2281,6 +2288,26 @@ class TestBaremetalSet(TestBaremetal):
reset_interfaces=None, reset_interfaces=None,
) )
def test_baremetal_set_automated_clean(self):
arglist = [
'node_uuid',
'--automated-clean'
]
verifylist = [
('node', 'node_uuid'),
('automated_clean', True)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.baremetal_mock.node.update.assert_called_once_with(
'node_uuid',
[{'path': '/automated_clean', 'value': 'True', 'op': 'add'}],
reset_interfaces=None,
)
def test_baremetal_set_extra(self): def test_baremetal_set_extra(self):
arglist = [ arglist = [
'node_uuid', 'node_uuid',
@ -2733,6 +2760,25 @@ class TestBaremetalUnset(TestBaremetal):
[{'path': '/conductor_group', 'op': 'remove'}] [{'path': '/conductor_group', 'op': 'remove'}]
) )
def test_baremetal_unset_automated_clean(self):
arglist = [
'node_uuid',
'--automated-clean',
]
verifylist = [
('node', 'node_uuid'),
('automated_clean', True)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.baremetal_mock.node.update.assert_called_once_with(
'node_uuid',
[{'path': '/automated_clean', 'op': 'remove'}]
)
def test_baremetal_unset_extra(self): def test_baremetal_unset_extra(self):
arglist = [ arglist = [
'node_uuid', 'node_uuid',

View File

@ -33,7 +33,8 @@ class NodeShellTest(utils.BaseTestCase):
with mock.patch.object(cliutils, 'print_dict', fake_print_dict): with mock.patch.object(cliutils, 'print_dict', fake_print_dict):
node = object() node = object()
n_shell._print_node_show(node) n_shell._print_node_show(node)
exp = ['chassis_uuid', exp = ['automated_clean',
'chassis_uuid',
'clean_step', 'clean_step',
'created_at', 'created_at',
'conductor_group', 'conductor_group',

View File

@ -53,7 +53,8 @@ class NodeManager(base.CreateManager):
'network_interface', 'power_interface', 'network_interface', 'power_interface',
'raid_interface', 'rescue_interface', 'raid_interface', 'rescue_interface',
'storage_interface', 'vendor_interface', 'storage_interface', 'vendor_interface',
'resource_class', 'conductor_group'] 'resource_class', 'conductor_group',
'automated_clean']
_resource_name = 'nodes' _resource_name = 'nodes'
def list(self, associated=None, maintenance=None, marker=None, limit=None, def list(self, associated=None, maintenance=None, marker=None, limit=None,

View File

@ -33,6 +33,7 @@ class Resource(object):
FIELDS = { FIELDS = {
'address': 'Address', 'address': 'Address',
'async': 'Async', 'async': 'Async',
'automated_clean': 'Automated clean',
'attach': 'Response is attachment', 'attach': 'Response is attachment',
'bios_name': 'BIOS setting name', 'bios_name': 'BIOS setting name',
'bios_value': 'BIOS setting value', 'bios_value': 'BIOS setting value',
@ -199,7 +200,8 @@ CHASSIS_RESOURCE = Resource(
# Nodes # Nodes
NODE_DETAILED_RESOURCE = Resource( NODE_DETAILED_RESOURCE = Resource(
['chassis_uuid', ['automated_clean',
'chassis_uuid',
'created_at', 'created_at',
'clean_step', 'clean_step',
'conductor_group', 'conductor_group',

View File

@ -0,0 +1,6 @@
---
features:
- |
Adds the ability to set the ``automated_clean`` field (available starting
with API version 1.47) on the baremetal node, to enable the automated
cleaning feature at the node level.