forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove deprecated parallels_tools_host_path and guest_os_distribution
- Loading branch information
1 parent
28b045e
commit fd62825
Showing
5 changed files
with
197 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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".` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |