Add the openstack baremetal introspection all status command
This also adds the --discoverd-url command to the introspection start variant. Change-Id: If36a093dc0ca8e05e6b35b91acabcd61b84a2692
This commit is contained in:
parent
208df7443c
commit
c2c96537aa
|
@ -65,6 +65,10 @@ class ClientWrapper(object):
|
|||
|
||||
def baremetal(self):
|
||||
|
||||
# TODO(d0ugal): When the ironicclient has it's own OSC plugin, the
|
||||
# following client handling code should be removed in favor of the
|
||||
# upstream version.
|
||||
|
||||
if self._baremetal is None:
|
||||
|
||||
endpoint = self._instace.get_endpoint_for_service_type(
|
||||
|
|
|
@ -155,7 +155,8 @@ class TestIntrospectionAll(fakes.TestBaremetal):
|
|||
parsed_args = self.check_parser(self.cmd, [], [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
discoverd_mock.assert_called_once_with('ABCDEFGH', auth_token='TOKEN')
|
||||
discoverd_mock.assert_called_once_with(
|
||||
'ABCDEFGH', base_url=None, auth_token='TOKEN')
|
||||
|
||||
@mock.patch('ironic_discoverd.client.introspect')
|
||||
def test_introspect_all(self, discoverd_mock):
|
||||
|
@ -171,7 +172,70 @@ class TestIntrospectionAll(fakes.TestBaremetal):
|
|||
self.cmd.take_action(parsed_args)
|
||||
|
||||
discoverd_mock.assert_has_calls([
|
||||
mock.call('ABCDEFGH', auth_token='TOKEN'),
|
||||
mock.call('IJKLMNOP', auth_token='TOKEN'),
|
||||
mock.call('QRSTUVWX', auth_token='TOKEN'),
|
||||
mock.call('ABCDEFGH', base_url=None, auth_token='TOKEN'),
|
||||
mock.call('IJKLMNOP', base_url=None, auth_token='TOKEN'),
|
||||
mock.call('QRSTUVWX', base_url=None, auth_token='TOKEN'),
|
||||
])
|
||||
|
||||
|
||||
class TestStatusAll(fakes.TestBaremetal):
|
||||
|
||||
def setUp(self):
|
||||
super(TestStatusAll, self).setUp()
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = baremetal.StatusAllPlugin(self.app, None)
|
||||
|
||||
@mock.patch('ironic_discoverd.client.get_status')
|
||||
def test_introspect_all_one(self, discoverd_mock):
|
||||
|
||||
client = self.app.client_manager.rdomanager_oscplugin.baremetal()
|
||||
client.node.list.return_value = [
|
||||
mock.Mock(uuid="ABCDEFGH")
|
||||
]
|
||||
|
||||
discoverd_mock.return_value = {
|
||||
'finished': False, 'error': None
|
||||
}
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, [], [])
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
discoverd_mock.assert_called_once_with(
|
||||
'ABCDEFGH', base_url=None, auth_token='TOKEN')
|
||||
|
||||
self.assertEqual(result, (
|
||||
('Node UUID', 'Finished', 'Error'),
|
||||
[('ABCDEFGH', False, None)]))
|
||||
|
||||
@mock.patch('ironic_discoverd.client.get_status')
|
||||
def test_introspect_all(self, discoverd_mock):
|
||||
|
||||
client = self.app.client_manager.rdomanager_oscplugin.baremetal()
|
||||
client.node.list.return_value = [
|
||||
mock.Mock(uuid="ABCDEFGH"),
|
||||
mock.Mock(uuid="IJKLMNOP"),
|
||||
mock.Mock(uuid="QRSTUVWX"),
|
||||
]
|
||||
|
||||
discoverd_mock.return_value = {
|
||||
'finished': False, 'error': None
|
||||
}
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, [], [])
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
discoverd_mock.assert_has_calls([
|
||||
mock.call('ABCDEFGH', base_url=None, auth_token='TOKEN'),
|
||||
mock.call('IJKLMNOP', base_url=None, auth_token='TOKEN'),
|
||||
mock.call('QRSTUVWX', base_url=None, auth_token='TOKEN'),
|
||||
])
|
||||
|
||||
self.assertEqual(result, (
|
||||
('Node UUID', 'Finished', 'Error'),
|
||||
[
|
||||
('ABCDEFGH', False, None),
|
||||
('IJKLMNOP', False, None),
|
||||
('QRSTUVWX', False, None)
|
||||
]
|
||||
))
|
||||
|
|
|
@ -21,7 +21,9 @@ import json
|
|||
import logging
|
||||
import sys
|
||||
|
||||
from cliff import lister
|
||||
from ironic_discoverd import client as discoverd_client
|
||||
from openstackclient.common import utils
|
||||
from os_cloud_config import nodes
|
||||
|
||||
from cliff import command
|
||||
|
@ -90,8 +92,19 @@ class ImportPlugin(command.Command):
|
|||
keystone_client=self.app.client_manager.identity)
|
||||
|
||||
|
||||
class IntrospectionAllPlugin(command.Command):
|
||||
"""Baremetal introspection all plugin"""
|
||||
class IntrospectionParser(object):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(IntrospectionParser, self).get_parser(prog_name)
|
||||
parser.add_argument('--discoverd-url',
|
||||
default=utils.env('DISCOVERD_URL', default=None),
|
||||
help='discoverd URL, defaults to localhost '
|
||||
'(env: DISCOVERD_URL).')
|
||||
return parser
|
||||
|
||||
|
||||
class IntrospectionAllPlugin(IntrospectionParser, command.Command):
|
||||
"""Baremetal all introspection plugin"""
|
||||
|
||||
log = logging.getLogger(__name__ + ".IntrospectionAll")
|
||||
|
||||
|
@ -104,4 +117,35 @@ class IntrospectionAllPlugin(command.Command):
|
|||
self.log.debug("Starting introspection of Ironic node {0}".format(
|
||||
node.uuid))
|
||||
auth_token = self.app.client_manager.auth_ref.auth_token
|
||||
discoverd_client.introspect(node.uuid, auth_token=auth_token)
|
||||
discoverd_client.introspect(
|
||||
node.uuid,
|
||||
base_url=parsed_args.discoverd_url,
|
||||
auth_token=auth_token)
|
||||
|
||||
|
||||
class StatusAllPlugin(IntrospectionParser, lister.Lister):
|
||||
"""Baremetal all status plugin"""
|
||||
|
||||
log = logging.getLogger(__name__ + ".StatusAllPlugin")
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
|
||||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
client = self.app.client_manager.rdomanager_oscplugin.baremetal()
|
||||
|
||||
statuses = []
|
||||
|
||||
for node in client.node.list():
|
||||
self.log.debug("Getting introspection status of Ironic node {0}"
|
||||
.format(node.uuid))
|
||||
auth_token = self.app.client_manager.auth_ref.auth_token
|
||||
statuses.append((node.uuid, discoverd_client.get_status(
|
||||
node.uuid,
|
||||
base_url=parsed_args.discoverd_url,
|
||||
auth_token=auth_token)))
|
||||
|
||||
return (
|
||||
("Node UUID", "Finished", "Error"),
|
||||
list((node_uuid, status['finished'], status['error'])
|
||||
for (node_uuid, status) in statuses)
|
||||
)
|
||||
|
|
|
@ -56,6 +56,7 @@ openstack.cli.extension =
|
|||
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
|
||||
overcloud_image_build = rdomanager_oscplugin.v1.overcloud_image:BuildPlugin
|
||||
overcloud_image_create = rdomanager_oscplugin.v1.overcloud_image:CreatePlugin
|
||||
undercloud_install = rdomanager_oscplugin.v1.undercloud:InstallPlugin
|
||||
|
|
Loading…
Reference in New Issue