Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
Redo collections. Use beaker's built-in code more.
Browse files Browse the repository at this point in the history
The variable `PUPPET_INSTALL_TYPE` was originally introduced to control
selecting the PE/foss installation code, and later was changed to
allow the puppet-agent install code. It was incorrectly updated in 0.8.0
to also control collections however beaker already controls collections
via `BEAKER_PUPPET_COLLECTION` so this was not need (and broke beaker's
usage.)

`PUPPET_INSTALL_TYPE` still can be used to install 3.x foss instead of
puppet-agent, but that is deprecated.

Other variables in beaker also cover the functionality provided by some
in BPIH.
  • Loading branch information
hunner committed Apr 19, 2018
1 parent 6479e8f commit 057f995
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 145 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.9.0]
### Changed
- Use `BEAKER_IS_PE` instead of `PUPPET_INSTALL_TYPE` to specify whether a run should be PE or agent.
- Use `BEAKER_PUPPET_COLLECTION` instead of `PUPPET_INSTALL_TYPE` to specify puppet5, puppet6-nightly, etc. collections.
- Use `BEAKER_PUPPET_AGENT_VERSION` instead of `PUPPET_INSTALL_VERSION`
- Use `BEAKER_PUPPET_AGENT_SHA` instead of `PUPPET_AGENT_SHA`

