diff options
author | Matt Riedemann <mriedem@us.ibm.com> | 2013-06-15 13:10:26 -0700 |
---|---|---|
committer | Matt Riedemann <mriedem@us.ibm.com> | 2013-06-27 05:17:39 -0700 |
commit | 0946017e289cc865913980dbe199106d9b152cf3 (patch) | |
tree | 50361c5382a6edd9e6f0dbc5de628596097ca8d3 | |
parent | 82fab9a0110e0ed5e2410c6d02468ff3a0a2feda (diff) | |
download | nova-0946017e289cc865913980dbe199106d9b152cf3.tar.gz nova-0946017e289cc865913980dbe199106d9b152cf3.tar.xz nova-0946017e289cc865913980dbe199106d9b152cf3.zip |
Implement get_host_uptime for powervm driver
This patch implements the get_host_uptime method for the powervm driver
by calling the sysstat command on the backing hypervisor and returning
the parsed results.
Fixes bug 1191785
Change-Id: I67aaf6a5f5eb6b3a411ca9a0284d9a3016dd2947
-rw-r--r-- | nova/tests/virt/powervm/test_powervm.py | 22 | ||||
-rw-r--r-- | nova/virt/powervm/command.py | 14 | ||||
-rwxr-xr-x | nova/virt/powervm/driver.py | 4 | ||||
-rw-r--r-- | nova/virt/powervm/operator.py | 17 |
4 files changed, 55 insertions, 2 deletions
diff --git a/nova/tests/virt/powervm/test_powervm.py b/nova/tests/virt/powervm/test_powervm.py index 6628c23ea..fddd97a9d 100644 --- a/nova/tests/virt/powervm/test_powervm.py +++ b/nova/tests/virt/powervm/test_powervm.py @@ -173,7 +173,8 @@ class FakeBlockAdapter(powervm_blockdev.PowerVMLocalVolumeAdapter): def fake_get_powervm_operator(): - return FakeIVMOperator(None) + return FakeIVMOperator(common.Connection('fake_host', 'fake_user', + 'fake_password')) def create_instance(testcase): @@ -618,6 +619,25 @@ class PowerVMDriverTestCase(test.TestCase): self.assertEquals(host_stats['supported_instances'][0][1], "powervm") self.assertEquals(host_stats['supported_instances'][0][2], "hvm") + def test_get_host_uptime(self): + """ + Tests that the get_host_uptime method issues the proper sysstat command + and parses the output correctly. + """ + exp_cmd = "ioscli sysstat -short fake_user" + output = [("02:54PM up 24 days, 5:41, 1 user, " + "load average: 0.06, 0.03, 0.02")] + + fake_op = self.powervm_connection._powervm + self.mox.StubOutWithMock(fake_op._operator, 'run_vios_command') + fake_op._operator.run_vios_command(exp_cmd).AndReturn(output) + + self.mox.ReplayAll() + + # the host parameter isn't used so we just pass None + uptime = self.powervm_connection.get_host_uptime(None) + self.assertEquals("02:54PM up 24 days 5:41", uptime) + class PowerVMDriverLparTestCase(test.TestCase): """Unit tests for PowerVM connection calls.""" diff --git a/nova/virt/powervm/command.py b/nova/virt/powervm/command.py index eec7fc2d3..aa82650cc 100644 --- a/nova/virt/powervm/command.py +++ b/nova/virt/powervm/command.py @@ -1,6 +1,6 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2012 IBM Corp. +# Copyright 2013 IBM Corp. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -68,6 +68,15 @@ class BaseCommand(object): def chsyscfg(self, args=''): return 'chsyscfg %s' % args + def sysstat(self, args=''): + """ + Returns a string of the formatted sysstat command to run. + Typically this command should be run with the -short option + and a User operand should be provided to narrow the results. + :returns: string - formatted sysstat command + """ + return 'sysstat %s' % args + class IVMCommand(BaseCommand): @@ -97,3 +106,6 @@ class IVMCommand(BaseCommand): def hostname(self, args=''): return 'ioscli ' + BaseCommand.hostname(self, args=args) + + def sysstat(self, args=''): + return 'ioscli ' + BaseCommand.sysstat(self, args=args) diff --git a/nova/virt/powervm/driver.py b/nova/virt/powervm/driver.py index e49bbb209..a97f7d011 100755 --- a/nova/virt/powervm/driver.py +++ b/nova/virt/powervm/driver.py @@ -90,6 +90,10 @@ class PowerVMDriver(driver.ComputeDriver): """Return currently known host stats.""" return self._powervm.get_host_stats(refresh=refresh) + def get_host_uptime(self, host): + """Returns the result of calling "uptime" on the target host.""" + return self._powervm.get_host_uptime(host) + def plug_vifs(self, instance, network_info): pass diff --git a/nova/virt/powervm/operator.py b/nova/virt/powervm/operator.py index 18cba0ba2..02addb54d 100644 --- a/nova/virt/powervm/operator.py +++ b/nova/virt/powervm/operator.py @@ -169,6 +169,10 @@ class PowerVMOperator(object): self._host_stats = data + def get_host_uptime(self, host): + """Returns the result of calling "uptime" on the target host.""" + return self._operator.get_host_uptime(host) + def spawn(self, context, instance, image_id, network_info): def _create_image(context, instance, image_id): """Fetch image from glance and copy it to the remote system.""" @@ -626,6 +630,19 @@ class BaseOperator(object): return {'total_mem': int(total_mem), 'avail_mem': int(avail_mem)} + def get_host_uptime(self, host): + """ + Get host uptime. + :returns: string - amount of time since last system startup + """ + # The output of the command is like this: + # "02:54PM up 24 days, 5:41, 1 user, load average: 0.06, 0.03, 0.02" + cmd = self.command.sysstat('-short %s' % self.connection_data.username) + output = self.run_vios_command(cmd) + # parse the sysstat output so we just return the uptime + system_time, uptime = output[0].split(',')[0:2] + return system_time + uptime + def get_cpu_info(self): """Get CPU info. |