Remove mistral from the configure workflows

This change removes all of mistral from the configure functions
by calling the required functions directly.

Story: 2007212
Task: 38447
Task: 38448

Change-Id: I65eac9f813330d066f8ca6cbaae6c972d43d0246
Signed-off-by: Kevin Carter <kecarter@redhat.com>
This commit is contained in:
Kevin Carter 2020-03-11 08:18:50 -05:00 committed by Dougal Matthews
parent 4e6e37e2ce
commit af719b795b
4 changed files with 103 additions and 166 deletions

View File

@ -165,7 +165,8 @@ class FakePlaybookExecution(utils.TestCommand):
self.app.options = FakeOptions() self.app.options = FakeOptions()
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN") self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
self.app.client_manager.baremetal = mock.Mock() baremetal = self.app.client_manager.baremetal = mock.Mock()
baremetal.node.list.return_value = []
compute = self.app.client_manager.compute = mock.Mock() compute = self.app.client_manager.compute = mock.Mock()
compute.servers.list.return_value = [] compute.servers.list.return_value = []
self.app.client_manager.identity = mock.Mock() self.app.client_manager.identity = mock.Mock()
@ -217,6 +218,19 @@ class FakePlaybookExecution(utils.TestCommand):
) )
self.register_or_update.start() self.register_or_update.start()
self.addCleanup(self.register_or_update.stop) self.addCleanup(self.register_or_update.stop)
self.boot_action = mock.patch(
'tripleo_common.actions.baremetal.ConfigureBootAction.run',
autospec=True,
return_value=None
)
self.boot_action.start()
self.addCleanup(self.boot_action.stop)
self.boot_action = mock.patch(
'tripleo_common.actions.baremetal.ConfigureRootDeviceAction.run',
autospec=True
)
self.boot_action.start()
self.addCleanup(self.boot_action.stop)
if ansible_mock: if ansible_mock:
get_stack = mock.patch('tripleoclient.utils.get_stack') get_stack = mock.patch('tripleoclient.utils.get_stack')

View File

