Merge "TOSCA: Handle memory units"
This commit is contained in:
commit
93901bea0f
@ -11,6 +11,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from translator.common.utils import MemoryUnit
|
||||
from translator.hot.syntax.hot_resource import HotResource
|
||||
|
||||
# A design issue to be resolved is how to translate the generic TOSCA server
|
||||
@ -107,11 +108,13 @@ class ToscaCompute(HotResource):
|
||||
match_cpu = self._match_flavors(match_all, FLAVORS, 'num_cpus', cpu)
|
||||
|
||||
# flavors that fit the mem size
|
||||
mem = properties.get('mem_size')
|
||||
mem = MemoryUnit.convert_unit_size_to_num(properties.get('mem_size'),
|
||||
'MB')
|
||||
match_cpu_mem = self._match_flavors(match_cpu, FLAVORS,
|
||||
'mem_size', mem)
|
||||
# flavors that fit the disk size
|
||||
disk = properties.get('disk_size')
|
||||
disk = MemoryUnit.convert_unit_size_to_num(properties.get('disk_size'),
|
||||
'GB')
|
||||
match_cpu_mem_disk = self._match_flavors(match_cpu_mem, FLAVORS,
|
||||
'disk_size', disk)
|
||||
# if multiple match, pick the flavor with the least memory
|
||||
|
@ -27,9 +27,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
@ -27,9 +27,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
@ -45,9 +45,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
@ -27,9 +27,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
@ -45,9 +45,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
@ -9,9 +9,9 @@ imports:
|
||||
dsl_definitions:
|
||||
ubuntu_node: &ubuntu_node
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: 1
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
os_capabilities: &os_capabilities
|
||||
architecture: x86_64
|
||||
type: Linux
|
||||
|
@ -25,9 +25,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
@ -50,9 +50,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
43
translator/tests/test_utils.py
Normal file
43
translator/tests/test_utils.py
Normal file
@ -0,0 +1,43 @@
|
||||
# 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.
|
||||
|
||||
import translator.common.utils
|
||||
from translator.toscalib.tests.base import TestCase
|
||||
|
||||
|
||||
class CommonUtilsTest(TestCase):
|
||||
|
||||
MemoryUnit = translator.common.utils.MemoryUnit
|
||||
|
||||
def test_convert_unit_size_to_num(self):
|
||||
size = '1 TB'
|
||||
num_to_convert = 'GB'
|
||||
expected_output = 1000
|
||||
output = self.MemoryUnit.convert_unit_size_to_num(size, num_to_convert)
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
size = '40 GB'
|
||||
num_to_convert = 'MB'
|
||||
expected_output = 40000
|
||||
output = self.MemoryUnit.convert_unit_size_to_num(size, num_to_convert)
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
def test_validate_unit(self):
|
||||
unit = 'AB'
|
||||
exp_msg = ('Provided unit "{0}" is not valid. The valid units are '
|
||||
'{1}').format(unit, self.MemoryUnit.UNIT_SIZE_DICT.keys())
|
||||
try:
|
||||
self.MemoryUnit.validate_unit(unit)
|
||||
except Exception as err:
|
||||
self.assertTrue(
|
||||
isinstance(err, ValueError))
|
||||
self.assertEqual(exp_msg, err.__str__())
|
@ -91,9 +91,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
@ -15,9 +15,9 @@ node_templates:
|
||||
type: Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
@ -13,9 +13,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
@ -15,9 +15,9 @@ node_template:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
@ -14,9 +14,9 @@ imports:
|
||||
dsl_definitions:
|
||||
ubuntu_node: &ubuntu_node
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: my_cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
os_capabilities: &os_capabilities
|
||||
architecture: x86_64
|
||||
type: Linux
|
||||
|
@ -99,9 +99,9 @@ node_templates:
|
||||
type: tosca.nodes.Compute
|
||||
properties:
|
||||
# compute properties (flavor)
|
||||
disk_size: 10
|
||||
disk_size: 10 GB
|
||||
num_cpus: { get_input: cpus }
|
||||
mem_size: 4096
|
||||
mem_size: 4096 MB
|
||||
capabilities:
|
||||
os:
|
||||
properties:
|
||||
|
@ -108,7 +108,7 @@ class ToscaTemplateTest(TestCase):
|
||||
'''Test property value'''
|
||||
for property in tpl.properties:
|
||||
if property.name == 'mem_size':
|
||||
self.assertEqual(property.value, 4096)
|
||||
self.assertEqual(property.value, '4096 MB')
|
||||
'''Test capability'''
|
||||
self.assertIn('os', [cap.name for cap in tpl.capabilities])
|
||||
os_props_objs = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user