Skip to content

Commit

Permalink
Remove deprecated parallels_tools_host_path and guest_os_distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
rickard-von-essen committed Feb 1, 2016
1 parent 28b045e commit fd62825
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 62 deletions.
20 changes: 0 additions & 20 deletions builder/parallels/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ type Config struct {
SkipCompaction bool `mapstructure:"skip_compaction"`
VMName string `mapstructure:"vm_name"`

// Deprecated parameters
GuestOSDistribution string `mapstructure:"guest_os_distribution"`
ParallelsToolsHostPath string `mapstructure:"parallels_tools_host_path"`

ctx interpolate.Context
}

Expand Down Expand Up @@ -99,16 +95,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.GuestOSType = "other"
}

if b.config.GuestOSDistribution != "" {
// Compatibility with older templates:
// Use value of 'guest_os_distribution' if it is defined.
b.config.GuestOSType = b.config.GuestOSDistribution
warnings = append(warnings,
"A 'guest_os_distribution' has been completely replaced with 'guest_os_type'\n"+
"It is recommended to remove it and assign the previous value to 'guest_os_type'.\n"+
"Run it to see all available values: `prlctl create x -d list` ")
}

if len(b.config.HostInterfaces) == 0 {
b.config.HostInterfaces = []string{"en0", "en1", "en2", "en3", "en4", "en5", "en6", "en7",
"en8", "en9", "ppp0", "ppp1", "ppp2"}
Expand All @@ -130,12 +116,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
"will forcibly halt the virtual machine, which may result in data loss.")
}

if b.config.ParallelsToolsHostPath != "" {
warnings = append(warnings,
"A 'parallels_tools_host_path' has been deprecated and not in use anymore\n"+
"You can remove it from your Packer template.")
}

if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
}
Expand Down
35 changes: 0 additions & 35 deletions builder/parallels/iso/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,6 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
}
}

func TestBuilderPrepare_GuestOSType(t *testing.T) {
var b Builder
config := testConfig()
delete(config, "guest_os_distribution")

// Test deprecated parameter
config["guest_os_distribution"] = "bolgenos"
warns, err := b.Prepare(config)
if len(warns) == 0 {
t.Fatalf("should have warning")
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.GuestOSType != "bolgenos" {
t.Fatalf("bad: %s", b.config.GuestOSType)
}
}

func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
var b Builder
config := testConfig()
Expand Down Expand Up @@ -152,19 +133,3 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
t.Fatal("should have error")
}
}

