diff options
author | Dileep Ranganathan <dileep.ranganathan@intel.com> | 2018-09-19 17:59:53 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-19 17:59:53 +0000 |
commit | 933d21d61f23b9c854b883eb357aea612cf1df38 (patch) | |
tree | 770afe2a0e7a94a6489334e8dfca7fefd24d7582 /conductor | |
parent | dc1e0098fd0c7f1731888abec9efe66fc27987cb (diff) | |
parent | aeca074c3a5b38428eefbd0b5d5ac52cd18ea382 (diff) |
Merge "Support multiple candidates with same feature name"
Diffstat (limited to 'conductor')
4 files changed, 578 insertions, 15 deletions
diff --git a/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py b/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py index 2414e61..a77f0bf 100644 --- a/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py +++ b/conductor/conductor/data/plugins/inventory_provider/hpa_utils.py @@ -211,12 +211,14 @@ class HpaMatchProvider(object): # for the feature get the capabilty feature attribute list def _get_flavor_cfa_list(self, feature, flavor_cap_list): + feature_attr_list = [] for capability in CapabilityDataParser.get_item(flavor_cap_list, 'hpa-capability'): flavor_feature, feature_attributes = capability.get_fields() - # Multiple features will match this condition as we have pre-filtered + # Multiple features that match this condition will be filtered if feature == flavor_feature: - return feature_attributes + feature_attr_list.append(feature_attributes) + return feature_attr_list # flavor has all the required capabilties # For each required capability find capability in flavor @@ -229,23 +231,33 @@ class HpaMatchProvider(object): feature_directive = capability.get_directives() if feature_directive: feature_directive[:] = [d for d in feature_directive - if d.get("type") != ""] + if d.get("type") != ""] for item in feature_directive: directives.append(item) flavor_cfa_list = self._get_flavor_cfa_list(hpa_feature, flavor_cap_list) + req_flag = False if flavor_cfa_list is not None: - for req_feature_attr in req_cfa_list: - req_attr_key = req_feature_attr['hpa-attribute-key'] - # filter to get the attribute being compared - flavor_feature_attr = \ - filter(lambda ele: ele['hpa-attribute-key'] == \ - req_attr_key, flavor_cfa_list) - if not flavor_feature_attr and capability.item['mandatory'] == 'True': - return False, 0, None - if not self._compare_attribute(flavor_feature_attr[0], req_feature_attr) \ - and capability.item['mandatory'] == 'True': - return False, 0, None - if flavor_cfa_list is not None and capability.item['mandatory'] == 'False': + for flavor_cfa in flavor_cfa_list: + flavor_flag = True + for req_feature_attr in req_cfa_list: + req_attr_key = req_feature_attr['hpa-attribute-key'] + # filter to get the attribute being compared + flavor_feature_attr = \ + filter(lambda ele: ele['hpa-attribute-key'] == + req_attr_key, flavor_cfa) + if not flavor_feature_attr: + flavor_flag = False + if not self._compare_attribute(flavor_feature_attr[0], + req_feature_attr): + flavor_flag = False + if not flavor_flag: + continue + else: + req_flag = True + break + if not req_flag and capability.item['mandatory'] == 'True': + return False, 0, None + if req_flag and capability.item['mandatory'] == 'False': score = score + int(capability.item['score']) return True, score, directives diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/hpa_flavors.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/hpa_flavors.json index 19cf8b9..47681f5 100644 --- a/conductor/conductor/tests/unit/data/plugins/inventory_provider/hpa_flavors.json +++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/hpa_flavors.json @@ -297,6 +297,134 @@ "resource-version": "1520943439264" }, { + "flavor-id": "f5aa2b2e-3206-41b6-19d5-cf6t2b098c43", + "flavor-name": "flavor-ovsdpdk-cpu-pinning-double-sriov-NIC-Network-set", + "flavor-vcpus": 32, + "flavor-ram": 131072, + "flavor-disk": 2097152, + "flavor-ephemeral": 128, + "flavor-swap": "0", + "flavor-is-public": false, + "flavor-selflink": "pXtX", + "flavor-disabled": false, + "hpa-capabilities": { + "hpa-capability": [ + { + "hpa-capability-id": "8d36a8fe-bfee-446a-bbcb-881ee66c8f78", + "hpa-feature": "ovsDpdk", + "hpa-version": "v1", + "architecture": "generic", + "resource-version": "1520943846328", + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "dataProcessingAccelerationLibrary", + "hpa-attribute-value": "{\"value\":\"v18.02\"}", + "resource-version": "1520943846346" + } + ] + }, + { + "hpa-capability-id": "c140c945-1532-4908-86c9-d7f71416f1dd", + "hpa-feature": "cpuPinning", + "hpa-version": "v1", + "architecture": "generic", + "resource-version": "1520943846297", + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "logicalCpuPinningPolicy", + "hpa-attribute-value": "{\"value\":\"dedicated\"}", + "resource-version": "1520943846312" + }, + { + "hpa-attribute-key": "logicalCpuThreadPinningPolicy", + "hpa-attribute-value": "{\"value\":\"prefer\"}", + "resource-version": "1520943846301" + } + ] + }, + { + "hpa-capability-id": "4565615b-1077-4bb5-a340-c5be48db2aaa", + "hpa-feature": "basicCapabilities", + "hpa-version": "v1", + "architecture": "generic", + "resource-version": "1520943846269", + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": "{\"value\":\"16\", \"unit\":\"GB\" }", + "resource-version": "1520943846282" + }, + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "{\"value\":\"8\"}", + "resource-version": "1520943846272" + } + ] + }, + { + "hpa-capability-id": "8fa22e64-41b4-471f-96ad-6c470868eo4c", + "hpa-feature": "sriovNICNetwork", + "hpa-version": "v1", + "architecture": "generic", + "resource-version": "1520943845443", + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "pciCount", + "hpa-attribute-value": "{\"value\":\"1\"}", + "resource-version": "1520943845870" + }, + { + "hpa-attribute-key": "pciVendorId", + "hpa-attribute-value": "{\"value\": \"8086\"}", + "resource-version": "1520943845764" + }, + { + "hpa-attribute-key": "pciDeviceId", + "hpa-attribute-value": "{\"value\": \"1234\"}", + "resource-version": "1520943847729" + }, + { + "hpa-attribute-key": "physicalNetwork", + "hpa-attribute-value": "{\"value\": \"physnet1\"}", + "resource-version": "1520943871129" + } + ] + }, + { + "hpa-capability-id": "86y7ee64-41b4-471f-96ad-6c470868eo4c", + "hpa-feature": "sriovNICNetwork", + "hpa-version": "v1", + "architecture": "generic", + "resource-version": "1520943845443", + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "pciCount", + "hpa-attribute-value": "{\"value\":\"1\"}", + "resource-version": "1520943845870" + }, + { + "hpa-attribute-key": "pciVendorId", + "hpa-attribute-value": "{\"value\": \"8086\"}", + "resource-version": "1520943845764" + }, + { + "hpa-attribute-key": "pciDeviceId", + "hpa-attribute-value": "{\"value\": \"4321\"}", + "resource-version": "1520943847729" + }, + { + "hpa-attribute-key": "physicalNetwork", + "hpa-attribute-value": "{\"value\": \"physnet2\"}", + "resource-version": "1520943871129" + } + ] + } + + ] + }, + "resource-version": "1520943439264" + }, + { "flavor-id": "f5aa2b2e-3206-41b6-80d5-cf041b098c43", "flavor-name": "flavor-cpu-pinning-ovsdpdk-instruction-set", "flavor-vcpus": 32, diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/hpa_req_features.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/hpa_req_features.json index bfda6a7..9e2c507 100644 --- a/conductor/conductor/tests/unit/data/plugins/inventory_provider/hpa_req_features.json +++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/hpa_req_features.json @@ -323,5 +323,399 @@ } ] } + ], + [ + { + "hpa-feature": "basicCapabilities", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "True", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "8", + "operator": "=" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": "16", + "operator": "=", + "unit": "GB" + } + ] + }, + { + "hpa-feature": "ovsDpdk", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "False", + "score": "5", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "dataProcessingAccelerationLibrary", + "hpa-attribute-value": "v18.02", + "operator": "=" + } + ] + }, + { + "hpa-feature": "cpuPinning", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "False", + "score": "1", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "logicalCpuThreadPinningPolicy", + "hpa-attribute-value": "prefer", + "operator": "=" + }, + { + "hpa-attribute-key": "logicalCpuPinningPolicy", + "hpa-attribute-value": "dedicated", + "operator": "=" + } + ] + }, + { + "hpa-feature": "hugePages", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "True", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "memoryPageSize", + "hpa-attribute-value": "2", + "operator": "=", + "unit": "GB" + } + ] + } + ], + [ + { + "hpa-feature": "basicCapabilities", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "True", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "8", + "operator": "=" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": "16", + "operator": "=", + "unit": "GB" + } + ] + }, + { + "hpa-feature": "ovsDpdk", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "False", + "score": "5", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "dataProcessingAccelerationLibrary", + "hpa-attribute-value": "v18.02", + "operator": "=" + } + ] + }, + { + "hpa-feature": "cpuPinning", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "False", + "score": "1", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "logicalCpuThreadPinningPolicy", + "hpa-attribute-value": "prefer", + "operator": "=" + }, + { + "hpa-attribute-key": "logicalCpuPinningPolicy", + "hpa-attribute-value": "dedicated", + "operator": "=" + } + ] + }, + { + "hpa-feature": "instructionSetExtensions", + "hpa-version": "v1", + "architecture": "Intel64", + "mandatory": "False", + "score": "5", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "instructionSetExtensions", + "hpa-attribute-value": [ + "A11", + "B22" + ], + "operator": "ALL" + } + ] + }, + { + "hpa-feature": "sriovNICNetwork", + "hpa-version": "v1", + "mandatory": "True", + "architecture": "generic", + "directives": [ + { + "type": "sriovNICNetwork_directives", + "attributes": [ + { + "attribute_name": "A", + "attribute_value": "a" + } + ] + } + ], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "pciCount", + "hpa-attribute-value": "1", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciVendorId", + "hpa-attribute-value": "8086", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciDeviceId", + "hpa-attribute-value": "1234", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "physicalNetwork", + "hpa-attribute-value": "physnet1", + "operator": "=", + "unit": "" + } + ] + }, + { + "hpa-feature": "sriovNICNetwork", + "hpa-version": "v1", + "mandatory": "True", + "architecture": "generic", + "directives": [ + { + "type": "sriovNICNetwork_directives", + "attributes": [ + { + "attribute_name": "B", + "attribute_value": "b" + } + ] + } + ], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "pciCount", + "hpa-attribute-value": "1", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciVendorId", + "hpa-attribute-value": "8086", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciDeviceId", + "hpa-attribute-value": "4321", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "physicalNetwork", + "hpa-attribute-value": "physnet2", + "operator": "=", + "unit": "" + } + ] + } + ], + [ + { + "hpa-feature": "basicCapabilities", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "True", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "numVirtualCpu", + "hpa-attribute-value": "8", + "operator": "=" + }, + { + "hpa-attribute-key": "virtualMemSize", + "hpa-attribute-value": "16", + "operator": "=", + "unit": "GB" + } + ] + }, + { + "hpa-feature": "ovsDpdk", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "False", + "score": "5", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "dataProcessingAccelerationLibrary", + "hpa-attribute-value": "v18.02", + "operator": "=" + } + ] + }, + { + "hpa-feature": "cpuPinning", + "hpa-version": "v1", + "architecture": "generic", + "mandatory": "False", + "score": "1", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "logicalCpuThreadPinningPolicy", + "hpa-attribute-value": "prefer", + "operator": "=" + }, + { + "hpa-attribute-key": "logicalCpuPinningPolicy", + "hpa-attribute-value": "dedicated", + "operator": "=" + } + ] + }, + { + "hpa-feature": "instructionSetExtensions", + "hpa-version": "v1", + "architecture": "Intel64", + "mandatory": "False", + "score": "5", + "directives": [], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "instructionSetExtensions", + "hpa-attribute-value": [ + "A11", + "B22" + ], + "operator": "ALL" + } + ] + }, + { + "hpa-feature": "sriovNICNetwork", + "hpa-version": "v1", + "mandatory": "True", + "architecture": "generic", + "directives": [ + { + "type": "sriovNICNetwork_directives", + "attributes": [ + { + "attribute_name": "C", + "attribute_value": "c" + } + ] + } + ], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "pciCount", + "hpa-attribute-value": "1", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciVendorId", + "hpa-attribute-value": "8086", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciDeviceId", + "hpa-attribute-value": "1235", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "physicalNetwork", + "hpa-attribute-value": "physnet1", + "operator": "=", + "unit": "" + } + ] + }, + { + "hpa-feature": "sriovNICNetwork", + "hpa-version": "v1", + "mandatory": "True", + "architecture": "generic", + "directives": [ + { + "type": "sriovNICNetwork_directives", + "attributes": [ + { + "attribute_name": "B", + "attribute_value": "b" + } + ] + } + ], + "hpa-feature-attributes": [ + { + "hpa-attribute-key": "pciCount", + "hpa-attribute-value": "1", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciVendorId", + "hpa-attribute-value": "8086", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "pciDeviceId", + "hpa-attribute-value": "4321", + "operator": "=", + "unit": "" + }, + { + "hpa-attribute-key": "physicalNetwork", + "hpa-attribute-value": "physnet2", + "operator": "=", + "unit": "" + } + ] + } ] ]
\ No newline at end of file diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py b/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py index 435e0a9..0c04b07 100644 --- a/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py +++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py @@ -331,3 +331,32 @@ class TestAAI(unittest.TestCase): self.assertEqual(flavor_map, self.aai_ep.match_hpa(candidate_json['candidate_list'][1], feature_json[2])) + self.assertEqual(None, self.aai_ep.match_hpa(candidate_json['candidate_list'][1], + feature_json[3])) + flavor_map = {"flavor_map": {"flavor-id": "f5aa2b2e-3206-41b6-19d5-cf6t2b098c43", + "flavor-name": "flavor-ovsdpdk-cpu-pinning-double-sriov-NIC-Network-set", + "score": 6}, + "directives": [ + { + "type": "sriovNICNetwork_directives", + "attributes": [ + { + "attribute_name": "A", + "attribute_value": "a" + } + ] + }, + { + "type": "sriovNICNetwork_directives", + "attributes": [ + { + "attribute_name": "B", + "attribute_value": "b" + } + ] + }] + } + self.assertEqual(flavor_map, self.aai_ep.match_hpa(candidate_json['candidate_list'][1], + feature_json[4])) + self.assertEqual(None, self.aai_ep.match_hpa(candidate_json['candidate_list'][1], + feature_json[5])) |