67646a5db08abf28e4f4ff970506c00a961cec31
[pti/rtp.git] /
1 From 1577df1f8edf3e322eb743eab8f8e82ee6e3f5ee Mon Sep 17 00:00:00 2001
2 From: Jackie Huang <jackie.huang@windriver.com>
3 Date: Thu, 16 Nov 2023 16:52:33 +0800
4 Subject: [PATCH 2/2] sysinv-agent: get cpu model from lscpu for Arm
5
6 Change-Id: I70a155b98090a0bb83577345f64c3ffb281183e8
7 Signed-off-by: Jackie Huang <jackie.huang@windriver.com>
8 ---
9  sysinv/sysinv/sysinv/sysinv/agent/node.py | 28 +++++++++++++++++++++++
10  1 file changed, 28 insertions(+)
11
12 diff --git a/sysinv/sysinv/sysinv/sysinv/agent/node.py b/sysinv/sysinv/sysinv/sysinv/agent/node.py
13 index 4b75a11af..2a09b43cb 100644
14 --- a/sysinv/sysinv/sysinv/sysinv/agent/node.py
15 +++ b/sysinv/sysinv/sysinv/sysinv/agent/node.py
16 @@ -20,6 +20,8 @@ import re
17  from oslo_log import log as logging
18  import tsconfig.tsconfig as tsc
19  
20 +from sysinv.common import utils
21 +
22  LOG = logging.getLogger(__name__)
23  
24  # Defines the size of one kilobyte
25 @@ -223,8 +225,10 @@ class NodeOperator(object):
26  
27          # In the case topology not detected, hard-code structures
28          if self.num_nodes == 0:
29 +            cpu_model = self._get_cpu_model_lscpu()
30              n_sockets, n_cores, n_threads = (1, int(self.num_cpus), 1)
31              self.topology = {}
32 +            cpu = 0
33              for socket_id in range(n_sockets):
34                  self.topology[socket_id] = {}
35                  if socket_id not in sockets:
36 @@ -245,7 +249,11 @@ class NodeOperator(object):
37                              'thread': thread_id,
38                              'capabilities': {},
39                          }
40 +                        if cpu_model:
41 +                            attrs.update({'cpu_model': cpu_model})
42 +
43                          icpus.append(attrs)
44 +                        cpu += 1
45  
46              # Define Thread-Socket-Core order for logical cpu enumeration
47              cpu = 0
48 @@ -267,6 +275,8 @@ class NodeOperator(object):
49                              'thread': thread_id,
50                              'capabilities': {},
51                          }
52 +                        if cpu_model:
53 +                            attrs.update({'cpu_model': cpu_model})
54                          icpus.append(attrs)
55                          cpu += 1
56              self.num_nodes = len(list(self.topology.keys()))
57 @@ -275,6 +285,24 @@ class NodeOperator(object):
58  
59          return inumas, icpus
60  
61 +    def _get_cpu_model_lscpu(self):
62 +        """Get cpu model from lscpu
63 +
64 +        Returns:
65 +            string: the cpu model name
66 +        """
67 +        cpu_model = ""
68 +        output = utils.execute(
69 +            "lscpu | grep 'Model name' | cut -f 2- -d:|awk '{$1=$1}1'",
70 +            shell=True)
71 +
72 +        if isinstance(output, tuple):
73 +            cpu_model = output[0]
74 +            if cpu_model:
75 +                cpu_model = cpu_model.strip()
76 +                LOG.info("CPU Model name: {}".format(cpu_model))
77 +        return cpu_model
78 +
79      def _get_immediate_subdirs(self, dir):
80          return [name for name in listdir(dir)
81                  if os.path.isdir(join(dir, name))]
82 -- 
83 2.30.2
84