Skip to content

Commit

Permalink
Allow disabling agent entity validation and API validation
Browse files Browse the repository at this point in the history
Fix acceptance tests to work around systemd issues
Test against PostgreSQL 11 as 9.6 no longer available
  • Loading branch information
Trey Dockendorf committed Feb 26, 2023
1 parent 5a067b9 commit 552baaa
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ jobs:
bundler-cache: true
bundler: '2.1.0'
- name: Validate
run: bundle exec rake validate lint strings:generate reference
run: bundle exec rake sensu_validate lint strings:generate reference
- name: Run tests
run: bundle exec rake parallel_spec
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,20 @@ sensu::agent::annotation { 'ec2_access_key':
}
```

### Advanced agent - Disable validations

In some cases it might be desired to disable API and entity validations when agents are managing their own entity.

```puppet
class { 'sensu':
validate_api => false,
}
class { 'sensu::agent':
agent_managed_entity => true,
validate_entity => false,
}
```

### Advanced agent - Custom config entries

It is possible to define config entries for `agent.yml` in many locations in Puppet:
Expand Down Expand Up @@ -648,7 +662,7 @@ The following example will add a PostgreSQL server and database to the sensu-bac
```puppet
class { 'postgresql::globals':
manage_package_repo => true,
version => '9.6',
version => '11',
}
class { 'postgresql::server': }
class { 'sensu::backend':
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RSpec::Core::RakeTask.new(:acceptance) do |t|
end

desc 'Validate manifests, templates, ruby files and shell scripts'
task :validate do
task :sensu_validate do
# lib/* gets checked by puppetlabs_spec_helper, though it skips spec entirely
puts "\nValidating ruby files ignored by puppetlabs_spec_helper (Vagrantfile', 'spec/**/*.rb)"
Dir['Vagrantfile', 'spec/**/*.rb'].each do |ruby_file|
Expand Down
6 changes: 3 additions & 3 deletions examples/postgresql-replication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Adjustments will have to be made for IP addresses and password.
Once the primary and standby have applied their Puppet catalog you must bootstrap the standby:

```
systemctl stop postgresql-9.6.service
rm -rf /var/lib/pgsql/9.6/data/*
sudo -u postgres pg_basebackup -h 192.168.52.11 -D /var/lib/pgsql/9.6/data -P -U repl -R --xlog-method=stream
systemctl stop postgresql-11.service
rm -rf /var/lib/pgsql/11/data/*
sudo -u postgres pg_basebackup -h 192.168.52.11 -D /var/lib/pgsql/11/data -P -U repl -R --xlog-method=stream
```

Once the bootstrap is done, re-run Puppet.
Expand Down
2 changes: 1 addition & 1 deletion examples/postgresql-replication/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class { 'postgresql::globals':
manage_package_repo => true,
version => '9.6',
version => '11',
}
class { 'postgresql::server':
listen_addresses => '*',
Expand Down
2 changes: 1 addition & 1 deletion examples/postgresql-ssl/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class { 'postgresql::globals':
manage_package_repo => true,
version => '9.6',
version => '11',
}

class { 'postgresql::server':
Expand Down
14 changes: 10 additions & 4 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
# Defaults to `C:\ProgramData\sensu\log\sensu-agent.log`
# @param agent_entity_config_provider
# The provider to use when managing sensu_agent_entity_config resources
# @param validate_entity
# Sets whether to validate the agent's entity before attempting
# to configure the entity
#
class sensu::agent (
Optional[String] $version = undef,
Expand All @@ -98,6 +101,7 @@
Boolean $show_diff = true,
Optional[Stdlib::Absolutepath] $log_file = undef,
Enum['sensuctl','sensu_api'] $agent_entity_config_provider = 'sensu_api',
Boolean $validate_entity = true,
) {

include sensu
Expand Down Expand Up @@ -295,9 +299,11 @@
subscribe => $service_subscribe,
}

sensu_agent_entity_validator { $config['name']:
ensure => 'present',
namespace => $config['namespace'],
provider => 'sensu_api',
if $validate_entity {
sensu_agent_entity_validator { $config['name']:
ensure => 'present',
namespace => $config['namespace'],
provider => 'sensu_api',
}
}
}
12 changes: 7 additions & 5 deletions manifests/api.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
validate_namespaces => $sensu::validate_namespaces,
}

sensu_api_validator { 'sensu':
ensure => 'present',
sensu_api_server => $sensu::api_host,
sensu_api_port => $sensu::api_port,
use_ssl => $sensu::use_ssl,
if $sensu::validate_api {
sensu_api_validator { 'sensu':
ensure => 'present',
sensu_api_server => $sensu::api_host,
sensu_api_port => $sensu::api_port,
use_ssl => $sensu::use_ssl,
}
}
}
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
# Defaults to value used for `agent_password`.
# @param validate_namespaces
# Determines if sensuctl and sensu_api types will validate their namespace exists
# @param validate_api
# Determines if Sensu API is validated
class sensu (
String $version = 'installed',
Stdlib::Absolutepath $etc_dir = '/etc/sensu',
Expand All @@ -80,6 +82,7 @@
String $agent_password = 'P@ssw0rd!',
Optional[String] $agent_entity_config_password = undef,
Boolean $validate_namespaces = true,
Boolean $validate_api = true,
) {

if $ssl_ca_content {
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/06_postgresql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class { 'sensu::agent':
pp = <<-EOS
class { 'postgresql::globals':
manage_package_repo => true,
version => '9.6',
version => '11',
}
class { 'postgresql::server':}
class { 'sensu::backend':
Expand Down
6 changes: 6 additions & 0 deletions spec/acceptance/nodesets/centos-7-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ HOSTS:
docker_image_commands:
- "sed -i -r '/^tsflags/d' /etc/yum.conf"
- 'yum install -y wget which iproute'
- 'wget --no-check-certificate https://copr.fedorainfracloud.org/coprs/jsynacek/systemd-backports-for-centos-7/repo/epel-7/jsynacek-systemd-backports-for-centos-7-epel-7.repo -O /etc/yum.repos.d/jsynacek-systemd-centos-7.repo'
- 'yum update -y systemd'
docker_container_name: 'sensu-backend1-el7'
sensu-backend2:
roles:
Expand All @@ -28,6 +30,8 @@ HOSTS:
docker_image_commands:
- "sed -i -r '/^tsflags/d' /etc/yum.conf"
- 'yum install -y wget which iproute'
- 'wget --no-check-certificate https://copr.fedorainfracloud.org/coprs/jsynacek/systemd-backports-for-centos-7/repo/epel-7/jsynacek-systemd-backports-for-centos-7-epel-7.repo -O /etc/yum.repos.d/jsynacek-systemd-centos-7.repo'
- 'yum update -y systemd'
docker_container_name: 'sensu-backend2-el7'
sensu-backend3:
roles:
Expand All @@ -42,6 +46,8 @@ HOSTS:
docker_image_commands:
- "sed -i -r '/^tsflags/d' /etc/yum.conf"
- 'yum install -y wget which iproute'
- 'wget --no-check-certificate https://copr.fedorainfracloud.org/coprs/jsynacek/systemd-backports-for-centos-7/repo/epel-7/jsynacek-systemd-backports-for-centos-7-epel-7.repo -O /etc/yum.repos.d/jsynacek-systemd-centos-7.repo'
- 'yum update -y systemd'
docker_container_name: 'sensu-backend3-el7'
CONFIG:
log_level: debug
Expand Down
4 changes: 4 additions & 0 deletions spec/acceptance/nodesets/centos-7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ HOSTS:
docker_image_commands:
- "sed -i -r '/^tsflags/d' /etc/yum.conf"
- 'yum install -y wget which iproute'
- 'wget --no-check-certificate https://copr.fedorainfracloud.org/coprs/jsynacek/systemd-backports-for-centos-7/repo/epel-7/jsynacek-systemd-backports-for-centos-7-epel-7.repo -O /etc/yum.repos.d/jsynacek-systemd-centos-7.repo'
- 'yum update -y systemd'
docker_env:
- LANG=en_US.UTF-8
- LANGUAGE=en_US.UTF-8
Expand All @@ -32,6 +34,8 @@ HOSTS:
docker_image_commands:
- "sed -i -r '/^tsflags/d' /etc/yum.conf"
- 'yum install -y wget which initscripts iproute'
- 'wget --no-check-certificate https://copr.fedorainfracloud.org/coprs/jsynacek/systemd-backports-for-centos-7/repo/epel-7/jsynacek-systemd-backports-for-centos-7-epel-7.repo -O /etc/yum.repos.d/jsynacek-systemd-centos-7.repo'
- 'yum update -y systemd'
docker_env:
- LANG=en_US.UTF-8
- LANGUAGE=en_US.UTF-8
Expand Down
27 changes: 17 additions & 10 deletions spec/acceptance/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
context 'default' do
pp = <<-EOS
class { '::sensu':
api_host => 'localhost',
api_host => 'localhost',
validate_api => false,
}
class { 'sensu::cli':
install_source => 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.20.1/sensu-go_5.20.1_windows_amd64.zip',
Expand Down Expand Up @@ -65,14 +66,17 @@ class { 'sensu::cli':

context 'default' do
pp = <<-EOS
class { '::sensu': }
class { '::sensu':
validate_api => false,
}
class { 'sensu::agent':
backends => ['sensu-backend:8081'],
entity_name => 'sensu-agent',
service_env_vars => { 'SENSU_API_PORT' => '4041' },
config_hash => {
'log-level' => 'info',
}
},
validate_entity => false,
}
EOS

Expand Down Expand Up @@ -117,15 +121,18 @@ class { 'sensu::agent':

context 'using package_source' do
pp = <<-EOS
class { '::sensu': }
class { '::sensu':
validate_api => false,
}
class { 'sensu::agent':
package_name => 'Sensu Agent',
package_source => 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.20.1/sensu-go-agent_5.20.1.12427_en-US.x64.msi',
backends => ['sensu-backend:8081'],
entity_name => 'sensu-agent',
config_hash => {
package_name => 'Sensu Agent',
package_source => 'https://s3-us-west-2.amazonaws.com/sensu.io/sensu-go/5.20.1/sensu-go-agent_5.20.1.12427_en-US.x64.msi',
backends => ['sensu-backend:8081'],
entity_name => 'sensu-agent',
config_hash => {
'log-level' => 'info',
}
},
validate_entity => false,
}
EOS

Expand Down
19 changes: 16 additions & 3 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@
it { should_not contain_file('sensu-agent_env_vars') }
end

context 'systemd systems deploy dropin', if: facts[:kernel] == 'Linux' do
let(:facts) { facts.merge({:service_provider => 'systemd'}) }
if facts[:service_provider] == 'systemd'
it {
should contain_systemd__dropin_file('sensu-agent-start.conf').with({
'unit' => 'sensu-agent.service',
Expand All @@ -127,7 +126,11 @@
})
}
end
it { should_not contain_systemd__dropin_file('sensu-agent-start.conf') }

context 'when not systemd', if: facts[:kernel] == 'Linux' do
let(:facts) { facts.merge({:service_provider => 'sysvinit'}) }
it { should_not contain_systemd__dropin_file('sensu-agent-start.conf') }
end

it {
should contain_service('sensu-agent').with({
Expand Down Expand Up @@ -328,6 +331,16 @@
it { should contain_package('sensu-go-agent').without_require }
end

context 'when validate_entity => false' do
let(:params) do
{
validate_entity: false
}
end

it { is_expected.not_to contain_sensu_agent_entity_validator('localhost') }
end

context 'with service_env_vars defined' do
let(:params) {{ :service_env_vars => { 'SENSU_API_PORT' => '4041' } }}
let(:service_env_vars_content) do
Expand Down
12 changes: 12 additions & 0 deletions spec/classes/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
}

end

context 'when validate_api => false' do
let(:pre_condition) do
<<-PP
class { 'sensu':
validate_api => false,
}
PP
end

it { is_expected.not_to contain_sensu_api_validator('sensu') }
end
end
end
end
Expand Down
Loading

0 comments on commit 552baaa

Please sign in to comment.