def test_host_failure_flow_no_instances_on_host(self, _mock_notify,
                                                    _mock_novaclient,
                                                    mock_unlock, mock_lock,
                                                    mock_enable_disable):
        _mock_novaclient.return_value = self.fake_client
        self.override_config("evacuate_all_instances", True, "host_failure")

        # execute DisableComputeServiceTask
        self._test_disable_compute_service(mock_enable_disable)

        # execute PrepareHAEnabledInstancesTask
        task = host_failure.PrepareHAEnabledInstancesTask(
            self.ctxt, self.novaclient)
        self.assertRaises(exception.SkipHostRecoveryException, task.execute,
                          self.instance_host)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call("Disabling compute service on host: 'fake-host'"),
            mock.call("Disabled compute service on host: 'fake-host'", 1.0),
            mock.call('Preparing instances for evacuation'),
            mock.call(
                "Total instances running on failed host 'fake-host' is 0"
                "", 0.3),
            mock.call("Total HA Enabled instances count: '0'", 0.6),
            mock.call("Total Non-HA Enabled instances count: '0'", 0.7),
            mock.call(
                "All instances (HA Enabled/Non-HA Enabled) should be "
                "considered for evacuation. Total count is: '0'", 0.8),
            mock.call(
                "Skipped host 'fake-host' recovery as no instances needs"
                " to be evacuated", 1.0)
        ])
    def test_host_failure_flow_ignore_error_instances_raise_skip_host_recovery(
            self, _mock_notify, _mock_novaclient, mock_unlock, mock_lock,
            mock_enable_disable):
        self.override_config("ignore_instances_in_error_state", True,
                             "host_failure")
        self.override_config("evacuate_all_instances", False, "host_failure")
        _mock_novaclient.return_value = self.fake_client

        # create ha_enabled test data
        self.fake_client.servers.create(id="1",
                                        host=self.instance_host,
                                        vm_state='error',
                                        ha_enabled=True)

        # execute PrepareHAEnabledInstancesTask
        task = host_failure.PrepareHAEnabledInstancesTask(
            self.ctxt, self.novaclient)
        self.assertRaises(exception.SkipHostRecoveryException, task.execute,
                          self.instance_host)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call('Preparing instances for evacuation'),
            mock.call(
                "Total instances running on failed host 'fake-host' is 1"
                "", 0.3),
            mock.call(
                "Ignoring recovery of HA_Enabled instance '1' as it is "
                "in 'error' state.", 0.4),
            mock.call("Total HA Enabled instances count: '0'", 0.6),
            mock.call(
                "Skipped host 'fake-host' recovery as no instances needs"
                " to be evacuated", 1.0)
        ])
    def test_host_failure_flow_no_ha_enabled_instances(self, _mock_notify,
                                                       _mock_novaclient,
                                                       mock_unlock, mock_lock,
                                                       mock_enable_disable):
        _mock_novaclient.return_value = self.fake_client

        # create test data
        self.fake_client.servers.create(id="1", host=self.instance_host)
        self.fake_client.servers.create(id="2", host=self.instance_host)

        # execute DisableComputeServiceTask
        self._test_disable_compute_service(mock_enable_disable)

        # execute PrepareHAEnabledInstancesTask
        task = host_failure.PrepareHAEnabledInstancesTask(
            self.ctxt, self.novaclient)
        self.assertRaises(exception.SkipHostRecoveryException, task.execute,
                          self.instance_host)

        # verify progress details
        _mock_notify.assert_has_calls([
            mock.call("Disabling compute service on host: 'fake-host'"),
            mock.call("Disabled compute service on host: 'fake-host'", 1.0),
            mock.call('Preparing instances for evacuation'),
            mock.call(
                "Total instances running on failed host 'fake-host' is 2"
                "", 0.3),
            mock.call("Total HA Enabled instances count: '0'", 0.6),
            mock.call(
                "Skipped host 'fake-host' recovery as no instances needs"
                " to be evacuated", 1.0)
        ])
