Merge pull request #8411 from kevingunn-wk/fix_8410
rename galaxy_command to galaxycommand
This commit is contained in:
commit
b79986c3c5
|
@ -45,6 +45,7 @@ func init() {
|
|||
"clean-image-name": new(FixerCleanImageName),
|
||||
"spot-price-auto-product": new(FixerAmazonSpotPriceProductDeprecation),
|
||||
"qemu-disk-size": new(FixerQEMUDiskSize),
|
||||
"galaxy-command": new(FixerGalaxyCommand),
|
||||
}
|
||||
|
||||
FixerOrder = []string{
|
||||
|
@ -73,5 +74,6 @@ func init() {
|
|||
"clean-image-name",
|
||||
"spot-price-auto-product",
|
||||
"qemu-disk-size",
|
||||
"galaxy-command",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// FixerGalaxyCommand removes the escape character from user
|
||||
// environment variables and replace galaxycommand with galaxy_command
|
||||
type FixerGalaxyCommand struct{}
|
||||
|
||||
func (FixerGalaxyCommand) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
||||
type template struct {
|
||||
Provisioners []interface{}
|
||||
}
|
||||
|
||||
// Decode the input into our structure, if we can
|
||||
var tpl template
|
||||
if err := mapstructure.WeakDecode(input, &tpl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i, raw := range tpl.Provisioners {
|
||||
var provisioners map[string]interface{}
|
||||
if err := mapstructure.Decode(raw, &provisioners); err != nil {
|
||||
// Ignore errors, could be a non-map
|
||||
continue
|
||||
}
|
||||
|
||||
if ok := provisioners["type"] == "ansible-local"; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := provisioners["galaxy_command"]; ok {
|
||||
|
||||
// drop galaxycommand if it is also included
|
||||
if _, galaxyCommandIncluded := provisioners["galaxycommand"]; galaxyCommandIncluded {
|
||||
delete(provisioners, "galaxycommand")
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// replace galaxycommand with galaxy_command if it exists
|
||||
galaxyCommandRaw, ok := provisioners["galaxycommand"]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
galaxyCommandString, ok := galaxyCommandRaw.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
delete(provisioners, "galaxycommand")
|
||||
provisioners["galaxy_command"] = galaxyCommandString
|
||||
}
|
||||
|
||||
// Write all changes back to template
|
||||
tpl.Provisioners[i] = provisioners
|
||||
}
|
||||
|
||||
if len(tpl.Provisioners) > 0 {
|
||||
input["provisioners"] = tpl.Provisioners
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (FixerGalaxyCommand) Synopsis() string {
|
||||
return `Replaces "galaxycommad" in ansible-local provisioner configs with "galaxy_command"`
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFixerGalaxyCommand_Impl(t *testing.T) {
|
||||
var _ Fixer = new(FixerGalaxyCommand)
|
||||
}
|
||||
|
||||
func TestFixerGalaxyCommand_Fix(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input map[string]interface{}
|
||||
Expected map[string]interface{}
|
||||
}{
|
||||
// set galaxy_command
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "ansible-local",
|
||||
"galaxy_command": "/usr/local/bin/ansible-galaxy",
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "ansible-local",
|
||||
"galaxy_command": "/usr/local/bin/ansible-galaxy",
|
||||
},
|
||||
},
|
||||
|
||||
// set galaxycommand (old key)
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "ansible-local",
|
||||
"galaxycommand": "/usr/bin/ansible-galaxy",
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "ansible-local",
|
||||
"galaxy_command": "/usr/bin/ansible-galaxy",
|
||||
},
|
||||
},
|
||||
|
||||
// set galaxy_command and galaxycommand
|
||||
// galaxy_command takes precedence
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "ansible-local",
|
||||
"galaxy_command": "ansible_galaxy_command",
|
||||
"galaxycommand": "ansible_galaxycommand",
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "ansible-local",
|
||||
"galaxy_command": "ansible_galaxy_command",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
var f FixerGalaxyCommand
|
||||
|
||||
input := map[string]interface{}{
|
||||
"provisioners": []interface{}{tc.Input},
|
||||
}
|
||||
|
||||
expected := map[string]interface{}{
|
||||
"provisioners": []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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -67,7 +67,7 @@ type Config struct {
|
|||
GalaxyFile string `mapstructure:"galaxy_file"`
|
||||
|
||||
// The command to run ansible-galaxy
|
||||
GalaxyCommand string
|
||||
GalaxyCommand string `mapstructure:"galaxy_command"`
|
||||
}
|
||||
|
||||
type Provisioner struct {
|
||||
|
|
|
@ -30,7 +30,7 @@ type FlatConfig struct {
|
|||
InventoryFile *string `mapstructure:"inventory_file" cty:"inventory_file"`
|
||||
InventoryGroups []string `mapstructure:"inventory_groups" cty:"inventory_groups"`
|
||||
GalaxyFile *string `mapstructure:"galaxy_file" cty:"galaxy_file"`
|
||||
GalaxyCommand *string `cty:"galaxy_command"`
|
||||
GalaxyCommand *string `mapstructure:"galaxy_command" cty:"galaxy_command"`
|
||||
}
|
||||
|
||||
// FlatMapstructure returns a new FlatConfig.
|
||||
|
|
Loading…
Reference in New Issue