#!/bin/bash

set -ex

#juju 2.3+ supports cidr expansion for no_proxy
export no_proxy=10.0.8.0/24,$no_proxy

# For the future- tests, we can't really make a 'yenial' image to launch from
# lxd, and the default will be the LTS anyway. So, treat this as a test of
# using the next development release spawning xenial lxd machines.
# TODO: This needs something fancier for backporting to earlier series.
SERIES=xenial

echo "Prepopulating lxd with daily $SERIES image: "
lxc image copy ubuntu-daily:$SERIES local: --alias ubuntu-$SERIES
lxc image list
lxc info

echo "Testing juju bootstrap: "
BOOTSTRAP_ARGS="--debug --config default-series=$SERIES --config enable-os-upgrade=false --config no-proxy=$no_proxy"
if [ "$http_proxy" ]
then
   BOOTSTRAP_ARGS=$BOOTSTRAP_ARGS' --config http-proxy='$http_proxy
fi
if [ "$https_proxy" ]
then
      BOOTSTRAP_ARGS=$BOOTSTRAP_ARGS' --config https-proxy='$https_proxy
fi
juju bootstrap lxd my-controller $BOOTSTRAP_ARGS
echo "OK"

echo "Waiting for environment to bootstrap: "
juju status --debug -m controller
juju status --debug
echo "OK"

echo "Destroying environment: "
juju destroy-controller --debug --yes my-controller
echo "OK"
