Skip to content

Commit d6f99b7

Browse files
author
Hironori Shiina
committed
Fix regular expression for uptime in hypervisor show
Hypervisor show command has a few bugs as follows. - It doesn't trim an extra whitespace in the head of uptime information. - It doesn't display uptime information when the number of user is 1. This patch fixes the regular expression to match uptime information. Change-Id: Ic2f7fd9a9274466717084a0886f95f78e98a9007 Closes-Bug: 1611809
1 parent d2273ec commit d6f99b7

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

openstackclient/compute/v2/hypervisor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ def take_action(self, parsed_args):
9898
# Extract data from uptime value
9999
# format: 0 up 0, 0 users, load average: 0, 0, 0
100100
# example: 17:37:14 up 2:33, 3 users, load average: 0.33, 0.36, 0.34
101-
m = re.match("(.+)\sup\s+(.+),\s+(.+)\susers,\s+load average:\s(.+)",
102-
uptime['uptime'])
101+
m = re.match(
102+
"\s*(.+)\sup\s+(.+),\s+(.+)\susers?,\s+load average:\s(.+)",
103+
uptime['uptime'])
103104
if m:
104105
hypervisor["host_time"] = m.group(1)
105106
hypervisor["uptime"] = m.group(2)

openstackclient/tests/unit/compute/v2/test_hypervisor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ def setUp(self):
159159
'free_disk_gb',
160160
'free_ram_mb',
161161
'host_ip',
162+
'host_time',
162163
'hypervisor_hostname',
163164
'hypervisor_type',
164165
'hypervisor_version',
165166
'id',
167+
'load_average',
166168
'local_gb',
167169
'local_gb_used',
168170
'memory_mb',
@@ -172,6 +174,8 @@ def setUp(self):
172174
'service_id',
173175
'state',
174176
'status',
177+
'uptime',
178+
'users',
175179
'vcpus',
176180
'vcpus_used',
177181
)
@@ -183,10 +187,12 @@ def setUp(self):
183187
50,
184188
1024,
185189
'192.168.0.10',
190+
'01:28:24',
186191
self.hypervisor.hypervisor_hostname,
187192
'QEMU',
188193
2004001,
189194
self.hypervisor.id,
195+
'0.94, 0.62, 0.50',
190196
50,
191197
0,
192198
1024,
@@ -196,6 +202,8 @@ def setUp(self):
196202
1,
197203
'up',
198204
'enabled',
205+
'3 days, 11:15',
206+
'1',
199207
4,
200208
0,
201209
)

0 commit comments

Comments
 (0)