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
This commit is contained in:
Hironori Shiina 2016-08-11 00:02:29 +09:00
parent d2273ecea5
commit d6f99b721d
2 changed files with 11 additions and 2 deletions
openstackclient
compute/v2
tests/unit/compute/v2

@ -98,8 +98,9 @@ class ShowHypervisor(command.ShowOne):
# Extract data from uptime value
# format: 0 up 0, 0 users, load average: 0, 0, 0
# example: 17:37:14 up 2:33, 3 users, load average: 0.33, 0.36, 0.34
m = re.match("(.+)\sup\s+(.+),\s+(.+)\susers,\s+load average:\s(.+)",
uptime['uptime'])
m = re.match(
"\s*(.+)\sup\s+(.+),\s+(.+)\susers?,\s+load average:\s(.+)",
uptime['uptime'])
if m:
hypervisor["host_time"] = m.group(1)
hypervisor["uptime"] = m.group(2)

@ -159,10 +159,12 @@ class TestHypervisorShow(TestHypervisor):
'free_disk_gb',
'free_ram_mb',
'host_ip',
'host_time',
'hypervisor_hostname',
'hypervisor_type',
'hypervisor_version',
'id',
'load_average',
'local_gb',
'local_gb_used',
'memory_mb',
@ -172,6 +174,8 @@ class TestHypervisorShow(TestHypervisor):
'service_id',
'state',
'status',
'uptime',
'users',
'vcpus',
'vcpus_used',
)
@ -183,10 +187,12 @@ class TestHypervisorShow(TestHypervisor):
50,
1024,
'192.168.0.10',
'01:28:24',
self.hypervisor.hypervisor_hostname,
'QEMU',
2004001,
self.hypervisor.id,
'0.94, 0.62, 0.50',
50,
0,
1024,
@ -196,6 +202,8 @@ class TestHypervisorShow(TestHypervisor):
1,
'up',
'enabled',
'3 days, 11:15',
'1',
4,
0,
)