diff options
author | Daniel Watkins <daniel.watkins@canonical.com> | 2019-03-14 23:06:47 +0000 |
---|---|---|
committer | Server Team CI Bot <josh.powers+server-team-bot@canonical.com> | 2019-03-14 23:06:47 +0000 |
commit | f2fd6eac4407e60d0e98826ab03847dda4cde138 (patch) | |
tree | cbd47c6633145a5de7e90768252623c149605fb1 /tests/unittests/test_datasource/test_scaleway.py | |
parent | 3acaacc92be1b7d7bad099c323d6e923664a8afa (diff) | |
download | vyos-cloud-init-f2fd6eac4407e60d0e98826ab03847dda4cde138.tar.gz vyos-cloud-init-f2fd6eac4407e60d0e98826ab03847dda4cde138.zip |
DataSource: move update_events from a class to an instance attribute
Currently, DataSourceAzure updates self.update_events in __init__. As
update_events is a class attribute on DataSource, this updates it for
all instances of classes derived from DataSource including those for
other clouds. This means that if DataSourceAzure is even instantiated,
its behaviour is applied to whichever data source ends up being used for
boot.
To address this, update_events is moved from a class attribute to an
instance attribute (that is therefore populated at instantiation time).
This retains the defaults for all DataSource sub-class instances, but
avoids them being able to mutate the state in instances of other
DataSource sub-classes.
update_events is only ever referenced on an instance of DataSource (or a
sub-class); no code relies on it being a class attribute. (In fact,
it's only used within methods on DataSource or its sub-classes, so it
doesn't even _need_ to remain public, though I think it's appropriate
for it to be public.)
DataSourceScaleway is also updated to move update_events from a
class attribute to an instance attribute, as the class attribute would
now be masked by the DataSource instance attribute.
LP: #1819913
Diffstat (limited to 'tests/unittests/test_datasource/test_scaleway.py')
-rw-r--r-- | tests/unittests/test_datasource/test_scaleway.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/unittests/test_datasource/test_scaleway.py b/tests/unittests/test_datasource/test_scaleway.py index f96bf0a2..3bfd7527 100644 --- a/tests/unittests/test_datasource/test_scaleway.py +++ b/tests/unittests/test_datasource/test_scaleway.py @@ -7,6 +7,7 @@ import requests from cloudinit import helpers from cloudinit import settings +from cloudinit.event import EventType from cloudinit.sources import DataSourceScaleway from cloudinit.tests.helpers import mock, HttprettyTestCase, CiTestCase @@ -403,3 +404,9 @@ class TestDataSourceScaleway(HttprettyTestCase): netcfg = self.datasource.network_config self.assertEqual(netcfg, '0xdeadbeef') + + def test_update_events_is_correct(self): + """ensure update_events contains correct data""" + self.assertEqual( + {'network': {EventType.BOOT_NEW_INSTANCE, EventType.BOOT}}, + self.datasource.update_events) |