-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
puppet module: prevent running match call if a preassignment failed (#…
…17175) for #16954 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Added/updated tests - [x] Manual QA for all new/changed functionality
- Loading branch information
Roberto Dip
authored
Feb 28, 2024
1 parent
4751e66
commit 456bc3c
Showing
4 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'puppet/reports' | ||
require_relative '../../../lib/puppet/reports/fleetdm.rb' | ||
|
||
describe 'Puppet::Reports::Fleetdm' do | ||
let(:fleet_client_mock) { instance_double('Puppet::Util::FleetClient') } | ||
let(:catalog_uuid) { '827a74c8-cf98-44da-9ff7-18c5e4bee41e' } | ||
let(:node_name) { Puppet[:node_name_value] } | ||
let(:report) do | ||
report = Puppet::Transaction::Report.new('apply') | ||
report.extend(Puppet::Reports.report(:fleetdm)) | ||
report | ||
end | ||
|
||
before(:each) do | ||
Puppet[:reports] = 'fleetdm' | ||
Puppet::Util::Log.level = :warning | ||
Puppet::Util::Log.newdestination(:console) | ||
|
||
fleet_client_class = class_spy('Puppet::Util::FleetClient') | ||
stub_const('Puppet::Util::FleetClient', fleet_client_class) | ||
allow(fleet_client_class).to receive(:instance) { fleet_client_mock } | ||
allow(SecureRandom).to receive(:uuid).and_return(catalog_uuid) | ||
end | ||
|
||
it 'does not process in noop mode' do | ||
allow(report).to receive(:noop).and_return(true) | ||
expect(fleet_client_mock).not_to receive(:match_profiles) | ||
report.process | ||
end | ||
|
||
it 'logs an error if resources failed to be assigned' do | ||
allow(report).to receive(:resource_statuses).and_return({ 'myresource' => 'error pre-setting fleetdm::profile' }) | ||
expect(Puppet).to receive(:err).with(%r{Some resources failed to be assigned}) | ||
expect(fleet_client_mock).not_to receive(:match_profiles) | ||
report.process | ||
end | ||
|
||
it 'successfully matches profiles when there are no errors' do | ||
allow(report).to receive(:noop).and_return(false) | ||
allow(report).to receive(:resource_statuses).and_return({}) | ||
allow(fleet_client_mock).to receive(:match_profiles).and_return({ 'error' => '' }) | ||
allow(report).to receive(:catalog_uuid).and_return(catalog_uuid) | ||
|
||
expect(fleet_client_mock).to receive(:match_profiles).with("#{catalog_uuid}-#{node_name}", anything) | ||
expect(Puppet).to receive(:info).with("Successfully matched #{node_name} with a team containing configuration profiles") | ||
|
||
report.process | ||
end | ||
|
||
it 'logs an error when matching profiles fails' do | ||
allow(report).to receive(:noop).and_return(false) | ||
allow(report).to receive(:resource_statuses).and_return({}) | ||
allow(fleet_client_mock).to receive(:match_profiles).and_return({ 'error' => 'Some error' }) | ||
allow(report).to receive(:catalog_uuid).and_return(catalog_uuid) | ||
|
||
expect(fleet_client_mock).to receive(:match_profiles).with("#{catalog_uuid}-#{node_name}", anything) | ||
expect(Puppet).to receive(:err).with("Error matching node #{node_name} with a team containing configuration profiles: Some error") | ||
|
||
report.process | ||
end | ||
end |