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

     1  test_deploy_and_remove_application() {
     2  	echo
     3  
     4  	# Ensure that a valid Juju controller exists
     5  	model_name="controller-model-sidecar"
     6  	file="${TEST_DIR}/test-${model_name}.log"
     7  	ensure "${model_name}" "${file}"
     8  
     9  	# Deploy snappass-test application
    10  	juju deploy snappass-test
    11  	wait_for "active" '.applications["snappass-test"]["application-status"].current'
    12  	wait_for "active" '.applications["snappass-test"].units["snappass-test/0"]["workload-status"].current'
    13  
    14  	# Check that it's properly responding
    15  	check_snappass
    16  
    17  	# Remove application
    18  	juju remove-application snappass-test --no-prompt
    19  	wait_for "0" '.applications | length'
    20  
    21  	# Clean up model
    22  	destroy_model "${model_name}"
    23  }
    24  
    25  test_deploy_and_force_remove_application() {
    26  	echo
    27  
    28  	# Ensure that a valid Juju controller exists
    29  	model_name="controller-model-sidecar"
    30  	file="${TEST_DIR}/test-${model_name}.log"
    31  	ensure "${model_name}" "${file}"
    32  
    33  	# Deploy snappass-test application
    34  	juju deploy snappass-test
    35  	wait_for "active" '.applications["snappass-test"]["application-status"].current'
    36  	wait_for "active" '.applications["snappass-test"].units["snappass-test/0"]["workload-status"].current'
    37  
    38  	# Check that it's properly responding
    39  	check_snappass
    40  
    41  	# Remove application with --force
    42  	juju remove-application snappass-test --force --no-prompt
    43  	wait_for "0" '.applications | length'
    44  
    45  	# Clean up model
    46  	destroy_model "${model_name}"
    47  }
    48  
    49  # Check that snappass-test is properly responding
    50  # Allow multiple attempts, as it could fail initially if we try to connect
    51  # before it's ready
    52  check_snappass() {
    53  	attempt=1
    54  	while true; do
    55  		address=$(juju status --format=json | jq -r '.applications["snappass-test"].units["snappass-test/0"].address')
    56  		if curl "http://${address}:5000" | grep Snappass; then
    57  			break
    58  		fi
    59  		if [[ ${attempt} -ge 3 ]]; then
    60  			echo "Failed to connect to application"
    61  			exit 1
    62  		fi
    63  		attempt=$((attempt + 1))
    64  		sleep 5
    65  	done
    66  }
    67  
    68  test_pebble_notices() {
    69  	echo
    70  
    71  	# Ensure that a valid Juju controller exists
    72  	model_name="controller-model-sidecar"
    73  	file="${TEST_DIR}/test-${model_name}.log"
    74  	ensure "${model_name}" "${file}"
    75  
    76  	# Deploy Pebble Notices test application
    77  	juju deploy juju-qa-pebble-notices
    78  	wait_for "active" '.applications["juju-qa-pebble-notices"].units["juju-qa-pebble-notices/0"]["workload-status"].current'
    79  
    80  	# Check that it's responding to new notices
    81  	juju ssh --container redis juju-qa-pebble-notices/0 /charm/bin/pebble notify foo.com/bar key=val
    82  	wait_for "maintenance" '.applications["juju-qa-pebble-notices"].units["juju-qa-pebble-notices/0"]["workload-status"].current'
    83  	wait_for "notice type=custom key=foo.com/bar" '.applications["juju-qa-pebble-notices"].units["juju-qa-pebble-notices/0"]["workload-status"].message'
    84  
    85  	juju ssh --container redis juju-qa-pebble-notices/0 /charm/bin/pebble notify example.com/bazz key=val
    86  	wait_for "maintenance" '.applications["juju-qa-pebble-notices"].units["juju-qa-pebble-notices/0"]["workload-status"].current'
    87  	wait_for "notice type=custom key=example.com/bazz" '.applications["juju-qa-pebble-notices"].units["juju-qa-pebble-notices/0"]["workload-status"].message'
    88  
    89  	# Clean up model
    90  	destroy_model "${model_name}"
    91  }