diff options
author | James Falcon <TheRealFalcon@users.noreply.github.com> | 2021-05-13 12:55:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-13 12:55:41 -0500 |
commit | 864346999702e6b2b8bf7e6244a6608bcead72a5 (patch) | |
tree | f460467494bdafe8e85dfc4615de636b747aa9fa /cloudinit/tests/test_event.py | |
parent | 899bfaa9d6bfab1db0df99257628ca1f6febff60 (diff) | |
download | vyos-cloud-init-864346999702e6b2b8bf7e6244a6608bcead72a5.tar.gz vyos-cloud-init-864346999702e6b2b8bf7e6244a6608bcead72a5.zip |
Allow user control over update events (#834)
Control is currently limited to boot events, though this should
allow us to more easily incorporate HOTPLUG support. Disabling
'instance-first-boot' is not supported as we apply networking config
too early in boot to have processed userdata (along with the fact
that this would be a pretty big foot-gun).
The concept of update events on datasource has been split into
supported update events and default update events. Defaults will be
used if there is no user-defined update events, but user-defined
events won't be supplied if they aren't supported.
When applying the networking config, we now check to see if the event
is supported by the datasource as well as if it is enabled.
Configuration looks like:
updates:
network:
when: ['boot']
Diffstat (limited to 'cloudinit/tests/test_event.py')
-rw-r--r-- | cloudinit/tests/test_event.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cloudinit/tests/test_event.py b/cloudinit/tests/test_event.py new file mode 100644 index 00000000..3da4c70c --- /dev/null +++ b/cloudinit/tests/test_event.py @@ -0,0 +1,26 @@ +# This file is part of cloud-init. See LICENSE file for license information. +"""Tests related to cloudinit.event module.""" +from cloudinit.event import EventType, EventScope, userdata_to_events + + +class TestEvent: + def test_userdata_to_events(self): + userdata = {'network': {'when': ['boot']}} + expected = {EventScope.NETWORK: {EventType.BOOT}} + assert expected == userdata_to_events(userdata) + + def test_invalid_scope(self, caplog): + userdata = {'networkasdfasdf': {'when': ['boot']}} + userdata_to_events(userdata) + assert ( + "'networkasdfasdf' is not a valid EventScope! Update data " + "will be ignored for 'networkasdfasdf' scope" + ) in caplog.text + + def test_invalid_event(self, caplog): + userdata = {'network': {'when': ['bootasdfasdf']}} + userdata_to_events(userdata) + assert ( + "'bootasdfasdf' is not a valid EventType! Update data " + "will be ignored for 'network' scope" + ) in caplog.text |