diff options
author | momousta <momousta> | 2019-11-08 15:02:07 -0600 |
---|---|---|
committer | Ryan Harper <ryan.harper@canonical.com> | 2019-11-08 15:02:07 -0600 |
commit | 92cc71dec8da73bf43d345418b73db1a32a6b8b9 (patch) | |
tree | 578d45b726f809104155bf4263e1039ea8a12dba /tests | |
parent | 8ae0a7030e5e825dd4179761a62fa7f8670df101 (diff) | |
download | vyos-cloud-init-92cc71dec8da73bf43d345418b73db1a32a6b8b9.tar.gz vyos-cloud-init-92cc71dec8da73bf43d345418b73db1a32a6b8b9.zip |
reporting: Using a uuid to enforce uniqueness on the KVP keys.
The KVPs currently being emitted to the .kvp_pool file can have
duplicate keys which is wrong since these keys should be unique.
The situation can occur if for example one azure function
called twice or more and this function is reporting telemetry
through the use of KVPs. Any KVP consumer can get confused by
the duplicate keys and a race condition can and have occurred.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_reporting_hyperv.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/unittests/test_reporting_hyperv.py b/tests/unittests/test_reporting_hyperv.py index 640895a4..3582cf0b 100644 --- a/tests/unittests/test_reporting_hyperv.py +++ b/tests/unittests/test_reporting_hyperv.py @@ -191,3 +191,21 @@ class TextKvpReporter(CiTestCase): if "test_diagnostic" not in evt_msg: raise AssertionError("missing expected diagnostic message") + + def test_unique_kvp_key(self): + reporter = HyperVKvpReportingHandler(kvp_file_path=self.tmp_file_path) + evt1 = events.ReportingEvent( + "event_type", 'event_message', + "event_description") + reporter.publish_event(evt1) + + evt2 = events.ReportingEvent( + "event_type", 'event_message', + "event_description", timestamp=evt1.timestamp + 1) + reporter.publish_event(evt2) + + reporter.q.join() + kvps = list(reporter._iterate_kvps(0)) + self.assertEqual(2, len(kvps)) + self.assertNotEqual(kvps[0]["key"], kvps[1]["key"], + "duplicate keys for KVP entries") |