Verify the validity of cpu_affinity
we should preventing user to create a vnf when getting any invalid value of cpu_affinity Change-Id: Ic0014ab55b4710fd04fd2121d46679d319af6681
This commit is contained in:
parent
f9414c99e8
commit
43cf012ea8
|
@ -126,6 +126,11 @@ class CpuAllocationInvalidKeys(exceptions.InvalidInput):
|
|||
"Supported keys are: %(valid_keys)s")
|
||||
|
||||
|
||||
class CpuAllocationInvalidValues(exceptions.InvalidInput):
|
||||
message = _("Invalid values specified in VNFD - %(error_msg_details)s."
|
||||
"Supported Values are: %(valid_values)s")
|
||||
|
||||
|
||||
class NumaNodesInvalidKeys(exceptions.InvalidInput):
|
||||
message = _("Invalid keys specified in VNFD - %(error_msg_details)s."
|
||||
"Supported keys are: %(valid_keys)s")
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
|
||||
|
||||
description: OpenWRT with services
|
||||
|
||||
metadata:
|
||||
template_name: OpenWRT
|
||||
|
||||
topology_template:
|
||||
node_templates:
|
||||
|
||||
VDU1:
|
||||
type: tosca.nodes.nfv.VDU.Tacker
|
||||
capabilities:
|
||||
nfv_compute:
|
||||
properties:
|
||||
num_cpus: 8
|
||||
disk_size: 10 GB
|
||||
mem_size: 4096 MB
|
||||
mem_page_size: any
|
||||
numa_node_count: 2
|
||||
cpu_allocation:
|
||||
cpu_affinity: dedicatedss
|
||||
thread_allocation: avoid
|
||||
socket_count: 2
|
||||
thread_count: 2
|
||||
core_count: 2
|
||||
properties:
|
||||
image: OpenWRT
|
||||
mgmt_driver: openwrt
|
||||
monitoring_policy:
|
||||
name: ping
|
||||
actions:
|
||||
failure: respawn
|
||||
parameters:
|
||||
count: 3
|
||||
interval: 10
|
|
@ -17,6 +17,7 @@ import os
|
|||
import testtools
|
||||
import yaml
|
||||
|
||||
from tacker.extensions import vnfm
|
||||
from tacker.tosca import utils as toscautils
|
||||
from toscaparser import tosca_template
|
||||
from translator.hot import tosca_translator
|
||||
|
@ -179,6 +180,18 @@ class TestToscaUtils(testtools.TestCase):
|
|||
actual_flavor_dict = toscautils.get_flavor_dict(tosca)
|
||||
self.assertEqual(expected_flavor_dict, actual_flavor_dict)
|
||||
|
||||
def test_get_flavor_dict_with_wrong_cpu(self):
|
||||
tosca_fes = _get_template(
|
||||
'tosca_flavor_with_wrong_cpu.yaml')
|
||||
vnfd_dict = yaml.safe_load(tosca_fes)
|
||||
toscautils.updateimports(vnfd_dict)
|
||||
tosca = tosca_template.ToscaTemplate(a_file=False,
|
||||
yaml_dict_tpl=vnfd_dict)
|
||||
|
||||
self.assertRaises(vnfm.CpuAllocationInvalidValues,
|
||||
toscautils.get_flavor_dict,
|
||||
tosca)
|
||||
|
||||
def test_tacker_conf_heat_extra_specs_all_numa_count(self):
|
||||
tosca_fes_all_numa_count = _get_template(
|
||||
'tosca_flavor_all_numa_count.yaml')
|
||||
|
|
|
@ -57,6 +57,8 @@ CPU_PROP_MAP = (('hw:cpu_policy', 'cpu_affinity'),
|
|||
('hw:cpu_threads', 'thread_count'),
|
||||
('hw:cpu_cores', 'core_count'))
|
||||
|
||||
CPU_PROP_VAL_MAP = {'cpu_affinity': ('shared', 'dedicated')}
|
||||
|
||||
CPU_PROP_KEY_SET = {'cpu_affinity', 'thread_allocation', 'socket_count',
|
||||
'thread_count', 'core_count'}
|
||||
|
||||
|
@ -621,8 +623,14 @@ def populate_flavor_extra_specs(es_dict, properties, flavor_extra_input):
|
|||
error_msg_details=(', '.join(invalid_input)),
|
||||
valid_keys=(', '.join(CPU_PROP_KEY_SET)))
|
||||
for(k, v) in CPU_PROP_MAP:
|
||||
if v in cpu_dict:
|
||||
es_dict[k] = cpu_dict[v]
|
||||
if v not in cpu_dict:
|
||||
continue
|
||||
if CPU_PROP_VAL_MAP.get(v, None):
|
||||
if cpu_dict[v] not in CPU_PROP_VAL_MAP[v]:
|
||||
raise vnfm.CpuAllocationInvalidValues(
|
||||
error_msg_details=cpu_dict[v],
|
||||
valid_values=CPU_PROP_VAL_MAP[v])
|
||||
es_dict[k] = cpu_dict[v]
|
||||
if flavor_extra_input:
|
||||
es_dict.update(flavor_extra_input)
|
||||
|
||||
|
|
Loading…
Reference in New Issue