MAAS Show and Tell: Test scripts with Lee

Here’s another MAAS show and tell session, where Lee explains test scripts and how to use them:

The script’s shown in Lee’s presentation can be seen below. More information about writing custom commissioning scripts can be found at in the MAAS docs.

basic.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: basic
# title: This is a basic testing script
# description: This is a very basic testing script used for demoing
# tags: [demo, commissioning]
# script_type: testing
# timeout: 5
# hardware_type: cpu
# --- End MAAS 1.0 script metadata ---

echo "Hello stdout"
echo "Hello stderr" >&2

storage-param.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: storage-param
# title: This is a basic testing script with a storage param
# description: This is a very basic testing script used for demoing a storage param
# tags: [demo, commissioning]
# script_type: testing
# timeout: 5
# # Don't allow script to run on deployed systems as this test may overwrite data.
# destructive: True
# hardware_type: storage
# # instance means run one instance of this script per storage device in parallel
# parallel: instance
# parameters:
#   # storage_param is the name of the argument
#   storage_param:
#     type: storage
#     # argument_format isn't required, defaults to --storage={path}
#     argument_format: '{name} {path} {input} {model} {serial}'
# --- End MAAS 1.0 script metadata ---

echo "Testing $@..."
sudo hdparm -i $2

interface-param.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: interface-param
# title: This is a basic testing script with an interface param
# description: This is a very basic testing script used for demoing an interface param
# tags: [demo, commissioning]
# script_type: testing
# timeout: 5
# hardware_type: network
# # instance means run one instance of this script per interface in parallel
# parallel: instance
# parameters:
#   nic_param:
#     type: interface
#     # argument_format isn't required, defaults to --interface={name}
#     argument_format: '{name} {mac_address} {product} {vendor}'
#   url:
#     type: url
#     # description is shown in the UI
#     description: The URL to use with this test script
#     # The default value of the parameter. URLs don't have a built in default
#     # storage and interface parameters both default to 'all' which is a placeholder
#     # telling MAAS to run the test on all storage devices or interfaces.
#     default: https://example.com
#     # Whether or not the field is required. URL's default to False while storage and interface
#     # parameters default to True. If False and no input is given the parameter is not passed.
#     required: True
#     # Allow a comma separated list of URLs to be passed, e.g maas.io,ubuntu.com
#     allow_list: True
# # Apply all user configured networking options while the test is running. MAAS will ensure
# # network configuration is reset between test runs.
# apply_configured_networking: True
# --- End MAAS 1.0 script metadata ---

echo "Testing $@..."
ip addr show dev $1

result.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: result
# title: This is a basic testing script which results results
# description: This is a very basic testing script used for demoing results
# tags: [demo, commissioning]
# script_type: testing
# # When giving results the results metadata is optional. If these are not given
# # the result name is used in the otherwise and no tooltip is generated.
# results:
#   kernel:
#     title: Kernel
#     description: The kernel this test is running on
# --- End MAAS 1.0 script metadata ---

uname -a
if [ -n "$RESULT_PATH" ]; then
    echo "{results: {kernel: $(uname -r)}}" >> $RESULT_PATH
fi

skipped.sh

#!/bin/bash
# --- Start MAAS 1.0 script metadata ---
# name: skipped
# title: This is a basic testing script which is skipped
# description: This is a very basic testing script used for demoing skipping
# tags: [demo, commissioning]
# script_type: testing
# timeout: 5
# --- End MAAS 1.0 script metadata ---

echo "Unable to run this test!"

if [ -n "$RESULT_PATH" ]; then
    # Status can also be passed, failed, degraded, or timedout
    echo "{status: skipped}" >> $RESULT_PATH
fi

Please add any comments or questions to this post. Hope you enjoy it!

2 Likes

This is coooooooooooool!

2 Likes

@dvnt, did you see the one on commissioning scripts? MAAS Show and Tell: Commissioning Scripts; Discourse Automation Tools

please ignore my very ham-handed and unprepared following act on doc stuff. i really wasn’t ready.

1 Like

Nicely done, very helpful. Perhaps it’s my aging eyes, but I would have found it somewhat better if these videos cut /eliminate the live camera feed (it’s nice to see the speaker to start, but having the code larger would have made following some details easier).