From 835fefef77e88e8e22ac0cd7e3e84daafa229e87 Mon Sep 17 00:00:00 2001 From: Sergey Kraynev Date: Wed, 24 Jun 2015 09:10:28 -0400 Subject: [PATCH] Add base_attribute schema for all resources - base_attributes_schema was added for base resource class. - 'show' attribute was added to base_attributes_schema. - fixed corresponding unittests - definition of 'show' attribute was deleted from some resources, because now it's presented in base resource class. - Also was added temporary hook for stack_resource class to stop resolving 'show' attribute. Change-Id: Ie07fdc28a98be72064692ebffaf6d0c3eb128887 --- heat/engine/resource.py | 12 ++++++++++++ .../engine/resources/openstack/neutron/firewall.py | 8 ++------ .../resources/openstack/neutron/floatingip.py | 8 ++------ .../resources/openstack/neutron/loadbalancer.py | 14 ++------------ heat/engine/resources/openstack/neutron/net.py | 8 ++------ .../resources/openstack/neutron/network_gateway.py | 8 ++------ heat/engine/resources/openstack/neutron/port.py | 8 ++------ .../resources/openstack/neutron/provider_net.py | 8 ++------ heat/engine/resources/openstack/neutron/router.py | 8 ++------ heat/engine/resources/openstack/neutron/subnet.py | 8 ++------ .../resources/openstack/neutron/vpnservice.py | 8 ++------ heat/engine/resources/openstack/nova/server.py | 8 ++------ heat/engine/resources/stack_resource.py | 5 ++++- heat/engine/resources/template_resource.py | 1 + heat/tests/test_engine_api_utils.py | 6 ++++-- heat/tests/test_engine_service.py | 3 +++ heat/tests/test_stack_resource.py | 4 ++-- 17 files changed, 48 insertions(+), 77 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 2491e62906..5b26ab6310 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -106,6 +106,8 @@ class Resource(object): STATUSES = (IN_PROGRESS, FAILED, COMPLETE ) = ('IN_PROGRESS', 'FAILED', 'COMPLETE') + BASE_ATTRIBUTES = (SHOW, ) = ('show', ) + # If True, this resource must be created before it can be referenced. strict_dependency = True @@ -120,6 +122,15 @@ class Resource(object): # Resource implementations set this to update policies update_policy_schema = {} + # Description dictionary, that describes the common attributes for all + # resources + base_attributes_schema = { + SHOW: attributes.Schema( + _("Dictionary with resource attributes."), + type=attributes.Schema.MAP + ) + } + # If True, this resource may perform authenticated API requests # throughout its lifecycle requires_deferred_auth = False @@ -180,6 +191,7 @@ class Resource(object): self.name = name self.t = definition self.reparse() + self.attributes_schema.update(self.base_attributes_schema) self.attributes = attributes.Attributes(self.name, self.attributes_schema, self._resolve_attribute) diff --git a/heat/engine/resources/openstack/neutron/firewall.py b/heat/engine/resources/openstack/neutron/firewall.py index 6bdd94945d..e26f2f3860 100644 --- a/heat/engine/resources/openstack/neutron/firewall.py +++ b/heat/engine/resources/openstack/neutron/firewall.py @@ -34,10 +34,10 @@ class Firewall(neutron.NeutronResource): ATTRIBUTES = ( NAME_ATTR, DESCRIPTION_ATTR, ADMIN_STATE_UP_ATTR, - FIREWALL_POLICY_ID_ATTR, SHARED_ATTR, STATUS, TENANT_ID, SHOW, + FIREWALL_POLICY_ID_ATTR, SHARED_ATTR, STATUS, TENANT_ID, ) = ( 'name', 'description', 'admin_state_up', - 'firewall_policy_id', 'shared', 'status', 'tenant_id', 'show', + 'firewall_policy_id', 'shared', 'status', 'tenant_id', ) properties_schema = { @@ -107,10 +107,6 @@ class Firewall(neutron.NeutronResource): _('Id of the tenant owning the firewall.'), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _('All attributes.'), - type=attributes.Schema.MAP - ), } def _show_resource(self): diff --git a/heat/engine/resources/openstack/neutron/floatingip.py b/heat/engine/resources/openstack/neutron/floatingip.py index 28e36b1b8d..fdcc8bd89d 100644 --- a/heat/engine/resources/openstack/neutron/floatingip.py +++ b/heat/engine/resources/openstack/neutron/floatingip.py @@ -34,10 +34,10 @@ class FloatingIP(neutron.NeutronResource): ATTRIBUTES = ( ROUTER_ID, TENANT_ID, FLOATING_NETWORK_ID_ATTR, FIXED_IP_ADDRESS_ATTR, - FLOATING_IP_ADDRESS_ATTR, PORT_ID_ATTR, SHOW, + FLOATING_IP_ADDRESS_ATTR, PORT_ID_ATTR, ) = ( 'router_id', 'tenant_id', 'floating_network_id', 'fixed_ip_address', - 'floating_ip_address', 'port_id', 'show', + 'floating_ip_address', 'port_id', ) properties_schema = { @@ -121,10 +121,6 @@ class FloatingIP(neutron.NeutronResource): _('ID of the port associated with this IP.'), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _('All attributes.'), - type=attributes.Schema.MAP - ), } def add_dependencies(self, deps): diff --git a/heat/engine/resources/openstack/neutron/loadbalancer.py b/heat/engine/resources/openstack/neutron/loadbalancer.py index 4edd34618e..cd870eeb60 100644 --- a/heat/engine/resources/openstack/neutron/loadbalancer.py +++ b/heat/engine/resources/openstack/neutron/loadbalancer.py @@ -39,11 +39,9 @@ class HealthMonitor(neutron.NeutronResource): ATTRIBUTES = ( ADMIN_STATE_UP_ATTR, DELAY_ATTR, EXPECTED_CODES_ATTR, HTTP_METHOD_ATTR, MAX_RETRIES_ATTR, TIMEOUT_ATTR, TYPE_ATTR, URL_PATH_ATTR, TENANT_ID, - SHOW, ) = ( 'admin_state_up', 'delay', 'expected_codes', 'http_method', 'max_retries', 'timeout', 'type', 'url_path', 'tenant_id', - 'show', ) properties_schema = { @@ -145,10 +143,6 @@ class HealthMonitor(neutron.NeutronResource): _('Tenant owning the health monitor.'), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _('All attributes.'), - type=attributes.Schema.MAP - ), } def handle_create(self): @@ -563,10 +557,10 @@ class PoolMember(neutron.NeutronResource): ATTRIBUTES = ( ADMIN_STATE_UP_ATTR, TENANT_ID, WEIGHT_ATTR, ADDRESS_ATTR, - POOL_ID_ATTR, PROTOCOL_PORT_ATTR, SHOW, + POOL_ID_ATTR, PROTOCOL_PORT_ATTR, ) = ( 'admin_state_up', 'tenant_id', 'weight', 'address', - 'pool_id', 'protocol_port', 'show', + 'pool_id', 'protocol_port', ) properties_schema = { @@ -634,10 +628,6 @@ class PoolMember(neutron.NeutronResource): 'connections.'), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _('All attributes.'), - type=attributes.Schema.MAP - ), } def handle_create(self): diff --git a/heat/engine/resources/openstack/neutron/net.py b/heat/engine/resources/openstack/neutron/net.py index 18e4190cd4..5d1e8fcb5f 100644 --- a/heat/engine/resources/openstack/neutron/net.py +++ b/heat/engine/resources/openstack/neutron/net.py @@ -28,10 +28,10 @@ class Net(neutron.NeutronResource): ) ATTRIBUTES = ( - STATUS, NAME_ATTR, SUBNETS, ADMIN_STATE_UP_ATTR, TENANT_ID_ATTR, SHOW, + STATUS, NAME_ATTR, SUBNETS, ADMIN_STATE_UP_ATTR, TENANT_ID_ATTR, PORT_SECURITY_ENABLED_ATTR, MTU_ATTR, ) = ( - "status", "name", "subnets", "admin_state_up", "tenant_id", "show", + "status", "name", "subnets", "admin_state_up", "tenant_id", "port_security_enabled", "mtu", ) @@ -109,10 +109,6 @@ class Net(neutron.NeutronResource): _("The tenant owning this network."), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _("All attributes."), - type=attributes.Schema.MAP - ), PORT_SECURITY_ENABLED_ATTR: attributes.Schema( _("Port security enabled of the network."), support_status=support.SupportStatus(version='5.0.0'), diff --git a/heat/engine/resources/openstack/neutron/network_gateway.py b/heat/engine/resources/openstack/neutron/network_gateway.py index 501e0d16e4..87cd226ec6 100644 --- a/heat/engine/resources/openstack/neutron/network_gateway.py +++ b/heat/engine/resources/openstack/neutron/network_gateway.py @@ -39,9 +39,9 @@ class NetworkGateway(neutron.NeutronResource): ) ATTRIBUTES = ( - DEFAULT, SHOW, + DEFAULT, ) = ( - 'default', 'show', + 'default', ) _DEVICES_KEYS = ( @@ -141,10 +141,6 @@ class NetworkGateway(neutron.NeutronResource): _("A boolean value of default flag."), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _("All attributes."), - type=attributes.Schema.MAP - ), } def _show_resource(self): diff --git a/heat/engine/resources/openstack/neutron/port.py b/heat/engine/resources/openstack/neutron/port.py index 760e9d0b07..191ac8bc11 100644 --- a/heat/engine/resources/openstack/neutron/port.py +++ b/heat/engine/resources/openstack/neutron/port.py @@ -58,12 +58,12 @@ class Port(neutron.NeutronResource): ATTRIBUTES = ( ADMIN_STATE_UP_ATTR, DEVICE_ID_ATTR, DEVICE_OWNER_ATTR, FIXED_IPS_ATTR, MAC_ADDRESS_ATTR, NAME_ATTR, NETWORK_ID_ATTR, SECURITY_GROUPS_ATTR, - STATUS, TENANT_ID, ALLOWED_ADDRESS_PAIRS_ATTR, SHOW, SUBNETS_ATTR, + STATUS, TENANT_ID, ALLOWED_ADDRESS_PAIRS_ATTR, SUBNETS_ATTR, PORT_SECURITY_ENABLED_ATTR, ) = ( 'admin_state_up', 'device_id', 'device_owner', 'fixed_ips', 'mac_address', 'name', 'network_id', 'security_groups', - 'status', 'tenant_id', 'allowed_address_pairs', 'show', 'subnets', + 'status', 'tenant_id', 'allowed_address_pairs', 'subnets', 'port_security_enabled', ) @@ -277,10 +277,6 @@ class Port(neutron.NeutronResource): "a port."), type=attributes.Schema.LIST ), - SHOW: attributes.Schema( - _("All attributes."), - type=attributes.Schema.MAP - ), SUBNETS_ATTR: attributes.Schema( _("A list of all subnet attributes for the port."), type=attributes.Schema.LIST diff --git a/heat/engine/resources/openstack/neutron/provider_net.py b/heat/engine/resources/openstack/neutron/provider_net.py index de4aaed09c..b423e00f72 100644 --- a/heat/engine/resources/openstack/neutron/provider_net.py +++ b/heat/engine/resources/openstack/neutron/provider_net.py @@ -35,9 +35,9 @@ class ProviderNet(net.Net): ) ATTRIBUTES = ( - STATUS, SUBNETS, SHOW, + STATUS, SUBNETS, ) = ( - 'status', 'subnets', 'show', + 'status', 'subnets', ) properties_schema = { @@ -83,10 +83,6 @@ class ProviderNet(net.Net): _("Subnets of this network."), type=attributes.Schema.LIST ), - SHOW: attributes.Schema( - _("All attributes."), - type=attributes.Schema.MAP - ), } def validate(self): diff --git a/heat/engine/resources/openstack/neutron/router.py b/heat/engine/resources/openstack/neutron/router.py index fc56af57d4..dc3aa4eecc 100644 --- a/heat/engine/resources/openstack/neutron/router.py +++ b/heat/engine/resources/openstack/neutron/router.py @@ -41,10 +41,10 @@ class Router(neutron.NeutronResource): ATTRIBUTES = ( STATUS, EXTERNAL_GATEWAY_INFO_ATTR, NAME_ATTR, ADMIN_STATE_UP_ATTR, - TENANT_ID, SHOW, + TENANT_ID, ) = ( 'status', 'external_gateway_info', 'name', 'admin_state_up', - 'tenant_id', 'show', + 'tenant_id', ) properties_schema = { @@ -148,10 +148,6 @@ class Router(neutron.NeutronResource): _("Tenant owning the router."), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _("All attributes."), - type=attributes.Schema.MAP - ), } def validate(self): diff --git a/heat/engine/resources/openstack/neutron/subnet.py b/heat/engine/resources/openstack/neutron/subnet.py index 8d6bc9df16..4738a3f174 100644 --- a/heat/engine/resources/openstack/neutron/subnet.py +++ b/heat/engine/resources/openstack/neutron/subnet.py @@ -55,11 +55,11 @@ class Subnet(neutron.NeutronResource): ATTRIBUTES = ( NAME_ATTR, NETWORK_ID_ATTR, TENANT_ID_ATTR, ALLOCATION_POOLS_ATTR, GATEWAY_IP_ATTR, HOST_ROUTES_ATTR, IP_VERSION_ATTR, CIDR_ATTR, - DNS_NAMESERVERS_ATTR, ENABLE_DHCP_ATTR, SHOW, + DNS_NAMESERVERS_ATTR, ENABLE_DHCP_ATTR, ) = ( 'name', 'network_id', 'tenant_id', 'allocation_pools', 'gateway_ip', 'host_routes', 'ip_version', 'cidr', - 'dns_nameservers', 'enable_dhcp', 'show', + 'dns_nameservers', 'enable_dhcp', ) properties_schema = { @@ -238,10 +238,6 @@ class Subnet(neutron.NeutronResource): _("'true' if DHCP is enabled for this subnet; 'false' otherwise."), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _("All attributes."), - type=attributes.Schema.MAP - ), } @classmethod diff --git a/heat/engine/resources/openstack/neutron/vpnservice.py b/heat/engine/resources/openstack/neutron/vpnservice.py index 3f67d81301..6692da29fb 100644 --- a/heat/engine/resources/openstack/neutron/vpnservice.py +++ b/heat/engine/resources/openstack/neutron/vpnservice.py @@ -34,10 +34,10 @@ class VPNService(neutron.NeutronResource): ATTRIBUTES = ( ADMIN_STATE_UP_ATTR, DESCRIPTION_ATTR, NAME_ATTR, ROUTER_ID_ATTR, - STATUS, SUBNET_ID_ATTR, TENANT_ID, SHOW, + STATUS, SUBNET_ID_ATTR, TENANT_ID, ) = ( 'admin_state_up', 'description', 'name', 'router_id', - 'status', 'subnet_id', 'tenant_id', 'show', + 'status', 'subnet_id', 'tenant_id', ) properties_schema = { @@ -129,10 +129,6 @@ class VPNService(neutron.NeutronResource): _('The unique identifier of the tenant owning the vpn service.'), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _('All attributes.'), - type=attributes.Schema.MAP - ), } def _show_resource(self): diff --git a/heat/engine/resources/openstack/nova/server.py b/heat/engine/resources/openstack/nova/server.py index d2b884791a..fa5e94851f 100644 --- a/heat/engine/resources/openstack/nova/server.py +++ b/heat/engine/resources/openstack/nova/server.py @@ -115,10 +115,10 @@ class Server(stack_user.StackUser): ) ATTRIBUTES = ( - NAME_ATTR, SHOW, ADDRESSES, NETWORKS_ATTR, FIRST_ADDRESS, + NAME_ATTR, ADDRESSES, NETWORKS_ATTR, FIRST_ADDRESS, INSTANCE_NAME, ACCESSIPV4, ACCESSIPV6, CONSOLE_URLS, ) = ( - 'name', 'show', 'addresses', 'networks', 'first_address', + 'name', 'addresses', 'networks', 'first_address', 'instance_name', 'accessIPv4', 'accessIPv6', 'console_urls', ) properties_schema = { @@ -443,10 +443,6 @@ class Server(stack_user.StackUser): _('Name of the server.'), type=attributes.Schema.STRING ), - SHOW: attributes.Schema( - _('A dict of all server details as returned by the API.'), - type=attributes.Schema.MAP - ), ADDRESSES: attributes.Schema( _('A dict of all network addresses with corresponding port_id. ' 'Each network will have two keys in dict, they are network ' diff --git a/heat/engine/resources/stack_resource.py b/heat/engine/resources/stack_resource.py index 91b4372fab..74bf09d9da 100644 --- a/heat/engine/resources/stack_resource.py +++ b/heat/engine/resources/stack_resource.py @@ -516,7 +516,10 @@ class StackResource(resource.Resource): return stack.output(op) def _resolve_attribute(self, name): - return self.get_output(name) + # NOTE(skraynev): should be removed in patch with methods, + # which resolve base attributes + if name != 'show': + return self.get_output(name) def implementation_signature(self): schema_names = ([prop for prop in self.properties_schema] + diff --git a/heat/engine/resources/template_resource.py b/heat/engine/resources/template_resource.py index e2c721e1ac..1df48d7a42 100644 --- a/heat/engine/resources/template_resource.py +++ b/heat/engine/resources/template_resource.py @@ -113,6 +113,7 @@ class TemplateResource(stack_resource.StackResource): self.properties = definition.properties(self.properties_schema, self.context) + self.attributes_schema.update(self.base_attributes_schema) self.attributes = attributes.Attributes(self.name, self.attributes_schema, self._resolve_attribute) diff --git a/heat/tests/test_engine_api_utils.py b/heat/tests/test_engine_api_utils.py index 39e51c010b..835062a35a 100644 --- a/heat/tests/test_engine_api_utils.py +++ b/heat/tests/test_engine_api_utils.py @@ -109,9 +109,10 @@ class FormatTest(common.HeatTestCase): def test_format_resource_attributes(self): res = self.stack['generic1'] formatted_attributes = api.format_resource_attributes(res) - self.assertEqual(2, len(formatted_attributes)) + self.assertEqual(3, len(formatted_attributes)) self.assertIn('foo', formatted_attributes) self.assertIn('Foo', formatted_attributes) + self.assertIn('show', formatted_attributes) def test_format_resource_attributes_show_attribute(self): res = mock.Mock() @@ -134,9 +135,10 @@ class FormatTest(common.HeatTestCase): force_attrs = ['a1', 'a2'] formatted_attributes = api.format_resource_attributes(res, force_attrs) - self.assertEqual(4, len(formatted_attributes)) + self.assertEqual(5, len(formatted_attributes)) self.assertIn('foo', formatted_attributes) self.assertIn('Foo', formatted_attributes) + self.assertIn('show', formatted_attributes) self.assertIn('a1', formatted_attributes) self.assertIn('a2', formatted_attributes) diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 5f6bb05ddb..7b947013c3 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -2093,6 +2093,9 @@ class StackServiceTest(common.HeatTestCase): 'attributes': { 'foo': {'description': 'A generic attribute'}, 'Foo': {'description': 'Another generic attribute'}, + 'show': { + 'description': 'Dictionary with resource attributes.', + 'type': 'map'}, }, 'support_status': { 'status': 'SUPPORTED', diff --git a/heat/tests/test_stack_resource.py b/heat/tests/test_stack_resource.py index 5a31aed001..0a8d8827e4 100644 --- a/heat/tests/test_stack_resource.py +++ b/heat/tests/test_stack_resource.py @@ -209,8 +209,8 @@ class StackResourceTest(StackResourceBaseTest): self.parent_resource.child_template = mock.Mock( return_value=self.simple_template) sig1, sig2 = self.parent_resource.implementation_signature() - self.assertEqual('3ce48c5d860e8e76087897376bc686d23591d4a00' - 'e8df8ec25e84e6bd83e70a6', sig1) + self.assertEqual('7b0eaabb5b82b9e90804d42e0bb739035588cb797' + '82427770646686ca2235028', sig1) self.assertEqual('5a58b34cc3dd7f4e11fa35b63daad7b6b3aaa1744' '19eb1c42b75d102bdda5fc9', sig2) self.parent_stack.t.files["foo"] = "bar"