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
tests
unit

@ -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)