Fix attribute type for hugepages for DPDK

Change attribute type to support both 'integer' and 'string' values.

Change-Id: If8539ade57365a40fe493c584e6bf9d0516e5662
Closes-Bug: #1561543
This commit is contained in:
Fedor Zhadaev 2016-03-28 17:48:29 +03:00
parent 29d6deb84b
commit b04a2541fe
7 changed files with 16 additions and 15 deletions

View File

@ -241,7 +241,8 @@ ATTRIBUTE_SCHEMA = {
'file',
'text_list',
'textarea_list',
'custom_hugepages'
'custom_hugepages',
'simple_hugepages'
]
},
# 'value': None, # custom validation depending on type
@ -321,6 +322,7 @@ ATTRIBUTE_TYPE_SCHEMAS = {
'radio': ALLOWED_VALUES_SCHEMA,
'select': ALLOWED_VALUES_SCHEMA,
'text': {'value': {'type': 'string'}},
'simple_hugepages': {'value': {'type': ['string', 'integer']}},
'textarea': {'value': {'type': 'string'}},
'text_list': MULTIPLE_TEXT_FIELDS_SCHEMA,
'textarea_list': MULTIPLE_TEXT_FIELDS_SCHEMA

View File

@ -2140,7 +2140,7 @@
weight: 20
description: "DPDK Huge Pages per NUMA node in MB"
label: "DPDK Huge Pages"
type: "text"
type: "simple_hugepages"
value: "0"
regex:
source: '^\d+$'

View File

@ -1317,7 +1317,7 @@ class NodeAttributes(object):
# FIXME(asvechnikov): remove this part,
# after implementing of blueprint input-type-number in UI
for attr in six.itervalues(hugepages):
if attr.get('type') == 'text':
if attr.get('type') == 'simple_hugepages':
attr['value'] = int(attr['value'])
elif attr.get('type') == 'custom_hugepages':
for size in attr['value']:
@ -1416,7 +1416,7 @@ class NodeAttributes(object):
value = attrs['value']
for size, count in six.iteritems(value):
hugepages[size] += int(count)
elif attrs.get('type') == 'text':
elif attrs.get('type') == 'simple_hugepages':
# type text means that value is the number of memory in MB
# per NUMA node which should be converted to pages count
count_per_numa_node = cls.pages_per_numa_node(attrs['value'])
@ -1481,7 +1481,7 @@ class NodeAttributes(object):
components = {'all': [], 'any': []}
for attrs in hugepages.values():
if attrs.get('type') == 'text':
if attrs.get('type') == 'simple_hugepages':
# type text means size of memory in MiB to allocate with
# 2MiB pages, so we need to calculate pages count
pages_count = cls.pages_per_numa_node(attrs['value'])

View File

@ -1890,7 +1890,7 @@ class TestHandlers(BaseIntegrationTest):
node = self.env.nodes[0]
node.attributes['hugepages'] = {
'dpdk': {'type': 'text', 'value': '1026'},
'dpdk': {'type': 'simple_hugepages', 'value': '1026'},
'nova': {'type': 'custom_hugepages', 'value': {'2048': 1}}
}

View File

@ -318,13 +318,12 @@ class TestDeploymentAttributesSerialization90(
'nova': {
'type': 'custom_hugepages',
'value': {
# FIXME make counts integer after appropriate UI fix
'2048': '512',
'2048': 512,
}
},
'dpdk': {
'type': 'text',
'value': '512',
'type': 'simple_hugepages',
'value': 512,
}
}
})

View File

@ -71,7 +71,7 @@ class TestNodeAttributes(base.BaseUnitTest):
'2048': 14,
'1048576': '2'}},
'comp2': {
'type': 'text',
'type': 'simple_hugepages',
'value': 20}}},
meta={'numa_topology': {'numa_nodes': [{'id': 0}]}})
expected = {
@ -90,7 +90,7 @@ class TestNodeAttributes(base.BaseUnitTest):
'value': {
'1048576': 2}},
'comp2': {
'type': 'text',
'type': 'simple_hugepages',
'value': '10'}}},
meta={'numa_topology': {'numa_nodes': [{'id': '0'}]}})
expected = " hugepagesz=2M hugepages=5 hugepagesz=1G hugepages=2"
@ -110,7 +110,7 @@ class TestNodeAttributes(base.BaseUnitTest):
}
},
'comp2': {
'type': 'text',
'type': 'simple_hugepages',
'value': '512'}}},
meta={'numa_topology': {'numa_nodes': [
{'id': 0, 'memory': 2 ** 31},

View File

@ -45,7 +45,7 @@ class BaseNodeAttributeValidatorTest(base.BaseTestCase):
'value': {},
},
'dpdk': {
'type': 'text',
'type': 'simple_hugepages',
'value': '0',
},
},
@ -81,7 +81,7 @@ class TestNodeAttributesValidatorHugepages(BaseNodeAttributeValidatorTest):
},
},
'dpdk': {
'value': '2',
'value': 2,
},
}
}