From 319f9fbe1954fd172da638f3ccd76e58c3ec8c7f Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Mon, 23 Jun 2014 15:51:28 +0100 Subject: 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 --- lib/puppet/provider/vcsrepo/p4.rb | 51 +++++++++++++++++++++------------------ lib/puppet/type/vcsrepo.rb | 22 +++-------------- 2 files changed, 31 insertions(+), 42 deletions(-) (limited to 'lib/puppet') 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 -- cgit v1.2.3