Skip to content

Commit 19e76e6

Browse files
lionceeimlav
authored andcommitted
(FM-7798) Test audit making making testing more efficient (puppetlabs#81)
1 parent 0b811af commit 19e76e6

File tree

5 files changed

+36
-60
lines changed

5 files changed

+36
-60
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ This module provides services tasks, There are two kinds of tasks. The default t
1818
## Requirements
1919
This module is compatible with Puppet Enterprise and Puppet Bolt.
2020

21-
* To run tasks with Puppet Enterprise, PE 2017.3 or later must be installed on the machine from which you are running task commands. Machines receiving task requests must be Puppet agents.
21+
* To run tasks with Puppet Enterprise, PE 2018.1 or later must be installed on the machine from which you are running task commands. Machines receiving task requests must be Puppet agents.
2222

23-
* To run tasks with Puppet Bolt, Bolt 0.5 or later must be installed on the machine from which you are running task commands. Machines receiving task requests must have SSH or WinRM services enabled.
23+
* To run tasks with Puppet Bolt, Bolt 1.0 or later must be installed on the machine from which you are running task commands. Machines receiving task requests must have SSH or WinRM services enabled.
2424

2525
## Usage
2626

@@ -68,6 +68,8 @@ For a complete list of services that are supported see the Puppet [services](htt
6868

6969
## Limitations
7070

71+
To run acceptance tests against Windows machines, ensure that the `BEAKER_password` environment variable has been set to the password of the Administrator user of the target machine.
72+
7173
For an extensive list of supported operating systems, see [metadata.json](https://github.com/puppetlabs/puppetlabs-service/blob/master/metadata.json)
7274

7375
## Getting Help

metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
}
6666
],
6767
"description": "Tasks that manipulate a service",
68-
"pdk-version": "1.8.0",
69-
"template-url": "https://github.com/puppetlabs/pdk-templates",
68+
"pdk-version": "1.9.0",
69+
"template-url": "https://github.com/puppetlabs/pdk-templates.git",
7070
"template-ref": "heads/master-0-gfde5699"
7171
}

spec/acceptance/init_spec.rb

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,39 @@
55
include Beaker::TaskHelper::Inventory
66
include BoltSpec::Run
77

8-
def module_path
9-
RSpec.configuration.module_path
10-
end
11-
12-
def config
13-
{ 'modulepath' => module_path }
14-
end
15-
16-
def inventory
17-
hosts_to_inventory.merge('features' => ['puppet-agent'])
18-
end
19-
20-
def run(params)
21-
run_task('service', 'default', params, config: config, inventory: inventory)
22-
end
23-
24-
osfamily_fact = fact('osfamily')
25-
268
package_to_use = ''
279
before(:all) do
28-
if osfamily_fact != 'windows'
29-
if osfamily_fact == 'RedHat' && fact('operatingsystemrelease') < '6'
30-
run('action' => 'stop', 'name' => 'syslog')
10+
if os[:family] != 'windows'
11+
if os[:family] == 'redhat' && os[:release].to_i < 6
12+
task_run('service', 'action' => 'stop', 'name' => 'syslog')
3113
end
3214
package_to_use = 'rsyslog'
3315
apply_manifest_on(default, "package { \"#{package_to_use}\": ensure => present, }")
3416
else
3517
package_to_use = 'W32Time'
36-
run('action' => 'start', 'name' => package_to_use)
18+
task_run('service', 'action' => 'start', 'name' => package_to_use)
3719
end
3820
end
3921

4022
describe 'enable action' do
4123
it 'enable/status a service' do
42-
result = run('action' => 'enable', 'name' => package_to_use)
24+
result = task_run('service', 'action' => 'enable', 'name' => package_to_use)
4325
expect(result[0]['status']).to eq('success')
4426
expect(result[0]['result']['status']).to match(%r{in_sync|enabled})
4527

46-
result = run('action' => 'status', 'name' => package_to_use)
28+
result = task_run('service', 'action' => 'status', 'name' => package_to_use)
4729
expect(result[0]['status']).to eq('success')
4830
expect(result[0]['result']['enabled']).to eq('true')
4931
end
5032
end
5133

5234
describe 'restart action' do
5335
it 'restart/status a service' do
54-
result = run('action' => 'restart', 'name' => package_to_use)
36+
result = task_run('service', 'action' => 'restart', 'name' => package_to_use)
5537
expect(result[0]['status']).to eq('success')
5638
expect(result[0]['result']['status']).to eq('restarted')
5739

58-
result = run('action' => 'status', 'name' => package_to_use)
40+
result = task_run('service', 'action' => 'status', 'name' => package_to_use)
5941
expect(result[0]['status']).to eq('success')
6042
expect(result[0]['result']['status']).to eq('running')
6143
expect(result[0]['result']['enabled']).to eq('true')
@@ -64,13 +46,13 @@ def run(params)
6446

6547
describe 'stop action' do
6648
it 'stop/status a service' do
67-
result = run('action' => 'stop', 'name' => package_to_use)
49+
result = task_run('service', 'action' => 'stop', 'name' => package_to_use)
6850
expect(result[0]['status']).to eq('success')
6951
expect(result[0]['result']['status']).to match(%r{in_sync|stopped})
7052

