Skip to content

Commit

Permalink
add the test packer template
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Mar 15, 2023
1 parent b32b470 commit ef665b2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@ packer-plugin-windows-update
packer-plugin-windows-update.exe
tmp*
.idea/
output-*/
*.log
10 changes: 8 additions & 2 deletions Makefile
Expand Up @@ -41,6 +41,12 @@ uninstall:
rm -f $(HOME)/.packer.d/plugins/packer-plugin-windows-update$(GOEXE)

clean:
rm -rf dist tmp*
rm -rf dist tmp* output-test *.log

.PHONY: all init build release release-snapshot install uninstall clean
test:
rm -rf output-test test.log
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=test.log \
PKR_VAR_disk_image=~/.vagrant.d/boxes/windows-2022-amd64/0.0.0/libvirt/box.img \
packer build -only=qemu.test -on-error=abort test.pkr.hcl

.PHONY: all init build release release-snapshot install uninstall clean test
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -108,3 +108,11 @@ make install

If you are having problems running `packer` set the `PACKER_LOG=1` environment
variable to see more information.

## Test (QEMU)

You can test the plugin with a previously installed [rgl/windows-vagrant](https://github.com/rgl/windows-vagrant) image with:

```bash
make test
```
66 changes: 66 additions & 0 deletions test.pkr.hcl
@@ -0,0 +1,66 @@
variable "disk_size" {
type = string
default = "61440"
}

variable "disk_image" {
type = string
}

source "qemu" "test" {
headless = false
accelerator = "kvm"
machine_type = "q35"
cpus = 2
memory = 4096
qemuargs = [
["-cpu", "host"],
["-device", "qemu-xhci"],
["-device", "virtio-tablet"],
["-device", "virtio-scsi-pci,id=scsi0"],
["-device", "scsi-hd,bus=scsi0.0,drive=drive0"],
["-device", "virtio-net,netdev=user.0"],
["-vga", "qxl"],
["-device", "virtio-serial-pci"],
["-chardev", "socket,path=/tmp/{{ .Name }}-qga.sock,server,nowait,id=qga0"],
["-device", "virtserialport,chardev=qga0,name=org.qemu.guest_agent.0"],
["-chardev", "spicevmc,id=spicechannel0,name=vdagent"],
["-device", "virtserialport,chardev=spicechannel0,name=com.redhat.spice.0"],
["-spice", "unix,addr=/tmp/{{ .Name }}-spice.socket,disable-ticketing"],
]
disk_interface = "virtio-scsi"
disk_cache = "unsafe"
disk_discard = "unmap"
disk_image = true
use_backing_file = true
disk_size = var.disk_size
iso_url = var.disk_image
iso_checksum = "none"
net_device = "virtio-net"
shutdown_command = "shutdown /s /t 0 /f /d p:4:1 /c \"Packer Shutdown\""
communicator = "winrm"
winrm_username = "vagrant"
winrm_password = "vagrant"
winrm_timeout = "4h"
}

build {
sources = [
"source.qemu.test",
]
provisioner "windows-update" {
}
provisioner "powershell" {
use_pwsh = true
inline = [
<<-EOF
$p = 'c:/packer.delete.me.to.end.test.wait.txt'
Set-Content $p 'delete this file to end the packer test wait'
Write-Host "ATTENTION To end this test wait, login into the machine and delete the $p file"
while (Test-Path $p) {
Start-Sleep -Seconds 5
}
EOF
]
}
}

0 comments on commit ef665b2

Please sign in to comment.