Exemple #1
0
 def _test_stop_instance(self):
     task = instance_failure.StopInstanceTask(self.novaclient)
     task.execute(self.ctxt, self.instance_id)
     # verify instance is stopped
     instance = self.novaclient.get_server(self.ctxt, self.instance_id)
     self.assertEqual('stopped',
                      getattr(instance, 'OS-EXT-STS:vm_state'))
    def test_instance_failure_flow_stop_failed(self, _mock_notify,
                                               _mock_novaclient):
        _mock_novaclient.return_value = self.fake_client

        # create test data
        server = self.fake_client.servers.create(self.instance_id,
                                                 host="fake-host",
                                                 ha_enabled=True)

        def fake_stop_server(context, uuid):
            # assume that while stopping instance goes into error state
            setattr(server, 'OS-EXT-STS:vm_state', "error")
            return server

        # test StopInstanceTask
        task = instance_failure.StopInstanceTask(self.ctxt, self.novaclient)
        with mock.patch.object(self.novaclient, 'stop_server',
                               fake_stop_server):
            self.assertRaises(exception.InstanceRecoveryFailureException,
                              task.execute, self.instance_id)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call('Stopping instance: ' + self.instance_id),
            mock.call('Failed to stop instance ' + self.instance_id, 1.0)
        ])
Exemple #3
0
    def test_instance_failure_flow_not_ha_enabled(self, _mock_novaclient):
        _mock_novaclient.return_value = self.fake_client

        # create test data
        self.fake_client.servers.create(self.instance_id, host="fake-host")

        # test StopInstanceTask
        task = instance_failure.StopInstanceTask(self.novaclient)
        self.assertRaises(
            exception.SkipInstanceRecoveryException, task.execute,
            self.ctxt, self.instance_id)
    def test_instance_failure_flow_not_ha_enabled(self, _mock_notify,
                                                  _mock_novaclient):
        _mock_novaclient.return_value = self.fake_client

        # create test data
        self.fake_client.servers.create(self.instance_id, host="fake-host")

        # test StopInstanceTask
        task = instance_failure.StopInstanceTask(self.ctxt, self.novaclient)
        self.assertRaises(exception.SkipInstanceRecoveryException,
                          task.execute, self.instance_id)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call(
                'Skipping recovery for instance: ' + self.instance_id +
                ' as it is not Ha_Enabled', 1.0)
        ])
    def test_instance_failure_flow_vm_in_paused_state(self, _mock_notify,
                                                      _mock_novaclient):
        _mock_novaclient.return_value = self.fake_client

        # create test data
        self.fake_client.servers.create(self.instance_id,
                                        host="fake-host",
                                        ha_enabled=True,
                                        vm_state="paused")

        # test StopInstanceTask
        task = instance_failure.StopInstanceTask(self.ctxt, self.novaclient)
        self.assertRaises(exception.IgnoreInstanceRecoveryException,
                          task.execute, self.instance_id)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call(
                "Recovery of instance '" + self.instance_id +
                "' is ignored as it is in 'paused' state.", 1.0)
        ])