Tweaking a few minor things according to the feedback on GH

This commit is contained in:
Sander van Harmelen 2015-05-12 10:37:38 +02:00
parent a8dacede24
commit 11314a3d71
6 changed files with 16 additions and 12 deletions

View File

@ -74,6 +74,7 @@ type Provisioner struct {
installChefClient func(terraform.UIOutput, communicator.Communicator) error
createConfigFiles func(terraform.UIOutput, communicator.Communicator) error
runChefClient func(terraform.UIOutput, communicator.Communicator) error
useSudo bool
}
// ResourceProvisioner represents a generic chef provisioner
@ -93,15 +94,15 @@ func (r *ResourceProvisioner) Apply(
// Set some values based on the targeted OS
switch s.Ephemeral.ConnInfo["type"] {
case "ssh", "": // The default connection type is ssh, so if the type is empty use ssh
p.PreventSudo = p.PreventSudo || s.Ephemeral.ConnInfo["user"] == "root"
p.installChefClient = p.sshInstallChefClient
p.createConfigFiles = p.sshCreateConfigFiles
p.runChefClient = p.runChefClientFunc(linuxConfDir)
p.useSudo = !p.PreventSudo && s.Ephemeral.ConnInfo["user"] != "root"
case "winrm":
p.PreventSudo = true
p.installChefClient = p.winrmInstallChefClient
p.createConfigFiles = p.winrmCreateConfigFiles
p.runChefClient = p.runChefClientFunc(windowsConfDir)
p.useSudo = false
default:
return fmt.Errorf("Unsupported connection type: %s", s.Ephemeral.ConnInfo["type"])
}
@ -363,7 +364,7 @@ func (p *Provisioner) runCommand(
var err error
// Unless prevented, prefix the command with sudo
if !p.PreventSudo {
if p.useSudo {
command = "sudo " + command
}

View File

@ -126,6 +126,7 @@ func TestResourceProvider_runChefClient(t *testing.T) {
}
p.runChefClient = p.runChefClientFunc(tc.ConfDir)
p.useSudo = !p.PreventSudo
err = p.runChefClient(o, c)
if err != nil {

View File

@ -50,7 +50,7 @@ func (p *Provisioner) sshCreateConfigFiles(
}
// Make sure we have enough rights to upload the files if using sudo
if !p.PreventSudo {
if p.useSudo {
if err := p.runCommand(o, comm, "chmod 777 "+linuxConfDir); err != nil {
return err
}
@ -61,7 +61,7 @@ func (p *Provisioner) sshCreateConfigFiles(
}
// When done copying the files restore the rights and make sure root is owner
if !p.PreventSudo {
if p.useSudo {
if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil {
return err
}

View File

@ -116,6 +116,8 @@ func TestResourceProvider_sshInstallChefClient(t *testing.T) {
t.Fatalf("Error: %v", err)
}
p.useSudo = !p.PreventSudo
err = p.sshInstallChefClient(o, c)
if err != nil {
t.Fatalf("Test %q failed: %v", k, err)
@ -254,6 +256,8 @@ func TestResourceProvider_sshCreateConfigFiles(t *testing.T) {
t.Fatalf("Error: %v", err)
}
p.useSudo = !p.PreventSudo
err = p.sshCreateConfigFiles(o, c)
if err != nil {
t.Fatalf("Test %q failed: %v", k, err)

View File

@ -17,7 +17,6 @@ func TestResourceProvider_winrmInstallChefClient(t *testing.T) {
"Default": {
Config: testConfig(t, map[string]interface{}{
"node_name": "nodename1",
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
"run_list": []interface{}{"cookbook::recipe"},
"server_url": "https://chef.local",
"validation_client_name": "validator",
@ -38,7 +37,6 @@ func TestResourceProvider_winrmInstallChefClient(t *testing.T) {
"http_proxy": "http://proxy.local",
"no_proxy": []interface{}{"http://local.local", "http://local.org"},
"node_name": "nodename1",
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
"run_list": []interface{}{"cookbook::recipe"},
"server_url": "https://chef.local",
"validation_client_name": "validator",
@ -57,7 +55,6 @@ func TestResourceProvider_winrmInstallChefClient(t *testing.T) {
"Version": {
Config: testConfig(t, map[string]interface{}{
"node_name": "nodename1",
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
"run_list": []interface{}{"cookbook::recipe"},
"server_url": "https://chef.local",
"validation_client_name": "validator",
@ -88,6 +85,8 @@ func TestResourceProvider_winrmInstallChefClient(t *testing.T) {
t.Fatalf("Error: %v", err)
}
p.useSudo = false
err = p.winrmInstallChefClient(o, c)
if err != nil {
t.Fatalf("Test %q failed: %v", k, err)
@ -104,7 +103,6 @@ func TestResourceProvider_winrmCreateConfigFiles(t *testing.T) {
"Default": {
Config: testConfig(t, map[string]interface{}{
"node_name": "nodename1",
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
"run_list": []interface{}{"cookbook::recipe"},
"server_url": "https://chef.local",
"validation_client_name": "validator",
@ -128,7 +126,6 @@ func TestResourceProvider_winrmCreateConfigFiles(t *testing.T) {
"https_proxy": "https://proxy.local",
"no_proxy": []interface{}{"http://local.local", "https://local.local"},
"node_name": "nodename1",
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
"run_list": []interface{}{"cookbook::recipe"},
"server_url": "https://chef.local",
"validation_client_name": "validator",
@ -170,7 +167,6 @@ func TestResourceProvider_winrmCreateConfigFiles(t *testing.T) {
},
},
"node_name": "nodename1",
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
"run_list": []interface{}{"cookbook::recipe"},
"server_url": "https://chef.local",
"validation_client_name": "validator",
@ -203,6 +199,8 @@ func TestResourceProvider_winrmCreateConfigFiles(t *testing.T) {
t.Fatalf("Error: %v", err)
}
p.useSudo = false
err = p.winrmCreateConfigFiles(o, c)
if err != nil {
t.Fatalf("Test %q failed: %v", k, err)

View File

@ -48,7 +48,7 @@ resource "aws_instance" "web" {
The following arguments are supported:
* `attributes (hash)` - (Optional) A hash with initial node attributes for the new node.
* `attributes (map)` - (Optional) A map with initial node attributes for the new node.
See example.
* `environment (string)` - (Optional) The Chef environment the new node will be joining