Exemplo n.º 1
0
    def test_reboot_ok(self):
        self.mox.StubOutWithMock(ipmi, '_power_off')
        self.mox.StubOutWithMock(ipmi, '_power_on')

        ipmi._power_off(self.info)
        ipmi._power_on(self.info).AndReturn(states.POWER_ON)
        self.mox.ReplayAll()

        with task_manager.acquire([self.node['uuid']]) as task:
            self.driver.power.reboot(task, self.node)

        self.mox.VerifyAll()
Exemplo n.º 2
0
    def test_set_power_on_ok(self):
        self.config(ipmi_power_retry=0)
        self.mox.StubOutWithMock(ipmi, '_power_on')
        self.mox.StubOutWithMock(ipmi, '_power_off')

        ipmi._power_on(self.info).AndReturn(states.POWER_ON)
        self.mox.ReplayAll()

        with task_manager.acquire([self.node['uuid']]) as task:
            self.driver.power.set_power_state(
                    task, self.node, states.POWER_ON)
        self.mox.VerifyAll()
Exemplo n.º 3
0
    def test_reboot_fail(self):
        self.mox.StubOutWithMock(ipmi, '_power_off')
        self.mox.StubOutWithMock(ipmi, '_power_on')

        ipmi._power_off(self.info)
        ipmi._power_on(self.info).AndReturn(states.ERROR)
        self.mox.ReplayAll()

        with task_manager.acquire([self.node['uuid']]) as task:
            self.assertRaises(exception.PowerStateFailure,
                    self.driver.power.reboot,
                    task,
                    self.node)

        self.mox.VerifyAll()
Exemplo n.º 4
0
    def test_set_power_on_fail(self):
        self.config(ipmi_power_retry=0)

        self.mox.StubOutWithMock(ipmi, '_power_on')
        self.mox.StubOutWithMock(ipmi, '_power_off')

        ipmi._power_on(self.info).AndReturn(states.ERROR)
        self.mox.ReplayAll()

        with task_manager.acquire([self.node['uuid']]) as task:
            self.assertRaises(exception.PowerStateFailure,
                    self.driver.power.set_power_state,
                    task,
                    self.node,
                    states.POWER_ON)
        self.mox.VerifyAll()
Exemplo n.º 5
0
    def test__power_on_max_retries(self):
        self.config(retry_timeout=2, group='ipmi')

        def side_effect(driver_info, command):
            resp_dict = {
                "power status": ["Chassis Power is off\n", None],
                "power on": [None, None]
            }
            return resp_dict.get(command, ["Bad\n", None])

        with mock.patch.object(ipmi, '_exec_ipmitool',
                               autospec=True) as mock_exec:
            mock_exec.side_effect = side_effect

            expected = [
                mock.call(self.info, "power status"),
                mock.call(self.info, "power on"),
                mock.call(self.info, "power status"),
                mock.call(self.info, "power status"),
                mock.call(self.info, "power status")
            ]

            state = ipmi._power_on(self.info)

            self.assertEqual(mock_exec.call_args_list, expected)
            self.assertEqual(state, states.ERROR)
Exemplo n.º 6
0
    def test__power_on_max_retries(self, sleep_mock, mock_exec):
        self.config(retry_timeout=2, group='ipmi')

        def side_effect(driver_info, command):
            resp_dict = {"power status": ["Chassis Power is off\n", None],
                         "power on": [None, None]}
            return resp_dict.get(command, ["Bad\n", None])

        mock_exec.side_effect = side_effect

        expected = [mock.call(self.info, "power on"),
                    mock.call(self.info, "power status"),
                    mock.call(self.info, "power status")]

        state = ipmi._power_on(self.info)

        self.assertEqual(mock_exec.call_args_list, expected)
        self.assertEqual(states.ERROR, state)
Exemplo n.º 7
0
    def test__power_on_max_retries(self):
        self.config(ipmi_power_retry=2)
        self.mox.StubOutWithMock(ipmi, '_exec_ipmitool')

        ipmi._exec_ipmitool(self.info, "power status").AndReturn(
                ["Chassis Power is off\n", None])
        ipmi._exec_ipmitool(self.info, "power on").AndReturn([None, None])
        ipmi._exec_ipmitool(self.info, "power status").AndReturn(
                ["Chassis Power is off\n", None])
        ipmi._exec_ipmitool(self.info, "power on").AndReturn([None, None])
        ipmi._exec_ipmitool(self.info, "power status").AndReturn(
                ["Chassis Power is off\n", None])
        ipmi._exec_ipmitool(self.info, "power on").AndReturn([None, None])
        ipmi._exec_ipmitool(self.info, "power status").AndReturn(
                ["Chassis Power is off\n", None])
        self.mox.ReplayAll()

        state = ipmi._power_on(self.info)
        self.mox.VerifyAll()
        self.assertEqual(state, states.ERROR)
Exemplo n.º 8
0
    def test__power_on_max_retries(self):
        self.config(retry_timeout=2, group='ipmi')

        def side_effect(driver_info, command):
            resp_dict = {"power status": ["Chassis Power is off\n", None],
                         "power on": [None, None]}
            return resp_dict.get(command, ["Bad\n", None])

        with mock.patch.object(ipmi, '_exec_ipmitool',
                               autospec=True) as mock_exec:
            mock_exec.side_effect = side_effect

            expected = [mock.call(self.info, "power status"),
                        mock.call(self.info, "power on"),
                        mock.call(self.info, "power status"),
                        mock.call(self.info, "power status"),
                        mock.call(self.info, "power status")]

            state = ipmi._power_on(self.info)

            self.assertEqual(mock_exec.call_args_list, expected)
            self.assertEqual(state, states.ERROR)
Exemplo n.º 9
0
    def test__power_on_max_retries(self, sleep_mock, mock_exec, mock_sleep):
        self.config(retry_timeout=2, group='ipmi')

        def side_effect(driver_info, command):
            resp_dict = {
                "power status": ["Chassis Power is off\n", None],
                "power on": [None, None]
            }
            return resp_dict.get(command, ["Bad\n", None])

        mock_exec.side_effect = side_effect

        expected = [
            mock.call(self.info, "power on"),
            mock.call(self.info, "power status"),
            mock.call(self.info, "power status")
        ]

        state = ipmi._power_on(self.info)

        self.assertEqual(mock_exec.call_args_list, expected)
        self.assertEqual(states.ERROR, state)