Skip to content

Commit

Permalink
Merge pull request #31 from ggiamarchi/integration-test
Browse files Browse the repository at this point in the history
Integration tests
  • Loading branch information
ggiamarchi authored Apr 19, 2020
2 parents 3d4d9f6 + c70ff1f commit f9b5611
Show file tree
Hide file tree
Showing 24 changed files with 646 additions and 86 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ test/tftp_root/pxelinux.cfg/01-*
# Binary tools localy installed
#
bin/

#
# Vagrant things
#
.vagrant/
*.log
20 changes: 16 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
language: go

sudo: false

go: 1.14

install:
before_install:
- make dep-dev

install:
- GOOS=linux GOARCH=amd64 make --debug EXECUTABLE=pxe-pilot-linux-amd64

before_script:
- test/scripts/install-tools.sh
- test/scripts/install-bats.sh
- test/scripts/install-mocks.sh
- test/scripts/install-service.sh

script:
- GOOS=linux GOARCH=amd64 make --debug EXECUTABLE=pxe-pilot-linux-amd64
- test/run.bats

after_success:
- GOOS=linux GOARCH=arm make --debug EXECUTABLE=pxe-pilot-linux-arm
- GOOS=darwin GOARCH=amd64 make --debug EXECUTABLE=pxe-pilot-darwin-amd64

after_failure:
- cat test/test.log

deploy:
provider: releases
api_key:
Expand Down
41 changes: 41 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

ENV["LC_ALL"] = "en_US.UTF-8"

Vagrant.configure(2) do |config|

config.vm.box = "ubuntu/xenial64"

config.vm.define "pxe-pilot" do |server|
config.vm.provider 'virtualbox' do |vb|
vb.customize ['modifyvm', :id, '--memory', '2048']
vb.customize ['modifyvm', :id, '--chipset', 'ich9']
end

server.vm.hostname = 'pxe-pilot'

server.vm.network "private_network", ip: "10.69.70.70", mac: "000000000a70"
server.vm.network "private_network", ip: "10.69.71.70", mac: "000000000b70"

server.vm.provision "shell", privileged: false, path: "test/scripts/install-tools.sh"
server.vm.provision "shell", privileged: false, path: "test/scripts/install-go.sh"
server.vm.provision "shell", privileged: false, path: "test/scripts/install-bats.sh"
server.vm.provision "shell", privileged: false, path: "test/scripts/install-mocks.sh"
server.vm.provision "shell", privileged: false, path: "test/scripts/build.sh"
server.vm.provision "shell", privileged: false, path: "test/scripts/install-service.sh"

#
# Running tests
#
server.vm.provision "shell", privileged: false, inline: <<-SHELL
set -e
echo "##############################################################"
echo "### Running integration tests ###"
echo "##############################################################"
/vagrant/test/run.bats
SHELL
end
end
1 change: 1 addition & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func ReadHosts(appConfig *model.AppConfig, status bool) []*model.Host {

if _, err := os.Stat(pxeFilePath); err != nil {
// No PXE config deployed for this host
appConfig.Hosts[i].Configuration = nil
continue
}

Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pxe-pilot.yml
10 changes: 10 additions & 0 deletions test/mocks/arp-mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [ ! -e /tmp/arp-populated ]; then
exit 0
fi

echo "? (10.69.70.14) at 00:00:00:00:0a:04 [ether] on enp0s8
? (10.69.70.12) at 00:00:00:00:0a:02 [ether] on enp0s8
? (10.69.70.13) at 00:00:00:00:0a:03 [ether] on enp0s8
? (10.69.70.11) at 00:00:00:00:0a:01 [ether] on enp0s8"
1 change: 1 addition & 0 deletions test/mocks/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/status
Empty file.
Empty file.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions test/mocks/fping-mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

sleep 5

touch /tmp/arp-populated
114 changes: 114 additions & 0 deletions test/mocks/ipmitool-mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash

set -e

data=$(cat /etc/pxe-pilot/test-home)/mocks/data

mkdir -p ${data}

POSITIONAL=()
while [ $# -gt 0 ]; do
case $1 in
-I)
:
shift
shift
;;
-P)
:
password=$2
shift
shift
;;
-U)
:
username=$2
shift
shift
;;
-N)
:
shift
shift
;;
-R)
:
shift
shift
;;
-H)
host="$2"
shift
shift
;;
*)
POSITIONAL+=("$1")
shift
:
;;
esac
done

