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
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user