mirror of https://github.com/hashicorp/packer
Merge pull request #2751 from rickard-von-essen/prl_deprecations
Remove deprecated parallels_tools_host_path and guest_os_distributionpull/2776/merge
commit
2155576fd6
@ -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".`
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue