Permalink
Browse files

Implement logger definitions.

  • Loading branch information...
dzimine committed Oct 9, 2018
1 parent 6d23c52 commit f35e10ac4e197a4a9a09d7ea19a19118ca21c65c
Showing with 93 additions and 3 deletions.
  1. +10 −1 greengo.yaml
  2. +46 −2 greengo/greengo.py
  3. +11 −0 tests/main_test.py
  4. +26 −0 tests/test_state.json
@@ -36,7 +36,7 @@ Subscriptions:
Target: Lambda::GreengrassHelloWorld

Resources:
# Resource as defined at http://boto3.readthedocs.io/en/latest/reference/services/greengrass.html#Greengrass.Client.create_resource_definition_version
# For parameter definitions, see http://boto3.readthedocs.io/en/latest/reference/services/greengrass.html#Greengrass.Client.create_resource_definition_version
- Name: path_to_input
Id: resource_1_path_to_input
LocalVolumeResourceData:
@@ -45,7 +45,16 @@ Resources:
GroupOwnerSetting:
AutoAddGroupOwner: True

Loggers:
# For parameter definitions, see https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/greengrass.html#Greengrass.Client.create_logger_definition
- Component: Lambda # 'GreengrassSystem'|'Lambda'
Id: logger_1 # Arbitrary string
Level: DEBUG # 'DEBUG'|'INFO'|'WARN'|'ERROR'|'FATAL'
Space: 1024 # The amount of file space, in KB, to use if the local file system is used for logging purposes
Type: FileSystem # 'FileSystem'|'AWSCloudWatch'

Devices: # not implemented
- name: ml_take2_thing_1
key_path: ./certs


@@ -459,6 +459,50 @@ def remove_resources(self):
_update_state(self.state)
log.info("Resources definition deleted OK!")

def create_loggers(self):
if not self.group.get('Loggers'):
log.info("Loggers not defined. Moving on...")
return

if self.state and self.state.get('Loggers'):
log.warning("Previously created Loggers exist. Remove before creating!")
return

loggers = self.group['Loggers']
name = self.name + '_loggers'
log.info("Creating loggers definition: '{0}'".format(name))

res_def = self._gg.create_logger_definition(
Name=name,
InitialVersion={'Loggers': loggers}
)

self.state['Loggers'] = rinse(res_def)
_update_state(self.state)

log_def_ver = self._gg.get_logger_definition_version(
LoggerDefinitionId=self.state['Loggers']['Id'],
LoggerDefinitionVersionId=self.state['Loggers']['LatestVersion'])

self.state['Loggers']['LatestVersionDetails'] = rinse(log_def_ver)
_update_state(self.state)

log.info("Loggers definition created OK!")

def remove_loggers(self):
if not (self.state and self.state.get('Loggers')):
log.info("There seem to be nothing to remove.")
return
log.info("Deleting loggers definition Id='{0}'".format(
self.state['Loggers']['Id']))

self._gg.delete_logger_definition(
LoggerDefinitionId=self.state['Loggers']['Id'])

self.state.pop('Loggers')
_update_state(self.state)
log.info("Loggers definition deleted OK!")

def update(self):
self.remove_subscriptions()
self.remove_lambdas()
@@ -467,9 +511,9 @@ def update(self):
self.create_resources()
self.create_lambdas()
self.create_subscriptions()

self.create_group_version()

log.info('Updated on Greengrass! Execute "greengo deploy" to apply')

def _create_cores(self):
@@ -107,6 +107,17 @@ def test_remove_resources(self):
self.gg.remove_resources()
self.assertFalse(self.gg.state.get('Resources'), "Resources shall be removed")

def test_create_loggers(self):
self.gg.group.pop('Loggers')
self.gg.create_loggers()

def test_remove_loggers(self):
self.gg._gg.delete_resource_definition = MagicMock(return_value=state['Loggers'])
self.gg.state = greengo.State(state.copy())

self.gg.remove_loggers()
self.assertFalse(self.gg.state.get('Loggers'), "Loggers shall be removed")


@patch('greengo.greengo.rinse', rinse)
class LambdaTest(unittest.TestCase):
@@ -159,6 +159,32 @@
"ZipPath": "/path/to/greengo/.gg/GreengrassHelloWorld.zip"
}
],
"Loggers": {
"Arn": "arn:aws:greengrass:us-east-1:000000000000:/greengrass/definition/loggers/d89956dd-18c0-4833-919f-aafa15e171cc",
"CreationTimestamp": "2018-10-09T21:04:16.840Z",
"Id": "d89956dd-18c0-4833-919f-aafa15e171cc",
"LastUpdatedTimestamp": "2018-10-09T21:04:16.840Z",
"LatestVersion": "d2624229-619a-453d-91cb-264df916d43c",
"LatestVersionArn": "arn:aws:greengrass:us-east-1:000000000000:/greengrass/definition/loggers/d89956dd-18c0-4833-919f-aafa15e171cc/versions/d2624229-619a-453d-91cb-264df916d43c",
"LatestVersionDetails": {
"Arn": "arn:aws:greengrass:us-east-1:000000000000:/greengrass/definition/loggers/d89956dd-18c0-4833-919f-aafa15e171cc/versions/d2624229-619a-453d-91cb-264df916d43c",
"CreationTimestamp": "2018-10-09T21:04:16.840Z",
"Definition": {
"Loggers": [
{
"Component": "Lambda",
"Id": "logger_1",
"Level": "DEBUG",
"Space": 1024,
"Type": "FileSystem"
}
]
},
"Id": "d89956dd-18c0-4833-919f-aafa15e171cc",
"Version": "d2624229-619a-453d-91cb-264df916d43c"
},
"Name": "GreengoGroup_loggers"
},
"Subscriptions": {
"Arn": "arn:aws:greengrass:us-west-2:000000000000:/greengrass/definition/subscriptions/37d25372-c98e-4435-978d-756b14a11911",
"CreationTimestamp": "2018-04-04T09:21:46.234Z",

0 comments on commit f35e10a

Please sign in to comment.