Don't create actions when inspection fails
At the moment, if the inspection of an action fails we set the arg_list to None. This will create a broken action in many cases. This change means that we skip actions, only if the inspect fails and an exception is raised. Change-Id: I826e24b5bebfc67b0c0101528fd44074dcd3cead
This commit is contained in:
parent
66ef4e3848
commit
f72c4621b4
|
@ -85,25 +85,21 @@ class OpenStackActionGenerator(action_generator.ActionGenerator):
|
||||||
action_classes = []
|
action_classes = []
|
||||||
|
|
||||||
for action_name, method_name in method_dict.items():
|
for action_name, method_name in method_dict.items():
|
||||||
clazz = cls.create_action_class(method_name)
|
class_ = cls.create_action_class(method_name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client_method = clazz.get_fake_client_method()
|
client_method = class_.get_fake_client_method()
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception("Failed to create action: %s.%s" %
|
LOG.exception("Failed to create action: %s.%s" %
|
||||||
(cls.action_namespace, action_name))
|
(cls.action_namespace, action_name))
|
||||||
client_method = None
|
continue
|
||||||
|
|
||||||
if client_method:
|
arg_list = i_u.get_arg_list_as_str(client_method)
|
||||||
arg_list = i_u.get_arg_list_as_str(client_method)
|
description = i_u.get_docstring(client_method)
|
||||||
description = i_u.get_docstring(client_method)
|
|
||||||
else:
|
|
||||||
arg_list = ''
|
|
||||||
description = None
|
|
||||||
|
|
||||||
action_classes.append(
|
action_classes.append(
|
||||||
{
|
{
|
||||||
'class': clazz,
|
'class': class_,
|
||||||
'name': "%s.%s" % (cls.action_namespace, action_name),
|
'name': "%s.%s" % (cls.action_namespace, action_name),
|
||||||
'description': description,
|
'description': description,
|
||||||
'arg_list': arg_list,
|
'arg_list': arg_list,
|
||||||
|
|
|
@ -15,6 +15,8 @@ import os
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
from mistral.actions import generator_factory
|
from mistral.actions import generator_factory
|
||||||
from mistral.actions.openstack import actions
|
from mistral.actions.openstack import actions
|
||||||
from mistral import config
|
from mistral import config
|
||||||
|
@ -61,12 +63,28 @@ CONF.register_opt(config.os_actions_mapping_path)
|
||||||
|
|
||||||
|
|
||||||
class GeneratorTest(base.BaseTest):
|
class GeneratorTest(base.BaseTest):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(GeneratorTest, self).setUp()
|
||||||
|
|
||||||
|
# The baremetal inspector client expects the service to be running
|
||||||
|
# when it is initialised and attempts to connect. This mocks out this
|
||||||
|
# service only and returns a simple function that can be used by the
|
||||||
|
# inspection utils.
|
||||||
|
self.baremetal_patch = mock.patch.object(
|
||||||
|
actions.BaremetalIntrospectionAction,
|
||||||
|
"get_fake_client_method",
|
||||||
|
return_value=lambda x: None)
|
||||||
|
|
||||||
|
self.baremetal_patch.start()
|
||||||
|
self.addCleanup(self.baremetal_patch.stop)
|
||||||
|
|
||||||
def test_generator(self):
|
def test_generator(self):
|
||||||
for generator_cls in generator_factory.all_generators():
|
for generator_cls in generator_factory.all_generators():
|
||||||
action_classes = generator_cls.create_actions()
|
action_classes = generator_cls.create_actions()
|
||||||
|
|
||||||
action_name = MODULE_MAPPING.get(generator_cls.action_namespace)[0]
|
action_name = MODULE_MAPPING[generator_cls.action_namespace][0]
|
||||||
action_cls = MODULE_MAPPING.get(generator_cls.action_namespace)[1]
|
action_cls = MODULE_MAPPING[generator_cls.action_namespace][1]
|
||||||
method_name_pre = action_name.split('.')[1]
|
method_name_pre = action_name.split('.')[1]
|
||||||
method_name = (
|
method_name = (
|
||||||
method_name_pre
|
method_name_pre
|
||||||
|
|
Loading…
Reference in New Issue