Merge "Update code base to be hacking compatible"

This commit is contained in:
Jenkins
2015-04-27 20:08:41 +00:00
committed by Gerrit Code Review
25 changed files with 75 additions and 86 deletions

View File

@@ -2,3 +2,4 @@ pbr>=0.6,!=0.7,<1.0
Babel>=1.3 Babel>=1.3
PyYAML>=3.1.0 PyYAML>=3.1.0
python_dateutil>=2.4.0 python_dateutil>=2.4.0
six>=1.9.0

View File

@@ -1,4 +1,4 @@
hacking>=0.5.6,<0.8 hacking>=0.10.0,<0.11
coverage>=3.6 coverage>=3.6
discover discover
fixtures>=0.3.14 fixtures>=0.3.14

View File

@@ -33,8 +33,8 @@ class MemoryUnit(object):
@staticmethod @staticmethod
def convert_unit_size_to_num(size, unit=None): def convert_unit_size_to_num(size, unit=None):
"""Convert given size to a number representing given unit. """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 size: unit size e.g. 1 TB
:param unit: unit to be converted to e.g GB :param unit: unit to be converted to e.g GB
:return: converted number e.g. 1000 for 1 TB size and unit GB :return: converted number e.g. 1000 for 1 TB size and unit GB
@@ -69,11 +69,11 @@ class CompareUtils(object):
@staticmethod @staticmethod
def compare_dicts(dict1, dict2): def compare_dicts(dict1, dict2):
'''Returns False if not equal or any input parameter is empty. """Return False if not equal, True if both are equal."""
Returns True if both are equal.
'''
if not dict1 or not dict2: if not dict1 or not dict2:
return False return False
# compare generated and expected hot templates # compare generated and expected hot templates
both_equal = True both_equal = True
for generated_item, expected_item in zip(dict1.items(), dict2.items()): for generated_item, expected_item in zip(dict1.items(), dict2.items()):
@@ -94,7 +94,7 @@ class CompareUtils(object):
def str_to_num(value): 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): if isinstance(value, numbers.Number):
return value return value
try: try:

View File

@@ -58,7 +58,7 @@ class ToscaNetworkPort(HotResource):
port_props['fixed_ips'] = [fixed_ip] port_props['fixed_ips'] = [fixed_ip]
elif key == 'order': elif key == 'order':
self.order = value self.order = value
#TODO(sdmonov). Need to implement the properties below # TODO(sdmonov): Need to implement the properties below
elif key == 'is_default': elif key == 'is_default':
pass pass
elif key == 'ip_range_start': elif key == 'ip_range_start':
@@ -105,7 +105,7 @@ class ToscaNetworkPort(HotResource):
if compute_resource: if compute_resource:
port_resources = compute_resource.assoc_port_resources port_resources = compute_resource.assoc_port_resources
self._insert_sorted_resource(port_resources, self) 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 # network is not the fastest way to do the things. We should
# do this only once at the end. # do this only once at the end.
networks = self._generate_networks_for_compute(port_resources) networks = self._generate_networks_for_compute(port_resources)

View File

@@ -49,7 +49,7 @@ TOSCA_TO_HOT_INPUT_TYPES = {'string': 'string',
'null': 'string'} 'null': 'string'}
class TranslateInputs(): class TranslateInputs(object):
'''Translate TOSCA Inputs to Heat Parameters.''' '''Translate TOSCA Inputs to Heat Parameters.'''
def __init__(self, inputs, parsed_params): def __init__(self, inputs, parsed_params):

View File