@ -780,27 +780,6 @@ class TestConfigureNode(fakes.TestOvercloudNode):
[('all_manageable', True)]) [('all_manageable', True)])
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure_manageable_nodes',
workflow_input=self.workflow_input
)
def test_failed_to_configure_all_manageable_nodes(self):
self.websocket.wait_for_messages.return_value = iter([{
"status": "FAILED",
"message": "Test failure.",
"execution_id": "IDID"
}])
parsed_args = self.check_parser(self.cmd, ['--all-manageable'], [])
self.assertRaises(exceptions.NodeConfigurationError,
self.cmd.take_action, parsed_args)
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure_manageable_nodes',
workflow_input=self.workflow_input
)
def test_configure_specified_nodes(self): def test_configure_specified_nodes(self):
argslist = ['node_uuid1', 'node_uuid2'] argslist = ['node_uuid1', 'node_uuid2']
verifylist = [('node_uuids', ['node_uuid1', 'node_uuid2'])] verifylist = [('node_uuids', ['node_uuid1', 'node_uuid2'])]
@ -808,29 +787,6 @@ class TestConfigureNode(fakes.TestOvercloudNode):
parsed_args = self.check_parser(self.cmd, argslist, verifylist) parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.workflow_input['node_uuids'] = ['node_uuid1', 'node_uuid2']
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure',
workflow_input=self.workflow_input
)
def test_failed_to_configure_specified_nodes(self):
self.websocket.wait_for_messages.return_value = iter([{
"status": "FAILED",
"message": "Test failure.",
"execution_id": "IDID"
}])
parsed_args = self.check_parser(self.cmd, ['node_uuid1'], [])
self.assertRaises(exceptions.NodeConfigurationError,
self.cmd.take_action, parsed_args)
self.workflow_input['node_uuids'] = ['node_uuid1']
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure',
workflow_input=self.workflow_input
)
def test_configure_no_node_or_flag_specified(self): def test_configure_no_node_or_flag_specified(self):
self.assertRaises(test_utils.ParserException, self.assertRaises(test_utils.ParserException,
self.check_parser, self.check_parser,
@ -853,13 +809,6 @@ class TestConfigureNode(fakes.TestOvercloudNode):
parsed_args = self.check_parser(self.cmd, argslist, verifylist) parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.workflow_input['kernel_name'] = 'test_kernel'
self.workflow_input['ramdisk_name'] = 'test_ramdisk'
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure_manageable_nodes',
workflow_input=self.workflow_input
)
def test_configure_instance_boot_option(self): def test_configure_instance_boot_option(self):
argslist = ['--all-manageable', '--instance-boot-option', 'netboot'] argslist = ['--all-manageable', '--instance-boot-option', 'netboot']
verifylist = [('instance_boot_option', 'netboot')] verifylist = [('instance_boot_option', 'netboot')]
@ -867,12 +816,6 @@ class TestConfigureNode(fakes.TestOvercloudNode):
parsed_args = self.check_parser(self.cmd, argslist, verifylist) parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.workflow_input['instance_boot_option'] = 'netboot'
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure_manageable_nodes',
workflow_input=self.workflow_input
)
def test_configure_root_device(self): def test_configure_root_device(self):
argslist = ['--all-manageable', argslist = ['--all-manageable',
'--root-device', 'smallest', '--root-device', 'smallest',
@ -885,14 +828,6 @@ class TestConfigureNode(fakes.TestOvercloudNode):
parsed_args = self.check_parser(self.cmd, argslist, verifylist) parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.workflow_input['root_device'] = 'smallest'
self.workflow_input['root_device_minimum_size'] = 2
self.workflow_input['overwrite_root_device_hints'] = True
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure_manageable_nodes',
workflow_input=self.workflow_input
)
def test_configure_specified_node_with_all_arguments(self): def test_configure_specified_node_with_all_arguments(self):
argslist = ['node_id', argslist = ['node_id',
'--deploy-kernel', 'test_kernel', '--deploy-kernel', 'test_kernel',
@ -912,18 +847,6 @@ class TestConfigureNode(fakes.TestOvercloudNode):
parsed_args = self.check_parser(self.cmd, argslist, verifylist) parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args) self.cmd.take_action(parsed_args)
self.workflow_input.update({'node_uuids': ['node_id'],
'kernel_name': 'test_kernel',
'ramdisk_name': 'test_ramdisk',
'instance_boot_option': 'netboot',
'root_device': 'smallest',
'root_device_minimum_size': 2,
'overwrite_root_device_hints': True})
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure',
workflow_input=self.workflow_input
)
class TestDiscoverNode(fakes.TestOvercloudNode): class TestDiscoverNode(fakes.TestOvercloudNode):

View File

@ -230,60 +230,11 @@ class TestBaremetalWorkflows(fakes.FakePlaybookExecution):
) )
def test_configure_success(self): def test_configure_success(self):
self.websocket.wait_for_messages.return_value = self.message_success
baremetal.configure(self.app.client_manager, node_uuids=[]) baremetal.configure(self.app.client_manager, node_uuids=[])
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure',
workflow_input={
'node_uuids': [],
})
def test_configure_error(self):
self.websocket.wait_for_messages.return_value = self.message_failed
self.assertRaises(
exceptions.NodeConfigurationError,
baremetal.configure,
self.app.client_manager,
node_uuids=[]
)
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure',
workflow_input={
'node_uuids': [],
})
def test_configure_manageable_nodes_success(self): def test_configure_manageable_nodes_success(self):
self.websocket.wait_for_messages.return_value = self.message_success
baremetal.configure_manageable_nodes(self.app.client_manager) baremetal.configure_manageable_nodes(self.app.client_manager)
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure_manageable_nodes',
workflow_input={}
)
def test_configure_manageable_nodes_error(self):
self.websocket.wait_for_messages.return_value = self.message_failed
self.assertRaises(
exceptions.NodeConfigurationError,
baremetal.configure_manageable_nodes,
self.app.client_manager
)
self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.configure_manageable_nodes',
workflow_input={}
)
def test_clean_nodes_success(self): def test_clean_nodes_success(self):
self.websocket.wait_for_messages.return_value = self.message_success self.websocket.wait_for_messages.return_value = self.message_success

View File

