Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in datapipeline definition serializer #705

Merged
merged 2 commits into from
Mar 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ CHANGELOG
Next Release (TBD)
==================

* bugfix:``aws datapipeline``: Fix issue when serializing
pipeline definitions containing list elements
(`issue 705 <https://github.com/aws/aws-cli/issues/705>`__)
* bugfix:``aws s3``: Fix issue when recursively removing keys
containing control characters
(`issue 675 <https://github.com/aws/aws-cli/issues/675>`__)
Expand Down
18 changes: 13 additions & 5 deletions awscli/customizations/datapipeline/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,25 @@ def definition_to_api(definition):
# with a 'key', 'stringValue'|'refValue'
fields = []
for key, value in sorted(element.items()):
field = {'key': key}
if isinstance(value, dict) and list(value.keys()) == ['ref']:
field['refValue'] = value['ref']
if isinstance(value, list):
for item in value:
fields.append(_convert_single_field(key, item))
else:
field['stringValue'] = value
fields.append(field)
fields.append(_convert_single_field(key, value))
api_object['fields'] = fields
api_elements.append(api_object)
return api_elements


def _convert_single_field(key, value):
field = {'key': key}
if isinstance(value, dict) and list(value.keys()) == ['ref']:
field['refValue'] = value['ref']
else:
field['stringValue'] = value
return field


def api_to_definition(api_response):
# When we're translating from api_response -> definition
# we have to be careful *not* to mutate the existing
Expand Down
39 changes: 38 additions & 1 deletion tests/unit/customizations/datapipeline/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# language governing permissions and limitations under the License.
from tests import unittest

import mock
from botocore.compat import OrderedDict, json

from awscli.customizations.datapipeline import translator
Expand Down Expand Up @@ -114,6 +113,44 @@ def test_missing_id_field(self):
with self.assertRaises(translator.PipelineDefinitionError):
translator.definition_to_api(definition)

def test_list_value_with_strings(self):
definition = self.load_def("""{"objects": [
{
"id" : "emrActivity",
"type" : "EmrActivity",
"name" : "Foo",
"step" : ["s3://foo1", "s3://foo2", "s3://foo3"]
}
]}""")
actual = translator.definition_to_api(definition)
api = [{"name": "Foo", "id": "emrActivity",
"fields": [
{"key": "step", "stringValue": "s3://foo1"},
{"key": "step", "stringValue": "s3://foo2"},
{"key": "step", "stringValue": "s3://foo3"},
{"key": "type", "stringValue": "EmrActivity"},
]}]
self.assertEqual(actual, api)

def test_value_with_refs(self):
definition = self.load_def("""{"objects": [
{
"id" : "emrActivity",
"type" : "EmrActivity",
"name" : "Foo",
"step" : ["s3://foo1", {"ref": "otherValue"}, "s3://foo3"]
}
]}""")
actual = translator.definition_to_api(definition)
api = [{"name": "Foo", "id": "emrActivity",
"fields": [
{"key": "step", "stringValue": "s3://foo1"},
{"key": "step", "refValue": "otherValue"},
{"key": "step", "stringValue": "s3://foo3"},
{"key": "type", "stringValue": "EmrActivity"},
]}]
self.assertEqual(actual, api)

# These tests check the API -> DF conversion.
def test_api_to_df(self):
api = [{"name": "S3ToS3Copy", "id": "S3ToS3Copy",
Expand Down