Skip to content

Commit b9af0b1

Browse files
Added integration and pwsh lint tests (#7)
* Blank commit for PR * test new pipeline * Removed intergation test * check files * check files * check webserver * check with https * Create web server * Create web dir within workspace * fix path * Check dir * Check bolt avaliable * Correct setup_matrix to setup_vm * remove matrix * Set local module path * set module path * run task * include module path * certname * Try to elevate permissions * check sudoers * try with sudo * Run with sudo * check bundle location * attempt with path * test with changes * test again with localhost * Check webserver * Move web server to integration * Test with just integration * Remove needs * test on multiple test * Seperate windows ruby * enable long file path * ruby 3.2 * use windows latest * Show plans * with sudo * with sudo _e * with bash * set path * check bundle * with bundle path * check sudo options * add sudo * edit file * add s * run with sudo -E * Try without inventory file * Remove webservrer check * Added module path * use inventory file * test with task * check tasks * REmove install task * show plans * Confirm fact plan works. * check hosts file * try with 127.0.0.1 * with local host * with targets plan parameter * add stdlib * Test with real bolt * assume yes * don't modify sudo * With updates * Update integration tests, added pwsh lint * Push with acceptance * test again * set bolt config * Run tests * use the variables * Move to forge modules * Set test on PR only * remove plugin helper from repo fixtures. * supress PSUseShouldProcessForStateChangingFunction * try at top * More fixes * move location * Missed s * Disable unused sender variable. * Fix regex to match all characters * Restore old behaviour * Supress other warning. * Set scope all * Set scope function * Try without scope set * remove target * Removed unused sender variable * Delete unneeded files * Delete unused plans
1 parent b608ed5 commit b9af0b1

File tree

8 files changed

+123
-111
lines changed

8 files changed

+123
-111
lines changed

Diff for: .fixtures.yml

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ fixtures:
44
facts: 'https://github.com/puppetlabs/puppetlabs-facts.git'
55
puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git'
66
provision: 'https://github.com/puppetlabs/provision.git'
7+
deploy_pe: "https://github.com/jarretlavallee/puppet-deploy_pe"
8+
forge_modules:
9+
ruby_task_helper: "puppetlabs/ruby_task_helper"
10+
stdlib: "puppetlabs/stdlib"
11+
ruby_plugin_helper:
12+
repo: "puppetlabs/ruby_plugin_helper"
13+
ref: "0.2.0"

Diff for: .github/workflows/integration_test.yml

+68-95
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,80 @@
1-
name: "Integration Testing"
1+
name: "integration"
22

3-
on:
3+
on:
44
pull_request:
55
branches:
66
- "main"
7-
workflow_call:
8-
workflow_dispatch:
97

108
jobs:
11-
setup_matrix:
12-
name: "Setup Test Matrix"
13-
runs-on: ubuntu-20.04
14-
outputs:
15-
matrix: ${{ steps.get-matrix.outputs.matrix }}
169

17-
steps:
18-
- name: Checkout Source
19-
uses: actions/checkout@v3
20-
if: ${{ github.repository_owner == 'puppetlabs' }}
21-
22-
- name: Activate Ruby 2.7
23-
uses: ruby/setup-ruby@v1
24-
if: ${{ github.repository_owner == 'puppetlabs' }}
25-
with:
26-
ruby-version: "2.7"
27-
bundler-cache: true
28-
29-
- name: Print bundle environment
30-
if: ${{ github.repository_owner == 'puppetlabs' }}
31-
run: |
32-
echo ::group::bundler environment
33-
bundle env
34-
echo ::endgroup::
35-
36-
- name: Setup Integration Test Matrix
37-
id: get-matrix
38-
run: |
39-
if [ '${{ github.repository_owner }}' == 'puppetlabs' ]; then
40-
echo "matrix={'platform':['centos-7'],'collection':['puppet7-nightly', 'puppet8-nightly']}" >> $GITHUB_OUTPUT
41-
else
42-
echo "matrix={}" >> $GITHUB_OUTPUT
43-
fi
44-
45-
Integration:
46-
needs:
47-
- setup_matrix
48-
if: ${{ needs.setup_matrix.outputs.matrix != '{}' }}
49-
50-
runs-on: ubuntu-20.04
51-
strategy:
52-
fail-fast: false
53-
matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}}
10+
Integration_linux:
11+
runs-on: ubuntu-22.04
5412

