Skip to content

Loading…

Add --modules command line option to test modules #206

Merged
merged 1 commit into from

2 participants

@jeffmccune

Without this patch the git acceptance type has no way to install
arbitrary Puppet modules. We need this functionality to properly test
the Registry puppet module.

This patch fixes the problem by providing a --modules command line
option. This option takes a list of URI's to Puppet module
repositories. Each listed URI will be cloned into /opt/puppet-git-repos
on each master system using the 04_InstallModules setup step when using
--type git.

Individual test cases may then configure a modulepath directory that
symlinks in the modules we're testing are "installed" on the puppet
master systems.

@djm68
Puppet Labs member

needs rebase -- a few commits were merged today

@jeffmccune jeffmccune Add --modules command line option to test modules
Without this patch the git acceptance type has no way to install
arbitrary Puppet modules.  We need this functionality to properly test
the Registry puppet module.

This patch fixes the problem by providing a --modules command line
option.  This option takes a list of URI's to Puppet module
repositories.  Each listed URI will be cloned into /opt/puppet-git-repos
on each master system using the 04_InstallModules setup step when using
--type git.

Individual test cases may then configure a modulepath directory that
symlinks in the modules we're testing are "installed" on the puppet
master systems.
e37a782
@jeffmccune

@djm68 Rebased, this should be good to go now.

@djm68 djm68 merged commit d20d52b into puppetlabs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 10, 2012
  1. @jeffmccune

    Add --modules command line option to test modules

    jeffmccune committed
    Without this patch the git acceptance type has no way to install
    arbitrary Puppet modules.  We need this functionality to properly test
    the Registry puppet module.
    
    This patch fixes the problem by providing a --modules command line
    option.  This option takes a list of URI's to Puppet module
    repositories.  Each listed URI will be cloned into /opt/puppet-git-repos
    on each master system using the 04_InstallModules setup step when using
    --type git.
    
    Individual test cases may then configure a modulepath directory that
    symlinks in the modules we're testing are "installed" on the puppet
    master systems.
This page is out of date. Refresh to see the latest.
Showing with 61 additions and 0 deletions.
  1. +5 −0 lib/options_parsing.rb
  2. +56 −0 setup/git/04_InstallModules.rb
View
5 lib/options_parsing.rb
@@ -89,6 +89,11 @@ def self.parse_args
@options[:hiera] = value
end
+ @options[:modules] = []
+ opts.on('-m' '--modules URI', 'Select puppet module git install URI') do |value|
+ @options[:modules] << value
+ end
+
@options[:plugins] = []
opts.on('--plugin URI', 'Select puppet plugin git install URI') do |value|
#@options[:type] = 'git'
View
56 setup/git/04_InstallModules.rb
@@ -0,0 +1,56 @@
+require 'pathname'
+
+# Given an array of modules specified by the --modules command line option,
+# Parse all of them into an array of usable hash structures.
+class PuppetModules
+ attr_reader :modules
+
+ def initialize(modules=[])
+ @modules = modules
+ end
+
+ def list
+ return [] unless modules
+ modules.collect do |uri|
+ git_url, git_ref = uri.split '#'
+ folder = Pathname.new(git_url).basename('.git')
+ name = folder.to_s.split('-', 2)[1] || folder.to_s
+ {
+ :name => name,
+ :url => git_url,
+ :folder => folder.to_s,
+ :ref => git_ref,
+ }
+ end
+ end
+end
+
+modules = PuppetModules.new(options[:modules]).list
+
+step "Masters: Install Puppet Modules"
+masters = hosts.select { |host| host['roles'].include? 'master' }
+
+masters.each do |host|
+ modules.each do |mod|
+ # The idea here is that each test can symlink the modules they want from a
+ # temporary directory to this location. This will preserve the global
+ # state of the system while allowing individual test cases to quickly run
+ # with a module "installed" in the module path.
+ moddir = "/opt/puppet-git-repos"
+ target = "#{moddir}/#{mod[:name]}"
+
+ step "Clone #{mod[:url]} if needed"
+ on host, "test -d #{moddir} || mkdir -p #{moddir}"
+ on host, "test -d #{target} || git clone #{mod[:url]} #{target}"
+ step "Update #{mod[:name]} and check out revision #{mod[:ref]}"
+
+ commands = ["cd #{target}",
+ "remote rm origin",
+ "remote add origin #{mod[:url]}",
+ "fetch origin",
+ "clean -fdx",
+ "checkout -f #{mod[:ref]}"]
+
+ on host, commands.join(" && git ")
+ end
+end
Something went wrong with that request. Please try again.