Merge pull request #2793 from svanharmelen/b-chef-sudo

provisioner/chef: fix error when uploading `hints` when using `sudo`
This commit is contained in:
Mitchell Hashimoto 2015-07-20 09:38:19 -07:00
commit a6183212db
2 changed files with 26 additions and 6 deletions

View File

@ -71,12 +71,29 @@ func (p *Provisioner) linuxCreateConfigFiles(
return err
}
// Make sure we have enough rights to upload the hints if using sudo
if p.useSudo {
if err := p.runCommand(o, comm, "chmod 777 "+hintsDir); err != nil {
return err
}
}
if err := p.deployOhaiHints(o, comm, hintsDir); err != nil {
return err
}
// When done copying the hints restore the rights and make sure root is owner
if p.useSudo {
if err := p.runCommand(o, comm, "chmod 755 "+hintsDir); err != nil {
return err
}
if err := p.runCommand(o, comm, "chown -R root.root "+hintsDir); err != nil {
return err
}
}
}
// When done copying the files restore the rights and make sure root is owner
// When done copying all files restore the rights and make sure root is owner
if p.useSudo {
if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil {
return err

View File

@ -163,11 +163,14 @@ func TestResourceProvider_linuxCreateConfigFiles(t *testing.T) {
}),
Commands: map[string]bool{
"sudo mkdir -p " + linuxConfDir: true,
"sudo chmod 777 " + linuxConfDir: true,
"sudo mkdir -p " + path.Join(linuxConfDir, "ohai/hints"): true,
"sudo chmod 755 " + linuxConfDir: true,
"sudo chown -R root.root " + linuxConfDir: true,
"sudo mkdir -p " + linuxConfDir: true,
"sudo chmod 777 " + linuxConfDir: true,
"sudo mkdir -p " + path.Join(linuxConfDir, "ohai/hints"): true,
"sudo chmod 777 " + path.Join(linuxConfDir, "ohai/hints"): true,
"sudo chmod 755 " + path.Join(linuxConfDir, "ohai/hints"): true,
"sudo chown -R root.root " + path.Join(linuxConfDir, "ohai/hints"): true,
"sudo chmod 755 " + linuxConfDir: true,
"sudo chown -R root.root " + linuxConfDir: true,
},
Uploads: map[string]string{