summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Stone <aaron@serendipity.cx>2014-10-29 07:08:37 -0700
committerAaron Stone <aaron@serendipity.cx>2014-10-29 07:08:37 -0700
commit35f773056485f06fc42e9e4dced930de7a3e1fa2 (patch)
tree2623269e03771c1e512c3e3d11136480b52f3bd2
parentf6f870b959d1c897cbe23778e54087550e110d14 (diff)
parent2b927e514a3d8aef5d35094e84dee3d6b47d6bf2 (diff)
downloadpuppet-vcsrepo-35f773056485f06fc42e9e4dced930de7a3e1fa2.tar.gz
puppet-vcsrepo-35f773056485f06fc42e9e4dced930de7a3e1fa2.tar.bz2
Merge pull request #213 from jfautley/cvs-runas
Add `user` feature support to CVS provider
-rw-r--r--README.markdown4
-rw-r--r--lib/puppet/provider/vcsrepo/cvs.rb22
-rw-r--r--spec/unit/puppet/provider/vcsrepo/cvs_spec.rb19
3 files changed, 26 insertions, 19 deletions
diff --git a/README.markdown b/README.markdown
index 6d03a7c..de6ae9a 100644
--- a/README.markdown
+++ b/README.markdown
@@ -456,7 +456,7 @@ The vcsrepo module is slightly unusual in that it is simply a type and providers
* `git` - Supports the Git VCS. (Contains features: `bare_repositories`, `depth`, `multiple_remotes`, `reference_tracking`, `ssh_identity`, `user`.)
* `bar` - Supports the Bazaar VCS. (Contains features: `reference_tracking`.)
-* `cvs` - Supports the CVS VCS. (Contains features: `cvs_rsh`, `gzip_compression`, `modules`,`reference_tracking`.)
+* `cvs` - Supports the CVS VCS. (Contains features: `cvs_rsh`, `gzip_compression`, `modules`, `reference_tracking`, `user`.)
* `dummy` -
* `hg` - Supports the Mercurial VCS. (Contains features: `reference_tracking`, `ssh_identity`, `user`.)
* `p4` - Supports the Perforce VCS. (Contains features: `reference_tracking`, `filesystem_types`, `p4config`.)
@@ -477,7 +477,7 @@ The vcsrepo module is slightly unusual in that it is simply a type and providers
* `multiple_remotes` - The repository tracks multiple remote repositories. (Available with `git`.)
* `reference_tracking` - The provider supports tracking revision references that can change over time (e.g. some VCS tags and branch names). (Available with `bar`, `cvs`, `git`, `hg`, `svn`.)
* `ssh_identity` - The provider supports a configurable SSH identity file. (Available with `git` and `hg`.)
-* `user` - The provider can run as a different user. (Available with `git` and `hg`.)
+* `user` - The provider can run as a different user. (Available with `git`, `hg` and `cvs`.)
* `p4config` - The provider support setting the P4CONFIG environment. (Available with `p4`.)
####Parameters
diff --git a/lib/puppet/provider/vcsrepo/cvs.rb b/lib/puppet/provider/vcsrepo/cvs.rb
index 01094b1..7a8f6ef 100644
--- a/lib/puppet/provider/vcsrepo/cvs.rb
+++ b/lib/puppet/provider/vcsrepo/cvs.rb
@@ -4,7 +4,7 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo)
desc "Supports CVS repositories/workspaces"
commands :cvs => 'cvs'
- has_features :gzip_compression, :reference_tracking, :modules, :cvs_rsh
+ has_features :gzip_compression, :reference_tracking, :modules, :cvs_rsh, :user
def create
if !@resource.value(:source)
@@ -33,13 +33,13 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo)
end
def latest?
- debug "Checking for updates because 'ensure => latest'"
+ Puppet.debug "Checking for updates because 'ensure => latest'"
at_path do
# We cannot use -P to prune empty dirs, otherwise
# CVS would report those as "missing", regardless
# if they have contents or updates.
is_current = (runcvs('-nq', 'update', '-d').strip == "")
- if (!is_current) then debug "There are updates available on the checkout's current branch/tag." end
+ if (!is_current) then Puppet.debug "There are updates available on the checkout's current branch/tag." end
return is_current
end
end
@@ -62,7 +62,7 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo)
else
@rev = 'HEAD'
end
- debug "Checkout is on branch/tag '#{@rev}'"
+ Puppet.debug "Checkout is on branch/tag '#{@rev}'"
end
return @rev
end
@@ -119,19 +119,17 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo)
def runcvs(*args)
if @resource.value(:cvs_rsh)
- debug "Using CVS_RSH = " + @resource.value(:cvs_rsh)
+ Puppet.debug "Using CVS_RSH = " + @resource.value(:cvs_rsh)
e = { :CVS_RSH => @resource.value(:cvs_rsh) }
else
e = {}
end
- # The location of withenv changed from Puppet 2.x to 3.x
- withenv = Puppet::Util.method(:withenv) if Puppet::Util.respond_to?(:withenv)
- withenv = Puppet::Util::Execution.method(:withenv) if Puppet::Util::Execution.respond_to?(:withenv)
- fail("Cannot set custom environment #{e}") if e && !withenv
-
- withenv.call e do
- Puppet.debug cvs *args
+ if @resource.value(:user) and @resource.value(:user) != Facter['id'].value
+ Puppet.debug "Running as user " + @resource.value(:user)
+ Puppet::Util::Execution.execute([:cvs, *args], :uid => @resource.value(:user), :custom_environment => e)
+ else
+ Puppet::Util::Execution.execute([:cvs, *args], :custom_environment => e)
end
end
end
diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb
index f5eebd9..2e18149 100644
--- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb
@@ -23,14 +23,23 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do
resource[:source] = ':ext:source@example.com:/foo/bar'
resource[:revision] = 'an-unimportant-value'
expects_chdir('/tmp')
- provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar')
+ Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :custom_environment => {})
+ provider.create
+ end
+
+ it "should execute 'cvs checkout' as user 'muppet'" do
+ resource[:source] = ':ext:source@example.com:/foo/bar'
+ resource[:revision] = 'an-unimportant-value'
+ resource[:user] = 'muppet'
+ expects_chdir('/tmp')
+ Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :uid => 'muppet', :custom_environment => {})
provider.create
end
it "should just execute 'cvs checkout' without a revision" do
resource[:source] = ':ext:source@example.com:/foo/bar'
resource.delete(:revision)
- provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
+ Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))], :custom_environment => {})
provider.create
end
@@ -39,7 +48,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do
resource[:source] = ':ext:source@example.com:/foo/bar'
resource[:compression] = '3'
resource.delete(:revision)
- provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
+ Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))], :custom_environment => {})
provider.create
end
end
@@ -48,7 +57,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do
context "when a source is not given" do
it "should execute 'cvs init'" do
resource.delete(:source)
- provider.expects(:cvs).with('-d', resource.value(:path), 'init')
+ Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:path), 'init'], :custom_environment => {})
provider.create
end
end
@@ -107,7 +116,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do
it "should use 'cvs update -dr'" do
expects_chdir
- provider.expects(:cvs).with('update', '-dr', @tag, '.')
+ Puppet::Util::Execution.expects(:execute).with([:cvs, 'update', '-dr', @tag, '.'], :custom_environment => {})
provider.revision = @tag
end
end