5513
env:
5614
PUPPET_GEM_VERSION: '~> 7.24'
57-
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?
15+
FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main'
5816

5917
steps:
60-
61-
- name: Checkout Source
62-
uses: actions/checkout@v3
63-
64-
- name: Activate Ruby 2.7
65-
uses: ruby/setup-ruby@v1
66-
with:
67-
ruby-version: "2.7"
68-
bundler-cache: true
69-
70-
- name: Print bundle environment
71-
run: |
72-
echo ::group::bundler environment
73-
bundle env
74-
echo ::endgroup::
75-
76-
- name: Create the fixtures directory
77-
run: |
78-
bundle exec rake spec_prep
79-
80-
- name: Provision test environment
81-
run: |
82-
bundle exec bolt --modulepath spec/fixtures/modules plan run ntp::acceptance::provision_integration image=${{ matrix.platform }}
83-
# Redact password
84-
FILE='spec/fixtures/litmus_inventory.yaml'
85-
sed -e 's/password: .*/password: "[redacted]"/' < $FILE || true
86-
87-
- name: Install PE
88-
run: |
89-
bundle exec bolt --modulepath spec/fixtures/modules -i ./spec/fixtures/litmus_inventory.yaml plan run ntp::acceptance::pe_server
90-
91-
- name: Install Agents
92-
run: |
93-
bundle exec bolt --modulepath spec/fixtures/modules -i ./spec/fixtures/litmus_inventory.yaml plan run ntp::acceptance::pe_agent
94-
95-
- name: Install module
96-
run: |
97-
bundle exec rake 'litmus:install_module'
98-
99-
- name: Run integration tests
100-
run: |
101-
bundle exec rake ntp:integration
102-
103-
- name: Remove test environment
104-
if: ${{ always() }}
105-
continue-on-error: true
106-
run: |
107-
bundle exec rake 'litmus:tear_down'
18+
- name: checkout source
19+
uses: actions/checkout@v4
20+
21+
- name: Activate Ruby 2.7
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: "2.7"
25+
bundler-cache: true
26+
27+
- name: Print bundle environment
28+
run: |
29+
echo ::group::bundler environment
30+
bundle env
31+
echo ::endgroup::
32+
33+
- name: modify sudo settings
34+
run: |
35+
sudo sed -i 's/Defaults env_reset//' /etc/sudoers
36+
37+
- name: Create the fixtures directory
38+
run: |
39+
bundle exec rake spec_prep
40+
41+
- name: install actual bolt
42+
run: |
43+
wget https://apt.puppet.com/puppet-tools-release-jammy.deb
44+
sudo -E dpkg -i puppet-tools-release-jammy.deb
45+
sudo -E apt-get update
46+
sudo -E apt-get -y install puppet-bolt
47+
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan show
48+
49+
- name: install pe
50+
run: |
51+
echo -e 'groups:\n - name: pe\n targets:\n - localhost' > inventory.yaml
52+
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan show
53+
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan run facts targets=localhost
54+
sudo -E /usr/local/bin/bolt --modulepath spec/fixtures/modules plan run deploy_pe::provision_master targets=localhost version=2021.7.8
55+
56+
- name: run bootstrap task
57+
run: |
58+
curl -k https://localhost:8140/packages/current/install.bash -I
59+
sudo -E /opt/hostedtoolcache/Ruby/2.7.8/x64/bin/bundle exec bolt --modulepath spec/fixtures/modules task run bootstrap --targets localhost master=localhost certname=testing123.com
60+
61+
# Integration_windows: Currently no way to test Windows agent installation.
62+
# runs-on: windows-latest
63+
# env:
64+
# PUPPET_GEM_VERSION: '~> 7.24'
65+
# FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' # why is this set?
66+
67+
68+
# steps:
69+
# - name: enable long file path
70+
# run: |
71+
# New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
72+
# - name: checkout source
73+
# uses: actions/checkout@v4
74+
75+
# - name: Activate Ruby 3.2
76+
# uses: ruby/setup-ruby@v1
77+
# with:
78+
# ruby-version: "3.2"
79+
# bundler-cache: true
80+
# cache-version: 1

