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
This commit is contained in:
		
				
					committed by
					
						
						Dmitry Tantsur
					
				
			
			
				
	
			
			
			
						parent
						
							625f45d699
						
					
				
				
					commit
					808a4cbfa4
				
			@@ -714,6 +714,21 @@ class PowerBaremetalNode(command.Command):
 | 
			
		||||
            metavar='<node>',
 | 
			
		||||
            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='<power-timeout>',
 | 
			
		||||
            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='<node>',
 | 
			
		||||
            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='<power-timeout>',
 | 
			
		||||
            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):
 | 
			
		||||
 
 | 
			
		||||
@@ -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):
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,4 @@
 | 
			
		||||
---
 | 
			
		||||
features:
 | 
			
		||||
  - Enhances OSC to support soft reboot and soft power off with
 | 
			
		||||
    power control timeout option.
 | 
			
		||||
		Reference in New Issue
	
	Block a user