Skip to content

Commit

Permalink
Merge pull request #14 from lsst-it/IT-1827/pscheduler-agent
Browse files Browse the repository at this point in the history
add pscheduler-agent management
  • Loading branch information
treydock authored Aug 11, 2020
2 parents 24f7b3a + 9b901f6 commit 3ec477c
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ group :development do
gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-lint-param-docs", require: false
gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')
gem "rspec-json_expectations"
end
group :system_tests do
gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby]
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ class { '::perfsonar':
}
```

### Managing pscheduler-agent

One or more `pscheduler-agent` remotes may be configured.

(Hiera Example)

```yaml
perfsonar::manage_pscheduler_agent: true
perfsonar::pscheduler_agent_config:
remotes:
- url: "https://foo.example.org/psconfig/bar.json"
configure-archives: true
```
## Reference
[http://treydock.github.io/puppet-module-perfsonar/](http://treydock.github.io/puppet-module-perfsonar/)
14 changes: 14 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
# The Apache service name
# @param primary_interface
# The primary interface of host
# @param manage_pscheduler_agent
# Weather or not the pscheduler-agent daemon should be managed
# @param pscheduler_agent_config
# Configuration to convert to json and write to pscheduler-agent.json
class perfsonar (
Boolean $manage_repo = true,
Boolean $manage_epel = true,
Expand All @@ -59,6 +63,9 @@
String $apache_service = 'httpd',
# Interfaces
Optional[String] $primary_interface = $facts.dig('networking','primary'),
# pscheduler-agent
Boolean $manage_pscheduler_agent = false,
Optional[Hash] $pscheduler_agent_config = undef,
) {

if $manage_repo {
Expand All @@ -70,6 +77,13 @@
contain 'perfsonar::firewall'
}

if $manage_pscheduler_agent {
contain 'perfsonar::pscheduler::agent'

Class['perfsonar::install']
-> Class['perfsonar::pscheduler::agent']
}

contain 'perfsonar::install'
contain 'perfsonar::config'

Expand Down
22 changes: 22 additions & 0 deletions manifests/pscheduler/agent.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @summary Manage pschedular-agent service
# @api private
class perfsonar::pscheduler::agent {
assert_private()

$config_path = '/etc/perfsonar/psconfig/pscheduler-agent.json'

service { 'psconfig-pscheduler-agent':
ensure => running,
enable => true,
}

if $::perfsonar::pscheduler_agent_config {
file { $config_path:
ensure => file,
owner => 'perfsonar',
group => 'perfsonar',
mode => '0644',
content => to_json_pretty($::perfsonar::pscheduler_agent_config),
} ~> Service['psconfig-pscheduler-agent']
}
}
35 changes: 35 additions & 0 deletions spec/acceptance/pscheduler_agent_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper_acceptance'

describe 'perfsonar::pscheduler::agent' do
context 'with pscheduler_agent_config' do
let(:pp) do
<<-EOS
class { 'perfsonar':
manage_firewall => false,
manage_pscheduler_agent => true,
pscheduler_agent_config => {
remotes => [{
url => 'https://foo.example.org',
configure-archives => true,
}],
}
}
EOS
end

it_behaves_like 'an idempotent resource'

describe service('psconfig-pscheduler-agent') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe file('/etc/perfsonar/psconfig/pscheduler-agent.json') do
it { is_expected.to be_file }
it { is_expected.to be_owned_by 'perfsonar' }
it { is_expected.to be_grouped_into 'perfsonar' }
it { is_expected.to be_mode '644' } # serverspec does not like a leading 0
its(:content) { is_expected.to match %r{https://foo.example.org} }
end
end
end
40 changes: 40 additions & 0 deletions spec/classes/perfsonar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,46 @@

it { is_expected.to contain_file('/etc/profile.d/add_psadmin_pssudo.sh').with_ensure('absent') }
end

context 'when manage_pscheduler_agent' do
let(:params) { { manage_pscheduler_agent: true } }

it do
is_expected.to contain_service('psconfig-pscheduler-agent').with(
ensure: 'running',
enable: true,
)
end
end

context 'when pscheduler_agent_conf is not undef' do
let(:params) do
{
manage_pscheduler_agent: true,
pscheduler_agent_config: {
'remotes' => [{
'url' => 'https://foo.example.org',
'configure-archives' => true,
}],
},
}
end
let(:config_path) { '/etc/perfsonar/psconfig/pscheduler-agent.json' }

it do
is_expected.to contain_file(config_path).with(
ensure: 'file',
owner: 'perfsonar',
group: 'perfsonar',
mode: '0644',
).that_notifies(['Service[psconfig-pscheduler-agent]'])
end

it 'converts data into json' do
mycontent = catalogue.resource('File', config_path)[:content]
expect(mycontent).to include_json(params[:pscheduler_agent_config])
end
end
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'rspec-puppet-facts'

require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb'))
require 'rspec/json_expectations'

include RspecPuppetFacts

Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@

require 'spec_helper_acceptance_setup' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_setup.rb'))
# 'spec_overrides' from sync.yml will appear below this line

shared_examples 'an idempotent resource' do
it 'applies with no errors' do
apply_manifest(pp, catch_failures: true)
end

it 'applies a second time without changes' do
apply_manifest(pp, catch_changes: true)
end
end

0 comments on commit 3ec477c

Please sign in to comment.