Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update e2e test framework #107

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 78 additions & 15 deletions .github/workflows/test-plugin-e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: E2E tests

on:
pull_request:
workflow_dispatch:
inputs:
logs:
Expand All @@ -9,40 +10,102 @@ on:
default: '0'

jobs:
plugin-build:
runs-on: [self-hosted, nxlab, packer]
outputs:
test-list: ${{ steps.test-list.outputs.list}}

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup `golang`
uses: actions/setup-go@v3
with:
go-version: '>=1.19.0'

- name: Build packer plugin
run: |
cd $GITHUB_WORKSPACE
make dev

- uses: actions/upload-artifact@v3
with:
name: packer-plugin-nutanix
path: ~/.packer.d/plugins/packer-plugin-nutanix
retention-days: 7

- name: build test list
id: test-list
run: echo "list=$(ls test/e2e | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT


e2e:
runs-on: ubuntu-latest
name: launch E2E tests
name: E2E test
needs: plugin-build

strategy:
fail-fast: false
matrix:
test: [ simple ]
test: ${{fromJSON(needs.plugin-build.outputs.test-list)}}

runs-on: [self-hosted, nxlab, packer]
defaults:
run:
working-directory: test/e2e/${{ matrix.test}}


steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup `packer`
uses: hashicorp/setup-packer@main
id: setup
id: setup-packer

- name: Setup `xorriso`
run: |
sudo apt update -y
sudo apt install -y xorriso

- uses: actions/download-artifact@v3
with:
name: packer-plugin-nutanix
path: /tmp

- name: Install plugin
run: |
mkdir -p ~/.packer.d/plugins/
cp /tmp/packer-plugin-nutanix ~/.packer.d/plugins/packer-plugin-nutanix
chmod 755 ~/.packer.d/plugins/packer-plugin-nutanix

- name: Run `packer init`
id: init
run: "packer init ."
with:
working_directory: test/e2e/${{ matrix.version}}
run: |
packer init .

- name: Run `packer validate`
id: validate
run: "packer validate ."
run: packer validate -var "test=${{ matrix.test}}" .
env:
PACKER_LOG: ${{ github.event.inputs.logs }}
with:
working_directory: test/e2e/${{ matrix.version}}

- name: Run `packer validate`
- name: Run `packer build`
id: build
run: "packer build ."
run: packer build -var "test=${{ matrix.test}}" .
env:
PACKER_LOG: ${{ github.event.inputs.logs }}
with:
working_directory: test/e2e/${{ matrix.version}}

results:
if: ${{ always() }}
runs-on: [self-hosted, nxlab, packer]
name: Final E2E results
needs: [e2e]
steps:
- run: |
result="${{ needs.e2e.result }}"
if [[ $result == "success" || $result == "skipped" ]]; then
exit 0
else
exit 1
fi

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build {
}

provisioner "shell" {
only = ["nutanix.centos"]
environment_vars = [
"FOO=hello world",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ source "nutanix" "centos" {

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

vm_nics {
subnet_name = var.nutanix_subnet
}

image_name = "centos-packer-image"
image_category_key = "region"
image_category_value = "paris"
vm_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"

image_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"
image_delete = true
image_category_key = "Environment"
image_category_value = "Testing"

force_deregister = true
user_data = "I2Nsb3VkLWNvbmZpZwp1c2VyczoKICAtIG5hbWU6IGNlbnRvcwogICAgc3VkbzogWydBTEw9KEFMTCkgTk9QQVNTV0Q6QUxMJ10KY2hwYXNzd2Q6CiAgbGlzdDogfAogICAgY2VudG9zOnBhY2tlcgogIGV4cGlyZTogRmFsc2UKc3NoX3B3YXV0aDogVHJ1ZQ=="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ variable "nutanix_cluster" {
type = string
}

variable "centos_disk_image_name" {
variable "test" {
type = string
}
}
14 changes: 14 additions & 0 deletions test/e2e/centos-iso/build.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build {
source "nutanix.centos" {
name = "centos"
}

provisioner "shell" {
environment_vars = [
"FOO=hello world",
]
inline = [
"echo \"FOO is $FOO\" > example.txt",
]
}
}
51 changes: 51 additions & 0 deletions test/e2e/centos-iso/scripts/ks.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Author: Tomasz Filipiec <[email protected]>
# Desc.: Simple kickstart file for automated installation
# OS: CentOS 7 Minimal (core)
# Version: 1.0

# Turning on text-mode installation (little quicker than GUI)
text

# Setting up authentication and keyboard
auth --enableshadow --passalgo=sha512
keyboard --vckeymap=us --xlayouts='us'

# Installation files source (CentOS-7.0-1406-x86_64-Minimal.iso)
cdrom

# Using only primary disk, ignoring others
ignoredisk --only-use=sda

# Setting up language to English
lang en-US.UTF-8

# Setting up network interface to DHCP
network --bootproto=dhcp --ipv6=auto --hostname=centos-ks.local --activate

# Root password (remember that plaintext only for information purposes)
rootpw --plaintext packer

# Setting up firewall and enabling SSH for remote management
firewall --enabled --service=ssh

# Setting timezone
timezone Europe/Berlin --isUtc

# Setting up Security-Enhanced Linux into enforcing
selinux --enforcing

# Setting up MBR
bootloader --location=mbr --boot-drive=sda

# Setting up Logical Volume Manager and autopartitioning
clearpart --all --drives=sda --initlabel
autopart --type=lvm

# Eject cdrom and reboot
reboot --eject

# Installing only packages for minimal install
%packages
@Core
chrony
%end
40 changes: 40 additions & 0 deletions test/e2e/centos-iso/source.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
source "nutanix" "centos" {
nutanix_username = var.nutanix_username
nutanix_password = var.nutanix_password
nutanix_endpoint = var.nutanix_endpoint
nutanix_port = var.nutanix_port
nutanix_insecure = var.nutanix_insecure
cluster_name = var.nutanix_cluster
os_type = "Linux"

vm_disks {
image_type = "ISO_IMAGE"
source_image_uri = "http://fr2.rpmfind.net/linux/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso"
}

vm_disks {
image_type = "DISK"
disk_size_gb = 40
}

vm_nics {
subnet_name = var.nutanix_subnet
}

cd_files = ["scripts/ks.cfg"]
cd_label = "OEMDRV"

vm_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"

image_name = "e2e-packer-${var.test}-${formatdate("MDYYhms", timestamp())}"
image_delete = true
image_category_key = "Environment"
image_category_value = "Testing"

force_deregister = true

shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
shutdown_timeout = "2m"
ssh_password = "packer"
ssh_username = "root"
}
33 changes: 33 additions & 0 deletions test/e2e/centos-iso/variables.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
variable "nutanix_username" {
type = string
}

variable "nutanix_password" {
type = string
sensitive = true
}

variable "nutanix_endpoint" {
type = string
}

variable "nutanix_port" {
type = number
}

variable "nutanix_insecure" {
type = bool
default = true
}

variable "nutanix_subnet" {
type = string
}

variable "nutanix_cluster" {
type = string
}

variable "test" {
type = string
}
8 changes: 0 additions & 8 deletions test/e2e/simple/plugin.pkr.hcl

This file was deleted.