@@ -67,7 +67,7 @@ TOSCA_TO_HOT_REQUIRES = {'container': 'server', 'host': 'server',
TOSCA_TO_HOT_PROPERTIES = {'properties': 'input'} TOSCA_TO_HOT_PROPERTIES = {'properties': 'input'}
class TranslateNodeTemplates(): class TranslateNodeTemplates(object):
'''Translate TOSCA NodeTemplates to Heat Resources.''' '''Translate TOSCA NodeTemplates to Heat Resources.'''
def __init__(self, tosca, hot_template): def __init__(self, tosca, hot_template):

View File

@@ -14,7 +14,7 @@
from translator.hot.syntax.hot_output import HotOutput from translator.hot.syntax.hot_output import HotOutput
class TranslateOutputs(): class TranslateOutputs(object):
'''Translate TOSCA Outputs to Heat Outputs.''' '''Translate TOSCA Outputs to Heat Outputs.'''
def __init__(self, outputs, node_translator): def __init__(self, outputs, node_translator):

View File

@@ -95,12 +95,15 @@ class ToscaNetworkTest(TestCase):
'properties': 'properties':
{'cidr': {'get_param': 'network_cidr'}, {'cidr': {'get_param': 'network_cidr'},
'ip_version': 4, 'ip_version': 4,
'allocation_pools': [{'start': {'get_param': 'network': {'get_resource': 'my_network'},
'allocation_pools': [{'start':
{'get_param':
'network_start_ip'}, 'network_start_ip'},
'end': {'get_param': 'end':
{'get_param':
'network_end_ip' 'network_end_ip'
}}], }}
'network': {'get_resource': 'my_network'} ]
}} }}
expected_resource_3 = {'type': 'OS::Neutron::Port', expected_resource_3 = {'type': 'OS::Neutron::Port',
@@ -197,21 +200,20 @@ class ToscaNetworkTest(TestCase):
expected_resource_net = {'type': 'OS::Neutron::Net', expected_resource_net = {'type': 'OS::Neutron::Net',
'properties': 'properties':
{'name': 'net%d' % (net_num) {'name': 'net%d' % (net_num)}}
}}
expected_resource_subnet = {'type': 'OS::Neutron::Subnet', expected_resource_subnet = {'type': 'OS::Neutron::Subnet',
'properties': 'properties':
{'cidr': '192.168.%d.0/24' % (net_num), {'cidr': '192.168.%d.0/24' % (net_num),
'ip_version': 4, 'ip_version': 4,
'network': {'get_resource': net_name} 'network': {'get_resource': net_name}}
}} }
expected_resource_port = {'type': 'OS::Neutron::Port', expected_resource_port = {'type': 'OS::Neutron::Port',
'depends_on': [net_name], 'depends_on': [net_name],
'properties': 'properties':
{'network': {'get_resource': net_name} {'network': {'get_resource': net_name}}}
}}
self.assertIn(net_name, resources.keys()) self.assertIn(net_name, resources.keys())
self.assertIn(subnet_name, resources.keys()) self.assertIn(subnet_name, resources.keys())
self.assertIn(port_name, resources.keys()) self.assertIn(port_name, resources.keys())

View File

@@ -53,7 +53,7 @@ class CommonUtilsTest(TestCase):
str_to_convert = '55063.000000' str_to_convert = '55063.000000'
expected_output = 55063.0 expected_output = 55063.0
output = translator.common.utils.str_to_num(str_to_convert) 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): def test_compare_dicts_unequal(self):
dict1 = {'allowed_values': [1, 2, 4, 8], dict1 = {'allowed_values': [1, 2, 4, 8],

View File

@@ -13,8 +13,9 @@
from translator.toscalib.common.exception import MissingRequiredFieldError from translator.toscalib.common.exception import MissingRequiredFieldError
from translator.toscalib.common.exception import TypeMismatchError from translator.toscalib.common.exception import TypeMismatchError
from translator.toscalib.common.exception import UnknownFieldError 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.datatype import DataType
from translator.toscalib.elements.constraints import Constraint, Schema
class DataEntity(object): class DataEntity(object):

View File

@@ -36,9 +36,7 @@ class DataType(StatefulEntityType):
return self.entity_value(self.defs, 'type') return self.entity_value(self.defs, 'type')
def get_all_properties_objects(self): def get_all_properties_objects(self):
'''Return all properties objects defined in this type '''Return all properties objects defined in type and parent type.'''
and its parent type.
'''
props_def = self.get_properties_def_objects() props_def = self.get_properties_def_objects()
ptype = self.parent_type ptype = self.parent_type
while ptype: while ptype:
@@ -47,9 +45,7 @@ class DataType(StatefulEntityType):
return props_def return props_def
def get_all_properties(self): def get_all_properties(self):
'''Return a dictionary of all property definition '''Return a dictionary of all property definition name-object pairs.'''
name-object pairs.
'''
return {prop.name: prop return {prop.name: prop
for prop in self.get_all_properties_objects()} for prop in self.get_all_properties_objects()}

View File

@@ -13,6 +13,7 @@
import abc import abc
import six
from translator.toscalib.common.exception import UnknownInputError from translator.toscalib.common.exception import UnknownInputError
from translator.toscalib.utils.gettextutils import _ from translator.toscalib.utils.gettextutils import _
@@ -28,11 +29,10 @@ HOST = 'HOST'
HOSTED_ON = 'tosca.relationships.HostedOn' HOSTED_ON = 'tosca.relationships.HostedOn'
@six.add_metaclass(abc.ABCMeta)
class Function(object): class Function(object):
"""An abstract type for representing a Tosca template function.""" """An abstract type for representing a Tosca template function."""
__metaclass__ = abc.ABCMeta
def __init__(self, tosca_tpl, context, name, args): def __init__(self, tosca_tpl, context, name, args):
self.tosca_tpl = tosca_tpl self.tosca_tpl = tosca_tpl
self.context = context self.context = context
@@ -59,8 +59,7 @@ class Function(object):
class GetInput(Function): class GetInput(Function):
"""Get a property value declared within the inputs section of the service """Get a property value declared within the input of the service template.
template.
Arguments: Arguments:

View File

@@ -15,8 +15,9 @@ import logging
from translator.toscalib.common.exception import TypeMismatchError from translator.toscalib.common.exception import TypeMismatchError
from translator.toscalib.common.exception import UnknownFieldError 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 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.elements.relationshiptype import RelationshipType
from translator.toscalib.entity_template import EntityTemplate from translator.toscalib.entity_template import EntityTemplate
from translator.toscalib.relationship_template import RelationshipTemplate from translator.toscalib.relationship_template import RelationshipTemplate

View File

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

View File

@@ -258,7 +258,7 @@ class ToscaTemplateTest(TestCase):
node in node_tpl.relationships.items()]) node in node_tpl.relationships.items()])
def test_template_requirements_not_implemented(self): def test_template_requirements_not_implemented(self):
#TODO(spzala) replace this test with new one once TOSCA types look up # TODO(spzala): replace this test with new one once TOSCA types look up
# support is implemented. # support is implemented.
"""Requirements that yet need to be implemented """Requirements that yet need to be implemented

View File

@@ -15,7 +15,8 @@ import six
from translator.toscalib.common import exception from translator.toscalib.common import exception
from translator.toscalib.nodetemplate import NodeTemplate 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.relationship_template import RelationshipTemplate
from translator.toscalib.tests.base import TestCase from translator.toscalib.tests.base import TestCase
from translator.toscalib.tosca_template import ToscaTemplate from translator.toscalib.tosca_template import ToscaTemplate

View File

@@ -19,7 +19,8 @@ from translator.toscalib.common.exception import MissingRequiredFieldError
from translator.toscalib.common.exception import UnknownFieldError from translator.toscalib.common.exception import UnknownFieldError
from translator.toscalib import functions from translator.toscalib import functions
from translator.toscalib.nodetemplate import NodeTemplate 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.relationship_template import RelationshipTemplate
from translator.toscalib.tpl_relationship_graph import ToscaGraph from translator.toscalib.tpl_relationship_graph import ToscaGraph