Exemplo n.º 1
0
    def test_instance_evacute_error(self, _mock_log, _mock_evacuate, _mock_get,
                                    mock_unlock, mock_lock,
                                    mock_enable_disable):
        task = host_failure.EvacuateInstancesTask(
            self.ctxt,
            self.novaclient,
            update_host_method=manager.update_host_method)

        def get_fake_server(server, status):
            fake_server = copy.deepcopy(server)
            setattr(fake_server, 'OS-EXT-SRV-ATTR:hypervisor_hostname',
                    self.instance_host)
            setattr(fake_server, 'OS-EXT-STS:vm_state', status)

            return fake_server

        failed_evacuation_instances = []
        fake_instance = self.fake_client.servers.create(
            id="1", host=self.instance_host, ha_enabled=True)

        _mock_get.side_effect = [
            get_fake_server(fake_instance, 'active'),
            get_fake_server(fake_instance, 'error'),
        ]
        task._evacuate_and_confirm(self.ctxt, fake_instance,
                                   self.instance_host,
                                   failed_evacuation_instances)
        self.assertIn(fake_instance.id, failed_evacuation_instances)
        expected_log = 'Failed to evacuate instance %s' % fake_instance.id
        _mock_log.warning.assert_called_once_with(expected_log)
Exemplo n.º 2
0
    def _evacuate_instances(self, instance_list, reserved_host=None):
        task = host_failure.EvacuateInstancesTask(self.novaclient)
        if reserved_host:
            with mock.patch.object(
                self.novaclient,
                    "enable_disable_service") as mock_enable_disable_service:
                instance_list = task.execute(self.ctxt, self.instance_host,
                                             instance_list['instance_list'],
                                             reserved_host=reserved_host)

            mock_enable_disable_service.assert_called_once_with(
                self.ctxt, reserved_host.name, enable=True)
        else:
            instance_list = task.execute(
                self.ctxt, self.instance_host, instance_list['instance_list'])

        return instance_list
Exemplo n.º 3
0
    def _evacuate_instances(self,
                            instance_list,
                            mock_enable_disable,
                            reserved_host=None):
        task = host_failure.EvacuateInstancesTask(self.novaclient)
        old_instance_list = copy.deepcopy(instance_list['instance_list'])

        if reserved_host:
            task.execute(self.ctxt,
                         self.instance_host,
                         instance_list['instance_list'],
                         reserved_host=reserved_host)

            self.assertTrue(mock_enable_disable.called)
        else:
            task.execute(self.ctxt, self.instance_host,
                         instance_list['instance_list'])

        # make sure instance is active and has different host
        self._verify_instance_evacuated(old_instance_list)
Exemplo n.º 4
0
    def test_evacuate_instances_task(self, _mock_novaclient):
        _mock_novaclient.return_value = self.fake_client

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

        # execute DisableComputeServiceTask
        self._test_disable_compute_service()

        # execute PrepareHAEnabledInstancesTask
        instance_list = self._test_instance_list()

        # execute EvacuateInstancesTask
        task = host_failure.EvacuateInstancesTask(self.novaclient)
        # mock evacuate method of FakeNovaClient to confirm that evacuate
        # method is called.
        with mock.patch.object(fakes.FakeNovaClient.ServerManager,
                               "evacuate") as mock_evacuate:
            task.execute(self.ctxt, self.instance_host,
                         instance_list['instance_list'])
            self.assertEqual(2, mock_evacuate.call_count)