Exemplo n.º 1
0
 def _cast_to_cells(self, context, instance, method, *args, **kwargs):
     instance_uuid = instance['uuid']
     cell_name = instance['cell_name']
     if not cell_name:
         raise exception.InstanceUnknownCell(instance_uuid=instance_uuid)
     self.cells_rpcapi.cast_compute_api_method(context, cell_name, method,
                                               instance_uuid, *args,
                                               **kwargs)
Exemplo n.º 2
0
 def action_events_get(self, ctxt, instance, action_id):
     if not instance['cell_name']:
         raise exception.InstanceUnknownCell(instance_uuid=instance['uuid'])
     return self.call(ctxt,
                      self.make_msg('action_events_get',
                                    cell_name=instance['cell_name'],
                                    action_id=action_id),
                      version='1.5')
Exemplo n.º 3
0
 def action_events_get(self, ctxt, instance, action_id):
     if not instance['cell_name']:
         raise exception.InstanceUnknownCell(instance_uuid=instance['uuid'])
     cctxt = self.client.prepare(version='1.5')
     return cctxt.call(ctxt,
                       'action_events_get',
                       cell_name=instance['cell_name'],
                       action_id=action_id)
Exemplo n.º 4
0
 def action_get_by_request_id(self, ctxt, instance, request_id):
     if not instance['cell_name']:
         raise exception.InstanceUnknownCell(instance_uuid=instance['uuid'])
     return self.call(ctxt, self.make_msg('action_get_by_request_id',
                                          cell_name=instance['cell_name'],
                                          instance_uuid=instance['uuid'],
                                          request_id=request_id),
                      version='1.5')
Exemplo n.º 5
0
 def test_soft_delete_instance_no_cell(self):
     cells_rpcapi = self.compute_api.cells_rpcapi
     self.mox.StubOutWithMock(cells_rpcapi, 'instance_delete_everywhere')
     inst = self._create_fake_instance_obj()
     exc = exception.InstanceUnknownCell(instance_uuid=inst['uuid'])
     cells_rpcapi.instance_delete_everywhere(self.context, inst, 'soft')
     self.mox.ReplayAll()
     self.compute_api.soft_delete(self.context, inst)
Exemplo n.º 6
0
 def action_get_by_request_id(self, ctxt, instance, request_id):
     if not instance['cell_name']:
         raise exception.InstanceUnknownCell(instance_uuid=instance['uuid'])
     cctxt = self.client.prepare(version='1.5')
     return cctxt.call(ctxt, 'action_get_by_request_id',
                       cell_name=instance['cell_name'],
                       instance_uuid=instance['uuid'],
                       request_id=request_id)
Exemplo n.º 7
0
 def validate_console_port(self, ctxt, instance_uuid, console_port,
                           console_type):
     """Validate console port with child cell compute node."""
     instance = objects.Instance.get_by_uuid(ctxt, instance_uuid)
     if not instance.cell_name:
         raise exception.InstanceUnknownCell(instance_uuid=instance_uuid)
     response = self.msg_runner.validate_console_port(ctxt,
             instance.cell_name, instance_uuid, console_port,
             console_type)
     return response.value_or_raise()
Exemplo n.º 8
0
 def _validate_cell(self, instance, method):
     cell_name = instance['cell_name']
     if not cell_name:
         raise exception.InstanceUnknownCell(instance_uuid=instance['uuid'])
     if self._cell_read_only(cell_name):
         raise exception.InstanceInvalidState(
             attr="vm_state",
             instance_uuid=instance['uuid'],
             state="temporary_readonly",
             method=method)
Exemplo n.º 9
0
 def test_delete_instance_no_cell(self):
     cells_rpcapi = self.compute_api.cells_rpcapi
     self.mox.StubOutWithMock(cells_rpcapi, 'instance_delete_everywhere')
     self.mox.StubOutWithMock(self.compute_api, '_cast_to_cells')
     inst = self._create_fake_instance()
     exc = exception.InstanceUnknownCell(instance_uuid=inst['uuid'])
     self.compute_api._cast_to_cells(self.context, inst,
                                     'delete').AndRaise(exc)
     cells_rpcapi.instance_delete_everywhere(self.context, inst, 'hard')
     self.mox.ReplayAll()
     self.compute_api.delete(self.context, inst)