Diff for: .github/workflows/pwsh_lint.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: "pwsh_lint"
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- "main"
8+
9+
jobs:
10+
pwsh_lint:
11+
runs-on: windows-latest
12+
13+
steps:
14+
- name: enable long file path
15+
run: |
16+
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
17+
18+
- name: checkout source
19+
uses: actions/checkout@v4
20+
21+
- name: install PSScriptAnalyzer
22+
run: |
23+
Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.21.0
24+
Get-InstalledModule
25+
26+
- name: pwsh lint check
27+
run: |
28+
Invoke-ScriptAnalyzer -Recurse -EnableExit -Path .\tasks -ReportSummary

Diff for: spec/acceptance/linux_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# run a test task
22
require 'spec_helper_acceptance'
3+
require 'bolt_spec/run'
4+
require 'open3'
35

46
def return_hostname
57
host = if pe_install?

Diff for: tasks/init.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"puppet_conf_settings": {
3838
"description": "Puppet conf settings. See https://www.puppet.com/docs/pe/2021.7/installing_nix_and_windows_agents_using_an_install_script.html#customize-install-script for usage instructions",
39-
"type": "Optional[Array[Pattern[/\\w+:\\w+=\\w+/]]]"
39+
"type": "Optional[Array[Pattern[/\\w+:\\w+=.*/]]]"
4040
}
4141
},
4242
"extensions": {

Diff for: tasks/linux.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"puppet_conf_settings": {
3939
"description": "Puppet conf settings. See https://www.puppet.com/docs/pe/2021.7/installing_nix_and_windows_agents_using_an_install_script.html#customize-install-script for usage instructions",
40-
"type": "Optional[Array[Pattern[/\\w+:\\w+=\\w+/]]]"
40+
"type": "Optional[Array[Pattern[/\\w+:\\w+=.*/]]]"
4141
}
4242
}
4343
}

Diff for: tasks/windows.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"puppet_conf_settings": {
3939
"description": "Puppet conf settings. See https://www.puppet.com/docs/pe/2021.7/installing_nix_and_windows_agents_using_an_install_script.html#customize-install-script for usage instructions",
40-
"type": "Optional[Array[Pattern[/\\w+:\\w+=\\w+/]]]"
40+
"type": "Optional[Array[Pattern[/\\w+:\\w+=.*/]]]"
4141
}
4242
}
4343
}

