Merge "Refactor action generator"

This commit is contained in:
Jenkins 2015-12-10 10:08:12 +00:00 committed by Gerrit Code Review
commit 8bb6cada74
13 changed files with 79 additions and 364 deletions

View File

@ -1,6 +1,6 @@
# Copyright 2014 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@ -12,18 +12,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from oslo_utils import importutils
from mistral.actions.openstack.action_generator import base
SUPPORTED_MODULES = [
'Nova', 'Glance', 'Keystone', 'Heat', 'Neutron', 'Cinder', 'Ceilometer',
'Trove', 'Ironic'
]
def all_generators():
return [
generators.NovaActionGenerator,
generators.GlanceActionGenerator,
generators.KeystoneActionGenerator,
generators.HeatActionGenerator,
generators.NeutronActionGenerator,
generators.CinderActionGenerator,
generators.CeilometerActionGenerator,
generators.TroveActionGenerator,
generators.IronicActionGenerator
]
for mod_name in SUPPORTED_MODULES:
mod_namespace = mod_name.lower()
mod_cls_name = 'mistral.actions.openstack.actions.%sAction' % mod_name
mod_action_cls = importutils.import_class(mod_cls_name)
generator_cls_name = '%sActionGenerator' % mod_name
yield type(
generator_cls_name,
(base.OpenStackActionGenerator,),
{
'action_namespace': mod_namespace,
'base_action_class': mod_action_cls
}
)

View File

@ -1,61 +0,0 @@
# Copyright 2014 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import base
from mistral.actions.openstack import actions
class NovaActionGenerator(base.OpenStackActionGenerator):
action_namespace = "nova"
base_action_class = actions.NovaAction
class GlanceActionGenerator(base.OpenStackActionGenerator):
action_namespace = "glance"
base_action_class = actions.GlanceAction
class KeystoneActionGenerator(base.OpenStackActionGenerator):
action_namespace = "keystone"
base_action_class = actions.KeystoneAction
class HeatActionGenerator(base.OpenStackActionGenerator):
action_namespace = "heat"
base_action_class = actions.HeatAction
class NeutronActionGenerator(base.OpenStackActionGenerator):
action_namespace = "neutron"
base_action_class = actions.NeutronAction
class CinderActionGenerator(base.OpenStackActionGenerator):
action_namespace = "cinder"
base_action_class = actions.CinderAction
class CeilometerActionGenerator(base.OpenStackActionGenerator):
action_namespace = "ceilometer"
base_action_class = actions.CeilometerAction
class TroveActionGenerator(base.OpenStackActionGenerator):
action_namespace = "trove"
base_action_class = actions.TroveAction
class IronicActionGenerator(base.OpenStackActionGenerator):
action_namespace = "ironic"
base_action_class = actions.IronicAction

View File

@ -21,10 +21,9 @@ from keystoneclient import httpclient
from keystoneclient.v3 import client as keystoneclient
from neutronclient.v2_0 import client as neutronclient
from novaclient import client as novaclient
from troveclient import client as troveclient
from oslo_config import cfg
from oslo_log import log
from troveclient import client as troveclient
from mistral.actions.openstack import base
from mistral import context

View File

@ -1,32 +0,0 @@
# Copyright 2015 Alcatel-Lucent, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class CeilometerGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "ceilometer.alarms_list"
generator = generators.CeilometerActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.CeilometerAction))
self.assertEqual("alarms.list", action['class'].client_method_name)

View File

@ -1,32 +0,0 @@
# Copyright 2014 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class CinderGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "cinder.volumes_list"
generator = generators.CinderActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.CinderAction))
self.assertEqual("volumes.list", action['class'].client_method_name)

View File

@ -0,0 +1,54 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions import generator_factory
from mistral.actions.openstack import actions
from mistral.tests.unit import base
MODULE_MAPPING = {
'nova': ['nova.servers_get', actions.NovaAction],
'glance': ['glance.images_list', actions.GlanceAction],
'keystone': ['keystone.users_create', actions.KeystoneAction],
'heat': ['heat.stacks_list', actions.HeatAction],
'neutron': ['neutron.show_network', actions.NeutronAction],
'cinder': ['cinder.volumes_list', actions.CinderAction],
'ceilometer': ['ceilometer.alarms_list', actions.CeilometerAction],
'trove': ['trove.instances_list', actions.TroveAction],
'ironic': ['ironic.node_list', actions.IronicAction],
}
EXTRA_MODULES = ['neutron']
class GeneratorTest(base.BaseTest):
def test_generator(self):
for generator_cls in generator_factory.all_generators():
action_classes = generator_cls.create_actions()
action_name = MODULE_MAPPING.get(generator_cls.action_namespace)[0]
action_cls = MODULE_MAPPING.get(generator_cls.action_namespace)[1]
method_name_pre = action_name.split('.')[1]
method_name = (
method_name_pre
if generator_cls.action_namespace in EXTRA_MODULES
else method_name_pre.replace('_', '.')
)
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertTrue(issubclass(action['class'], action_cls))
self.assertEqual(method_name, action['class'].client_method_name)

View File

@ -1,32 +0,0 @@
# Copyright 2014 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class GlanceGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "glance.images_list"
generator = generators.GlanceActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.GlanceAction))
self.assertEqual("images.list", action['class'].client_method_name)

View File

@ -1,32 +0,0 @@
# Copyright 2014 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class HeatGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "heat.stacks_list"
generator = generators.HeatActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.HeatAction))
self.assertEqual("stacks.list", action['class'].client_method_name)

View File

@ -1,32 +0,0 @@
# Copyright 2015 - AT&T Services, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class IronicGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "ironic.node_list"
generator = generators.IronicActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.IronicAction))
self.assertEqual("node.list", action['class'].client_method_name)

View File

@ -1,32 +0,0 @@
# Copyright 2014 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class KeystoneGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "keystone.users_create"
generator = generators.KeystoneActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.KeystoneAction))
self.assertEqual("users.create", action['class'].client_method_name)

View File

@ -1,32 +0,0 @@
# Copyright 2014 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class NeutronGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "neutron.show_network"
generator = generators.NeutronActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.NeutronAction))
self.assertEqual("show_network", action['class'].client_method_name)

View File

@ -1,32 +0,0 @@
# Copyright 2014 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class NovaGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "nova.servers_get"
generator = generators.NovaActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.NovaAction))
self.assertEqual("servers.get", action['class'].client_method_name)

View File

@ -1,32 +0,0 @@
# Copyright 2015 - AT&T Services, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.actions.openstack.action_generator import generators
from mistral.actions.openstack import actions
from mistral.tests.unit import base
class TroveGeneratorTest(base.BaseTest):
def test_generator(self):
action_name = "trove.instances_list"
generator = generators.TroveActionGenerator
action_classes = generator.create_actions()
action = self._assert_single_item(
action_classes,
name=action_name
)
self.assertIsNotNone(generator)
self.assertTrue(issubclass(action['class'], actions.TroveAction))
self.assertEqual("instances.list", action['class'].client_method_name)