def host_delete(context, host_uuid): count = model_query(context, models.Host).filter_by( uuid=host_uuid).soft_delete(synchronize_session=False) if count == 0: raise exception.HostNotFound(id=host_uuid)
def host_get_by_id(context, host_id): query = model_query(context, models.Host).filter_by(id=host_id).options( joinedload('failover_segment')) result = query.first() if not result: raise exception.HostNotFound(id=host_id) return result
def test_save_host_not_found(self, mock_host_update): mock_host_update.side_effect = exception.HostNotFound(name="foo-host") host_object = host.Host(context=self.context) host_object.name = "foo-host" host_object.id = 123 host_object.uuid = uuidsentinel.fake_host self.assertRaises(exception.HostNotFound, host_object.save)
def test_update_with_non_exising_host(self, mock_update_host): test_data = {"host": {"name": "host11"}} mock_update_host.side_effect = exception.HostNotFound(id="2") self.assertRaises(exc.HTTPNotFound, self.controller.update, self.req, uuidsentinel.fake_segment1, "2", body=test_data)
def test_destroy_host_not_found(self, mock_host_destroy, mock_notify_about_host_api): mock_host_destroy.side_effect = exception.HostNotFound(id=123) host_obj = self._host_create_attributes() host_obj.id = 123 self.assertRaises(exception.HostNotFound, host_obj.destroy) action = fields.EventNotificationAction.HOST_DELETE phase_start = fields.EventNotificationPhase.START notify_calls = [ mock.call(self.context, host_obj, action=action, phase=phase_start) ] mock_notify_about_host_api.assert_has_calls(notify_calls)
def get_host(self, context, segment_uuid, host_uuid): """Get a host by id""" objects.FailoverSegment.get_by_uuid(context, segment_uuid) if uuidutils.is_uuid_like(host_uuid): LOG.debug("Fetching host by " "UUID", host_uuid=host_uuid) host = objects.Host.get_by_uuid(context, host_uuid) else: LOG.debug("Failed to fetch host by uuid %s", host_uuid) raise exception.HostNotFound(id=host_uuid) return host
def _host_get_by_uuid(context, host_uuid, segment_uuid=None): query = model_query(context, models.Host).filter_by(uuid=host_uuid).options( joinedload('failover_segment')) if segment_uuid: query = query.filter_by(failover_segment_id=segment_uuid) result = query.first() if not result: if segment_uuid: raise exception.HostNotFoundUnderFailoverSegment( host_uuid=host_uuid, segment_uuid=segment_uuid) else: raise exception.HostNotFound(id=host_uuid) return result
def test_save_host_not_found(self, mock_host_update, mock_notify_about_host_api): mock_host_update.side_effect = exception.HostNotFound(id="foo-host") host_object = host.Host(context=self.context) host_object.name = "foo-host" host_object.id = 123 host_object.uuid = uuidsentinel.fake_host self.assertRaises(exception.HostNotFound, host_object.save) action = fields.EventNotificationAction.HOST_UPDATE phase_start = fields.EventNotificationPhase.START notify_calls = [ mock.call(self.context, host_object, action=action, phase=phase_start)] mock_notify_about_host_api.assert_has_calls(notify_calls)
def test_delete_host_not_found(self, mock_delete): mock_delete.side_effect = exception.HostNotFound(id="2") self.assertRaises(exc.HTTPNotFound, self.controller.delete, self.req, uuidsentinel.fake_segment1, uuidsentinel.fake_host_3)
def test_show_with_non_existing_id(self, mock_get_host): mock_get_host.side_effect = exception.HostNotFound(id="2") self.assertRaises(exc.HTTPNotFound, self.controller.show, self.req, uuidsentinel.fake_segment1, "2")
def test_destroy_host_not_found(self, mock_host_destroy): mock_host_destroy.side_effect = exception.HostNotFound(id=123) host_obj = self._host_create_attributes() host_obj.id = 123 self.assertRaises(exception.HostNotFound, host_obj.destroy)