Add shutdown method to all power drivers
* Added shutdown command to libvirt and impi drivers. Change-Id: I984724ca582f8d000dff1afb5e0867eda42b7442
This commit is contained in:
parent
34edf10456
commit
5c9665dfb8
|
@ -165,6 +165,14 @@ class NodeCollection(object):
|
|||
LOG.info('Reset nodes: %s', self)
|
||||
self.cloud_management.power_manager.reset(self.hosts)
|
||||
|
||||
@public
|
||||
def shutdown(self):
|
||||
"""Shutdown all nodes gracefully
|
||||
|
||||
"""
|
||||
LOG.info('Shutdown nodes: %s', self)
|
||||
self.cloud_management.power_manager.shutdown(self.hosts)
|
||||
|
||||
def snapshot(self, snapshot_name, suspend=True):
|
||||
"""Create snapshot for all nodes
|
||||
|
||||
|
|
|
@ -25,19 +25,23 @@ class PowerDriver(base_driver.BaseDriver):
|
|||
|
||||
@abc.abstractmethod
|
||||
def supports(host):
|
||||
pass
|
||||
"""Returns True if host is supported by the power driver"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def poweroff(self, host):
|
||||
pass
|
||||
"""Power off host abruptly"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def poweron(self, host):
|
||||
pass
|
||||
"""Power on host"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def reset(self, host):
|
||||
pass
|
||||
"""Reset host"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def shutdown(self, host):
|
||||
"""Graceful shutdown host"""
|
||||
|
||||
def snapshot(self, host, snapshot_name, suspend=True):
|
||||
raise NotImplementedError
|
||||
|
@ -88,6 +92,9 @@ class PowerManager(object):
|
|||
def reset(self, hosts):
|
||||
self._run_command('reset', hosts)
|
||||
|
||||
def shutdown(self, hosts):
|
||||
self._run_command('shutdown', hosts)
|
||||
|
||||
def snapshot(self, hosts, snapshot_name, suspend=True):
|
||||
self._run_command('snapshot', hosts,
|
||||
snapshot_name=snapshot_name, suspend=suspend)
|
||||
|
|
|
@ -134,3 +134,8 @@ class IPMIDriver(power_management.PowerDriver):
|
|||
self._run_set_power_cmd(host.mac, cmd='boot')
|
||||
# NOTE(astudenov): This command does not wait for node to boot
|
||||
LOG.info('Node reset: %s', host.mac)
|
||||
|
||||
def shutdown(self, host):
|
||||
LOG.debug('Shutdown Node with MAC address: %s', host.mac)
|
||||
self._run_set_power_cmd(host.mac, cmd='shutdown', expected_state='off')
|
||||
LOG.info('Node is off: %s', host.mac)
|
||||
|
|
|
@ -101,6 +101,12 @@ class LibvirtDriver(power_management.PowerDriver):
|
|||
domain.reset()
|
||||
LOG.info('Domain reset: %s', host.mac)
|
||||
|
||||
def shutdown(self, host):
|
||||
LOG.debug('Shutdown domain with MAC address: %s', host.mac)
|
||||
domain = self._find_domain_by_mac_address(host.mac)
|
||||
domain.shutdown()
|
||||
LOG.info('Domain is off: %s', host.mac)
|
||||
|
||||
def snapshot(self, host, snapshot_name, suspend):
|
||||
LOG.debug('Create snapshot "%s" for domain with MAC address: %s',
|
||||
snapshot_name, host.mac)
|
||||
|
|
|
@ -188,6 +188,10 @@ class NodeCollectionTestCase(test.TestCase):
|
|||
self.node_collection.reset()
|
||||
self.mock_power_manager.reset.assert_called_once_with(self.hosts)
|
||||
|
||||
def test_shutdown(self):
|
||||
self.node_collection.shutdown()
|
||||
self.mock_power_manager.shutdown.assert_called_once_with(self.hosts)
|
||||
|
||||
def test_reboot(self):
|
||||
self.node_collection.reboot()
|
||||
self.mock_cloud_management.execute_on_cloud.assert_called_once_with(
|
||||
|
|
|
@ -59,6 +59,12 @@ class PowerManagerTestCase(test.TestCase):
|
|||
self.dummy_driver1.reset.called_once_with(host=self.hosts[0])
|
||||
self.dummy_driver2.reset.called_once_with(host=self.hosts[1])
|
||||
|
||||
def test_shutdown(self):
|
||||
self.pm.shutdown(self.hosts)
|
||||
|
||||
self.dummy_driver1.shutdown.called_once_with(host=self.hosts[0])
|
||||
self.dummy_driver2.shutdown.called_once_with(host=self.hosts[1])
|
||||
|
||||
def test_snapshot(self):
|
||||
self.pm.snapshot(self.hosts, 'snap1', suspend=False)
|
||||
|
||||
|
|
|
@ -85,12 +85,15 @@ class IPMIDriverTestCase(test.TestCase):
|
|||
'00:00:00:00:00:00', 'off', expected_state='off')
|
||||
|
||||
@mock.patch('os_faults.drivers.ipmi.IPMIDriver._run_set_power_cmd')
|
||||
@ddt.data(('poweroff', 'off'), ('poweron', 'on'), ('reset', 'boot'))
|
||||
@ddt.data(('poweroff', 'off', 'off'),
|
||||
('poweron', 'on', 'on'),
|
||||
('reset', 'boot'),
|
||||
('shutdown', 'shutdown', 'off'))
|
||||
def test_driver_actions(self, actions, mock__run_set_power_cmd):
|
||||
getattr(self.driver, actions[0])(self.host)
|
||||
if actions[0] in ('poweroff', 'poweron'):
|
||||
if len(actions) == 3:
|
||||
mock__run_set_power_cmd.assert_called_once_with(
|
||||
'00:00:00:00:00:00', cmd=actions[1], expected_state=actions[1])
|
||||
'00:00:00:00:00:00', cmd=actions[1], expected_state=actions[2])
|
||||
else:
|
||||
mock__run_set_power_cmd.assert_called_once_with(
|
||||
'00:00:00:00:00:00', cmd=actions[1])
|
||||
|
|
|
@ -90,7 +90,7 @@ class LibvirtDriverTestCase(test.TestCase):
|
|||
|
||||
@mock.patch(DRIVER_PATH + '.LibvirtDriver._find_domain_by_mac_address')
|
||||
@ddt.data(('poweroff', 'destroy'), ('poweron', 'create'),
|
||||
('reset', 'reset'))
|
||||
('reset', 'reset'), ('shutdown', 'shutdown'))
|
||||
def test_driver_actions(self, actions, mock__find_domain_by_mac_address):
|
||||
getattr(self.driver, actions[0])(self.host)
|
||||
domain = mock__find_domain_by_mac_address.return_value
|
||||
|
|
Loading…
Reference in New Issue