Example #1
0
 def test_start_job_bad_payload(self):
     """ Negative test - Send a junk payload """
     payload = {}
     response = compute.create_job(environment.ATHERA_API_TEST_BASE_URL,
                                   environment.ATHERA_API_TEST_GROUP_ID,
                                   environment.ATHERA_API_TEST_TOKEN,
                                   payload)
     self.assertEqual(response.status_code, codes.bad_request)
Example #2
0
 def test_start_job_incomplete_payload(self):
     """ Negative test - Send a incomplete payload """
     payload = compute.make_job_request("", "", "", "",
                                        "incomplete_payload", 0, 0, 0, "",
                                        ())
     response = compute.create_job(environment.ATHERA_API_TEST_BASE_URL,
                                   environment.ATHERA_API_TEST_GROUP_ID,
                                   environment.ATHERA_API_TEST_TOKEN,
                                   payload)
     self.assertEqual(response.status_code, codes.bad_request)
Example #3
0
 def test_start_job_bad_payload(self):
     """ Negative test - Send a junk payload """
     payload = {}
     response = compute.create_job(
         environment.ATHERA_API_TEST_BASE_URL,
         environment.ATHERA_API_TEST_GROUP_ID,
         self.token,
         payload
     )
     self.assertEqual(response.status_code, codes.bad_request, "Start job with bad payload, unexpected status code {}".format(response.status_code))
Example #4
0
 def test_start_job_incomplete_payload(self):
     """ Negative test - Send a incomplete payload """
     payload = compute.make_job_request("", "", "", "", "incomplete_payload", 0, 0, 0, "", ())
     response = compute.create_job(
         environment.ATHERA_API_TEST_BASE_URL,
         environment.ATHERA_API_TEST_GROUP_ID,
         self.token,
         payload
     )
     self.assertEqual(response.status_code, codes.bad_request, "Start job with incomplete payload, unexpected status code {}".format(response.status_code))
Example #5
0
    def test_start_and_stop_job(self):
        """ Positive test """
        payload = compute.make_job_request(
            environment.ATHERA_API_TEST_USER_ID,
            environment.ATHERA_API_TEST_GROUP_ID,
            environment.ATHERA_API_TEST_COMPUTE_APP_ID,
            environment.ATHERA_API_TEST_COMPUTE_FILE_PATH,
            "test_start_and_stop_job_{}".format(hash(self)),
            1,
            2,
            1,
            environment.ATHERA_API_TEST_REGION,
            compute_arguments,
        )
        response = compute.create_job(
            environment.ATHERA_API_TEST_BASE_URL,
            environment.ATHERA_API_TEST_GROUP_ID,
            self.token,
            payload,
        )
        self.assertEqual(
            response.status_code, codes.ok,
            "Create job unexpected status code {}".format(
                response.status_code))
        job_data = response.json()
        job_id = job_data['id']

        # Wait until job status is CREATED
        error_msg = self.wait_for_job_status(
            job_id, ("CREATED", "PENDING", "COMPLETE"))
        self.assertIsNone(error_msg, error_msg)

        stop_job_attempts = 0
        while stop_job_attempts < 5:
            # Abort! Abort!
            response = compute.stop_job(environment.ATHERA_API_TEST_BASE_URL,
                                        environment.ATHERA_API_TEST_GROUP_ID,
                                        self.token, job_id)
            print("Stop job attempt {}, status code={}".format(
                stop_job_attempts, response.status_code))
            if response.status_code == codes.ok:
                break
            stop_job_attempts += 1
            time.sleep(5)

        # Wait until job status is CANCELED. This can take a while because if vm provisioning began, we have to wait for it to be READY to turn it off.
        error_msg = self.wait_for_job_status(job_id, ("CANCELED"), 600)
        self.assertIsNone(error_msg, error_msg)
Example #6
0
 def test_start_job_wrong_group(self):
     """ Negative test - check we cannot launch a compute job in someone else's group """
     payload = compute.make_job_request(
         environment.ATHERA_API_TEST_OTHER_USER_ID,
         environment.ATHERA_API_TEST_OTHER_GROUP_ID,
         environment.ATHERA_API_TEST_COMPUTE_APP_ID,
         environment.ATHERA_API_TEST_COMPUTE_FILE_PATH,
         "test_start_job_wrong_group_{}".format(hash(self)),
         1,
         2,
         1,
         environment.ATHERA_API_TEST_REGION,
         compute_arguments,
     )
     response = compute.create_job(
         environment.ATHERA_API_TEST_BASE_URL,
         environment.ATHERA_API_TEST_OTHER_GROUP_ID,
         environment.ATHERA_API_TEST_TOKEN, payload)
     self.assertEqual(response.status_code, codes.forbidden)
Example #7
0
    def test_start_job_and_get_part(self):
        """ Positive test - Nuke simply prints the help message and exits, ending the job (no need to stop) """
        payload = compute.make_job_request(
            environment.ATHERA_API_TEST_USER_ID,
            environment.ATHERA_API_TEST_GROUP_ID,
            environment.ATHERA_API_TEST_COMPUTE_APP_ID,
            environment.ATHERA_API_TEST_COMPUTE_FILE_PATH,
            "test_start_job_and_get_part_{}".format(hash(self)),
            1,
            2,
            1,
            environment.ATHERA_API_TEST_REGION,
            compute_arguments,
        )
        response = compute.create_job(
            environment.ATHERA_API_TEST_BASE_URL,
            environment.ATHERA_API_TEST_GROUP_ID,
            environment.ATHERA_API_TEST_TOKEN,
            payload,
        )
        self.assertEqual(response.status_code, codes.ok)
        data = response.json()
        job_id = data['id']

        # Can take some time for the parts to be assigned
        timeout = 600
        interval = 10
        while timeout > 0:
            response = compute.get_parts(
                environment.ATHERA_API_TEST_BASE_URL,
                environment.ATHERA_API_TEST_GROUP_ID,
                environment.ATHERA_API_TEST_TOKEN,
                environment.ATHERA_API_TEST_JOB_ID,
            )
            self.assertEqual(response.status_code, codes.ok)
            data = response.json()
            part_data = data['parts']
            print("{}s {}".format(timeout, len(part_data)))
            if len(part_data) > 0:
                break
            timeout -= interval
            time.sleep(interval)
        self.assertGreater(timeout, 0)
Example #8
0
def launch(logger, base_url, group_id, token):
    """
    Run a compute job in the supplied group_id context.

    Compute jobs need 'arguments' to go into the 'payload'. The payload is POSTED to the API to describe the job required.
    """
    # The JWT token contains a user id in its metadata. Lets extract it
    token_helper = common.TokenHelper(token)
    user_id = token_helper.get_user_id()
    logger.info("User ID {}".format(user_id))

    # Use the provided helper functions to create the app specific arguments.
    # These are template parameters which will be swapped for things like start frame, end frame, on multi-part jobs.
    args = compute_arguments.get_nuke_arguments(NUKE_SCRIPT_WRITE_NODE)

    # Make a random job name
    name = "example_" + str(time.time())

    region = common.select_region(logger,
                                  "Select a Region to run the compute job in")

    # Next, use the payload helper to build the job request body
    payload = compute.make_job_request(
        user_id, group_id, NUKE_COMPUTE_APP_ID,
        "/data/dropbox/{}".format(NUKE_SCRIPT_PATH_WITHIN_DROPBOX), name, 1,
        100, 1, region, args)

    # Now its time to actually launch it
    compute_response = compute.create_job(base_url, group_id, token, payload)
    if compute_response.status_code == 200:
        compute_dict = common.convert_response(compute_response)
        logger.error("Create job succeeded: {}".format(compute_dict['id']))
        return compute_dict['id']
    else:
        logger.error("Create job failed [{}] {}".format(
            compute_response.status_code, compute_response.text))
        return None