if [ ! -d ${data}/${host} ]; then
sleep 5
echo "Error: Unable to establish IPMI v2 / RMCP+ session"
exit 1
fi

if [ "${username}" != "user" ] || [ "${password}" != "password" ]; then
echo "Error: Unable to establish IPMI v2 / RMCP+ session"
exit 1
fi

ipmi_cmd="${POSITIONAL[@]}"

power_status() {
local statusFile="${data}/${host}/status"

if [ ! -e ${statusFile} ]; then
echo "off" > ${statusFile}
fi

sleep .2
echo "Chassis Power is $(cat ${statusFile})"

exit 0
}

power_on() {
sleep .2
local statusFile="${data}/${host}/status"
echo "on" > ${statusFile}
echo 'Chassis Power Control: Up/On'
}

power_off() {
sleep .2
local statusFile="${data}/${host}/status"
echo "off" > ${statusFile}
echo 'Chassis Power Control: Down/Off'
}

power_reset() {
sleep .2
local statusFile="${data}/${host}/status"
echo 'Chassis Power Control: Reset'
}

[[ "${ipmi_cmd}" = "power status" || "${ipmi_cmd}" = "chassis power status" ]] && {
power_status
}

[[ "${ipmi_cmd}" = "power on" || "${ipmi_cmd}" = "chassis power on" ]] && {
power_on
}

[[ "${ipmi_cmd}" = "power off" || "${ipmi_cmd}" = "chassis power off" ]] && {
power_off
}

[[ "${ipmi_cmd}" = "power reset" || "${ipmi_cmd}" = "chassis power reset" ]] && {
power_reset
}

exit 0
89 changes: 89 additions & 0 deletions test/pxe-pilot-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---

host_management_adapters:

- name: ipmitool
vars:
- name: command
value: ipmitool-mock -N 2 -R 2 -I lanplus -U user -P password -H {{.ip_address}}
power_status:
cmd: '{{.command}} power status'
pattern_on: 'Chassis Power is on'
pattern_off: 'Chassis Power is off'
power_reset:
cmd: '{{.command}} power reset'
power_on:
cmd: '{{.command}} power on'
power_off:
cmd: '{{.command}} power off'

- name: ipmitool-with-variables
vars:
- name: command
value: ipmitool-mock -N 2 -R 2 -I lanplus -U {{.username}} -P {{.password}} -H {{.ip_address}}
power_status:
cmd: '{{.command}} power status'
pattern_on: 'Chassis Power is on'
pattern_off: 'Chassis Power is off'
power_reset:
cmd: '{{.command}} power reset'
power_on:
cmd: '{{.command}} power on'
power_off:
cmd: '{{.command}} power off'

hosts:

- name: h1
mac_addresses: ["00:00:00:00:0b:01"]
ipmi:
mac_address: "00:00:00:00:0a:01"
subnet: 10.69.70.0/24
username: "user"
password: "password"
interface: "lanplus"

- name: h2
mac_addresses: ["00:00:00:00:0b:02"]
management:
mac_address: "00:00:00:00:0a:02"
subnet: 10.69.70.0/24
adapter: ipmitool-with-variables
vars:
- name: username
value: user
- name: password
value: password

- name: h3
mac_addresses: ["00:00:00:00:0b:03", "00:00:00:00:0c:03", "00:00:00:00:0d:03"]

- name: h4
mac_addresses: ["00:00:00:00:0b:04"]
management:
mac_address: "00:00:00:00:0a:04"
subnet: 10.69.70.0/24
adapter: ipmitool

tftp:
root: "%%TFTP_ROOT%%"

configuration:
directory: "%%CONFIG_DIR%%"
bootloaders:
- name: pxelinux
file: pxelinux.0
- name: syslinux
file: syslinux.efi
- name: grub
file: grubnetx64.efi.signed
config_path: grub/grub.cfg

discovery:
cmd: fping -c 1 -D -q -g {{.subnet}}

arp:
cmd: arp -an

server:
port: 3478
Loading

0 comments on commit f9b5611

Please sign in to comment.