Merge ~paride/autopkgtest-cloud:lint-shellscripts into autopkgtest-cloud:master

Proposed by Paride Legovini
Status: Merged
Approved by: Tim Andersson
Approved revision: ef73341a1cf9f455d77cc93d9b58c45530253045
Merged at revision: ef73341a1cf9f455d77cc93d9b58c45530253045
Proposed branch: ~paride/autopkgtest-cloud:lint-shellscripts
Merge into: autopkgtest-cloud:master
Diff against target: 341 lines (+61/-52)
12 files modified
.launchpad.yaml (+8/-0)
.pre-commit-config.yaml (+5/-0)
charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/build-adt-image (+11/-10)
charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-nova-image-new-release (+19/-20)
charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-test-instances (+1/-1)
charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/ensure-keypair (+5/-4)
charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/exec-in-region (+2/-1)
charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh (+2/-0)
ci/lint_test (+0/-8)
lxc-slave-admin/cmd (+5/-5)
mojo/make-lxd-secgroup (+1/-1)
mojo/postdeploy (+2/-2)
Reviewer Review Type Date Requested Status
Tim Andersson Approve
Review via email: mp+445422@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Paride Legovini (paride) wrote :

WIP branch to work at linting with Tim.

Revision history for this message
Tim Andersson (andersson123) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/.launchpad.yaml b/.launchpad.yaml
index b08e2c3..a744b71 100755
--- a/.launchpad.yaml
+++ b/.launchpad.yaml
@@ -1,8 +1,16 @@
1pipeline:1pipeline:
2 - pre_commit
2 - build_charms3 - build_charms
3 - lint_test4 - lint_test
45
5jobs:6jobs:
7 pre_commit:
8 series: jammy
9 architectures: amd64
10 packages:
11 - git
12 - pre-commit
13 run: pre-commit run --all-files --show-diff-on-failure
6 build_charms:14 build_charms:
7 series: focal15 series: focal
8 architectures: amd6416 architectures: amd64
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
9new file mode 10064417new file mode 100644
index 0000000..eb05b79
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,5 @@
1repos:
2 - repo: https://github.com/shellcheck-py/shellcheck-py
3 rev: v0.9.0.5
4 hooks:
5 - id: shellcheck
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/build-adt-image b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/build-adt-image
index be6b4d3..a0ad87a 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/build-adt-image
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/build-adt-image
@@ -1,10 +1,11 @@
1#!/bin/bash1#!/bin/bash
2# Build adt cloud images with create-nova-image-new-release for the given2# Build adt cloud images with create-nova-image-new-release for the given
3# cloud, release and arch3# cloud, release and arch
4# shellcheck disable=SC1090
45
5set -eu6set -eu
67
7IFS="[- ]" read -r RELEASE REGION ARCH bootstrap <<< "$@"8IFS="[- ]" read -r RELEASE REGION ARCH _bootstrap <<< "$@"
89
9if [ -z "${RELEASE}" ] || [ -z "${REGION}" ] || [ -z "${ARCH}" ]; then10if [ -z "${RELEASE}" ] || [ -z "${REGION}" ] || [ -z "${ARCH}" ]; then
10 echo "Usage: $0 RELEASE REGION ARCH" >&211 echo "Usage: $0 RELEASE REGION ARCH" >&2
@@ -12,8 +13,8 @@ if [ -z "${RELEASE}" ] || [ -z "${REGION}" ] || [ -z "${ARCH}" ]; then
12fi13fi
1314
14if [ -z "${MIRROR:-}" ]; then15if [ -z "${MIRROR:-}" ]; then
15 if [ -e ~/mirror-${REGION}.rc ]; then16 if [ -e ~/mirror-"${REGION}".rc ]; then
16 . ~/mirror-${REGION}.rc17 . ~/mirror-"${REGION}".rc
17 else18 else
18 . ~/mirror.rc19 . ~/mirror.rc
19 fi20 fi
@@ -24,10 +25,10 @@ export MIRROR
24export NET_NAME25export NET_NAME
2526
26if [ -z "${USE_CLOUD_CONFIG_FROM_ENV:-}" ]; then27if [ -z "${USE_CLOUD_CONFIG_FROM_ENV:-}" ]; then
27 if [ -e ~/cloudrcs/${REGION}-${ARCH}.rc ]; then28 if [ -e ~/cloudrcs/"${REGION}"-"${ARCH}".rc ]; then
28 . ~/cloudrcs/${REGION}-${ARCH}.rc29 . ~/cloudrcs/"${REGION}"-"${ARCH}".rc
29 else30 else
30 . ~/cloudrcs/${REGION}.rc31 . ~/cloudrcs/"${REGION}".rc
31 fi32 fi
32fi33fi
3334
@@ -73,11 +74,11 @@ fi
7374
74echo "$REGION-$ARCH: using image $IMG"75echo "$REGION-$ARCH: using image $IMG"
75KEYNAME=${KEYNAME:-testbed-$(hostname)}76KEYNAME=${KEYNAME:-testbed-$(hostname)}
76$(dirname $0)/create-nova-image-new-release $RELEASE $ARCH $IMG "${KEYNAME}" "$IMAGE_NAME"77"$(dirname "${0}")/create-nova-image-new-release" "${RELEASE}" "${ARCH}" "${IMG}" "${KEYNAME}" "${IMAGE_NAME}"
77# clean old images78# clean old images
78openstack image list --private -f value | grep --color=none -v "$IMAGE_NAME" | while read id img state; do79openstack image list --private -f value | grep --color=none -v "$IMAGE_NAME" | while read -r id img state; do
79 if $(echo ${img} | grep -qs "adt/ubuntu-${RELEASE}-${ARCH}") && [ ${state} = active ]; then80 if echo "${img}" | grep -qs "adt/ubuntu-${RELEASE}-${ARCH}" && [ "${state}" = active ]; then
80 echo "Cleaning up old image $img ($id)"81 echo "Cleaning up old image $img ($id)"
81 openstack image delete $id82 openstack image delete "${id}"
82 fi83 fi
83done84done
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-nova-image-new-release b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-nova-image-new-release
index bc51ff1..349c217 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-nova-image-new-release
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-nova-image-new-release
@@ -1,6 +1,7 @@
1#!/bin/bash1#!/bin/bash
2# create an autopkgtest nova image for a new release, based on a generic image2# create an autopkgtest nova image for a new release, based on a generic image
3# Author: Martin Pitt <martin.pitt@ubuntu.com>3# Author: Martin Pitt <martin.pitt@ubuntu.com>
4# shellcheck disable=SC2154
4set -eu5set -eu
5RELEASE="${1:-}"6RELEASE="${1:-}"
6ARCH="${2:-}"7ARCH="${2:-}"
@@ -48,9 +49,9 @@ else
48fi49fi
4950
50# unbreak my server option :-(51# unbreak my server option :-(
51userdata=`mktemp`52userdata=$(mktemp)
52trap "rm $userdata" EXIT TERM INT QUIT PIPE53trap 'rm ${userdata}' EXIT TERM INT QUIT PIPE
53cat <<EOF > $userdata54cat <<EOF > "${userdata}"
54#cloud-config55#cloud-config
5556
56manage_etc_hosts: true57manage_etc_hosts: true
@@ -67,13 +68,13 @@ EOF
6768
68# create new instance69# create new instance
69INSTNAME="${BASEIMG}-adt-prepare"70INSTNAME="${BASEIMG}-adt-prepare"
70eval "$(openstack network show -f shell ${NET_NAME})"71eval "$(openstack network show -f shell "${NET_NAME}")"
7172
72NET_ID=${id}73NET_ID="${id}"
7374
74retries=2075retries=20
75while true; do76while true; do
76 eval "$(openstack server create -f shell --flavor autopkgtest --image $BASEIMG --user-data $userdata --key-name $KEYNAME --wait $INSTNAME --nic net-id=${NET_ID})"77 eval "$(openstack server create -f shell --flavor autopkgtest --image "${BASEIMG}" --user-data "${userdata}" --key-name "${KEYNAME}" --wait "${INSTNAME}" --nic net-id="${NET_ID}")"
77 if openstack server show "${id}" >/dev/null 2>/dev/null; then78 if openstack server show "${id}" >/dev/null 2>/dev/null; then
78 break79 break
79 fi80 fi
@@ -90,27 +91,25 @@ done
9091
91SRVID="${id}"92SRVID="${id}"
9293
93trap "openstack server delete ${SRVID}" EXIT TERM INT QUIT PIPE94trap 'openstack server delete ${SRVID}' EXIT TERM INT QUIT PIPE
9495
95# determine IP address96# determine IP address
96eval "$(openstack server show -f shell ${SRVID})"97eval "$(openstack server show -f shell "${SRVID}")"
97ipaddr=$(echo ${addresses} | awk 'BEGIN { FS="=" } { print $2 }')98ipaddr=$(echo "${addresses}" | awk 'BEGIN { FS="=" } { print $2 }')
9899
99SSH_CMD="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$ipaddr"100SSH_CMD="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$ipaddr"
100echo "Waiting for ssh (may cause some error messages)..."101echo "Waiting for ssh (may cause some error messages)..."
101timeout 300 sh -c "while ! $SSH_CMD true; do sleep 5; done"102timeout 300 sh -c "while ! $SSH_CMD true; do sleep 5; done"
102103
103echo "Waiting until cloud-init is done..."104echo "Waiting until cloud-init is done..."
104timeout 25m $SSH_CMD 'while [ ! -e /var/lib/cloud/instance/boot-finished ]; do sleep 1; done'105timeout 25m "${SSH_CMD}" 'while [ ! -e /var/lib/cloud/instance/boot-finished ]; do sleep 1; done'
105106
106echo "Running setup script..."107echo "Running setup script..."
107cat "${SETUP_TESTBED}" | $SSH_CMD "sudo env MIRROR='${MIRROR:-}' RELEASE='$RELEASE' sh -"108"${SSH_CMD}" "sudo env MIRROR='${MIRROR:-}' RELEASE='$RELEASE' sh -" < "${SETUP_TESTBED}"
108109
109echo "Running Canonical setup script..."110echo "Running Canonical setup script..."
110CANONICAL_SCRIPT=$(dirname $(dirname $(readlink -f $0)))/worker-config-production/setup-canonical.sh111CANONICAL_SCRIPT="$(dirname "$(dirname "$(readlink -f "${0}")")")"/worker-config-production/setup-canonical.sh
111cat "$CANONICAL_SCRIPT" | $SSH_CMD "sudo env MIRROR='${MIRROR:-}' RELEASE='$RELEASE' sh -"112"${SSH_CMD}" "sudo env MIRROR='${MIRROR:-}' RELEASE='$RELEASE' sh -" < "${CANONICAL_SCRIPT}"
112
113arch=$($SSH_CMD dpkg --print-architecture)
114113
115echo "Check that the upgraded image boots..."114echo "Check that the upgraded image boots..."
116while true; do115while true; do
@@ -138,10 +137,10 @@ $SSH_CMD sudo journalctl --rotate --vacuum-time=12h || true
138137
139echo "Powering off to get a clean file system..."138echo "Powering off to get a clean file system..."
140$SSH_CMD sudo poweroff || true139$SSH_CMD sudo poweroff || true
141eval "$(openstack server show -f shell ${SRVID})"140eval "$(openstack server show -f shell "${SRVID}")"
142while [ ${os_ext_sts_vm_state} != "stopped" ]; do141while [ "${os_ext_sts_vm_state}" != "stopped" ]; do
143 sleep 1142 sleep 1
144 eval "$(openstack server show -f shell ${SRVID})"143 eval "$(openstack server show -f shell "${SRVID}")"
145done144done
146145
147echo "Creating image $IMAGE_NAME ..."146echo "Creating image $IMAGE_NAME ..."
@@ -155,8 +154,8 @@ while true; do
155 while [ $inner_retries -gt 0 ]; do154 while [ $inner_retries -gt 0 ]; do
156 # server image create often loses its connection but it's actually155 # server image create often loses its connection but it's actually
157 # working - if the image is uploading, wait a bit for it to finish156 # working - if the image is uploading, wait a bit for it to finish
158 eval $(openstack image show -f shell --prefix=image_ "${IMAGE_NAME}")157 eval "$(openstack image show -f shell --prefix=image_ "${IMAGE_NAME}")"
159 eval $(openstack server show -f shell --prefix=server_ "${SRVID}")158 eval "$(openstack server show -f shell --prefix=server_ "${SRVID}")"
160 if [ "${server_os_ext_sts_task_state}" = "image_uploading" ] ||159 if [ "${server_os_ext_sts_task_state}" = "image_uploading" ] ||
161 [ "${image_status}" = "saving" ]; then160 [ "${image_status}" = "saving" ]; then
162 echo "image ${IMAGE_NAME} is uploading, waiting..." >&2161 echo "image ${IMAGE_NAME} is uploading, waiting..." >&2
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-test-instances b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-test-instances
index 6730c03..450ea83 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-test-instances
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/create-test-instances
@@ -13,5 +13,5 @@ IMAGE=$(openstack image list | grep "adt/ubuntu-$DEVEL-$ARCH" | cut -d' ' -f2)
13NET_ID=$(openstack network list | grep 'net_prod-proposed-migration' | cut -d' ' -f2)13NET_ID=$(openstack network list | grep 'net_prod-proposed-migration' | cut -d' ' -f2)
1414
15for i in $(seq 1 10); do15for i in $(seq 1 10); do
16 openstack server create --image $IMAGE --flavor cpu4-ram8-disk50 --nic net-id=$NET_ID -- "creation-test-$ARCH-$i"16 openstack server create --image "${IMAGE}" --flavor cpu4-ram8-disk50 --nic net-id="${NET_ID}" -- "creation-test-$ARCH-$i"
17done17done
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/ensure-keypair b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/ensure-keypair
index be664d6..4ef1daa 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/ensure-keypair
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/ensure-keypair
@@ -2,12 +2,13 @@
22
3set -eu3set -eu
44
5IFS="[- ]" read -r RELEASE REGION ARCH bootstrap <<< "$@"5IFS="[- ]" read -r _RELEASE REGION ARCH _bootstrap <<< "$@"
66
7if [ -e ~/cloudrcs/${REGION}-${ARCH}.rc ]; then7# shellcheck disable=SC1090
8 . ~/cloudrcs/${REGION}-${ARCH}.rc8if [ -e ~/cloudrcs/"${REGION}"-"${ARCH}".rc ]; then
9 . ~/cloudrcs/"${REGION}"-"${ARCH}".rc
9else10else
10 . ~/cloudrcs/${REGION}.rc11 . ~/cloudrcs/"${REGION}".rc
11fi12fi
1213
13if ! [ -e "${HOME}/.ssh/id_rsa" ]; then14if ! [ -e "${HOME}/.ssh/id_rsa" ]; then
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/exec-in-region b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/exec-in-region
index 0261108..2e78e83 100755
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/exec-in-region
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/tools/exec-in-region
@@ -1,5 +1,6 @@
1#!/bin/sh1#!/bin/sh
2# usage: exec-in-region <region name> <command> <argument>...2# usage: exec-in-region <region name> <command> <argument>...
3# shellcheck disable=SC1090
34
4set -e5set -e
56
@@ -25,7 +26,7 @@ export REGION
25if [ "${REGION#lxd-}" != "$REGION" ]; then26if [ "${REGION#lxd-}" != "$REGION" ]; then
26 LXD_ARCH=${REGION#*-}; LXD_ARCH=${LXD_ARCH%%-*}27 LXD_ARCH=${REGION#*-}; LXD_ARCH=${LXD_ARCH%%-*}
27else28else
28 . ${HOME}/cloudrcs/${REGION}.rc29 . "${HOME}"/cloudrcs/"${REGION}".rc
29fi30fi
3031
31exec "$@"32exec "$@"
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh
index 93d48d8..7cd94c8 100644
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh
@@ -1,3 +1,4 @@
1#!/bin/sh
1# Canonical/Ubuntu specific testbed setup2# Canonical/Ubuntu specific testbed setup
23
3# Remove trailing dot from the machine fqdn.4# Remove trailing dot from the machine fqdn.
@@ -70,6 +71,7 @@ if type iptables >/dev/null 2>&1; then
70iptables -w -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu || true71iptables -w -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu || true
71EOF72EOF
72 chmod 755 /etc/rc.local73 chmod 755 /etc/rc.local
74 # shellcheck disable=SC1091
73 . /etc/rc.local75 . /etc/rc.local
74fi76fi
7577
diff --git a/ci/lint_test b/ci/lint_test
index e52edc4..15fc01d 100755
--- a/ci/lint_test
+++ b/ci/lint_test
@@ -94,14 +94,6 @@ if __name__=="__main__":
94 "output": "",94 "output": "",
95 "code": 095 "code": 0
96 },96 },
97 "shellcheck": {
98 "files": [],
99 "extensions": [".sh", ".bash"],
100 "shebangs": ["#!/bin/bash", "#!/bin/sh"],
101 "args": None,
102 "output": "",
103 "code": 0
104 },
105 'yamllint': {97 'yamllint': {
106 "files": ["../"],98 "files": ["../"],
107 "extensions": None,99 "extensions": None,
diff --git a/lxc-slave-admin/cmd b/lxc-slave-admin/cmd
index ff991ff..0700964 100755
--- a/lxc-slave-admin/cmd
+++ b/lxc-slave-admin/cmd
@@ -1,6 +1,6 @@
1#!/bin/sh1#!/bin/sh
2set -e2set -e
3MYDIR=`dirname $0`3MYDIR=$(dirname "${0}")
44
5if [ -z "$1" ]; then5if [ -z "$1" ]; then
6 echo "Usage: $0 <hosts> <commands or .commands file>" >&26 echo "Usage: $0 <hosts> <commands or .commands file>" >&2
@@ -8,11 +8,11 @@ if [ -z "$1" ]; then
8fi8fi
99
10if [ "$1" = "all" ]; then10if [ "$1" = "all" ]; then
11 for f in $MYDIR/*.hosts; do11 for f in "${MYDIR}"/*.hosts; do
12 hosts="$hosts -h $f";12 hosts="$hosts -h $f";
13 done13 done
14else14else
15 if [ -e ${1} ]; then15 if [ -e "${1}" ]; then
16 hosts="-h ${1}"16 hosts="-h ${1}"
17 elif [ -e "${1}.hosts" ]; then17 elif [ -e "${1}.hosts" ]; then
18 hosts="-h ${1}.hosts"18 hosts="-h ${1}.hosts"
@@ -29,8 +29,8 @@ if [ "${1%.commands}" != "$1" ]; then
29 exit 129 exit 1
30 fi30 fi
31 # command file31 # command file
32 cat "$1" | parallel-ssh -x "-F $MYDIR/ssh_config" -OUserKnownHostsFile=/dev/null -OStrictHostKeyChecking=no -OIdentitiesOnly=yes $hosts -p8 -t 0 -i -I32 parallel-ssh -x "-F ${MYDIR}/ssh_config" -OUserKnownHostsFile=/dev/null -OStrictHostKeyChecking=no -OIdentitiesOnly=yes "${hosts}" -p8 -t 0 -i -I < "${1}"
33else33else
34 # command34 # command
35 parallel-ssh -x "-F $MYDIR/ssh_config" -OUserKnownHostsFile=/dev/null -OStrictHostKeyChecking=no -OIdentitiesOnly=yes $hosts -p8 -t 0 -i -- "$@"35 parallel-ssh -x "-F ${MYDIR}/ssh_config" -OUserKnownHostsFile=/dev/null -OStrictHostKeyChecking=no -OIdentitiesOnly=yes "${hosts}" -p8 -t 0 -i -- "$@"
36fi36fi
diff --git a/mojo/make-lxd-secgroup b/mojo/make-lxd-secgroup
index d41274c..3199669 100755
--- a/mojo/make-lxd-secgroup
+++ b/mojo/make-lxd-secgroup
@@ -1,5 +1,5 @@
1#!/bin/sh1#!/bin/sh
22# shellcheck disable=SC1090
3set -eu3set -eu
44
5# there's apparently no way to get this dynamically5# there's apparently no way to get this dynamically
diff --git a/mojo/postdeploy b/mojo/postdeploy
index 0f857ae..79fe50a 100755
--- a/mojo/postdeploy
+++ b/mojo/postdeploy
@@ -11,5 +11,5 @@ if [ "${MOJO_STAGE_NAME}" == "staging" ]; then
11fi11fi
1212
13echo "Setting up the floating IP address of the front end..."13echo "Setting up the floating IP address of the front end..."
14$(dirname $0)/add-floating-ip haproxy14"$(dirname "$0")/add-floating-ip" haproxy
15$(dirname $0)/add-floating-ip rabbitmq-server15"$(dirname "$0")/add-floating-ip" rabbitmq-server

Subscribers

People subscribed via source and target branches