-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cmd-modules): exit code when --mode init #5017
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beyond using class_client, l let's also add a failure test as well.
--- a/tests/integration_tests/modules/test_cli.py
+++ b/tests/integration_tests/modules/test_cli.py
@@ -20,6 +20,12 @@ runcmd:
- echo 'hi' > /var/tmp/test
"""
+FAILING_USER_DATA_RUNCMD = """\
+#cloud-config
+runcmd:
+ - exit 1
+"""
+
# The '-' in 'hashed-password' fails schema validation
INVALID_USER_DATA_SCHEMA = """\
#cloud-config
@@ -37,25 +43,25 @@ users:
@pytest.mark.user_data(VALID_USER_DATA)
class TestValidUserData:
- def test_schema_status(self, client: IntegrationInstance):
+ def test_schema_status(self, class_client: IntegrationInstance):
"""Test `cloud-init schema` with valid userdata.
PR #575
"""
- result = client.execute("cloud-init schema --system")
+ result = class_client.execute("cloud-init schema --system")
assert result.ok
assert "Valid schema user-data" in result.stdout.strip()
- result = client.execute("cloud-init status --long")
+ result = class_client.execute("cloud-init status --long")
assert 0 == result.return_code, (
f"Unexpected exit {result.return_code} from cloud-init status:"
f" {result}"
)
- @pytest.mark.parametrize("mode", ["init", "config", "final"])
- def test_modules_init(self, mode, client: IntegrationInstance):
- result = client.execute(f"cloud-init modules --mode {mode}")
- assert result.ok
- assert f"'modules:{mode}'" in result.stdout.strip()
+ def test_modules_init(self, class_client: IntegrationInstance):
+ for mode in ("init", "config", "final"):
+ result = class_client.execute(f"cloud-init modules --mode {mode}")
+ assert result.ok
+ assert f"'modules:{mode}'" in result.stdout.strip()
@pytest.mark.skipif(
@@ -105,3 +111,12 @@ def test_invalid_userdata_schema(client: IntegrationInstance):
)
assert warning in log
assert "asdfasdf" not in log
+
+
+@pytest.mark.user_data(FAILING_USER_DATA_RUNCMD)
+def test_failing_userdata_exit_codes(client: IntegrationInstance):
+ """Test failing in modules representd in exit status"""
+ for mode in ("init", "config", "final"):
+ result = client.execute(f"cloud-init modules --mode {mode}")
+ assert result.failed if mode == "init" else result.ok
+ assert f"'modules:{mode}'" in result.stdout.strip()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved for landing once we minimally have class_client
and your decision on the failure test.
Co-authored-by: Chad Smith <chad.smith@canonical.com>
f86c610
to
94fbaa9
Compare
The sole intention of making those test belong to the same class was to use I have included your failure test with a small modification: to make Thanks for the review and suggestions! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Chad Smith <chad.smith@canonical.com>
Proposed Commit Message
Additional Context
Supersedes #4939
Execute
cloud-init modules --mode init
on any instance.Test Steps
Checklist
Merge type