Implementation of the Baremental introspection all start command

Change-Id: I8dfc727155dc562c4a74b84548658b08b74fa166
This commit is contained in:
Dougal Matthews
2015-03-24 17:19:58 +00:00
parent d6a3d98ed9
commit 208df7443c
5 changed files with 67 additions and 10 deletions

View File

@@ -36,4 +36,5 @@ class TestBaremetal(utils.TestCommand):
def setUp(self):
super(TestBaremetal, self).setUp()
self.app.client_manager.auth_ref = mock.Mock(auth_token="TOKEN")
self.app.client_manager.rdomanager_oscplugin = FakeClientWrapper()

View File

@@ -23,20 +23,14 @@ from rdomanager_oscplugin.tests.v1.baremetal import fakes
from rdomanager_oscplugin.v1 import baremetal
class TestBaremetalBase(fakes.TestBaremetal):
def setUp(self):
super(TestBaremetalBase, self).setUp()
# Get the command object to test
self.cmd = baremetal.ImportPlugin(self.app, None)
class TestImport(TestBaremetalBase):
class TestImport(fakes.TestBaremetal):
def setUp(self):
super(TestImport, self).setUp()
# Get the command object to test
self.cmd = baremetal.ImportPlugin(self.app, None)
self.json_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
self.csv_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
@@ -140,3 +134,44 @@ pxe_ssh,192.168.122.1,root,"KEY2",00:7c:ef:3d:eb:60""")
],
client=self.app.client_manager.rdomanager_oscplugin.baremetal(),
keystone_client=None)
class TestIntrospectionAll(fakes.TestBaremetal):
def setUp(self):
super(TestIntrospectionAll, self).setUp()
# Get the command object to test
self.cmd = baremetal.IntrospectionAllPlugin(self.app, None)
@mock.patch('ironic_discoverd.client.introspect')
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")
]
parsed_args = self.check_parser(self.cmd, [], [])
self.cmd.take_action(parsed_args)
discoverd_mock.assert_called_once_with('ABCDEFGH', auth_token='TOKEN')
@mock.patch('ironic_discoverd.client.introspect')
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"),
]
parsed_args = self.check_parser(self.cmd, [], [])
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'),
])

View File

@@ -21,6 +21,7 @@ import json
import logging
import sys
from ironic_discoverd import client as discoverd_client
from os_cloud_config import nodes
from cliff import command
@@ -87,3 +88,20 @@ class ImportPlugin(command.Command):
nodes_json,
client=self.app.client_manager.rdomanager_oscplugin.baremetal(),
keystone_client=self.app.client_manager.identity)
class IntrospectionAllPlugin(command.Command):
"""Baremetal introspection all plugin"""
log = logging.getLogger(__name__ + ".IntrospectionAll")
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
client = self.app.client_manager.rdomanager_oscplugin.baremetal()
for node in client.node.list():
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)

View File

@@ -10,3 +10,5 @@ os-cloud-config
python-ironicclient>=0.4.1
python-openstackclient>=1.0.0
# The ironic-discoverd OSC integration isn't yet on PyPI
-e git://github.com/stackforge/ironic-discoverd.git#egg=ironic_discoverd

View File

@@ -55,6 +55,7 @@ openstack.cli.extension =
openstack.rdomanager_oscplugin.v1 =
baremetal_import = rdomanager_oscplugin.v1.baremetal:ImportPlugin
baremetal_introspection_all_start = rdomanager_oscplugin.v1.baremetal:IntrospectionAllPlugin
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