From 986245c553d5a3abd659d5b5682ce987da94c653 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Sat, 9 Jan 2016 15:56:49 +0100 Subject: [PATCH] provisioner/chef: fixes #4262 This small tweak fixes #4262 by making sure files can be uploaded correctly. --- .../provisioners/chef/linux_provisioner.go | 13 ++++++++++++ .../chef/linux_provisioner_test.go | 21 ++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/builtin/provisioners/chef/linux_provisioner.go b/builtin/provisioners/chef/linux_provisioner.go index b7a3b2813..ebfe72979 100644 --- a/builtin/provisioners/chef/linux_provisioner.go +++ b/builtin/provisioners/chef/linux_provisioner.go @@ -10,6 +10,7 @@ import ( ) const ( + chmod = "find %s -maxdepth 1 -type f -exec /bin/chmod %d {} +" installURL = "https://www.chef.io/chef/install.sh" ) @@ -58,6 +59,9 @@ func (p *Provisioner) linuxCreateConfigFiles( if err := p.runCommand(o, comm, "chmod 777 "+linuxConfDir); err != nil { return err } + if err := p.runCommand(o, comm, fmt.Sprintf(chmod, linuxConfDir, 666)); err != nil { + return err + } } if err := p.deployConfigFiles(o, comm, linuxConfDir); err != nil { @@ -76,6 +80,9 @@ func (p *Provisioner) linuxCreateConfigFiles( if err := p.runCommand(o, comm, "chmod 777 "+hintsDir); err != nil { return err } + if err := p.runCommand(o, comm, fmt.Sprintf(chmod, hintsDir, 666)); err != nil { + return err + } } if err := p.deployOhaiHints(o, comm, hintsDir); err != nil { @@ -87,6 +94,9 @@ func (p *Provisioner) linuxCreateConfigFiles( if err := p.runCommand(o, comm, "chmod 755 "+hintsDir); err != nil { return err } + if err := p.runCommand(o, comm, fmt.Sprintf(chmod, hintsDir, 600)); err != nil { + return err + } if err := p.runCommand(o, comm, "chown -R root.root "+hintsDir); err != nil { return err } @@ -98,6 +108,9 @@ func (p *Provisioner) linuxCreateConfigFiles( if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil { return err } + if err := p.runCommand(o, comm, fmt.Sprintf(chmod, linuxConfDir, 600)); err != nil { + return err + } if err := p.runCommand(o, comm, "chown -R root.root "+linuxConfDir); err != nil { return err } diff --git a/builtin/provisioners/chef/linux_provisioner_test.go b/builtin/provisioners/chef/linux_provisioner_test.go index 6c57bfef0..b068df30c 100644 --- a/builtin/provisioners/chef/linux_provisioner_test.go +++ b/builtin/provisioners/chef/linux_provisioner_test.go @@ -1,6 +1,7 @@ package chef import ( + "fmt" "path" "testing" @@ -163,14 +164,18 @@ 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 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, + "sudo mkdir -p " + linuxConfDir: true, + "sudo chmod 777 " + linuxConfDir: true, + "sudo " + fmt.Sprintf(chmod, linuxConfDir, 666): true, + "sudo mkdir -p " + path.Join(linuxConfDir, "ohai/hints"): true, + "sudo chmod 777 " + path.Join(linuxConfDir, "ohai/hints"): true, + "sudo " + fmt.Sprintf(chmod, path.Join(linuxConfDir, "ohai/hints"), 666): true, + "sudo chmod 755 " + path.Join(linuxConfDir, "ohai/hints"): true, + "sudo " + fmt.Sprintf(chmod, path.Join(linuxConfDir, "ohai/hints"), 600): true, + "sudo chown -R root.root " + path.Join(linuxConfDir, "ohai/hints"): true, + "sudo chmod 755 " + linuxConfDir: true, + "sudo " + fmt.Sprintf(chmod, linuxConfDir, 600): true, + "sudo chown -R root.root " + linuxConfDir: true, }, Uploads: map[string]string{