[Pkg-puppet-devel] [facter] 57/352: (maint) Add acceptance setup steps from puppet-acceptance

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:31 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 50ae44ab8607e67bac1c16a50f07f194ff7ed1ca
Author: Josh Partlow <joshua.partlow at puppetlabs.com>
Date:   Thu Oct 10 10:59:44 2013 -0700

    (maint) Add acceptance setup steps from puppet-acceptance
    
    This is so that we can run the acceptance tests with Beaker, which
    expects each project to manage all of its own setup process.
---
 acceptance/setup/01_TestSetup.rb          | 40 ++++++++++++++++
 acceptance/setup/02_PuppetWorkArounds.rb  | 21 +++++++++
 acceptance/setup/03_PuppetMasterSanity.rb | 24 ++++++++++
 acceptance/setup/04_ValidateSignCert.rb   | 28 ++++++++++++
 acceptance/setup/06_InstallModules.rb     | 76 +++++++++++++++++++++++++++++++
 5 files changed, 189 insertions(+)

diff --git a/acceptance/setup/01_TestSetup.rb b/acceptance/setup/01_TestSetup.rb
new file mode 100755
index 0000000..ee71151
--- /dev/null
+++ b/acceptance/setup/01_TestSetup.rb
@@ -0,0 +1,40 @@
+test_name "Install packages and repositories on target machines..." do
+  extend Beaker::DSL::InstallUtils
+
+  SourcePath  = Beaker::DSL::InstallUtils::SourcePath
+  GitURI      = Beaker::DSL::InstallUtils::GitURI
+  GitHubSig   = Beaker::DSL::InstallUtils::GitHubSig
+
+  tmp_repositories = []
+  options[:install].each do |uri|
+    raise(ArgumentError, "#{uri} is not recognized.") unless(uri =~ GitURI)
+    tmp_repositories << extract_repo_info_from(uri)
+  end
+
+  repositories = order_packages(tmp_repositories)
+
+  versions = {}
+  hosts.each_with_index do |host, index|
+    on host, "echo #{GitHubSig} >> $HOME/.ssh/known_hosts"
+
+    repositories.each do |repository|
+      step "Install #{repository[:name]}"
+      install_from_git host, SourcePath, repository
+
+      if index == 1
+        versions[repository[:name]] = find_git_repo_versions(host,
+                                                             SourcePath,
+                                                             repository)
+      end
+    end
+  end
+
+  step "Agents: create basic puppet.conf" do
+    agents.each do |agent|
+      puppetconf = File.join(agent['puppetpath'], 'puppet.conf')
+
+      on agent, "echo '[agent]' > #{puppetconf} && " +
+                "echo server=#{master} >> #{puppetconf}"
+    end
+  end
+end
diff --git a/acceptance/setup/02_PuppetWorkArounds.rb b/acceptance/setup/02_PuppetWorkArounds.rb
new file mode 100644
index 0000000..d7b1f71
--- /dev/null
+++ b/acceptance/setup/02_PuppetWorkArounds.rb
@@ -0,0 +1,21 @@
+test_name 'work arounds for bugs' do
+  hosts.each do |host|
+    next if host['platform'].include? 'windows'
+
+    step "REVISIT: see #9862, this step should not be required for agents" do
+      on host, "getent group puppet || groupadd puppet"
+
+      if host['platform'].include? 'solaris'
+        useradd_opts = '-d /puppet -m -s /bin/sh -g puppet puppet'
+      else
+        useradd_opts = 'puppet -g puppet -G puppet'
+      end
+
+      on host, "getent passwd puppet || useradd #{useradd_opts}"
+    end
+
+    step "REVISIT: Work around bug #5794 not creating reports as required" do
+      on host, "mkdir -p /tmp/reports && chown puppet:puppet /tmp/reports"
+    end
+  end
+end
diff --git a/acceptance/setup/03_PuppetMasterSanity.rb b/acceptance/setup/03_PuppetMasterSanity.rb
new file mode 100755
index 0000000..6d1df4c
--- /dev/null
+++ b/acceptance/setup/03_PuppetMasterSanity.rb
@@ -0,0 +1,24 @@
+test_name "Puppet Master sanity checks: PID file and SSL dir creation"
+
+pidfile = '/var/lib/puppet/run/master.pid'
+
+hostname = on(master, 'facter hostname').stdout.strip                                             
+fqdn = on(master, 'facter fqdn').stdout.strip                                                     
+                                                                                                  
+master_conf = {
+  :main => {
+    :dns_alt_names => "puppet,#{hostname},#{fqdn}",
+    :verbose => true,
+    :noop => true,
+  },
+}
+
+with_puppet_running_on(master, master_conf) do
+  # SSL dir created?
+  step "SSL dir created?"
+  on master,  "[ -d #{master['puppetpath']}/ssl ]"
+
+  # PID file exists?
+  step "PID file created?"
+  on master, "[ -f #{pidfile} ]"
+end
diff --git a/acceptance/setup/04_ValidateSignCert.rb b/acceptance/setup/04_ValidateSignCert.rb
new file mode 100755
index 0000000..7c9e309
--- /dev/null
+++ b/acceptance/setup/04_ValidateSignCert.rb
@@ -0,0 +1,28 @@
+test_name "Validate Sign Cert"
+
+hostname = on(master, 'facter hostname').stdout.strip                                             
+fqdn = on(master, 'facter fqdn').stdout.strip                                                     
+                                                                                                  
+master_conf = {
+  :master => {
+    :dns_alt_names => "puppet,#{hostname},#{fqdn}",
+  },
+}
+
+step "Master: Start Puppet Master"
+with_puppet_running_on(master, master_conf) do
+  hosts.each do |host|
+    next if host['roles'].include? 'master'
+
+    step "Agents: Run agent --test first time to gen CSR"
+    on host, puppet_agent("--test"), :acceptable_exit_codes => [1]
+  end
+
+  # Sign all waiting certs
+  step "Master: sign all certs"
+  on master, puppet_cert("--sign --all"), :acceptable_exit_codes => [0,24]
+
+  step "Agents: Run agent --test second time to obtain signed cert"
+  on agents, puppet_agent("--test"), :acceptable_exit_codes => [0,2]
+end
+
diff --git a/acceptance/setup/06_InstallModules.rb b/acceptance/setup/06_InstallModules.rb
new file mode 100644
index 0000000..0024301
--- /dev/null
+++ b/acceptance/setup/06_InstallModules.rb
@@ -0,0 +1,76 @@
+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,
+        :protocol => git_url.split(':')[0].intern,
+      }
+    end
+  end
+end
+
+def install_git_module(mod, hosts)
+  # 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 hosts, "test -d #{moddir} || mkdir -p #{moddir}"
+  on hosts, "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",
+              "checkout -f #{mod[:ref]}",
+              "reset --hard refs/remotes/origin/#{mod[:ref]}",
+              "clean -fdx",
+  ]
+
+  on hosts, commands.join(" && git ")
+end
+
+def install_scp_module(mod, hosts)
+  moddir = "/opt/puppet-git-repos"
+  target = "#{moddir}/#{mod[:name]}"
+
+  step "Purge #{target} if needed"
+  on hosts, "test -d #{target} && rm -rf #{target} || true"
+
+  step "Copy #{mod[:name]} to hosts"
+  scp_to hosts, mod[:url].split(':', 2)[1], target
+end
+
+modules = PuppetModules.new(options[:modules]).list
+
+step "Masters: Install Puppet Modules"
+masters = hosts.select { |host| host['roles'].include? 'master' }
+
+modules.each do |mod|
+  if mod[:protocol] == :scp
+    install_scp_module(mod, masters)
+  else
+    install_git_module(mod, masters)
+  end
+end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list