Exemple #4
0
    def test_host_failure_flow_no_instances_on_host(self, _mock_novaclient):
        _mock_novaclient.return_value = self.fake_client
        self.override_config("evacuate_all_instances",
                             True, "host_failure")

        # execute DisableComputeServiceTask
        self._test_disable_compute_service()

        # execute PrepareHAEnabledInstancesTask
        task = host_failure.PrepareHAEnabledInstancesTask(self.novaclient)
        self.assertRaises(exception.SkipHostRecoveryException, task.execute,
                          self.ctxt, self.instance_host)
Exemple #5
0
    def _test_instance_list(self):
        task = host_failure.PrepareHAEnabledInstancesTask(self.novaclient)
        instance_list = task.execute(
            self.ctxt, self.instance_host)
        evacuate_all_instances = CONF.host_failure.evacuate_all_instances

        if evacuate_all_instances:
            self.assertEqual(len(self.fake_client.servers.list()),
                             len(instance_list['instance_list']))
        else:
            for instance in instance_list['instance_list']:
                self.assertTrue(instance.metadata.get('HA_Enabled', False))

        return instance_list
Exemple #6
0
    def test_host_failure_flow_no_ha_enabled_instances(self, _mock_novaclient):
        _mock_novaclient.return_value = self.fake_client

        # create test data
        self.fake_client.servers.create(id="1", host=self.instance_host)
        self.fake_client.servers.create(id="2", host=self.instance_host)

        # execute DisableComputeServiceTask
        self._test_disable_compute_service()

        # execute PrepareHAEnabledInstancesTask
        task = host_failure.PrepareHAEnabledInstancesTask(self.novaclient)
        self.assertRaises(exception.SkipHostRecoveryException, task.execute,
                          self.ctxt, self.instance_host)
    def _test_instance_list(self, instances_evacuation_count):
        task = host_failure.PrepareHAEnabledInstancesTask(self.novaclient)
        instance_list = task.execute(self.ctxt, self.instance_host)

        for instance in instance_list['instance_list']:
            if CONF.host_failure.ignore_instances_in_error_state:
                self.assertNotEqual("error",
                                    getattr(instance, "OS-EXT-STS:vm_state"))
            if not CONF.host_failure.evacuate_all_instances:
                self.assertTrue(instance.metadata.get('HA_Enabled', False))

        self.assertEqual(instances_evacuation_count,
                         len(instance_list['instance_list']))

        return instance_list
    def test_host_failure_flow_ignore_error_instances_raise_skip_host_recovery(
            self, _mock_novaclient, mock_unlock, mock_lock,
            mock_enable_disable):
        self.override_config("ignore_instances_in_error_state", True,
                             "host_failure")
        self.override_config("evacuate_all_instances", False, "host_failure")
        _mock_novaclient.return_value = self.fake_client

        # create ha_enabled test data
        self.fake_client.servers.create(id="1",
                                        host=self.instance_host,
                                        vm_state='error',
                                        ha_enabled=True)

        # execute PrepareHAEnabledInstancesTask
        task = host_failure.PrepareHAEnabledInstancesTask(self.novaclient)
        self.assertRaises(exception.SkipHostRecoveryException, task.execute,
                          self.ctxt, self.instance_host)
    def _test_instance_list(self, instances_evacuation_count):
        task = host_failure.PrepareHAEnabledInstancesTask(
            self.ctxt, self.novaclient)
        instances = task.execute(self.instance_host)
        instance_uuid_list = []
        for instance_id in instances['instance_list']:
            instance = self.novaclient.get_server(self.ctxt, instance_id)
            if CONF.host_failure.ignore_instances_in_error_state:
                self.assertNotEqual("error",
                                    getattr(instance, "OS-EXT-STS:vm_state"))
            if not CONF.host_failure.evacuate_all_instances:
                ha_enabled_key = (
                    CONF.host_failure.ha_enabled_instance_metadata_key)
                self.assertTrue(instance.metadata.get(ha_enabled_key, False))

            instance_uuid_list.append(instance.id)

        self.assertEqual(instances_evacuation_count,
                         len(instances['instance_list']))

        return {
            "instance_list": instance_uuid_list,
        }