### Fixed
- Beaker only cares about the SHA and no longer cares about `PUPPET_AGENT_SUITE_VERSION` so deprecating that variable. See (the beaker source)[https://github.com/puppetlabs/beaker-puppet/blob/63ea32a0d7caa8f261c533b020625de19569f971/lib/beaker-puppet/install_utils/foss_utils.rb#L1150-L1152]

## [0.8.0]
### Changed
- Changed the default `PUPPET_INSTALL_TYPE` from "agent" (puppet 4) to "puppet5"
Expand Down
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ This gem is simply an abstraction for the various ways that we install puppet fr

### `run_puppet_install_helper`

The way to use this is to declare either `run_puppet_install_helper()` or `run_puppet_install_helper_on(hosts)` and set environment variables `PUPPET_INSTALL_VERSION` and/or `PUPPET_INSTALL_TYPE` in the following combinations to have puppet installed on the desired hosts:
The way to use this is to declare either `run_puppet_install_helper()` or `run_puppet_install_helper_on(hosts)` and set environment variables `BEAKER_PUPPET_AGENT_VERSION` and/or `BEAKER_PUPPET_COLLECTION` in the following combinations to have puppet installed on the desired hosts. The nodeset should be configured with `type: pe` or `type: aio` to control the type of install.

- `PUPPET_INSTALL_TYPE` is unset: if `type: pe` is set for the default node in the nodeset, it will us the PE install method. Otherwise it will only install an agent.
- `PUPPET_INSTALL_TYPE=pe` will read `PUPPET_INSTALL_VERSION` and attempt to install that version of the PE tarball. If no version is set, then it uses the latest stable build.
- `PUPPET_INSTALL_TYPE=agent` will read `PUPPET_INSTALL_VERSION` and install that version of puppet-agent (eg, `PUPPET_INSTALL_TYPE=agent PUPPET_INSTALL_VERSION=1.0.0`)
- `PUPPET_INSTALL_TYPE=foss` will read `PUPPET_INSTALL_VERSION` and pass that on to beaker's [install_puppet_on](http://www.rubydoc.info/github/puppetlabs/beaker/Beaker%2FDSL%2FInstallUtils%2FFOSSUtils%3Ainstall_puppet_on)
- if a `master` role is defined, will install puppetserver on that node. Note that the corresponding puppet-agent dependency will be installed on that node rather than the specified `PUPPET_INSTALL_VERSION`.
- `BEAKER_PUPPET_COLLECTION=<puppet collection>` will install the specified `BEAKER_PUPPET_AGENT_VERSION` from the specified collection. Valid values are `pc1`, `puppet5`, `puppet6-nightly` etc. This may change with time.
- `BEAKER_PUPPET_AGENT_VERSION=<version>` to specify
- `BEAKER_IS_PE=<yes or no>` may be used to force a nodeset to be PE or not, regardless of the nodeset `type` or absence thereof.
- `BEAKER_PUPPET_AGENT_SHA=<sha>` may be used in order to use a development puppet-agent package.
- `PUPPET_INSTALL_TYPE=foss` may be used to install foss puppet 3.x, but is deprecated and should not be used.

The best way is explicitly set `PUPPET_INSTALL_TYPE` and `PUPPET_INSTALL_VERSION` to what you want. It'll probably do what you expect.

#### Installing a puppet-agent package from a development repository

In order to use a custom, or unreleased, puppet-agent package set the following environment variables"
- `PUPPET_INSTALL_TYPE=agent`
- `PUPPET_AGENT_SHA` is the longform commit SHA used when building the puppet-agent package, for example `PUPPET_AGENT_SHA=18d31fd5ed41abb276398201f84a4347e0fc7092`. This is required to be set in order to use a development puppet-agent package
- `PUPPET_AGENT_SUITE_VERSION` is the version of the puppet-agent package, for example `PUPPET_AGENT_SUITE_VERSION="1.8.2.350.g18d31fd`. This is optional, and will default to `PUPPET_AGENT_SHA` if not set
The best way is explicitly set `BEAKER_PUPPET_COLLECTION` and `BEAKER_PUPPET_AGENT_VERSION` to what you want. It'll probably do what you expect.

### `install_ca_certs`

Expand Down
2 changes: 1 addition & 1 deletion beaker-puppet_install_helper.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'beaker-puppet_install_helper'
s.version = '0.8.0'
s.version = '0.9.0'
s.authors = ['Puppetlabs']
s.email = ['[email protected]']
s.homepage = 'https://github.com/puppetlabs/beaker-puppet_install_helper'
Expand Down
68 changes: 29 additions & 39 deletions lib/beaker/puppet_install_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,21 @@ def run_puppet_install_helper(type_arg = find_install_type, version = find_insta
end

# Takes a host(s) object, install type string, and install version string.
# - Type defaults to PE for PE nodes, and puppet5 agent otherwise.
# - Version will default to the latest 5x agent or pe package, depending on type
def run_puppet_install_helper_on(hosts, type_arg = find_install_type, version = find_install_version)
type = type_arg || find_install_type

# Short circuit based on rspec-system and beaker variables
if (ENV['RS_PROVISION'] == 'no') || (ENV['BEAKER_provision'] == 'no')
configure_defaults_on(hosts, type_arg)
configure_type_defaults_on(hosts)
return
end

# Example environment variables to be read:
# PUPPET_INSTALL_VERSION=4.1.0 <-- for agent
# PUPPET_INSTALL_VERSION=1.0.1 <-- for agent
#
# PUPPET_INSTALL_TYPE=pe
# PUPPET_INSTALL_TYPE=foss
# PUPPET_INSTALL_TYPE=agent
# PUPPET_INSTALL_TYPE=nightly

# For PUPPET_INSTALL_TYPE=puppet6-nightly using a development version of Puppet Agent
# PUPPET_AGENT_SHA=0ed2bbc918326263da9d97d0361a9e9303b52938 <-- Long form commit SHA used to build the Puppet Agent
# BEAKER_PUPPET_COLLECTION=pc1 <-- for latest 4.x
# BEAKER_PUPPET_COLLECTION=puppet5 <-- for latest 5.x
# BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_PUPPET_AGENT_VERSION=5.3.1 <-- for specific version
# BEAKER_PUPPET_COLLECTION=puppet6-nightly <-- for latest nightly build
# BEAKER_PUPPET_AGENT_SHA=0ed2bbc918326263da9d97d0361a9e9303b52938 <-- for specific dev build

# Ensure windows 2003 is always set to 32 bit
Array(hosts).each do |host|
Expand All @@ -47,9 +40,12 @@ def run_puppet_install_helper_on(hosts, type_arg = find_install_type, version =
if hosts_with_role(hosts, 'master').length>0 then
next if host == master
end
# XXX install_puppet_on() will call install_puppet_agent_on() if there
# is a :version option >= 4.x passed, but does foss by default.
install_puppet_on(host, opts)
end
if hosts_with_role(hosts, 'master').length>0 then
# TODO Make the puppetserver code work with puppet5/puppet6
# install puppetserver
install_puppetlabs_release_repo( master, 'pc1' )
master.install_package('puppetserver')
Expand Down Expand Up @@ -85,45 +81,39 @@ def run_puppet_install_helper_on(hosts, type_arg = find_install_type, version =
on host, "echo 'export PATH=/opt/puppet/bin:/var/ruby/1.8/gem_home/bin:${PATH}' >> ~/.bashrc"
end
end
when 'agent', 'agent4', 'puppet4'
install_agent_on(hosts, 'pc1', version)
when 'agent5', 'puppet5'
install_agent_on(hosts, 'puppet5', version)
when /^puppet\d-nightly$/ # Just 'puppet-nightly' doesn't work: https://github.com/puppetlabs/beaker-puppet/blob/63ea32a0d7caa8f261c533b020625de19569f971/lib/beaker-puppet/install_utils/foss_utils.rb#L944
install_agent_on(hosts, type, version)
when 'agent'
if find_agent_sha.nil?
install_puppet_agent_on(hosts, options.merge(version: version))
else
opts = options.merge(puppet_agent_sha: find_agent_sha,
puppet_agent_version: ENV['PUPPET_AGENT_SUITE_VERSION'] || find_agent_sha)
install_puppet_agent_dev_repo_on(hosts, opts)
end

# XXX install_puppet_agent_on() will only add_aio_defaults_on when the
# nodeset type == 'aio', but we don't want to depend on that.
add_aio_defaults_on(hosts)
add_puppet_paths_on(hosts)
else
raise ArgumentError, "Type must be pe, puppet4, puppet5, or puppet6-nightly; got #{type.inspect}"
raise ArgumentError, "Type must be pe, foss, or agent; got #{type.inspect}"
end
end

def find_install_type
# XXX Just use default.is_pe? when PUPPET_INSTALL_TYPE=foss is removed.
ENV['PUPPET_INSTALL_TYPE'] || if default.is_pe?
'pe'
else
'puppet5'
'agent'
end
end

def find_install_version
ENV['PUPPET_INSTALL_VERSION'] || ENV['PUPPET_VERSION']
def find_agent_sha
ENV['BEAKER_PUPPET_AGENT_SHA'] || ENV['PUPPET_AGENT_SHA']
end

def install_agent_on(hosts, collection, version)
if ENV['PUPPET_AGENT_SHA'].nil?
opts = options.merge(puppet_collection: collection,
version: version)
install_puppet_agent_on(hosts, opts)
else
opts = options.merge(puppet_collection: collection,
puppet_agent_sha: ENV['PUPPET_AGENT_SHA'],
puppet_agent_version: ENV['PUPPET_AGENT_SUITE_VERSION'] || ENV['PUPPET_AGENT_SHA'])
install_puppet_agent_dev_repo_on(hosts, opts)
end

# XXX install_puppet_agent_on() will only add_aio_defaults_on when the
# nodeset type == 'aio', but we don't want to depend on that.
add_aio_defaults_on(hosts)
add_puppet_paths_on(hosts)
def find_install_version
ENV['BEAKER_PUPPET_AGENT_VERSION'] || ENV['PUPPET_INSTALL_VERSION'] || ENV['PUPPET_VERSION']
end
end

Expand Down
Loading

0 comments on commit 057f995

Please sign in to comment.