Skip to content

Commit

Permalink
integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
blackboxsw committed Jan 9, 2022
1 parent 115cc88 commit 9a04f5b
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions tests/integration_tests/modules/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
- echo 'hi' > /var/tmp/test
"""

INVALID_USER_DATA = """\
INVALID_USER_DATA_HEADER = """\
runcmd:
- echo 'hi' > /var/tmp/test
"""

INVALID_USER_DATA_SCHEMA = """\
#cloud-config
updates:
notnetwork: -1
apt_pipelining: bogus
"""


@pytest.mark.sru_2020_11
@pytest.mark.user_data(VALID_USER_DATA)
Expand All @@ -29,10 +36,15 @@ def test_valid_userdata(client: IntegrationInstance):
result = client.execute("cloud-init devel schema --system")
assert result.ok
assert "Valid cloud-config: system userdata" == result.stdout.strip()
result = client.execute("cloud-init status --long")
if not result.ok:
raise AssertionError(
f"Unexpected error from cloud-init status: {result}"
)


@pytest.mark.sru_2020_11
@pytest.mark.user_data(INVALID_USER_DATA)
@pytest.mark.user_data(INVALID_USER_DATA_HEADER)
def test_invalid_userdata(client: IntegrationInstance):
"""Test `cloud-init devel schema` with invalid userdata.
Expand All @@ -42,3 +54,30 @@ def test_invalid_userdata(client: IntegrationInstance):
assert not result.ok
assert "Cloud config schema errors" in result.stderr
assert 'needs to begin with "#cloud-config"' in result.stderr
result = client.execute("cloud-init status --long")
if not result.ok:
raise AssertionError(
f"Unexpected error from cloud-init status: {result}"
)


@pytest.mark.user_data(INVALID_USER_DATA_SCHEMA)
def test_invalid_userdata_schema(client: IntegrationInstance):
"""Test invalid schema represented as Warnings, not fatal
PR #1175
"""
result = client.execute("cloud-init status --long")
assert result.ok
log = client.read_from_file("/var/log/cloud-init.log")
warning = (
"[WARNING]: Invalid cloud-config provided:\napt_pipelining: 'bogus'"
" is not valid under any of the given schemas\nupdates: Additional"
" properties are not allowed ('notnetwork' was unexpected)"
)
assert warning in log
result = client.execute("cloud-init status --long")
if not result.ok:
raise AssertionError(
f"Unexpected error from cloud-init status: {result}"
)

0 comments on commit 9a04f5b

Please sign in to comment.