dist: trusty
sudo: true
language: python
matrix:
  include:
    - env: TARGET=check2 IMAGE=ubuntu:xenial
      script:
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo apt-get update && sudo apt-get -y install make python-distutils-extra python-mock python-twisted python-apt python-twisted-core python-pycurl python-netifaces"';
        # creates user and dirs, some used through tests
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo apt-get -y install landscape-common"';
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo chown -R ubuntu:ubuntu /target"';
        - sg lxd -c 'lxc exec testcontainer -- sudo -i -u ubuntu sh -c "cd /target; make ${TARGET}" ubuntu';
    - env: TARGET=check3 IMAGE=ubuntu:bionic
      script:
        # bionic needs cgroupv2 not on this kernel, so nudge the system a bit
        - sg lxd -c 'lxc exec testcontainer -- sh -c "dhclient eth0; cloud-init init"';
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo apt-get update && sudo apt-get -y install make python3-distutils-extra python3-mock python3-twisted python3-apt python-twisted-core python3-pycurl python3-netifaces"';
        # creates user and dirs, some used through tests
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo apt-get -y install landscape-common"';
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo chown -R ubuntu:ubuntu /target"';
        - sg lxd -c 'lxc exec testcontainer -- sudo -i -u ubuntu sh -c "cd /target; make ${TARGET}" ubuntu';
    - env: TARGET=check3 IMAGE=ubuntu-daily:focal
      script:
        # bionic needs cgroupv2 not on this kernel, so nudge the system a bit
        - sg lxd -c 'lxc exec testcontainer -- sh -c "dhclient eth0; cloud-init init"';
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo apt-get update && sudo apt-get -y install make python3-distutils-extra python3-mock python3-twisted python3-apt python-twisted-core python3-pycurl python3-netifaces net-tools"';
        # creates user and dirs, some used through tests
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo apt-get -y install landscape-common"';
        - sg lxd -c 'lxc exec testcontainer -- sh -c "sudo chown -R ubuntu:ubuntu /target"';
        - sg lxd -c 'lxc exec testcontainer -- sudo -i -u ubuntu sh -c "cd /target; make ${TARGET}" ubuntu';
    - python: 3.6
      env: TARGET=lint
      install:
        - pip install flake8
    - python: 3.4
      env: TARGET=coverage
      before_script:
        - python3 -m pip install -U coverage
        - python3 -m pip install -U codecov
      install:
        - pip install flake8
        # These match "make depends"
        - pip install twisted==16.4.0 mock==1.3.0 configobj==5.0.6 pycurl netifaces==0.10.4
        - pip install http://launchpad.net/python-distutils-extra/trunk/2.39/+download/python-distutils-extra-2.39.tar.gz
        # build & install python-apt
        - make -f Makefile.travis pipinstallpythonapt
      script:
        - make $TARGET
      after_success:
        - codecov
env:
  global:
    - TRIAL_ARGS=-j4
before_script:
  - if [ ! -z ${IMAGE} ]; then
      sudo apt-get -y -t trusty-backports install lxd;
      sudo lxd init --auto;
      sudo usermod -a -G lxd travis;
      sudo sed -e 's/LXD_IPV4_ADDR=""/LXD_IPV4_ADDR="10.0.8.1"/' -e 's/LXD_IPV4_NETMASK=""/LXD_IPV4_NETMASK="255.255.255.0"/' -e 's:LXD_IPV4_NETWORK="":LXD_IPV4_NETWORK="10.0.8.0/24":' -e 's/LXD_IPV4_DHCP_RANGE=""/LXD_IPV4_DHCP_RANGE="10.0.8.2,10.0.8.254"/' -e 's/LXD_IPV4_DHCP_MAX=""/LXD_IPV4_DHCP_MAX="250"/' -i /etc/default/lxd-bridge;
      sudo /etc/init.d/lxd restart;
   fi
  - if [ ! -z ${IMAGE} ]; then
      sg lxd -c 'lxc launch ${IMAGE} testcontainer -c security.privileged=true';
      echo "waiting for nic";
      for t in 1 2 5 8; do sg lxd -c 'lxc list' | grep 10.0.8 && break; sleep ${t}; done;
      sg lxd -c 'lxc config device add testcontainer srcdir disk path=/target source=${PWD}';
      sg lxd -c 'lxc config device add testcontainer srcdir disk path=/target source=${PWD}';
      sg lxd -c 'lxc exec testcontainer -- sh -c "echo 1 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6"';
    fi
script:
  - make $TARGET PYTHON=python$TRAVIS_PYTHON_VERSION;
