Skip to content

Commit

Permalink
Merge pull request #84 from nasa/jk/CUMULUS-2751-bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jkovarik authored Jan 7, 2022
2 parents 422f2ff + 064847b commit 2091a63
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 37 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [v2.0.1] 2022-01-07

### Fixed

- **CUMULUS-2751**
- Fix regression in 2.0.0 that caused tasks without `task_config` defined cause CMA to fail

## [v2.0.0] 2021-12-17

### BREAKING CHANGES
Expand Down
12 changes: 12 additions & 0 deletions examples/messages/basic_no_config.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"cumulus_meta": {
"message_source": "local",
"id": "id-1234"
},
"meta": {
"foo": "bar"
},
"payload": {
"anykey": "anyvalue"
}
}
13 changes: 13 additions & 0 deletions examples/messages/basic_no_config.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"cumulus_meta": {
"message_source": "local",
"id": "id-1234"
},
"meta": {
"foo": "bar"
},
"payload": {
"input": { "anykey": "anyvalue" }
},
"exception": "None"
}
9 changes: 9 additions & 0 deletions examples/schemas/examples-messages-no-config.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"properties": {
"input": {
"type": "object"
}
},
"additionalProperties": false
}

2 changes: 1 addition & 1 deletion message_adapter/cumulus_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def load_config(event):

if 'task_config' in event:
return event['task_config']
return None
return {}

