Add HPA cpu topology capabilities for TC 57/38357/1
authorYun Huang <yun.huang@windriver.com>
Mon, 26 Mar 2018 05:05:44 +0000 (13:05 +0800)
committerYun Huang <yun.huang@windriver.com>
Mon, 26 Mar 2018 05:08:57 +0000 (13:08 +0800)
Change-Id: I6e787e26ccc4288e1ff4055c5f4b3cbab52c5c61
Issue-ID: MULTICLOUD-200
Signed-off-by: Yun Huang <yun.huang@windriver.com>
windriver/titanium_cloud/registration/tests/test_registration.py
windriver/titanium_cloud/registration/views/registration.py

index 3e8c561..53e8a47 100644 (file)
@@ -50,7 +50,10 @@ MOCK_GET_FLAVOR_EXTRA_SPECS_RESPONSE = {
       "aggregate_instance_extra_specs:storage" : "local_image",
       "capabilities:cpu_info:model" : "Haswell",
       "hw:cpu_policy" : "dedicated",
-      "hw:cpu_thread_policy" : "prefer"
+      "hw:cpu_thread_policy" : "prefer",
+      "hw:cpu_sockets" : "2",
+      "hw:cpu_cores" : "4",
+      "hw:cpu_threads" : "16"
    }
 }
 
index 8a21cb5..c2d2f07 100644 (file)
@@ -94,6 +94,12 @@ class Registry(newton_registration.Registry):
             self._logger.debug("cpupining_capabilities_info: %s" % caps_dict)
             hpa_caps.append(caps_dict)
 
+        # cputopology capabilities
+        caps_dict = self._get_cputopology_capabilities(extra_specs)
+        if len(caps_dict) > 0:
+            self._logger.debug("cputopology_capabilities_info: %s" % caps_dict)
+            hpa_caps.append(caps_dict)
+
         return hpa_caps
 
     def _get_hpa_basic_capabilities(self, flavor):
@@ -133,3 +139,26 @@ class Registry(newton_registration.Registry):
 
         return cpupining_capability
 
+    def _get_cputopology_capabilities(self, extra_specs):
+        cputopology_capability = {}
+        feature_uuid = uuid.uuid4()
+
+        if extra_specs.has_key('hw:cpu_sockets') or extra_specs.has_key('hw:cpu_cores') or extra_specs.has_key('hw:cpu_threads'):
+            cputopology_capability['hpaCapabilityID'] = str(feature_uuid)
+            cputopology_capability['hpaFeature'] = 'cpuTopology'
+            cputopology_capability['hardwareArchitecture'] = 'generic'
+            cputopology_capability['version'] = 'v1'
+
+            cputopology_capability['attributes'] = []
+            if extra_specs.has_key('hw:cpu_sockets'):
+                cputopology_capability['attributes'].append({'hpa-attribute-key': 'numCpuSockets',
+                                                             'hpa-attribute-value':{'value': str(extra_specs['hw:cpu_sockets'])}})
+            if extra_specs.has_key('hw:cpu_cores'):
+                cputopology_capability['attributes'].append({'hpa-attribute-key': 'numCpuCores',
+                                                             'hpa-attribute-value':{'value': str(extra_specs['hw:cpu_cores'])}})
+            if extra_specs.has_key('hw:cpu_threads'):
+                cputopology_capability['attributes'].append({'hpa-attribute-key': 'numCpuThreads',
+                                                             'hpa-attribute-value':{'value': str(extra_specs['hw:cpu_threads'])}})
+
+        return cputopology_capability
+