Handle IPMI transient failures better.

Sometimes, IPMI "power status" doesn't return either "on" or "off".
When this happens, the IPMI driver shouldn't assume what the state is,
and the baremetal driver shouldn't assume that NOSTATE means SHUTDOWN.

This patch also improves the doc strings for the IPMI driver.

Fix bug 1178378.

Change-Id: I54a5e6309f68ab8e5601e65039366d7d87c03478
This commit is contained in:
Devananda van der Veen
2013-05-13 19:13:36 -07:00
parent a8eb94a639
commit f328137523
2 changed files with 47 additions and 2 deletions

View File

@@ -22,6 +22,7 @@
from oslo.config import cfg
from nova.compute import power_state
from nova import exception
from nova import test
from nova.tests.baremetal.db import base as bm_db_base
@@ -327,3 +328,36 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
self.driver.destroy(**node2['destroy_params'])
self.assertEqual([], self.driver.list_instances())
def test_get_info_no_such_node(self):
node = self._create_node()
self.assertRaises(exception.InstanceNotFound,
self.driver.get_info,
node['instance'])
def test_get_info_ok(self):
node = self._create_node()
db.bm_node_associate_and_update(self.context, node['node']['uuid'],
{'instance_uuid': node['instance']['uuid'],
'instance_name': node['instance']['hostname'],
'task_state': baremetal_states.ACTIVE})
res = self.driver.get_info(node['instance'])
self.assertEqual(res['state'], power_state.RUNNING)
def test_get_info_with_defunct_pm(self):
# test fix for bug 1178378
node = self._create_node()
db.bm_node_associate_and_update(self.context, node['node']['uuid'],
{'instance_uuid': node['instance']['uuid'],
'instance_name': node['instance']['hostname'],
'task_state': baremetal_states.ACTIVE})
# fake the power manager and don't get a power state
self.mox.StubOutWithMock(fake.FakePowerManager, 'is_power_on')
fake.FakePowerManager.is_power_on().AndReturn(None)
self.mox.ReplayAll()
res = self.driver.get_info(node['instance'])
# prior to the fix, returned power_state was SHUTDOWN
self.assertEqual(res['state'], power_state.NOSTATE)
self.mox.VerifyAll()

View File

@@ -85,13 +85,24 @@ class BareMetalIPMITestCase(test.TestCase):
self.ipmi._exec_ipmitool('A B C')
self.mox.VerifyAll()
def test_is_power(self):
def test_is_power_on_ok(self):
self.mox.StubOutWithMock(self.ipmi, '_exec_ipmitool')
self.ipmi._exec_ipmitool("power status").AndReturn(
["Chassis Power is on\n"])
self.mox.ReplayAll()
self.ipmi._is_power("on")
res = self.ipmi.is_power_on()
self.assertEqual(res, True)
self.mox.VerifyAll()
def test_is_power_no_answer(self):
self.mox.StubOutWithMock(self.ipmi, '_exec_ipmitool')
self.ipmi._exec_ipmitool("power status").AndReturn(
["Fake reply\n"])
self.mox.ReplayAll()
res = self.ipmi.is_power_on()
self.assertEqual(res, None)
self.mox.VerifyAll()
def test_power_already_on(self):