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
This commit is contained in:
Sergey Kraynev 2015-06-24 09:10:28 -04:00
parent c0558e69bd
commit 835fefef77
17 changed files with 48 additions and 77 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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'),

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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 '

View File

@ -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] +

View File

@ -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)

View File

@ -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)

View File

@ -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',

View File

@ -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"