Browse Source

Merge "Remove mistral from the discover_and_enroll workflow"

tags/13.1.0
Zuul Gerrit Code Review 2 weeks ago
parent
commit
fc324e38e0
2 changed files with 83 additions and 53 deletions
  1. +20
    -32
      tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py
  2. +63
    -21
      tripleoclient/workflows/baremetal.py

+ 20
- 32
tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py View File

@@ -26,6 +26,8 @@ from osc_lib.tests import utils as test_utils
import yaml

from tripleoclient import exceptions
from tripleoclient import plugin
from tripleoclient.tests import fakes as ooofakes
from tripleoclient.tests.v1.overcloud_node import fakes
from tripleoclient.v1 import overcloud_node

@@ -1205,10 +1207,26 @@ class TestDiscoverNode(fakes.TestOvercloudNode):
execution.id = "IDID"
self.workflow.executions.create.return_value = execution
client = self.app.client_manager.tripleoclient
client.create_mistral_context = plugin.ClientWrapper(
instance=ooofakes.FakeInstanceData
).create_mistral_context
self.websocket = client.messaging_websocket()

self.cmd = overcloud_node.DiscoverNode(self.app, None)

self.gcn = mock.patch(
'tripleo_common.actions.baremetal.GetCandidateNodes',
autospec=True
)
self.gcn.start()
self.addCleanup(self.gcn.stop)
self.roun = mock.patch(
'tripleo_common.actions.baremetal.RegisterOrUpdateNodes',
autospec=True
)
self.roun.start()
self.addCleanup(self.roun.stop)

self.websocket.wait_for_messages.return_value = [{
"status": "SUCCESS",
"message": "Success",
@@ -1229,17 +1247,6 @@ class TestDiscoverNode(fakes.TestOvercloudNode):
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args)

self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.discover_and_enroll_nodes',
workflow_input={
'ip_addresses': '10.0.0.0/24',
'credentials': [['admin', 'password']],
'kernel_name': 'file://%s/agent.kernel' % self.http_boot,
'ramdisk_name': 'file://%s/agent.ramdisk' % self.http_boot,
'instance_boot_option': 'local'
}
)

def test_with_address_list(self):
argslist = ['--ip', '10.0.0.1', '--ip', '10.0.0.2',
'--credentials', 'admin:password']
@@ -1249,17 +1256,6 @@ class TestDiscoverNode(fakes.TestOvercloudNode):
parsed_args = self.check_parser(self.cmd, argslist, verifylist)
self.cmd.take_action(parsed_args)

self.workflow.executions.create.assert_called_once_with(
'tripleo.baremetal.v1.discover_and_enroll_nodes',
workflow_input={
'ip_addresses': ['10.0.0.1', '10.0.0.2'],
'credentials': [['admin', 'password']],
'kernel_name': 'file://%s/agent.kernel' % self.http_boot,
'ramdisk_name': 'file://%s/agent.ramdisk' % self.http_boot,
'instance_boot_option': 'local'
}
)

def test_with_all_options(self):
argslist = ['--range', '10.0.0.0/24',
'--credentials', 'admin:password',
@@ -1282,20 +1278,12 @@ class TestDiscoverNode(fakes.TestOvercloudNode):
self.cmd.take_action(parsed_args)

workflows_calls = [
mock.call('tripleo.baremetal.v1.discover_and_enroll_nodes',
workflow_input={'ip_addresses': '10.0.0.0/24',
'credentials': [['admin', 'password'],
['admin2', 'password2']],
'ports': [623, 6230],
'kernel_name': None,
'ramdisk_name': None,
'instance_boot_option': 'netboot'}),
mock.call('tripleo.baremetal.v1.introspect',
workflow_input={'node_uuids': ['MOCK_NODE_UUID'],
workflow_input={'node_uuids': [],
'run_validations': True,
'concurrency': 10}),
mock.call('tripleo.baremetal.v1.provide',
workflow_input={'node_uuids': ['MOCK_NODE_UUID']}
workflow_input={'node_uuids': []}
)
]
self.workflow.executions.create.assert_has_calls(workflows_calls)


+ 63
- 21
tripleoclient/workflows/baremetal.py View File

@@ -16,6 +16,8 @@ from __future__ import print_function

import six

from tripleo_common.actions import baremetal

from tripleoclient import exceptions
from tripleoclient.workflows import base

@@ -313,34 +315,74 @@ def create_raid_configuration(clients, **workflow_input):
'Failed to create RAID: {}'.format(payload['message']))


def discover_and_enroll(clients, **workflow_input):
"""Discover nodes.
def discover_and_enroll(clients, ip_addresses, credentials, kernel_name,
ramdisk_name, instance_boot_option,
existing_nodes=None, ports=None):
"""Discover nodes and enroll baremetal nodes.

:param clients: application client object.
:type clients: Object

:param ip_addresses: List of IP addresses.
:type ip_addresses: List || String

:param credentials: Credential information object
:type credentials: Tuple

: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 existing_nodes: List of nodes already discovered. If this is
undefined this object will be set to an empty
array.
:type existing_nodes: List

Run the tripleo.baremetal.v1.discover_and_enroll_nodes Mistral workflow.
:param ports: List of ports, if no ports are provided the list of ports
will be limted to [623].
:type ports: List

:returns: List
"""

workflow_client = clients.workflow_engine
tripleoclients = clients.tripleoclient
if not ports:
ports = [623]

with tripleoclients.messaging_websocket() as ws:
execution = base.start_workflow(
workflow_client,
'tripleo.baremetal.v1.discover_and_enroll_nodes',
workflow_input=workflow_input
)
if not existing_nodes:
existing_nodes = list()

for payload in base.wait_for_messages(workflow_client, ws, execution):
if payload.get('message'):
print(payload['message'])
context = clients.tripleoclient.create_mistral_context()

if payload['status'] == 'SUCCESS':
registered_nodes = payload['registered_nodes']
for nd in registered_nodes:
print('Successfully registered node UUID %s' % nd['uuid'])
return registered_nodes
get_candiate_nodes = baremetal.GetCandidateNodes(
ip_addresses,
ports,
credentials,
existing_nodes
)
probed_nodes = list()
for node in get_candiate_nodes.run(context=context):
probed_nodes.append(
baremetal.ProbeNode(**node).run(context=context)
)
print('Successfully probed node IP {}'.format(node['ip']))

register_or_update = baremetal.RegisterOrUpdateNodes(
nodes_json=probed_nodes,
instance_boot_option=instance_boot_option,
kernel_name=kernel_name,
ramdisk_name=ramdisk_name
)
registered_nodes = list()
for node in register_or_update.run(context=context):
print('Successfully registered node UUID {}'.format(node['uuid']))
registered_nodes.append(node)
else:
raise exceptions.RegisterOrUpdateError(
'Exception discovering nodes: {}'.format(payload['message']))
return registered_nodes


def clean_nodes(clients, **workflow_input):


Loading…
Cancel
Save