From 808a4cbfa46f741858d666878d7552c7a508766e Mon Sep 17 00:00:00 2001 From: Naohiro Tamura Date: Fri, 19 Aug 2016 14:54:50 +0900 Subject: [PATCH] Support soft reboot and soft power off with timeout for OSC This patch enhances OSC to support soft reboot and soft power off with power control timeout option. Partial-Bug: #1526226 Change-Id: Ibf63d55754610769bf201f1766ddb6f9a0ce8971 --- ironicclient/osc/v1/baremetal_node.py | 39 +++++- .../tests/unit/osc/v1/test_baremetal_node.py | 113 +++++++++++++++++- ...soft-reboot-poweroff-121b8043567f54a9.yaml | 4 + 3 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/osc-soft-reboot-poweroff-121b8043567f54a9.yaml diff --git a/ironicclient/osc/v1/baremetal_node.py b/ironicclient/osc/v1/baremetal_node.py index b5a611f7a..34954370b 100644 --- a/ironicclient/osc/v1/baremetal_node.py +++ b/ironicclient/osc/v1/baremetal_node.py @@ -714,6 +714,21 @@ class PowerBaremetalNode(command.Command): metavar='', help="Name or UUID of the node." ) + parser.add_argument( + '--soft', + dest='soft', + action='store_true', + default=False, + help=_("Request graceful power-off.") + ) + parser.add_argument( + '--power-timeout', + metavar='', + default=None, + type=int, + help=_("Timeout (in seconds, positive integer) to wait for the " + "target power state before erroring out.") + ) return parser def take_action(self, parsed_args): @@ -722,7 +737,8 @@ class PowerBaremetalNode(command.Command): baremetal_client = self.app.client_manager.baremetal baremetal_client.node.set_power_state( - parsed_args.node, parsed_args.power_state) + parsed_args.node, parsed_args.power_state, parsed_args.soft, + timeout=parsed_args.power_timeout) class ProvideBaremetalNode(ProvisionStateBaremetalNode): @@ -743,7 +759,23 @@ class RebootBaremetalNode(command.Command): parser.add_argument( 'node', metavar='', - help="Name or UUID of the node.") + help="Name or UUID of the node." + ) + parser.add_argument( + '--soft', + dest='soft', + action='store_true', + default=False, + help=_("Request Graceful reboot.") + ) + parser.add_argument( + '--power-timeout', + metavar='', + default=None, + type=int, + help=_("Timeout (in seconds, positive integer) to wait for the " + "target power state before erroring out.") + ) return parser @@ -753,7 +785,8 @@ class RebootBaremetalNode(command.Command): baremetal_client = self.app.client_manager.baremetal baremetal_client.node.set_power_state( - parsed_args.node, 'reboot') + parsed_args.node, 'reboot', parsed_args.soft, + timeout=parsed_args.power_timeout) class RebuildBaremetalNode(ProvisionStateBaremetalNode): diff --git a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py index f519f0b08..942e9e87c 100644 --- a/ironicclient/tests/unit/osc/v1/test_baremetal_node.py +++ b/ironicclient/tests/unit/osc/v1/test_baremetal_node.py @@ -893,26 +893,86 @@ class TestBaremetalPower(TestBaremetal): def test_baremetal_power_on(self): arglist = ['on', 'node_uuid'] verifylist = [('power_state', 'on'), - ('node', 'node_uuid')] + ('node', 'node_uuid'), + ('soft', False), + ('power_timeout', None)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) self.baremetal_mock.node.set_power_state.assert_called_once_with( - 'node_uuid', 'on') + 'node_uuid', 'on', False, timeout=None) + + def test_baremetal_power_on_timeout(self): + arglist = ['on', 'node_uuid', '--power-timeout', '2'] + verifylist = [('power_state', 'on'), + ('node', 'node_uuid'), + ('soft', False), + ('power_timeout', 2)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_power_state.assert_called_once_with( + 'node_uuid', 'on', False, timeout=2) def test_baremetal_power_off(self): arglist = ['off', 'node_uuid'] verifylist = [('power_state', 'off'), - ('node', 'node_uuid')] + ('node', 'node_uuid'), + ('soft', False), + ('power_timeout', None)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) self.baremetal_mock.node.set_power_state.assert_called_once_with( - 'node_uuid', 'off') + 'node_uuid', 'off', False, timeout=None) + + def test_baremetal_power_off_timeout(self): + arglist = ['off', 'node_uuid', '--power-timeout', '2'] + verifylist = [('power_state', 'off'), + ('node', 'node_uuid'), + ('soft', False), + ('power_timeout', 2)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_power_state.assert_called_once_with( + 'node_uuid', 'off', False, timeout=2) + + def test_baremetal_soft_power_off(self): + arglist = ['off', 'node_uuid', '--soft'] + verifylist = [('power_state', 'off'), + ('node', 'node_uuid'), + ('soft', True), + ('power_timeout', None)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_power_state.assert_called_once_with( + 'node_uuid', 'off', True, timeout=None) + + def test_baremetal_soft_power_off_timeout(self): + arglist = ['off', 'node_uuid', '--soft', '--power-timeout', '2'] + verifylist = [('power_state', 'off'), + ('node', 'node_uuid'), + ('soft', True), + ('power_timeout', 2)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_power_state.assert_called_once_with( + 'node_uuid', 'off', True, timeout=2) class TestDeployBaremetalProvisionState(TestBaremetal): @@ -969,14 +1029,55 @@ class TestBaremetalReboot(TestBaremetal): def test_baremetal_reboot_uuid_only(self): arglist = ['node_uuid'] - verifylist = [('node', 'node_uuid')] + verifylist = [('node', 'node_uuid'), + ('soft', False), + ('power_timeout', None)] parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) self.baremetal_mock.node.set_power_state.assert_called_once_with( - 'node_uuid', 'reboot') + 'node_uuid', 'reboot', False, timeout=None) + + def test_baremetal_reboot_timeout(self): + arglist = ['node_uuid', '--power-timeout', '2'] + verifylist = [('node', 'node_uuid'), + ('soft', False), + ('power_timeout', 2)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_power_state.assert_called_once_with( + 'node_uuid', 'reboot', False, timeout=2) + + def test_baremetal_soft_reboot(self): + arglist = ['node_uuid', '--soft'] + verifylist = [('node', 'node_uuid'), + ('soft', True), + ('power_timeout', None)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_power_state.assert_called_once_with( + 'node_uuid', 'reboot', True, timeout=None) + + def test_baremetal_soft_reboot_timeout(self): + arglist = ['node_uuid', '--soft', '--power-timeout', '2'] + verifylist = [('node', 'node_uuid'), + ('soft', True), + ('power_timeout', 2)] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.baremetal_mock.node.set_power_state.assert_called_once_with( + 'node_uuid', 'reboot', True, timeout=2) class TestBaremetalSet(TestBaremetal): diff --git a/releasenotes/notes/osc-soft-reboot-poweroff-121b8043567f54a9.yaml b/releasenotes/notes/osc-soft-reboot-poweroff-121b8043567f54a9.yaml new file mode 100644 index 000000000..ab38a152c --- /dev/null +++ b/releasenotes/notes/osc-soft-reboot-poweroff-121b8043567f54a9.yaml @@ -0,0 +1,4 @@ +--- +features: + - Enhances OSC to support soft reboot and soft power off with + power control timeout option.