summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-07-01 08:01:52 +0000
committerGerrit Code Review <review@openstack.org>2013-07-01 08:01:52 +0000
commitd376043bef1477a9aaab5037e8a38429cf5a6926 (patch)
tree32f9c92714bce966817ccba6706ccbb812d66f9d
parent52c8539e2dc6d055d4e5bdedffa5d05fec258eb7 (diff)
parent0946017e289cc865913980dbe199106d9b152cf3 (diff)
downloadnova-d376043bef1477a9aaab5037e8a38429cf5a6926.tar.gz
nova-d376043bef1477a9aaab5037e8a38429cf5a6926.tar.xz
nova-d376043bef1477a9aaab5037e8a38429cf5a6926.zip
Merge "Implement get_host_uptime for powervm driver"
-rw-r--r--nova/tests/virt/powervm/test_powervm.py22
-rw-r--r--nova/virt/powervm/command.py14
-rwxr-xr-xnova/virt/powervm/driver.py4
-rw-r--r--nova/virt/powervm/operator.py17
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 fffb77fc9..9d59e7ce4 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.