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.
Files changed (98) hide show
  1. checksums.yaml +8 -8
  2. data/HISTORY.md +378 -2
  3. data/README.md +1 -3
  4. data/acceptance/config/acceptance-options.rb +3 -0
  5. data/acceptance/fixtures/files/failing_shell_script.txt +3 -0
  6. data/acceptance/fixtures/files/retry_script.txt +14 -0
  7. data/acceptance/fixtures/files/shell_script_with_output.txt +3 -0
  8. data/acceptance/fixtures/files/simple_text_file.txt +3 -0
  9. data/acceptance/fixtures/files/sles-11-x86_64.repo +5 -0
  10. data/acceptance/lib/helpers/test_helper.rb +111 -0
  11. data/acceptance/tests/base/dsl/helpers/configuration_test.rb +17 -0
  12. data/acceptance/tests/base/dsl/helpers/host_helpers/add_system32_hosts_entry_test.rb +50 -0
  13. data/acceptance/tests/base/dsl/helpers/host_helpers/backup_the_file_test.rb +64 -0
  14. data/acceptance/tests/base/dsl/helpers/host_helpers/check_for_package_test.rb +100 -0
  15. data/acceptance/tests/base/dsl/helpers/host_helpers/create_remote_file_test.rb +201 -0
  16. data/acceptance/tests/base/dsl/helpers/host_helpers/create_tmpdir_on_test.rb +68 -0
  17. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_on_test.rb +48 -0
  18. data/acceptance/tests/base/dsl/helpers/host_helpers/curl_with_retries_test.rb +28 -0
  19. data/acceptance/tests/base/dsl/helpers/host_helpers/deploy_package_repo_test.rb +142 -0
  20. data/acceptance/tests/base/dsl/helpers/host_helpers/echo_on_test.rb +13 -0
  21. data/acceptance/tests/base/dsl/helpers/host_helpers/install_package_test.rb +67 -0
  22. data/acceptance/tests/base/dsl/helpers/host_helpers/on_test.rb +109 -0
  23. data/acceptance/tests/base/dsl/helpers/host_helpers/retry_on_test.rb +42 -0
  24. data/acceptance/tests/base/dsl/helpers/host_helpers/rsync_to_test.rb +143 -0
  25. data/acceptance/tests/base/dsl/helpers/host_helpers/run_cron_on_test.rb +242 -0
  26. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_on_test.rb +69 -0
  27. data/acceptance/tests/base/dsl/helpers/host_helpers/run_script_test.rb +53 -0
  28. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_from_test.rb +53 -0
  29. data/acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb +54 -0
  30. data/acceptance/tests/base/dsl/helpers/host_helpers/shell_test.rb +51 -0
  31. data/acceptance/tests/base/dsl/helpers/host_helpers/upgrade_package_test.rb +92 -0
  32. data/acceptance/tests/base/dsl/install_utils/clone_git_repo_on_test.rb +47 -0
  33. data/acceptance/tests/base/{host.rb → host_test.rb} +2 -0
  34. data/acceptance/tests/hypervisor/{communication.rb → communication_test.rb} +0 -0
  35. data/acceptance/tests/load_path_bootstrap.rb +10 -0
  36. data/acceptance/tests/puppet/{install_smoke.rb → install_smoke_test.rb} +0 -0
  37. data/beaker.gemspec +1 -1
  38. data/docs/Access-the-Live-Test-Console-with-Pry.md +305 -0
  39. data/docs/Argument-Processing-and-Precedence.md +325 -0
  40. data/docs/Beaker-Installation.md +59 -0
  41. data/docs/Beaker-Owners-and-Reviewers.md +16 -0
  42. data/docs/Beaker-Test-Tagging.md +76 -0
  43. data/docs/Beaker-with-Masterless-Puppet.md +42 -0
  44. data/docs/Creating-A-Test-Environment.md +91 -0
  45. data/docs/Docker-Support.md +129 -0
  46. data/docs/EC2-Support.md +77 -0
  47. data/docs/Example-Vagrant-Hosts-Files.md +66 -0
  48. data/docs/File-a-Beaker-Bug.md +3 -0
  49. data/docs/Google-Compute-Engine-Support.md +41 -0
  50. data/docs/How-To-Beaker.md +7 -0
  51. data/docs/How-To-Use-User-Password-Authentication-with-Beaker.md +53 -0
  52. data/docs/How-to-Write-a-Beaker-Test-for-a-Module.md +145 -0
  53. data/docs/Lets-Write-a-Test.md +73 -0
  54. data/docs/Openstack-Support.md +32 -0
  55. data/docs/Overview.md +31 -0
  56. data/docs/README.md +43 -0
  57. data/docs/Roles-What-Are-They.md +44 -0
  58. data/docs/Shared-Options-for-Executing-Beaker-Commands.md +43 -0
  59. data/docs/Solaris-Support.md +10 -0
  60. data/docs/The-Beaker-DSL.md +283 -0
  61. data/docs/The-Command-Line.md +24 -0
  62. data/docs/Types,-Puppet-4,-and-the-All-In-One-Agent.md +13 -0
  63. data/docs/VMWare-Fusion-Support.md +36 -0
  64. data/docs/Vagrant-Support.md +47 -0
  65. data/docs/beaker-vs.-beaker-rspec.md +87 -0
  66. data/docs/hosts/README.md +8 -0
  67. data/docs/hosts/eos.md +30 -0
  68. data/docs/hypervisors/README.md +8 -0
  69. data/docs/hypervisors/aws.md +143 -0
  70. data/docs/vSphere-Support.md +46 -0
  71. data/lib/beaker/dsl/helpers/host_helpers.rb +2 -4
  72. data/lib/beaker/dsl/helpers/puppet_helpers.rb +45 -11
  73. data/lib/beaker/dsl/install_utils/foss_utils.rb +20 -23
  74. data/lib/beaker/dsl/install_utils/module_utils.rb +4 -0
  75. data/lib/beaker/dsl/install_utils/pe_utils.rb +2 -6
  76. data/lib/beaker/dsl/patterns.rb +1 -1
  77. data/lib/beaker/host.rb +3 -0
  78. data/lib/beaker/host/eos.rb +56 -0
  79. data/lib/beaker/host/mac/pkg.rb +1 -1
  80. data/lib/beaker/host/unix/pkg.rb +36 -0
  81. data/lib/beaker/hypervisor/aws_sdk.rb +1 -1
  82. data/lib/beaker/hypervisor/vagrant.rb +3 -3
  83. data/lib/beaker/logger.rb +1 -0
  84. data/lib/beaker/options/presets.rb +5 -0
  85. data/lib/beaker/shared/host_manager.rb +7 -4
  86. data/lib/beaker/version.rb +1 -1
  87. data/spec/beaker/dsl/helpers/puppet_helpers_spec.rb +87 -0
  88. data/spec/beaker/dsl/install_utils/foss_utils_spec.rb +53 -20
  89. data/spec/beaker/dsl/install_utils/module_utils_spec.rb +1 -1
  90. data/spec/beaker/dsl/install_utils/pe_utils_spec.rb +7 -14
  91. data/spec/beaker/host/eos_spec.rb +65 -0
  92. data/spec/beaker/host/unix/pkg_spec.rb +42 -0
  93. data/spec/beaker/hypervisor/aws_sdk_spec.rb +17 -56
  94. data/spec/beaker/hypervisor/vagrant_spec.rb +1 -1
  95. data/spec/beaker/logger_spec.rb +1 -1
  96. data/spec/mocks.rb +0 -13
  97. metadata +76 -6
  98. data/acceptance/tests/dsl/install_utils/clone_git_repo_on.rb +0 -50
