Merge "Limit the minimal RAM amount for OVS+DPDK to 1024MB"

This commit is contained in:
Jenkins 2017-02-13 12:25:55 +00:00 committed by Gerrit Code Review
commit c77aa8923a
4 changed files with 94 additions and 9 deletions

View File

@ -503,6 +503,23 @@ class NodeAttributesValidator(base.BasicAttributesValidator):
)
)
dpdk_hugepages = utils.get_in(attrs, 'hugepages', 'dpdk', 'value')
if objects.Node.dpdk_enabled(node):
min_dpdk_hugepages = consts.MIN_DPDK_HUGEPAGES_MEMORY
if dpdk_hugepages < min_dpdk_hugepages:
raise errors.InvalidData(
"Node {0} does not have enough hugepages for dpdk. "
"Need to allocate at least {1} MB.".format(
node.id,
min_dpdk_hugepages
)
)
elif dpdk_hugepages != 0:
raise errors.InvalidData(
"Hugepages for dpdk should be equal to 0 "
"if dpdk is disabled."
)
try:
objects.NodeAttributes.distribute_hugepages(node, attrs)
except ValueError as exc:

View File

@ -518,6 +518,8 @@ DEFAULT_DEPLOYMENT_GRAPH_TYPE = 'default'
DEFAULT_HUGEPAGE_SIZE = '2048'
HUGE_PAGES_SIZE_MAP = [('2048', '2M'), ('1048576', '1G')]
DPDK_OVS_CORE_CPUS = 1
# minimal RAM amount for OVS+DPDK in MB
MIN_DPDK_HUGEPAGES_MEMORY = 1024
MEMORY_RESERVED_FOR_OPERATING_SYSTEM = 1024 ** 3 # one GiB in bytes

View File

@ -488,7 +488,7 @@ class TestDeploymentAttributesSerialization90(
numa_nodes.append({
'id': i,
'cpus': [i],
'memory': 1024 ** 3
'memory': 2 * 1024 ** 3
})
meta = {
@ -501,17 +501,19 @@ class TestDeploymentAttributesSerialization90(
cluster_id=self.cluster_db.id,
roles=['compute'],
meta=meta)
node.interfaces[0].attributes.get('dpdk', {}).get(
'enabled', {})['value'] = True
node.attributes.update({
'hugepages': {
'dpdk': {
'value': 128},
'value': 1024},
'nova': {
'value': {'2048': 1}}}}
)
serialized_for_astute = self.serialize()
serialized_node = serialized_for_astute['nodes'][0]
self.assertEquals(
[128, 128, 128],
[1024, 1024, 1024],
serialized_node['dpdk']['ovs_socket_mem'])
self.assertTrue(serialized_node['nova']['enable_hugepages'])

View File

@ -28,7 +28,7 @@ validator = node_validator.NodeAttributesValidator.validate
def mock_cluster_attributes(func):
def wrapper(*args, **kwargs):
attr_mock = mock.patch.object(
cluster_attr_mock = mock.patch.object(
objects.Cluster,
'get_editable_attributes',
return_value={
@ -39,7 +39,12 @@ def mock_cluster_attributes(func):
}
}
)
with attr_mock:
node_dpdk_mock = mock.patch.object(
objects.Node,
'dpdk_enabled',
return_value=True
)
with cluster_attr_mock, node_dpdk_mock:
func(*args, **kwargs)
return wrapper
@ -54,8 +59,8 @@ class BaseNodeAttributeValidatorTest(base.BaseTestCase):
meta['numa_topology'] = {
"supported_hugepages": [2048, 1048576],
"numa_nodes": [
{"id": 0, "cpus": [0, 1], 'memory': 2 * 1024 ** 3},
{"id": 1, "cpus": [2, 3], 'memory': 2 * 1024 ** 3},
{"id": 0, "cpus": [0, 1], 'memory': 3 * 1024 ** 3},
{"id": 1, "cpus": [2, 3], 'memory': 3 * 1024 ** 3},
]
}
meta['cpu']['total'] = 4
@ -68,7 +73,7 @@ class BaseNodeAttributeValidatorTest(base.BaseTestCase):
},
'dpdk': {
'type': 'number',
'value': 0,
'value': 1024,
},
},
'cpu_pinning': {
@ -107,7 +112,7 @@ class TestNodeAttributesValidatorHugepages(BaseNodeAttributeValidatorTest):
},
},
'dpdk': {
'value': 2,
'value': 1024,
},
}
}
@ -132,6 +137,65 @@ class TestNodeAttributesValidatorHugepages(BaseNodeAttributeValidatorTest):
errors.InvalidData, 'Not enough memory for components',
validator, json.dumps(data), self.node, self.cluster)
@mock_cluster_attributes
def test_not_enough_dpdk_hugepages(self, m_dpdk_nics):
data = {
'hugepages': {
'nova': {
'value': {
'2048': 1,
'1048576': 0,
},
},
'dpdk': {
'value': 1023,
'min': 1024
},
}
}
message = ("Node {0} does not have enough hugepages for dpdk. "
"Need to allocate at least {1} MB.").format(self.node.id,
1024)
self.assertRaisesWithMessageIn(
errors.InvalidData, message,
validator, json.dumps(data), self.node, self.cluster)
@mock_cluster_attributes
@mock.patch.object(objects.Node, 'dpdk_enabled', return_value=False)
def test_valid_hugepages_non_dpdk(self, m_dpdk_nics, m_dpdk_enabled):
data = {
'hugepages': {
'nova': {
'value': {
'2048': 1,
'1048576': 1,
},
},
'dpdk': {
'value': 0,
},
}
}
self.assertNotRaises(errors.InvalidData, validator,
json.dumps(data), self.node, self.cluster)
@mock_cluster_attributes
@mock.patch.object(objects.Node, 'dpdk_enabled', return_value=False)
def test_non_zero_value_hugepages_non_dpdk(self, m_dpdk_nics,
m_dpdk_enabled):
data = {
'hugepages': {
'dpdk': {
'value': 1,
},
}
}
message = ("Hugepages for dpdk should be equal to 0 "
"if dpdk is disabled.")
self.assertRaisesWithMessageIn(
errors.InvalidData, message,
validator, json.dumps(data), self.node, self.cluster)
@mock_cluster_attributes
def test_dpdk_requires_too_much(self, m_dpdk_nics):
data = {