def set_and_assert_state(self, obj, state, check=True, run=True):
     command = Command.set_state([(obj, state)],
                                 "Unit test transition %s to %s" %
                                 (obj, state),
                                 run=run)
     log.debug("calling drain_progress")
     self.drain_progress()
     if check:
         if command:
             self.assertEqual(
                 Command.objects.get(pk=command.id).complete, True)
         try:
             return self.assertState(obj, state)
         except obj.__class__.DoesNotExist:
             return obj
     else:
         return command
예제 #2
0
    def _set_profile(self, host_id, profile):
        server_profile = get_object_or_404(ServerProfile, pk=profile)

        commands = []

        host = ManagedHost.objects.get(pk=host_id)

        if host.server_profile.name != profile:
            command = JobSchedulerClient.set_host_profile(host.id, server_profile.id)

            if command:
                commands.append(command)

            if server_profile.initial_state in host.get_available_states(host.state):
                commands.append(Command.set_state([(host, server_profile.initial_state)]))

        return map(dehydrate_command, commands)
 def set_state_delayed(self, obj_state_pairs):
     """Schedule some jobs without executing them"""
     Command.set_state(obj_state_pairs, "Unit test transition", run=False)