Diff for: tasks/windows.ps1

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[CmdletBinding()]
2+
# Suppress some linter warnings
3+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='*')]
4+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectComparisonWithNull', '')]
25
Param(
36
[Parameter(Mandatory = $True)]
47
[String]
@@ -17,7 +20,7 @@ Param(
1720
$CertName,
1821

1922
[Parameter(Mandatory = $False)]
20-
[ValidateScript({ $_ -split ',' | % {
23+
[ValidateScript({ $_ -split ',' | ForEach-Object {
2124
if ([System.URI]::CheckHostName($_) -ne 'Dns') {
2225
throw "Invalid DNS name `"$_`""
2326
}}; $True})]
@@ -60,8 +63,8 @@ function Set-SecurityProtocol {
6063
function Get-HostName
6164
{
6265
$ipAddress = ([System.Net.Dns]::GetHostEntry([System.Environment]::MachineName)).AddressList |
63-
? { $_.AddressFamily -eq 'InterNetwork' } |
64-
Select -First 1 -ExpandProperty IPAddressToString
66+
Where-Object { $_.AddressFamily -eq 'InterNetwork' } |
67+
Select-Object -First 1 -ExpandProperty IPAddressToString
6568

6669
$name = [System.Net.Dns]::GetHostEntry($ipAddress).HostName
6770
Write-Verbose "Resolved current hostname to $name"
@@ -102,7 +105,6 @@ function Get-InstallerScriptBlock($Master, $RootCertificate)
102105
{
103106
$customCACallback = {
104107
param(
105-
$sender,
106108
[System.Security.Cryptography.X509Certificates.X509Certificate]
107109
$certificate,
108110
[System.Security.Cryptography.X509Certificates.X509Chain]
@@ -171,14 +173,14 @@ function ConvertTo-JsonString($string)
171173
function New-OptionsHash($Prefix, $Values)
172174
{
173175
$hash = @{}
174-
$Values | % { $k, $v = $_ -split '=',2; $hash."$Prefix`:$k" = $v }
176+
$Values | ForEach-Object { $k, $v = $_ -split '=',2; $hash."$Prefix`:$k" = $v }
175177
$hash
176178
}
177179

178180
function New-OptionsStringHash($Values)
179181
{
180182
$hash = @{}
181-
$Values | % { $k, $v = $_ -split '=',2; $hash."$k" = $v }
183+
$Values | ForEach-Object { $k, $v = $_ -split '=',2; $hash."$k" = $v }
182184
$hash
183185
}
184186

@@ -200,7 +202,7 @@ function Invoke-SimplifiedInstaller
200202

201203
$ExtraConfig.Add('agent:certname', $CertName)
202204
$installerArgs = @{
203-
Arguments = $ExtraConfig.GetEnumerator() | % { "$($_.Key)=$($_.Value)" }
205+
Arguments = $ExtraConfig.GetEnumerator() | ForEach-Object { "$($_.Key)=$($_.Value)" }
204206
}
205207

206208
Write-Verbose "Calling installer ScriptBlock with arguments: $($installerArgs.Arguments)"
@@ -213,8 +215,8 @@ try
213215

214216
$options = @{
215217
Master = $Master
216-
CertName = ($PSBoundParameters['CertName'], (Get-HostName) -ne $null)[0].ToLower()
217-
CACertContent = ($PSBoundParameters['CACertContent'], (Get-CA -Master $Master) -ne $null)[0]
218+
CertName = ($PSBoundParameters['CertName'], (Get-HostName) -ne $null )[0].ToLower()
219+
CACertContent = ($PSBoundParameters['CACertContent'], (Get-CA -Master $Master) -ne $null )[0]
218220
ExtraConfig = @{}
219221
}
220222
if ($PSBoundParameters.ContainsKey('DNS_Alt_Names')) {
@@ -235,17 +237,17 @@ try
235237
if ($PSBoundParameters.ContainsKey('Set_Noop')) {
236238
$options.ExtraConfig += @{ 'agent:noop' = "$Set_Noop".ToLower() }
237239
}
238-
240+
239241
$installerOutput = Invoke-SimplifiedInstaller @options
240242
$jsonOutput = ConvertTo-JsonString $installerOutput
241243
$jsonSafeConfig = $options.ExtraConfig.GetEnumerator() |
242-
% { ConvertTo-JsonString "$($_.Key)=$($_.Value)" }
244+
ForEach-Object { ConvertTo-JsonString "$($_.Key)=$($_.Value)" }
243245
$jsonHostName = ConvertTo-JsonString (Get-HostName)
244246
$jsonCertName = ConvertTo-JsonString $options.CertName
245247

246248
# TODO: could use ConvertTo-Json, but that requires PS3
247249
# if embedding in literal, should make sure Name / Status doesn't need escaping
248-
Write-Host @"
250+
Write-Output @"
249251
{
250252
"host" : "$jsonHostName",
251253
"certname" : "$jsonCertName",
@@ -258,7 +260,7 @@ try
258260
}
259261
catch
260262
{
261-
Write-Host @"
263+
Write-Output @"
262264
{
263265
"status" : "failure",
264266
"host" : "$jsonHostName",

0 commit comments

Comments
 (0)