Skip to content

Commit 7656955

Browse files
author
jordanbreen28
committed
feat: add puppetcore agent installation support
This commit adds support for installing puppetcore agents through the `litmus:install_agent` rake task. To do this, you must supply a puppetcore collection to the rake task, and have exported your PUPPET_FORGE_TOKEN in the ENV.
1 parent d9864f2 commit 7656955

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Install Litmus as a gem by running `gem install puppet_litmus`.
2929

3030
- Note if you choose to override the `litmus_inventory.yaml` location, please ensure that the directory structure you define exists.
3131

32-
## Install a specific puppet agent version
32+
## Agent installs
33+
34+
### Install a specific puppet agent version
3335

3436
To install a specific version of the puppet agent, you can export the `PUPPET_VERSION` env var, like below:
3537
```
@@ -38,6 +40,13 @@ export PUPPET_VERSION=8.8.1
3840

3941
When set, the `litmus:install_agent` rake task will install the specified version. The default is `latest`.
4042

43+
## Installing puppetcore agents
44+
45+
To install a puppetcore puppet agent through the `litmus:install_agent` rake task, you need to export your Forge API key as an env var, like below:
46+
```
47+
export PUPPET_FORGE_TOKEN='<your_forge_api_key>'
48+
```
49+
4150
## matrix_from_metadata_v3
4251

4352
matrix_from_metadata_v3 tool generates a github action matrix from the supported operating systems listed in the module's metadata.json.

lib/puppet_litmus/rake_helper.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'puppet_litmus/version'
55

66
# helper methods for the litmus rake tasks
7-
module PuppetLitmus::RakeHelper
7+
module PuppetLitmus::RakeHelper # rubocop:disable Metrics/ModuleLength
88
# DEFAULT_CONFIG_DATA should be frozen for our safety, but it needs to work around https://github.com/puppetlabs/bolt/pull/1696
99
DEFAULT_CONFIG_DATA = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } # .freeze # rubocop:disable Style/MutableConstant
1010
SUPPORTED_PROVISIONERS = %w[abs docker docker_exp lxd provision_service vagrant vmpooler].freeze
@@ -130,13 +130,18 @@ def tear_down(node_name, inventory_hash)
130130
def install_agent(collection, targets, inventory_hash)
131131
include ::BoltSpec::Run
132132
puppet_version = ENV.fetch('PUPPET_VERSION', nil)
133+
forge_token = ENV.fetch('PUPPET_FORGE_TOKEN', nil)
133134
params = {}
135+
params['password'] = forge_token if forge_token
134136
params['collection'] = collection if collection
135137
params['version'] = puppet_version if puppet_version
136138

137139
raise "puppet_agent was not found in #{DEFAULT_CONFIG_DATA['modulepath']}, please amend the .fixtures.yml file" \
138140
unless File.directory?(File.join(DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent'))
139141

142+
raise 'puppetcore agent installs require a valid PUPPET_FORGE_TOKEN set in the env.' \
143+
if collection =~ /\Apuppetcore.*/ && !forge_token
144+
140145
# using boltspec, when the runner is called it changes the inventory_hash dropping the version field. The clone works around this
141146
bolt_result = run_task('puppet_agent::install', targets, params, config: DEFAULT_CONFIG_DATA, inventory: inventory_hash.clone)
142147
targets.each do |target|

spec/lib/puppet_litmus/rake_helper_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,34 @@
131131
[{ 'uri' => 'some.host', 'facts' => { 'provisioner' => 'docker', 'container_name' => 'foo', 'platform' => 'some.host' } }] }] }
132132
end
133133
let(:targets) { ['some.host'] }
134-
let(:params) { { 'collection' => 'puppet6' } }
134+
let(:token) { 'some_token' }
135+
let(:params) { { 'collection' => 'puppet6', 'password' => token } }
135136

136137
it 'calls function' do
138+
allow(ENV).to receive(:fetch).with('PUPPET_VERSION', nil).and_return(nil)
139+
allow(ENV).to receive(:fetch).with('PUPPET_FORGE_TOKEN', nil).and_return(token)
137140
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
138141
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: described_class::DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
139142
install_agent('puppet6', targets, inventory_hash)
140143
end
144+
145+
it 'adds puppet version' do
146+
params = { 'collection' => 'puppet7', 'version' => '7.35.0' }
147+
allow(ENV).to receive(:fetch).with('PUPPET_VERSION', nil).and_return('7.35.0')
148+
allow(ENV).to receive(:fetch).with('PUPPET_FORGE_TOKEN', nil).and_return(nil)
149+
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
150+
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: described_class::DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
151+
install_agent('puppet7', targets, inventory_hash)
152+
end
153+
154+
it 'fails for puppetcore if no token supplied' do
155+
params = { 'collection' => 'puppetcore7' }
156+
allow(ENV).to receive(:fetch).with('PUPPET_VERSION', nil).and_return(nil)
157+
allow(ENV).to receive(:fetch).with('PUPPET_FORGE_TOKEN', nil).and_return(nil)
158+
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
159+
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: described_class::DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
160+
expect { install_agent('puppetcore7', targets, inventory_hash) }.to raise_error(RuntimeError, /puppetcore agent installs require a valid PUPPET_FORGE_TOKEN set in the env\./)
161+
end
141162
end
142163

143164
context 'with install_module' do

0 commit comments

Comments
 (0)