Use system-config script to install puppet

Previously, we were using the helper methods provided by beaker to
install puppet. When we moved to Xenial but stayed on puppet 3, we
changed the spec helper to install puppet 3 from the Xenial repos. This
duplicates effort that we have already written into install_puppet.sh,
and it doesn't reflect how we really install puppet in production. This
patch changes the install_infra_puppet method to use the install script
in system-config, so that when we make changes to how we install puppet
or what version we install, we only have to do it in one place. This
passes the test environment to the install command so that any
environment variables we set in the job (for example, if we make the
puppet version configurable through environment variables) make it
through. Also add logic to support puppet 4 by adding the new bin path
to the environment and using the appropriate modulepath.

We also need to modernize this helper for Zuulv3. zuul-cloner doesn't
exist on CI nodes any more, but we can rely on Zuul installing the
system-config repo beforehand, so just use that.

Change-Id: Ifa95171e580da96456d76900092ba924da626def
This commit is contained in:
Colleen Murphy 2017-07-09 16:31:29 +02:00
parent 6a6f5c85cc
commit 1226b84c9e
1 changed files with 32 additions and 31 deletions

View File

@ -1,53 +1,54 @@
require 'beaker-rspec'
SYSTEM_CONFIG='openstack-infra/system-config'
SYSTEM_CONFIG='git.openstack.org/openstack-infra/system-config'
def install_infra_puppet(host)
# puppet 3 isn't available from apt.puppetlabs.com so install it from the Xenial repos
on host, "which apt-get && apt-get install puppet -y", { :acceptable_exit_codes => [0,1] }
# otherwise use the beaker helpers to install the yum.puppetlabs.com repo and puppet
r = on host, "which yum", { :acceptable_exit_codes => [0,1] }
if r.exit_code == 0
install_puppet
end
install_system_config(host)
on host, "bash -x #{ENV['HOME']}/src/#{SYSTEM_CONFIG}/install_puppet.sh", :environment => ENV.to_hash
end
def setup_host(host)
add_platform_foss_defaults(host, 'unix')
on host, "mkdir -p #{host['distmoduledir']}"
end
def install_system_config(host)
# install git
install_package host, 'git'
# Install dependent modules via git or zuul
on host, "rm -fr #{SYSTEM_CONFIG}"
if ENV['ZUUL_UUID']
zuul_clone_cmd = '/usr/zuul-env/bin/zuul-cloner '
zuul_clone_cmd += '--cache-dir /opt/git '
zuul_clone_cmd += "git://git.openstack.org #{SYSTEM_CONFIG}"
on host, zuul_clone_cmd, :environment => ENV.to_hash
else
on host, "git clone https://git.openstack.org/#{SYSTEM_CONFIG} #{SYSTEM_CONFIG}"
if ENV['PUPPET_VERSION'] == '4'
host.ssh_permit_user_environment()
host.add_env_var('PATH', '/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin/:/opt/puppetlabs/bin')
# The SSH connection needs to be closed in order to refresh the SSH environment changes.
# It will reopen the next time a host action starts.
host.close
end
end
def install_system_config(host)
install_package host, 'git'
on host, "test -d #{ENV['HOME']}/src/#{SYSTEM_CONFIG} || git clone https://#{SYSTEM_CONFIG} #{ENV['HOME']}/src/#{SYSTEM_CONFIG}"
end
def install_infra_modules(host, proj_root)
install_system_config(host)
# Clean out any module cruft
shell('rm -fr /etc/puppet/modules/*')
if ENV['PUPPET_VERSION'] == '4'
on host, 'rm -fr /etc/puppetlabs/code/modules/*'
else
on host, 'rm -fr /etc/puppet/modules/*'
end
# Install module and dependencies
modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1]
module_install_cmd = "bash #{SYSTEM_CONFIG}/tools/install_modules_acceptance.sh"
module_install_cmd = "bash #{ENV['HOME']}/src/#{SYSTEM_CONFIG}/tools/install_modules_acceptance.sh"
on host, module_install_cmd, :environment => ENV.to_hash
on host, "rm -fr /etc/puppet/modules/#{modname}"
if ENV['PUPPET_VERSION'] == '4'
on host, "rm -fr /etc/puppetlabs/code/modules/#{modname}"
else
on host, "rm -fr /etc/puppet/modules/#{modname}"
end
# Install the module being tested
puppet_module_install(:source => proj_root, :module_name => modname)
opts = {:source => proj_root, :module_name => modname}
if ENV['PUPPET_VERSION'] == '4'
opts[:target_module_path] = '/etc/puppetlabs/code/modules'
end
puppet_module_install(opts)
# List modules installed to help with debugging
on hosts[0], puppet('module','list'), { :acceptable_exit_codes => 0 }
on host, puppet('module','list'), { :acceptable_exit_codes => 0 }
end
proj_root = File.expand_path(File.join(Dir.getwd))
@ -64,7 +65,7 @@ end
# Set up hosts, before running any tests
hosts.each do |host|
install_infra_puppet(host)
setup_host(host)
install_infra_puppet(host)
install_infra_modules(host, proj_root)
end