summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
authorPaul Allen <pallen@perforce.com>2014-06-23 15:51:28 +0100
committerPaul Allen <pallen@perforce.com>2014-06-23 15:51:28 +0100
commit319f9fbe1954fd172da638f3ccd76e58c3ec8c7f (patch)
tree24f0bcc88c3b2ed927e7698a1b5b290f4f7e5768 /lib/puppet
parentac4e14770fc04db02be2f48f6de675e90e3f6b29 (diff)
downloadpuppet-vcsrepo-319f9fbe1954fd172da638f3ccd76e58c3ec8c7f.tar.gz
puppet-vcsrepo-319f9fbe1954fd172da638f3ccd76e58c3ec8c7f.tar.bz2
Added support for p4config.
- Removed p4port, p4client, p4user to keep name space clean. - Changed notify to Puppet.debug - Updated markdown and examples - Updated unit tests
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/provider/vcsrepo/p4.rb51
-rw-r--r--lib/puppet/type/vcsrepo.rb22
2 files changed, 31 insertions, 42 deletions
diff --git a/lib/puppet/provider/vcsrepo/p4.rb b/lib/puppet/provider/vcsrepo/p4.rb
index de3bc7a..ec40cf3 100644
--- a/lib/puppet/provider/vcsrepo/p4.rb
+++ b/lib/puppet/provider/vcsrepo/p4.rb
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports Perforce depots"
- has_features :filesystem_types, :reference_tracking, :p4_config
+ has_features :filesystem_types, :reference_tracking, :p4config
def create
# create or update client
@@ -90,7 +90,7 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
# +source+:: Depot path to sync
# +revision+:: Perforce change list to sync to (optional)
def sync_client(source, revision)
- notice "Syncing: #{source}"
+ Puppet.debug "Syncing: #{source}"
args = ['sync']
if revision
args.push(source + "@" + revision)
@@ -102,12 +102,23 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
# Returns the name of the Perforce client workspace
def client_name
+ p4config = @resource.value(:p4config)
+
+ # default (generated) client name
path = @resource.value(:path)
- client = @resource.value(:p4client)
- if not client
- client = "puppet-" + Digest::MD5.hexdigest(path)
+ default = "puppet-" + Digest::MD5.hexdigest(path)
+
+ # check config for client name
+ set_client = nil
+ if p4config && File.file?(p4config)
+ open(p4config) do |f|
+ m = f.grep(/^P4CLIENT=/).pop
+ p = /^P4CLIENT=(.*)$/
+ set_client = p.match(m)[1] if m
+ end
end
- return client
+
+ return set_client || ENV['P4CLIENT'] || default
end
# Create (or update) a client workspace spec.
@@ -116,7 +127,7 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
# +client+:: Name of client workspace
# +path+:: The Root location of the Perforce client workspace
def create_client(client, path)
- notice "Creating client: #{client}"
+ Puppet.debug "Creating client: #{client}"
hash = parse_client(client)
hash['Root'] = path
hash['Description'] = "Generated by Puppet VCSrepo"
@@ -158,20 +169,14 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
p4(args, {:input => spec, :marshal => false})
end
+ # Sets Perforce Configuration environment.
+ # P4CLIENT generated, but overwitten if defined in config.
def config
- p4port = @resource.value(:p4port)
- p4user = @resource.value(:p4user)
- p4charset = @resource.value(:p4charset)
- p4passwd = @resource.value(:p4passwd)
- p4client = @resource.value(:p4client) || client_name
-
- cfg = Hash.new
- cfg.store 'P4USER', p4user if p4user
- cfg.store 'P4PORT', p4port if p4port
- cfg.store 'P4CHARSET', p4charset if p4charset
- cfg.store 'P4PASSWD', p4passwd if p4passwd
- cfg.store 'P4CLIENT', p4client if p4client
+ p4config = @resource.value(:p4config)
+ cfg = Hash.new
+ cfg.store 'P4CONFIG', p4config if p4config
+ cfg.store 'P4CLIENT', client_name
return cfg
end
@@ -187,14 +192,14 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
cmd.push args
cmd_str = cmd.respond_to?(:join) ? cmd.join(' ') : cmd
- notice "environment: #{config}"
- notice "command: #{cmd_str}"
+ Puppet.debug "environment: #{config}"
+ Puppet.debug "command: #{cmd_str}"
hash = Hash.new
Open3.popen3(config, cmd_str) do |i, o, e, t|
# Send input stream if provided
if(opts[:input])
- notice "input:\n" + opts[:input]
+ Puppet.debug "input:\n" + opts[:input]
i.write opts[:input]
i.close
end
@@ -212,7 +217,7 @@ Puppet::Type.type(:vcsrepo).provide(:p4, :parent => Puppet::Provider::Vcsrepo) d
end
end
- notice "hash: #{hash}\n"
+ Puppet.debug "hash: #{hash}\n"
return hash
end
diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb
index 649789a..7ada022 100644
--- a/lib/puppet/type/vcsrepo.rb
+++ b/lib/puppet/type/vcsrepo.rb
@@ -40,7 +40,7 @@ Puppet::Type.newtype(:vcsrepo) do
feature :depth,
"The provider can do shallow clones"
- feature :p4_config,
+ feature :p4config,
"The provider understands Perforce Configuration"
ensurable do
@@ -212,26 +212,10 @@ Puppet::Type.newtype(:vcsrepo) do
desc "The value to be used to do a shallow clone."
end
- newparam :p4port, :required_features => [:p4_config] do
- desc "The Perforce P4PORT environment."
- end
-
- newparam :p4user, :required_features => [:p4_config] do
- desc "The Perforce P4USER environment."
- end
-
- newparam :p4client, :required_features => [:p4_config] do
- desc "The Perforce P4CLIENT environment."
+ newparam :p4config, :required_features => [:p4config] do
+ desc "The Perforce P4CONFIG environment."
end
- newparam :p4charset, :required_features => [:p4_config] do
- desc "The Perforce P4CHARSET environment."
- end
-
- newparam :p4passwd, :required_features => [:p4_config] do
- desc "The Perforce P4PASSWD environment."
- end
-
autorequire(:package) do
['git', 'git-core']
end