Configure boot for all Ironic nodes

Added `openstack baremetal configure boot` command to configure the boot
parameters in ironic for all nodes.

Change-Id: I468f6cbfc799cdb2386beac044a34fc8e949c161
This commit is contained in:
Dougal Matthews 2015-04-14 10:37:14 +01:00
parent 01b12f3fc1
commit 279d97ed0a
4 changed files with 93 additions and 5 deletions

View File

@ -21,13 +21,9 @@ class FakeClientWrapper(object):
def __init__(self):
self._instance = mock.Mock()
self._baremetal = None
self._baremetal = mock.Mock()
def baremetal(self):
if self._baremetal is None:
self._baremetal = mock.Mock()
return self._baremetal
@ -38,3 +34,4 @@ class TestBaremetal(utils.TestCommand):
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
self.app.client_manager.rdomanager_oscplugin = FakeClientWrapper()
self.app.client_manager.image = mock.Mock()

View File

@ -298,3 +298,51 @@ class TestStatusAll(fakes.TestBaremetal):
('QRSTUVWX', False, None)
]
))
class TestConfigureBoot(fakes.TestBaremetal):
def setUp(self):
super(TestConfigureBoot, self).setUp()
# Get the command object to test
self.cmd = baremetal.ConfigureBootPlugin(self.app, None)
@mock.patch('openstackclient.common.utils.find_resource')
def test_configure_boot(self, find_resource_mock):
find_resource_mock.return_value = mock.Mock(id="IDIDID")
bm_client = self.app.client_manager.rdomanager_oscplugin.baremetal()
bm_client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH"),
mock.Mock(uuid="IJKLMNOP"),
]
parsed_args = self.check_parser(self.cmd, [], [])
self.cmd.take_action(parsed_args)
self.assertEqual(find_resource_mock.call_count, 2)
self.assertEqual(bm_client.node.update.call_count, 2)
self.assertEqual(bm_client.node.update.mock_calls, [
mock.call('ABCDEFGH', [{
'op': 'add', 'value': 'boot_option:local',
'path': '/properties/capabilities'
}, {
'op': 'add', 'value': 'IDIDID',
'path': '/driver_info/deploy_ramdisk'
}, {
'op': 'add', 'value': 'IDIDID',
'path': '/driver_info/deploy_kernel'
}]),
mock.call('IJKLMNOP', [{
'op': 'add', 'value': 'boot_option:local',
'path': '/properties/capabilities'
}, {
'op': 'add', 'value': 'IDIDID',
'path': '/driver_info/deploy_ramdisk'
}, {
'op': 'add', 'value': 'IDIDID',
'path': '/driver_info/deploy_kernel'
}])
])

View File

@ -151,3 +151,45 @@ class StatusAllPlugin(IntrospectionParser, lister.Lister):
list((node_uuid, status['finished'], status['error'])
for (node_uuid, status) in statuses)
)
class ConfigureBootPlugin(command.Command):
"""Baremetal configure boot plugin"""
log = logging.getLogger(__name__ + ".ConfigureBootPlugin")
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
bm_client = self.app.client_manager.rdomanager_oscplugin.baremetal()
image_client = self.app.client_manager.image
kernel_id = utils.find_resource(
image_client.images, 'bm-deploy-kernel').id
ramdisk_id = utils.find_resource(
image_client.images, 'bm-deploy-ramdisk').id
self.log.debug("Using kernel ID: {0} and ramdisk ID: {1}".format(
kernel_id, ramdisk_id))
for node in bm_client.node.list():
self.log.debug("Configuring boot for Node {0}".format(
node.uuid))
bm_client.node.update(node.uuid, [
{
'op': 'add',
'path': '/properties/capabilities',
'value': 'boot_option:local',
},
{
'op': 'add',
'path': '/driver_info/deploy_ramdisk',
'value': ramdisk_id,
},
{
'op': 'add',
'path': '/driver_info/deploy_kernel',
'value': kernel_id,
},
])

View File

@ -57,6 +57,7 @@ openstack.rdomanager_oscplugin.v1 =
baremetal_import = rdomanager_oscplugin.v1.baremetal:ImportPlugin
baremetal_introspection_all_start = rdomanager_oscplugin.v1.baremetal:IntrospectionAllPlugin
baremetal_introspection_all_status = rdomanager_oscplugin.v1.baremetal:StatusAllPlugin
baremetal_configure_boot = rdomanager_oscplugin.v1.baremetal:ConfigureBootPlugin
overcloud_deploy = rdomanager_oscplugin.v1.overcloud_deploy:DeployPlugin
overcloud_image_build = rdomanager_oscplugin.v1.overcloud_image:BuildPlugin
overcloud_image_create = rdomanager_oscplugin.v1.overcloud_image:CreatePlugin