7153
# Debian can give incorrect status
72-
if osfamily_fact != 'Debian'
73-
result = run('action' => 'status', 'name' => package_to_use)
54+
unless ['debian', 'ubuntu'].include?(os[:family])
55+
result = task_run('service', 'action' => 'status', 'name' => package_to_use)
7456
expect(result[0]['status']).to eq('success')
7557
expect(result[0]['result']['status']).to eq('stopped')
7658
expect(result[0]['result']['enabled']).to eq('true')
@@ -80,13 +62,13 @@ def run(params)
8062

8163
describe 'start action' do
8264
it 'start/status a service' do
83-
result = run('action' => 'start', 'name' => package_to_use)
65+
result = task_run('service', 'action' => 'start', 'name' => package_to_use)
8466
expect(result[0]['status']).to eq('success')
8567
expect(result[0]['result']['status']).to match(%r{in_sync|started})
8668

8769
# Debian can give incorrect status
88-
if osfamily_fact != 'Debian'
89-
result = run('action' => 'status', 'name' => package_to_use)
70+
if os[:family] != 'debian'
71+
result = task_run('service', 'action' => 'status', 'name' => package_to_use)
9072
expect(result[0]['status']).to eq('success')
9173
expect(result[0]['result']['status']).to eq('running')
9274
expect(result[0]['result']['enabled']).to eq('true')
@@ -96,11 +78,11 @@ def run(params)
9678

9779
describe 'disable action' do
9880
it 'disable/status a service' do
99-
result = run('action' => 'disable', 'name' => package_to_use)
81+
result = task_run('service', 'action' => 'disable', 'name' => package_to_use)
10082
expect(result[0]['status']).to eq('success')
10183
expect(result[0]['result']['status']).to eq('disabled')
10284

103-
result = run('action' => 'status', 'name' => package_to_use)
85+
result = task_run('service', 'action' => 'status', 'name' => package_to_use)
10486
expect(result[0]['status']).to eq('success')
10587
expect(result[0]['result']['enabled']).to eq('false')
10688
end

spec/acceptance/linux_spec.rb

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,37 @@
11
# run a test task
22
require 'spec_helper_acceptance'
33

4-
describe 'linux service task', unless: fact('osfamily') == 'windows' do
4+
describe 'linux service task', unless: os[:family] == 'windows' do
55
include Beaker::TaskHelper::Inventory
66
include BoltSpec::Run
77

8-
def module_path
9-
RSpec.configuration.module_path
10-
end
11-
12-
def config
13-
{ 'modulepath' => module_path }
14-
end
15-
16-
def inventory
17-
hosts_to_inventory
18-
end
19-
20-
def run(params)
21-
run_task('service::linux', 'default', params, config: config, inventory: inventory)
22-
end
23-
248
package_to_use = 'rsyslog'
259
before(:all) do
26-
if fact('osfamily') == 'RedHat' && fact('operatingsystemrelease') < '6'
27-
run('action' => 'stop', 'name' => 'syslog')
10+
if os[:family] == 'redhat' && os[:release].to_i < 6
11+
task_run('service::linux', 'action' => 'stop', 'name' => 'syslog')
2812
end
2913
apply_manifest_on(default, "package { \"#{package_to_use}\": ensure => present, }")
3014
end
3115

3216
describe 'stop action' do
3317
it "stop #{package_to_use}" do
34-
result = run('action' => 'stop', 'name' => package_to_use)
18+
result = task_run('service::linux', 'action' => 'stop', 'name' => package_to_use)
3519
expect(result[0]['status']).to eq('success')
3620
expect(result[0]['result']['status']).to match(%r{stop})
3721
end
3822
end
3923

4024
describe 'start action' do
4125
it "start #{package_to_use}" do
42-
result = run('action' => 'start', 'name' => package_to_use)
26+
result = task_run('service::linux', 'action' => 'start', 'name' => package_to_use)
4327
expect(result[0]['status']).to eq('success')
4428
expect(result[0]['result']['status']).to match(%r{start})
4529
end
4630
end
4731

4832
describe 'restart action' do
4933
it "restart #{package_to_use}" do
50-
result = run('action' => 'restart', 'name' => package_to_use)
34+
result = task_run('service::linux', 'action' => 'restart', 'name' => package_to_use)
5135
expect(result[0]['status']).to eq('success')
5236
expect(result[0]['result']['status']).to match(%r{restart})
5337
end

spec/spec_helper_acceptance.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
install_module_on(hosts)
1414
install_module_dependencies_on(hosts)
1515

16+
# Bolt helper task
17+
def task_run(task_name, params)
18+
module_path = RSpec.configuration.module_path
19+
config = { 'modulepath' => module_path }
20+
inventory = hosts_to_inventory.merge('features' => ['puppet-agent'])
21+
run_task(task_name, 'default', params, config: config, inventory: inventory)
22+
end
23+
1624
RSpec.configure do |c|
1725
# Readable test descriptions
1826
c.formatter = :documentation

0 commit comments

Comments
 (0)