github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/tests/suites/deploy/deploy_charms.sh (about)

     1  # NOTE: when making changes, remember that all the tests here need to be able
     2  # to run on amd64 AND arm64.
     3  
     4  run_deploy_charm() {
     5  	echo
     6  
     7  	file="${TEST_DIR}/test-deploy-charm.log"
     8  
     9  	ensure "test-deploy-charm" "${file}"
    10  
    11  	juju deploy jameinel-ubuntu-lite
    12  	wait_for "ubuntu-lite" "$(idle_condition "ubuntu-lite")"
    13  
    14  	destroy_model "test-deploy-charm"
    15  }
    16  
    17  run_deploy_charm_placement_directive() {
    18  	echo
    19  
    20  	file="${TEST_DIR}/test-deploy-charm-placement-directive.log"
    21  
    22  	ensure "test-deploy-charm-placement-directive" "${file}"
    23  
    24  	juju add-machine --base ubuntu@20.04
    25  	juju deploy jameinel-ubuntu-lite --to 0
    26  	wait_for "ubuntu-lite" "$(idle_condition "ubuntu-lite")"
    27  
    28  	destroy_model "test-deploy-charm-placement-directive"
    29  
    30  }
    31  
    32  run_deploy_charm_unsupported_series() {
    33  	# Test trying to deploy a charmhub charm to an operating system
    34  	# never supported in the specified channel. It should fail.
    35  	echo
    36  
    37  	testname="test-deploy-charm-unsupported-series"
    38  	file="${TEST_DIR}/${testname}.log"
    39  
    40  	ensure "${testname}" "${file}"
    41  
    42  	# The charm in 3.0/stable only supports jammy and only
    43  	# one charm has been released to that channel.
    44  	juju deploy juju-qa-test --channel 3.0/stable --series focal | grep -q 'charm or bundle not found for channel' || true
    45  
    46  	destroy_model "${testname}"
    47  }
    48  
    49  run_deploy_specific_series() {
    50  	echo
    51  
    52  	file="${TEST_DIR}/test-deploy-specific-series.log"
    53  
    54  	ensure "test-deploy-specific-series" "${file}"
    55  
    56  	charm_name="juju-qa-refresher"
    57  	# Have to check against default base, to avoid false positives.
    58  	# These two bases should be different.
    59  	default_base="ubuntu@22.04"
    60  	specific_base="ubuntu@20.04"
    61  
    62  	juju deploy "$charm_name" app1
    63  	juju deploy "$charm_name" app2 --base "$specific_base"
    64  	base_name1=$(juju status --format=json | jq -r ".applications.app1.base.name")
    65  	base_chan1=$(juju status --format=json | jq -r ".applications.app1.base.channel")
    66  	base_name2=$(juju status --format=json | jq -r ".applications.app2.base.name")
    67  	base_chan2=$(juju status --format=json | jq -r ".applications.app2.base.channel")
    68  
    69  	destroy_model "test-deploy-specific-series"
    70  
    71  	echo "$base_name1@$base_chan1" | check "$default_base"
    72  	echo "$base_name2@$base_chan2" | check "$specific_base"
    73  }
    74  
    75  run_deploy_lxd_profile_charm() {
    76  	echo
    77  
    78  	file="${TEST_DIR}/test-deploy-lxd-profile.log"
    79  
    80  	ensure "test-deploy-lxd-profile" "${file}"
    81  
    82  	# This charm deploys to Xenial by default, which doesn't
    83  	# always result in a machine which becomes fully deployed
    84  	# with the lxd provider.
    85  	juju deploy juju-qa-lxd-profile-without-devices --series jammy
    86  	wait_for "lxd-profile-without-devices" "$(idle_condition "lxd-profile-without-devices")"
    87  
    88  	juju status --format=json | jq '.machines | .["0"] | .["lxd-profiles"] | keys[0]' | check "juju-test-deploy-lxd-profile-lxd-profile"
    89  
    90  	destroy_model "test-deploy-lxd-profile"
    91  }
    92  
    93  run_deploy_lxd_profile_charm_container() {
    94  	echo
    95  
    96  	file="${TEST_DIR}/test-deploy-lxd-profile.log"
    97  
    98  	ensure "test-deploy-lxd-profile-container" "${file}"
    99  
   100  	# This charm deploys to Xenial by default, which doesn't
   101  	# always result in a machine which becomes fully deployed
   102  	# with the lxd provider.
   103  	juju deploy juju-qa-lxd-profile-without-devices --to lxd --series jammy
   104  	wait_for "lxd-profile-without-devices" "$(idle_condition "lxd-profile-without-devices")"
   105  
   106  	juju status --format=json | jq '.machines | .["0"] | .containers | .["0/lxd/0"] | .["lxd-profiles"] | keys[0]' |
   107  		check "juju-test-deploy-lxd-profile-container-lxd-profile"
   108  
   109  	destroy_model "test-deploy-lxd-profile-container"
   110  }
   111  
   112  run_deploy_local_predeployed_charm() {
   113  	echo
   114  
   115  	model_name="test-deploy-local-predeployed-charm"
   116  	file="${TEST_DIR}/${model_name}.log"
   117  
   118  	ensure "${model_name}" "${file}"
   119  
   120  	juju deploy ./testcharms/charms/lxd-profile --base ubuntu@22.04
   121  	wait_for "lxd-profile" "$(idle_condition "lxd-profile")"
   122  
   123  	juju deploy local:jammy/lxd-profile-0 another-lxd-profile-app
   124  	wait_for "another-lxd-profile-app" "$(idle_condition "another-lxd-profile-app")"
   125  	wait_for "active" '.applications["another-lxd-profile-app"] | ."application-status".current'
   126  
   127  	destroy_model "${model_name}"
   128  }
   129  
   130  run_deploy_local_lxd_profile_charm() {
   131  	echo
   132  
   133  	file="${TEST_DIR}/test-deploy-local-lxd-profile.log"
   134  
   135  	ensure "test-deploy-local-lxd-profile" "${file}"
   136  
   137  	juju deploy ./testcharms/charms/lxd-profile
   138  	juju deploy ./testcharms/charms/lxd-profile-subordinate
   139  	juju integrate lxd-profile-subordinate lxd-profile
   140  
   141  	wait_for "lxd-profile" "$(idle_condition "lxd-profile")"
   142  	wait_for "lxd-profile-subordinate" ".applications | keys[1]"
   143  
   144  	lxd_profile_name="juju-test-deploy-local-lxd-profile-lxd-profile"
   145  	lxd_profile_sub_name="juju-test-deploy-local-lxd-profile-lxd-profile-subordinate"
   146  
   147  	# subordinates take longer to show, so use wait_for
   148  	machine_0="$(machine_path 0)"
   149  	wait_for "${lxd_profile_sub_name}" "${machine_0}"
   150  
   151  	juju status --format=json | jq "${machine_0}" | check "${lxd_profile_name}"
   152  	juju status --format=json | jq "${machine_0}" | check "${lxd_profile_sub_name}"
   153  
   154  	juju add-unit "lxd-profile"
   155  
   156  	machine_1="$(machine_path 1)"
   157  	wait_for "${lxd_profile_sub_name}" "${machine_1}"
   158  
   159  	juju status --format=json | jq "${machine_1}" | check "${lxd_profile_name}"
   160  	juju status --format=json | jq "${machine_1}" | check "${lxd_profile_sub_name}"
   161  
   162  	destroy_model "test-deploy-local-lxd-profile"
   163  }
   164  
   165  run_deploy_lxd_to_machine() {
   166  	echo
   167  
   168  	model_name="test-deploy-lxd-machine"
   169  	file="${TEST_DIR}/${model_name}.log"
   170  
   171  	ensure "${model_name}" "${file}"
   172  
   173  	juju add-machine -n 2 --series=jammy
   174  
   175  	charm=./tests/suites/deploy/charms/lxd-profile-alt
   176  	juju deploy "${charm}" --to 0 --base ubuntu@22.04
   177  
   178  	# Test the case where we wait for the machine to start
   179  	# before deploying the unit.
   180  	wait_for_machine_agent_status "1" "started"
   181  	juju add-unit lxd-profile-alt --to 1
   182  
   183  	wait_for "lxd-profile-alt" "$(idle_condition "lxd-profile-alt")"
   184  
   185  	lxc profile show "juju-test-deploy-lxd-machine-lxd-profile-alt-0" |
   186  		grep -E "linux.kernel_modules: ([a-zA-Z0-9\_,]+)?ip_tables,ip6_tables([a-zA-Z0-9\_,]+)?"
   187  
   188  	juju refresh "lxd-profile-alt" --path "${charm}"
   189  
   190  	# Ensure that an upgrade will be kicked off. This doesn't mean an upgrade
   191  	# has finished though, just started.
   192  	wait_for "lxd-profile-alt" "$(charm_rev "lxd-profile-alt" 1)"
   193  	wait_for "lxd-profile-alt" "$(idle_condition "lxd-profile-alt")"
   194  
   195  	attempt=0
   196  	while true; do
   197  		OUT=$(lxc profile show "juju-test-deploy-lxd-machine-lxd-profile-alt-1" | grep -E "linux.kernel_modules: ([a-zA-Z0-9\_,]+)?ip_tables,ip6_tables([a-zA-Z0-9\_,]+)?" || echo 'NOT FOUND')
   198  		if [ "${OUT}" != "NOT FOUND" ]; then
   199  			break
   200  		fi
   201  		lxc profile show "juju-test-deploy-lxd-machine-lxd-profile-alt-1"
   202  		attempt=$((attempt + 1))
   203  		if [ $attempt -eq 10 ]; then
   204  			# shellcheck disable=SC2046
   205  			echo $(red "timeout: waiting for lxc profile to show 50sec")
   206  			exit 5
   207  		fi
   208  		sleep 5
   209  	done
   210  
   211  	# Ensure that the old one is removed
   212  	attempt=0
   213  	while true; do
   214  		OUT=$(lxc profile show "juju-test-deploy-lxd-machine-lxd-profile-alt-0" || echo 'NOT FOUND')
   215  		if [[ ${OUT} == "NOT FOUND" ]]; then
   216  			break
   217  		fi
   218  		attempt=$((attempt + 1))
   219  		if [ $attempt -eq 10 ]; then
   220  			# shellcheck disable=SC2046
   221  			echo $(red "timeout: waiting for removal of lxc profile 50sec")
   222  			exit 5
   223  		fi
   224  		sleep 5
   225  	done
   226  
   227  	destroy_model "${model_name}"
   228  }
   229  
   230  run_deploy_lxd_to_container() {
   231  	# Ensure profiles get applied correctly to containers
   232  	# and 1 gets added if a subordinate is added.
   233  	echo
   234  
   235  	model_name="test-deploy-lxd-container"
   236  	file="${TEST_DIR}/${model_name}.log"
   237  
   238  	ensure "${model_name}" "${file}"
   239  
   240  	charm=./tests/suites/deploy/charms/lxd-profile-alt
   241  	juju deploy "${charm}" --to lxd
   242  
   243  	juju deploy ./testcharms/charms/lxd-profile-subordinate
   244  	juju integrate lxd-profile-subordinate lxd-profile-alt
   245  
   246  	wait_for "lxd-profile-alt" "$(idle_condition "lxd-profile-alt")"
   247  	wait_for "lxd-profile-subordinate" ".applications | keys[1]"
   248  
   249  	machine_0="$(machine_container_path 0 0/lxd/0)"
   250  	wait_for "lxd-profile-subordinate" "${machine_0}"
   251  
   252  	lxd_profile_name="juju-test-deploy-lxd-container-lxd-profile-alt"
   253  	lxd_profile_sub_name="juju-test-deploy-lxd-container-lxd-profile-subordinate"
   254  
   255  	juju status --format=json | jq "${machine_0}" | check "${lxd_profile_name}"
   256  	juju status --format=json | jq "${machine_0}" | check "${lxd_profile_sub_name}"
   257  
   258  	OUT=$(juju exec --machine 0 -- sh -c 'sudo lxc profile show "juju-test-deploy-lxd-container-lxd-profile-alt-0"')
   259  	echo "${OUT}" | grep -E "linux.kernel_modules: ([a-zA-Z0-9\_,]+)?ip_tables,ip6_tables([a-zA-Z0-9\_,]+)?"
   260  
   261  	juju refresh "lxd-profile-alt" --path "${charm}"
   262  
   263  	# Ensure that an upgrade will be kicked off. This doesn't mean an upgrade
   264  	# has finished though, just started.
   265  	wait_for "lxd-profile-alt" "$(charm_rev "lxd-profile-alt" 1)"
   266  	wait_for "lxd-profile-alt" "$(idle_condition "lxd-profile-alt")"
   267  
   268  	attempt=0
   269  	while true; do
   270  		OUT=$(juju exec --machine 0 -- sh -c 'sudo lxc profile show "juju-test-deploy-lxd-container-lxd-profile-alt-1"' || echo 'NOT FOUND')
   271  		if echo "${OUT}" | grep -E -q "linux.kernel_modules: ([a-zA-Z0-9\_,]+)?ip_tables,ip6_tables([a-zA-Z0-9\_,]+)?"; then
   272  			break
   273  		fi
   274  		attempt=$((attempt + 1))
   275  		if [ $attempt -eq 10 ]; then
   276  			# shellcheck disable=SC2046
   277  			echo $(red "timeout: waiting for lxc profile to show 50sec")
   278  			exit 5
   279  		fi
   280  		sleep 5
   281  	done
   282  
   283  	# Ensure that the old one is removed
   284  	attempt=0
   285  	while true; do
   286  		OUT=$(juju exec --machine 0 -- sh -c "sudo lxc profile list" || echo 'NOT FOUND')
   287  		if echo "${OUT}" | grep -v "juju-test-deploy-lxd-container-lxd-profile-alt-0"; then
   288  			break
   289  		fi
   290  		attempt=$((attempt + 1))
   291  		if [ $attempt -eq 10 ]; then
   292  			# shellcheck disable=SC2046
   293  			echo $(red "timeout: waiting for removal of lxc profile 50sec")
   294  			exit 5
   295  		fi
   296  		sleep 5
   297  	done
   298  
   299  	destroy_model "${model_name}"
   300  }
   301  
   302  # Checks the install hook resolving with --no-retry flag
   303  run_resolve_charm() {
   304  	echo
   305  
   306  	model_name="test-resolve-charm"
   307  	file="${TEST_DIR}/${model_name}.log"
   308  
   309  	ensure "${model_name}" "${file}"
   310  
   311  	charm=./testcharms/charms/simple-resolve
   312  	juju deploy "${charm}"
   313  
   314  	wait_for "error" '.applications["simple-resolve"] | ."application-status".current'
   315  
   316  	juju resolve --no-retry simple-resolve/0
   317  
   318  	wait_for "No install hook" '.applications["simple-resolve"] | ."application-status".message'
   319  	wait_for "active" '.applications["simple-resolve"] | ."application-status".current'
   320  
   321  	destroy_model "${model_name}"
   322  }
   323  
   324  test_deploy_charms() {
   325  	if [ "$(skip 'test_deploy_charms')" ]; then
   326  		echo "==> TEST SKIPPED: deploy charms"
   327  		return
   328  	fi
   329  
   330  	(
   331  		set_verbosity
   332  
   333  		cd .. || exit
   334  
   335  		run "run_deploy_charm"
   336  		run "run_deploy_charm_placement_directive"
   337  		run "run_deploy_specific_series"
   338  		run "run_resolve_charm"
   339  		run "run_deploy_charm_unsupported_series"
   340  
   341  		case "${BOOTSTRAP_PROVIDER:-}" in
   342  		"lxd" | "localhost")
   343  			run "run_deploy_lxd_to_machine"
   344  			run "run_deploy_lxd_profile_charm"
   345  			run "run_deploy_local_predeployed_charm"
   346  			run "run_deploy_local_lxd_profile_charm"
   347  			echo "==> TEST SKIPPED: deploy_lxd_to_container - tests for non LXD only"
   348  			echo "==> TEST SKIPPED: deploy_lxd_profile_charm_container - tests for non LXD only"
   349  			;;
   350  		*)
   351  			echo "==> TEST SKIPPED: deploy_lxd_to_machine - tests for LXD only"
   352  			echo "==> TEST SKIPPED: deploy_lxd_profile_charm - tests for LXD only"
   353  			echo "==> TEST SKIPPED: deploy_local_lxd_profile_charm - tests for LXD only"
   354  			run "run_deploy_lxd_to_container"
   355  			run "run_deploy_lxd_profile_charm_container"
   356  			;;
   357  		esac
   358  	)
   359  }
   360  
   361  machine_path() {
   362  	local machine
   363  
   364  	machine=${1}
   365  
   366  	echo ".machines | .[\"${machine}\"] | .[\"lxd-profiles\"] | keys"
   367  }
   368  
   369  machine_container_path() {
   370  	local machine container
   371  
   372  	machine=${1}
   373  	container=${2}
   374  
   375  	echo ".machines | .[\"${machine}\"] | .containers | .[\"${container}\"] | .[\"lxd-profiles\"] | keys"
   376  }