diff options
author | Mike Russell <michael.j.russell.email@gmail.com> | 2021-06-16 05:51:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 07:51:00 -0500 |
commit | c8d3f99be84a4a04074a94c451387932bd086b26 (patch) | |
tree | dc1358993bd37e3a48b74be14f429bf82d4a2e84 | |
parent | 950c186a7e0c66a3ed84ea97291e5829ca3d826c (diff) | |
download | vyos-cloud-init-c8d3f99be84a4a04074a94c451387932bd086b26.tar.gz vyos-cloud-init-c8d3f99be84a4a04074a94c451387932bd086b26.zip |
Small Doc Update for ReportEventStack and Test (#920)
- small document update for ReportEventStack explaining post_files
parameter
- small unit test for test_reporting demonstrating the close of an
event with optional post_files list
-rw-r--r-- | cloudinit/reporting/events.py | 8 | ||||
-rw-r--r-- | tests/unittests/test_reporting.py | 18 | ||||
-rw-r--r-- | tools/.github-cla-signers | 1 |
3 files changed, 27 insertions, 0 deletions
diff --git a/cloudinit/reporting/events.py b/cloudinit/reporting/events.py index b8677c8b..9afad747 100644 --- a/cloudinit/reporting/events.py +++ b/cloudinit/reporting/events.py @@ -165,7 +165,15 @@ class ReportEventStack(object): :param result_on_exception: The result value to set if an exception is caught. default value is FAIL. + + :param post_files: + Can hold filepaths of files that are to get posted/created + regarding a given event. Something like success or failure information + in a given log file. For each filepath, if it's a valid regular file + it will get: read & encoded as base64 at the close of the event. + Default value, if None, is an empty list. """ + def __init__(self, name, description, message=None, parent=None, reporting_enabled=None, result_on_exception=status.FAIL, post_files=None): diff --git a/tests/unittests/test_reporting.py b/tests/unittests/test_reporting.py index 9f11fd5c..b78a6939 100644 --- a/tests/unittests/test_reporting.py +++ b/tests/unittests/test_reporting.py @@ -113,6 +113,7 @@ class TestReportingEvent(TestCase): class TestFinishReportingEvent(TestCase): + def test_as_has_result(self): result = events.status.SUCCESS name, desc = 'test_name', 'test_desc' @@ -121,6 +122,23 @@ class TestFinishReportingEvent(TestCase): self.assertTrue('result' in ret) self.assertEqual(ret['result'], result) + def test_has_result_with_optional_post_files(self): + result = events.status.SUCCESS + name, desc, files = 'test_name', 'test_desc', [ + '/really/fake/path/install.log'] + event = events.FinishReportingEvent( + name, desc, result, post_files=files) + ret = event.as_dict() + self.assertTrue('result' in ret) + self.assertTrue('files' in ret) + self.assertEqual(ret['result'], result) + posted_install_log = ret['files'][0] + self.assertTrue('path' in posted_install_log) + self.assertTrue('content' in posted_install_log) + self.assertTrue('encoding' in posted_install_log) + self.assertEqual(posted_install_log['path'], files[0]) + self.assertEqual(posted_install_log['encoding'], 'base64') + class TestBaseReportingHandler(TestCase): diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers index 14916d31..0b9fbe9e 100644 --- a/tools/.github-cla-signers +++ b/tools/.github-cla-signers @@ -22,6 +22,7 @@ emmanuelthome esposem giggsoff hamalq +irishgordo izzyleung johnsonshi jordimassaguerpla |