Skip to content

Commit

Permalink
mypy: init user_tags to empty string, only set it when present in use…
Browse files Browse the repository at this point in the history
…rdata

- tests: lanscape.client.tags schema disallows spaces between tags.
  Update tests to assert comma-delimited values and the exclusion of
  the wsl tag from agent.yaml
  • Loading branch information
blackboxsw committed Jul 19, 2024
1 parent 7c1a3a5 commit 7c95527
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 2 additions & 6 deletions cloudinit/sources/DataSourceWSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,12 @@ def _get_data(self) -> bool:
# provides them instead.
# That's the reason for not using util.mergemanydict().
merged: dict = {}
user_tags: str = ""
overridden_keys: typing.List[str] = []
# We've already checked, this is just to please mypy.
assert user_data is not None
user_tags = (
user_data.get("landscape", {}).get("client", {}).get("tags")
)
if user_data:
merged = user_data
user_tags = (
merged.get("landscape", {}).get("client", {}).get("tags")
merged.get("landscape", {}).get("client", {}).get("tags", "")
)
if agent_data:
if user_data:
Expand Down
5 changes: 3 additions & 2 deletions tests/unittests/sources/test_wsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def test_landscape_vs_local_user(self, m_get_linux_dist, tmpdir, paths):
landscape:
client:
account_name: landscapetest
tags: tag_aiml, tag_dev
tags: tag_aiml,tag_dev
locale: en_GB.UTF-8"""
)

Expand Down Expand Up @@ -537,7 +537,7 @@ def test_landscape_provided_data(self, m_get_linux_dist, tmpdir, paths):
landscape:
client:
account_name: landscapetest
tags: tag_aiml, tag_dev
tags: tag_aiml,tag_dev
package_update: true"""
)

Expand Down Expand Up @@ -572,6 +572,7 @@ def test_landscape_provided_data(self, m_get_linux_dist, tmpdir, paths):
assert (
"tag_aiml" in userdata and "tag_dev" in userdata
), "User-data should override agent data's Landscape computer tags"
assert "wsl" not in userdata

@mock.patch("cloudinit.util.get_linux_distro")
def test_with_landscape_no_tags(self, m_get_linux_dist, tmpdir, paths):
Expand Down

0 comments on commit 7c95527

Please sign in to comment.