@ -247,57 +247,106 @@ def provide_manageable_nodes(clients, **workflow_input):
print(payload['message']) print(payload['message'])
def configure(clients, **workflow_input): def configure(clients, node_uuids, kernel_name='bm-deploy-kernel',
ramdisk_name='bm-deploy-ramdisk', instance_boot_option=None,
root_device=None, root_device_minimum_size=4,
overwrite_root_device_hints=False):
"""Configure Node boot options. """Configure Node boot options.
Run the tripleo.baremetal.v1.configure Mistral workflow. :param node_uuids: List of instance UUID(s).
:type node_uuids: List
:param kernel_name: Kernel to use
:type kernel_name: String
:param ramdisk_name: RAMDISK to use
:type ramdisk_name: String
:param instance_boot_option: Boot options to use
:type instance_boot_option: String
:param root_device: Path (name) of the root device.
:type root_device: String
:param root_device_minimum_size: Size of the given root device.
:type root_device_minimum_size: Integer
:param overwrite_root_device_hints: Whether to overwrite existing root
device hints when `root_device` is
used.
:type overwrite_root_device_hints: Boolean
""" """
workflow_client = clients.workflow_engine context = clients.tripleoclient.create_mistral_context()
ooo_client = clients.tripleoclient for node_uuid in node_uuids:
boot_action = baremetal.ConfigureBootAction(
with ooo_client.messaging_websocket() as ws: node_uuid=node_uuid,
execution = base.start_workflow( kernel_name=kernel_name,
workflow_client, ramdisk_name=ramdisk_name,
'tripleo.baremetal.v1.configure', instance_boot_option=instance_boot_option
workflow_input=workflow_input ).run(context=context)
if boot_action:
raise RuntimeError(boot_action)
root_device_action = baremetal.ConfigureRootDeviceAction(
node_uuid=node_uuid,
root_device=root_device,
minimum_size=root_device_minimum_size,
overwrite=overwrite_root_device_hints
) )
root_device_action.run(context=context)
for payload in base.wait_for_messages(workflow_client, ws, execution): else:
if 'message' in payload: print('Successfully configured the nodes.')
print(payload['message'])
if payload['status'] != 'SUCCESS':
raise exceptions.NodeConfigurationError(
'Failed to configure nodes: {}'.format(payload['message']))
def configure_manageable_nodes(clients, **workflow_input): def configure_manageable_nodes(clients, kernel_name='bm-deploy-kernel',
ramdisk_name='bm-deploy-ramdisk',
instance_boot_option=None,
root_device=None, root_device_minimum_size=4,
overwrite_root_device_hints=False):
"""Configure all manageable Nodes. """Configure all manageable Nodes.
Run the tripleo.baremetal.v1.configure_manageable_nodes Mistral workflow. kernel_name=parsed_args.deploy_kernel,
ramdisk_name=parsed_args.deploy_ramdisk,
instance_boot_option=parsed_args.instance_boot_option,
root_device=parsed_args.root_device,
root_device_minimum_size=parsed_args.root_device_minimum_size,
overwrite_root_device_hints=(parsed_args.overwrite_root_device_hints)
:param kernel_name: Kernel to use
:type kernel_name: String
:param ramdisk_name: RAMDISK to use
:type ramdisk_name: String
:param instance_boot_option: Boot options to use
:type instance_boot_option: String
:param root_device: Path (name) of the root device.
:type root_device: String
:param root_device_minimum_size: Size of the given root device.
:type root_device_minimum_size: Integer
:param overwrite_root_device_hints: Whether to overwrite existing root
device hints when `root_device` is
used.
:type overwrite_root_device_hints: Boolean
""" """
workflow_client = clients.workflow_engine configure(
ooo_client = clients.tripleoclient clients=clients,
node_uuids=[
with ooo_client.messaging_websocket() as ws: i.uuid for i in clients.baremetal.node.list()
execution = base.start_workflow( if i.provision_state == "manageable" and not i.maintenance
workflow_client, ],
'tripleo.baremetal.v1.configure_manageable_nodes', kernel_name=kernel_name,
workflow_input=workflow_input ramdisk_name=ramdisk_name,
instance_boot_option=instance_boot_option,
root_device=root_device,
root_device_minimum_size=root_device_minimum_size,
overwrite_root_device_hints=overwrite_root_device_hints
) )
for payload in base.wait_for_messages(workflow_client, ws, execution):
if 'message' in payload:
print(payload['message'])
if payload['status'] != 'SUCCESS':
raise exceptions.NodeConfigurationError(
'Exception configuring nodes: {}'.format(payload['message']))
print(payload['message'])
def create_raid_configuration(clients, node_uuids, configuration): def create_raid_configuration(clients, node_uuids, configuration):
"""Create RAID configuration on nodes. """Create RAID configuration on nodes.