-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azure: define new attribute for pre-22.3 pickles (#1725)
A new attribute was added to DataSourceAzure[1]. Since the base class uses CloudInitPickleMixin, we need to define this new attribute in _unpickle() Add multiple tests to improve pickle coverage. [1] #1523
- Loading branch information
Showing
5 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# Copyright (C) 2020 Canonical Ltd. | ||
# | ||
# Author: Daniel Watkins <[email protected]> | ||
# | ||
# This file is part of cloud-init. See LICENSE file for license information. | ||
|
||
"""Upgrade testing for cloud-init. | ||
|
@@ -19,8 +17,15 @@ | |
import pytest | ||
|
||
from cloudinit.sources import pkl_load | ||
from cloudinit.sources.DataSourceAzure import DataSourceAzure | ||
from cloudinit.sources.DataSourceNoCloud import DataSourceNoCloud | ||
from tests.unittests.helpers import resourceLocation | ||
|
||
DSNAME_TO_CLASS = { | ||
"Azure": DataSourceAzure, | ||
"NoCloud": DataSourceNoCloud, | ||
} | ||
|
||
|
||
class TestUpgrade: | ||
@pytest.fixture( | ||
|
@@ -36,6 +41,25 @@ def previous_obj_pkl(self, request): | |
""" | ||
return pkl_load(str(request.param)) | ||
|
||
def test_pkl_load_defines_all_init_side_effect_attributes( | ||
self, previous_obj_pkl | ||
): | ||
"""Any attrs as side-effects of __init__ exist in unpickled obj.""" | ||
ds_class = DSNAME_TO_CLASS[previous_obj_pkl.dsname] | ||
sys_cfg = previous_obj_pkl.sys_cfg | ||
distro = previous_obj_pkl.distro | ||
paths = previous_obj_pkl.paths | ||
ds = ds_class(sys_cfg, distro, paths) | ||
if ds.dsname == "NoCloud" and previous_obj_pkl.__dict__: | ||
expected = ( | ||
set({"seed_dirs"}), # LP: #1568150 handled with getattr checks | ||
set(), | ||
) | ||
else: | ||
expected = (set(),) | ||
missing_attrs = ds.__dict__.keys() - previous_obj_pkl.__dict__.keys() | ||
assert missing_attrs in expected | ||
|
||
def test_networking_set_on_distro(self, previous_obj_pkl): | ||
"""We always expect to have ``.networking`` on ``Distro`` objects.""" | ||
assert previous_obj_pkl.distro.networking is not None | ||
|