beaker 2.27.0 → 2.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/HISTORY.md +378 -2
- data/README.md +1 -3
- data/acceptance/config/acceptance-options.rb +3 -0
- data/acceptance/fixtures/files/failing_shell_script.txt +3 -0
- data/acceptance/fixtures/files/retry_script.txt +14 -0
- data/acceptance/fixtures/files/shell_script_with_output.txt +3 -0
- data/acceptance/fixtures/files/simple_text_file.txt +3 -0
- data/acceptance/fixtures/files/sles-11-x86_64.repo +5 -0
- data/acceptance/lib/helpers/test_helper.rb +111 -0
- data/acceptance/tests/base/dsl/helpers/configuration_test.rb +17 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +50 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +64 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +100 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +201 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/create_tmpdir_on_test.rb +68 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +48 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +28 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +142 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/echo_on_test.rb +13 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/install_package_test.rb +67 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +109 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +42 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +143 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +242 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +69 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +53 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +53 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +54 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +51 -0
- data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +92 -0
- data/acceptance/tests/base/dsl/install_utils/clone_git_repo_on_test.rb +47 -0
- data/acceptance/tests/base/{host.rb → host_test.rb} +2 -0
- data/acceptance/tests/hypervisor/{communication.rb → communication_test.rb} +0 -0
- data/acceptance/tests/load_path_bootstrap.rb +10 -0
- data/acceptance/tests/puppet/{install_smoke.rb → install_smoke_test.rb} +0 -0
- data/beaker.gemspec +1 -1
- data/docs/Access-the-Live-Test-Console-with-Pry.md +305 -0
- data/docs/Argument-Processing-and-Precedence.md +325 -0
- data/docs/Beaker-Installation.md +59 -0
- data/docs/Beaker-Owners-and-Reviewers.md +16 -0
- data/docs/Beaker-Test-Tagging.md +76 -0
- data/docs/Beaker-with-Masterless-Puppet.md +42 -0
- data/docs/Creating-A-Test-Environment.md +91 -0
- data/docs/Docker-Support.md +129 -0
- data/docs/EC2-Support.md +77 -0
- data/docs/Example-Vagrant-Hosts-Files.md +66 -0
- data/docs/File-a-Beaker-Bug.md +3 -0
- data/docs/Google-Compute-Engine-Support.md +41 -0
- data/docs/How-To-Beaker.md +7 -0
- data/docs/How-To-Use-User-Password-Authentication-with-Beaker.md +53 -0
- data/docs/How-to-Write-a-Beaker-Test-for-a-Module.md +145 -0
- data/docs/Lets-Write-a-Test.md +73 -0
- data/docs/Openstack-Support.md +32 -0
- data/docs/Overview.md +31 -0
- data/docs/README.md +43 -0
- data/docs/Roles-What-Are-They.md +44 -0
- data/docs/Shared-Options-for-Executing-Beaker-Commands.md +43 -0
- data/docs/Solaris-Support.md +10 -0
- data/docs/The-Beaker-DSL.md +283 -0
- data/docs/The-Command-Line.md +24 -0
- data/docs/Types,-Puppet-4,-and-the-All-In-One-Agent.md +13 -0
- data/docs/VMWare-Fusion-Support.md +36 -0
- data/docs/Vagrant-Support.md +47 -0
- data/docs/beaker-vs.-beaker-rspec.md +87 -0
- data/docs/hosts/README.md +8 -0
- data/docs/hosts/eos.md +30 -0
- data/docs/hypervisors/README.md +8 -0
- data/docs/hypervisors/aws.md +143 -0
- data/docs/vSphere-Support.md +46 -0
- data/lib/beaker/dsl/helpers/host_helpers.rb +2 -4
- data/lib/beaker/dsl/helpers/puppet_helpers.rb +45 -11
- data/lib/beaker/dsl/install_utils/foss_utils.rb +20 -23
- data/lib/beaker/dsl/install_utils/module_utils.rb +4 -0
- data/lib/beaker/dsl/install_utils/pe_utils.rb +2 -6
- data/lib/beaker/dsl/patterns.rb +1 -1
- data/lib/beaker/host.rb +3 -0
- data/lib/beaker/host/eos.rb +56 -0
- data/lib/beaker/host/mac/pkg.rb +1 -1
- data/lib/beaker/host/unix/pkg.rb +36 -0
- data/lib/beaker/hypervisor/aws_sdk.rb +1 -1
- data/lib/beaker/hypervisor/vagrant.rb +3 -3
- data/lib/beaker/logger.rb +1 -0
- data/lib/beaker/options/presets.rb +5 -0
- data/lib/beaker/shared/host_manager.rb +7 -4
- data/lib/beaker/version.rb +1 -1
- data/spec/beaker/dsl/helpers/puppet_helpers_spec.rb +87 -0
- data/spec/beaker/dsl/install_utils/foss_utils_spec.rb +53 -20
- data/spec/beaker/dsl/install_utils/module_utils_spec.rb +1 -1
- data/spec/beaker/dsl/install_utils/pe_utils_spec.rb +7 -14
- data/spec/beaker/host/eos_spec.rb +65 -0
- data/spec/beaker/host/unix/pkg_spec.rb +42 -0
- data/spec/beaker/hypervisor/aws_sdk_spec.rb +17 -56
- data/spec/beaker/hypervisor/vagrant_spec.rb +1 -1
- data/spec/beaker/logger_spec.rb +1 -1
- data/spec/mocks.rb +0 -13
- metadata +76 -6
- data/acceptance/tests/dsl/install_utils/clone_git_repo_on.rb +0 -50
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "helpers/test_helper"
|
|
2
|
+
|
|
3
|
+
test_name "dsl::helpers::host_helpers #retry_on" do
|
|
4
|
+
step "#retry_on CURRENTLY fails with a RuntimeError if command does not pass after all retries" do
|
|
5
|
+
# NOTE: would have expected this to fail with Beaker::Hosts::CommandFailure
|
|
6
|
+
|
|
7
|
+
remote_tmpdir = tmpdir_on default
|
|
8
|
+
remote_script_file = File.join(remote_tmpdir, "test.sh")
|
|
9
|
+
remote_filename, contents = create_remote_file_from_fixture("retry_script", default, remote_tmpdir, "test.sh")
|
|
10
|
+
|
|
11
|
+
assert_raises RuntimeError do
|
|
12
|
+
retry_on default, "bash #{remote_script_file} #{remote_tmpdir} 10", { :max_retries => 2, :retry_interval => 0.1 }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
step "#retry_on succeeds if command passes before retries are exhausted" do
|
|
17
|
+
remote_tmpdir = tmpdir_on default
|
|
18
|
+
remote_script_file = File.join(remote_tmpdir, "test.sh")
|
|
19
|
+
remote_filename, contents = create_remote_file_from_fixture("retry_script", default, remote_tmpdir, "test.sh")
|
|
20
|
+
|
|
21
|
+
result = retry_on default, "bash #{remote_script_file} #{remote_tmpdir} 2", { :max_retries => 4, :retry_interval => 0.1 }
|
|
22
|
+
assert_equal 0, result.exit_code
|
|
23
|
+
assert_equal "", result.stdout
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
step "#retry_on CURRENTLY fails when provided a host array" do
|
|
27
|
+
# NOTE: would expect this to work across hosts, or be better documented and
|
|
28
|
+
# to raise Beaker::Host::CommandFailure
|
|
29
|
+
|
|
30
|
+
remote_tmpdir = tmpdir_on default
|
|
31
|
+
remote_script_file = File.join(remote_tmpdir, "test.sh")
|
|
32
|
+
|
|
33
|
+
hosts.each do |host|
|
|
34
|
+
on host, "mkdir -p #{remote_tmpdir}"
|
|
35
|
+
remote_filename, contents = create_remote_file_from_fixture("retry_script", host, remote_tmpdir, "test.sh")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
assert_raises NoMethodError do
|
|
39
|
+
result = retry_on hosts, "bash #{remote_script_file} #{remote_tmpdir} 2", { :max_retries => 4, :retry_interval => 0.1 }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
require "helpers/test_helper"
|
|
2
|
+
|
|
3
|
+
test_name "dsl::helpers::host_helpers #rsync_to" do
|
|
4
|
+
|
|
5
|
+
confine_block :to, :platform => /^solaris.*10/ do
|
|
6
|
+
|
|
7
|
+
step "#rsync_to CURRENTLY will fail without error, but not copy the requested file, on #{default['platform']} due to lack of installed rsync" do
|
|
8
|
+
|
|
9
|
+
# NOTE: this should be documented
|
|
10
|
+
# FIXME: This is also true for CentOS/EL-*, but package removal appears
|
|
11
|
+
# to not be working properly, so we cannot get test isolation
|
|
12
|
+
# to test this as if the system is pristine.
|
|
13
|
+
Dir.mktmpdir do |local_dir|
|
|
14
|
+
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
|
|
15
|
+
remote_tmpdir = tmpdir_on default
|
|
16
|
+
|
|
17
|
+
rsync_to default, local_filename, remote_tmpdir
|
|
18
|
+
|
|
19
|
+
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
|
20
|
+
|
|
21
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
22
|
+
remote_contents = on(default, "cat #{remote_filename}").stdout
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
confine_block :to, :platform => /^centos|el-\d|fedora/ do
|
|
29
|
+
step "installing `rsync` on #{default['platform']} for all later test steps" do
|
|
30
|
+
hosts.each do |host|
|
|
31
|
+
install_package host, "rsync"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# NOTE: there does not seem to be a reliable way to confine to cygwin hosts.
|
|
37
|
+
confine_block :to, :platform => /windows/ do
|
|
38
|
+
|
|
39
|
+
# NOTE: rsync methods are not working currently on windows platforms. Would
|
|
40
|
+
# expect this to be documented better.
|
|
41
|
+
|
|
42
|
+
step "#rsync_to CURRENTLY fails on windows systems" do
|
|
43
|
+
Dir.mktmpdir do |local_dir|
|
|
44
|
+
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
|
|
45
|
+
remote_tmpdir = tmpdir_on default
|
|
46
|
+
|
|
47
|
+
rsync_to default, local_filename, remote_tmpdir
|
|
48
|
+
|
|
49
|
+
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
|
50
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
51
|
+
remote_contents = on(default, "cat #{remote_filename}").stdout
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
confine_block :except, :platform => /windows|solaris.*10/ do
|
|
58
|
+
|
|
59
|
+
step "#rsync_to fails if the local file cannot be found" do
|
|
60
|
+
remote_tmpdir = tmpdir_on default
|
|
61
|
+
assert_raises IOError do
|
|
62
|
+
rsync_to default, "/non/existent/file.txt", remote_tmpdir
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
step "#rsync_to CURRENTLY does not fail, but does not copy the file if the remote path cannot be found" do
|
|
67
|
+
# NOTE: would expect this to fail with Beaker::Host::CommandFailure
|
|
68
|
+
|
|
69
|
+
Dir.mktmpdir do |local_dir|
|
|
70
|
+
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
|
|
71
|
+
|
|
72
|
+
rsync_to default, local_filename, "/non/existent/testfile.txt"
|
|
73
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
74
|
+
on(default, "cat /non/existent/testfile.txt").exit_code
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
step "#rsync_to creates the file on the remote system" do
|
|
80
|
+
Dir.mktmpdir do |local_dir|
|
|
81
|
+
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
|
|
82
|
+
remote_tmpdir = tmpdir_on default
|
|
83
|
+
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
|
84
|
+
|
|
85
|
+
result = rsync_to default, local_filename, remote_tmpdir
|
|
86
|
+
|
|
87
|
+
fails_intermittently("https://tickets.puppetlabs.com/browse/QENG-3053",
|
|
88
|
+
"result" => result,
|
|
89
|
+
"default" => default,
|
|
90
|
+
"contents" => contents,
|
|
91
|
+
"local_filename" => local_filename,
|
|
92
|
+
"local_dir" => local_dir,
|
|
93
|
+
"remote_filename" => remote_filename,
|
|
94
|
+
"remote_tmdir" => remote_tmpdir,
|
|
95
|
+
"result" => result.inspect,
|
|
96
|
+
) do
|
|
97
|
+
remote_contents = on(default, "cat #{remote_filename}").stdout
|
|
98
|
+
assert_equal contents, remote_contents
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
step "#rsync_to creates the file on all remote systems when a host array is provided" do
|
|
104
|
+
Dir.mktmpdir do |local_dir|
|
|
105
|
+
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
|
|
106
|
+
remote_tmpdir = tmpdir_on default
|
|
107
|
+
on hosts, "mkdir -p #{remote_tmpdir}"
|
|
108
|
+
remote_filename = File.join(remote_tmpdir, "testfile.txt")
|
|
109
|
+
|
|
110
|
+
result = rsync_to hosts, local_filename, remote_tmpdir
|
|
111
|
+
|
|
112
|
+
hosts.each do |host|
|
|
113
|
+
fails_intermittently("https://tickets.puppetlabs.com/browse/QENG-3053",
|
|
114
|
+
"result" => result,
|
|
115
|
+
"host" => host,
|
|
116
|
+
"contents" => contents,
|
|
117
|
+
"local_filename" => local_filename,
|
|
118
|
+
"local_dir" => local_dir,
|
|
119
|
+
"remote_filename" => remote_filename,
|
|
120
|
+
"remote_tmdir" => remote_tmpdir,
|
|
121
|
+
"result" => result.inspect,
|
|
122
|
+
) do
|
|
123
|
+
remote_contents = on(host, "cat #{remote_filename}").stdout
|
|
124
|
+
assert_equal contents, remote_contents
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
confine_block :to, :platform => /centos|el-\d|fedora/ do
|
|
132
|
+
|
|
133
|
+
step "uninstall rsync package on #{default['platform']} for later test runs" do
|
|
134
|
+
# NOTE: this is basically a #teardown section for test isolation
|
|
135
|
+
# Could we reorganize tests into different files to make this
|
|
136
|
+
# clearer?
|
|
137
|
+
|
|
138
|
+
hosts.each do |host|
|
|
139
|
+
on host, "yum -y remove rsync"
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
require "helpers/test_helper"
|
|
2
|
+
|
|
3
|
+
test_name "dsl::helpers::host_helpers #run_cron_on" do
|
|
4
|
+
|
|
5
|
+
confine_block :to, :platform => /windows/ do
|
|
6
|
+
|
|
7
|
+
step "#run_cron_on fails on windows platforms when listing cron jobs for a user on a host" do
|
|
8
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
9
|
+
run_cron_on default, :list, default['user']
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
confine_block :to, :platform => /solaris/ do
|
|
15
|
+
|
|
16
|
+
step "#run_cron_on CURRENTLY does nothing and returns `nil` when an unknown command is provided" do
|
|
17
|
+
# NOTE: would have expected this to raise Beaker::Host::CommandFailure instead
|
|
18
|
+
|
|
19
|
+
assert_nil run_cron_on default, :nonexistent_action, default['user']
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
step "#run_cron_on CURRENTLY does not fail when listing cron jobs for an unknown user" do
|
|
23
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
24
|
+
run_cron_on default, :list, "nonexistentuser"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
step "#run_cron_on CURRENTLY does not fail when listing cron jobs for a user with no cron entries" do
|
|
29
|
+
result = run_cron_on default, :list, default['user']
|
|
30
|
+
assert_equal 0, result.exit_code
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
step "#run_cron_on returns a list of cron jobs for a user with cron entries" do
|
|
34
|
+
# this basically requires us to add a cron entry to make this work
|
|
35
|
+
run_cron_on default, :add, default['user'], "* * * * * /bin/ls >/dev/null"
|
|
36
|
+
result = run_cron_on default, :list, default['user']
|
|
37
|
+
assert_equal 0, result.exit_code
|
|
38
|
+
assert_match %r{/bin/ls}, result.stdout
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
step "#run_cron_on CURRENTLY does not fail, but returns nil, when adding cron jobs for an unknown user" do
|
|
42
|
+
result = run_cron_on default, :add, "nonexistentuser", %Q{* * * * * /bin/echo "hello" >/dev/null}
|
|
43
|
+
assert_nil result
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
step "#run_cron_on CURRENTLY does not fail, but returns nil, when attempting to add a bad cron entry" do
|
|
47
|
+
result = run_cron_on default, :add, default['user'], "* * * * /bin/ls >/dev/null"
|
|
48
|
+
assert_nil result
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
step "#run_cron_on can add a cron job for a user on a host" do
|
|
52
|
+
run_cron_on default, :add, default['user'], %Q{* * * * * /bin/echo "hello" >/dev/null}
|
|
53
|
+
result = run_cron_on default, :list, default['user']
|
|
54
|
+
assert_equal 0, result.exit_code
|
|
55
|
+
assert_match %r{/bin/echo}, result.stdout
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
step "#run_cron_on CURRENTLY replaces all of user's cron jobs with any newly added jobs" do
|
|
59
|
+
# NOTE: would have expected this to append new entries, or manage them as puppet manages
|
|
60
|
+
# cron entries. See also: https://github.com/puppetlabs/beaker/pull/937#discussion_r38338494
|
|
61
|
+
|
|
62
|
+
1.upto(3) do |job_number|
|
|
63
|
+
run_cron_on default, :add, default['user'], %Q{* * * * * /bin/echo "job :#{job_number}:" >/dev/null}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
result = run_cron_on default, :list, default['user']
|
|
67
|
+
|
|
68
|
+
assert_no_match %r{job :1:}, result.stdout
|
|
69
|
+
assert_no_match %r{job :2:}, result.stdout
|
|
70
|
+
assert_match %r{job :3:}, result.stdout
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
step "#run_cron_on :remove CURRENTLY removes all cron jobs for a user on a host" do
|
|
74
|
+
# NOTE: would have expected a more granular approach to removing cron jobs
|
|
75
|
+
# for a user on a host. This should otherwise be better documented.
|
|
76
|
+
|
|
77
|
+
run_cron_on default, :add, default['user'], %Q{* * * * * /bin/echo "quality: job 1" >/dev/null}
|
|
78
|
+
result = run_cron_on default, :list, default['user']
|
|
79
|
+
assert_match %r{quality: job 1}, result.stdout
|
|
80
|
+
|
|
81
|
+
run_cron_on default, :remove, default['user']
|
|
82
|
+
|
|
83
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
84
|
+
run_cron_on default, :list, default['user']
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
step "#run_cron_on fails when removing cron jobs for an unknown user" do
|
|
89
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
90
|
+
run_cron_on default, :remove, "nonexistentuser"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
step "#run_cron_on can list cron jobs for a user on all hosts when given a host array" do
|
|
95
|
+
hosts.each do |host|
|
|
96
|
+
# this basically requires us to add a cron entry to make this work
|
|
97
|
+
run_cron_on host, :add, host['user'], "* * * * * /bin/ls >/dev/null"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
results = run_cron_on hosts, :list, default['user']
|
|
101
|
+
results.each do |result|
|
|
102
|
+
assert_match %r{/bin/ls}, result.stdout
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
step "#run_cron_on can add cron jobs for a user on all hosts when given a host array" do
|
|
107
|
+
run_cron_on hosts, :add, default['user'], "* * * * * /bin/ls >/dev/null"
|
|
108
|
+
|
|
109
|
+
results = run_cron_on hosts, :list, default['user']
|
|
110
|
+
results.each do |result|
|
|
111
|
+
assert_match %r{/bin/ls}, result.stdout
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
step "#run_cron_on can remove cron jobs for a user on all hosts when given a host array" do
|
|
116
|
+
run_cron_on hosts, :add, default['user'], "* * * * * /bin/ls >/dev/null"
|
|
117
|
+
run_cron_on hosts, :remove, default['user']
|
|
118
|
+
|
|
119
|
+
hosts.each do |host|
|
|
120
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
121
|
+
results = run_cron_on host, :list, host['user']
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
confine_block :except, :platform => /windows|solaris/ do
|
|
128
|
+
|
|
129
|
+
step "#run_cron_on CURRENTLY does nothing and returns `nil` when an unknown command is provided" do
|
|
130
|
+
# NOTE: would have expected this to raise Beaker::Host::CommandFailure instead
|
|
131
|
+
|
|
132
|
+
assert_nil run_cron_on default, :nonexistent_action, default['user']
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
step "#run_cron_on fails when listing cron jobs for an unknown user" do
|
|
136
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
137
|
+
run_cron_on default, :list, "nonexistentuser"
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
step "#run_cron_on fails when listing cron jobs for a user with no cron entries" do
|
|
142
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
143
|
+
run_cron_on default, :list, default['user']
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
step "#run_cron_on returns a list of cron jobs for a user with cron entries" do
|
|
148
|
+
# this basically requires us to add a cron entry to make this work
|
|
149
|
+
run_cron_on default, :add, default['user'], "* * * * * /bin/ls >/dev/null"
|
|
150
|
+
result = run_cron_on default, :list, default['user']
|
|
151
|
+
assert_equal 0, result.exit_code
|
|
152
|
+
assert_match %r{/bin/ls}, result.stdout
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
step "#run_cron_on fails when adding cron jobs for an unknown user" do
|
|
156
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
157
|
+
run_cron_on default, :add, "nonexistentuser", %Q{* * * * * /bin/echo "hello" >/dev/null}
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
step "#run_cron_on fails when attempting to add a bad cron entry" do
|
|
162
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
163
|
+
run_cron_on default, :add, default['user'], "* * * * /bin/ls >/dev/null"
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
step "#run_cron_on can add a cron job for a user on a host" do
|
|
168
|
+
run_cron_on default, :add, default['user'], %Q{* * * * * /bin/echo "hello" >/dev/null}
|
|
169
|
+
result = run_cron_on default, :list, default['user']
|
|
170
|
+
assert_equal 0, result.exit_code
|
|
171
|
+
assert_match %r{/bin/echo}, result.stdout
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
step "#run_cron_on CURRENTLY replaces all of user's cron jobs with any newly added jobs" do
|
|
175
|
+
# NOTE: would have expected this to append new entries, or manage them as puppet manages
|
|
176
|
+
# cron entries. See also: https://github.com/puppetlabs/beaker/pull/937#discussion_r38338494
|
|
177
|
+
|
|
178
|
+
1.upto(3) do |job_number|
|
|
179
|
+
run_cron_on default, :add, default['user'], %Q{* * * * * /bin/echo "job :#{job_number}:" >/dev/null}
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
result = run_cron_on default, :list, default['user']
|
|
183
|
+
|
|
184
|
+
assert_no_match %r{job :1:}, result.stdout
|
|
185
|
+
assert_no_match %r{job :2:}, result.stdout
|
|
186
|
+
assert_match %r{job :3:}, result.stdout
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
step "#run_cron_on :remove CURRENTLY removes all cron jobs for a user on a host" do
|
|
190
|
+
# NOTE: would have expected a more granular approach to removing cron jobs
|
|
191
|
+
# for a user on a host. This should otherwise be better documented.
|
|
192
|
+
|
|
193
|
+
run_cron_on default, :add, default['user'], %Q{* * * * * /bin/echo "quality: job 1" >/dev/null}
|
|
194
|
+
result = run_cron_on default, :list, default['user']
|
|
195
|
+
assert_match %r{quality: job 1}, result.stdout
|
|
196
|
+
|
|
197
|
+
run_cron_on default, :remove, default['user']
|
|
198
|
+
|
|
199
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
200
|
+
run_cron_on default, :list, default['user']
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
step "#run_cron_on fails when removing cron jobs for an unknown user" do
|
|
205
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
206
|
+
run_cron_on default, :remove, "nonexistentuser"
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
step "#run_cron_on can list cron jobs for a user on all hosts when given a host array" do
|
|
211
|
+
hosts.each do |host|
|
|
212
|
+
# this basically requires us to add a cron entry to make this work
|
|
213
|
+
run_cron_on host, :add, host['user'], "* * * * * /bin/ls >/dev/null"
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
results = run_cron_on hosts, :list, default['user']
|
|
217
|
+
results.each do |result|
|
|
218
|
+
assert_match %r{/bin/ls}, result.stdout
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
step "#run_cron_on can add cron jobs for a user on all hosts when given a host array" do
|
|
223
|
+
run_cron_on hosts, :add, default['user'], "* * * * * /bin/ls >/dev/null"
|
|
224
|
+
|
|
225
|
+
results = run_cron_on hosts, :list, default['user']
|
|
226
|
+
results.each do |result|
|
|
227
|
+
assert_match %r{/bin/ls}, result.stdout
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
step "#run_cron_on can remove cron jobs for a user on all hosts when given a host array" do
|
|
232
|
+
run_cron_on hosts, :add, default['user'], "* * * * * /bin/ls >/dev/null"
|
|
233
|
+
run_cron_on hosts, :remove, default['user']
|
|
234
|
+
|
|
235
|
+
hosts.each do |host|
|
|
236
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
237
|
+
results = run_cron_on host, :list, host['user']
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require "helpers/test_helper"
|
|
2
|
+
|
|
3
|
+
test_name "dsl::helpers::host_helpers #run_script_on" do
|
|
4
|
+
|
|
5
|
+
step "#run_script_on fails when the local script cannot be found" do
|
|
6
|
+
assert_raises IOError do
|
|
7
|
+
run_script_on default, "/non/existent/testfile.sh"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
step "#run_script_on fails when there is an error running the remote script" do
|
|
12
|
+
Dir.mktmpdir do |local_dir|
|
|
13
|
+
local_filename = File.join(local_dir, "testfile.sh")
|
|
14
|
+
local_filename, contents = create_local_file_from_fixture("failing_shell_script", local_dir, "testfile.sh", "a+x")
|
|
15
|
+
|
|
16
|
+
assert_raises Beaker::Host::CommandFailure do
|
|
17
|
+
run_script_on default, local_filename
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
step "#run_script_on passes along options when running the remote command" do
|
|
23
|
+
Dir.mktmpdir do |local_dir|
|
|
24
|
+
local_filename = File.join(local_dir, "testfile.sh")
|
|
25
|
+
local_filename, contents = create_local_file_from_fixture("failing_shell_script", local_dir, "testfile.sh", "a+x")
|
|
26
|
+
|
|
27
|
+
result = run_script_on default, local_filename, { :accept_all_exit_codes => true }
|
|
28
|
+
assert_equal 1, result.exit_code
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
step "#run_script_on runs the script on the remote host" do
|
|
33
|
+
Dir.mktmpdir do |local_dir|
|
|
34
|
+
local_filename = File.join(local_dir, "testfile.sh")
|
|
35
|
+
local_filename, contents = create_local_file_from_fixture("shell_script_with_output", local_dir, "testfile.sh", "a+x")
|
|
36
|
+
|
|
37
|
+
results = run_script_on default, local_filename
|
|
38
|
+
assert_equal 0, results.exit_code
|
|
39
|
+
assert_equal "output\n", results.stdout
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
step "#run_script_on allows assertions in an optional block" do
|
|
44
|
+
Dir.mktmpdir do |local_dir|
|
|
45
|
+
local_filename = File.join(local_dir, "testfile.sh")
|
|
46
|
+
local_filename, contents = create_local_file_from_fixture("shell_script_with_output", local_dir, "testfile.sh", "a+x")
|
|
47
|
+
|
|
48
|
+
results = run_script_on default, local_filename do
|
|
49
|
+
assert_equal 0, exit_code
|
|
50
|
+
assert_equal "output\n", stdout
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
step "#run_script_on runs the script on all remote hosts when a host array is provided" do
|
|
56
|
+
Dir.mktmpdir do |local_dir|
|
|
57
|
+
local_filename = File.join(local_dir, "testfile.sh")
|
|
58
|
+
local_filename, contents = create_local_file_from_fixture("shell_script_with_output", local_dir, "testfile.sh", "a+x")
|
|
59
|
+
|
|
60
|
+
results = run_script_on hosts, local_filename
|
|
61
|
+
|
|
62
|
+
assert_equal hosts.size, results.size
|
|
63
|
+
results.each do |result|
|
|
64
|
+
assert_equal 0, result.exit_code
|
|
65
|
+
assert_equal "output\n", result.stdout
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|