Esempio n. 1
0
    def _verify_reboot(self, soft=True):
        actions = [{"soft_reboot" if soft else "hard_reboot": 5}]
        fake_server = mock.MagicMock()
        scenario = servers.BootAndBounceServer(self.context)

        scenario._reboot_server = mock.MagicMock()
        scenario._soft_reboot_server = mock.MagicMock()
        scenario._boot_server = mock.MagicMock(return_value=fake_server)
        scenario._delete_server = mock.MagicMock()
        scenario.generate_random_name = mock.MagicMock(return_value="name")

        scenario.run("img", 1, actions=actions)

        scenario._boot_server.assert_called_once_with("img", 1)
        server_calls = []
        for i in range(5):
            server_calls.append(mock.call(fake_server))
        if soft:
            self.assertEqual(5, scenario._soft_reboot_server.call_count,
                             "Reboot not called 5 times")
            scenario._soft_reboot_server.assert_has_calls(server_calls)
        else:
            self.assertEqual(5, scenario._reboot_server.call_count,
                             "Reboot not called 5 times")
            scenario._reboot_server.assert_has_calls(server_calls)
        scenario._delete_server.assert_called_once_with(fake_server,
                                                        force=False)
Esempio n. 2
0
    def test_validate_actions_additional(self):
        scenario = servers.BootAndBounceServer(self.context)

        self.assertRaises(rally_exceptions.InvalidConfigException,
                          scenario.run,
                          1,
                          1,
                          actions=[{
                              "not_existing_action": "no"
                          }])
        # NOTE: next should fail because actions parameter is a just a
        # dictionary, not an array of dictionaries
        self.assertRaises(rally_exceptions.InvalidConfigException,
                          scenario.run,
                          1,
                          1,
                          actions={"hard_reboot": 1})
Esempio n. 3
0
    def test_action_pair(self, action_pair, methods, nof_calls):
        actions = [{action_pair: nof_calls}]
        fake_server = mock.MagicMock()
        scenario = servers.BootAndBounceServer(self.context)
        scenario._boot_server = mock.MagicMock(return_value=fake_server)
        scenario._delete_server = mock.MagicMock()
        scenario.generate_random_name = mock.MagicMock(return_value="name")
        for method in methods:
            setattr(scenario, method, mock.MagicMock())

        scenario.run("img", 1, actions=actions)

        scenario._boot_server.assert_called_once_with("img", 1)
        server_calls = []
        for i in range(nof_calls):
            server_calls.append(mock.call(fake_server))
        for method in methods:
            mocked_method = getattr(scenario, method)
            self.assertEqual(nof_calls, mocked_method.call_count,
                             "%s not called %d times" % (method, nof_calls))
            mocked_method.assert_has_calls(server_calls)
        scenario._delete_server.assert_called_once_with(fake_server,
                                                        force=False)
Esempio n. 4
0
    def test_validate_actions(self, action):
        scenario = servers.BootAndBounceServer(self.context)

        self.assertRaises(rally_exceptions.InvalidConfigException,
                          scenario.run,
                          1,
                          1,
                          actions=[{
                              action: "no"
                          }])
        self.assertRaises(rally_exceptions.InvalidConfigException,
                          scenario.run,
                          1,
                          1,
                          actions=[{
                              action: -1
                          }])
        self.assertRaises(rally_exceptions.InvalidConfigException,
                          scenario.run,
                          1,
                          1,
                          actions=[{
                              action: 0
                          }])
Esempio n. 5
0
    def test_multiple_bounce_actions(self):
        actions = [{
            "hard_reboot": 5
        }, {
            "stop_start": 8
        }, {
            "rescue_unrescue": 3
        }, {
            "pause_unpause": 2
        }, {
            "suspend_resume": 4
        }, {
            "lock_unlock": 6
        }, {
            "shelve_unshelve": 7
        }]
        fake_server = mock.MagicMock()
        scenario = servers.BootAndBounceServer(self.context)

        scenario._boot_server = mock.MagicMock(return_value=fake_server)
        scenario._delete_server = mock.MagicMock()
        scenario._reboot_server = mock.MagicMock()
        scenario._stop_and_start_server = mock.MagicMock()
        scenario._rescue_and_unrescue_server = mock.MagicMock()
        scenario._pause_and_unpause_server = mock.MagicMock()
        scenario._suspend_and_resume_server = mock.MagicMock()
        scenario._lock_and_unlock_server = mock.MagicMock()
        scenario._shelve_and_unshelve_server = mock.MagicMock()
        scenario.generate_random_name = mock.MagicMock(return_value="name")

        scenario.run("img", 1, actions=actions)
        scenario._boot_server.assert_called_once_with("img", 1)
        server_calls = []
        for i in range(5):
            server_calls.append(mock.call(fake_server))
        self.assertEqual(5, scenario._reboot_server.call_count,
                         "Reboot not called 5 times")
        scenario._reboot_server.assert_has_calls(server_calls)
        server_calls = []
        for i in range(8):
            server_calls.append(mock.call(fake_server))
        self.assertEqual(8, scenario._stop_and_start_server.call_count,
                         "Stop/Start not called 8 times")
        scenario._stop_and_start_server.assert_has_calls(server_calls)
        server_calls = []
        for i in range(3):
            server_calls.append(mock.call(fake_server))
        self.assertEqual(3, scenario._rescue_and_unrescue_server.call_count,
                         "Rescue/Unrescue not called 3 times")
        scenario._rescue_and_unrescue_server.assert_has_calls(server_calls)
        server_calls = []
        for i in range(2):
            server_calls.append(mock.call(fake_server))
        self.assertEqual(2, scenario._pause_and_unpause_server.call_count,
                         "Pause/Unpause not called 2 times")
        scenario._pause_and_unpause_server.assert_has_calls(server_calls)
        server_calls = []
        for i in range(4):
            server_calls.append(mock.call(fake_server))
        self.assertEqual(4, scenario._suspend_and_resume_server.call_count,
                         "Suspend/Resume not called 4 times")
        scenario._suspend_and_resume_server.assert_has_calls(server_calls)
        server_calls = []
        for i in range(6):
            server_calls.append(mock.call(fake_server))
        self.assertEqual(6, scenario._lock_and_unlock_server.call_count,
                         "Lock/Unlock not called 6 times")
        scenario._lock_and_unlock_server.assert_has_calls(server_calls)
        server_calls = []
        for i in range(7):
            server_calls.append(mock.call(fake_server))
        self.assertEqual(7, scenario._shelve_and_unshelve_server.call_count,
                         "Shelve/Unshelve not called 7 times")
        scenario._shelve_and_unshelve_server.assert_has_calls(server_calls)
        scenario._delete_server.assert_called_once_with(fake_server,
                                                        force=False)