Ejemplo n.º 1
0
 def obj_delete(self, bundle, **kwargs):
     obj = self.obj_get(bundle, **kwargs)
     try:
         if obj.immutable_state and 'forgotten' in obj.states:
             command = Command.set_state([(obj, 'forgotten')])
         else:
             command = Command.set_state([(obj, 'removed')])
     except SchedulingError, e:
         raise custom_response(self, bundle.request, http.HttpBadRequest,
                               {'__all__': e.message})
 def obj_delete(self, bundle, **kwargs):
     obj = self.obj_get(bundle, **kwargs)
     try:
         if obj.immutable_state and "forgotten" in obj.states:
             command = Command.set_state([(obj, "forgotten")])
         else:
             command = Command.set_state([(obj, "removed")])
     except SchedulingError as e:
         raise custom_response(self, bundle.request, http.HttpBadRequest,
                               {"__all__": e.message})
     raise custom_response(self, bundle.request, http.HttpAccepted,
                           {"command": dehydrate_command(command)})
    def test_onejob(self):
        # Our self.host is initially lnet_up
        self.assertEqual(
            LNetConfiguration.objects.get(pk=self.lnet_configuration.pk).state,
            "lnet_up")

        # This tests a state transition which is done by a single job
        command_id = JobSchedulerClient.command_run_jobs(
            [{
                "class_name": "UpdateDevicesJob",
                "args": {
                    "hosts": [api.get_resource_uri(self.host)]
                }
            }],
            "Test single job action",
        )
        self.drain_progress()

        self.assertEqual(Command.objects.get(pk=command_id).complete, True)
        self.assertEqual(Command.objects.get(pk=command_id).jobs.count(), 1)

        # Test that if I try to run the same again I get None
        command = Command.set_state([(freshen(self.lnet_configuration),
                                      "lnet_up")])
        self.assertEqual(command, None)
Ejemplo n.º 4
0
    def obj_update(self, bundle, request, **kwargs):
        bundle.obj = self.cached_obj_get(
            request=request, **self.remove_api_resource_names(kwargs))

        stateful_object = bundle.obj

        dry_run = bundle.data.get('dry_run', False)
        if 'state' in bundle.data:
            new_state = bundle.data['state']

            if dry_run:
                # FIXME: should this be a GET to something like /foo/transitions/from/to/
                #        to get information about that transition?
                if stateful_object.state == new_state:
                    report = []
                else:
                    report = JobSchedulerClient.get_transition_consequences(
                        stateful_object, new_state)
                raise custom_response(self, request, http.HttpResponse, report)
            else:
                try:
                    command = Command.set_state([(stateful_object, new_state)])
                except SchedulingError, e:
                    raise custom_response(self, request, http.HttpBadRequest,
                                          {'state': e.message})

                if command:
                    raise custom_response(
                        self, request, http.HttpAccepted,
                        {'command': dehydrate_command(command)})
                else:
                    raise custom_response(self, request, http.HttpNoContent,
                                          None)
    def test_2steps(self):
        self.assertEqual(LNetConfiguration.objects.get(pk = self.lnet_configuration.pk).state, 'lnet_up')

        # This tests a state transition which requires two jobs acting on the same object
        # lnet_up -> lnet_down issues an StopLNetJob and a UnloadLNetJob
        command_id = Command.set_state([(freshen(self.lnet_configuration), 'lnet_unloaded')]).id
        self.drain_progress()

        self.assertEqual(LNetConfiguration.objects.get(pk = self.lnet_configuration.pk).state, 'lnet_unloaded')
        self.assertEqual(Command.objects.get(pk = command_id).complete, True)
        self.assertEqual(Command.objects.get(pk = command_id).jobs.count(), 2)
    def obj_update(self, bundle, **kwargs):
        self.is_valid(bundle)

        if bundle.errors:
            raise ImmediateHttpResponse(response=self.error_response(
                bundle.request, bundle.errors[self._meta.resource_name]))

        request = bundle.request
        bundle.obj = self.cached_obj_get(
            bundle, **self.remove_api_resource_names(kwargs))

        stateful_object = bundle.obj

        dry_run = bundle.data.get("dry_run", False)
        if "state" in bundle.data:
            new_state = bundle.data["state"]

            if dry_run:
                # FIXME: should this be a GET to something like /foo/transitions/from/to/
                #        to get information about that transition?
                if stateful_object.state == new_state:
                    report = []
                else:
                    report = JobSchedulerClient.get_transition_consequences(
                        stateful_object, new_state)
                raise custom_response(self, request, http.HttpResponse, report)
            else:
                try:
                    command = Command.set_state([(stateful_object, new_state)])
                except SchedulingError as e:
                    raise custom_response(self, request, http.HttpBadRequest,
                                          {"state": e.message})

                if command:
                    raise custom_response(
                        self, request, http.HttpAccepted,
                        {"command": dehydrate_command(command)})
                else:
                    raise custom_response(self, request, http.HttpNoContent,
                                          None)
        else:
            return bundle