Fix IPMI unit test to cover different platforms
As execution engine is singleton, test for the 2nd platform still use the 1st platform's engine and its initialization doesn't run at all. Reset engine init flag after test for each platform to fix it. Change-Id: I73b69892b8ee429ed649741419554076379c093c Closes-Bug: #1414903
This commit is contained in:
parent
889cc51483
commit
4b37a36fbf
@ -31,6 +31,12 @@ class TestNodeManager(base.BaseTestCase):
|
||||
utils.execute = mock.Mock(side_effect=fake_utils.execute_with_nm)
|
||||
self.nm = node_manager.NodeManager()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
# reset inited to force an initialization of singleton for next test
|
||||
node_manager.NodeManager()._inited = False
|
||||
super(TestNodeManager, cls).tearDownClass()
|
||||
|
||||
def test_read_power_all(self):
|
||||
power = self.nm.read_power_all()
|
||||
|
||||
@ -54,7 +60,6 @@ class TestNodeManager(base.BaseTestCase):
|
||||
min_val = node_manager._hex(temperature["Minimum_value"])
|
||||
cur_val = node_manager._hex(temperature["Current_value"])
|
||||
|
||||
self.assertTrue(self.nm.nm_support)
|
||||
# see ipmi_test_data.py for raw data
|
||||
self.assertEqual(23, cur_val)
|
||||
self.assertEqual(22, min_val)
|
||||
@ -69,11 +74,17 @@ class TestNonNodeManager(base.BaseTestCase):
|
||||
|
||||
utils.execute = mock.Mock(side_effect=fake_utils.execute_without_nm)
|
||||
self.nm = node_manager.NodeManager()
|
||||
self.nm.nm_support = False
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
# reset inited to force an initialization of singleton for next test
|
||||
node_manager.NodeManager()._inited = False
|
||||
super(TestNonNodeManager, cls).tearDownClass()
|
||||
|
||||
def test_read_power_all(self):
|
||||
power = self.nm.read_power_all()
|
||||
|
||||
self.assertFalse(self.nm.nm_support)
|
||||
# Non-Node Manager platform return empty data
|
||||
self.assertEqual({}, power)
|
||||
|
||||
|
@ -15,13 +15,12 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslotest import base
|
||||
|
||||
from ceilometer.ipmi.platform import ipmi_sensor
|
||||
from ceilometer.tests.ipmi.platform import fake_utils
|
||||
from ceilometer import utils
|
||||
|
||||
from oslotest import base
|
||||
|
||||
|
||||
class TestIPMISensor(base.BaseTestCase):
|
||||
|
||||
@ -31,9 +30,16 @@ class TestIPMISensor(base.BaseTestCase):
|
||||
utils.execute = mock.Mock(side_effect=fake_utils.execute_with_nm)
|
||||
self.ipmi = ipmi_sensor.IPMISensor()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
# reset inited to force an initialization of singleton for next test
|
||||
ipmi_sensor.IPMISensor()._inited = False
|
||||
super(TestIPMISensor, cls).tearDownClass()
|
||||
|
||||
def test_read_sensor_temperature(self):
|
||||
sensors = self.ipmi.read_sensor_any('Temperature')
|
||||
|
||||
self.assertTrue(self.ipmi.ipmi_support)
|
||||
# only temperature data returned.
|
||||
self.assertIn('Temperature', sensors)
|
||||
self.assertEqual(1, len(sensors))
|
||||
@ -91,11 +97,17 @@ class TestNonIPMISensor(base.BaseTestCase):
|
||||
|
||||
utils.execute = mock.Mock(side_effect=fake_utils.execute_without_ipmi)
|
||||
self.ipmi = ipmi_sensor.IPMISensor()
|
||||
self.ipmi.ipmi_support = False
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
# reset inited to force an initialization of singleton for next test
|
||||
ipmi_sensor.IPMISensor()._inited = False
|
||||
super(TestNonIPMISensor, cls).tearDownClass()
|
||||
|
||||
def test_read_sensor_temperature(self):
|
||||
sensors = self.ipmi.read_sensor_any('Temperature')
|
||||
|
||||
self.assertFalse(self.ipmi.ipmi_support)
|
||||
# Non-IPMI platform return empty data
|
||||
self.assertEqual({}, sensors)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user