YaleUniversity / packer-plugin-goss

Goss Provisioner for Packer
MIT License
136 stars 45 forks source link

Add support for using goss to target Windows #39

Closed jsturtevant closed 3 years ago

jsturtevant commented 3 years ago

This provisioner is used to provide goss testing in the image-builder project. I recently added Windows support to image-builder and would like to run the goss test against it during provision in the same manner as the other images. Goss also now has alpha support for Windows.

I've updated the code here to support Windows and added a few tests.

Here is the output of it running against a windows VM. It is using a custom goss url while I wait for the fix in goss https://github.com/aelsabbahy/goss/pull/666

==> vhd-windows-2019: Provisioning with Goss
==> vhd-windows-2019: Configured to run on Windows
    vhd-windows-2019: Creating directory: /tmp/goss
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019:     Directory: C:\tmp
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019: Mode                LastWriteTime         Length Name
    vhd-windows-2019: ----                -------------         ------ ----
    vhd-windows-2019: d-----       12/17/2020   6:37 PM                goss
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019: Installing Goss from, https://k8swin.blob.core.windows.net/k8s-windows/goss/goss-alpha-windows-amd64.exe
    vhd-windows-2019: Downloading Goss to /tmp/goss-windows-amd64.exe
==> vhd-windows-2019:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
==> vhd-windows-2019:                                  Dload  Upload   Total   Spent    Left  Speed
==> vhd-windows-2019: 100 11.5M  100 11.5M    0     0  11.5M      0  0:00:01 --:--:--  0:00:01 26.4M
==> vhd-windows-2019: 'chmod' is not recognized as an internal or external command,
==> vhd-windows-2019: operable program or batch file.
==> vhd-windows-2019: Uploading goss tests...
    vhd-windows-2019: Uploading vars file packer/goss/goss-vars.yaml
    vhd-windows-2019: Inline variables are --vars-inline {"ARCH":"amd64","OS":"windows","PROVIDER":"azure","containerd_version":"1.4.3","kubernetes_cni_source_type":"","kubernetes_cni_version":"","kubernetes_source_type":"pkg","kubernetes_version":"v1.17.11"}
    vhd-windows-2019: Env variables are set "GOSS_USE_ALPHA=1" &&
    vhd-windows-2019: Uploading Dir packer/goss
    vhd-windows-2019: Creating directory: /tmp/goss/goss
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019:     Directory: C:\tmp\goss
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019: Mode                LastWriteTime         Length Name
    vhd-windows-2019: ----                -------------         ------ ----
    vhd-windows-2019: d-----       12/17/2020   6:37 PM                goss
    vhd-windows-2019:
    vhd-windows-2019:
