From c8199458a76eef9cd5b19b57deeaf410cf40cbf8 Mon Sep 17 00:00:00 2001 From: DanHam Date: Fri, 8 Jun 2018 10:49:17 +0100 Subject: [PATCH 1/7] Prevent hang on export for remote ESXi build due to empty remote_password --- builder/vmware/iso/builder.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 31a024455..0944db927 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -221,6 +221,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { fmt.Errorf("format must be one of ova, ovf, or vmx")) } + if b.config.RemoteType == "esx5" && b.config.SkipExport != true && b.config.RemotePassword == "" { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("exporting the vm (with ovftool) requires that you set a value for remote_password")) + } + // Warnings if b.config.ShutdownCommand == "" { warnings = append(warnings, From eee16262b6778ca4061a07089b8415f62f5d87a0 Mon Sep 17 00:00:00 2001 From: DanHam Date: Fri, 8 Jun 2018 11:13:32 +0100 Subject: [PATCH 2/7] Remove duplicate/redundant test --- builder/vmware/iso/builder_test.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/builder/vmware/iso/builder_test.go b/builder/vmware/iso/builder_test.go index b123c1ba9..4b191b2a8 100644 --- a/builder/vmware/iso/builder_test.go +++ b/builder/vmware/iso/builder_test.go @@ -177,18 +177,6 @@ func TestBuilderPrepare_RemoteType(t *testing.T) { if err != nil { t.Fatalf("should not have error: %s", err) } - - // Good - config["remote_type"] = "esx5" - config["remote_host"] = "foobar.example.com" - b = Builder{} - warns, err = b.Prepare(config) - if len(warns) > 0 { - t.Fatalf("bad: %#v", warns) - } - if err != nil { - t.Fatalf("should not have error: %s", err) - } } func TestBuilderPrepare_Format(t *testing.T) { From 0d9134bdbce5685b458af5f42850a5f53616ca30 Mon Sep 17 00:00:00 2001 From: DanHam Date: Fri, 8 Jun 2018 11:29:10 +0100 Subject: [PATCH 3/7] Fix existing tests as they were not doing what they should have been * Fix test to check for remote_host when remote_type is set * Fix tests by including remote_password where required --- builder/vmware/iso/builder_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builder/vmware/iso/builder_test.go b/builder/vmware/iso/builder_test.go index 4b191b2a8..067e0483b 100644 --- a/builder/vmware/iso/builder_test.go +++ b/builder/vmware/iso/builder_test.go @@ -145,6 +145,7 @@ func TestBuilderPrepare_RemoteType(t *testing.T) { config["format"] = "ovf" config["remote_host"] = "foobar.example.com" + config["remote_password"] = "supersecret" // Bad config["remote_type"] = "foobar" warns, err := b.Prepare(config) @@ -155,9 +156,10 @@ func TestBuilderPrepare_RemoteType(t *testing.T) { t.Fatal("should have error") } - config["remote_host"] = "" - config["remote_type"] = "" + config["remote_type"] = "esx5" // Bad + config["remote_host"] = "" + b = Builder{} warns, err = b.Prepare(config) if len(warns) > 0 { t.Fatalf("bad: %#v", warns) @@ -169,6 +171,7 @@ func TestBuilderPrepare_RemoteType(t *testing.T) { // Good config["remote_type"] = "esx5" config["remote_host"] = "foobar.example.com" + config["remote_password"] = "supersecret" b = Builder{} warns, err = b.Prepare(config) if len(warns) > 0 { From efcdf60d96a05364dfc1074fc74c4b9995f3c1a1 Mon Sep 17 00:00:00 2001 From: DanHam Date: Sat, 9 Jun 2018 08:54:20 +0100 Subject: [PATCH 4/7] Add tests to ensure remote_password is set when exporting with ovftool --- builder/vmware/iso/builder_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/builder/vmware/iso/builder_test.go b/builder/vmware/iso/builder_test.go index 067e0483b..d1a7282a9 100644 --- a/builder/vmware/iso/builder_test.go +++ b/builder/vmware/iso/builder_test.go @@ -182,6 +182,34 @@ func TestBuilderPrepare_RemoteType(t *testing.T) { } } +func TestBuilderPrepare_RemoteExport(t *testing.T) { + var b Builder + config := testConfig() + + config["remote_type"] = "esx5" + config["remote_host"] = "foobar.example.com" + // Bad + config["remote_password"] = "" + warns, err := b.Prepare(config) + if len(warns) != 0 { + t.Fatalf("bad: %#v", warns) + } + if err == nil { + t.Fatal("should have error") + } + + // Good + config["remote_password"] = "supersecret" + b = Builder{} + warns, err = b.Prepare(config) + if len(warns) != 0 { + t.Fatalf("err: %s", err) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } +} + func TestBuilderPrepare_Format(t *testing.T) { var b Builder config := testConfig() From 939aa7e289f61ee48cc1bb3517f07f9b878a9985 Mon Sep 17 00:00:00 2001 From: DanHam Date: Mon, 2 Jul 2018 18:07:05 +0100 Subject: [PATCH 5/7] Add test: We shouldn't error when main remote options are unset --- builder/vmware/iso/builder_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/builder/vmware/iso/builder_test.go b/builder/vmware/iso/builder_test.go index d1a7282a9..59e18907d 100644 --- a/builder/vmware/iso/builder_test.go +++ b/builder/vmware/iso/builder_test.go @@ -168,6 +168,20 @@ func TestBuilderPrepare_RemoteType(t *testing.T) { t.Fatal("should have error") } + // Good + config["remote_type"] = "" + config["remote_host"] = "" + config["remote_password"] = "" + config["remote_private_key_file"] = "" + b = Builder{} + warns, err = b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + // Good config["remote_type"] = "esx5" config["remote_host"] = "foobar.example.com" From 66f9b64ff1a7aae4199b6b30eb2d40d20829c1e8 Mon Sep 17 00:00:00 2001 From: DanHam Date: Tue, 12 Jun 2018 14:27:08 +0100 Subject: [PATCH 6/7] Docs: Users must set remote_password when exporting the VM with ovftool --- website/source/docs/builders/vmware-iso.html.md.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/source/docs/builders/vmware-iso.html.md.erb b/website/source/docs/builders/vmware-iso.html.md.erb index 21d19c183..8e1a77415 100644 --- a/website/source/docs/builders/vmware-iso.html.md.erb +++ b/website/source/docs/builders/vmware-iso.html.md.erb @@ -540,6 +540,9 @@ modify as well: format of the exported virtual machine. This defaults to "ovf". Before using this option, you need to install `ovftool`. This option works currently only with option remote_type set to "esx5". + Since ovftool is only capable of password based authentication + `remote_password` must be set when exporting the VM. + ### VNC port discovery From 71f649456967daa72c40d50208592b489f1dee64 Mon Sep 17 00:00:00 2001 From: DanHam Date: Mon, 2 Jul 2018 18:08:55 +0100 Subject: [PATCH 7/7] Docs: Try and clarify export and export related opts only work with ESXi --- .../source/docs/builders/vmware-iso.html.md.erb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/website/source/docs/builders/vmware-iso.html.md.erb b/website/source/docs/builders/vmware-iso.html.md.erb index 8e1a77415..ee47b5a47 100644 --- a/website/source/docs/builders/vmware-iso.html.md.erb +++ b/website/source/docs/builders/vmware-iso.html.md.erb @@ -332,8 +332,13 @@ builder. using this configuration value. Defaults to `false`. - `skip_export` (boolean) - Defaults to `false`. When enabled, Packer will - not export the VM. Useful if the build output is not the resultant image, - but created inside the VM. + not export the VM. Useful if the build output is not the resultant + image, but created inside the VM. + Currently, exporting the build VM is only supported when building on + ESXi e.g. when `remote_type` is set to `esx5`. See the [Building on a + Remote vSphere + Hypervisor](/docs/builders/vmware-iso.html#building-on-a-remote-vsphere-hypervisor) + section below for more info. - `keep_registered` (boolean) - Set this to `true` if you would like to keep the VM registered with the remote ESXi server. This is convenient if you @@ -345,6 +350,11 @@ builder. during export. Each item in the array is a new argument. The options `--noSSLVerify`, `--skipManifestCheck`, and `--targetType` are reserved, and should not be passed to this argument. + Currently, exporting the build VM (with ovftool) is only supported when + building on ESXi e.g. when `remote_type` is set to `esx5`. See the + [Building on a Remote vSphere + Hypervisor](/docs/builders/vmware-iso.html#building-on-a-remote-vsphere-hypervisor) + section below for more info. - `sound` (boolean) - Enable VMware's virtual soundcard device for the VM. @@ -539,7 +549,7 @@ modify as well: - `format` (string) - Either "ovf", "ova" or "vmx", this specifies the output format of the exported virtual machine. This defaults to "ovf". Before using this option, you need to install `ovftool`. This option - works currently only with option remote_type set to "esx5". + currently only works when option remote_type is set to "esx5". Since ovftool is only capable of password based authentication `remote_password` must be set when exporting the VM.