@@ -0,0 +1,68 @@
1
+ require "helpers/test_helper"
2
+
3
+ test_name "dsl::helpers::host_helpers #create_tmpdir_on" do
4
+
5
+ # NOTE: there does not seem to be a reliable way to confine to cygwin hosts.
6
+ confine_block :to, :platform => /windows/ do
7
+
8
+ step "#create_tmpdir_on CURRENTLY fails when attempting to chown the created tempdir to the host user + group, on windows platforms" do
9
+ # NOTE: would have expected this to work.
10
+ # TODO: fix via https://tickets.puppetlabs.com/browse/BKR-496
11
+
12
+ assert_raises Beaker::Host::CommandFailure do
13
+ tmpdir = create_tmpdir_on default
14
+ end
15
+ end
16
+ end
17
+
18
+ confine_block :to, :platform => /osx/ do
19
+
20
+ step "#create_tmpdir_on CURRENTLY fails when attempting to call getent to check the creating user" do
21
+ # NOTE: would have expected this to work.
22
+ # TODO: fix via https://tickets.puppetlabs.com/browse/BKR-496
23
+
24
+ assert_raises Beaker::Host::CommandFailure do
25
+ tmpdir = create_tmpdir_on default
26
+ end
27
+ end
28
+ end
29
+
30
+ confine_block :except, :platform => /windows|osx/ do
31
+
32
+ step "#create_tmpdir_on chowns the created tempdir to the host user + group" do
33
+ tmpdir = create_tmpdir_on default
34
+ listing = on(default, "ls -al #{tmpdir}").stdout
35
+ tmpdir_ls = listing.split("\n").grep %r{\s+\./?\s*$}
36
+ assert_equal 1, tmpdir_ls.size
37
+ perms, inodes, owner, group, *rest = tmpdir_ls.first.split(/\s+/)
38
+ assert_equal default['user'], owner
39
+ assert_equal default['user'], group
40
+ end
41
+
42
+ step "#create_tmpdir_on returns a temporary directory on the remote system" do
43
+ tmpdir = create_tmpdir_on default
44
+ assert_match %r{/}, tmpdir
45
+ assert_equal 0, on(default, "touch #{tmpdir}/testfile").exit_code
46
+ end
47
+
48
+ step "#create_tmpdir_on uses the specified path prefix when provided" do
49
+ tmpdir = create_tmpdir_on(default, "mypathprefix")
50
+ assert_match %r{/mypathprefix}, tmpdir
51
+ assert_equal 0, on(default, "touch #{tmpdir}/testfile").exit_code
52
+ end
53
+
54
+ step "#create_tmpdir_on fails if a non-existent user is specified" do
55
+ assert_raises Beaker::Host::CommandFailure do
56
+ tmpdir = create_tmpdir_on default, '', "fakeuser"
57
+ end
58
+ end
59
+
60
+ step "#create_tmpdir_on operates on all hosts if given a hosts array" do
61
+ tmpdirs = create_tmpdir_on hosts
62
+ hosts.zip(tmpdirs).each do |(host, tmpdir)|
63
+ assert_match %r{/}, tmpdir
64
+ assert_equal 0, on(host, "touch #{tmpdir}/testfile").exit_code
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,48 @@
1
+ require "helpers/test_helper"
2
+
3
+ # construct an appropriate local file URL for curl testing
4
+ def host_local_url(host, path)
5
+ if host.is_cygwin?
6
+ "file://#{path.gsub('/', '\\\\\\\\')}"
7
+ else
8
+ "file://#{path}"
9
+ end
10
+ end
11
+
12
+ test_name "dsl::helpers::host_helpers #curl_on" do
13
+ step "#curl_on fails if the URL in question cannot be reached" do
14
+ assert Beaker::Host::CommandFailure do
15
+ curl_on default, "file:///non/existent.html"
16
+ end
17
+ end
18
+
19
+ step "#curl_on can retrieve the contents of a URL, using standard curl options" do
20
+ remote_tmpdir = tmpdir_on default
21
+ remote_filename, contents = create_remote_file_from_fixture("simple_text_file", default, remote_tmpdir, "testfile.txt")
22
+ remote_targetfilename = File.join remote_tmpdir, "outfile.txt"
23
+
24
+ result = curl_on default, "-o #{remote_targetfilename} #{host_local_url default, remote_filename}"
25
+
26
+ assert_equal 0, result.exit_code
27
+ remote_contents = on(default, "cat #{remote_targetfilename}").stdout
28
+ assert_equal contents, remote_contents
29
+ end
30
+
31
+ step "#curl_on can retrieve the contents of a URL, when given a hosts array" do
32
+ remote_tmpdir = tmpdir_on default
33
+ on hosts, "mkdir -p #{remote_tmpdir}"
34
+
35
+ remote_filename = contents = nil
36
+ hosts.each do |host|
37
+ remote_filename, contents = create_remote_file_from_fixture("simple_text_file", host, remote_tmpdir, "testfile.txt")
38
+ end
39
+ remote_targetfilename = File.join remote_tmpdir, "outfile.txt"
40
+
41
+ result = curl_on hosts, "-o #{remote_targetfilename} #{host_local_url default, remote_filename}"
42
+
43
+ hosts.each do |host|
44
+ remote_contents = on(host, "cat #{remote_targetfilename}").stdout
45
+ assert_equal contents, remote_contents
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ require "helpers/test_helper"
2
+
3
+ test_name "dsl::helpers::host_helpers #curl_with_retries" do
4
+
5
+ step "#curl_with_retries CURRENTLY fails with a RuntimeError if retries are exhausted without fetching the specified URL" do
6
+ # NOTE: would expect that this would raise Beaker::Host::CommandFailure
7
+
8
+ assert_raises RuntimeError do
9
+ curl_with_retries \
10
+ "description",
11
+ default,
12
+ "file:///non/existent.html",
13
+ desired_exit_codes = [0],
14
+ max_retries = 2,
15
+ retry_interval = 0.01
16
+ end
17
+ end
18
+
19
+ step "#curl_with_retries retrieves the contents of a URL after retrying" do
20
+ # TODO: testing curl_with_retries relies on having a portable means of
21
+ # making an unavailable URL available after a period of time.
22
+ end
23
+
24
+ step "#curl_with_retries can retrieve the contents of a URL after retrying, when given a hosts array" do
25
+ # TODO: testing curl_with_retries relies on having a portable means of
26
+ # making an unavailable URL available after a period of time.
27
+ end
28
+ end
@@ -0,0 +1,142 @@
1
+ require "helpers/test_helper"
2
+ require "fileutils"
3
+
4
+ test_name "dsl::helpers::host_helpers #deploy_package_repo" do
5
+
6
+ confine_block :to, :platform => /^el-4/ do
7
+
8
+ step "#deploy_package_repo CURRENTLY does nothing and throws no error on the #{default['platform']} platform" do
9
+ # NOTE: would expect this to fail with Beaker::Host::CommandFailure
10
+
11
+ Dir.mktmpdir do |local_dir|
12
+ name = "puppet-server"
13
+ version = "9.9.9"
14
+ platform = default['platform']
15
+
16
+ local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "pl-#{name}-#{version}-repos-pe-#{platform}.repo")
17
+
18
+ assert_nil deploy_package_repo(default, local_dir, name, version)
19
+ end
20
+ end
21
+ end
22
+
23
+ confine_block :to, :platform => /fedora|centos|eos|el-[56789]/i do
24
+
25
+ step "#deploy_package_repo pushes repo package to /etc/yum.repos.d on the remote host" do
26
+ Dir.mktmpdir do |local_dir|
27
+ name = "puppet-server"
28
+ version = "9.9.9"
29
+ platform = default['platform']
30
+
31
+ FileUtils.mkdir(File.join(local_dir, "rpm"))
32
+ local_filename, contents = create_local_file_from_fixture("simple_text_file", File.join(local_dir, "rpm"), "pl-#{name}-#{version}-repos-pe-#{platform}.repo")
33
+
34
+ deploy_package_repo default, local_dir, name, version
35
+
36
+ remote_contents = on(default, "cat /etc/yum.repos.d/#{name}.repo").stdout
37
+ assert_equal contents, remote_contents
38
+
39
+ # teardown
40
+ on default, "rm /etc/yum.repos.d/#{name}.repo"
41
+ end
42
+ end
43
+
44
+ step "#deploy_package_repo CURRENTLY fails with NoMethodError when passed a hosts array" do
45
+ # NOTE: would expect this to handle host arrays, or raise Beaker::Host::CommandFailure
46
+
47
+ Dir.mktmpdir do |local_dir|
48
+ name = "puppet-server"
49
+ version = "9.9.9"
50
+ platform = default['platform']
51
+
52
+ local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "pl-#{name}-#{version}-repos-pe-#{platform}.repo")
53
+
54
+ assert_raises NoMethodError do
55
+ deploy_package_repo hosts, local_dir, name, version
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ confine_block :to, :platform => /ubuntu|debian|cumulus/i do
62
+
63
+ step "#deploy_package_repo pushes repo package to /etc/apt/sources.list.d on the remote host" do
64
+ Dir.mktmpdir do |local_dir|
65
+ name = "puppet-server"
66
+ version = "9.9.9"
67
+ codename = default['platform'].codename
68
+
69
+ FileUtils.mkdir(File.join(local_dir, "deb"))
70
+ local_filename, contents = create_local_file_from_fixture("simple_text_file", File.join(local_dir, "deb"), "pl-#{name}-#{version}-#{codename}.list")
71
+
72
+ deploy_package_repo default, local_dir, name, version
73
+
74
+ remote_contents = on(default, "cat /etc/apt/sources.list.d/#{name}.list").stdout
75
+ assert_equal contents, remote_contents
76
+
77
+ # teardown
78
+ on default, "rm /etc/apt/sources.list.d/#{name}.list"
79
+ end
80
+ end
81
+
82
+ step "#deploy_package_repo CURRENTLY fails with NoMethodError when passed a hosts array" do
83
+ # NOTE: would expect this to handle host arrays, or raise Beaker::Host::CommandFailure
84
+
85
+ Dir.mktmpdir do |local_dir|
86
+ name = "puppet-server"
87
+ version = "9.9.9"
88
+ codename = default['platform'].codename
89
+
90
+ FileUtils.mkdir(File.join(local_dir, "deb"))
91
+ local_filename, contents = create_local_file_from_fixture("simple_text_file", File.join(local_dir, "deb"), "pl-#{name}-#{version}-#{codename}.list")
92
+
93
+ assert_raises NoMethodError do
94
+ deploy_package_repo hosts, local_dir, name, version
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ confine_block :to, :platform => /sles/i do
101
+
102
+ step "#deploy_package_repo updates zypper repository list on the remote host" do
103
+ Dir.mktmpdir do |local_dir|
104
+ name = "puppet-server"
105
+ version = "9.9.9"
106
+ platform = default['platform']
107
+
108
+ FileUtils.mkdir(File.join(local_dir, "rpm"))
109
+ local_filename, contents = create_local_file_from_fixture("sles-11-x86_64.repo", File.join(local_dir, "rpm"), "pl-#{name}-#{version}-repos-pe-#{platform}.repo")
110
+
111
+ deploy_package_repo default, local_dir, name, version
112
+
113
+ result = on default, "zypper repos -d"
114
+ assert_match "PE-3.8-sles-11-x86_64", result.stdout
115
+
116
+ # teardown
117
+ on default, "zypper rr PE-3.8-sles-11-x86_64"
118
+ end
119
+ end
120
+ end
121
+
122
+ confine_block :except, :platform => /el-\d|fedora|centos|eos|ubuntu|debian|cumulus|sles/i do
123
+
124
+ # OS X, windows (cygwin, powershell), solaris, etc.
125
+
126
+ step "#deploy_package_repo CURRENTLY fails with a RuntimeError on on the #{default['platform']} platform" do
127
+ # NOTE: would expect this to raise Beaker::Host::CommandFailure instead of RuntimeError
128
+
129
+ Dir.mktmpdir do |local_dir|
130
+ name = "puppet-server"
131
+ version = "9.9.9"
132
+ platform = default['platform']
133
+
134
+ local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "pl-#{name}-#{version}-repos-pe-#{platform}.repo")
135
+
136
+ assert_raises RuntimeError do
137
+ deploy_package_repo default, local_dir, name, version
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,13 @@
1
+ require "helpers/test_helper"
2
+
3
+ test_name "dsl::helpers::host_helpers #echo_on" do
4
+ step "#echo_on echoes the supplied string on the remote host" do
5
+ output = echo_on(default, "contents")
6
+ assert_equal output, "contents"
7
+ end
8
+
9
+ step "#echo_on echoes the supplied string on all hosts when given a hosts array" do
10
+ results = echo_on(hosts, "contents")
11
+ assert_equal ["contents"] * hosts.size, results
12
+ end
13
+ end
@@ -0,0 +1,67 @@
1
+ require "helpers/test_helper"
2
+
3
+ test_name "dsl::helpers::host_helpers #install_package" do
4
+ # NOTE: vivid packages are not ready on nightlies.puppetlabs.com,
5
+ # see: https://tickets.puppetlabs.com/browse/CPR-173
6
+ # also: https://tickets.puppetlabs.com/browse/BKR-513
7
+ confine :except, :platform => /ubuntu.*15/
8
+
9
+ # NOTE: there does not appear to be a way to confine just to cygwin hosts
10
+ confine_block :to, :platform => /windows/ do
11
+
12
+ # NOTE: install_package on windows currently fails as follows:
13
+ #
14
+ # ArgumentError: wrong number of arguments (3 for 1..2)
15
+ #
16
+ # Would expect this to be documented better, and to fail with Beaker::Host::CommandFailure
17
+
18
+ step "#install_package CURRENTLY fails on windows platforms" do
19
+ assert_raises ArgumentError do
20
+ install_package default, "rsync"
21
+ end
22
+ end
23
+ end
24
+
25
+ confine_block :to, :platform => /solaris/ do
26
+
27
+ step "#install_package CURRENTLY fails on solaris platforms" do
28
+ assert_raises Beaker::Host::CommandFailure do
29
+ install_package default, "rsync"
30
+ end
31
+ end
32
+ end
33
+
34
+ confine_block :to, :platform => /osx/ do
35
+ # TODO: install_package on OSX installs via a .dmg file -- how to test this?
36
+ end
37
+
38
+ confine_block :except, :platform => /windows|solaris|osx/ do
39
+
40
+ step "#install_package fails if package is not known on the OS" do
41
+ assert_raises Beaker::Host::CommandFailure do
42
+ install_package default, "non-existent-package-name"
43
+ end
44
+ end
45
+
46
+ step "#install_package installs a known package successfully" do
47
+ result = install_package default, "rsync"
48
+ assert check_for_package(default, "rsync"), "package was not successfully installed"
49
+ end
50
+
51
+ step "#install_package succeeds when installing an already-installed package" do
52
+ result = install_package default, "rsync"
53
+ result = install_package default, "rsync"
54
+ assert check_for_package(default, "rsync"), "package was not successfully installed"
55
+ end
56
+
57
+ step "#install_package CURRENTLY fails if given a host array" do
58
+ # NOTE: would expect this to work across hosts, or to be better
59
+ # documented. If not supported, should raise
60
+ # Beaker::Host::CommandFailure
61
+
62
+ assert_raises NoMethodError do
63
+ install_package hosts, "rsync"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,109 @@
1
+ require "helpers/test_helper"
2
+
3
+ test_name "dsl::helpers::host_helpers #on" do
4
+
5
+ step "#on raises an exception when remote command fails" do
6
+ assert_raises(Beaker::Host::CommandFailure) do
7
+ on default, "/bin/nonexistent-command"
8
+ end
9
+ end
10
+
11
+ step "#on makes command output available via `.stdout` on success" do
12
+ output = on(default, %Q{echo "echo via on"}).stdout
13
+ assert_equal "echo via on\n", output
14
+ end
15
+
16
+ step "#on makes command error output available via `.stderr` on success" do
17
+ output = on(default, "/bin/nonexistent-command", :acceptable_exit_codes => [0, 127]).stderr
18
+ assert_match /No such file/, output
19
+ end
20
+
21
+ step "#on makes exit status available via `.exit_code`" do
22
+ status = on(default, %Q{echo "echo via on"}).exit_code
23
+ assert_equal 0, status
24
+ end
25
+
26
+ step "#on with :acceptable_exit_codes will not fail for named exit codes" do
27
+ result = on default, "/bin/nonexistent-command", :acceptable_exit_codes => [0, 127]
28
+ output = result.stderr
29
+ assert_match /No such file/, output
30
+ status = result.exit_code
31
+ assert_equal 127, status
32
+ end
33
+
34
+ step "#on with :acceptable_exit_codes will fail for other exit codes" do
35
+ assert_raises(Beaker::Host::CommandFailure) do
36
+ on default, %Q{echo "echo via on"}, :acceptable_exit_codes => [127]
37
+ end
38
+ end
39
+
40
+ step "#on will pass :environment options to the remote host as ENV settings" do
41
+ result = on default, "env", { :environment => { 'FOO' => 'bar' } }
42
+ output = result.stdout
43
+
44
+ assert_match /\bFOO=bar\b/, output
45
+ end
46
+
47
+ step "#on runs command on all hosts when given a host array" do
48
+ # Run a command which is (basically) guaranteed to have distinct output
49
+ # on every host, and only requires bash to be present to run on any of
50
+ # our platforms.
51
+ results = on hosts, %Q{echo "${RANDOM}:${RANDOM}:${RANDOM}"}
52
+
53
+ # assert that we got results back for every host
54
+ assert_equal hosts.size, results.size
55
+
56
+ # that they were all successful runs
57
+ results.each do |result|
58
+ assert_equal 0, result.exit_code
59
+ end
60
+
61
+ # and that we have |hosts| distinct outputs
62
+ unique_outputs = results.map(&:output).uniq
63
+ assert_equal hosts.size, unique_outputs.size
64
+ end
65
+
66
+ step "#on runs command on all hosts matching a role, when given a symbol" do
67
+ # Run a command which is (basically) guaranteed to have distinct output
68
+ # on every host, and only requires bash to be present to run on any of
69
+ # our platforms.
70
+ results = on :agent, %Q{echo "${RANDOM}:${RANDOM}:${RANDOM}"}
71
+
72
+ # assert that we got results back for every host
73
+ assert_equal hosts.size, results.size
74
+
75
+ # that they were all successful runs
76
+ results.each do |result|
77
+ assert_equal 0, result.exit_code
78
+ end
79
+
80
+ # and that we have |hosts| distinct outputs
81
+ unique_outputs = results.map(&:output).uniq
82
+ assert_equal hosts.size, unique_outputs.size
83
+ end
84
+
85
+ step "#on runs command on all hosts matching a role, when given a string" do
86
+ # Run a command which is (basically) guaranteed to have distinct output
87
+ # on every host, and only requires bash to be present to run on any of
88
+ # our platforms.
89
+ results = on "agent", %Q{echo "${RANDOM}:${RANDOM}:${RANDOM}"}
90
+
91
+ # assert that we got results back for every host
92
+ assert_equal hosts.size, results.size
93
+
94
+ # that they were all successful runs
95
+ results.each do |result|
96
+ assert_equal 0, result.exit_code
97
+ end
98
+
99
+ # and that we have |hosts| distinct outputs
100
+ unique_outputs = results.map(&:output).uniq
101
+ assert_equal hosts.size, unique_outputs.size
102
+ end
103
+
104
+ step "#on allows assertions to be used in the optional block" do
105
+ on hosts, %Q{echo "${RANDOM}:${RANDOM}"} do
106
+ assert_match /\d+:\d+/, stdout
107
+ end
108
+ end
109
+ end