Add one general testing of resource_mapping

Each resource in Heat has resource_mapping fucntion for loading his type
in environment for futher using.
This method should be callable and should return dictionary, where
key is resource type and value is corresponding resource class.
More over resource_type should have format:
"Platform Type"/"Service type"/.../"Resource Name"

This patch adds common test for this method and check all modules in
heat.engine.resources sub-directories.
Duplicate useless tests were removed.

Change-Id: I8148811418c21277a4b732de98a53c5291f57f1f
changes/10/281810/8
Sergey Kraynev 7 years ago
parent b8da6cf95e
commit 440a306216

@ -15,7 +15,6 @@ import mock
import six
from heat.common import exception
from heat.engine.resources.openstack.cinder import volume_type
from heat.engine import stack
from heat.engine import template
from heat.tests import common
@ -57,14 +56,6 @@ class CinderVolumeTypeTest(common.HeatTestCase):
self.project_list = mock.MagicMock()
keystoneclient.client.projects.get = self.project_list
def test_resource_mapping(self):
mapping = volume_type.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(volume_type.CinderVolumeType,
mapping['OS::Cinder::VolumeType'])
self.assertIsInstance(self.my_volume_type,
volume_type.CinderVolumeType)
def _test_handle_create(self, is_public=True, projects=None):
value = mock.MagicMock()
volume_type_id = '927202df-1afb-497f-8368-9c2d2f26e5db'

@ -13,7 +13,6 @@
import mock
from heat.engine.resources.openstack.cinder import encrypted_volume_type
from heat.engine import stack
from heat.engine import template
from heat.tests import common
@ -55,16 +54,6 @@ class CinderEncryptedVolumeTypeTest(common.HeatTestCase):
self.volume_encryption_types = (
self.cinderclient.volume_encryption_types)
def test_resource_mapping(self):
mapping = encrypted_volume_type.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(encrypted_volume_type.CinderEncryptedVolumeType,
mapping['OS::Cinder::EncryptedVolumeType'])
self.assertIsInstance(
self.my_encrypted_vol_type,
encrypted_volume_type.CinderEncryptedVolumeType
)
def test_handle_create(self):
value = mock.MagicMock()
volume_type_id = '01bd581d-33fe-4d6d-bd7b-70ae076d39fb'

