Skip to content

Commit 9aed757

Browse files
authored
implement e2e test framework (#107)
1 parent ed683a3 commit 9aed757

File tree

9 files changed

+226
-31
lines changed

9 files changed

+226
-31
lines changed
Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: E2E tests
22

33
on:
4+
pull_request:
45
workflow_dispatch:
56
inputs:
67
logs:
@@ -9,40 +10,102 @@ on:
910
default: '0'
1011

1112
jobs:
13+
plugin-build:
14+
runs-on: [self-hosted, nxlab, packer]
15+
outputs:
16+
test-list: ${{ steps.test-list.outputs.list}}
17+
18+
steps:
19+
- name: Checkout Repository
20+
uses: actions/checkout@v3
21+
22+
- name: Setup `golang`
23+
uses: actions/setup-go@v3
24+
with:
25+
go-version: '>=1.19.0'
26+
27+
- name: Build packer plugin
28+
run: |
29+
cd $GITHUB_WORKSPACE
30+
make dev
31+
32+
- uses: actions/upload-artifact@v3
33+
with:
34+
name: packer-plugin-nutanix
35+
path: ~/.packer.d/plugins/packer-plugin-nutanix
36+
retention-days: 7
37+
38+
- name: build test list
39+
id: test-list
40+
run: echo "list=$(ls test/e2e | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
41+
42+
1243
e2e:
13-
runs-on: ubuntu-latest
14-
name: launch E2E tests
44+
name: E2E test
45+
needs: plugin-build
1546

1647
strategy:
17-
fail-fast: false
1848
matrix:
19-
test: [ simple ]
49+
test: ${{fromJSON(needs.plugin-build.outputs.test-list)}}
50+
51+
runs-on: [self-hosted, nxlab, packer]
52+
defaults:
53+
run:
54+
working-directory: test/e2e/${{ matrix.test}}
55+
56+
2057
steps:
2158
- name: Checkout Repository
2259
uses: actions/checkout@v3
2360

2461
- name: Setup `packer`
2562
uses: hashicorp/setup-packer@main
26-
id: setup
63+
id: setup-packer
64+
65+
- name: Setup `xorriso`
66+
run: |
67+
sudo apt update -y
68+
sudo apt install -y xorriso
69+
70+
- uses: actions/download-artifact@v3
71+
with:
72+
name: packer-plugin-nutanix
73+
path: /tmp
74+
75+
- name: Install plugin
76+
run: |
77+
mkdir -p ~/.packer.d/plugins/
78+
cp /tmp/packer-plugin-nutanix ~/.packer.d/plugins/packer-plugin-nutanix
79+
chmod 755 ~/.packer.d/plugins/packer-plugin-nutanix
2780
2881
- name: Run `packer init`
2982
id: init
30-
run: "packer init ."
31-
with:
32-
working_directory: test/e2e/${{ matrix.version}}
83+
run: |
84+
packer init .
3385
3486
- name: Run `packer validate`
3587
id: validate
36-
run: "packer validate ."
88+
run: packer validate -var "test=${{ matrix.test}}" .
3789
env:
3890
PACKER_LOG: ${{ github.event.inputs.logs }}
39-
with:
40-
working_directory: test/e2e/${{ matrix.version}}
4191

42-
- name: Run `packer validate`
92+
- name: Run `packer build`
4393
id: build
44-
run: "packer build ."
94+
run: packer build -var "test=${{ matrix.test}}" .
4595
env:
4696
PACKER_LOG: ${{ github.event.inputs.logs }}
47-
with:
48-
working_directory: test/e2e/${{ matrix.version}}
97+
98+
results:
99+
if: ${{ always() }}
100+
runs-on: [self-hosted, nxlab, packer]
101+
name: Final E2E results
102+
needs: [e2e]
103+
steps:
104+
- run: |
105+
result="${{ needs.e2e.result }}"
106+
if [[ $result == "success" || $result == "skipped" ]]; then
107+
exit 0
108+
else
109+
exit 1
110+
fi
111+

test/e2e/simple/build.pkr.hcl renamed to test/e2e/centos-img/build.pkr.hcl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ build {
44
}
55

66
provisioner "shell" {
7-
only = ["nutanix.centos"]
87
environment_vars = [
98
"FOO=hello world",
109
]

test/e2e/simple/source.pkr.hcl renamed to test/e2e/centos-img/source.pkr.hcl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ source "nutanix" "centos" {
99

1010
vm_disks {
1111
image_type = "DISK_IMAGE"
12-
source_image_name = var.centos_disk_image_name
13-
disk_size_gb = 40
12+
source_image_uri = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-2111.qcow2"
13+
disk_size_gb = 20
1414
}
1515

1616
vm_nics {
1717
subnet_name = var.nutanix_subnet
1818
}
1919

20-
image_name = "centos-packer-image"
21-
image_category_key = "region"
22-
image_category_value = "paris"
20+
vm_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"
21+
22+
image_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"
23+
image_delete = true
24+
image_category_key = "Environment"
25+
image_category_value = "Testing"
2326

2427
force_deregister = true
2528
user_data = "I2Nsb3VkLWNvbmZpZwp1c2VyczoKICAtIG5hbWU6IGNlbnRvcwogICAgc3VkbzogWydBTEw9KEFMTCkgTk9QQVNTV0Q6QUxMJ10KY2hwYXNzd2Q6CiAgbGlzdDogfAogICAgY2VudG9zOnBhY2tlcgogIGV4cGlyZTogRmFsc2UKc3NoX3B3YXV0aDogVHJ1ZQ=="

test/e2e/simple/variables.pkr.hcl renamed to test/e2e/centos-img/variables.pkr.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ variable "nutanix_cluster" {
2828
type = string
2929
}
3030

31-
variable "centos_disk_image_name" {
31+
variable "test" {
3232
type = string
33-
}
33+
}

test/e2e/centos-iso/build.pkr.hcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
build {
2+
source "nutanix.centos" {
3+
name = "centos"
4+
}
5+
6+
provisioner "shell" {
7+
environment_vars = [
8+
"FOO=hello world",
9+
]
10+
inline = [
11+
"echo \"FOO is $FOO\" > example.txt",
12+
]
13+
}
14+
}

test/e2e/centos-iso/scripts/ks.cfg

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Author: Tomasz Filipiec <tomasz.filipiec@gmail.com>
2+
# Desc.: Simple kickstart file for automated installation
3+
# OS: CentOS 7 Minimal (core)
4+
# Version: 1.0
5+
6+
# Turning on text-mode installation (little quicker than GUI)
7+
text
8+
9+
# Setting up authentication and keyboard
10+
auth --enableshadow --passalgo=sha512
11+
keyboard --vckeymap=us --xlayouts='us'
12+
13+
# Installation files source (CentOS-7.0-1406-x86_64-Minimal.iso)
14+
cdrom
15+
16+
# Using only primary disk, ignoring others
17+
ignoredisk --only-use=sda
18+
19+
# Setting up language to English
20+
lang en-US.UTF-8
21+
22+
# Setting up network interface to DHCP
23+
network --bootproto=dhcp --ipv6=auto --hostname=centos-ks.local --activate
24+
25+
# Root password (remember that plaintext only for information purposes)
26+
rootpw --plaintext packer
27+
28+
# Setting up firewall and enabling SSH for remote management
29+
firewall --enabled --service=ssh
30+
31+
# Setting timezone
32+
timezone Europe/Berlin --isUtc
33+
34+
# Setting up Security-Enhanced Linux into enforcing
35+
selinux --enforcing
36+
37+
# Setting up MBR
38+
bootloader --location=mbr --boot-drive=sda
39+
40+
# Setting up Logical Volume Manager and autopartitioning
41+
clearpart --all --drives=sda --initlabel
42+
autopart --type=lvm
43+
44+
# Eject cdrom and reboot
45+
reboot --eject
46+
47+
# Installing only packages for minimal install
48+
%packages
49+
@Core
50+
chrony
51+
%end

test/e2e/centos-iso/source.pkr.hcl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
source "nutanix" "centos" {
2+
nutanix_username = var.nutanix_username
3+
nutanix_password = var.nutanix_password
4+
nutanix_endpoint = var.nutanix_endpoint
5+
nutanix_port = var.nutanix_port
6+
nutanix_insecure = var.nutanix_insecure
7+
cluster_name = var.nutanix_cluster
8+
os_type = "Linux"
9+
10+
vm_disks {
11+
image_type = "ISO_IMAGE"
12+
source_image_uri = "http://fr2.rpmfind.net/linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso"
13+
}
14+
15+
vm_disks {
16+
image_type = "DISK"
17+
disk_size_gb = 40
18+
}
19+
20+
vm_nics {
21+
subnet_name = var.nutanix_subnet
22+
}
23+
24+
cd_files = ["scripts/ks.cfg"]
25+
cd_label = "OEMDRV"
26+
27+
vm_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"
28+
29+
image_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"
30+
image_delete = true
31+
image_category_key = "Environment"
32+
image_category_value = "Testing"
33+
34+
force_deregister = true
35+
36+
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
37+
shutdown_timeout = "2m"
38+
ssh_password = "packer"
39+
ssh_username = "root"
40+
}

test/e2e/centos-iso/variables.pkr.hcl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
variable "nutanix_username" {
2+
type = string
3+
}
4+
5+
variable "nutanix_password" {
6+
type = string
7+
sensitive = true
8+
}
9+
10+
variable "nutanix_endpoint" {
11+
type = string
12+
}
13+
14+
variable "nutanix_port" {
15+
type = number
16+
}
17+
18+
variable "nutanix_insecure" {
19+
type = bool
20+
default = true
21+
}
22+
23+
variable "nutanix_subnet" {
24+
type = string
25+
}
26+
27+
variable "nutanix_cluster" {
28+
type = string
29+
}
30+
31+
variable "test" {
32+
type = string
33+
}

test/e2e/simple/plugin.pkr.hcl

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)