name: Start client
testcases:
  - name: download_ulinux
    steps:
    - type: exec
      script: wget http://inverse.ca/downloads/PacketFence/LiveCD/ulinux.qcow2 -O /tmp/ulinux.qcow2

  - name: install_systemd_script
    steps:
      - type: exec
        script: |
          cat > /lib/systemd/system/ulinux.service << EOF
          [Unit]
          Description=QEMU virtual machine

          [Service]
          ExecStart= /usr/bin/qemu-system-x86_64 -boot d -hda /tmp/ulinux.qcow2 -m 128M -device "virtio-net-pci,netdev=network0,mac={{.security_event_random_mac.node.macaddress}}" -netdev tap,id=network0,ifname=blok-tap1,script=no,downscript=no -nographic -serial telnet:localhost:4321,server,nowait
          ExecStop=pkill -f qemu
          ExecStop=/usr/bin/bash -c 'while nc localhost 7100; do sleep 1; done'

          [Install]
          WantedBy=multi-user.target
          EOF

  - name: systemctl_daemon-reload
    steps:
      - type: exec
        script: systemctl daemon-reload

  - name: start_the_client
    steps:
      - type: exec
        script: systemctl start ulinux
      
      # let ulinux start
      - type: exec
        script: sleep 30