func TestBuilderPrepare_ParallelsToolsHostPath(t *testing.T) {
var b Builder
config := testConfig()
delete(config, "parallels_tools_host_path")

// Test that it is deprecated
config["parallels_tools_host_path"] = "/path/to/iso"
warns, err := b.Prepare(config)
if len(warns) == 0 {
t.Fatalf("should have warning")
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
}
16 changes: 9 additions & 7 deletions fix/fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ var FixerOrder []string

func init() {
Fixers = map[string]Fixer{
"iso-md5": new(FixerISOMD5),
"createtime": new(FixerCreateTime),
"pp-vagrant-override": new(FixerVagrantPPOverride),
"virtualbox-gaattach": new(FixerVirtualBoxGAAttach),
"virtualbox-rename": new(FixerVirtualBoxRename),
"vmware-rename": new(FixerVMwareRename),
"parallels-headless": new(FixerParallelsHeadless),
"iso-md5": new(FixerISOMD5),
"createtime": new(FixerCreateTime),
"pp-vagrant-override": new(FixerVagrantPPOverride),
"virtualbox-gaattach": new(FixerVirtualBoxGAAttach),
"virtualbox-rename": new(FixerVirtualBoxRename),
"vmware-rename": new(FixerVMwareRename),
"parallels-headless": new(FixerParallelsHeadless),
"parallels-deprecations": new(FixerParallelsDeprecations),
}

FixerOrder = []string{
Expand All @@ -37,5 +38,6 @@ func init() {
"virtualbox-rename",
"vmware-rename",
"parallels-headless",
"parallels-deprecations",
}
}
59 changes: 59 additions & 0 deletions fix/fixer_parallels_deprections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package fix

import (
"github.com/mitchellh/mapstructure"
)

// FixerParallelsDeprecations removes "parallels_tools_host_path" from a
// template in a Parallels builder and changes "guest_os_distribution" to
// "guest_os_type", possibly overwriting any existing "guest_os_type"
type FixerParallelsDeprecations struct{}

func (FixerParallelsDeprecations) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {
Builders []map[string]interface{}
}

// Decode the input into our structure, if we can
var tpl template
if err := mapstructure.Decode(input, &tpl); err != nil {
return nil, err
}

for _, builder := range tpl.Builders {
builderTypeRaw, ok := builder["type"]
if !ok {
continue
}

builderType, ok := builderTypeRaw.(string)
if !ok {
continue
}

if builderType != "parallels-iso" && builderType != "parallels-pvm" {
continue
}

_, ok = builder["parallels_tools_host_path"]
if ok {
delete(builder, "parallels_tools_host_path")
}

guestOsDistribution, ok := builder["guest_os_distribution"]

if ok {
builder["guest_os_type"] = guestOsDistribution
delete(builder, "guest_os_distribution")
}
}

input["builders"] = tpl.Builders
return input, nil
}

func (FixerParallelsDeprecations) Synopsis() string {
return `Removes deprecated "parallels_tools_host_path" from Parallels builders
and changes "guest_os_distribution" to "guest_os_type".`
}
129 changes: 129 additions & 0 deletions fix/fixer_parallels_deprections_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package fix

import (
"reflect"
"testing"
)

func TestFixerParallelsDeprecations(t *testing.T) {
var _ Fixer = new(FixerParallelsDeprecations)
}

func TestFixerParallelsDeprecations_Fix_parallels_tools_guest_path(t *testing.T) {
cases := []struct {
Input map[string]interface{}
Expected map[string]interface{}
}{
// No parallels_tools_host_path field
{
Input: map[string]interface{}{
"type": "parallels-iso",
},

Expected: map[string]interface{}{
"type": "parallels-iso",
},
},

// parallels_tools_host_path field
{
Input: map[string]interface{}{
"type": "parallels-iso",
"parallels_tools_host_path": "/Path...",
},

Expected: map[string]interface{}{
"type": "parallels-iso",
},
},
}

for _, tc := range cases {
var f FixerParallelsDeprecations

input := map[string]interface{}{
"builders": []map[string]interface{}{tc.Input},
}

expected := map[string]interface{}{
"builders": []map[string]interface{}{tc.Expected},
}

output, err := f.Fix(input)
if err != nil {
t.Fatalf("err: %s", err)
}

if !reflect.DeepEqual(output, expected) {
t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
}
}
}

func TestFixerParallelsDeprecations_Fix_guest_os_distribution(t *testing.T) {
cases := []struct {
Input map[string]interface{}
Expected map[string]interface{}
}{
// No guest_os_distribution field
{
Input: map[string]interface{}{
"type": "parallels-iso",
"guest_os_type": "ubuntu",
},

Expected: map[string]interface{}{
"type": "parallels-iso",
"guest_os_type": "ubuntu",
},
},

// guest_os_distribution and guest_os_type field
{
Input: map[string]interface{}{
"type": "parallels-iso",
"guest_os_type": "linux",
"guest_os_distribution": "ubuntu",
},

Expected: map[string]interface{}{
"type": "parallels-iso",
"guest_os_type": "ubuntu",
},
},

// guest_os_distribution but no guest_os_type field
{
Input: map[string]interface{}{
"type": "parallels-iso",
"guest_os_distribution": "ubuntu",
},

Expected: map[string]interface{}{
"type": "parallels-iso",
"guest_os_type": "ubuntu",
},
},
}

for _, tc := range cases {
var f FixerParallelsDeprecations

input := map[string]interface{}{
"builders": []map[string]interface{}{tc.Input},
}

expected := map[string]interface{}{
"builders": []map[string]interface{}{tc.Expected},
}

output, err := f.Fix(input)
if err != nil {
t.Fatalf("err: %s", err)
}

if !reflect.DeepEqual(output, expected) {
t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
}
}
}

0 comments on commit fd62825

Please sign in to comment.