==> vhd-windows-2019: 
==> vhd-windows-2019: 
==> vhd-windows-2019: 
==> vhd-windows-2019: Running goss tests...
==> vhd-windows-2019: Running GOSS render command: cd /tmp/goss && set "GOSS_USE_ALPHA=1" &&  /tmp/goss-windows-amd64.exe --gossfile goss/goss.yaml --vars /tmp/goss/goss-vars.yaml --vars-inline {"ARCH":"amd64","OS":"windows","PROVIDER":"azure","containerd_version":"1.4.3","kubernetes_cni_source_type":"","kubernetes_cni_version":"","kubernetes_source_type":"pkg","kubernetes_version":"v1.17.11"} render > /tmp/goss-spec.yaml
==> vhd-windows-2019: Goss render ran successfully
==> vhd-windows-2019: Running GOSS render debug command: cd /tmp/goss && set "GOSS_USE_ALPHA=1" &&  /tmp/goss-windows-amd64.exe --gossfile goss/goss.yaml --vars /tmp/goss/goss-vars.yaml --vars-inline {"ARCH":"amd64","OS":"windows","PROVIDER":"azure","containerd_version":"1.4.3","kubernetes_cni_source_type":"","kubernetes_cni_version":"","kubernetes_source_type":"pkg","kubernetes_version":"v1.17.11"} render -d > /tmp/debug-goss-spec.yaml
==> vhd-windows-2019: Goss render debug ran successfully
==> vhd-windows-2019: Running GOSS validate command: cd /tmp/goss &&  set "GOSS_USE_ALPHA=1" &&  /tmp/goss-windows-amd64.exe --gossfile goss/goss.yaml --vars /tmp/goss/goss-vars.yaml --vars-inline {"ARCH":"amd64","OS":"windows","PROVIDER":"azure","containerd_version":"1.4.3","kubernetes_cni_source_type":"","kubernetes_cni_version":"","kubernetes_source_type":"pkg","kubernetes_version":"v1.17.11"} validate --retry-timeout 0s --sleep 1s -f json -o pretty
    vhd-windows-2019: {
    vhd-windows-2019:     "results": [
    vhd-windows-2019:         {
    vhd-windows-2019:             "duration": 1587645100,
    vhd-windows-2019:             "err": null,
    vhd-windows-2019:             "expected": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "found": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "human": "",
    vhd-windows-2019:             "meta": null,
    vhd-windows-2019:             "property": "exit-status",
    vhd-windows-2019:             "resource-id": "kubectl.exe version --short --client=true -o json | powershell -Command \"($input | convertfrom-json).clientVersion.gitVersion\"",
    vhd-windows-2019:             "resource-type": "Command",
    vhd-windows-2019:             "result": 0,
    vhd-windows-2019:             "successful": true,
    vhd-windows-2019:             "summary-line": "Command: kubectl.exe version --short --client=true -o json | powershell -Command \"($input | convertfrom-json).clientVersion.gitVersion\": exit-status: matches expectation: [0]",
    vhd-windows-2019:             "test-type": 0,
    vhd-windows-2019:             "title": ""
    vhd-windows-2019:         },
    vhd-windows-2019:         {
    vhd-windows-2019:             "duration": 1587645100,
    vhd-windows-2019:             "err": null,
    vhd-windows-2019:             "expected": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "found": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "human": "",
    vhd-windows-2019:             "meta": null,
    vhd-windows-2019:             "property": "exit-status",
    vhd-windows-2019:             "resource-id": "kubeadm.exe version -o json | powershell -Command \"($input | convertfrom-json).clientVersion.gitVersion\"",
    vhd-windows-2019:             "resource-type": "Command",
    vhd-windows-2019:             "result": 0,
    vhd-windows-2019:             "successful": true,
    vhd-windows-2019:             "summary-line": "Command: kubeadm.exe version -o json | powershell -Command \"($input | convertfrom-json).clientVersion.gitVersion\": exit-status: matches expectation: [0]",
    vhd-windows-2019:             "test-type": 0,
    vhd-windows-2019:             "title": ""
    vhd-windows-2019:         },
    vhd-windows-2019:         {
    vhd-windows-2019:             "duration": 1822111700,
    vhd-windows-2019:             "err": null,
    vhd-windows-2019:             "expected": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "found": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "human": "",
    vhd-windows-2019:             "meta": null,
    vhd-windows-2019:             "property": "exit-status",
    vhd-windows-2019:             "resource-id": "kubelet.exe --version | powershell -command \"$input\".Split(\" \")[1]",
    vhd-windows-2019:             "resource-type": "Command",
    vhd-windows-2019:             "result": 0,
    vhd-windows-2019:             "successful": true,
    vhd-windows-2019:             "summary-line": "Command: kubelet.exe --version | powershell -command \"$input\".Split(\" \")[1]: exit-status: matches expectation: [0]",
    vhd-windows-2019:             "test-type": 0,
    vhd-windows-2019:             "title": ""
    vhd-windows-2019:         }
    vhd-windows-2019:     ],
    vhd-windows-2019:     "summary": {
    vhd-windows-2019:         "failed-count": 0,
    vhd-windows-2019:         "summary-line": "Count: 3, Failed: 0, Duration: 1.822s",
    vhd-windows-2019:         "test-count": 3,
    vhd-windows-2019:         "total-duration": 1822111700
    vhd-windows-2019:     }
    vhd-windows-2019: }
==> vhd-windows-2019: Goss validate ran successfully
==> vhd-windows-2019: 
==> vhd-windows-2019: 
==> vhd-windows-2019: 
==> vhd-windows-2019: Downloading spec file and debug info
    vhd-windows-2019: Downloading Goss specs from, /tmp/goss-spec.yaml and /tmp/debug-goss-spec.yaml to current dir
jsturtevant commented 3 years ago

@fishnix would you be able to help?

fishnix commented 3 years ago

Hi @jsturtevant, thanks for the PR! I'll find some cycles to review.

jsturtevant commented 3 years ago

Thanks for finding the time to review! I addressed the comments. If I pushed a github action for building and running the tests on PR would you be interested?

jsturtevant commented 3 years ago

output from a build:

==> vhd-windows-2019: Provisioning with Goss                                                                                                                                                                                                                
==> vhd-windows-2019: Configured to run on Windows 

//truncated

    vhd-windows-2019:     "summary": {
    vhd-windows-2019:         "failed-count": 0,
    vhd-windows-2019:         "summary-line": "Count: 3, Failed: 0, Duration: 2.648s",
    vhd-windows-2019:         "test-count": 3,
    vhd-windows-2019:         "total-duration": 2648382900
    vhd-windows-2019:     }
    vhd-windows-2019: }
==> vhd-windows-2019: Goss validate ran successfully
jsturtevant commented 3 years ago

@fishnix Thanks for the initial review. I addressed most comments would you take a look again? Thanks!

fishnix commented 3 years ago

@jsturtevant thanks for the fixes! 🙇 I'm sorry I haven't had a chance to review this. I will as soon as I can. Cheers!