Exemplo n.º 10
0
class DeferredDeleteExtensionTestV21(test.NoDBTestCase):
    ext_ver = dd_v21.DeferredDeleteController

    def setUp(self):
        super(DeferredDeleteExtensionTestV21, self).setUp()
        self.fake_input_dict = {}
        self.fake_uuid = 'fake_uuid'
        self.fake_context = context.RequestContext('fake', 'fake')
        self.fake_req = FakeRequest(self.fake_context)
        self.extension = self.ext_ver()

    @mock.patch.object(compute_api.API, 'get')
    @mock.patch.object(compute_api.API, 'force_delete')
    def test_force_delete(self, mock_force_delete, mock_get):
        instance = fake_instance.fake_instance_obj(
            self.fake_req.environ['nova.context'])
        mock_get.return_value = instance

        res = self.extension._force_delete(self.fake_req, self.fake_uuid,
                                           self.fake_input_dict)
        # NOTE: on v2.1, http status code is set as wsgi_code of API
        # method instead of status_int in a response object.
        if isinstance(self.extension, dd_v21.DeferredDeleteController):
            status_int = self.extension._force_delete.wsgi_code
        else:
            status_int = res.status_int
        self.assertEqual(202, status_int)

        mock_get.assert_called_once_with(self.fake_context,
                                         self.fake_uuid,
                                         expected_attrs=None,
                                         cell_down_support=False)
        mock_force_delete.assert_called_once_with(self.fake_context, instance)

    @mock.patch.object(compute_api.API, 'get')
    def test_force_delete_instance_not_found(self, mock_get):
        mock_get.side_effect = exception.InstanceNotFound(
            instance_id='instance-0000')

        self.assertRaises(webob.exc.HTTPNotFound, self.extension._force_delete,
                          self.fake_req, self.fake_uuid, self.fake_input_dict)

        mock_get.assert_called_once_with(self.fake_context,
                                         self.fake_uuid,
                                         expected_attrs=None,
                                         cell_down_support=False)

    @mock.patch.object(compute_api.API, 'get')
    @mock.patch.object(
        compute_api.API,
        'force_delete',
        side_effect=exception.InstanceIsLocked(instance_uuid='fake_uuid'))
    def test_force_delete_instance_locked(self, mock_force_delete, mock_get):
        req = fakes.HTTPRequest.blank('/v2/fake/servers/fake_uuid/action')
        ex = self.assertRaises(webob.exc.HTTPConflict,
                               self.extension._force_delete, req, 'fake_uuid',
                               '')
        self.assertIn('Instance fake_uuid is locked', ex.explanation)

    @mock.patch.object(compute_api.API, 'get')
    @mock.patch.object(
        compute_api.API,
        'force_delete',
        side_effect=exception.InstanceNotFound(instance_id='fake_uuid'))
    def test_force_delete_instance_notfound(self, mock_force_delete, mock_get):
        req = fakes.HTTPRequest.blank('/v2/fake/servers/fake_uuid/action')
        ex = self.assertRaises(webob.exc.HTTPNotFound,
                               self.extension._force_delete, req, 'fake_uuid',
                               '')
        self.assertIn('Instance fake_uuid could not be found', ex.explanation)

    @mock.patch.object(compute_api.API, 'get')
    @mock.patch.object(
        compute_api.API,
        'force_delete',
        side_effect=exception.InstanceUnknownCell(instance_uuid='fake_uuid'))
    def test_force_delete_instance_cellunknown(self, mock_force_delete,
                                               mock_get):
        req = fakes.HTTPRequest.blank('/v2/fake/servers/fake_uuid/action')
        ex = self.assertRaises(webob.exc.HTTPNotFound,
                               self.extension._force_delete, req, 'fake_uuid',
                               '')
        self.assertIn('Cell is not known for instance fake_uuid',
                      ex.explanation)

    @mock.patch.object(compute_api.API, 'get')
    @mock.patch.object(compute_api.API, 'restore')
    def test_restore(self, mock_restore, mock_get):
        instance = fake_instance.fake_instance_obj(
            self.fake_req.environ['nova.context'])
        mock_get.return_value = instance

        res = self.extension._restore(self.fake_req, self.fake_uuid,
                                      self.fake_input_dict)
        # NOTE: on v2.1, http status code is set as wsgi_code of API
        # method instead of status_int in a response object.
        if isinstance(self.extension, dd_v21.DeferredDeleteController):
            status_int = self.extension._restore.wsgi_code
        else:
            status_int = res.status_int
        self.assertEqual(202, status_int)

        mock_get.assert_called_once_with(self.fake_context,
                                         self.fake_uuid,
                                         expected_attrs=None,
                                         cell_down_support=False)
        mock_restore.assert_called_once_with(self.fake_context, instance)

    @mock.patch.object(compute_api.API, 'get')
    def test_restore_instance_not_found(self, mock_get):
        mock_get.side_effect = exception.InstanceNotFound(
            instance_id='instance-0000')

        self.assertRaises(webob.exc.HTTPNotFound, self.extension._restore,
                          self.fake_req, self.fake_uuid, self.fake_input_dict)

        mock_get.assert_called_once_with(self.fake_context,
                                         self.fake_uuid,
                                         expected_attrs=None,
                                         cell_down_support=False)

    @mock.patch.object(compute_api.API, 'get')
    @mock.patch.object(compute_api.API, 'restore')
    def test_restore_raises_conflict_on_invalid_state(self, mock_restore,
                                                      mock_get):
        instance = fake_instance.fake_instance_obj(
            self.fake_req.environ['nova.context'])
        mock_get.return_value = instance
        mock_restore.side_effect = exception.InstanceInvalidState(
            attr='fake_attr',
            state='fake_state',
            method='fake_method',
            instance_uuid='fake')

        self.assertRaises(webob.exc.HTTPConflict, self.extension._restore,
                          self.fake_req, self.fake_uuid, self.fake_input_dict)

        mock_get.assert_called_once_with(self.fake_context,
                                         self.fake_uuid,
                                         expected_attrs=None,
                                         cell_down_support=False)

        mock_restore.assert_called_once_with(self.fake_context, instance)