@ -159,12 +159,6 @@ class DesignateDomainTest(common.HeatTestCase):
self.test_resource.resource_id
)
def test_resource_mapping(self):
mapping = domain.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(domain.DesignateDomain, mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_resource, domain.DesignateDomain)
def test_resource_show_resource(self):
args = dict(
name='test',

@ -226,12 +226,6 @@ class DesignateRecordTest(common.HeatTestCase):
mock_record_delete.side_effect = designate_exception.NotFound
self.assertIsNone(self.test_resource.handle_delete())
def test_resource_mapping(self):
mapping = record.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(record.DesignateRecord, mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_resource, record.DesignateRecord)
def test_resource_show_resource(self):
args = dict(
name='test-record.com',

@ -16,7 +16,6 @@ import six
from heat.common import exception
from heat.common import template_format
from heat.engine.resources.openstack.glance import image as gi
from heat.engine import stack as parser
from heat.engine import template
from heat.tests import common
@ -79,12 +78,6 @@ class GlanceImageTest(common.HeatTestCase):
resource.validate)
self.assertIn(error_msg, six.text_type(exc))
def test_resource_mapping(self):
mapping = gi.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(gi.GlanceImage, mapping['OS::Glance::Image'])
self.assertIsInstance(self.my_image, gi.GlanceImage)
def test_invalid_min_disk(self):
# invalid 'min_disk'
tpl = template_format.parse(image_template_validate)

@ -15,7 +15,6 @@ import uuid
import mock
from heat.engine.resources.openstack.heat import cloud_config
from heat.engine import stack
from heat.engine import template
from heat.tests import common
@ -43,13 +42,6 @@ class CloudConfigTest(common.HeatTestCase):
self.rpc_client = mock.MagicMock()
self.config._rpc_client = self.rpc_client
def test_resource_mapping(self):
mapping = cloud_config.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(cloud_config.CloudConfig,
mapping['OS::Heat::CloudConfig'])
self.assertIsInstance(self.config, cloud_config.CloudConfig)
def test_handle_create(self):
config_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
value = {'id': config_id}

@ -17,7 +17,6 @@ import uuid
import mock
from heat.common import exception as exc
from heat.engine.resources.openstack.heat import multi_part as mp
from heat.engine import stack as parser
from heat.engine import template
from heat.tests import common
@ -47,13 +46,6 @@ class MultipartMimeTest(common.HeatTestCase):
self.rpc_client = mock.MagicMock()
self.config._rpc_client = self.rpc_client
def test_resource_mapping(self):
mapping = mp.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(mp.MultipartMime,
mapping['OS::Heat::MultipartMime'])
self.assertIsInstance(self.config, mp.MultipartMime)
def test_handle_create(self):
config_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
sc = {'id': config_id}

@ -197,10 +197,6 @@ class ResourceChainTests(common.HeatTestCase):
chain = self._create_chain(TEMPLATE)
self.assertEqual({}, chain.child_params())
def test_resource_mapping(self):
found = resource_chain.resource_mapping()['OS::Heat::ResourceChain']
self.assertEqual(found, resource_chain.ResourceChain)
def _create_chain(self, t):
self.stack = utils.parse_stack(t)
snip = self.stack.t.resource_definitions(self.stack)['test-chain']

@ -16,7 +16,6 @@ import six
from heat.common import exception as exc
from heat.common import template_format
from heat.engine.resources.openstack.heat import software_component as sc
from heat.engine import stack
from heat.engine import template
from heat.tests import common
@ -60,13 +59,6 @@ class SoftwareComponentTest(common.HeatTestCase):
self.rpc_client = mock.MagicMock()
self.component._rpc_client = self.rpc_client
def test_resource_mapping(self):
mapping = sc.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(sc.SoftwareComponent,
mapping['OS::Heat::SoftwareComponent'])
self.assertIsInstance(self.component, sc.SoftwareComponent)
def test_handle_create(self):
config_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
value = {'id': config_id}

@ -14,7 +14,6 @@
import mock
from heat.common import exception as exc
from heat.engine.resources.openstack.heat import software_config as sc
from heat.engine import stack
from heat.engine import template
from heat.tests import common
@ -46,13 +45,6 @@ class SoftwareConfigTest(common.HeatTestCase):
self.rpc_client = mock.MagicMock()
self.config._rpc_client = self.rpc_client
def test_resource_mapping(self):
mapping = sc.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(sc.SoftwareConfig,
mapping['OS::Heat::SoftwareConfig'])
self.assertIsInstance(self.config, sc.SoftwareConfig)
def test_handle_create(self):
config_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
value = {'id': config_id}

@ -214,10 +214,6 @@ class SoftwareDeploymentTest(common.HeatTestCase):
"SOFTWARE_CONFIG since there are "
"software deployments on it.", six.text_type(err))
def test_resource_mapping(self):
self._create_stack(self.template)
self.assertIsInstance(self.deployment, sd.SoftwareDeployment)
def mock_software_config(self):
config = {
'id': '48e8ade1-9196-42d5-89a2-f709fde42632',

@ -133,19 +133,6 @@ class StructuredConfigTestJSON(common.HeatTestCase):
self.rpc_client = mock.MagicMock()
self.config._rpc_client = self.rpc_client
def test_resource_mapping(self):
mapping = sc.resource_mapping()
self.assertEqual(4, len(mapping))
self.assertEqual(sc.StructuredConfig,
mapping['OS::Heat::StructuredConfig'])
self.assertEqual(sc.StructuredDeployment,
mapping['OS::Heat::StructuredDeployment'])
self.assertEqual(sc.StructuredDeploymentGroup,
mapping['OS::Heat::StructuredDeploymentGroup'])
self.assertEqual(sc.StructuredDeployments,
mapping['OS::Heat::StructuredDeployments'])
self.assertIsInstance(self.config, sc.StructuredConfig)
def test_handle_create(self):
config_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
value = {'id': config_id}

@ -213,13 +213,6 @@ class KeystoneEndpointTest(common.HeatTestCase):
enabled=prop_diff[endpoint.KeystoneEndpoint.ENABLED]
)
def test_resource_mapping(self):
rsrc = self._setup_endpoint_resource('test_resource_mapping')
mapping = endpoint.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(endpoint.KeystoneEndpoint, mapping[RESOURCE_TYPE])
self.assertIsInstance(rsrc, endpoint.KeystoneEndpoint)
def test_properties_title(self):
property_title_map = {
endpoint.KeystoneEndpoint.SERVICE: 'service',

@ -75,12 +75,6 @@ class KeystoneGroupTest(common.HeatTestCase):
return value
def test_resource_mapping(self):
mapping = group.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(group.KeystoneGroup, mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_group, group.KeystoneGroup)
def test_properties_title(self):
property_title_map = {
group.KeystoneGroup.NAME: 'name',

@ -76,12 +76,6 @@ class KeystoneProjectTest(common.HeatTestCase):
return value
def test_resource_mapping(self):
mapping = project.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(project.KeystoneProject, mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_project, project.KeystoneProject)
def test_project_handle_create(self):
mock_project = self._get_mock_project()
self.projects.create.return_value = mock_project

@ -68,12 +68,6 @@ class KeystoneRegionTest(common.HeatTestCase):
return value
def test_resource_mapping(self):
mapping = region.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(region.KeystoneRegion, mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_region, region.KeystoneRegion)
def test_region_handle_create(self):
mock_region = self._get_mock_region()
self.regions.create.return_value = mock_region

@ -59,12 +59,6 @@ class KeystoneRoleTest(common.HeatTestCase):
return value
def test_resource_mapping(self):
mapping = role.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(role.KeystoneRole, mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_role, role.KeystoneRole)
def test_role_handle_create(self):
mock_role = self._get_mock_role()
self.roles.create.return_value = mock_role

@ -95,14 +95,6 @@ class KeystoneRoleAssignmentMixinTest(common.HeatTestCase):
(self.test_role_assignment.client_plugin.
return_value) = self.keystone_client_plugin
def test_resource_mapping(self):
mapping = role_assignments.resource_mapping()
self.assertEqual(2, len(mapping))
self.assertEqual(role_assignments.KeystoneUserRoleAssignment,
mapping['OS::Keystone::UserRoleAssignment'])
self.assertEqual(role_assignments.KeystoneGroupRoleAssignment,
mapping['OS::Keystone::GroupRoleAssignment'])
def test_properties_title(self):
property_title_map = {MixinClass.ROLES: 'roles'}

@ -196,14 +196,6 @@ class KeystoneServiceTest(common.HeatTestCase):
enabled=prop_diff[service.KeystoneService.ENABLED]
)
def test_resource_mapping(self):
rsrc = self._setup_service_resource(
'test_resource_mapping')
mapping = service.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(service.KeystoneService, mapping[RESOURCE_TYPE])
self.assertIsInstance(rsrc, service.KeystoneService)
def test_properties_title(self):
property_title_map = {
service.KeystoneService.NAME: 'name',

@ -83,12 +83,6 @@ class KeystoneUserTest(common.HeatTestCase):
return value
def test_resource_mapping(self):
mapping = user.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(user.KeystoneUser, mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_user, user.KeystoneUser)
def test_user_handle_create(self):
mock_user = self._get_mock_user()
self.users.create.return_value = mock_user

@ -144,11 +144,6 @@ class TestMagnumBay(common.HeatTestCase):
self.assertEqual((b.DELETE, b.COMPLETE), b.state)
self.assertEqual(2, self.client.bays.get.call_count)
def test_resource_mapping(self):
mapping = bay.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(mapping[RESOURCE_TYPE], bay.Bay)
class BaymodelConstraintTest(common.HeatTestCase):
def setUp(self):

@ -90,11 +90,6 @@ class TestMagnumBayModel(common.HeatTestCase):
self.assertEqual((bm.CREATE, bm.COMPLETE), bm.state)
self.client.baymodels.create.assert_called_once_with(**self.expected)
def test_resource_mapping(self):
mapping = baymodel.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(baymodel.BayModel, mapping[RESOURCE_TYPE])
class TestMagnumBayModelWithAddedProperties(TestMagnumBayModel):
magnum_template = '''

@ -117,12 +117,6 @@ class ManilaSecurityServiceTest(common.HeatTestCase):
self.assertIn('Exception: resources.security_service: error',
six.text_type(exc))
def test_resource_mapping(self):
mapping = security_service.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(security_service.SecurityService,
mapping['OS::Manila::SecurityService'])
def test_update(self):
ss = self._create_resource('security_service', self.rsrc_defn,
self.stack)

@ -193,9 +193,3 @@ class ManilaShareNetworkTest(common.HeatTestCase):
self.assertEqual('3', net.FnGetAtt('cidr'))
self.assertEqual('5', net.FnGetAtt('ip_version'))
self.assertEqual('6', net.FnGetAtt('network_type'))
def test_resource_mapping(self):
mapping = share_network.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(share_network.ManilaShareNetwork,
mapping['OS::Manila::ShareNetwork'])

@ -82,12 +82,6 @@ class MistralCronTriggerTest(common.HeatTestCase):
expected_state = (ct.CREATE, ct.COMPLETE)
self.assertEqual(expected_state, ct.state)
def test_resource_mapping(self):
mapping = cron_trigger.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(cron_trigger.CronTrigger,
mapping['OS::Mistral::CronTrigger'])
def test_attributes(self):
ct = self._create_resource('trigger', self.rsrc_defn, self.stack)
self.assertEqual('2015-03-01 00:00:00',

@ -536,12 +536,6 @@ class TestMistralWorkflow(common.HeatTestCase):
self.assertEqual(2, self.mistral.executions.delete.call_count)
data_delete.assert_called_once_with('executions')
def test_resource_mapping(self):
mapping = workflow.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(workflow.Workflow,
mapping['OS::Mistral::Workflow'])
def test_signal_failed(self):
tmpl = template_format.parse(workflow_template_full)
stack = utils.parse_stack(tmpl)

@ -222,14 +222,6 @@ class MonascaAlarmDefinitionTest(common.HeatTestCase):
mock_alarm_delete.side_effect = client_plugin.monasca_exc.NotFound
self.assertIsNone(self.test_resource.handle_delete())
def test_resource_mapping(self):
mapping = alarm_definition.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(alarm_definition.MonascaAlarmDefinition,
mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_resource,
alarm_definition.MonascaAlarmDefinition)
def test_resource_show_resource(self):
mock_notification_get = self.test_client.alarm_definitions.get
mock_notification_get.return_value = {}

@ -168,14 +168,6 @@ class MonascaNotificationTest(common.HeatTestCase):
self.assertIsNone(self.test_resource.handle_delete())
def test_resource_mapping(self):
mapping = notification.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(notification.MonascaNotification,
mapping[RESOURCE_TYPE])
self.assertIsInstance(self.test_resource,
notification.MonascaNotification)
def test_resource_show_resource(self):
mock_notification_get = self.test_client.notifications.get
mock_notification_get.return_value = {}

@ -15,7 +15,6 @@ import mock
from heat.common import template_format
from heat.engine.clients.os import neutron
from heat.engine.resources.openstack.neutron import address_scope
from heat.engine import rsrc_defn
from heat.engine import stack
from heat.engine import template
@ -56,13 +55,6 @@ class NeutronAddressScopeTest(common.HeatTestCase):
self.my_address_scope.client = mock.MagicMock(
return_value=self.neutronclient)
def test_resource_mapping(self):
mapping = address_scope.resource_mapping()
self.assertEqual(address_scope.AddressScope,
mapping['OS::Neutron::AddressScope'])
self.assertIsInstance(self.my_address_scope,
address_scope.AddressScope)
def test_address_scope_handle_create(self):
addrs = {
'address_scope': {

@ -19,7 +19,6 @@ from neutronclient.common import exceptions
from heat.common import exception
from heat.common import template_format
from heat.engine.resources.openstack.neutron import rbac_policy
from heat.tests import common
from heat.tests.openstack.neutron import inline_templates
from heat.tests import utils
@ -27,11 +26,6 @@ from heat.tests import utils
class RBACPolicyTest(common.HeatTestCase):
def test_resource_mapping(self):
mapping = rbac_policy.resource_mapping()
self.assertEqual(rbac_policy.RBACPolicy,
mapping['OS::Neutron::RBACPolicy'])
@mock.patch('heat.engine.clients.os.neutron.'
'NeutronClientPlugin.has_extension', return_value=True)
def _create_stack(self, ext_func, tmpl=inline_templates.RBAC_TEMPLATE):

@ -63,16 +63,6 @@ class NeutronSubnetPoolTest(common.HeatTestCase):
self.assertEqual((rsrc.CREATE, status), rsrc.state)
return rsrc
def test_resource_mapping(self):
self.t = template_format.parse(inline_templates.SPOOL_TEMPLATE)
self.stack = utils.parse_stack(self.t)
rsrc = self.stack['sub_pool']
mapping = subnetpool.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(subnetpool.SubnetPool,
mapping['OS::Neutron::SubnetPool'])
self.assertIsInstance(rsrc, subnetpool.SubnetPool)
def test_validate_prefixlen_min_gt_max(self):
self.t = template_format.parse(inline_templates.SPOOL_TEMPLATE)
props = self.t['resources']['sub_pool']['properties']

@ -15,7 +15,6 @@ import mock
from heat.common import template_format
from heat.engine.clients.os import neutron
from heat.engine.resources.openstack.neutron import qos
from heat.engine import rsrc_defn
from heat.engine import stack
from heat.engine import template
@ -70,11 +69,6 @@ class NeutronQoSPolicyTest(common.HeatTestCase):
self.my_qos_policy.client = mock.MagicMock(
return_value=self.neutronclient)
def test_resource_mapping(self):
mapping = qos.resource_mapping()
self.assertEqual(qos.QoSPolicy, mapping['OS::Neutron::QoSPolicy'])
self.assertIsInstance(self.my_qos_policy, qos.QoSPolicy)
def test_qos_policy_handle_create(self):
policy = {
'policy': {
@ -192,14 +186,6 @@ class NeutronQoSBandwidthLimitRuleTest(common.HeatTestCase):
self.policy_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
self.find_mock.return_value = self.policy_id
def test_resource_mapping(self):
mapping = qos.resource_mapping()
self.assertEqual(2, len(mapping))
self.assertEqual(qos.QoSBandwidthLimitRule,
mapping['OS::Neutron::QoSBandwidthLimitRule'])
self.assertIsInstance(self.bandwidth_limit_rule,
qos.QoSBandwidthLimitRule)
def test_rule_handle_create(self):
rule = {
'bandwidth_limit_rule': {

@ -14,7 +14,6 @@
import mock
from heat.engine.clients.os import nova as novac
from heat.engine.resources.openstack.nova import flavor
from heat.engine import stack
from heat.engine import template
from heat.tests import common
@ -58,12 +57,6 @@ class NovaFlavorTest(common.HeatTestCase):
nova.return_value = self.novaclient
self.flavors = self.novaclient.flavors
def test_resource_mapping(self):
mapping = flavor.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(flavor.NovaFlavor, mapping['OS::Nova::Flavor'])
self.assertIsInstance(self.my_flavor, flavor.NovaFlavor)
def test_flavor_handle_create(self):
value = mock.MagicMock()
flavor_id = '927202df-1afb-497f-8368-9c2d2f26e5db'

@ -14,7 +14,6 @@
import mock
from heat.engine.clients.os import nova
from heat.engine.resources.openstack.nova import host_aggregate
from heat.engine import stack
from heat.engine import template
from heat.tests import common
@ -57,14 +56,6 @@ class NovaHostAggregateTest(common.HeatTestCase):
nova_client.return_value = self.novaclient
self.aggregates = self.novaclient.aggregates
def test_resource_mapping(self):
mapping = host_aggregate.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(host_aggregate.HostAggregate,
mapping['OS::Nova::HostAggregate'])
self.assertIsInstance(self.my_aggregate,
host_aggregate.HostAggregate)
def test_aggregate_handle_create(self):
value = mock.MagicMock()
aggregate_id = '927202df-1afb-497f-8368-9c2d2f26e5db'

@ -158,14 +158,6 @@ class SaharaClusterTest(common.HeatTestCase):
self.assertEqual({"cluster": "info"}, cluster.FnGetAtt('show'))
self.assertEqual(3, self.cl_mgr.get.call_count)
def test_cluster_resource_mapping(self):
cluster = self._init_cluster(self.t)
mapping = sc.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(sc.SaharaCluster,
mapping['OS::Sahara::Cluster'])
self.assertIsInstance(cluster, sc.SaharaCluster)
def test_cluster_create_no_image_anywhere_fails(self):
self.t['resources']['super-cluster']['properties'].pop(
'default_image_id')

@ -72,12 +72,6 @@ class SaharaDataSourceTest(common.HeatTestCase):
expected_state = (ds.CREATE, ds.COMPLETE)
self.assertEqual(expected_state, ds.state)
def test_resource_mapping(self):
mapping = data_source.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(data_source.DataSource,
mapping['OS::Sahara::DataSource'])
def test_update(self):
ds = self._create_resource('data-source', self.rsrc_defn,
self.stack)

@ -105,9 +105,3 @@ class SaharaImageTest(common.HeatTestCase):
value.to_dict.return_value = {'img': 'info'}
self.client.images.get.return_value = value
self.assertEqual({'img': 'info'}, img.FnGetAtt('show'))
def test_resource_mapping(self):
mapping = image.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(image.SaharaImageRegistry,
mapping['OS::Sahara::ImageRegistry'])

@ -71,12 +71,6 @@ class SaharaJobBinaryTest(common.HeatTestCase):
expected_state = (jb.CREATE, jb.COMPLETE)
self.assertEqual(expected_state, jb.state)
def test_resource_mapping(self):
mapping = job_binary.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(job_binary.JobBinary,
mapping['OS::Sahara::JobBinary'])
def test_update(self):
jb = self._create_resource('job-binary', self.rsrc_defn,
self.stack)

@ -132,14 +132,6 @@ class SaharaNodeGroupTemplateTest(common.HeatTestCase):
self.stack = utils.parse_stack(template)
return self.stack['node-group']
def test_ngt_resource_mapping(self):
ngt = self._init_ngt(self.t)
mapping = st.resource_mapping()
self.assertEqual(st.SaharaNodeGroupTemplate,
mapping['OS::Sahara::NodeGroupTemplate'])
self.assertIsInstance(ngt,
st.SaharaNodeGroupTemplate)
def _create_ngt(self, template):
ngt = self._init_ngt(template)
self.ngt_mgr.create.return_value = self.fake_ngt
@ -312,14 +304,6 @@ class SaharaClusterTemplateTest(common.HeatTestCase):
self.stack = utils.parse_stack(template)
return self.stack['cluster-template']
def test_ct_resource_mapping(self):
ct = self._init_ct(self.t)
mapping = st.resource_mapping()
self.assertEqual(st.SaharaClusterTemplate,
mapping['OS::Sahara::ClusterTemplate'])
self.assertIsInstance(ct,
st.SaharaClusterTemplate)
def _create_ct(self, template):
ct = self._init_ct(template)
self.ct_mgr.create.return_value = self.fake_ct

@ -101,12 +101,6 @@ class SenlinClusterTest(common.HeatTestCase):
self.assertEqual(self.fake_cl.id, cluster.resource_id)
return cluster
def test_resource_mapping(self):
mapping = sc.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(sc.Cluster,
mapping['OS::Senlin::Cluster'])
def test_cluster_create_success(self):
self._create_cluster(self.t)
expect_kwargs = {

@ -181,9 +181,3 @@ class SenlinPolicyTest(common.HeatTestCase):
policy = self._create_policy(self.t)
self.senlin_mock.get_policy.return_value = FakePolicy()
self.assertEqual(excepted_show, policy._show_resource())
def test_resource_mapping(self):
mapping = policy.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(policy.Policy,
mapping['OS::Senlin::Policy'])

@ -113,9 +113,3 @@ class SenlinProfileTest(common.HeatTestCase):
prop_diff=prop_diff)
self.senlin_mock.update_profile.assert_called_once_with(
profile.resource_id, **prop_diff)
def test_resource_mapping(self):
mapping = sp.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(sp.Profile,
mapping['OS::Senlin::Profile'])

@ -113,12 +113,6 @@ class SenlinReceiverTest(common.HeatTestCase):
self.senlin_mock.delete_receiver.assert_called_once_with(
recv.resource_id)
def test_resource_mapping(self):
mapping = sr.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(sr.Receiver,
mapping['OS::Senlin::Receiver'])
def test_cluster_resolve_attribute(self):
excepted_show = {
'id': 'some_id',

@ -117,12 +117,6 @@ class TroveClusterTest(common.HeatTestCase):
tc.resource_id)
self.assertEqual('clusters', tc.entity)
def test_resource_mapping(self):
mapping = cluster.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(cluster.TroveCluster,
mapping['OS::Trove::Cluster'])
def test_attributes(self):
tc = self._create_resource('cluster', self.rsrc_defn, self.stack)
self.assertEqual(['10.0.0.1'], tc.FnGetAtt('ip'))

@ -33,6 +33,7 @@ from heat.engine import clients
from heat.engine import constraints
from heat.engine import dependencies
from heat.engine import environment
from heat.engine import plugin_manager
from heat.engine import properties
from heat.engine import resource
from heat.engine import resources
@ -3747,3 +3748,45 @@ class ResourceUpdateRestrictionTest(common.HeatTestCase):
self.new_stack))
self.assertIn('requires replacement', six.text_type(error))
ev.assert_not_called()
class TestResourceMapping(common.HeatTestCase):
def _check_mapping_func(self, func, module):
self.assertTrue(callable(func))
res = func()
self.assertIsInstance(res, collections.Mapping)
for r_type, r_class in six.iteritems(res):
self.assertIsInstance(r_type, six.string_types)
type_elements = r_type.split('::')
# type has fixed format
# Platform type::Service/Type::Optional Sub-sections::Name
self.assertTrue(len(type_elements) >= 3)
# type should be OS or AWS
self.assertIn(type_elements[0], ('AWS', 'OS'))
# check that value is a class object
self.assertIsInstance(r_class, six.class_types)
# check that class is subclass of Resource base class
self.assertTrue(issubclass(r_class, resource.Resource))
# check that mentioned class is presented in the same module
self.assertTrue(hasattr(module, six.text_type(r_class.__name__)))
return len(res)
def test_resource_mappings(self):
# use plugin manager for loading all resources
# use the same approach like and in heat.engine.resources.__init__
manager = plugin_manager.PluginManager('heat.engine.resources')
num_of_types = 0
for module in manager.modules:
# check for both potential mappings
for name in ('resource_mapping', 'available_resource_mapping'):
mapping_func = getattr(module, name, None)
if mapping_func:
num_of_types += self._check_mapping_func(
mapping_func, module)
# check number of registred resource types to make sure,
# that there is no regressions
# It's soft check and should not be a cause of the merge conflict
# Feel free to update it in some separate patch
self.assertTrue(num_of_types >= 137)

Loading…
Cancel
Save