def load_remote_event(event):
"""
Expand Down
4 changes: 2 additions & 2 deletions message_adapter/message_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def load_nested_event(self, event):
final_payload = resolve_input(event, config)
response = {'input': final_payload}
self.__validate_json(final_payload, 'input')
self.__validate_json(final_config, 'config')
if final_config is not None:
if final_config:
self.__validate_json(final_config, 'config')
response['config'] = final_config
if 'cumulus_message' in config:
response['messageConfig'] = config['cumulus_message']
Expand Down
2 changes: 1 addition & 1 deletion message_adapter/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = 'v2.0.0'
__version__ = 'v2.0.1'
82 changes: 49 additions & 33 deletions tests/test-program.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,26 @@ def write_streaming_input(self, command, proc_input, p_stdin):
p_stdin.write('<EOC>\n'.encode('utf-8'))
p_stdin.flush()

def transform_messages_streaming(self, testcase, context=None):
def transform_messages_streaming(self, params):
"""
Given a testcase, run 'streaming' interface against input and check if outputs are correct
"""
if context is None:
context = {}

schemas = {
'input': 'schemas/examples-messages.input.json',
'output': 'schemas/examples-messages.output.json',
'config': 'schemas/examples-messages.config.json'
}
context = params.get('context', {})
schemas = params.get('schemas', schemas)
testcase = params['testcase']

inp = open(os.path.join(self.test_folder, f'{testcase}.input.json'), encoding='utf-8')
in_msg = json.loads(inp.read())
s3meta = None
if 'replace' in in_msg:
s3meta = self.place_remote_message(in_msg)
schemas = {
'input': 'schemas/examples-messages.output.json',
'output': 'schemas/examples-messages.output.json',
'config': 'schemas/examples-messages.config.json'
}

cma_input = {'event': in_msg, 'context': context, 'schemas': schemas}
current_directory = os.getcwd()

Expand Down Expand Up @@ -135,24 +138,27 @@ def transform_messages_streaming(self, testcase, context=None):
if s3meta is not None:
self.clean_up_remote_message(s3meta['bucket_name'], s3meta['key_name'])

def transform_messages(self, testcase, context=None):
def transform_messages(self, params):
"""
transform cumulus messages, and check if the command return status and outputs are correct.
Each test case (such as 'basic') has its corresponding example messages and schemas.
"""
if context is None:
context = {}

schemas = {
'input': 'schemas/examples-messages.input.json',
'output': 'schemas/examples-messages.output.json',
'config': 'schemas/examples-messages.config.json'
}
context = params.get('context', None)
schemas = params.get('schemas', schemas)
testcase = params['testcase']

inp = open(os.path.join(self.test_folder, f'{testcase}.input.json'), encoding='utf-8')
in_msg = json.loads(inp.read())
s3meta = None
if 'replace' in in_msg:
s3meta = self.place_remote_message(in_msg)
schemas = {
'input': 'schemas/examples-messages.output.json',
'output': 'schemas/examples-messages.output.json',
'config': 'schemas/examples-messages.config.json'
}


all_input = {'event': in_msg, 'context': context, 'schemas': schemas}
current_directory = os.getcwd()
Expand Down Expand Up @@ -194,38 +200,47 @@ def transform_messages(self, testcase, context=None):

def test_basic(self):
""" test basic message """
self.transform_messages('basic')
self.transform_messages_streaming('basic')
self.transform_messages({ 'testcase': 'basic'})
self.transform_messages_streaming({ 'testcase': 'basic'})

def test_basic_no_config(self):
""" test basic no config message """
schemas = {
'input': 'schemas/examples-messages.input.json',
'output': 'schemas/examples-messages-no-config.output.json',
}
self.transform_messages({ 'testcase': 'basic_no_config', 'schemas': schemas })
self.transform_messages_streaming({ 'testcase': 'basic_no_config', 'schemas': schemas })

def test_exception(self):
""" test remote message with exception """
self.transform_messages('exception')
self.transform_messages_streaming('exception')
self.transform_messages({ 'testcase': 'exception'})
self.transform_messages_streaming({ 'testcase': 'exception'})

def test_jsonpath(self):
""" test jsonpath message """
self.transform_messages('jsonpath')
self.transform_messages_streaming('jsonpath')
self.transform_messages({ 'testcase': 'jsonpath'})
self.transform_messages_streaming({ 'testcase': 'jsonpath'})

def test_meta(self):
""" test meta message """
self.transform_messages('meta')
self.transform_messages_streaming('meta')
self.transform_messages({ 'testcase': 'meta'})
self.transform_messages_streaming({ 'testcase': 'meta'})

def test_remote(self):
""" test remote message """
self.transform_messages('remote')
self.transform_messages_streaming('remote')
self.transform_messages({ 'testcase': 'remote'})
self.transform_messages_streaming({ 'testcase': 'remote'})

def test_templates(self):
""" test templates message """
self.transform_messages('templates')
self.transform_messages_streaming('templates')
self.transform_messages({ 'testcase': 'templates'})
self.transform_messages_streaming({ 'testcase': 'templates'})

def test_validation_failure_case(self):
""" test validation failure case """
try:
self.transform_messages("invalidinput")
self.transform_messages({ 'testcase': 'invalidinput'})
except AssertionError:
return
assert False
Expand All @@ -237,8 +252,8 @@ def test_workflow_task_meta(self):
'invokedFunctionArn': 'fakearn',
'functionVersion': '1',
}
self.transform_messages('workflow_tasks', context)
self.transform_messages_streaming('workflow_tasks', context)
self.transform_messages({'testcase': 'workflow_tasks', 'context': context})
self.transform_messages_streaming({'testcase': 'workflow_tasks', 'context': context})

def test_multiple_workflow_tasks_meta(self):
""" test multiple meta.workflow_task entries"""
Expand All @@ -247,5 +262,6 @@ def test_multiple_workflow_tasks_meta(self):
'invokedFunctionArn': 'fakearn2',
'functionVersion': '2',
}
self.transform_messages('workflow_tasks_multiple', context)
self.transform_messages_streaming('workflow_tasks_multiple', context)
self.transform_messages({'testcase': 'workflow_tasks_multiple', 'context': context})
self.transform_messages_streaming(
{'testcase': 'workflow_tasks_multiple', 'context': context})

0 comments on commit 2091a63

Please sign in to comment.