Skip to content
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

feat(testing): add spread testing template files #1514

Closed

Conversation

cmatsuoka
Copy link
Contributor

Add Jinja2 template files for machine charm testing, installed when
initializing a minimal charm with charmcraft init --profile machine.

Signed-off-by: Claudio Matsuoka claudio.matsuoka@canonical.com

Add Jinja2 template files for machine charm testing, installed when
initializing a minimal charm with `charmcraft init --profile machine`.

Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@cmatsuoka cmatsuoka changed the base branch from main to feature/testing February 9, 2024 01:23
Comment on lines 51 to 53
cmd = f"{os.environ['SNAP']}/bin/spread"
with emit.pause():
subprocess.run([cmd, "-v", *self.arguments], check=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is experimental code. This must be better handled before reaching production.

@cmatsuoka
Copy link
Contributor Author

This first iteration runs spread in verbose mode. Output example:

$ charmcraft test 
2024-02-08 21:59:09 Found /home/claudio/charmcraft/charmcraft/xxx/spread.yaml.
2024-02-08 21:59:09 Project content is packed for delivery (9.59KB).
2024-02-08 21:59:09 If killed, discard servers with: spread -reuse-pid=490332 -discard
2024-02-08 21:59:09 Allocating multipass:ubuntu-22.04...
2024-02-08 21:59:09 Allocating multipass:ubuntu-22.04...
2024-02-08 21:59:09 Allocating multipass:ubuntu-22.04...
2024-02-08 21:59:34 Waiting for multipass:ubuntu-22.04 to make SSH available at 10.109.46.197...
2024-02-08 21:59:34 Allocated multipass:ubuntu-22.04.
2024-02-08 21:59:34 Connecting to multipass:ubuntu-22.04...
2024-02-08 21:59:34 Connected to multipass:ubuntu-22.04 at 10.109.46.197.
2024-02-08 21:59:34 Sending project content to multipass:ubuntu-22.04...
2024-02-08 21:59:34 Preparing multipass:ubuntu-22.04 (multipass:ubuntu-22.04)...
2024-02-08 21:59:34 Preparing multipass:ubuntu-22.04:tests/spread/minimal:alt3 (multipass:ubuntu-22.04)...
2024-02-08 21:59:34 Waiting for multipass:ubuntu-22.04 to make SSH available at 10.109.46.85...
2024-02-08 21:59:34 Allocated multipass:ubuntu-22.04.
2024-02-08 21:59:34 Connecting to multipass:ubuntu-22.04...
2024-02-08 21:59:34 Connected to multipass:ubuntu-22.04 at 10.109.46.85.
2024-02-08 21:59:34 Sending project content to multipass:ubuntu-22.04...
2024-02-08 21:59:35 Preparing multipass:ubuntu-22.04 (multipass:ubuntu-22.04)...
2024-02-08 21:59:35 Waiting for multipass:ubuntu-22.04 to make SSH available at 10.109.46.254...
2024-02-08 21:59:35 Allocated multipass:ubuntu-22.04.
2024-02-08 21:59:35 Connecting to multipass:ubuntu-22.04...
2024-02-08 21:59:35 Connected to multipass:ubuntu-22.04 at 10.109.46.254.
2024-02-08 21:59:35 Sending project content to multipass:ubuntu-22.04...
2024-02-08 21:59:35 Preparing multipass:ubuntu-22.04:tests/spread/minimal:alt2 (multipass:ubuntu-22.04)...
2024-02-08 21:59:35 Preparing multipass:ubuntu-22.04 (multipass:ubuntu-22.04)...
2024-02-08 21:59:35 Preparing multipass:ubuntu-22.04:tests/spread/minimal:alt1 (multipass:ubuntu-22.04)...
2024-02-08 22:02:24 Executing multipass:ubuntu-22.04:tests/spread/minimal:alt2 (multipass:ubuntu-22.04) (1/3)...
2024-02-08 22:02:27 Executing multipass:ubuntu-22.04:tests/spread/minimal:alt1 (multipass:ubuntu-22.04) (2/3)...
2024-02-08 22:02:30 Executing multipass:ubuntu-22.04:tests/spread/minimal:alt3 (multipass:ubuntu-22.04) (3/3)...
2024-02-08 22:05:14 Restoring multipass:ubuntu-22.04:tests/spread/minimal:alt1 (multipass:ubuntu-22.04)...
2024-02-08 22:05:15 Restoring multipass:ubuntu-22.04:tests/spread/minimal:alt3 (multipass:ubuntu-22.04)...
2024-02-08 22:05:22 Restoring multipass:ubuntu-22.04:tests/spread/minimal:alt2 (multipass:ubuntu-22.04)...
2024-02-08 22:05:32 Restoring multipass:ubuntu-22.04 (multipass:ubuntu-22.04)...
2024-02-08 22:05:33 Discarding multipass:ubuntu-22.04...
2024-02-08 22:05:33 Restoring multipass:ubuntu-22.04 (multipass:ubuntu-22.04)...
2024-02-08 22:05:34 Discarding multipass:ubuntu-22.04...
2024-02-08 22:05:41 Restoring multipass:ubuntu-22.04 (multipass:ubuntu-22.04)...
2024-02-08 22:05:41 Discarding multipass:ubuntu-22.04...
2024-02-08 22:05:46 Successful tasks: 3
2024-02-08 22:05:46 Aborted tasks: 0

@cmatsuoka cmatsuoka force-pushed the charm-spread-minimal branch from 30620c9 to 9d75ee3 Compare February 9, 2024 01:42
@cmatsuoka cmatsuoka requested a review from lengau February 9, 2024 01:42
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@cmatsuoka cmatsuoka force-pushed the charm-spread-minimal branch from 9d75ee3 to 2bf8b8d Compare February 9, 2024 01:45
@cmatsuoka cmatsuoka requested a review from mr-cal February 9, 2024 01:46
Copy link
Contributor

@mr-cal mr-cal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (with the caveat that this is on a feature branch and only adds the test files to the machine charm template)

Copy link
Collaborator

@lengau lengau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I've got a few minor things but I'm happy with the overall structure.

users:
- default
- name: spread
plain_text_passwd: spread
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to do this using spread's generated passwords?

If you don't have a simple way to do it immediately, please make an issue so we don't forget about it - I don't want spread/spread to become one of the username/password pairs bad guys start scanning cloud services with :-)

@@ -0,0 +1,32 @@

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth a comment up here explaining what these functions are used for.

CHARMCRAFT_CHANNEL/alt1,alt3: latest/stable
CHARMCRAFT_CHANNEL/alt2: latest/candidate

# This creates 3 test variants:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might make more sense above environment?

Comment on lines 26 to 31
install_lxd
snap install charmcraft --classic --channel "$CHARMCRAFT_CHANNEL"
snap install juju --classic --channel "$JUJU_CHANNEL"
mkdir -p "$HOME"/.local/share/juju

bootstrap_juju
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be doing this once per runner in spread.yaml?

@@ -64,6 +64,9 @@ apps:
# same for config
XDG_CONFIG_HOME: $SNAP_USER_COMMON/config

spread:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not have a separate charmcraft.spread application for now.

def run(self, parsed_args: argparse.Namespace):
"""Execute command's actual functionality."""
try:
cmd = f"{os.environ['SNAP']}/bin/spread"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd = f"{os.environ['SNAP']}/bin/spread"
# TODO: Make this work without Charmcraft being snapped
cmd = f"{os.environ['SNAP']}/bin/spread"

Thinking of our users on macos :-)

lengau and others added 3 commits March 12, 2024 16:24
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@cmatsuoka cmatsuoka force-pushed the charm-spread-minimal branch from a51ebd8 to 6f84191 Compare March 21, 2024 22:39
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@cmatsuoka cmatsuoka force-pushed the charm-spread-minimal branch from 568ee53 to 999cb05 Compare March 22, 2024 02:04
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@cmatsuoka cmatsuoka force-pushed the charm-spread-minimal branch from 7e01e99 to 9153264 Compare March 22, 2024 17:30
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
@cmatsuoka
Copy link
Contributor Author

cmatsuoka commented May 27, 2024

Superseded by #1660, #1686

@cmatsuoka cmatsuoka closed this May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants