Skip to content

Commit

Permalink
Merge pull request juju#18211 from Aflynn50/fix-local-charm-test
Browse files Browse the repository at this point in the history
juju#18211

The local charm integration tests relied on the ntp charm which was not up to date with the latest charm requrements and caused an error on deploy. It was held in launchpad and not under our control.

Switch to using the ubuntu-plus charm instead from test testcharms directory.

Note that these tests deploy from directory so will not work in 4.0. They will need to be updated or maybe even just deleted when the patch is merged up. If they are kept they should use the work added in juju#18151.

BONUS COMMIT: add big V verbose option
<!-- 
The PR title should match: <type>(optional <scope>): <description>.

Please also ensure all commits in this PR comply with our conventional commits specification:
https://docs.google.com/document/d/1SYUo9G7qZ_jdoVXpUVamS5VCgHmtZ0QA-wZxKoMS-C0 
-->

<!-- Why this change is needed and what it does. -->

## Checklist

<!-- If an item is not applicable, use `~strikethrough~`. -->

- [x] Code style: imports ordered, good names, simple structure, etc
- [x] Comments saying why design decisions were made
- [x] Go unit tests, with comments saying what you're testing
- [x] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing
- [ ] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages

## QA steps
```
./main.sh -v cli
```
  • Loading branch information
jujubot authored Oct 10, 2024
2 parents 202a96c + ac3917d commit 66abfe3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 50 deletions.
5 changes: 5 additions & 0 deletions tests/includes/verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ set_verbosity() {
set -eu
set -o pipefail
;;
11)
# You asked for it!
set -eux
set -o pipefail
;;
*)
echo "Unexpected verbose level" >&2
exit 1
Expand Down
8 changes: 7 additions & 1 deletion tests/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ show_help() {
echo ""
echo " $(green './main.sh -h') Display this help message"
echo " $(green './main.sh -v') Verbose and debug messages"
echo " $(green './main.sh -V') Verbose and debug messages with all commands printed"
echo " $(green './main.sh -A') Run all the test suites"
echo " $(green './main.sh -s') Skip tests using a comma seperated list"
echo " $(green './main.sh -a') Create an artifact file"
Expand Down Expand Up @@ -161,7 +162,7 @@ show_help() {
exit 1
}

while getopts "hH?vAs:a:x:rl:p:c:R:S:" opt; do
while getopts "hH?vAs:a:x:rl:p:c:R:S:V" opt; do
case "${opt}" in
h | \?)
show_help
Expand All @@ -174,6 +175,11 @@ while getopts "hH?vAs:a:x:rl:p:c:R:S:" opt; do
# shellcheck disable=SC2262
alias juju="juju --debug"
;;
V)
VERBOSE=11
# shellcheck disable=SC2262
alias juju="juju --debug"
;;
A)
RUN_ALL="true"
;;
Expand Down
109 changes: 60 additions & 49 deletions tests/suites/cli/local_charms.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# Copyright 2024 Canonical Ltd.
# Licensed under the AGPLv3, see LICENCE file for details.

# Checks whether the cwd is used for the juju local deploy.
run_deploy_local_charm_revision() {
echo

file="${TEST_DIR}/local-charm-deploy-git.log"
ensure "local-charm-deploy" "${file}"

# Get a basic charm
TMP=$(mktemp -d -t ci-XXXXXXXXXX)
cp -r "$CURRENT_DIR/../testcharms/charms/ubuntu-plus" "${TMP}"
cd "${TMP}/ubuntu-plus" || exit 1

cd "${TMP}" || exit 1
git clone --depth=1 --quiet https://git.launchpad.net/ntp-charm ntp
cd "${TMP}/ntp" || exit 1
SHA_OF_NTP=\"$(git describe --dirty --always)\"

OUTPUT=$(juju deploy . 2>&1)
# Initialise a git repo to check the commit SHA is used as the charm version.
git init
git add . && git commit -m "commit everything"
SHA_OF_UBUNTU_PLUS=\"$(git describe --dirty --always)\"

wait_for "ntp" ".applications | keys[0]"
CURRENT_CHARM_SHA=$(juju status --format=json | jq '.applications.ntp."charm-version"')
# Deploy from directory.
juju deploy .

# If a error happens it means it could not use the git sha of the CWD.
check_not_contains "${OUTPUT}" "exit status 128"
wait_for "ubuntu-plus" ".applications | keys[0]"
CURRENT_CHARM_SHA=$(juju status --format=json | jq '.applications."ubuntu-plus"."charm-version"')

if [ "${SHA_OF_NTP}" != "${CURRENT_CHARM_SHA}" ]; then
if [ "${SHA_OF_UBUNTU_PLUS}" != "${CURRENT_CHARM_SHA}" ]; then
echo "The expected sha does not equal the ntp SHA"
exit 1
fi
Expand All @@ -35,14 +39,13 @@ run_deploy_local_charm_revision_no_vcs() {
file="${TEST_DIR}/local-charm-deploy-no-vcs.log"
ensure "local-charm-deploy-no-vcs" "${file}"

# Get a basic charm, there should be no VCS info in this file.
TMP=$(mktemp -d -t ci-XXXXXXXXXX)
cp -r "$CURRENT_DIR/../testcharms/charms/ubuntu-plus" "${TMP}"
cd "${TMP}/ubuntu-plus" || exit 1

cd "${TMP}" || exit 1
git clone --depth=1 --quiet https://git.launchpad.net/ntp-charm ntp
cd "${TMP}/ntp" || exit 1
rm -rf .git
# make sure that no version file exists.
rm -f version
# Remove version file
rm version

OUTPUT=$(juju deploy --debug . 2>&1)

Expand All @@ -58,26 +61,22 @@ run_deploy_local_charm_revision_no_vcs_but_version_file() {
file="${TEST_DIR}/local-charm-deploy-version-file.log"
ensure "local-charm-deploy-version-file" "${file}"

# Get a basic charm, there should be no VCS info in this file.
TMP=$(mktemp -d -t ci-XXXXXXXXXX)
cp -r "$CURRENT_DIR/../testcharms/charms/ubuntu-plus" "${TMP}"
cd "${TMP}/ubuntu-plus" || exit 1

cd "${TMP}" || exit 1
git clone --depth=1 --quiet https://git.launchpad.net/ntp-charm ntp
cd "${TMP}/ntp" || exit 1
rm -rf .git
touch version
echo 123 >version
VERSION_OUTPUT=\""$(cat version)"\"

VERSION_OUTPUT=\""$(cat version | sed 's/.* //')"\"
CURRENT_DIRECTORY=$(pwd)

# this is done relative because we expect that the output will be absolute in the end.
OUTPUT=$(juju deploy --debug . 2>&1)

wait_for "ntp" ".applications | keys[0]"
CURRENT_CHARM_SHA=$(juju status --format=json | jq '.applications.ntp."charm-version"')
wait_for "ubuntu-plus" ".applications | keys[0]"
CURRENT_CHARM_SHA=$(juju status --format=json | jq '.applications."ubuntu-plus"."charm-version"')

if [ "${VERSION_OUTPUT}" != "${CURRENT_CHARM_SHA}" ]; then
echo "The expected sha does not equal the ntp SHA. Current sha: ${CURRENT_CHARM_SHA} expected sha: ${VERSION_OUTPUT}"
echo "The expected sha does not equal the ubuntu-plus SHA. Current sha: ${CURRENT_CHARM_SHA} expected sha: ${VERSION_OUTPUT}"
exit 1
fi

Expand All @@ -95,32 +94,40 @@ run_deploy_local_charm_revision_relative_path() {

ensure "relative-path" "${file}"

# Get a basic charm
TMP=$(mktemp -d -t ci-XXXXXXXXXX)
cp -r "$CURRENT_DIR/../testcharms/charms/ubuntu-plus" "${TMP}"
cd "${TMP}/ubuntu-plus" || exit 1

cd "${TMP}" || exit 1
# Initialise a git repo and commit everything so that commit SHA is used as the charm version.
git init
git add . && git commit -m "commit everything"
SHA_OF_UBUNTU_PLUS=\"$(git describe --dirty --always)\"

# Create git directory outside the charm directory
cd ..
create_local_git_folder
SHA_OF_TMP=\"$(git describe --dirty --always)\"
# create ${TMP}/ntp git folder
git clone --depth=1 --quiet https://git.launchpad.net/ntp-charm ntp

# state: ${TMP} is wrong git ${TMP}/ntp is correct git
juju deploy ./ntp 2>&1
# state: there is a git repo in the current directory, $TMP, but the correct
# git repo is in $TMP/ubuntu-plus.
juju deploy ./ubuntu-plus 2>&1

cd "${TMP}/ntp" || exit 1
SHA_OF_NTP=\"$(git describe --dirty --always)\"
cd "${TMP}/ubuntu-plus" || exit 1
SHA_OF_UBUNTU_PLUS=\"$(git describe --dirty --always)\"

wait_for "ntp" ".applications | keys[0]"
wait_for "ubuntu-plus" ".applications | keys[0]"

# We still expect the SHA to be the one from the place we deploy and not the CWD, which in this case has no SHA
CURRENT_CHARM_SHA=$(juju status --format=json | jq '.applications.ntp."charm-version"')
CURRENT_CHARM_SHA=$(juju status --format=json | jq '.applications."ubuntu-plus"."charm-version"')

if [ "${SHA_OF_TMP}" = "${CURRENT_CHARM_SHA}" ]; then
echo "The expected sha should not equal the tmp SHA. Current sha: ${CURRENT_CHARM_SHA}"
exit 1
fi

if [ "${SHA_OF_NTP}" != "${CURRENT_CHARM_SHA}" ]; then
echo "The expected sha does not equal the ntp SHA. Current sha: ${CURRENT_CHARM_SHA} expected sha: ${SHA_OF_NTP}"
if [ "${SHA_OF_UBUNTU_PLUS}" != "${CURRENT_CHARM_SHA}" ]; then
echo "The expected sha does not equal the ntp SHA. Current sha: ${CURRENT_CHARM_SHA} expected sha: ${SHA_OF_UBUNTU_PLUS}"
exit 1
fi

Expand All @@ -137,24 +144,28 @@ run_deploy_local_charm_revision_invalid_git() {
TMP_CHARM_GIT=$(mktemp -d -t ci-XXXXXXXXXX)
TMP=$(mktemp -d -t ci-XXXXXXXXXX)

cd "${TMP_CHARM_GIT}" || exit 1
git clone --depth=1 --quiet https://git.launchpad.net/ntp-charm ntp
# Get a basic charm
cp -r "$CURRENT_DIR/../testcharms/charms/ubuntu-plus" "${TMP_CHARM_GIT}"
cd "${TMP_CHARM_GIT}/ubuntu-plus" || exit 1

# Initialise a git repo and commit everything so that commit SHA is used as the charm version.
git init
git add . && git commit -m "commit everything"
SHA_OF_UBUNTU_PLUS=\"$(git describe --dirty --always)\"

cd "${TMP_CHARM_GIT}/ntp" || exit 1
WANTED_CHARM_SHA=\"$(git describe --dirty --always)\"

# We cd into a folder without git and deploy from the folder without git.
# We cd into a folder without git, add an unrelated repo there.
cd "${TMP}" || exit 1

create_local_git_folder
# Deploy from the correct repo
juju deploy "${TMP_CHARM_GIT}"/ubuntu-plus

juju deploy "${TMP_CHARM_GIT}"/ntp ntp

wait_for "ntp" ".applications | keys[0]"
wait_for "ubuntu-plus" ".applications | keys[0]"
# We still expect the SHA to be the one from the place we deploy and not the CWD, which in this case has no SHA.
CURRENT_CHARM_SHA=$(juju status --format=json | jq '.applications.ntp."charm-version"')
CURRENT_CHARM_SHA=$(juju status --format=json | jq '.applications."ubuntu-plus"."charm-version"')
if [ "${WANTED_CHARM_SHA}" != "${CURRENT_CHARM_SHA}" ]; then
echo "The expected sha does not equal the ntp SHA. Current sha: ${CURRENT_CHARM_SHA} expected sha: ${WANTED_CHARM_SHA}"
echo "The expected sha does not equal the ubuntu-plus SHA. Current sha: ${CURRENT_CHARM_SHA} expected sha: ${WANTED_CHARM_SHA}"
exit 1
fi

Expand Down

0 comments on commit 66abfe3

Please sign in to comment.