Better EMR coverage and boto3 request/response handling

This revision includes:

- A handler for requests for which content-type is JSON (from boto3).

- A decorator (generate_boto3_response) to convert XML responses to
  JSON (for boto3). This way, existing response templates for boto can
  be shared for generating boto3 response.

- Utility class/functions to use botocore's service specification data
  (accessible under botocore.data) for type casting, from query
  parameters to Python objects and XML to JSON.

- Updates to response handlers/models to cover more EMR end points and
  mockable parameters
This commit is contained in:
Taro Sato 2016-09-21 20:59:19 -07:00
commit 7cd404808b
10 changed files with 2399 additions and 841 deletions

View file

@ -1,19 +1,25 @@
from __future__ import unicode_literals
import random
import string
import six
def random_job_id(size=13):
def random_id(size=13):
chars = list(range(10)) + list(string.ascii_uppercase)
job_tag = ''.join(six.text_type(random.choice(chars)) for x in range(size))
return 'j-{0}'.format(job_tag)
return ''.join(six.text_type(random.choice(chars)) for x in range(size))
def random_cluster_id(size=13):
return 'j-{0}'.format(random_id())
def random_step_id(size=13):
return 's-{0}'.format(random_id())
def random_instance_group_id(size=13):
chars = list(range(10)) + list(string.ascii_uppercase)
job_tag = ''.join(six.text_type(random.choice(chars)) for x in range(size))
return 'i-{0}'.format(job_tag)
return 'i-{0}'.format(random_id())
def tags_from_query_string(querystring_dict):
@ -30,3 +36,18 @@ def tags_from_query_string(querystring_dict):
else:
response_values[tag_key] = None
return response_values
def steps_from_query_string(querystring_dict):
steps = []
for step in querystring_dict:
step['jar'] = step.pop('hadoop_jar_step._jar')
step['properties'] = dict((o['Key'], o['Value']) for o in step.get('properties', []))
step['args'] = []
idx = 1
keyfmt = 'hadoop_jar_step._args.member.{0}'
while keyfmt.format(idx) in step:
step['args'].append(step.pop(keyfmt.format(idx)))
idx += 1
steps.append(step)
return steps