diff --git a/.github/workflows/test-plugin-e2e.yaml b/.github/workflows/test-plugin-e2e.yaml index 0c6e0be..0cf2fbd 100644 --- a/.github/workflows/test-plugin-e2e.yaml +++ b/.github/workflows/test-plugin-e2e.yaml @@ -1,6 +1,7 @@ name: E2E tests on: + pull_request: workflow_dispatch: inputs: logs: @@ -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 + diff --git a/test/e2e/simple/build.pkr.hcl b/test/e2e/centos-img/build.pkr.hcl similarity index 87% rename from test/e2e/simple/build.pkr.hcl rename to test/e2e/centos-img/build.pkr.hcl index d51480e..542124b 100644 --- a/test/e2e/simple/build.pkr.hcl +++ b/test/e2e/centos-img/build.pkr.hcl @@ -4,7 +4,6 @@ build { } provisioner "shell" { - only = ["nutanix.centos"] environment_vars = [ "FOO=hello world", ] diff --git a/test/e2e/simple/source.pkr.hcl b/test/e2e/centos-img/source.pkr.hcl similarity index 67% rename from test/e2e/simple/source.pkr.hcl rename to test/e2e/centos-img/source.pkr.hcl index 119fc48..ce0e35a 100644 --- a/test/e2e/simple/source.pkr.hcl +++ b/test/e2e/centos-img/source.pkr.hcl @@ -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==" diff --git a/test/e2e/simple/variables.pkr.hcl b/test/e2e/centos-img/variables.pkr.hcl similarity index 91% rename from test/e2e/simple/variables.pkr.hcl rename to test/e2e/centos-img/variables.pkr.hcl index 66e6096..d701cf0 100644 --- a/test/e2e/simple/variables.pkr.hcl +++ b/test/e2e/centos-img/variables.pkr.hcl @@ -28,6 +28,6 @@ variable "nutanix_cluster" { type = string } -variable "centos_disk_image_name" { +variable "test" { type = string -} +} \ No newline at end of file diff --git a/test/e2e/centos-iso/build.pkr.hcl b/test/e2e/centos-iso/build.pkr.hcl new file mode 100644 index 0000000..542124b --- /dev/null +++ b/test/e2e/centos-iso/build.pkr.hcl @@ -0,0 +1,14 @@ +build { + source "nutanix.centos" { + name = "centos" + } + + provisioner "shell" { + environment_vars = [ + "FOO=hello world", + ] + inline = [ + "echo \"FOO is $FOO\" > example.txt", + ] + } +} diff --git a/test/e2e/centos-iso/scripts/ks.cfg b/test/e2e/centos-iso/scripts/ks.cfg new file mode 100644 index 0000000..93c8e9f --- /dev/null +++ b/test/e2e/centos-iso/scripts/ks.cfg @@ -0,0 +1,51 @@ +# Author: Tomasz Filipiec +# 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 \ No newline at end of file diff --git a/test/e2e/centos-iso/source.pkr.hcl b/test/e2e/centos-iso/source.pkr.hcl new file mode 100644 index 0000000..846d3a9 --- /dev/null +++ b/test/e2e/centos-iso/source.pkr.hcl @@ -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" +} diff --git a/test/e2e/centos-iso/variables.pkr.hcl b/test/e2e/centos-iso/variables.pkr.hcl new file mode 100644 index 0000000..d701cf0 --- /dev/null +++ b/test/e2e/centos-iso/variables.pkr.hcl @@ -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 +} \ No newline at end of file diff --git a/test/e2e/simple/plugin.pkr.hcl b/test/e2e/simple/plugin.pkr.hcl deleted file mode 100644 index fdeb8e9..0000000 --- a/test/e2e/simple/plugin.pkr.hcl +++ /dev/null @@ -1,8 +0,0 @@ -packer { - required_plugins { - nutanix = { - version = ">= 0.4.0" - source = "github.com/nutanix-cloud-native/nutanix" - } - } -}