Update code base to be hacking compatible
Lots of minor changes to make the latest version of hacking happy. Change-Id: Ide0cfaa64f33f4e3157f5aaafdbd6de94a13b127
This commit is contained in:
parent
88ce5ec962
commit
c52d403e7b
@ -2,3 +2,4 @@ pbr>=0.6,!=0.7,<1.0
|
||||
Babel>=1.3
|
||||
PyYAML>=3.1.0
|
||||
python_dateutil>=2.4.0
|
||||
six>=1.9.0
|
||||
|
@ -1,4 +1,4 @@
|
||||
hacking>=0.5.6,<0.8
|
||||
hacking>=0.10.0,<0.11
|
||||
coverage>=3.6
|
||||
discover
|
||||
fixtures>=0.3.14
|
||||
|
@ -33,8 +33,8 @@ class MemoryUnit(object):
|
||||
@staticmethod
|
||||
def convert_unit_size_to_num(size, unit=None):
|
||||
"""Convert given size to a number representing given unit.
|
||||
If unit is None, convert to a number representing UNIT_SIZE_DEFAULT
|
||||
|
||||
If unit is None, convert to a number representing UNIT_SIZE_DEFAULT
|
||||
:param size: unit size e.g. 1 TB
|
||||
:param unit: unit to be converted to e.g GB
|
||||
:return: converted number e.g. 1000 for 1 TB size and unit GB
|
||||
@ -69,12 +69,12 @@ class CompareUtils(object):
|
||||
|
||||
@staticmethod
|
||||
def compare_dicts(dict1, dict2):
|
||||
'''Returns False if not equal or any input parameter is empty.
|
||||
Returns True if both are equal.
|
||||
'''
|
||||
"""Return False if not equal, True if both are equal."""
|
||||
|
||||
if not dict1 or not dict2:
|
||||
return False
|
||||
#compare generated and expected hot templates
|
||||
|
||||
# compare generated and expected hot templates
|
||||
both_equal = True
|
||||
for generated_item, expected_item in zip(dict1.items(), dict2.items()):
|
||||
if generated_item != expected_item:
|
||||
@ -94,7 +94,7 @@ class CompareUtils(object):
|
||||
|
||||
|
||||
def str_to_num(value):
|
||||
'''Convert a string representation of a number into a numeric type.'''
|
||||
"""Convert a string representation of a number into a numeric type."""
|
||||
if isinstance(value, numbers.Number):
|
||||
return value
|
||||
try:
|
||||
|
@ -33,7 +33,7 @@ class ToscaBlockStorageAttachment(HotResource):
|
||||
else:
|
||||
tosca_props[prop.name] = prop.value
|
||||
self.properties = tosca_props
|
||||
#instance_uuid and volume_id for Cinder volume attachment
|
||||
# instance_uuid and volume_id for Cinder volume attachment
|
||||
self.properties['instance_uuid'] = self.instace_uuid
|
||||
self.properties['volume_id'] = self.volume_id
|
||||
|
||||
|
@ -58,7 +58,7 @@ class ToscaNetworkPort(HotResource):
|
||||
port_props['fixed_ips'] = [fixed_ip]
|
||||
elif key == 'order':
|
||||
self.order = value
|
||||
#TODO(sdmonov). Need to implement the properties below
|
||||
# TODO(sdmonov): Need to implement the properties below
|
||||
elif key == 'is_default':
|
||||
pass
|
||||
elif key == 'ip_range_start':
|
||||
@ -105,7 +105,7 @@ class ToscaNetworkPort(HotResource):
|
||||
if compute_resource:
|
||||
port_resources = compute_resource.assoc_port_resources
|
||||
self._insert_sorted_resource(port_resources, self)
|
||||
#TODO(sdmonov). Using generate networks every time we add a
|
||||
# TODO(sdmonov): Using generate networks every time we add a
|
||||
# network is not the fastest way to do the things. We should
|
||||
# do this only once at the end.
|
||||
networks = self._generate_networks_for_compute(port_resources)
|
||||
|
@ -34,9 +34,9 @@ class ToscaObjectStorage(HotResource):
|
||||
if key == "store_name":
|
||||
objectstore_props["name"] = value
|
||||
elif key == "store_size" or key == "store_maxsize":
|
||||
#currently heat is not supporting dynamically increase
|
||||
#the container quota-size.
|
||||
#if both defined in tosca template, consider store_maxsize.
|
||||
# currently heat is not supporting dynamically increase
|
||||
# the container quota-size.
|
||||
# if both defined in tosca template, consider store_maxsize.
|
||||
if skip_check:
|
||||
continue
|
||||
quota_size = None
|
||||
|
@ -49,7 +49,7 @@ TOSCA_TO_HOT_INPUT_TYPES = {'string': 'string',
|
||||
'null': 'string'}
|
||||
|
||||
|
||||
class TranslateInputs():
|
||||
class TranslateInputs(object):
|
||||
'''Translate TOSCA Inputs to Heat Parameters.'''
|
||||
|
||||
def __init__(self, inputs, parsed_params):
|
||||
|
@ -67,7 +67,7 @@ TOSCA_TO_HOT_REQUIRES = {'container': 'server', 'host': 'server',
|
||||
TOSCA_TO_HOT_PROPERTIES = {'properties': 'input'}
|
||||
|
||||
|
||||
class TranslateNodeTemplates():
|
||||
class TranslateNodeTemplates(object):
|
||||
'''Translate TOSCA NodeTemplates to Heat Resources.'''
|
||||
|
||||
def __init__(self, tosca, hot_template):
|
||||
|
@ -14,7 +14,7 @@
|
||||
from translator.hot.syntax.hot_output import HotOutput
|
||||
|
||||
|
||||
class TranslateOutputs():
|
||||
class TranslateOutputs(object):
|
||||
'''Translate TOSCA Outputs to Heat Outputs.'''
|
||||
|
||||
def __init__(self, outputs, node_translator):
|
||||
|
@ -95,12 +95,15 @@ class ToscaNetworkTest(TestCase):
|
||||
'properties':
|
||||
{'cidr': {'get_param': 'network_cidr'},
|
||||
'ip_version': 4,
|
||||
'allocation_pools': [{'start': {'get_param':
|
||||
'network_start_ip'},
|
||||
'end': {'get_param':
|
||||
'network_end_ip'
|
||||
}}],
|
||||
'network': {'get_resource': 'my_network'}
|
||||
'network': {'get_resource': 'my_network'},
|
||||
'allocation_pools': [{'start':
|
||||
{'get_param':
|
||||
'network_start_ip'},
|
||||
'end':
|
||||
{'get_param':
|
||||
'network_end_ip'
|
||||
}}
|
||||
]
|
||||
}}
|
||||
|
||||
expected_resource_3 = {'type': 'OS::Neutron::Port',
|
||||
@ -197,21 +200,20 @@ class ToscaNetworkTest(TestCase):
|
||||
|
||||
expected_resource_net = {'type': 'OS::Neutron::Net',
|
||||
'properties':
|
||||
{'name': 'net%d' % (net_num)
|
||||
}}
|
||||
{'name': 'net%d' % (net_num)}}
|
||||
|
||||
expected_resource_subnet = {'type': 'OS::Neutron::Subnet',
|
||||
'properties':
|
||||
{'cidr': '192.168.%d.0/24' % (net_num),
|
||||
'ip_version': 4,
|
||||
'network': {'get_resource': net_name}
|
||||
}}
|
||||
{'cidr': '192.168.%d.0/24' % (net_num),
|
||||
'ip_version': 4,
|
||||
'network': {'get_resource': net_name}}
|
||||
}
|
||||
|
||||
expected_resource_port = {'type': 'OS::Neutron::Port',
|
||||
'depends_on': [net_name],
|
||||
'properties':
|
||||
{'network': {'get_resource': net_name}
|
||||
}}
|
||||
{'network': {'get_resource': net_name}}}
|
||||
|
||||
self.assertIn(net_name, resources.keys())
|
||||
self.assertIn(subnet_name, resources.keys())
|
||||
self.assertIn(port_name, resources.keys())
|
||||
|
@ -31,7 +31,7 @@ class ToscaObjectStoreTemplateTest(TestCase):
|
||||
translate = TOSCATranslator(tosca, parsed_params)
|
||||
hot_translated_output = translate.translate()
|
||||
|
||||
#load expected hot yaml file
|
||||
# load expected hot yaml file
|
||||
hot_yaml_file = "../toscalib/tests/data/hot_output/" + \
|
||||
"hot_single_object_store.yaml"
|
||||
hot_tpl = os.path.join(
|
||||
@ -40,7 +40,7 @@ class ToscaObjectStoreTemplateTest(TestCase):
|
||||
with open(hot_tpl) as f:
|
||||
hot_expected_output = f.read()
|
||||
|
||||
#compare generated and expected hot templates
|
||||
# compare generated and expected hot templates
|
||||
status = CompareUtils.compare_hot_yamls(hot_translated_output,
|
||||
hot_expected_output)
|
||||
self.assertEqual(status, True)
|
||||
|
@ -30,7 +30,7 @@ class ToscaTemplateOutputOrderTest(TestCase):
|
||||
translate = TOSCATranslator(tosca, parsed_params)
|
||||
hot_translated_output = translate.translate()
|
||||
|
||||
#load expected hot yaml file
|
||||
# load expected hot yaml file
|
||||
hot_yaml_file = "data/hot_output/hot_single_server.yaml"
|
||||
hot_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
@ -38,7 +38,7 @@ class ToscaTemplateOutputOrderTest(TestCase):
|
||||
with open(hot_tpl) as f:
|
||||
hot_expected_output = f.read()
|
||||
|
||||
#compare generated and expected hot templates
|
||||
# compare generated and expected hot templates
|
||||
status = CompareUtils.compare_hot_yamls(hot_translated_output,
|
||||
hot_expected_output)
|
||||
self.assertEqual(status, True)
|
||||
|
@ -53,7 +53,7 @@ class CommonUtilsTest(TestCase):
|
||||
str_to_convert = '55063.000000'
|
||||
expected_output = 55063.0
|
||||
output = translator.common.utils.str_to_num(str_to_convert)
|
||||
self.assertEquals(output, expected_output)
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
def test_compare_dicts_unequal(self):
|
||||
dict1 = {'allowed_values': [1, 2, 4, 8],
|
||||
|
@ -13,8 +13,9 @@
|
||||
from translator.toscalib.common.exception import MissingRequiredFieldError
|
||||
from translator.toscalib.common.exception import TypeMismatchError
|
||||
from translator.toscalib.common.exception import UnknownFieldError
|
||||
from translator.toscalib.elements.constraints import Constraint
|
||||
from translator.toscalib.elements.constraints import Schema
|
||||
from translator.toscalib.elements.datatype import DataType
|
||||
from translator.toscalib.elements.constraints import Constraint, Schema
|
||||
|
||||
|
||||
class DataEntity(object):
|
||||
@ -29,8 +30,8 @@ class DataEntity(object):
|
||||
def validate(self):
|
||||
'''Validate the value by the definition of the datatype.'''
|
||||
|
||||
#A datatype can not have both 'type' and 'properties' definitions.
|
||||
#If the datatype has 'type' definition
|
||||
# A datatype can not have both 'type' and 'properties' definitions.
|
||||
# If the datatype has 'type' definition
|
||||
if self.datatype.value_type:
|
||||
DataEntity.validate_datatype(self.datatype.value_type, self.value,
|
||||
None, self.custom_def)
|
||||
|
@ -36,9 +36,7 @@ class DataType(StatefulEntityType):
|
||||
return self.entity_value(self.defs, 'type')
|
||||
|
||||
def get_all_properties_objects(self):
|
||||
'''Return all properties objects defined in this type
|
||||
and its parent type.
|
||||
'''
|
||||
'''Return all properties objects defined in type and parent type.'''
|
||||
props_def = self.get_properties_def_objects()
|
||||
ptype = self.parent_type
|
||||
while ptype:
|
||||
@ -47,9 +45,7 @@ class DataType(StatefulEntityType):
|
||||
return props_def
|
||||
|
||||
def get_all_properties(self):
|
||||
'''Return a dictionary of all property definition
|
||||
name-object pairs.
|
||||
'''
|
||||
'''Return a dictionary of all property definition name-object pairs.'''
|
||||
return {prop.name: prop
|
||||
for prop in self.get_all_properties_objects()}
|
||||
|
||||
|
@ -48,8 +48,8 @@ class EntityType(object):
|
||||
RELATIONSHIP_PREFIX = 'tosca.relationships.'
|
||||
CAPABILITY_PREFIX = 'tosca.capabilities.'
|
||||
INTERFACE_PREFIX = 'tosca.interfaces.'
|
||||
#currently the data types are defined only for network
|
||||
#but may have changes in the future.
|
||||
# currently the data types are defined only for network
|
||||
# but may have changes in the future.
|
||||
DATATYPE_PREFIX = 'tosca.datatypes.network.'
|
||||
TOSCA = 'tosca'
|
||||
|
||||
@ -70,7 +70,7 @@ class EntityType(object):
|
||||
if parent and not value:
|
||||
p = self.parent_type
|
||||
while value is None:
|
||||
#check parent node
|
||||
# check parent node
|
||||
if not p:
|
||||
break
|
||||
if p and p.type == 'tosca.nodes.Root':
|
||||
|
@ -55,7 +55,7 @@ class NodeType(StatefulEntityType):
|
||||
keyword = None
|
||||
node_type = None
|
||||
for req in requires:
|
||||
#get all keys in requirement
|
||||
# get all keys in requirement
|
||||
if 'relationship' in req:
|
||||
keys = req.keys()
|
||||
for k in keys:
|
||||
|
@ -124,11 +124,11 @@ class EntityTemplate(object):
|
||||
self._common_validate_properties(capabilitydef,
|
||||
props[self.PROPERTIES])
|
||||
|
||||
#validating capability properties values
|
||||
# validating capability properties values
|
||||
for prop in self.get_capability(cap).get_properties_objects():
|
||||
prop.validate()
|
||||
|
||||
#TODO(srinivas_tadepalli): temporary work around to validate
|
||||
# TODO(srinivas_tadepalli): temporary work around to validate
|
||||
# default_instances until standardized in specification
|
||||
if cap == "scalable" and prop.name == "default_instances":
|
||||
prop_dict = props[self.PROPERTIES]
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
|
||||
import abc
|
||||
import six
|
||||
|
||||
from translator.toscalib.common.exception import UnknownInputError
|
||||
from translator.toscalib.utils.gettextutils import _
|
||||
@ -28,11 +29,10 @@ HOST = 'HOST'
|
||||
HOSTED_ON = 'tosca.relationships.HostedOn'
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Function(object):
|
||||
"""An abstract type for representing a Tosca template function."""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
def __init__(self, tosca_tpl, context, name, args):
|
||||
self.tosca_tpl = tosca_tpl
|
||||
self.context = context
|
||||
@ -59,8 +59,7 @@ class Function(object):
|
||||
|
||||
|
||||
class GetInput(Function):
|
||||
"""Get a property value declared within the inputs section of the service
|
||||
template.
|
||||
"""Get a property value declared within the input of the service template.
|
||||
|
||||
Arguments:
|
||||
|
||||
|
@ -15,8 +15,9 @@ import logging
|
||||
|
||||
from translator.toscalib.common.exception import TypeMismatchError
|
||||
from translator.toscalib.common.exception import UnknownFieldError
|
||||
from translator.toscalib.elements.interfaces import CONFIGURE
|
||||
from translator.toscalib.elements.interfaces import InterfacesDef
|
||||
from translator.toscalib.elements.interfaces import LIFECYCLE, CONFIGURE
|
||||
from translator.toscalib.elements.interfaces import LIFECYCLE
|
||||
from translator.toscalib.elements.relationshiptype import RelationshipType
|
||||
from translator.toscalib.entity_template import EntityTemplate
|
||||
from translator.toscalib.relationship_template import RelationshipTemplate
|
||||
@ -75,8 +76,8 @@ class NodeTemplate(EntityTemplate):
|
||||
explicit_relation = {}
|
||||
node = value.get('node')
|
||||
if node:
|
||||
#TODO(spzala) implement look up once Glance meta data is available
|
||||
#to find a matching TOSCA node using the TOSCA types
|
||||
# TODO(spzala) implement look up once Glance meta data is available
|
||||
# to find a matching TOSCA node using the TOSCA types
|
||||
msg = _('Lookup by TOSCA types are not supported. '
|
||||
'Requirement for %s can not be full-filled.') % self.name
|
||||
if (node in list(self.type_definition.TOSCA_DEF.keys())
|
||||
@ -86,14 +87,14 @@ class NodeTemplate(EntityTemplate):
|
||||
relationship = value.get('relationship')
|
||||
if relationship:
|
||||
found_relationship_tpl = False
|
||||
#apply available relationship templates if found
|
||||
# apply available relationship templates if found
|
||||
for tpl in self.available_rel_tpls:
|
||||
if tpl.name == relationship:
|
||||
rtype = RelationshipType(tpl.type)
|
||||
explicit_relation[rtype] = related_tpl
|
||||
self.relationship_tpl.append(tpl)
|
||||
found_relationship_tpl = True
|
||||
#create relationship template object.
|
||||
# create relationship template object.
|
||||
if not found_relationship_tpl:
|
||||
if isinstance(relationship, dict):
|
||||
relationship = relationship.get('type')
|
||||
|
@ -1,13 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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.
|
@ -142,13 +142,13 @@ class PropertyTest(TestCase):
|
||||
|
||||
def test_timestamp(self):
|
||||
test_property_schema = {'type': 'timestamp'}
|
||||
#canonical timestamp
|
||||
# canonical timestamp
|
||||
propertyInstance = Property('test_property', '2015-04-01T02:59:43.1Z',
|
||||
test_property_schema)
|
||||
self.assertIsNone(propertyInstance.validate())
|
||||
self.assertEqual("2015-04-01T02:59:43.1Z", propertyInstance.value)
|
||||
|
||||
#iso8601 timestamp
|
||||
# iso8601 timestamp
|
||||
propertyInstance = Property('test_property',
|
||||
'2015-04-01t21:59:43.10-05:00',
|
||||
test_property_schema)
|
||||
@ -156,20 +156,20 @@ class PropertyTest(TestCase):
|
||||
self.assertEqual("2015-04-01t21:59:43.10-05:00",
|
||||
propertyInstance.value)
|
||||
|
||||
#space separated timestamp
|
||||
# space separated timestamp
|
||||
propertyInstance = Property('test_property',
|
||||
'2015-04-01 21:59:43.10 -5',
|
||||
test_property_schema)
|
||||
self.assertIsNone(propertyInstance.validate())
|
||||
self.assertEqual("2015-04-01 21:59:43.10 -5", propertyInstance.value)
|
||||
|
||||
#no time zone timestamp
|
||||
# no time zone timestamp
|
||||
propertyInstance = Property('test_property', '2015-04-01 21:59:43.10',
|
||||
test_property_schema)
|
||||
self.assertIsNone(propertyInstance.validate())
|
||||
self.assertEqual("2015-04-01 21:59:43.10", propertyInstance.value)
|
||||
|
||||
#date (00:00:00Z)
|
||||
# date (00:00:00Z)
|
||||
propertyInstance = Property('test_property', '2015-04-01',
|
||||
test_property_schema)
|
||||
self.assertIsNone(propertyInstance.validate())
|
||||
@ -177,7 +177,7 @@ class PropertyTest(TestCase):
|
||||
|
||||
def test_timestamp_invalid(self):
|
||||
test_property_schema = {'type': 'timestamp'}
|
||||
#invalid timestamp - day out of range
|
||||
# invalid timestamp - day out of range
|
||||
propertyInstance = Property('test_property', '2015-04-115T02:59:43.1Z',
|
||||
test_property_schema)
|
||||
error = self.assertRaises(ValueError, propertyInstance.validate)
|
||||
|
@ -168,7 +168,7 @@ class ToscaTemplateTest(TestCase):
|
||||
'Unexpected interface: {0}'.format(interface.name))
|
||||
|
||||
def test_normative_type_by_short_name(self):
|
||||
#test template with a short name Compute
|
||||
# test template with a short name Compute
|
||||
template = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"data/test_tosca_normative_type_by_shortname.yaml")
|
||||
@ -258,8 +258,8 @@ class ToscaTemplateTest(TestCase):
|
||||
node in node_tpl.relationships.items()])
|
||||
|
||||
def test_template_requirements_not_implemented(self):
|
||||
#TODO(spzala) replace this test with new one once TOSCA types look up
|
||||
#support is implemented.
|
||||
# TODO(spzala): replace this test with new one once TOSCA types look up
|
||||
# support is implemented.
|
||||
"""Requirements that yet need to be implemented
|
||||
|
||||
The following requirement formats are not yet implemented,
|
||||
@ -333,7 +333,7 @@ class ToscaTemplateTest(TestCase):
|
||||
properties:
|
||||
test: 1
|
||||
'''
|
||||
#custom definition with capability type definition
|
||||
# custom definition with capability type definition
|
||||
custom_def = '''
|
||||
tosca.nodes.WebApplication.TestApp:
|
||||
derived_from: tosca.nodes.WebApplication
|
||||
@ -358,7 +358,7 @@ class ToscaTemplateTest(TestCase):
|
||||
expected_capabilities,
|
||||
sorted(tpl.get_capabilities().keys()))
|
||||
|
||||
#custom definition without capability type definition
|
||||
# custom definition without capability type definition
|
||||
custom_def = '''
|
||||
tosca.nodes.WebApplication.TestApp:
|
||||
derived_from: tosca.nodes.WebApplication
|
||||
|
@ -15,7 +15,8 @@ import six
|
||||
|
||||
from translator.toscalib.common import exception
|
||||
from translator.toscalib.nodetemplate import NodeTemplate
|
||||
from translator.toscalib.parameters import Input, Output
|
||||
from translator.toscalib.parameters import Input
|
||||
from translator.toscalib.parameters import Output
|
||||
from translator.toscalib.relationship_template import RelationshipTemplate
|
||||
from translator.toscalib.tests.base import TestCase
|
||||
from translator.toscalib.tosca_template import ToscaTemplate
|
||||
|
@ -19,14 +19,15 @@ from translator.toscalib.common.exception import MissingRequiredFieldError
|
||||
from translator.toscalib.common.exception import UnknownFieldError
|
||||
from translator.toscalib import functions
|
||||
from translator.toscalib.nodetemplate import NodeTemplate
|
||||
from translator.toscalib.parameters import Input, Output
|
||||
from translator.toscalib.parameters import Input
|
||||
from translator.toscalib.parameters import Output
|
||||
from translator.toscalib.relationship_template import RelationshipTemplate
|
||||
from translator.toscalib.tpl_relationship_graph import ToscaGraph
|
||||
|
||||
import translator.toscalib.utils.yamlparser
|
||||
|
||||
|
||||
#TOSCA template key names
|
||||
# TOSCA template key names
|
||||
SECTIONS = (DEFINITION_VERSION, DEFAULT_NAMESPACE, TEMPLATE_NAME,
|
||||
TEMPLATE_AUTHOR, TEMPLATE_VERSION, DESCRIPTION, IMPORTS,
|
||||
DSL_DEFINITIONS, INPUTS, NODE_TEMPLATES, RELATIONSHIP_TEMPLATES,
|
||||
|
Loading…
Reference in New Issue
Block a user