~mojo-maintainers/mojo/trunk

« back to all changes in this revision

Viewing changes to contrib/test/lxc-test

  • Committer: mergebot at canonical
  • Author(s): "Paul Collins"
  • Date: 2020-07-31 07:14:19 UTC
  • mfrom: (566.2.1 apt-update-test-lxc)
  • Revision ID: mergebot@juju-139df4-prod-is-toolbox-0.canonical.com-20200731071419-40h2f0aezo1qjiyz
lxc-test: poll "cloud-init status" for up to 1 minute instead of fixed sleep

This works around a problem where "apt update" is run too soon, before cloud-init updates sources.list with my local mirror.

Reviewed-on: https://code.launchpad.net/~pjdc/mojo/apt-update-test-lxc/+merge/388445
Reviewed-by: Tom Haddon <tom.haddon@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    echo "$(date '+%Y-%m-%d %H:%M:%S') INFO: $1"
21
21
}
22
22
 
 
23
function lxc_wait_for_cloud_init_done {
 
24
    lxc=$1
 
25
    echo -n "Polling ${lxc} for cloud-init completion..."
 
26
    for x in {1..20} ; do
 
27
        status=$(lxc exec $lxc cloud-init status)
 
28
        case "$status" in
 
29
            "status: done")
 
30
                echo " done."
 
31
                return 0        # exit status, not boolean
 
32
                ;;
 
33
            *)
 
34
                echo -n .
 
35
                ;;
 
36
        esac
 
37
        sleep 3
 
38
    done
 
39
 
 
40
    return 1                    # again, exit status
 
41
}
 
42
 
23
43
function lxc_run() {
24
44
    cmd=$1
25
45
    log_info "Running command \"${cmd}\" in container \"${CONTAINER_NAME}\" as root"
42
62
    fi
43
63
    set -e
44
64
    lxc launch ubuntu:20.04 ${CONTAINER_NAME} -c security.nesting=true -c security.privileged=true
45
 
    # We shouldn't need to just wait here, but there doesn't appear to be an
46
 
    # lxc wait command.
47
 
    sleep 20
 
65
    # In lieu of "lxc wait" or similar, poll "cloud-init status" (https://github.com/lxc/lxd/issues/7711):
 
66
    if ! lxc_wait_for_cloud_init_done ${CONTAINER_NAME} ; then
 
67
        echo "Container ${CONTAINER_NAME} did not finish running cloud-init!  Exiting." >&2
 
68
        exit 1
 
69
    fi
48
70
    # Install packages.
49
71
    lxc_run "apt update"
50
72
    lxc_run "apt upgrade -y"