repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_manage_attributes_aix.rb | acceptance/tests/resource/user/should_manage_attributes_aix.rb | test_name "should correctly manage the attributes property for the User resource (AIX only)" do
confine :to, :platform => /aix/
tag 'audit:high',
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
require 'puppet/acceptance/aix_util'
extend Puppet::Acceptance::AixUtil
initial_attributes = {
'nofiles' => 10000,
'fsize' => 100000,
'data' => 60000,
}
changed_attributes = {
'nofiles' => -1,
'data' => 40000
}
run_attribute_management_tests('user', :uid, initial_attributes, changed_attributes)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_modify_gid.rb | acceptance/tests/resource/user/should_modify_gid.rb | test_name "verify that we can modify the gid"
confine :except, :platform => 'windows'
confine :except, :platform => /aix/ # PUP-5358
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
user = "u#{rand(99999).to_i}"
group1 = "#{user}o"
group2 = "#{user}n"
agents.each do |host|
step "ensure that the groups both exist"
on(host, puppet_resource('group', group1, 'ensure=present'))
on(host, puppet_resource('group', group2, 'ensure=present'))
step "ensure the user exists and has the old group"
on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group1}"))
step "verify that the user has the correct gid"
group_gid1 = host.group_gid(group1)
host.user_get(user) do |result|
user_gid1 = result.stdout.split(':')[3]
fail_test "didn't have the expected old GID #{group_gid1}, but got: #{user_gid1}" unless group_gid1 == user_gid1
end
step "modify the GID of the user"
on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group2}"))
step "verify that the user has the updated gid"
group_gid2 = host.group_gid(group2)
host.user_get(user) do |result|
user_gid2 = result.stdout.split(':')[3]
fail_test "didn't have the expected old GID #{group_gid}, but got: #{user_gid2}" unless group_gid2 == user_gid2
end
step "ensure that we remove the things we made"
on(host, puppet_resource('user', user, 'ensure=absent'))
on(host, puppet_resource('group', group1, 'ensure=absent'))
on(host, puppet_resource('group', group2, 'ensure=absent'))
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_not_create_existing.rb | acceptance/tests/resource/user/should_not_create_existing.rb | test_name "tests that user resource will not add users that already exist." do
tag 'audit:high',
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
user = "u#{rand(999999).to_i}"
group = "g#{rand(999999).to_i}"
teardown do
agents.each do |agent|
agent.user_absent(user)
agent.group_absent(group)
end
end
step "Setup: Create test user and group" do
agents.each do |agent|
agent.user_present(user)
agent.group_present(group)
end
end
step "verify that we don't try to create a user account that already exists" do
agents.each do |agent|
on(agent, puppet_resource('user', user, 'ensure=present')) do |result|
fail_test "tried to create '#{user}' user" if result.stdout.include? 'created'
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_destroy.rb | acceptance/tests/resource/user/should_destroy.rb | test_name "should delete a user"
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
name = "pl#{rand(999999).to_i}"
agents.each do |agent|
step "ensure the user is present"
agent.user_present(name)
step "delete the user"
on agent, puppet_resource('user', name, 'ensure=absent')
step "verify the user was deleted"
fail_test "User #{name} was not deleted" if agent.user_list.include? name
step "delete the user, if any"
agent.user_absent(name)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_not_destroy_unexisting.rb | acceptance/tests/resource/user/should_not_destroy_unexisting.rb | test_name "ensure that puppet does not report removing a user that does not exist"
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
name = "pl#{rand(999999).to_i}"
step "verify that user #{name} does not exist"
agents.each do |agent|
agent.user_absent(name)
end
step "ensure absent doesn't try and do anything"
on(agents, puppet_resource('user', name, 'ensure=absent')) do |result|
fail_test "tried to remove the user, apparently" if result.stdout.include? 'removed'
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_query_all.rb | acceptance/tests/resource/user/should_query_all.rb | test_name "should query all users"
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:integration'
agents.each do |agent|
next if agent == master
skip_test('this test fails on windows French due to Cygwin/UTF Issues - PUP-8319,IMAGES-492') if agent['platform'] =~ /windows/ && agent['locale'] == 'fr'
step "query natively"
users = agent.user_list
fail_test("No users found") unless users
step "query with puppet"
on(agent, puppet_resource('user')) do |result|
result.stdout.each_line do |line|
name = ( line.match(/^user \{ '([^']+)'/) or next )[1]
unless users.delete(name)
fail_test "user #{name} found by puppet, not natively"
end
end
end
if users.length > 0 then
fail_test "#{users.length} users found natively, not puppet: #{users.join(', ')}"
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_create_with_gid.rb | acceptance/tests/resource/user/should_create_with_gid.rb | test_name "verifies that puppet resource creates a user and assigns the correct group"
confine :except, :platform => 'windows'
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
user = "pl#{rand(999999).to_i}"
group = "gp#{rand(999999).to_i}"
agents.each do |host|
step "user should not exist"
host.user_absent(user)
step "group should exist"
host.group_present(group)
step "create user with group"
on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group}"))
step "verify the group exists and find the gid"
group_gid = host.group_gid(group)
step "verify that the user has that as their gid"
host.user_get(user) do |result|
if host['platform'] =~ /aix/
match = result.stdout.match(/pgrp=([^\s\\]+)/)
user_gid = match ? host.group_gid(match[1]) : nil
else
user_gid = result.stdout.split(':')[3]
end
fail_test "expected gid #{group_gid} but got: #{user_gid}" unless group_gid == user_gid
end
step "clean up after the test is done"
on(host, puppet_resource('user', user, 'ensure=absent'))
on(host, puppet_resource('group', group, 'ensure=absent'))
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_modify_when_not_managing_home.rb | acceptance/tests/resource/user/should_modify_when_not_managing_home.rb | test_name "should modify a user when no longer managing home (#20726)"
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
require 'puppet/acceptance/windows_utils'
extend Puppet::Acceptance::WindowsUtils
name = "pl#{rand(999999).to_i}"
pw = "Passwrd-#{rand(999999).to_i}"[0..11]
def get_home_dir(host, user_name)
home_dir = nil
on host, puppet_resource('user', user_name) do |result|
home_dir = result.stdout.match(/home\s*=>\s*'([^']+)'/m)[1]
end
home_dir
end
agents.each do |agent|
home_prop = nil
case agent['platform']
when /windows/
# Sadly Windows ADSI won't tell us the default home directory
# for a user. You can get it via WMI Win32_UserProfile, but that
# doesn't exist in a base 2003 install. So we simply specify an
# initial home directory, that matches what the default will be.
# This way we are guaranteed that `puppet resource user name`
# will include the home directory in its output.
home_prop = "home='#{profile_base(agent)}\\#{name}'"
when /solaris/
pending_test("managehome needs work on solaris")
when /osx/
skip_test("OSX doesn't support managehome")
# we don't get here
end
teardown do
step "delete the user"
agent.user_absent(name)
agent.group_absent(name)
end
step "ensure the user is present with managehome"
on agent, puppet_resource('user', name, ["ensure=present", "managehome=true", "password=#{pw}", home_prop].compact)
step "find the current home dir"
home_dir = get_home_dir(agent, name)
on agent, "test -d '#{home_dir}'"
step "modify the user"
new_home_dir = "#{home_dir}_foo"
on agent, puppet_resource('user', name, ["ensure=present", "home='#{new_home_dir}'"]) do |result|
found_home_dir = result.stdout.match(/home\s*=>\s*'([^']+)'/m)[1]
assert_equal new_home_dir, found_home_dir, "Failed to change home property of user"
end
step "verify that home directory still exists since we did not specify managehome"
on agent, "test -d '#{home_dir}'"
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_create_with_expiry_absent.rb | acceptance/tests/resource/user/should_create_with_expiry_absent.rb | test_name "verifies that puppet resource creates a user and assigns the correct expiry date when absent" do
confine :except, :platform => 'windows'
tag 'audit:high',
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
user = "pl#{rand(999999).to_i}"
teardown do
step "cleanup"
agents.each do |host|
on(host, puppet_resource('user', user, 'ensure=absent'))
end
end
agents.each do |host|
step "user should not exist"
on(host, puppet_resource('user', user, 'ensure=absent'), :acceptable_exit_codes => [0])
step "create user with expiry=absent"
on(host, puppet_resource('user', user, 'ensure=present', 'expiry=absent'), :acceptable_exit_codes => [0])
step "verify the user exists and expiry is not set (meaning never expire)"
on(host, puppet_resource('user', user)) do |result|
assert_match(/ensure.*=> 'present'/, result.stdout)
refute_match(/expiry.*=>/, result.stdout)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/osx_10.4_should_fail_when_modify_home.rb | acceptance/tests/resource/user/osx_10.4_should_fail_when_modify_home.rb | test_name "should not modify the home directory of an user on OS X >= 10.14" do
confine :to, :platform => /osx/
tag 'audit:high',
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::BeakerUtils
extend Puppet::Acceptance::ManifestUtils
user = "pl#{rand(999999).to_i}"
agents.each do |agent|
teardown do
agent.user_absent(user)
end
step "ensure the user is present" do
agent.user_present(user)
end
step "verify the error message is correct" do
expected_error = /OS X version [0-9\.]+ does not allow changing home using puppet/
user_manifest = resource_manifest('user', user, ensure: 'present', home: "/opt/#{user}")
apply_manifest_on(agent, user_manifest) do |result|
assert_match(
expected_error,
result.stderr,
"Puppet fails to report an error when changing home directory on OS X >= 10.14"
)
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_create.rb | acceptance/tests/resource/user/should_create.rb | test_name "should create a user"
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
name = "pl#{rand(999999).to_i}"
agents.each do |agent|
step "ensure the user and group do not exist"
agent.user_absent(name)
agent.group_absent(name)
step "create the user"
on agent, puppet_resource('user', name, 'ensure=present')
step "verify the user exists"
agent.user_get(name)
case agent['platform']
when /sles/, /solaris/, /windows/, /osx/, /aix/
# no private user groups by default
else
agent.group_get(name)
end
step "delete the user, and group, if any"
agent.user_absent(name)
agent.group_absent(name)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_create_modify_with_password.rb | acceptance/tests/resource/user/should_create_modify_with_password.rb | # frozen_string_literal: true
test_name 'should create a user with password and modify the password' do
tag 'audit:high',
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::ManifestUtils
name = "pl#{rand(999_999).to_i}"
initial_password = 'test1'
modified_password = 'test2'
agents.each do |agent|
teardown { agent.user_absent(name) }
step 'ensure the user does not exist' do
user_manifest = resource_manifest('user', name, { ensure: 'absent', provider: 'useradd' } )
apply_manifest_on(agent, user_manifest) do |result|
skip_test 'Useradd provider not present on this host' if result.stderr =~ /Provider useradd is not functional on this host/
end
end
step 'create the user with password' do
apply_manifest_on(agent, <<-MANIFEST, catch_failures: true)
user { '#{name}':
ensure => present,
password => '#{initial_password}',
}
MANIFEST
end
step 'verify the password was set correctly' do
on(agent, puppet('resource', 'user', name), acceptable_exit_codes: 0) do |result|
assert_match(/password\s*=>\s*'#{initial_password}'/, result.stdout, 'Password was not set correctly')
end
end
step 'modify the user with a different password' do
apply_manifest_on(agent, <<-MANIFEST, catch_failures: true)
user { '#{name}':
ensure => present,
password => '#{modified_password}',
}
MANIFEST
end
step 'verify the password was set correctly' do
on(agent, "puppet resource user #{name}", acceptable_exit_codes: 0) do |result|
assert_match(/password\s*=>\s*'#{modified_password}'/, result.stdout, 'Password was not changed correctly')
end
end
step 'Verify idempotency when setting the same password' do
apply_manifest_on(agent, <<-MANIFEST, expect_changes: false)
user { '#{name}':
ensure => present,
password => '#{modified_password}',
}
MANIFEST
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/osx_10.4_should_fail_when_modify_uid.rb | acceptance/tests/resource/user/osx_10.4_should_fail_when_modify_uid.rb | test_name "should not modify the uid of an user on OS X >= 10.14" do
confine :to, :platform => /osx/
tag 'audit:high',
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::BeakerUtils
extend Puppet::Acceptance::ManifestUtils
user = "pl#{rand(999999).to_i}"
agents.each do |agent|
teardown do
agent.user_absent(user)
end
step "ensure the user is present" do
agent.user_present(user)
end
step "verify the error message is correct" do
expected_error = /OS X version [0-9\.]+ does not allow changing uid using puppet/
user_manifest = resource_manifest('user', user, ensure: 'present', uid: rand(999999))
apply_manifest_on(agent, user_manifest) do |result|
assert_match(
expected_error,
result.stderr,
"Puppet fails to report an error when changing uid on OS X >= 10.14"
)
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_manage_shell.rb | acceptance/tests/resource/user/should_manage_shell.rb | test_name "should manage user shell"
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
name = "pl#{rand(999999).to_i}"
confine :except, :platform => 'windows'
agents.each do |agent|
step "ensure the user and group do not exist"
agent.user_absent(name)
agent.group_absent(name)
step "create the user with shell"
shell = '/bin/sh'
on agent, puppet_resource('user', name, ["ensure=present", "shell=#{shell}"])
step "verify the user shell matches the managed shell"
agent.user_get(name) do |result|
fail_test "didn't set the user shell for #{name}" unless result.stdout.include? shell
end
step "modify the user with shell"
# We need to use an allowed shell in AIX, as according to `/etc/security/login.cfg`
if agent['platform'] =~ /aix/
shell = '/bin/ksh'
else
shell = '/bin/bash'
end
on agent, puppet_resource('user', name, ["ensure=present", "shell=#{shell}"])
step "verify the user shell matches the managed shell"
agent.user_get(name) do |result|
fail_test "didn't set the user shell for #{name}" unless result.stdout.include? shell
end
step "delete the user, and group, if any"
agent.user_absent(name)
agent.group_absent(name)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/user/should_query.rb | acceptance/tests/resource/user/should_query.rb | test_name "test that we can query and find a user that exists."
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
name = "pl#{rand(999999).to_i}"
agents.each do |agent|
step "ensure that our test user exists"
agent.user_present(name)
step "query for the resource and verify it was found"
on(agent, puppet_resource('user', name)) do |result|
fail_test "didn't find the user #{name}" unless result.stdout.include? 'present'
end
step "clean up the user and group we added"
agent.user_absent(name)
agent.group_absent(name)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/should_run_command_as_user.rb | acceptance/tests/resource/exec/should_run_command_as_user.rb | test_name "The exec resource should be able to run commands as a different user" do
confine :except, :platform => 'windows'
tag 'audit:high',
'audit:acceptance'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::BeakerUtils
def random_username
"pl#{rand(999999).to_i}"
end
def exec_resource_manifest(params = {})
default_params = {
:logoutput => true,
:path => '/usr/bin:/usr/sbin:/bin:/sbin',
:command => 'echo Hello'
}
params = default_params.merge(params)
params_str = params.map do |param, value|
value_str = value.to_s
value_str = "'#{value_str}'" if value.is_a?(String)
" #{param} => #{value_str}"
end.join(",\n")
<<-MANIFEST
exec { 'run_test_command':
#{params_str}
}
MANIFEST
end
agents.each do |agent|
username = random_username
# Create our user. Ensure that we start with a clean slate.
agent.user_absent(username)
agent.user_present(username)
teardown { agent.user_absent(username) }
tmpdir = agent.tmpdir("forbidden")
on(agent, "chmod 700 #{tmpdir}")
step "Runs the command even when the user doesn't have permissions to access the pwd" do
# Can't use apply_manifest_on here because that does not take the :cwd
# as an option.
tmpfile = agent.tmpfile("exec_user_perms_manifest")
create_remote_file(agent, tmpfile, exec_resource_manifest(user: username))
on(agent, "cd #{tmpdir} && puppet apply #{tmpfile} --detailed-exitcodes", acceptable_exit_codes: [0, 2])
end
step "Runs the command even when the user doesn't have permission to access the specified cwd" do
apply_manifest_on(agent, exec_resource_manifest(user: username, cwd: tmpdir), catch_failures: true)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/should_run_command.rb | acceptance/tests/resource/exec/should_run_command.rb | test_name "tests that puppet correctly runs an exec."
# original author: Dan Bode --daniel 2010-12-23
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance'
def before(agent)
step "file to be touched should not exist."
agent.tmpfile('test-exec')
end
def after(agent, touched)
step "checking the output worked"
on agent, "test -f #{touched}"
step "clean up the system"
on agent, "rm -f #{touched}"
end
agents.each do |agent|
touched = before(agent)
apply_manifest_on(agent, "exec {'test': command=>'#{agent.touch(touched)}'}") do |result|
fail_test "didn't seem to run the command" unless
result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja'
end
after(agent, touched)
touched = before(agent)
on(agent, puppet_resource('-d', 'exec', 'test', "command='#{agent.touch(touched)}'}")) do |result|
fail_test "didn't seem to run the command" unless
result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja'
end
after(agent, touched)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/accept_array_commands.rb | acceptance/tests/resource/exec/accept_array_commands.rb | test_name "Be able to execute array commands" do
tag 'audit:high',
'audit:acceptance'
agents.each do |agent|
if agent.platform =~ /windows/
cmd = ['C:\Windows\System32\cmd.exe', '/c', 'echo', '*']
else
cmd = ['/bin/echo', '*']
end
exec_manifest = <<~MANIFEST
exec { "test exec":
command => #{cmd},
logoutput => true,
}
MANIFEST
apply_manifest_on(agent, exec_manifest) do |output|
assert_match('Notice: /Stage[main]/Main/Exec[test exec]/returns: *', output.stdout)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/should_set_environment_variables.rb | acceptance/tests/resource/exec/should_set_environment_variables.rb | test_name "The Exec resource should set user-specified environment variables" do
tag 'audit:high',
'audit:acceptance'
# Would be nice to parse the actual values from puppet_output,
# but that would require some complicated matching since
# puppet_output contains other stuff.
def assert_env_var_values(puppet_output, expected_values)
expected_values.each do |env_var, value|
assert_match(/#{env_var}=#{value}/, puppet_output, "Expected '#{env_var}=#{value}' to be printed as part of the output!")
end
end
agents.each do |agent|
# Calculate some top-level variables/functions we
# will need for our tests.
unless agent.platform =~ /windows/
path = '/usr/bin:/usr/sbin:/bin:/sbin'
print_env_vars = lambda do |*env_vars|
env_vars_str = env_vars.map do |env_var|
"#{env_var}=$#{env_var}"
end.join(" ")
"echo #{env_vars_str}"
end
else
# Powershell's directory is dependent on what version of Powershell is
# installed on the system (e.g. v1.0, v2.0), so we need to programmatically
# calculate the executable's directory to add to our PATH variable.
powershell_path = on(agent, "cmd.exe /c where powershell.exe").stdout.chomp
*powershell_dir, _ = powershell_path.split('\\')
powershell_dir = powershell_dir.join('\\')
path = "C:\Windows\System32;#{powershell_dir}"
print_env_vars = lambda do |*env_vars|
env_vars_str = env_vars.map do |env_var|
"#{env_var}=$env:#{env_var}"
end
"powershell.exe \"Write-Host -NoNewLine #{env_vars_str}\""
end
end
# Easier to read than a def. The def. would require us
# to specify the host as a param. in order to get the path
# and print_cwd command, which is unnecessary clutter.
exec_resource_manifest = lambda do |params = {}|
default_params = {
:logoutput => true,
:path => path
}
params = default_params.merge(params)
params_str = params.map do |param, value|
value_str = value.to_s
# Single quote the strings in case our value is a Windows
# path
value_str = "'#{value_str}'" if value.is_a?(String)
" #{param} => #{value_str}"
end.join(",\n")
<<-MANIFEST
exec { 'run_test_command':
#{params_str}
}
MANIFEST
end
step 'Passes the user-specified environment variables into the command' do
manifest = exec_resource_manifest.call(
command: print_env_vars.call('ENV_VAR_ONE', 'ENV_VAR_TWO'),
environment: ['ENV_VAR_ONE=VALUE_ONE', 'ENV_VAR_TWO=VALUE_TWO']
)
apply_manifest_on(agent, manifest) do |result|
assert_env_var_values(result.stdout, ENV_VAR_ONE: 'VALUE_ONE', ENV_VAR_TWO: 'VALUE_TWO')
end
end
step "Temporarily overrides previously set environment variables" do
manifest = exec_resource_manifest.call(
command: print_env_vars.call('ENV_VAR_ONE'),
environment: ['ENV_VAR_ONE=VALUE_OVERRIDE']
)
apply_manifest_on(agent, manifest, environment: { 'ENV_VAR_ONE' => 'VALUE' }) do |result|
assert_env_var_values(result.stdout, ENV_VAR_ONE: 'VALUE_OVERRIDE')
end
end
step "Temporarily overrides previously set environment variables even if the passed-in value is empty" do
manifest = exec_resource_manifest.call(
command: print_env_vars.call('ENV_VAR_ONE'),
environment: ['ENV_VAR_ONE=']
)
apply_manifest_on(agent, manifest, environment: { 'ENV_VAR_ONE' => 'VALUE' }) do |result|
assert_env_var_values(result.stdout, ENV_VAR_ONE: '')
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/should_run_command_in_cwd.rb | acceptance/tests/resource/exec/should_run_command_in_cwd.rb | test_name "The Exec resource should run commands in the specified cwd" do
tag 'audit:high',
'audit:acceptance'
confine :except, :platform => /debian-12-amd64/ # PUP-12020
require 'puppet/acceptance/windows_utils'
extend Puppet::Acceptance::WindowsUtils
# Useful utility that converts a string literal
# to a regex. We do a lot of assertions on file
# paths here that we need to escape, so this is
# a nice way of making the code more readable.
def to_regex(str)
Regexp.new(Regexp.escape(str))
end
def exec_resource_manifest(command, params = {})
default_params = {
:command => command
}
params = default_params.merge(params)
params_str = params.map do |param, value|
value_str = value.to_s
# Single quote the strings in case our value is a Windows
# path
value_str = "'#{value_str}'" if value.is_a?(String)
" #{param} => #{value_str}"
end.join(",\n")
<<-MANIFEST
exec { 'run_test_command':
#{params_str}
}
MANIFEST
end
def assert_file_on(host, filepath, failure_comment)
if host.platform =~ /windows/
cmd = "cmd.exe /c \"type #{filepath.gsub('/', '\\')}\""
else
cmd = "test -f #{filepath}"
end
on(host, cmd, :acceptable_exit_codes => [0, 1]) do |result|
assert_equal(0, result.exit_code, failure_comment)
end
end
agents.each do |agent|
testdir = agent.tmpdir("mock_testdir")
if agent.platform =~ /windows/
path = 'C:\Windows\System32'
echo_to = 'cmd.exe /c echo testing >'
cat = 'cmd.exe /c type'
non_existant_dir = 'C:\does_not_exist'
origin_working_dir = on(agent, 'cmd.exe /c echo %CD%').stdout.chomp
else
path = '/usr/bin:/usr/sbin:/bin:/sbin'
echo_to = 'echo testing >'
cat = 'cat'
non_existant_dir = '/does_not_exist'
origin_working_dir = on(agent, 'pwd').stdout.chomp
end
step "clean current working directory" do
on(agent, "rm -f cwd_test*")
end
step "Defaults to the current directory if the CWD option is not provided" do
apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test1", {:path => path}), :catch_failures => true)
assert_file_on(agent, File.join(origin_working_dir, 'cwd_test1'), 'Exec did not create file in origin pwd, exec resource not defaulting to pwd when no :cwd option is given')
end
step "Runs the command in the user specified CWD" do
apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test2", {:cwd => testdir, :path => path}), :catch_failures => true)
assert_file_on(agent, File.join(testdir, 'cwd_test2'), 'Exec did not create file in test directory, exec resource not using :cwd given')
end
step "Errors if the user specified CWD does not exist" do
apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test3", {cwd: non_existant_dir, :path => path}), :expect_failures => true) do |result|
assert_equal(4, result.exit_code, "Exec manifest still executed with non-existant :cwd")
end
end
# "onlyif" testing will require some form of runnable test in the testdir for the
# onlyif clause to actually execute. The runnable test we will use is attempting to
# 'cat' an unqualified file that will only exist in the testdir
create_remote_file(agent, File.join(testdir, 'testdir_onlyif.txt'), 'testing')
step 'Runs a "check" command (:onlyif or :unless) in the user specified CWD' do
apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test4", {cwd: testdir, :path => path, :onlyif => "#{cat} testdir_onlyif.txt"}), :expect_changes => true)
assert_file_on(agent, File.join(testdir, 'cwd_test4'), 'Exec did not create file in test directory, exec resource not using :cwd given')
end
step 'Does not run the exec if the "check" command (:onlyif or :unless) fails' do
apply_manifest_on(agent, exec_resource_manifest("#{echo_to} cwd_test5", {cwd: testdir, :path => path, :onlyif => "foobar"}), :expect_failures => true) do |result|
assert_equal(4, result.exit_code, "Exec manifest still executed with failed :onlyif clause")
end
end
tmpdir_noaccess = agent.tmpdir("mock_dir")
create_remote_file(agent, File.join(tmpdir_noaccess, 'noaccess.txt'), 'foobar')
username = "pl#{rand(999999).to_i}"
# The next two steps set up to test running with a CWD that the user does not have access to.
# The setup for the test creates 1. a new user and 2. a new directory that the new user does
# not have access to.
step "Setup user for 'no access' test" do
agent.user_present(username)
if agent.platform =~ /solaris/
# for some reason applications of 'user_present' on solaris 10 don't manage the homedir correctly, so just
# force a puppet apply to manage the user
on agent, puppet_resource('user', username, "ensure=present managehome=true home=/export/home/#{username}")
# we need to create the user directory ourselves in order for solaris users to successfully login
on(agent, "mkdir /export/home/#{username} && chown -R #{username} /export/home/#{username}")
elsif agent.platform =~ /osx/
# we need to create the user directory ourselves in order for macos users to successfully login
on(agent, "mkdir /Users/#{username} && chown -R #{username}:80 /Users/#{username}")
elsif agent.platform =~ /debian|ubuntu|sles/
# we need to create the user directory ourselves in order for deb users to successfully login
on(agent, "mkdir /home/#{username} && chown -R #{username} /home/#{username}")
end
teardown { agent.user_absent(username) }
end
tmpdir_noaccess = agent.tmpdir("mock_noaccess")
create_remote_file(agent, File.join(tmpdir_noaccess, 'noaccess.txt'), 'foobar')
step "Setup restricted access directory for 'no access' test" do
if agent.platform =~ /windows/
deny_administrator_access_to(agent, tmpdir_noaccess)
deny_administrator_access_to(agent, File.join(tmpdir_noaccess, 'noaccess.txt'))
else
if agent.platform =~ /osx/
# This is a little nuts, but on MacOS the tmpdir returned from agent.tmpdir is located in
# a directory that users other than root can't even access, i.e. other users won't have access
# to either the noaccess dir itself (which we want) _or the tmpdir root it's located in_. This is
# a problem since it will look to puppet like the noacceess dir doesn't exist at all, and so we
# can't count on any reliaable failure since we want a return indicating no access, not a missing directory.
#
# To get around this for MacOS platforms we simply use the new user's homedir as the 'tmpdir' and
# put the noaccess dir there.
on(agent, "mkdir /Users/#{username}/noaccess_test && cp #{tmpdir_noaccess}/noaccess.txt /Users/#{username}/noaccess_test && chmod -R 600 /Users/#{username}/noaccess_test")
tmpdir_noaccess = "/Users/#{username}/noaccess_test"
end
# remove permissions for all other users other than root, which should force puppet to fail when running as another user
on(agent, "chmod -R 600 #{tmpdir_noaccess}")
end
end
step "Errors if the user does not have access to the specified CWD" do
manifest_path = agent.tmpfile('apply_manifest.pp')
create_remote_file(agent, manifest_path, exec_resource_manifest("#{cat} noaccess.txt", {:cwd => tmpdir_noaccess, :path => path}))
if agent.platform =~ /windows/
on(agent, "cmd.exe /c \"puppet apply #{manifest_path} --detailed-exitcodes\"", :acceptable_exit_codes => [4]) do |result|
assert_equal(4, result.exit_code, "Exec manifest still executed inside restricted directory", )
end
elsif agent.platform =~ /osx/
# on MacOS we need to copy the manifest to run to the user's home dir and give the user ownership. otherwise puppet won't run on it.
on(agent, "cp #{manifest_path} /Users/#{username}/noaccess_manifest.pp && chown #{username}:80 /Users/#{username}/noaccess_manifest.pp")
on(agent, "su - #{username} -c \"/opt/puppetlabs/bin/puppet apply /Users/#{username}/noaccess_manifest.pp --detailed-exitcodes\"", :acceptable_exit_codes => [4]) do |result|
assert_equal(4, result.exit_code, "Exec manifest still executed inside restricted directory")
end
else
on(agent, "chown #{username} #{manifest_path}")
if agent.platform =~ /solaris|aix/
on(agent, "su - #{username} -c \"/opt/puppetlabs/bin/puppet apply #{manifest_path} --detailed-exitcodes\"", :acceptable_exit_codes => [4]) do |result|
assert_equal(4, result.exit_code, "Exec manifest still executed inside restricted directory")
end
else
on(agent, "su #{username} -c \"/opt/puppetlabs/bin/puppet apply #{manifest_path} --detailed-exitcodes\"", :acceptable_exit_codes => [4]) do |result|
assert_equal(4, result.exit_code, "Exec manifest still executed inside restricted directory")
end
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/accept_multi-line_commands.rb | acceptance/tests/resource/exec/accept_multi-line_commands.rb | test_name "Be able to execute multi-line commands (#9996)"
confine :except, :platform => 'windows'
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance'
agents.each do |agent|
temp_file_name = agent.tmpfile('9996-multi-line-commands')
test_manifest = <<HERE
exec { "test exec":
command => "/bin/echo '#Test' > #{temp_file_name};
/bin/echo 'bob' >> #{temp_file_name};"
}
HERE
expected_results = <<HERE
#Test
bob
HERE
on(agent, "rm -f #{temp_file_name}")
apply_manifest_on agent, test_manifest
on(agent, "cat #{temp_file_name}") do |result|
assert_equal(expected_results, result.stdout, "Unexpected result for host '#{agent}'")
end
on(agent, "rm -f #{temp_file_name}")
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/should_not_run_command_creates.rb | acceptance/tests/resource/exec/should_not_run_command_creates.rb | test_name "should not run command creates"
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance'
agents.each do |agent|
touch = agent.tmpfile('touched')
donottouch = agent.tmpfile('not-touched')
manifest = %Q{
exec { "test#{Time.new.to_i}": command => '#{agent.touch(donottouch)}', creates => "#{touch}"}
}
step "prepare the agents for the test"
on agent, "touch #{touch} && rm -f #{donottouch}"
step "test using puppet apply"
apply_manifest_on(agent, manifest) do |result|
fail_test "looks like the thing executed, which it shouldn't" if
result.stdout.include? 'executed successfully'
end
step "verify the file didn't get created"
on agent, "test -f #{donottouch}", :acceptable_exit_codes => [1]
step "prepare the agents for the second part of the test"
on agent, "touch #{touch} ; rm -f #{donottouch}"
step "test using puppet resource"
on(agent, puppet_resource('exec', "test#{Time.new.to_i}",
"command='#{agent.touch(donottouch)}'",
"creates='#{touch}'")) do |result|
fail_test "looks like the thing executed, which it shouldn't" if
result.stdout.include? 'executed successfully'
end
step "verify the file didn't get created the second time"
on agent, "test -f #{donottouch}", :acceptable_exit_codes => [1]
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/should_run_bad_command.rb | acceptance/tests/resource/exec/should_run_bad_command.rb | test_name "tests that puppet can run badly written scripts that fork and inherit descriptors"
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance'
def sleepy_daemon_script(agent)
if agent['platform'] =~ /win/
# Windows uses a shorter sleep, because it's expected to wait until the end.
return <<INITSCRIPT
echo hello
start /b ping.exe 127.0.0.1 -n 1
INITSCRIPT
else
return <<INITSCRIPT
echo hello
/bin/sleep 60 &
INITSCRIPT
end
end
# TODO: taken from pxp-agent, find common home
def stop_sleep_process(targets, accept_no_pid_found = false)
targets = [targets].flatten
targets.each do |target|
case target['platform']
when /osx/
command = "ps -e -o pid,comm | grep sleep | sed 's/^[^0-9]*//g' | cut -d\\ -f1"
when /win/
command = "cmd.exe /C WMIC path win32_process WHERE Name=\\\"PING.EXE\\\" get ProcessId | egrep -o '[0-9]+\\s*$'"
else
command = "ps -ef | grep 'bin/sleep ' | grep -v 'grep' | grep -v 'true' | sed 's/^[^0-9]*//g' | cut -d\\ -f1"
end
# A failed test may leave an orphaned sleep process, handle multiple matches.
pids = nil
on(target, command, accept_all_exit_codes: accept_no_pid_found) do |output|
pids = output.stdout.chomp.split
if pids.empty? && !accept_no_pid_found
raise("Did not find a pid for a sleep process on #{target}")
end
end
pids.each do |pid|
target['platform'] =~ /win/ ?
on(target, "taskkill /F /pid #{pid}") :
on(target, "kill -s TERM #{pid}")
end
end
end
teardown do
# On Windows, Puppet waits until the sleep process exits before exiting
stop_sleep_process(agents.select {|agent| agent['platform'] =~ /win/}, true)
# Requiring a sleep process asserts that Puppet exited before the sleep process.
stop_sleep_process(agents.reject {|agent| agent['platform'] =~ /win/})
end
agents.each do |agent|
ext = if agent['platform'] =~ /win/ then '.bat' else '' end
daemon = agent.tmpfile('sleepy_daemon') + ext
create_remote_file(agent, daemon, sleepy_daemon_script(agent))
on(agent, "chmod +x #{daemon}")
apply_manifest_on(agent, "exec {'#{daemon}': logoutput => true}") do |result|
fail_test "didn't seem to run the command" unless
result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja'
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/should_set_path.rb | acceptance/tests/resource/exec/should_set_path.rb | test_name "the path statement should work to locate commands"
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance'
agents.each do |agent|
file = agent.tmpfile('touched-should-set-path')
step "clean up the system for the test"
on agent, "rm -f #{file}"
step "invoke the exec resource with a path set"
on(agent, puppet_resource('exec', 'test',
"command='#{agent.touch(file, false)}'", "path='#{agent.path}'"))
step "verify that the files were created"
on agent, "test -f #{file}"
step "clean up the system after testing"
on agent, "rm -f #{file}"
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/exec/should_accept_large_output.rb | acceptance/tests/resource/exec/should_accept_large_output.rb | test_name "tests that puppet correctly captures large and empty output."
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance'
agents.each do |agent|
testfile = agent.tmpfile('should_accept_large_output')
# Generate >64KB file to exceed pipe buffer.
lorem_ipsum = <<EOF
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
EOF
create_remote_file(agent, testfile, lorem_ipsum*1024)
apply_manifest_on(agent, "exec {'cat #{testfile}': path => ['/bin', '/usr/bin', 'C:/cygwin32/bin', 'C:/cygwin64/bin', 'C:/cygwin/bin'], logoutput => true}") do |result|
fail_test "didn't seem to run the command" unless
result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja'
fail_test "didn't print output correctly" unless
result.stdout.lines.select {|line| line =~ /\/returns:/}.count == 4097
end
apply_manifest_on(agent, "exec {'echo': path => ['/bin', '/usr/bin', 'C:/cygwin32/bin', 'C:/cygwin64/bin', 'C:/cygwin/bin'], logoutput => true}") do |result|
fail_test "didn't seem to run the command" unless
result.stdout.include? 'executed successfully' unless agent['locale'] == 'ja'
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_manage_attributes_aix.rb | acceptance/tests/resource/group/should_manage_attributes_aix.rb | test_name "should correctly manage the attributes property for the Group (AIX only)" do
confine :to, :platform => /aix/
tag 'audit:high',
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
require 'puppet/acceptance/aix_util'
extend Puppet::Acceptance::AixUtil
initial_attributes = {
'admin' => true
}
changed_attributes = {
'admin' => false
}
run_attribute_management_tests('group', :gid, initial_attributes, changed_attributes)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_modify_gid.rb | acceptance/tests/resource/group/should_modify_gid.rb | test_name "should modify gid of existing group"
confine :except, :platform => 'windows'
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
name = "pl#{rand(999999).to_i}"
gid1 = (rand(989999).to_i + 10000)
gid2 = (rand(989999).to_i + 10000)
agents.each do |agent|
# AIX group provider returns quoted gids
step "ensure that the group exists with gid #{gid1}"
on(agent, puppet_resource('group', name, 'ensure=present', "gid=#{gid1}")) do |result|
fail_test "missing gid notice" unless result.stdout =~ /gid +=> +'?#{gid1}'?/
end
step "ensure that we can modify the GID of the group to #{gid2}"
on(agent, puppet_resource('group', name, 'ensure=present', "gid=#{gid2}")) do |result|
fail_test "missing gid notice" unless result.stdout =~ /gid +=> +'?#{gid2}'?/
end
step "verify that the GID changed"
gid_output = agent.group_gid(name).to_i
fail_test "gid #{gid_output} does not match expected value of: #{gid2}" unless gid_output == gid2
step "clean up the system after the test run"
on(agent, puppet_resource('group', name, 'ensure=absent'))
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_not_create_existing.rb | acceptance/tests/resource/group/should_not_create_existing.rb | test_name "group should not create existing group"
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
name = "gr#{rand(999999).to_i}"
agents.each do |agent|
step "ensure the group exists on the target node"
agent.group_present(name)
step "verify that we don't try and create the existing group"
on(agent, puppet_resource('group', name, 'ensure=present')) do |result|
fail_test "looks like we created the group" if
result.stdout.include? "/Group[#{name}]/ensure: created"
end
step "clean up the system after the test run"
agent.group_absent(name)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_destroy.rb | acceptance/tests/resource/group/should_destroy.rb | test_name "should destroy a group"
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
name = "pl#{rand(999999).to_i}"
agents.each do |agent|
step "ensure the group is present"
agent.group_present(name)
step "delete the group"
on agent, puppet_resource('group', name, 'ensure=absent')
step "verify the group was deleted"
agent.group_absent(name)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_not_destroy_unexisting.rb | acceptance/tests/resource/group/should_not_destroy_unexisting.rb | test_name "should not destroy a group that doesn't exist"
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
name = "test-group-#{Time.new.to_i}"
step "verify the group does not already exist"
agents.each do |agent|
agent.group_absent(name)
end
step "verify that we don't remove the group when it doesn't exist"
on(agents, puppet_resource('group', name, 'ensure=absent')) do |result|
fail_test "it looks like we tried to remove the group" if
result.stdout.include? "/Group[#{name}]/ensure: removed"
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_query_all.rb | acceptance/tests/resource/group/should_query_all.rb | test_name "should query all groups"
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:integration' # Does not modify system running test
agents.each do |agent|
skip_test('this test fails on windows French due to Cygwin/UTF Issues - PUP-8319,IMAGES-492') if agent['platform'] =~ /windows/ && agent['locale'] == 'fr'
step "query natively"
groups = agent.group_list
fail_test("No groups found") unless groups
step "query with puppet"
on(agent, puppet_resource('group')) do |result|
result.stdout.each_line do |line|
name = ( line.match(/^group \{ '([^']+)'/) or next )[1]
unless groups.delete(name)
fail_test "group #{name} found by puppet, not natively"
end
end
end
if groups.length > 0 then
fail_test "#{groups.length} groups found natively, not puppet: #{groups.join(', ')}"
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_create.rb | acceptance/tests/resource/group/should_create.rb | test_name "should create a group"
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
name = "pl#{rand(999999).to_i}"
agents.each do |agent|
step "ensure the group does not exist"
agent.group_absent(name)
step "create the group"
on agent, puppet_resource('group', name, 'ensure=present')
step "verify the group exists"
agent.group_get(name)
step "delete the group"
agent.group_absent(name)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_manage_members.rb | acceptance/tests/resource/group/should_manage_members.rb | test_name "should correctly manage the members property for the Group resource" do
# These are the only platforms whose group providers manage the members
# property
confine :to, :platform => /windows|osx|aix|^el-|fedora/
tag 'audit:high',
'audit:acceptance' # Could be done as integration tests, but would
# require changing the system running the test
# in ways that might require special permissions
# or be harmful to the system running the test
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::BeakerUtils
def random_name
"pl#{rand(999999).to_i}"
end
def group_manifest(user, params)
params_str = params.map do |param, value|
value_str = value.to_s
value_str = "\"#{value_str}\"" if value.is_a?(String)
" #{param} => #{value_str}"
end.join(",\n")
<<-MANIFEST
group { '#{user}':
#{params_str}
}
MANIFEST
end
def members_of(host, group)
case host['platform']
when /windows/
# More verbose than 'net localgroup <group>', but more programmatic
# because it does not require us to parse stdout
get_group_members = <<-PS1
# Adapted from https://github.com/RamblingCookieMonster/PowerShell/blob/master/Get-ADGroupMembers.ps1
function Get-Members([string] $group) {
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName 'System.DirectoryServices.AccountManagement' -ErrorAction Stop
$contextType = [System.DirectoryServices.AccountManagement.ContextType]::Machine
$groupObject = [System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity(
$contextType,
$group
)
if (-Not $groupObject) {
throw "Could not find the group '$group'!"
}
$members = $groupObject.GetMembers($false) | ForEach-Object { "'$($_.Name)'" }
write-output "[$([string]::join(',', $members))]"
}
Get-Members #{group}
PS1
Kernel.eval(
execute_powershell_script_on(host, get_group_members).stdout.chomp
)
else
# This reads the group members from the /etc/group file
get_group_members = <<-RUBY
require 'etc'
group_struct = nil
Etc.group do |g|
if g.name == '#{group}'
group_struct = g
break
end
end
unless group_struct
raise "Could not find the group '#{group}'!"
end
puts(group_struct.mem.to_s)
RUBY
script_path = "#{host.tmpfile("get_group_members")}.rb"
create_remote_file(host, script_path, get_group_members)
# The setup step should have already set :privatebindir on the
# host. We only include the default here to make this routine
# work for local testing, which sometimes skips the setup step.
privatebindir = host.has_key?(:privatebindir) ? host[:privatebindir] : '/opt/puppetlabs/puppet/bin'
result = on(host, "#{privatebindir}/ruby #{script_path}")
Kernel.eval(result.stdout.chomp)
end
end
agents.each do |agent|
users = 6.times.collect { random_name }
users.each { |user| agent.user_absent(user) }
group = random_name
agent.group_absent(group)
teardown { agent.group_absent(group) }
step 'Creating the Users' do
users.each do |user|
agent.user_present(user)
teardown { agent.user_absent(user) }
end
end
group_members = [users[0], users[1]]
step 'Ensure that the group is created with the specified members' do
manifest = group_manifest(group, members: group_members)
apply_manifest_on(agent, manifest)
assert_matching_arrays(group_members, members_of(agent, group), "The group was not successfully created with the specified members!")
end
step "Verify that Puppet errors when one of the members does not exist" do
manifest = group_manifest(group, members: ['nonexistent_member'])
apply_manifest_on(agent, manifest, :acceptable_exit_codes => [0, 1]) do |result|
assert_match(/Error:.*#{group}/, result.stderr, "Puppet fails to report an error when one of the members in the members property does not exist")
end
end
step "Verify that Puppet noops when the group's members are already set after creating the group" do
manifest = group_manifest(group, members: group_members)
apply_manifest_on(agent, manifest, catch_changes: true)
assert_matching_arrays(group_members, members_of(agent, group), "The group's members somehow changed despite Puppet reporting a noop")
end
step "Verify that Puppet enforces minimum user membership when auth_membership == false" do
new_members = [users[2], users[4]]
manifest = group_manifest(group, members: new_members, auth_membership: false)
apply_manifest_on(agent, manifest)
group_members += new_members
assert_matching_arrays(group_members, members_of(agent, group), "Puppet fails to enforce minimum user membership when auth_membership == false")
end
step "Verify that Puppet noops when the group's members are already set after enforcing minimum user membership" do
manifest = group_manifest(group, members: group_members)
apply_manifest_on(agent, manifest, catch_changes: true)
assert_matching_arrays(group_members, members_of(agent, group), "The group's members somehow changed despite Puppet reporting a noop")
end
# Run some special, platform-specific tests. If these get too large, then
# we should consider placing them in a separate file.
case agent['platform']
when /windows/
domain = on(agent, 'hostname').stdout.chomp.upcase
step "(Windows) Verify that Puppet prints each group member as DOMAIN\\<user>" do
new_members = [users[3]]
manifest = group_manifest(group, members: new_members, auth_membership: false)
apply_manifest_on(agent, manifest) do |result|
group_members += new_members
stdout = result.stdout.chomp
group_members.each do |user|
assert_match(/#{domain}\\#{user}/, stdout, "Puppet fails to print the group member #{user} as #{domain}\\#{user}")
end
end
end
step "(Windows) Verify that `puppet resource` prints each group member as DOMAIN\\<user>" do
on(agent, puppet('resource', 'group', group)) do |result|
stdout = result.stdout.chomp
group_members.each do |user|
assert_match(/#{domain}\\#{user}/, stdout, "`puppet resource` fails to print the group member #{user} as #{domain}\\#{user}")
end
end
end
when /aix/
step "(AIX) Verify that Puppet accepts a comma-separated list of members for backwards compatibility" do
new_members = [users[3], users[5]]
manifest = group_manifest(group, members: new_members.join(','), auth_membership: false)
apply_manifest_on(agent, manifest)
group_members += new_members
assert_matching_arrays(group_members, members_of(agent, group), "Puppet cannot manage the members property when the members are provided as a comma-separated list")
end
end
step "Verify that Puppet enforces inclusive user membership when auth_membership == true" do
group_members = [users[0]]
manifest = group_manifest(group, members: group_members, auth_membership: true)
apply_manifest_on(agent, manifest)
assert_matching_arrays(group_members, members_of(agent, group), "Puppet fails to enforce inclusive group membership when auth_membership == true")
end
step "Verify that Puppet noops when the group's members are already set after enforcing inclusive user membership" do
manifest = group_manifest(group, members: group_members)
apply_manifest_on(agent, manifest, catch_changes: true)
assert_matching_arrays(group_members, members_of(agent, group), "The group's members somehow changed despite Puppet reporting a noop")
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/group/should_query.rb | acceptance/tests/resource/group/should_query.rb | test_name "test that we can query and find a group that exists."
tag 'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
name = "pl#{rand(999999).to_i}"
agents.each do |agent|
skip_test('this test fails on windows French due to Cygwin/UTF Issues - PUP-8319,IMAGES-492') if agent['platform'] =~ /windows/ && agent['locale'] == 'fr'
step "ensure that our test group exists"
agent.group_present(name)
step "query for the resource and verify it was found"
on(agent, puppet_resource('group', name)) do |result|
fail_test "didn't find the group #{name}" unless result.stdout.include? 'present'
end
step "clean up the group we added"
agent.group_absent(name)
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/yum.rb | acceptance/tests/resource/package/yum.rb | test_name "test the yum package provider" do
confine :to, {:platform => /(?:centos|el-|fedora)/}, agents
# Skipping tests if facter finds this is an ec2 host, PUP-7774
agents.each do |agent|
skip_test('Skipping EC2 Hosts') if fact_on(agent, 'ec2_metadata')
end
# Upgrade the AlmaLinux release package for newer keys until our image is updated (RE-16096)
agents.each do |agent|
on(agent, 'dnf -y upgrade almalinux-release') if fact_on(agent, 'os.name') == 'AlmaLinux'
end
tag 'audit:high',
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/rpm_util'
extend Puppet::Acceptance::RpmUtils
epoch_rpm_options = {:pkg => 'epoch', :version => '1.1', :epoch => '1'}
no_epoch_rpm_options = {:pkg => 'guid', :version => '1.0'}
teardown do
step "cleanup"
agents.each do |agent|
clean_rpm agent, epoch_rpm_options
clean_rpm agent, no_epoch_rpm_options
end
end
def verify_state(hosts, pkg, state, match)
hosts.each do |agent|
cmd = rpm_provider(agent)
# Note yum and dnf list packages as <name>.<arch>
on(agent, "#{cmd} list installed") do |result|
method(match).call(/^#{pkg}\./, result.stdout)
end
end
end
def verify_present(hosts, pkg)
verify_state(hosts, pkg, '(?!purged|absent)[^\']+', :assert_match)
end
def verify_absent(hosts, pkg)
verify_state(hosts, pkg, '(?:purged|absent)', :refute_match)
end
step "Managing a package which does not include an epoch in its version" do
step 'Setup repo and package'
agents.each do |agent|
clean_rpm agent, no_epoch_rpm_options
setup_rpm agent, no_epoch_rpm_options
send_rpm agent, no_epoch_rpm_options
end
step 'Installing a known package succeeds' do
verify_absent agents, 'guid'
apply_manifest_on(agents, 'package {"guid": ensure => installed}') do |result|
assert_match('Package[guid]/ensure: created', "#{result.host}: #{result.stdout}")
end
end
step 'Removing a known package succeeds' do
verify_present agents, 'guid'
apply_manifest_on(agents, 'package {"guid": ensure => absent}') do |result|
assert_match('Package[guid]/ensure: removed', "#{result.host}: #{result.stdout}")
end
end
step 'Installing a specific version of a known package succeeds' do
verify_absent agents, 'guid'
apply_manifest_on(agents, 'package {"guid": ensure => "1.0"}') do |result|
assert_match('Package[guid]/ensure: created', "#{result.host}: #{result.stdout}")
end
end
step 'Removing a specific version of a known package succeeds' do
verify_present agents, 'guid'
apply_manifest_on(agents, 'package {"guid": ensure => absent}') do |result|
assert_match('Package[guid]/ensure: removed', "#{result.host}: #{result.stdout}")
end
end
step 'Installing a non-existent version of a known package fails' do
verify_absent agents, 'guid'
apply_manifest_on(agents, 'package {"guid": ensure => "1.1"}') do |result|
refute_match(/Package\[guid\]\/ensure: created/, "#{result.host}: #{result.stdout}")
assert_match("Package[guid]/ensure: change from 'purged' to '1.1' failed", "#{result.host}: #{result.stderr}")
end
verify_absent agents, 'guid'
end
step 'Installing a non-existent package fails' do
verify_absent agents, 'not_a_package'
apply_manifest_on(agents, 'package {"not_a_package": ensure => present}') do |result|
refute_match(/Package\[not_a_package\]\/ensure: created/, "#{result.host}: #{result.stdout}")
assert_match("Package[not_a_package]/ensure: change from 'purged' to 'present' failed", "#{result.host}: #{result.stderr}")
end
verify_absent agents, 'not_a_package'
end
step 'Removing a non-existent package succeeds' do
verify_absent agents, 'not_a_package'
apply_manifest_on(agents, 'package {"not_a_package": ensure => absent}') do |result|
refute_match(/Package\[not_a_package\]\/ensure/, "#{result.host}: #{result.stdout}")
assert_match('Applied catalog', "#{result.host}: #{result.stdout}")
end
verify_absent agents, 'not_a_package'
end
step 'Installing a known package using source succeeds' do
verify_absent agents, 'guid'
apply_manifest_on(agents, "package { 'guid': ensure => installed, install_options => '--nogpgcheck', source=>'/tmp/rpmrepo/RPMS/noarch/guid-1.0-1.noarch.rpm' }") do |result|
assert_match('Package[guid]/ensure: created', "#{result.host}: #{result.stdout}")
end
end
end
### Epoch tests ###
agents.each do |agent|
step "Managing a package which includes an epoch in its version" do
step "Setup repo and package" do
clean_rpm agent, no_epoch_rpm_options
setup_rpm agent, epoch_rpm_options
send_rpm agent, epoch_rpm_options
end
step 'Installing a known package with an epoch succeeds' do
verify_absent [agent], 'epoch'
apply_manifest_on(agent, 'package {"epoch": ensure => installed}') do |result|
assert_match('Package[epoch]/ensure: created', "#{result.host}: #{result.stdout}")
end
end
step 'Removing a known package with an epoch succeeds' do
verify_present [agent], 'epoch'
apply_manifest_on(agent, 'package {"epoch": ensure => absent}') do |result|
assert_match('Package[epoch]/ensure: removed', "#{result.host}: #{result.stdout}")
end
end
step "Installing a specific version of a known package with an epoch succeeds when epoch and arch are specified" do
verify_absent [agent], 'epoch'
apply_manifest_on(agent, "package {'epoch': ensure => '1:1.1-1.noarch'}") do |result|
assert_match('Package[epoch]/ensure: created', "#{result.host}: #{result.stdout}")
end
apply_manifest_on(agent, "package {'epoch': ensure => '1:1.1-1.noarch'}") do |result|
refute_match(/epoch/, result.stdout)
end
end
if rpm_provider(agent) == 'dnf'
# Yum requires the arch to be specified whenever epoch is specified. This step is only
# expected to work in DNF.
step "Installing a specific version of a known package with an epoch succeeds when epoch is specified and arch is not" do
step "Remove the package" do
apply_manifest_on(agent, 'package {"epoch": ensure => absent}')
verify_absent [agent], 'epoch'
end
apply_manifest_on(agent, 'package {"epoch": ensure => "1:1.1-1"}') do |result|
assert_match('Package[epoch]/ensure: created', "#{result.host}: #{result.stdout}")
end
apply_manifest_on(agent, 'package {"epoch": ensure => "1:1.1-1"}') do |result|
refute_match(/epoch/, result.stdout)
end
apply_manifest_on(agent, "package {'epoch': ensure => '1:1.1-1.noarch'}") do |result|
refute_match(/epoch/, result.stdout)
end
end
end
if rpm_provider(agent) == 'yum'
step "Installing a specified version of a known package with an epoch succeeds without epoch or arch provided" do
# Due to a bug in DNF, epoch is required. This step is only expected to work in Yum.
# See https://bugzilla.redhat.com/show_bug.cgi?id=1286877
step "Remove the package" do
apply_manifest_on(agent, 'package {"epoch": ensure => absent}')
verify_absent [agent], 'epoch'
end
apply_manifest_on(agent, 'package {"epoch": ensure => "1.1-1"}') do |result|
assert_match('Package[epoch]/ensure: created', "#{result.host}: #{result.stdout}")
end
apply_manifest_on(agent, 'package {"epoch": ensure => "1.1-1"}') do |result|
refute_match(/epoch/, result.stdout)
end
apply_manifest_on(agent, "package {'epoch': ensure => '1:1.1-1.noarch'}") do |result|
refute_match(/epoch/, result.stdout)
end
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/does_not_exist.rb | acceptance/tests/resource/package/does_not_exist.rb | # Redmine (#22529)
test_name "Puppet returns only resource package declaration when querying an uninstalled package" do
tag 'audit:high',
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
agents.each do |agent|
step "test puppet resource package" do
on(agent, puppet('resource', 'package', 'not-installed-on-this-host')) do |result|
assert_match(/package.*not-installed-on-this-host.*\n.*ensure.*(?:absent|purged).*\n.*provider/, result.stdout)
end
end
end
# Until #3707 is fixed and purged rpm/yum packages no longer give spurious creation notices
# Also skipping solaris, windows whose providers do not have purgeable implemented.
confine_block(:to, :platform => /debian|ubuntu/) do
agents.each do |agent|
step "test puppet apply" do
on(agent, puppet('apply', '-e', %Q|"package {'not-installed-on-this-host': ensure => purged }"|)) do |result|
refute_match(/warning/i, result.stdout)
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/common_package_name_in_different_providers.rb | acceptance/tests/resource/package/common_package_name_in_different_providers.rb | test_name "ticket 1073: common package name in two different providers should be allowed" do
confine :to, {:platform => /(?:centos|el-|fedora)/}, agents
# Skipping tests if facter finds this is an ec2 host, PUP-7774
agents.each do |agent|
skip_test('Skipping EC2 Hosts') if fact_on(agent, 'ec2_metadata')
end
# Upgrade the AlmaLinux release package for newer keys until our image is updated (RE-16096)
agents.each do |agent|
on(agent, 'dnf -y upgrade almalinux-release') if fact_on(agent, 'os.name') == 'AlmaLinux'
end
tag 'audit:high',
'audit:acceptance' # Uses a provider that depends on AIO packaging
require 'puppet/acceptance/rpm_util'
extend Puppet::Acceptance::RpmUtils
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::CommandUtils
rpm_options = {:pkg => 'guid', :version => '1.0'}
teardown do
step "cleanup"
agents.each do |agent|
clean_rpm agent, rpm_options
end
end
step "Verify gem and ruby-devel on fedora-22 and above if not aio" do
if @options[:type] != 'aio' then
agents.each do |agent|
if agent[:platform] =~ /fedora-2[2-9]/ then
unless check_for_package agent, 'rubygems'
install_package agent, 'rubygems'
end
unless check_for_package agent, 'ruby-devel'
install_package agent, 'ruby-devel'
end
end
end
end
end
def gem_provider
if @options[:type] == 'aio'
'puppet_gem'
else
'gem'
end
end
def verify_state(hosts, pkg, state, match)
hosts.each do |agent|
cmd = rpm_provider(agent)
# Note yum lists packages as <name>.<arch>
on(agent, "#{cmd} list installed") do |result|
method(match).call(/^#{pkg}\./, result.stdout)
end
on(agent, "#{gem_command(agent, @options[:type])} list --local") do |result|
method(match).call(/^#{pkg} /, result.stdout)
end
end
end
def verify_present(hosts, pkg)
verify_state(hosts, pkg, '(?!purged|absent)[^\']+', :assert_match)
end
def verify_absent(hosts, pkg)
verify_state(hosts, pkg, '(?:purged|absent)', :refute_match)
end
# Setup repo and package
agents.each do |agent|
clean_rpm agent, rpm_options
setup_rpm agent, rpm_options
send_rpm agent, rpm_options
end
verify_absent agents, 'guid'
# Test error trying to install duplicate packages
collide1_manifest = <<-MANIFEST
package {'guid': ensure => installed}
package {'other-guid': name => 'guid', ensure => present}
MANIFEST
apply_manifest_on(agents, collide1_manifest, :acceptable_exit_codes => [1]) do |result|
assert_match(/Error while evaluating a Resource Statement, Cannot alias Package\[other-guid\] to \[nil, "guid", nil\]/, "#{result.host}: #{result.stderr}")
end
verify_absent agents, 'guid'
gem_source = if ENV['GEM_SOURCE'] then "source => '#{ENV['GEM_SOURCE']}'," else '' end
collide2_manifest = <<-MANIFEST
package {'guid': ensure => '0.1.0', provider => #{gem_provider}, #{gem_source}}
package {'other-guid': name => 'guid', ensure => installed, provider => #{gem_provider}, #{gem_source}}
MANIFEST
apply_manifest_on(agents, collide2_manifest, :acceptable_exit_codes => [1]) do |result|
assert_match(/Error while evaluating a Resource Statement, Cannot alias Package\[other-guid\] to \[nil, "guid", "#{gem_provider}"\]/, "#{result.host}: #{result.stderr}")
end
verify_absent agents, 'guid'
# Test successful parallel installation
install_manifest = <<-MANIFEST
package {'guid': ensure => installed}
package {'gem-guid':
provider => #{gem_provider},
name => 'guid',
ensure => installed,
#{gem_source}
}
MANIFEST
apply_manifest_on(agents, install_manifest) do |result|
assert_match('Package[guid]/ensure: created', "#{result.host}: #{result.stdout}")
assert_match('Package[gem-guid]/ensure: created', "#{result.host}: #{result.stdout}")
end
verify_present agents, 'guid'
# Test removal
remove_manifest = <<-MANIFEST
package {'gem-guid':
provider => #{gem_provider},
name => 'guid',
ensure => absent,
#{gem_source}
}
package {'guid': ensure => absent}
MANIFEST
apply_manifest_on(agents, remove_manifest) do |result|
assert_match('Package[guid]/ensure: removed', "#{result.host}: #{result.stdout}")
assert_match('Package[gem-guid]/ensure: removed', "#{result.host}: #{result.stdout}")
end
verify_absent agents, 'guid'
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/windows.rb | acceptance/tests/resource/package/windows.rb | test_name "Windows Package Provider" do
confine :to, :platform => 'windows'
tag 'audit:high',
'audit:acceptance'
require 'puppet/acceptance/windows_utils'
extend Puppet::Acceptance::WindowsUtils
def package_manifest(name, params, installer_source)
params_str = params.map do |param, value|
value_str = value.to_s
value_str = "\"#{value_str}\"" if value.is_a?(String)
" #{param} => #{value_str}"
end.join(",\n")
<<-MANIFEST
package { '#{name}':
source => '#{installer_source}',
#{params_str}
}
MANIFEST
end
mock_package = {
:name => "MockPackage"
}
agents.each do |agent|
tmpdir = agent.tmpdir("mock_installer")
installer_location = create_mock_package(agent, tmpdir, mock_package)
step 'Verify that ensure = present installs the package' do
apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :present}, installer_location))
assert(package_installed?(agent, mock_package[:name]), 'Package succesfully installed')
end
step 'Verify that ensure = absent removes the package' do
apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :absent}, installer_location))
assert_equal(false, package_installed?(agent, mock_package[:name]), 'Package successfully Uninstalled')
end
tmpdir = agent.tmpdir("mock_installer")
mock_package[:name] = "MockPackageWithFile"
mock_package[:install_commands] = 'System.IO.File.ReadAllLines("install.txt");'
installer_location = create_mock_package(agent, tmpdir, mock_package)
# Since we didn't add the install.txt package the installation should fail with code 1004
step 'Verify that ensure = present fails when an installer fails with a non-zero exit code' do
apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :present}, installer_location)) do |result|
assert_match(/#{mock_package[:name]}/, result.stderr, 'Windows package provider did not fail when the package install failed')
end
end
step 'Verify that ensure = present installs a package that requires additional resources' do
create_remote_file(agent, "#{tmpdir}/install.txt", 'foobar')
apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :present}, installer_location))
assert(package_installed?(agent, mock_package[:name]), 'Package succesfully installed')
end
step 'Verify that ensure = absent removes the package that required additional resources' do
apply_manifest_on(agent, package_manifest(mock_package[:name], {ensure: :absent}, installer_location))
assert_equal(false, package_installed?(agent, mock_package[:name]), 'Package successfully Uninstalled')
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/should_remove.rb | acceptance/tests/resource/package/ips/should_remove.rb | test_name "Package:IPS basic tests"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
on agent, "pkg install mypkg"
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
step "IPS: ensure removed."
apply_manifest_on(agent, 'package {mypkg : ensure=>absent}')
on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do
refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/should_be_updatable.rb | acceptance/tests/resource/package/ips/should_be_updatable.rb | test_name "Package:IPS test for updatable (update, latest)"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: basic - it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: ask to be latest"
send_pkg agent, :pkg => 'mypkg@0.0.2'
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
step "IPS: ensure it was upgraded"
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}")
end
step "IPS: when there are more than one option, choose latest."
send_pkg agent,:pkg => 'mypkg@0.0.3'
send_pkg agent,:pkg => 'mypkg@0.0.4'
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.4/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/should_be_versionable.rb | acceptance/tests/resource/package/ips/should_be_versionable.rb | test_name "Package:IPS versionable"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
send_pkg agent, :pkg => 'mypkg@0.0.2'
set_publisher agent
step "IPS: basic - it should create a specific version"
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1"}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
on agent, "pkg list mypkg" do
assert_match( /0.0.1/, result.stdout, "err: #{agent}")
end
step "IPS: it should upgrade if asked for next version"
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.2"}') do
assert_match( /ensure changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list mypkg" do
refute_match( /0.0.1/, result.stdout, "err: #{agent}")
assert_match( /0.0.2/, result.stdout, "err: #{agent}")
end
step "IPS: it should downpgrade if asked for previous version"
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1"}') do
assert_match( /ensure changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list mypkg" do
refute_match( /0.0.2/, result.stdout, "err: #{agent}")
assert_match( /0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/should_be_idempotent.rb | acceptance/tests/resource/package/ips/should_be_idempotent.rb | test_name "Package:IPS idempotency"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: should be idempotent (present)"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
refute_match( /created/, result.stdout, "err: #{agent}")
refute_match( /changed/, result.stdout, "err: #{agent}")
end
send_pkg agent, :pkg => 'mypkg@0.0.2'
step "IPS: ask for latest version"
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
step "IPS: ask for latest version again: should be idempotent (latest)"
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}') do
refute_match( /created/, result.stdout, "err: #{agent}")
end
step "IPS: ask for specific version"
send_pkg agent,:pkg => 'mypkg@0.0.3'
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3"}') do
assert_match( /changed/, result.stdout, "err: #{agent}")
end
step "IPS: ask for specific version again: should be idempotent (version)"
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3"}') do
refute_match( /created/, result.stdout, "err: #{agent}")
refute_match( /changed/, result.stdout, "err: #{agent}")
end
step "IPS: ensure removed."
apply_manifest_on(agent, 'package {mypkg : ensure=>absent}')
on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do
refute_match( /mypkg/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/basic_tests.rb | acceptance/tests/resource/package/ips/basic_tests.rb | test_name "Package:IPS basic tests"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: clean slate"
clean agent
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: basic ensure we are clean"
apply_manifest_on(agent, 'package {mypkg : ensure=>absent}')
on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do
refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
step "IPS: basic - it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: check it was created"
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}")
end
step "IPS: do not upgrade until latest is mentioned"
send_pkg agent,:pkg => 'mypkg@0.0.2'
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
refute_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: verify it was not upgraded"
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}")
end
step "IPS: ask to be latest"
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
step "IPS: ensure it was upgraded"
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.2[,:]?.*'/, result.stdout, "err: #{agent}")
end
step "IPS: when there are more than one option, choose latest."
send_pkg agent,:pkg => 'mypkg@0.0.3'
send_pkg agent,:pkg => 'mypkg@0.0.4'
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.4[,:]?.*'/, result.stdout, "err: #{agent}")
end
step "IPS: ensure removed."
apply_manifest_on(agent, 'package {mypkg : ensure=>absent}')
on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do
refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/should_be_holdable.rb | acceptance/tests/resource/package/ips/should_be_holdable.rb | test_name "Package:IPS versionable"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent, :pkg => 'mypkg2'
clean agent, :pkg => 'mypkg'
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
setup_fakeroot2 agent
send_pkg2 agent, :pkg => 'mypkg2@0.0.1'
set_publisher agent
step "IPS: basic - it should create a specific version and install dependent package"
apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.1"}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg2" do
assert_match( /mypkg2@0.0.1/, result.stdout, "err: #{agent}")
end
step "IPS: it should upgrade current and dependent package"
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.2'
setup_fakeroot2 agent
send_pkg2 agent, :pkg => 'mypkg2@0.0.2', :pkgdep => 'mypkg@0.0.2'
apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.2"}') do
assert_match( /changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg2" do
assert_match( /mypkg2@0.0.2/, result.stdout, "err: #{agent}")
end
step "IPS: it should not upgrade current and dependent package if dependent package is hold"
apply_manifest_on(agent, 'package {mypkg : ensure=>"present", mark=>"hold", provider=>"pkg"}') do
assert_match( //, result.stdout, "err: #{agent}")
end
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.3'
setup_fakeroot2 agent
send_pkg2 agent, :pkg => 'mypkg2@0.0.3', :pkgdep => 'mypkg@0.0.3'
apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.2"}') do
refute_match( /changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg2" do
assert_match( /mypkg2@0.0.2/, result.stdout, "err: #{agent}")
end
step "IPS: it should upgrade if hold was released."
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3", provider=>"pkg"}') do
assert_match( //, result.stdout, "err: #{agent}")
end
apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.3"}') do
assert_match( /changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.3/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg2" do
assert_match( /mypkg2@0.0.3/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/should_be_updateable_and_unholdable_at_same_time.rb | acceptance/tests/resource/package/ips/should_be_updateable_and_unholdable_at_same_time.rb | test_name "Package:IPS test for updatable holded package" do
confine :to, :platform => 'solaris-11'
tag 'audit:high'
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
agents.each do |agent|
teardown do
clean agent
end
step "IPS: setup" do
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
end
step "IPS: it should create and hold in same manifest" do
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1", mark=>hold}') do |result|
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
end
step "IPS: it should update and unhold in same manifest" do
send_pkg agent, :pkg => 'mypkg@0.0.2'
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.2", mark=>"none"}')
end
step "IPS: ensure it was upgraded" do
on agent, "pkg list -v mypkg" do |result|
assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}")
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/should_create.rb | acceptance/tests/resource/package/ips/should_create.rb | test_name "Package:IPS basic tests"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: clean slate"
clean agent
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: basic - it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: check it was created"
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/package/ips/should_query.rb | acceptance/tests/resource/package/ips/should_query.rb | test_name "Package:IPS query"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: basic - it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>"present"}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
on(agent, puppet("resource package mypkg")) do
assert_match( /0.0.1/, result.stdout, "err: #{agent}")
end
on(agent, puppet("resource package")) do
assert_match( /0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/tidy/should_remove_old_files.rb | acceptance/tests/resource/tidy/should_remove_old_files.rb | test_name "Tidying files by date"
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:integration'
agents.each do |agent|
step "Create a directory of old and new files"
dir = agent.tmpdir('tidy-test')
on agent, "mkdir -p #{dir}"
# YYMMddhhmm, so 03:04 Jan 2 1970
old = %w[one two three four five]
new = %w[a b c d e]
on agent, "touch -t 7001020304 #{dir}/{#{old.join(',')}}"
on agent, "touch #{dir}/{#{new.join(',')}}"
step "Run a tidy resource to remove the old files"
manifest = <<-MANIFEST
tidy { "#{dir}":
age => '1d',
recurse => true,
}
MANIFEST
apply_manifest_on agent, manifest
step "Ensure the old files are gone"
old_test = old.map {|name| "-f #{File.join(dir, name)}"}.join(' -o ')
on agent, "[ #{old_test} ]", :acceptable_exit_codes => [1]
step "Ensure the new files are still present"
new_test = new.map {|name| "-f #{File.join(dir, name)}"}.join(' -a ')
on agent, "[ #{new_test} ]"
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/resource/tidy/resources_should_be_non_isomorphic.rb | acceptance/tests/resource/tidy/resources_should_be_non_isomorphic.rb | # This test is to verify multi tidy resources with same path but
# different matches should not cause error as found in the bug PUP-6508
test_name "PUP-6655 - C98145 tidy resources should be non-isomorphic" do
tag 'audit:high',
'audit:integration'
agents. each do |agent|
dir = agent.tmpdir('tidy-test-dir')
on(agent, "mkdir -p #{dir}")
files = %w{file1.txt file2.doc}
on(agent, "touch #{dir}/{#{files.join(',')}}")
manifest = <<-MANIFEST
tidy {'tidy-resource1':
path => "#{dir}",
matches => "*.txt",
recurse => true,
}
tidy {'tidy-resource2':
path => "#{dir}",
matches => "*.doc",
recurse => true,
}
MANIFEST
step "Ensure the newly created files are present:" do
present = files.map {|file| "-f #{File.join(dir, file)}"}.join(' -a ')
on(agent, "[ #{present} ]")
end
step "Create multiple tidy resources with same path" do
apply_manifest_on(agent, manifest) do |result|
refute_match(/Error:/, result.stderr, "Unexpected error was detected")
end
end
step "Verify that the files are actually removed successfully:" do
present = files.map {|file| "-f #{File.join(dir, file)}"}.join(' -o ')
on(agent, "[ #{present} ]", :acceptable_exit_codes => [1])
end
teardown do
on(agent, puppet("apply -e \"file{'#{dir}': ensure => absent, force => true}\""))
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/aix/nim_package_provider.rb | acceptance/tests/aix/nim_package_provider.rb | test_name "NIM package provider should work correctly"
tag 'audit:high',
'audit:acceptance' # OS specific by definition
# nim test is slow, confine to only aix 7.2 and recent puppet versions
confine :to, :platform => "aix" do |aix|
version = on(aix, 'puppet --version').stdout
version &&
Gem::Version.new(version) > Gem::Version.new('6.4.0') &&
on(aix, 'facter os.release.full').stdout == '7.2'
end
teardown do
test_apply('cdrecord', 'absent', '')
test_apply('puppet.test.rte', 'absent', '')
end
def assert_package_version(package, expected_version)
# The output of lslpp is a colon-delimited list like:
# sudo:sudo.rte:1.8.6.4: : :C: :Configurable super-user privileges runtime: : : : : : :0:0:/:
# We want the version, so grab the third field
on(hosts, "lslpp -qLc #{package} | cut -f3 -d:") do |result|
actual_version = result.stdout.chomp
assert_equal(expected_version, actual_version, "Installed package version #{actual_version} does not match expected version #{expected_version}")
end
end
def get_manifest(package, ensure_value)
<<MANIFEST
package {'#{package}':
ensure => '#{ensure_value}',
source => 'lpp_custom',
provider => nim,
}
MANIFEST
end
def test_apply(package_name, ensure_value, expected_version)
manifest = get_manifest(package_name, ensure_value)
on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]),
{:stdin => manifest, :acceptable_exit_codes => [2]}
step "validate installed package version" do
assert_package_version package_name, expected_version
end
step "run again to ensure idempotency" do
on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]),
{:stdin => manifest, :acceptable_exit_codes => [0]}
end
step "validate installed package version" do
assert_package_version package_name, expected_version
end
end
# These two packages live in an LPP source on the NIM master. Details
# on our nim masters are available at
# https://confluence.puppetlabs.com/display/OPS/IBM+Power+LPARs
package_types = {
"RPM" => {
:package_name => "cdrecord",
:old_version => '1.9-6',
:new_version => '1.9-9'
},
"BFF" => {
:package_name => "puppet.test.rte",
:old_version => '1.0.0.0',
:new_version => '2.0.0.0'
}
}
step "Setup: ensure test packages are not installed" do
pkgs = ['cdrecord', 'puppet.test.rte']
pkgs.each do |pkg|
on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]),
{:stdin => get_manifest(pkg, 'absent'), :acceptable_exit_codes => [0,2]}
end
end
package_types.each do |package_type, details|
step "install a #{package_type} package via 'ensure=>present'" do
package_name = details[:package_name]
version = details[:new_version]
test_apply(package_name, 'present', version)
end
step "uninstall a #{package_type} package via 'ensure=>absent'" do
package_name = details[:package_name]
version = ''
test_apply(package_name, 'absent', version)
end
step "install a #{package_type} package via 'ensure=><OLD_VERSION>'" do
package_name = details[:package_name]
version = details[:old_version]
test_apply(package_name, version, version)
end
step "upgrade a #{package_type} package via 'ensure=><NEW_VERSION>'" do
package_name = details[:package_name]
version = details[:new_version]
test_apply(package_name, version, version)
end
step "attempt to downgrade a #{package_type} package via 'ensure=><OLD_VERSION>'" do
package_name = details[:package_name]
version = details[:old_version]
manifest = get_manifest(package_name, version)
on(hosts, puppet_apply("--verbose", "--detailed-exitcodes"),
{ :stdin => manifest,
:acceptable_exit_codes => [4,6] }) do |result|
assert_match(/NIM package provider is unable to downgrade packages/, result.stderr, "Didn't get an error about downgrading packages")
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/aix/aix_package_provider.rb | acceptance/tests/aix/aix_package_provider.rb | test_name "aix package provider should work correctly" do
tag 'audit:high',
'audit:acceptance' # OS specific by definition.
confine :to, :platform => /aix/
dir = "/tmp/aix-packages-#{$$}"
def assert_package_version(package, expected_version)
# The output of lslpp is a colon-delimited list like:
# sudo:sudo.rte:1.8.6.4: : :C: :Configurable super-user privileges runtime: : : : : : :0:0:/:
# We want the version, so grab the third field
on(hosts, "lslpp -qLc #{package} | cut -f3 -d:") do |result|
actual_version = result.stdout.chomp
assert_equal(expected_version, actual_version, "Installed package version #{actual_version} does not match expected version #{expected_version}")
end
end
def get_package_manifest(package, version, sourcedir)
<<-MANIFEST
package { '#{package}':
ensure => '#{version}',
provider => aix,
source => '#{sourcedir}',
}
MANIFEST
end
package = 'sudo.rte'
version1 = '1.7.10.4'
version2 = '1.8.6.4'
teardown do
on hosts, "rm -rf #{dir}"
on hosts, "installp -u #{package}"
end
step "download packages to use for test" do
on hosts, "mkdir -p #{dir}"
on hosts, "curl https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/misc/sudo.#{version1}.aix51.lam.bff > #{dir}/sudo.#{version1}.aix51.lam.bff"
on hosts, "curl https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/misc/sudo.#{version2}.aix51.lam.bff > #{dir}/sudo.#{version2}.aix51.lam.bff"
end
step "install the older version of package" do
apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :catch_failures => true)
end
step "verify package is installed and at the correct version" do
assert_package_version package, version1
end
step "install a newer version of the package" do
apply_manifest_on(hosts, get_package_manifest(package, version2, dir), :catch_failures => true)
end
step "verify package is installed and at the newer version" do
assert_package_version package, version2
end
step "test that downgrading fails by trying to install an older version of the package" do
apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :acceptable_exit_codes => [4,6]) do |res|
assert_match(/aix package provider is unable to downgrade packages/, res.stderr, "Didn't get an error about downgrading packages")
end
end
step "uninstall the package" do
apply_manifest_on(hosts, get_package_manifest(package, 'absent', dir), :catch_failures => true)
end
step "verify the package is gone" do
on hosts, "lslpp -qLc #{package}", :acceptable_exit_codes => [1]
end
step "install the older version of package" do
apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :catch_failures => true)
end
step "verify package is installed and at the correct version" do
assert_package_version package, version1
end
step "install latest version of the package" do
apply_manifest_on(hosts, get_package_manifest(package, 'latest', dir), :catch_failures => true)
end
step "verify package is installed and at the correct version" do
assert_package_version package, version2
end
step "PUP-7818 remove a package without defining the source metaparameter" do
manifest = get_package_manifest(package, 'latest', dir)
manifest = manifest + "package { 'nonexistant_example_package.rte': ensure => absent, }"
apply_manifest_on(hosts, manifest, :catch_failures => true)
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/loader/func4x_loadable_from_modules.rb | acceptance/tests/loader/func4x_loadable_from_modules.rb | test_name "Exercise a module with 4x function and 4x system function"
# Purpose:
# Test that a packed puppet can call a 4x system function, and that a 4x function in
# a module can be called.
#
# Method:
# * Manually construct a very simple module with a manifest that creates a file.
# * The file has content that depends on logic that calls both a system function (reduce), and
# a function supplied in the module (helloworld::mul10).
# * The module is manually constructed to allow the test to also run on Windows where the module tool
# is not supported.
# * The module is included by calling 'include' from 'puppet apply'.
# * Puppet apply is executed to generate the file with the content.
# * The generated contents is asserted.
# TODO: The test can be improved by adding yet another module that calls the function in helloworld.
# TODO: The test can be improved to also test loading of a non namespaced function
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
tag 'audit:high',
'audit:unit' # This should be covered adequately by unit tests
initialize_temp_dirs
agents.each do |agent|
# The modulepath to use in environment 'dev'
envs_path = get_test_file_path(agent, 'environments')
dev_modulepath = get_test_file_path(agent, 'environments/dev/modules')
target_path = get_test_file_path(agent, 'output')
mkdirs agent, target_path
# make sure that we use the modulepath from the dev environment
puppetconf = get_test_file_path(agent, 'puppet.conf')
on agent, puppet("config", "set", "environmentpath", envs_path, "--section", "main", "--config", puppetconf)
on agent, puppet("config", "set", "environment", "dev", "--section", "user", "--config", puppetconf)
# Where the functions in the written modules should go
helloworld_functions = 'helloworld/lib/puppet/functions/helloworld'
# Clean out the module that will be written to ensure no interference from a previous run
on agent, "rm -rf #{File.join(dev_modulepath, 'helloworld')}"
mkdirs agent, File.join(dev_modulepath, helloworld_functions)
# Write a module
# Write the function helloworld::mul10, that multiplies its argument by 10
create_remote_file(agent, File.join(dev_modulepath, helloworld_functions, "mul10.rb"), <<'SOURCE')
Puppet::Functions.create_function(:'helloworld::mul10') do
def mul10(x)
x * 10
end
end
SOURCE
# Write a manifest that calls a 4x function (reduce), and calls a function defined in the module
# (helloworld::mul10).
#
mkdirs agent, File.join(dev_modulepath, "helloworld", "manifests")
create_remote_file(agent, File.join(dev_modulepath, "helloworld", "manifests", "init.pp"), <<SOURCE)
class helloworld {
file { "#{target_path}/result.txt":
ensure => 'file',
mode => '0666',
content => [1,2,3].reduce("Generated") |$memo, $n| {
"${memo}, ${n} => ${helloworld::mul10($n)}"
}
}
}
SOURCE
# Run apply to generate the file with the output
on(agent, puppet('apply', '-e', "'include helloworld'", '--config', puppetconf))
# Assert that the file was written with the generated content
on(agent, "cat #{File.join(target_path, 'result.txt')}") do |result|
assert_match(/^Generated, 1 => 10, 2 => 20, 3 => 30$/, result.stdout, "Generated the wrong content")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/loader/autoload_from_resource_type_decl.rb | acceptance/tests/loader/autoload_from_resource_type_decl.rb | test_name 'C100303: Resource type statement triggered auto-loading works both with and without generated types' do
tag 'risk:high'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/agent_fqdn_utils'
extend Puppet::Acceptance::AgentFqdnUtils
# create the file and make sure its empty and accessible by everyone
def empty_execution_log_file(host, path)
create_remote_file(host, path, '')
on(host, "chmod 777 '#{path}'")
end
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
relative_type_dir = 'modules/one/lib/puppet/type'
relative_type_path = "#{relative_type_dir}/type_tst.rb"
execution_log = {}
execution_log[agent_to_fqdn(master)] = master.tmpfile('master_autoload_resource')
agents.each do |agent|
execution_log[agent_to_fqdn(agent)] = agent.tmpfile('agent_autoload_resource')
end
teardown do
on(master, "rm -f '#{execution_log[agent_to_fqdn(master)]}'")
agents.each do |agent|
on(agent, "rm -f '#{execution_log[agent_to_fqdn(agent)]}'")
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step 'create custom type' do
on(master, "mkdir -p '#{fq_tmp_environmentpath}/#{relative_type_dir}'")
# create a custom type that will write out to a different file on each agent
# this way we can verify whether the newtype code was executed on each system
custom_type = <<-END
Puppet::Type.newtype(:type_tst) do
newparam(:name, :namevar => true) do
fqdn = Facter.value('networking.fqdn')
if fqdn == '#{agent_to_fqdn(master)}'
File.open("#{execution_log[agent_to_fqdn(master)]}", 'a+') { |f| f.puts("found_type_tst: " + Time.now.to_s) }
end
END
agents.each do |agent|
custom_type << <<-END
if fqdn == '#{agent_to_fqdn(agent)}'
File.open("#{execution_log[agent_to_fqdn(agent)]}", 'a+') { |f| f.puts("found_type_tst: " + Time.now.to_s) }
end
END
end
custom_type << <<-END
Puppet.notice("found_type_tst")
end
end
END
create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_type_path}", custom_type)
site_pp = <<-PP
Resource['type_tst'] { 'found_type': }
PP
create_sitepp(master, tmp_environment, site_pp)
end
on(master, "chmod -R 755 '/tmp/#{tmp_environment}'")
# when the agent does its run, the newtype is executed on both the agent and master nodes
# so we should see a message in the execution log file on the agent and the master
agents.each do |agent|
with_puppet_running_on(master, {}) do
empty_execution_log_file(master, execution_log[agent_to_fqdn(master)])
empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)])
on(agent, puppet("agent -t --environment '#{tmp_environment}'")) do |puppet_result|
assert_match(/\/File\[.*\/type_tst.rb\]\/ensure: defined content as/, puppet_result.stdout,
'Expected to see defined content message for type: type_tst')
assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see the notice from the new type: type_tst')
end
on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result|
assert_match(/found_type_tst:/, cat_result.stdout,
"Expected to see execution log entry on master #{agent_to_fqdn(master)}")
end
on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result|
assert_match(/found_type_tst:/, cat_result.stdout,
"Expected to see execution log entry on agent #{agent_to_fqdn(agent)}")
end
end
end
# when generating the pcore the newtype should only be run on the master node
step 'generate pcore files' do
# start with an empty execution log
empty_execution_log_file(master, execution_log[agent_to_fqdn(master)])
agents.each do |agent|
empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)])
end
on(master, puppet("generate types --environment '#{tmp_environment}'")) do |puppet_result|
assert_match(/Notice: Generating '\/.*\/type_tst\.pp' using 'pcore' format/, puppet_result.stdout,
'Expected to see Generating message for type: type_tst')
assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see log entry on master ')
end
# we should see a log entry on the master node
on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result|
assert_match(/found_type_tst:/, cat_result.stdout,
"Expected to see execution log entry on master #{agent_to_fqdn(master)}")
end
# we should not see any log entries on any of the agent nodes
agents.each do |agent|
next if agent == master
on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result|
assert_empty(cat_result.stdout.chomp, "Expected execution log file to be empty on agent node #{agent_to_fqdn(agent)}")
end
end
end
empty_execution_log_file(master, execution_log[agent_to_fqdn(master)])
agents.each do |agent|
next if agent == master
empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)])
# this test is relying on the beaker helper with_puppet_running_on() to restart the server
# Compilation should now work using the generated types,
# so we should only see a log entry on the agent node and nothing on the master node
with_puppet_running_on(master, {}) do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"),
:acceptable_exit_codes => 0) do |puppet_result|
assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see output from new type: type_tst')
end
end
on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result|
assert_match(/found_type_tst:/, cat_result.stdout,
"Expected to see an execution log entry on agent #{agent_to_fqdn(agent)}")
end
end
on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result|
assert_empty(cat_result.stdout.chomp, "Expected master execution log to be empty #{agent_to_fqdn(master)}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/loader/resource_triggers_autoload.rb | acceptance/tests/loader/resource_triggers_autoload.rb | test_name 'C100296: can auto-load defined types using a Resource statement' do
tag 'risk:high'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
relative_define_type_dir = 'modules/one/manifests'
relative_define_type_1_path = "#{relative_define_type_dir}/tst1.pp"
relative_define_type_2_path = "#{relative_define_type_dir}/tst2.pp"
step 'create custom type in two environments' do
on(master, "mkdir -p #{fq_tmp_environmentpath}/#{relative_define_type_dir}")
define_type_1 = <<-END
define one::tst1($var) {
notify { "tst1: ${var}": }
}
END
define_type_2 = <<-END
define one::tst2($var) {
notify { "tst2: ${var}": }
}
END
create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_define_type_1_path}", define_type_1)
create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_define_type_2_path}", define_type_2)
site_pp = <<-PP
each(['tst1', 'tst2']) |$nr| {
Resource["one::${nr}"] { "some_title_${nr}": var => "Define found one::${nr}" }
}
PP
create_sitepp(master, tmp_environment, site_pp)
end
on(master, "chmod -R 755 /tmp/#{tmp_environment}")
with_puppet_running_on(master, {}) do
agents.each do |agent|
on(agent, puppet("agent -t --environment #{tmp_environment}"),
:acceptable_exit_codes => 2) do |puppet_result|
assert_match(/Notice: tst1: Define found one::tst1/, puppet_result.stdout, 'Expected to see output from define notify')
assert_match(/Notice: tst2: Define found one::tst2/, puppet_result.stdout, 'Expected to see output from define notify')
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/ordering/master_agent_application.rb | acceptance/tests/ordering/master_agent_application.rb | test_name "Puppet applies resources without dependencies in file order over the network"
tag 'audit:high',
'audit:integration',
'server'
testdir = master.tmpdir('application_order')
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0750",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}':;
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/production/manifests/site.pp':
ensure => file,
mode => "0640",
content => '
notify { "first": }
notify { "second": }
notify { "third": }
notify { "fourth": }
notify { "fifth": }
notify { "sixth": }
notify { "seventh": }
notify { "eighth": }
';
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
}
}
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
on(agent, puppet('agent', "--no-daemonize --onetime --verbose")) do |result|
if result.stdout !~ /Notice: first.*Notice: second.*Notice: third.*Notice: fourth.*Notice: fifth.*Notice: sixth.*Notice: seventh.*Notice: eighth/m
fail_test "Output did not include the notify resources in the correct order"
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/apply/classes/should_allow_param_undef_override.rb | acceptance/tests/apply/classes/should_allow_param_undef_override.rb | test_name "should allow overriding a parameter to undef in inheritence"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
agents.each do |agent|
dir = agent.tmpdir('class_undef_override')
out = File.join(dir, 'class_undef_override_out')
source = File.join(dir, 'class_undef_override_test')
manifest = %Q{
class parent {
file { 'test':
path => '#{out}',
source => '#{source}',
}
}
class child inherits parent {
File['test'] {
source => undef,
content => 'hello new world!',
}
}
include parent
include child
}
step "prepare the target file on all systems"
on(agent, "echo 'hello world!' > #{out}")
step "apply the manifest"
apply_manifest_on(agent, manifest)
step "verify the file content"
on(agent, "cat #{out}") do |result|
fail_test "the file was not touched" if result.stdout.include? "hello world!"
fail_test "the file was not updated" unless result.stdout.include? "hello new world"
end
on(agent, "rm -rf #{dir}")
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/apply/classes/should_include_resources_from_class.rb | acceptance/tests/apply/classes/should_include_resources_from_class.rb | test_name "resources declared in a class can be applied with include"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
manifest = %q{
class x {
notify{'a':}
}
include x
}
apply_manifest_on(agents, manifest) do |result|
fail_test "the resource did not apply" unless result.stdout.include?("defined 'message' as 'a'")
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb | acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb | test_name "resources declared in classes are not applied without include"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
manifest = %q{ class x { notify { 'test': message => 'never invoked' } } }
apply_manifest_on(agents, manifest) do |result|
fail_test "found the notify despite not including it" if
result.stdout.include? "never invoked"
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/apply/classes/parameterized_classes.rb | acceptance/tests/apply/classes/parameterized_classes.rb | test_name "parametrized classes"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
########################################################################
step "should allow param classes"
manifest = %q{
class x($y, $z) {
notice("${y}-${z}")
}
class {x: y => '1', z => '2'}
}
apply_manifest_on(agents, manifest) do |result|
fail_test "inclusion after parameterization failed" unless result.stdout.include? "1-2"
end
########################################################################
# REVISIT: This was ported from the old set of tests, but I think that
# the desired behaviour has recently changed. --daniel 2010-12-23
step "should allow param class post inclusion"
manifest = %q{
class x($y, $z) {
notice("${y}-${z}")
}
class {x: y => '1', z => '2'}
include x
}
apply_manifest_on(agents, manifest) do |result|
fail_test "inclusion after parameterization failed" unless result.stdout.include? "1-2"
end
########################################################################
step "should allow param classes defaults"
manifest = %q{
class x($y, $z='2') {
notice("${y}-${z}")
}
class {x: y => '1'}
}
apply_manifest_on(agents, manifest) do |result|
fail_test "the default didn't apply as expected" unless result.stdout.include? "1-2"
end
########################################################################
step "should allow param class defaults to be overridden"
manifest = %q{
class x($y, $z='2') {
notice("${y}-${z}")
}
class {x: y => '1', z => '3'}
}
apply_manifest_on(agents, manifest) do |result|
fail_test "the override didn't happen as we expected" unless result.stdout.include? "1-3"
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/apply/classes/should_allow_param_override.rb | acceptance/tests/apply/classes/should_allow_param_override.rb | test_name "should allow param override"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
manifest = %q{
class parent {
notify { 'msg':
message => parent,
}
}
class child inherits parent {
Notify['msg'] {message => 'child'}
}
include parent
include child
}
apply_manifest_on(agents, manifest) do |result|
fail_test "parameter override didn't work" unless
result.stdout.include? "defined 'message' as 'child'"
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/lookup/v4_hieradata_with_v5_configs.rb | acceptance/tests/lookup/v4_hieradata_with_v5_configs.rb | test_name 'C99572: v4 hieradata with v5 configs' do
require 'puppet/acceptance/puppet_type_test_tools.rb'
extend Puppet::Acceptance::PuppetTypeTestTools
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
confdir = puppet_config(master, 'confdir', section: 'master')
hiera_conf_backup = master.tmpfile('C99572-hiera-yaml')
step "backup global hiera.yaml" do
on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1])
end
teardown do
step "restore global hiera.yaml" do
on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create global hiera.yaml and data" do
create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: "%{environment}"
data_hash: yaml_data
path: "%{environment}.yaml"
- name: common
data_hash: yaml_data
path: "common.yaml"
HIERA
on(master, "chmod 755 #{confdir}/hiera.yaml")
create_remote_file(master, "#{confdir}/#{tmp_environment}.yaml", <<-YAML)
---
environment_key: environment_key-global_env_file
global_key: global_key-global_env_file
YAML
create_remote_file(master, "#{confdir}/common.yaml", <<-YAML)
---
environment_key: environment_key-global_common_file
global_key: global_key-global_common_file
YAML
end
step "create environment hiera.yaml and data" do
on(master, "mkdir -p #{fq_tmp_environmentpath}/data")
create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: "%{environment}"
data_hash: yaml_data
path: "%{environment}.yaml"
- name: common
data_hash: yaml_data
path: "common.yaml"
- name: hocon
data_hash: hocon_data
path: "common.conf"
HIERA
create_remote_file(master, "#{fq_tmp_environmentpath}/data/#{tmp_environment}.yaml", <<-YAML)
---
environment_key: "environment_key-env_file"
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/data/common.yaml", <<-YAML)
---
environment_key: "environment_key-common_file"
global_key: "global_key-common_file"
YAML
step "C99628: add hocon backend and data" do
create_remote_file(master, "#{fq_tmp_environmentpath}/data/common.conf", <<-HOCON)
environment_key2 = "hocon value",
HOCON
end
create_sitepp(master, tmp_environment, <<-SITE)
notify { "${lookup('environment_key')}": }
notify { "${lookup('global_key')}": }
notify { "${lookup('environment_key2')}": }
SITE
on(master, "chmod -R 755 #{fq_tmp_environmentpath}")
end
step 'assert lookups using lookup subcommand' do
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "1: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/environment_key-env_file/, result.stdout,
'lookup environment_key subcommand didn\'t find correct key')
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'global_key'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "2: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/global_key-common_file/, result.stdout,
'lookup global_key subcommand didn\'t find correct key')
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "3: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/hocon value/, result.stdout,
'lookup environment_key2 subcommand didn\'t find correct key')
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step 'agent lookup' do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/global_key-common_file/m, result.stdout,
'agent lookup didn\'t find global key')
assert_match(/environment_key-env_file/m, result.stdout,
'agent lookup didn\'t find environment_key')
assert_match(/hocon value/m, result.stdout,
'agent lookup didn\'t find environment_key2')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/lookup/merge_strategies.rb | acceptance/tests/lookup/merge_strategies.rb | test_name 'C99903: merge strategies' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type + '1')
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
tmp_environment2 = mk_tmp_environment_with_teardown(master, app_type + '2')
fq_tmp_environmentpath2 = "#{environmentpath}/#{tmp_environment2}"
master_confdir = puppet_config(master, 'confdir', section: 'master')
hiera_conf_backup = master.tmpfile(app_type)
teardown do
step "restore default global hiera.yaml" do
on(master, "mv #{hiera_conf_backup} #{master_confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create global hiera.yaml and environment data" do
step "backup global hiera.yaml" do
on(master, "cp -a #{master_confdir}/hiera.yaml #{hiera_conf_backup}")
end
create_remote_file(master, "#{master_confdir}/hiera.yaml", <<-HIERA)
---
:backends:
- yaml
:yaml:
:datadir: "/etc/puppetlabs/code/environments/%{::environment}/hieradata"
:hierarchy:
- "host"
- "roles"
- "profiles"
- "%{facts.os.name}"
- "%{facts.os.family}"
- "%{facts.kernel}"
- "common"
:merge_behavior: deeper
:deep_merge_options:
:merge_hash_arrays: true
HIERA
on(master, "chown puppet:puppet #{master_confdir}/hiera.yaml")
on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/")
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/host.yaml", <<-YAML)
---
profiles:
webserver:
apache:
httpd:
modules:
- mpm_prefork
- php
- ssl
arrayed_hash:
the_hash:
- array1:
key1: val1
key2: val2
array:
- foo
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/profiles.yaml", <<-YAML)
profiles:
webserver:
apache:
httpd:
modules:
- auth_kerb
- authnz_ldap
- cgid
- php
- status
array:
- bar
YAML
create_sitepp(master, tmp_environment, <<-SITE)
notify { "hiera_hash: ${hiera_hash ('profiles')['webserver']['apache']['httpd']['modules']}": }
notify { "lookup1: ${lookup ('profiles')['webserver']['apache']['httpd']['modules']}": }
notify { "lookup1b: ${lookup ({'name' => 'profiles', 'merge' => 'deep'})['webserver']['apache']['httpd']['modules']}": }
notify { "hiera_merge_hash: ${hiera_hash ('arrayed_hash')}": }
notify { "lookup_arrayed_hash: ${lookup ({'name' => 'arrayed_hash', 'merge' => {'strategy' => 'deep', 'merge_hash_arrays' => true}})}": }
notify { "hiera-array: ${hiera ('array')}": }
notify { "hiera_array: ${hiera_array ('array')}": }
notify { "lookup-array: ${lookup ('array')}": }
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath}")
end
step "create another environment, hiera5 config and environment data: #{tmp_environment2}" do
create_remote_file(master, "#{fq_tmp_environmentpath2}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: "%{environment}/host"
data_hash: yaml_data
path: "hieradata/host.yaml"
- name: "%{environment}/profiles"
data_hash: yaml_data
path: "hieradata/profiles.yaml"
HIERA
on(master, "mkdir -p #{fq_tmp_environmentpath2}/hieradata/")
create_remote_file(master, "#{fq_tmp_environmentpath2}/hieradata/host.yaml", <<-YAML)
---
profiles:
webserver:
apache:
httpd:
modules:
- mpm_prefork
- php
- ssl
arrayed_hash:
the_hash:
- array1:
key1: val1
key2: val2
array:
- foo
lookup_options:
'profiles':
merge:
strategy: deep
YAML
create_remote_file(master, "#{fq_tmp_environmentpath2}/hieradata/profiles.yaml", <<-YAML)
profiles:
webserver:
apache:
httpd:
modules:
- auth_kerb
- authnz_ldap
- cgid
- php
- status
array:
- bar
lookup_options:
'profiles':
merge:
strategy: deep
YAML
create_sitepp(master, tmp_environment2, <<-SITE)
notify { "hiera_hash: ${hiera_hash ('profiles')['webserver']['apache']['httpd']['modules']}": }
notify { "lookup2: ${lookup ('profiles')['webserver']['apache']['httpd']['modules']}": }
notify { "lookup2b: ${lookup ({'name' => 'profiles', 'merge' => 'first'})['webserver']['apache']['httpd']['modules']}": }
notify { "hiera_merge_hash: ${hiera_hash ('arrayed_hash')}": }
notify { "lookup_arrayed_hash: ${lookup ({'name' => 'arrayed_hash', 'merge' => {'strategy' => 'deep', 'merge_hash_arrays' => true}})}": }
notify { "hiera-array: ${hiera ('array')}": }
notify { "hiera_array: ${hiera_array ('array')}": }
notify { "lookup-array: ${lookup ('array')}": }
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath2}")
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookups #{agent.hostname}, hiera3" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
# hiera_hash will honor old global merge strategies, which were a bad idea
assert_match(/hiera_hash: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout,
"1: agent hiera_hash didn't find correct key")
# so, lookup doesn't honor them except on a by-key or by-lookup basis
assert_match(/lookup1: \[mpm_prefork, php, ssl\]/, result.stdout,
"1: agent lookup didn't find correct key")
assert_match(/lookup1b: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout,
"1b: agent lookup didn't find correct key")
assert_match(/hiera_merge_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout,
"agent hiera_hash 1 merge_hash_arrays didn't work properly")
assert_match(/lookup_arrayed_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout,
"agent lookup 1 deep merge with merge_hash_arrays didn't work properly")
assert_match(/hiera-array: \[foo\]/, result.stdout,
"hiera() lookup of an array with deeper should be merged")
assert_match(/hiera_array: \[foo, bar\]/, result.stdout,
"hiera_array() lookup of an array should be merged")
assert_match(/lookup-array: \[foo\]/, result.stdout,
"lookup() lookup of an array should default to first")
end
end
step "agent lookups #{agent.hostname}, hiera5" do
on(agent, puppet('agent', "-t --environment #{tmp_environment2}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/hiera_hash: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout,
"2: agent hiera_hash didn't find correct key")
assert_match(/lookup2: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout,
"2: agent lookup didn't find correct key")
assert_match(/lookup2b: \[mpm_prefork, php, ssl\]/, result.stdout,
"2b: agent lookup didn't find correct key")
assert_match(/hiera_merge_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout,
"agent hiera_hash 2 merge_hash_arrays didn't work properly")
assert_match(/lookup_arrayed_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout,
"agent lookup 2 deep merge with merge_hash_arrays didn't work properly")
assert_match(/hiera-array: \[foo\]/, result.stdout,
"hiera() 2 lookup in hiera5 of an array should default to first")
assert_match(/hiera_array: \[foo, bar\]/, result.stdout,
"hiera_array() 2 lookup of an array should be merged")
assert_match(/lookup-array: \[foo\]/, result.stdout,
"lookup() 2 lookup in hiera5 of an array should default to first")
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/lookup/config5_interpolation.rb | acceptance/tests/lookup/config5_interpolation.rb | test_name 'C99578: hiera5 lookup config with interpolated scoped nested variables' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # This test specifically tests interpolation on the master.
# Recommend adding an additonal test that validates
# lookup in a masterless setup.
'server'
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type + '1')
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create environment hiera5.yaml and environment data" do
create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA)
---
version: 5
defaults:
datadir: 'hieradata'
data_hash: yaml_data
hierarchy:
- name: "Global settings"
path: "global.yaml"
- name: "Role specific settings"
paths:
- "roles/%{::roles.0}.yaml"
- name: "Other Role specific settings"
paths:
- "roles/%{roles2.0}.yaml"
- name: "scoped variable"
paths:
- "roles/%{::myclass::myvar.0}.yaml"
- name: "nested hash variable"
paths:
- "roles/%{::hash_array.key1.0}.yaml"
HIERA
on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/roles")
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/global.yaml", <<-YAML)
roles:
- test1
roles2:
- test2
data:
- "from global"
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test1.yaml", <<-YAML)
data:
- 'from test1'
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test2.yaml", <<-YAML)
data:
- 'from test2'
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test3.yaml", <<-YAML)
data:
- 'from test3'
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test4.yaml", <<-YAML)
data:
- 'from test4'
YAML
create_sitepp(master, tmp_environment, <<-SITE)
class myclass {
$myvar = ['test3']
}
include myclass
$hash_array = {key1 => ['test4']}
$roles = lookup('roles')
$data = lookup('data', Array[String], 'unique')
notify{"data: ${data}":}
$hiera_array_data = hiera_array('data')
notify{"hiera_array_data: ${hiera_array_data}":}
$roles2 = lookup('roles2')
$data2 = lookup('data', Array[String], 'unique')
notify{"data2: ${data2}":}
$hiera_array_data2 = hiera_array('data')
notify{"hiera_array_data2: ${hiera_array_data2}":}
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath}")
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookups: #{agent.hostname}, hiera5" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/data: \[from global, from test1/, result.stdout,
"agent lookup didn't interpolate with hiera value")
assert_match(/hiera_array_data: \[from global, from test1/, result.stdout,
"agent hiera_array didn't interpolate with hiera value")
assert_match(/data2: \[from global, from test1, from test2/, result.stdout,
"agent lookup didn't interpolate non-global scope with hiera value")
assert_match(/hiera_array_data2: \[from global, from test1, from test2/, result.stdout,
"agent hiera_array didn't interpolate non-global scope with hiera value")
assert_match(/data2: \[from global, from test1, from test2, from test3/, result.stdout,
"agent lookup didn't interpolate class scope with hiera value")
assert_match(/hiera_array_data2: \[from global, from test1, from test2, from test3/, result.stdout,
"agent hiera_array didn't interpolate class scope with hiera value")
assert_match(/data2: \[from global, from test1, from test2, from test3, from test4\]/, result.stdout,
"agent lookup didn't interpolate nested hashes with hiera value")
assert_match(/hiera_array_data2: \[from global, from test1, from test2, from test3, from test4\]/, result.stdout,
"agent hiera_array didn't interpolate nested hashes with hiera value")
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/lookup/lookup_rich_values.rb | acceptance/tests/lookup/lookup_rich_values.rb | test_name 'C99044: lookup should allow rich data as values' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local environment.
'server'
# The following two lines are required for the puppetserver service to
# start correctly. These should be removed when PUP-7102 is resolved.
confdir = puppet_config(master, 'confdir', section: 'master')
on(master, "chown puppet:puppet #{confdir}/hiera.yaml")
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
sensitive_value_rb = 'foot, no mouth'
sensitive_value_pp = 'toe, no step'
sensitive_value_pp2 = 'toe, no module'
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create ruby lookup function in #{tmp_environment}" do
on(master, "mkdir -p #{fq_tmp_environmentpath}/lib/puppet/functions/environment")
create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: Test
data_hash: rich_data_test
- name: Test2
data_hash: some_mod::rich_data_test2
- name: Test3
data_hash: rich_data_test3
HIERA
create_remote_file(master, "#{fq_tmp_environmentpath}/lib/puppet/functions/rich_data_test.rb", <<-FUNC)
Puppet::Functions.create_function(:rich_data_test) do
def rich_data_test(options, context)
rich_type_instance = Puppet::Pops::Types::PSensitiveType::Sensitive.new("#{sensitive_value_rb}")
{
'environment_key' => rich_type_instance,
}
end
end
FUNC
end
step "create puppet language lookup function in #{tmp_environment} module" do
on(master, "mkdir -p #{fq_tmp_environmentpath}/modules/some_mod/functions")
create_remote_file(master, "#{fq_tmp_environmentpath}/modules/some_mod/functions/rich_data_test2.pp", <<-FUNC)
function some_mod::rich_data_test2($options, $context) {
{
"environment_key2" => Sensitive('#{sensitive_value_pp}'),
}
}
FUNC
on(master, "chmod -R a+rw #{fq_tmp_environmentpath}")
end
step "C99571: create puppet language lookup function in #{tmp_environment}" do
on(master, "mkdir -p #{fq_tmp_environmentpath}/functions")
create_remote_file(master, "#{fq_tmp_environmentpath}/functions/rich_data_test3.pp", <<-FUNC)
function rich_data_test3($options, $context) {
{
"environment_key3" => Sensitive('#{sensitive_value_pp2}'),
}
}
FUNC
on(master, "chmod -R a+rw #{fq_tmp_environmentpath}")
end
step "create site.pp which calls lookup on our keys" do
create_sitepp(master, tmp_environment, <<-SITE)
notify { "${unwrap(lookup('environment_key'))}": }
notify { "${unwrap(lookup('environment_key2'))}": }
notify { "${unwrap(lookup('environment_key3'))}": }
SITE
end
step 'assert lookups using lookup subcommand' do
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "lookup subcommand using ruby function didn't exit properly: (#{result.exit_code})")
assert_match(sensitive_value_rb, result.stdout,
"lookup subcommand using ruby function didn't find correct key")
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "lookup subcommand using puppet function in module didn't exit properly: (#{result.exit_code})")
assert_match(sensitive_value_pp, result.stdout,
"lookup subcommand using puppet function in module didn't find correct key")
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key3'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "lookup subcommand using puppet function didn't exit properly: (#{result.exit_code})")
assert_match(sensitive_value_pp2, result.stdout,
"lookup subcommand using puppet function didn't find correct key")
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookup in ruby function" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup using ruby function didn't exit properly: (#{result.exit_code})")
assert_match(sensitive_value_rb, result.stdout,
"agent lookup using ruby function didn't find correct key")
assert_match(sensitive_value_pp, result.stdout,
"agent lookup using puppet function in module didn't find correct key")
assert_match(sensitive_value_pp2, result.stdout,
"agent lookup using puppet function didn't find correct key")
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/lookup/lookup.rb | acceptance/tests/lookup/lookup.rb | test_name "Lookup data using the agnostic lookup function" do
# pre-docs:
# https://puppet-on-the-edge.blogspot.com/2015/01/puppet-40-data-in-modules-and.html
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
# Use mk_tmp_environment_with_teardown to create environment.
'server'
testdir = master.tmpdir('lookup')
module_name = "data_module"
module_name2 = "other_module"
hash_name = "hash_name"
array_key = "array_key"
env_data_implied_key = "env_data_implied"
env_data_implied_value = "env_implied_a"
env_data_key = "env_data"
env_data_value = "env_a"
env_hash_key = "env_hash_key"
env_hash_value = "env_class_a"
env_array_value0 = "env_array_a"
env_array_value1 = "env_array_b"
module_data_implied_key = "module_data_implied"
module_data_implied_value = "module_implied_b"
module_data_key = "module_data"
module_data_value = "module_b"
module_data_value_other = "other_module_b"
module_hash_key = "module_hash_key"
module_hash_value = "module_class_b"
module_array_value0 = "module_array_a"
module_array_value1 = "module_array_b"
env_data_override_implied_key = "env_data_override_implied"
env_data_override_implied_value = "env_override_implied_c"
env_data_override_key = "env_data_override"
env_data_override_value = "env_override_c"
hiera_data_implied_key = "apache_server_port_implied"
hiera_data_implied_value = "8080"
hiera_data_key = "apache_server_port"
hiera_data_value = "9090"
hiera_hash_key = "hiera_hash_key"
hiera_hash_value = "hiera_class_c"
hiera_array_value0 = "hiera_array_a"
hiera_array_value1 = "hiera_array_b"
automatic_data_key = "automatic_data_key"
automatic_data_value = "automatic_data_value"
automatic_default_value = "automatic_default_value"
def mod_manifest_entry(module_name = nil, testdir, module_data_implied_key,
module_data_implied_value, module_data_key,
module_data_value, hash_name, module_hash_key,
module_hash_value, array_key, module_array_value0,
module_array_value1)
if module_name
module_files_manifest = <<PP
# the function to provide data for this module
file { '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/functions/#{module_name}/data.rb':
ensure => file,
content => "
Puppet::Functions.create_function(:'#{module_name}::data') do
def data()
{ '#{module_name}::#{module_data_implied_key}' => '#{module_data_implied_value}',
'#{module_name}::#{module_data_key}' => '#{module_data_value}',
'#{module_name}::#{hash_name}' => {'#{module_hash_key}' => '#{module_hash_value}'},
'#{module_name}::#{array_key}' => ['#{module_array_value0}', '#{module_array_value1}']
}
end
end
",
mode => "0640",
}
PP
module_files_manifest
end
end
def mod_manifest_metadata_json(module_name = nil, testdir)
if module_name
<<PPmetadata
file { '#{testdir}/environments/production/modules/#{module_name}/metadata.json':
ensure => file,
content => '
{
"name": "tester-#{module_name}",
"version": "0.1.0",
"author": "tester",
"summary": null,
"license": "Apache-2.0",
"source": "",
"project_page": null,
"issues_url": null,
"dependencies": [
],
"data_provider": "function"
}
',
mode => "0644",
}
file { '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings':
ensure => absent,
force => true,
}
PPmetadata
end
end
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
module_manifest1 = mod_manifest_entry(module_name, testdir, module_data_implied_key,
module_data_implied_value, module_data_key, module_data_value,
hash_name, module_hash_key, module_hash_value, array_key,
module_array_value0, module_array_value1)
module_manifest2 = mod_manifest_entry(module_name2, testdir, module_data_implied_key,
module_data_implied_value, module_data_key, module_data_value_other,
hash_name, module_hash_key, module_hash_value, array_key,
module_array_value0, module_array_value1)
metadata_manifest1 = mod_manifest_metadata_json(module_name, testdir)
metadata_manifest2 = mod_manifest_metadata_json(module_name2, testdir)
apply_manifest_on(master, <<-PP, :catch_failures => true)
File {
ensure => directory,
mode => "0750",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}':;
'#{testdir}/hieradata':;
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/production/modules':;
'#{testdir}/environments/production/lib':;
'#{testdir}/environments/production/lib/puppet':;
'#{testdir}/environments/production/lib/puppet/functions':;
'#{testdir}/environments/production/lib/puppet/functions/environment':;
'#{testdir}/environments/production/modules/#{module_name}':;
'#{testdir}/environments/production/modules/#{module_name}/manifests':;
'#{testdir}/environments/production/modules/#{module_name}/lib':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings/#{module_name}':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet/functions':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet/functions/#{module_name}':;
'#{testdir}/environments/production/modules/#{module_name2}':;
'#{testdir}/environments/production/modules/#{module_name2}/manifests':;
'#{testdir}/environments/production/modules/#{module_name2}/lib':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/bindings':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/bindings/#{module_name2}':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/functions':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/functions/#{module_name2}':;
}
file { '#{testdir}/hiera.yaml':
ensure => file,
content => '---
:backends:
- "yaml"
:logger: "console"
:hierarchy:
- "global"
:yaml:
:datadir: "#{testdir}/hieradata"
',
mode => "0640",
}
file { '#{testdir}/hieradata/global.yaml':
ensure => file,
content => "---
#{hiera_data_key}: #{hiera_data_value}
#{module_name}::#{hiera_data_implied_key}: #{hiera_data_implied_value}
#{module_name}::#{hash_name}:
#{hiera_hash_key}: #{hiera_hash_value}
#{module_name}::#{array_key}:
- #{hiera_array_value0}
- #{hiera_array_value1}
#{module_name}::#{automatic_data_key}: #{automatic_data_value}
",
mode => "0640",
}
file { '#{testdir}/environments/production/environment.conf':
ensure => file,
content => '
environment_timeout = 0
# for this environment, provide our own function to supply data to lookup
# implies a ruby function in <environment>/lib/puppet/functions/environment/data.rb
# named environment::data()
environment_data_provider = "function"
',
mode => "0640",
}
# the function to provide data for this environment
file { '#{testdir}/environments/production/lib/puppet/functions/environment/data.rb':
ensure => file,
content => "
Puppet::Functions.create_function(:'environment::data') do
def data()
{ '#{module_name}::#{env_data_implied_key}' => '#{env_data_implied_value}',
'#{module_name}::#{env_data_override_implied_key}' => '#{env_data_override_implied_value}',
'#{env_data_key}' => '#{env_data_value}',
'#{module_name}::#{hash_name}' => {'#{env_hash_key}' => '#{env_hash_value}'},
'#{env_data_override_key}' => '#{env_data_override_value}',
'#{module_name}::#{array_key}' => ['#{env_array_value0}', '#{env_array_value1}']
}
end
end
",
mode => "0640",
}
# place module file segments here
#{module_manifest1}
# same key, different module and values
#{module_manifest2}
file { '#{testdir}/environments/production/modules/#{module_name}/manifests/init.pp':
ensure => file,
content => '
class #{module_name}($#{env_data_implied_key},
$#{module_data_implied_key},
$#{env_data_override_implied_key},
$#{hiera_data_implied_key},
$#{automatic_data_key}=$#{automatic_default_value}) {
# lookup data from the environment function databinding
notify { "#{env_data_implied_key} $#{env_data_implied_key}": }
$lookup_env = lookup("#{env_data_key}")
notify { "#{env_data_key} $lookup_env": }
# lookup data from the module databinding
notify { "#{module_data_implied_key} $#{module_data_implied_key}": }
$lookup_module = lookup("#{module_name}::#{module_data_key}")
notify { "#{module_data_key} $lookup_module": }
# lookup data from another modules databinding
$lookup_module2 = lookup("#{module_name2}::#{module_data_key}")
notify { "#{module_data_key} $lookup_module2": }
# ensure env can override module
notify { "#{env_data_override_implied_key} $#{env_data_override_implied_key}": }
$lookup_override = lookup("#{env_data_override_key}")
notify { "#{env_data_override_key} $lookup_override": }
# should fall-back to hiera global.yaml data
notify { "#{hiera_data_implied_key} $#{hiera_data_implied_key}": }
$lookup_port = lookup("#{hiera_data_key}")
notify { "#{hiera_data_key} $lookup_port": }
# should be able to merge hashes across sources
# this mimicks/covers behavior for including classes
$lookup_hash = lookup("#{module_name}::#{hash_name}",Hash[String,String],\\'hash\\')
notify { "#{hash_name} $lookup_hash": }
# should be able to make an array across sources
# this mimicks/covers behavior for including classes
$lookup_array = lookup("#{module_name}::#{array_key}",Array[String],\\'unique\\')
notify { "yep": message => "#{array_key} $lookup_array" }
# automatic data lookup of parametrized class
notify { "#{automatic_data_key} $#{automatic_data_key}": }
}',
mode => "0640",
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
content => "
node default {
include #{module_name}
}",
mode => "0640",
}
PP
apply_manifest_on(master, <<-PP, :catch_failures => true)
#{metadata_manifest1}
#{metadata_manifest2}
PP
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
'hiera_config' => "#{testdir}/hiera.yaml",
},
}
with_puppet_running_on master, master_opts, testdir do
step "Lookup string data, binding specified in metadata.json" do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [0, 2]) do |result|
assert_match("#{env_data_implied_key} #{env_data_implied_value}", result.stdout)
assert_match("#{env_data_key} #{env_data_value}", result.stdout)
assert_match("#{module_data_implied_key} #{module_data_implied_value}", result.stdout)
assert_match("#{module_data_key} #{module_data_value}", result.stdout)
assert_match("#{module_data_key} #{module_data_value_other}", result.stdout)
assert_match("#{env_data_override_implied_key} #{env_data_override_implied_value}", result.stdout)
assert_match("#{env_data_override_key} #{env_data_override_value}", result.stdout)
assert_match("#{hiera_data_implied_key} #{hiera_data_implied_value}", result.stdout)
assert_match("#{hiera_data_key} #{hiera_data_value}", result.stdout)
assert_match("#{hash_name} {#{module_hash_key} => #{module_hash_value}, #{env_hash_key} => #{env_hash_value}, #{hiera_hash_key} => #{hiera_hash_value}}", result.stdout)
assert_match("#{array_key} [#{hiera_array_value0}, #{hiera_array_value1}, #{env_array_value0}, #{env_array_value1}, #{module_array_value0}, #{module_array_value1}]", result.stdout)
assert_match("#{automatic_data_key} #{automatic_data_value}", result.stdout)
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/lookup/v3_config_and_data.rb | acceptance/tests/lookup/v3_config_and_data.rb | test_name 'C99629: hiera v5 can use v3 config and data' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
hiera_conf_backup = master.tmpfile('C99629-hiera-yaml')
step "create hiera v3 global config and data" do
confdir = puppet_config(master, 'confdir', section: 'master')
step "backup global hiera.yaml" do
on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1])
end
teardown do
step "restore global hiera.yaml" do
on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create global hiera.yaml and module data" do
create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA)
---
:backends:
- "yaml"
- "json"
- "hocon"
:hierarchy:
- "somesuch"
- "common"
HIERA
on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/")
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.yaml", <<-YAML)
---
environment_key1: "env value1"
environment_key3: "env value3"
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.json", <<-JSON)
{
"environment_key1" : "wrong value",
"environment_key2" : "env value2"
}
JSON
step "C99628: add hocon backend and data" do
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.conf", <<-HOCON)
environment_key4 = "hocon value",
HOCON
end
create_sitepp(master, tmp_environment, <<-SITE)
notify { "${lookup('environment_key1')}": }
notify { "${lookup('environment_key2')}": }
notify { "${lookup('environment_key3')}": }
notify { "${lookup('environment_key4')}": }
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath}")
on(master, "chmod -R 775 #{confdir}")
end
end
step 'assert lookups using lookup subcommand' do
step 'assert lookup --explain using lookup subcommand' do
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key1 --explain'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "1: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/env value1/, result.stdout,
"1: lookup subcommand didn't find correct key")
assert_match(/hiera configuration version 3/, result.stdout,
"hiera config version not reported properly")
assert_match(/#{fq_tmp_environmentpath}\/hieradata\/somesuch\.yaml/, result.stdout,
"hiera hierarchy abs path not reported properly")
assert_match(/path: "somesuch"/, result.stdout,
"hiera hierarchy path not reported properly")
end
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "2: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/env value2/, result.stdout,
"2: lookup subcommand didn't find correct key")
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key3'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "3: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/env value3/, result.stdout,
"3: lookup subcommand didn't find correct key")
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key4'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "4: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/hocon value/, result.stdout,
"4: lookup subcommand didn't find correct key")
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookup" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/env value1/, result.stdout,
"1: agent lookup didn't find correct key")
assert_match(/env value2/, result.stdout,
"2: agent lookup didn't find correct key")
assert_match(/env value3/, result.stdout,
"3: agent lookup didn't find correct key")
assert_match(/hocon value/, result.stdout,
"4: agent lookup didn't find correct key")
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/lookup/config3_interpolation.rb | acceptance/tests/lookup/config3_interpolation.rb | test_name 'C99578: lookup should allow interpolation in hiera3 configs' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # This test specifically tests interpolation on the master.
# Recommend adding an additonal test that validates
# lookup in a masterless setup.
'server'
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
master_confdir = puppet_config(master, 'confdir', section: 'master')
hiera_conf_backup = master.tmpfile('C99578-hiera-yaml')
step "backup global hiera.yaml" do
on(master, "cp -a #{master_confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1])
end
teardown do
on(master, "mv #{hiera_conf_backup} #{master_confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create hiera configs in #{tmp_environment} and global" do
step "create global hiera.yaml and module data" do
create_remote_file(master, "#{master_confdir}/hiera.yaml", <<-HIERA)
---
:backends:
- "yaml"
:hierarchy:
- "%{calling_class_path}"
- "%{calling_class}"
- "%{calling_module}"
- "common"
HIERA
on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/")
on(master, "mkdir -p #{fq_tmp_environmentpath}/modules/some_mod/manifests")
create_remote_file(master, "#{fq_tmp_environmentpath}/modules/some_mod/manifests/init.pp", <<-PP)
class some_mod {
notify { "${lookup('environment_key')}": }
}
PP
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/some_mod.yaml", <<-YAML)
---
environment_key: "env value"
YAML
create_sitepp(master, tmp_environment, <<-SITE)
include some_mod
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath}")
on(master, "chmod -R 775 #{master_confdir}")
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookup" do
on(agent, puppet('agent', "-t --environment #{tmp_environment} --debug"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/env value/, result.stdout,
"agent lookup didn't find correct key")
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/lookup/hiera3_custom_backend.rb | acceptance/tests/lookup/hiera3_custom_backend.rb | test_name 'C99630: hiera v3 custom backend' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/temp_file_utils.rb'
extend Puppet::Acceptance::TempFileUtils
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
puppetserver_config = "#{master['puppetserver-confdir']}/puppetserver.conf"
existing_loadpath = read_tk_config_string(on(master, "cat #{puppetserver_config}").stdout.strip)['jruby-puppet']['ruby-load-path'].first
confdir = puppet_config(master, 'confdir', section: 'master')
hiera_conf_backup = master.tmpfile('C99629-hiera-yaml')
step "backup global hiera.yaml" do
on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1])
end
teardown do
step 'delete custom backend, restore default hiera config' do
on(master, "rm #{existing_loadpath}/hiera/backend/custom_backend.rb", :acceptable_exit_codes => [0,1])
on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
on(master, "/opt/puppetlabs/server/bin/puppetserver gem uninstall --executables --force hiera")
on(master, "/opt/puppetlabs/puppet/bin/gem uninstall --executables --force hiera")
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "install hiera v3 gem" do
# for puppet agent <-> server, hiera must be installed using puppetserver's gem command
on(master, "/opt/puppetlabs/server/bin/puppetserver gem install --no-document hiera")
# for puppet lookup, hiera must be installed using puppet's gem command
on(master, "/opt/puppetlabs/puppet/bin/gem install --no-document hiera")
end
step "create hiera v5 config and v3 custom backend" do
on(master, "cp #{confdir}/hiera.yaml /tmp")
create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: Test
hiera3_backend: custom
HIERA
on(master, "chmod -R #{PUPPET_CODEDIR_PERMISSIONS} #{confdir}")
on(master, "mkdir -p #{existing_loadpath}/hiera/backend/")
custom_backend_rb = <<-RB
class Hiera
module Backend
class Custom_backend
def lookup(key, scope, order_override, resolution_type, context)
return 'custom value' unless (key == 'lookup_options')
end
end
end
end
RB
create_remote_file(master, "#{existing_loadpath}/hiera/backend/custom_backend.rb", custom_backend_rb)
on(master, "chmod #{PUPPET_CODEDIR_PERMISSIONS} #{existing_loadpath}/hiera/backend/custom_backend.rb")
end
step "create site.pp which calls lookup on our keys" do
create_sitepp(master, tmp_environment, <<-SITE)
notify { "${lookup('anykey')}": }
SITE
on(master, "chmod -R #{PUPPET_CODEDIR_PERMISSIONS} #{fq_tmp_environmentpath}")
end
step 'assert lookups using lookup subcommand on the master' do
on(master, puppet('lookup', "--environment #{tmp_environment}", '--explain', 'anykey'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/custom value/, result.stdout,
"lookup subcommand didn't find correct key")
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent manifest lookup on #{agent.hostname}" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/custom value/, result.stdout,
"agent lookup didn't find correct key")
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/enable_option_disable_i18n.rb | acceptance/tests/i18n/enable_option_disable_i18n.rb | test_name 'Verify that disable_i18n can be set to true and have translations disabled' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
step "configure server locale to #{language}" do
configure_master_system_locale(language)
end
tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*'))
step 'install a i18ndemo module' do
install_i18n_demo_module(master, tmp_environment)
end
disable_i18n_default_master = master.puppet['disable_i18n']
teardown do
step 'resetting the server locale' do
on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }"))
reset_master_system_locale
end
step 'uninstall the module' do
agents.each do |agent|
uninstall_i18n_demo_module(agent)
end
uninstall_i18n_demo_module(master)
end
end
agents.each do |agent|
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
on(master, puppet("config set disable_i18n false"))
reset_master_system_locale
end
step 'expect #{language} translation for a custom type' do
site_pp_content = <<-PP
node default {
i18ndemo_type { '12345': }
}
PP
create_sitepp(master, tmp_environment, site_pp_content)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, result.stderr, 'missing error from invalid value for custom type param')
end
end
step 'disable i18n' do
on(agent, puppet("config set disable_i18n true"))
on(master, puppet("config set disable_i18n true"))
reset_master_system_locale
end
step 'expect no #{language} translation for a custom type' do
site_pp_content = <<-PP
node default {
i18ndemo_type { '12345': }
}
PP
create_sitepp(master, tmp_environment, site_pp_content)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Error: .* Value 12345 is not a valid value for i18ndemo_type\:\:name/, result.stderr)
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/translation_fallback.rb | acceptance/tests/i18n/translation_fallback.rb | test_name 'C100560: puppet agent run output falls back to english when language not available' do
# No confines because even on non-translation supported OS' we should still fall back to english
tag 'audit:medium',
'audit:acceptance'
agents.each do |agent|
step 'Run Puppet apply with language Hungarian and check the output' do
unsupported_language='hu_HU'
on(agent, puppet("agent -t",
'ENV' => {'LANG' => unsupported_language, 'LANGUAGE' => ''})) do |apply_result|
assert_match(/Applying configuration version '[^']*'/, apply_result.stdout,
'agent run should default to english translation')
assert_match(/Applied catalog in [0-9.]* seconds/, apply_result.stdout,
'agent run should default to english translation')
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_resource.rb | acceptance/tests/i18n/modules/puppet_resource.rb | test_name 'C100572: puppet resource with module translates messages' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step "Run puppet resource for a module with language #{agent_language} and verify the translations" do
step 'puppet resource i18ndemo_type information contains translation' do
on(agent, puppet('resource i18ndemo_type', 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Warning: Puppet::Type::I18ndemo_type::ProviderRuby: \w+-i18ndemo type: i18ndemo_typeからの警告メッセージ/, result.stderr, 'missing translation of resource i18ndemo_type information')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_apply_module_lang.rb | acceptance/tests/i18n/modules/puppet_apply_module_lang.rb | test_name 'C100574: puppet apply using a module should translate messages in a language not supported by puppet' do
confine :except, :platform => /^windows/ # Can't print Finish on an English or Japanese code page
tag 'audit:medium',
'audit:acceptance'
skip_test('i18n test module uses deprecated function; update module to resume testing.')
# function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language='fi_FI'
agents.each do |agent|
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
type_path = agent.tmpdir('provider')
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
on(agent, "rm -rf '#{type_path}'")
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step "Run puppet apply of a module with language #{agent_language} and verify default english returned" do
step 'verify custom fact message translated and applied catalog message not translatated' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/i18ndemo_fact: tämä on korotus mukautetusta tosiasiasta \w+-i18ndemo/,
apply_result.stderr, 'missing translated message for raise from ruby fact')
assert_match(/Notice: Applied catalog in [0-9.]+ seconds/, apply_result.stdout, 'missing untranslated message for catalog applied')
end
end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved
step 'verify warning translated from init.pp' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning: .*I18ndemo-tiedoston luominen/, apply_result.stderr, 'missing translated warning from init.pp')
end
on(agent, puppet("apply -e \"class { 'i18ndemo': param1 => false }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error: .* tiedostoa ei voitu luoda./, apply_result.stderr, 'missing translated message for fail from init.pp')
end
end
step 'verify custom type messages translated' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Warning: .* Hyvä arvo i18ndemo_type::name/, apply_result.stderr, 'missing translated warning from custom type')
end
on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error: .* Arvo 12345 ei ole kelvollinen arvo i18ndemo_type::name/, apply_result.stderr, 'missing translated error from invalid value for custom type param')
end
end
step 'verify custom provider translation' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning: .* Onko i18ndemo_type olemassa\?/, apply_result.stderr, 'missing translated provider message')
end
end
step 'verify function string translation' do
on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Notice: --\*SE ON HAUSKAA AIKAA\*--/, apply_result.stdout, 'missing translated notice message')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_describe.rb | acceptance/tests/i18n/modules/puppet_describe.rb | test_name 'C100576: puppet describe with module type translates message' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step "Run puppet describe from a module with language #{agent_language} and verify the translations" do
on(agent, puppet('describe i18ndemo_type', 'ENV' => shell_env_language)) do |result|
assert_match(/\w+-i18ndemo type: dirパラメータは、検査するディレクトリパスをとります/, result.stdout, 'missing translation of dir parameter from i18ndemo_type')
assert_match(/\w+-i18ndemo type: nameパラメータには、大文字と小文字の変数A-Za-zが使用されます/, result.stdout, 'missing translation of name parameter from i18ndemo_type')
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_apply_unsupported_lang.rb | acceptance/tests/i18n/modules/puppet_apply_unsupported_lang.rb | test_name 'C100568: puppet apply of module for an unsupported language should fall back to english' do
tag 'audit:medium',
'audit:acceptance'
skip_test('i18n test module uses deprecated function; update module to resume testing.')
# function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
unsupported_language='hu_HU'
shell_env_language = { 'LANGUAGE' => unsupported_language, 'LANG' => unsupported_language }
agents.each do |agent|
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
type_path = agent.tmpdir('provider')
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
on(agent, "rm -rf '#{type_path}'")
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step "Run puppet apply of a module with language #{unsupported_language} and verify default english returned" do
step 'verify custom fact messages not translatated' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/.*i18ndemo_fact: this is a raise from a custom fact from \w+-i18ndemo/, apply_result.stderr, 'missing untranslated message for raise from ruby fact')
end
end
step 'verify warning not translated from init.pp' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning:.*Creating an i18ndemo file/, apply_result.stderr, 'missing untranslated warning from init.pp')
end
on(agent, puppet("apply -e \"class { 'i18ndemo': param1 => false }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error:.*Failed to create/, apply_result.stderr, 'missing untranslated message for fail from init.pp')
end
end
step 'verify custom type messages not translated' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Warning:.*Good value for i18ndemo_type::name/, apply_result.stderr, 'missing untranslated warning from custom type')
end
on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error:.*Value 12345 is not a valid value for i18ndemo_type::name/, apply_result.stderr, 'missing untranslated error from invalid value for custom type param')
end
end
step 'verify custom provider translation' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning:.* Does i18ndemo_type exist\?/, apply_result.stderr, 'missing untranslated provider message')
end
end
step 'verify function string translation' do
on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Notice: --\*IT'S HAPPY FUN TIME\*--/, apply_result.stdout, 'missing untranslated notice message')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_agent_cached_catalog.rb | acceptance/tests/i18n/modules/puppet_agent_cached_catalog.rb | test_name 'C100566: puppet agent with module should translate messages when using a cached catalog' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
skip_test('i18n test module uses deprecated function; update module to resume testing.')
# function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
disable_i18n_default_master = master.puppet['disable_i18n']
step 'enable i18n on master' do
on(master, puppet("config set disable_i18n false"))
end
step "configure server locale to #{language}" do
configure_master_system_locale(language)
end
tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*'))
step 'install a i18ndemo module' do
install_i18n_demo_module(master, tmp_environment)
end
teardown do
step 'resetting the server locale' do
on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }"))
reset_master_system_locale
end
step 'uninstall the module' do
agents.each do |agent|
uninstall_i18n_demo_module(agent)
end
uninstall_i18n_demo_module(master)
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
type_path = agent.tmpdir('provider')
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
agent.rm_rf(type_path)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
unresolved_server = 'puppet.unresolved.host.example.com'
step "Run puppet apply of a module with language #{agent_language} and verify the translations using the cached catalog" do
step 'verify custom fact translations' do
site_pp_content_1 = <<-PP
node default {
class { 'i18ndemo':
filename => '#{type_path}'
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_1)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact')
end
on(agent, puppet("agent -t --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact when using cached catalog')
end
end
step 'verify custom provider translation' do
site_pp_content_2 = <<-PP
node default {
i18ndemo_type { 'hello':
ensure => present,
dir => '#{type_path}',
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_2)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message')
end
on(agent, puppet("agent -t --server #{unresolved_server} --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message when using cached catalog')
end
end
step 'verify function string translation' do
site_pp_content_3 = <<-PP
node default {
notify { 'happy':
message => happyfuntime('happy')
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_3)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message')
end
on(agent, puppet("agent -t --server #{unresolved_server} --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message when using cached catalog')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_face.rb | acceptance/tests/i18n/modules/puppet_face.rb | test_name 'C100573: puppet application/face with module translates messages' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step "Run puppet i18ndemo (face/application from a module with language #{agent_language} and verify the translations" do
step 'puppet --help contains i18ndemo summary translation' do
on(agent, puppet('--help', 'ENV' => shell_env_language)) do |result|
assert_match(/\s*i18ndemo\s+\w+-i18ndemo face: I18ndemoモジュールの人形の顔の例/, result.stdout, 'missing translation of i18ndemo help summary')
end
end
step 'puppet i18ndemo --help contains test_face summary' do
on(agent, puppet('i18ndemo --help', 'ENV' => shell_env_language)) do |result|
assert_match(/\s*test_face\s+\w+-i18ndemo face: test_faceアクションのヘルプの要約/, result.stdout, 'missing translation of i18ndemo face help summary')
end
end
step 'puppet i18ndemo test_face contains translated warning' do
on(agent, puppet('i18ndemo', 'ENV' => shell_env_language)) do |result|
assert_match(/Warning: \w+-i18ndemo face: i18ndemo test_faceが呼び出されました/, result.stderr, 'missing translation of Warning message from i18ndemo face')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_apply.rb | acceptance/tests/i18n/modules/puppet_apply.rb | test_name 'C100567: puppet apply of module should translate messages' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
skip_test('i18n test module uses deprecated function; update module to resume testing.')
# function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
type_path = agent.tmpdir('provider')
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
on(agent, "rm -rf '#{type_path}'")
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step "Run puppet apply of a module with language #{agent_language} and verify the translations" do
step 'verify custom fact translations' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, apply_result.stderr, 'missing translation for raise from ruby fact')
end
end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved
step 'verify custom translations' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Warning:.*\w+-i18ndemo type: 良い値/, apply_result.stderr, 'missing warning from custom type')
end
on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, apply_result.stderr, 'missing error from invalid value for custom type param')
end
end
step 'verify custom provider translation' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, apply_result.stderr, 'missing translated provider message')
end
end
step 'verify function string translation' do
on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, apply_result.stdout, 'missing translated notice message')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_agent.rb | acceptance/tests/i18n/modules/puppet_agent.rb | test_name 'C100565: puppet agent with module should translate messages' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
skip_test('i18n test module uses deprecated function; update module to resume testing.')
# function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
disable_i18n_default_master = master.puppet['disable_i18n']
step 'enable i18n on master' do
on(master, puppet("config set disable_i18n false"))
end
step "configure server locale to #{language}" do
configure_master_system_locale(language)
end
tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*'))
step 'install a i18ndemo module' do
install_i18n_demo_module(master, tmp_environment)
end
teardown do
step 'resetting the server locale' do
on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }"))
reset_master_system_locale
end
step 'uninstall the module' do
agents.each do |agent|
uninstall_i18n_demo_module(agent)
end
uninstall_i18n_demo_module(master)
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
type_path = agent.tmpdir('provider')
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
agent.rm_rf(type_path)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step "Run puppet agent of a module with language #{agent_language} and verify the translations" do
step 'verify custom fact translations' do
site_pp_content_1 = <<-PP
node default {
class { 'i18ndemo':
filename => '#{type_path}'
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_1)
on(agent, puppet("agent -t --no-disable_i18n --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact')
end
end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved
step 'verify custom type translations' do
site_pp_content_2 = <<-PP
node default {
i18ndemo_type { 'hello': }
}
PP
create_sitepp(master, tmp_environment, site_pp_content_2)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Warning:.*\w+-i18ndemo type: 良い値/, result.stderr, 'missing warning from custom type')
end
site_pp_content_3 = <<-PP
node default {
i18ndemo_type { '12345': }
}
PP
create_sitepp(master, tmp_environment, site_pp_content_3)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, result.stderr, 'missing error from invalid value for custom type param')
end
end
step 'verify custom provider translation' do
site_pp_content_4 = <<-PP
node default {
i18ndemo_type { 'hello':
ensure => present,
dir => '#{type_path}',
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_4)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language)) do |result|
assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message')
end
end
step 'verify function string translation' do
site_pp_content_5 = <<-PP
node default {
notify { 'happy':
message => happyfuntime('happy')
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_5)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result|
assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/i18n/modules/puppet_agent_with_multiple_environments.rb | acceptance/tests/i18n/modules/puppet_agent_with_multiple_environments.rb | test_name 'C100575: puppet agent with different modules in different environments should translate based on their module' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
app_type_1 = File.basename(__FILE__, '.*') + "_env_1"
app_type_2 = File.basename(__FILE__, '.*') + "_env_2"
tmp_environment_1 = mk_tmp_environment_with_teardown(master, app_type_1)
tmp_environment_2 = mk_tmp_environment_with_teardown(master, app_type_2)
full_path_env_1 = File.join('/tmp', tmp_environment_1)
full_path_env_2 = File.join('/tmp', tmp_environment_2)
tmp_po_file = master.tmpfile('tmp_po_file')
disable_i18n_default_master = master.puppet['disable_i18n']
step 'enable i18n on master' do
on(master, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(master, tmp_environment_1)
install_i18n_demo_module(master, tmp_environment_2)
end
step "configure server locale to #{language}" do
configure_master_system_locale(language)
end
teardown do
on(master, "rm -f '#{tmp_po_file}'")
step 'uninstall the module' do
agents.each do |agent|
uninstall_i18n_demo_module(agent)
end
uninstall_i18n_demo_module(master)
end
step 'resetting the server locale' do
on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }"))
reset_master_system_locale
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
env_1_po_file = File.join(full_path_env_1, 'modules', I18NDEMO_NAME, 'locales', 'ja', "#{I18NDEMO_MODULE_NAME}.po")
on(master, "sed -e 's/\\(msgstr \"\\)\\([^\"]\\)/\\1'\"ENV_1\"':\\2/' #{env_1_po_file} > #{tmp_po_file} && mv #{tmp_po_file} #{env_1_po_file}")
env_2_po_file = File.join(full_path_env_2, 'modules', I18NDEMO_NAME, 'locales', 'ja', "#{I18NDEMO_MODULE_NAME}.po")
on(master, "sed -e 's/\\(msgstr \"\\)\\([^\"]\\)/\\1'\"ENV_2\"':\\2/' #{env_2_po_file} > #{tmp_po_file} && mv #{tmp_po_file} #{env_2_po_file}")
on(master, "chmod a+r '#{env_1_po_file}' '#{env_2_po_file}'")
step 'verify function string translation' do
site_pp_content = <<-PP
node default {
notify { 'happy':
message => happyfuntime('happy')
}
}
PP
create_sitepp(master, tmp_environment_1, site_pp_content)
on(agent, puppet("agent -t --environment #{tmp_environment_1}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result|
assert_match(/Notice: --\*(ENV_1:)?ENV_1:\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message for environment 1')
end
create_sitepp(master, tmp_environment_2, site_pp_content)
on(agent, puppet("agent -t --environment #{tmp_environment_2}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result|
assert_match(/Notice: --\*(ENV_2:)?ENV_2:\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message for environment 2')
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/reports/corrective_change_via_puppet.rb | acceptance/tests/reports/corrective_change_via_puppet.rb | test_name "C98094 - a resource changed via Puppet manifest will not be reported as a corrective change" do
require 'yaml'
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/agent_fqdn_utils'
extend Puppet::Acceptance::AgentFqdnUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # Uses a server currently, but is testing agent report
'broken:images',
'server'
test_file_name = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name)
tmp_file = {}
original_test_data = 'this is my original important data'
modified_test_data = 'this is my modified important data'
agents.each do |agent|
tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment)
end
teardown do
# Remove all traces of the last used environment
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
step 'clean out produced resources' do
agents.each do |agent|
if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != ''
on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)
end
end
end
end
def create_manifest_for_file_resource(file_resource, file_contents, environment_name)
manifest = <<-MANIFEST
file { '#{environmentpath}/#{environment_name}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$facts["networking"]["fqdn"] ? #{file_resource}
file { \$test_path:
content => @(UTF8)
#{file_contents}
| UTF8
}
',
}
MANIFEST
apply_manifest_on(master, manifest, :catch_failures => true)
end
step 'create file resource in site.pp' do
create_manifest_for_file_resource(tmp_file, original_test_data, tmp_environment)
end
step 'run agent(s) to create the new resource' do
with_puppet_running_on(master, {}) do
agents.each do |agent|
step 'Run agent once to create new File resource' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_contents|
assert_equal(original_test_data, file_contents, 'file contents did not match expected contents')
end
end
end
step 'Change the manifest for the resource' do
create_manifest_for_file_resource(tmp_file, modified_test_data, tmp_environment)
end
agents.each do |agent|
step 'Run agent a 2nd time to change the File resource' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_contents|
assert_equal(modified_test_data, file_contents, 'file contents did not match expected contents')
end
end
end
end
end
# Open last_run_report.yaml
step 'Check report' do
agents.each do |agent|
on(agent, puppet('config print statedir')) do |command_result|
report_path = command_result.stdout.chomp + '/last_run_report.yaml'
on(agent, "cat '#{report_path}'").stdout do |report_contents|
yaml_data = YAML::parse(report_contents)
# Remove any Ruby class tags from the yaml
yaml_data.root.each do |o|
if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby")
o.tag = nil
end
end
report_yaml = yaml_data.to_ruby
file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"]
assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing')
corrective_change_value = file_resource_details["corrective_change"]
assert_equal(false, corrective_change_value, 'corrective_change flag for the changed resource should be false')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/reports/cached_catalog_status_in_report.rb | acceptance/tests/reports/cached_catalog_status_in_report.rb | test_name "PUP-5867: The report specifies whether a cached catalog was used, and if so, why" do
tag 'audit:high',
'audit:integration',
'server'
master_reportdir = create_tmpdir_for_user(master, 'report_dir')
teardown do
on(master, "rm -rf #{master_reportdir}")
end
def remove_reports_on_master(master_reportdir, agent_node_name)
on(master, "rm -rf #{master_reportdir}/#{agent_node_name}/*")
end
with_puppet_running_on(master, :master => { :reportdir => master_reportdir, :reports => 'store' }) do
agents.each do |agent|
step "cached_catalog_status should be 'not used' when a new catalog is retrieved" do
step "Initial run: cache a newly retrieved catalog" do
on(agent, puppet("agent", "-t"), :acceptable_exit_codes => [0,2])
end
step "Run again and ensure report indicates that the cached catalog was not used" do
on(agent, puppet("agent", "--onetime", "--no-daemonize"), :acceptable_exit_codes => [0, 2])
on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result|
assert_match(/cached_catalog_status: not_used/, result.stdout, "expected to find 'cached_catalog_status: not_used' in the report")
end
remove_reports_on_master(master_reportdir, agent.node_name)
end
end
step "Run with --use_cached_catalog and ensure report indicates cached catalog was explicitly requested" do
on(agent, puppet("agent", "--onetime", "--no-daemonize", "--use_cached_catalog"), :acceptable_exit_codes => [0, 2])
on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result|
assert_match(/cached_catalog_status: explicitly_requested/, result.stdout, "expected to find 'cached_catalog_status: explicitly_requested' in the report")
end
remove_reports_on_master(master_reportdir, agent.node_name)
end
step "On a run which fails to retrieve a new catalog, ensure report indicates cached catalog was used on failure" do
on(agent, puppet("agent", "--onetime", "--no-daemonize", "--report_server #{master}", "--server nonexist"), :acceptable_exit_codes => [0, 2])
on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result|
assert_match(/cached_catalog_status: on_failure/, result.stdout, "expected to find 'cached_catalog_status: on_failure' in the report")
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/reports/corrective_change_outside_puppet.rb | acceptance/tests/reports/corrective_change_outside_puppet.rb | test_name "C98093 - a resource changed outside of Puppet will be reported as a corrective change" do
require 'yaml'
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/agent_fqdn_utils'
extend Puppet::Acceptance::AgentFqdnUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # Uses a server currently, but is testing agent report
'broken:images'
test_file_name = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name)
tmp_file = {}
agents.each do |agent|
tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment)
end
teardown do
step 'clean out produced resources' do
agents.each do |agent|
if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != ''
on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)
end
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
end
step 'create file resource - site.pp to verify corrective change flag' do
file_contents = 'this is a test'
manifest = <<-MANIFEST
file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$facts["networking"]["fqdn"] ? #{tmp_file}
file { \$test_path:
content => @(UTF8)
#{file_contents}
| UTF8
}
',
}
MANIFEST
apply_manifest_on(master, manifest, :catch_failures => true)
end
step 'run agent(s)' do
with_puppet_running_on(master, {}) do
agents.each do |agent|
#Run agent once to create new File resource
step 'Run agent once to create new File resource' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
#Verify the file resource is created
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result|
assert_equal(file_contents, file_result, 'file contents did not match accepted')
end
end
#Delete the file
step 'Delete the file' do
on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)
end
#Run agent to correct the file's absence
step 'Run agent to correct the files absence' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
#Verify the file resource is created
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result|
assert_equal(file_contents, file_result, 'file contents did not match accepted')
end
end
end
end
end
# Open last_run_report.yaml
step 'Check report' do
agents.each do |agent|
on(agent, puppet('config print statedir')) do |command_result|
report_path = command_result.stdout.chomp + '/last_run_report.yaml'
on(agent, "cat '#{report_path}'").stdout do |report_contents|
yaml_data = YAML::parse(report_contents)
# Remove any Ruby class tags from the yaml
yaml_data.root.each do |o|
if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby")
o.tag = nil
end
end
report_yaml = yaml_data.to_ruby
file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"]
assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing')
corrective_change_value = file_resource_details["corrective_change"]
assert_equal(true, corrective_change_value, 'corrective_change flag should be true')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/reports/submission.rb | acceptance/tests/reports/submission.rb | test_name "Report submission"
tag 'audit:high',
'audit:integration'
if master.is_pe?
require "time"
def puppetdb
hosts.detect { |h| h['roles'].include?('database') }
end
def sleep_until_queue_empty(timeout=60)
metric = "org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=com.puppetlabs.puppetdb.commands"
queue_size = nil
begin
Timeout.timeout(timeout) do
until queue_size == 0
result = on(puppetdb, %Q{curl http://localhost:8080/v3/metrics/mbean/#{CGI.escape(metric)}})
if md = /"?QueueSize"?\s*:\s*(\d+)/.match(result.stdout.chomp)
queue_size = Integer(md[1])
end
sleep 1
end
end
rescue Timeout::Error
raise "Queue took longer than allowed #{timeout} seconds to empty"
end
end
def query_last_report_time_on(agent)
time_query_script = <<-EOS
require "net/http"
require "json"
puppetdb_url = URI("http://localhost:8080/v3/reports")
puppetdb_url.query = CGI.escape(%Q{query=["=","certname","#{agent}"]})
result = Net::HTTP.get(puppetdb_url)
json = JSON.load(result)
puts json.first["receive-time"]
EOS
on(puppetdb, "#{master[:privatebindir]}/ruby -e '#{time_query_script}'").output.chomp
end
last_times = {}
agents.each do |agent|
last_times[agent] = query_last_report_time_on(agent)
end
with_puppet_running_on(master, {}) do
agents.each do |agent|
on(agent, puppet('agent', "-t"))
sleep_until_queue_empty
current_time = Time.parse(query_last_report_time_on(agent))
last_time = Time.parse(last_times[agent])
assert(current_time > last_time, "Most recent report time #{current_time} is not newer than last report time #{last_time}")
end
end
else
testdir = create_tmpdir_for_user master, 'report_submission'
teardown do
on master, "rm -rf #{testdir}"
end
with_puppet_running_on(master, :main => { :reportdir => testdir, :reports => 'store' }) do
agents.each do |agent|
on(agent, puppet('agent', "-t"))
on master, "grep -q #{agent.node_name} #{testdir}/*/*"
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/reports/corrective_change_new_resource.rb | acceptance/tests/reports/corrective_change_new_resource.rb | test_name "C98092 - a new resource should not be reported as a corrective change" do
require 'yaml'
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/agent_fqdn_utils'
extend Puppet::Acceptance::AgentFqdnUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # Uses a server currently but is testing agent report
'broken:images'
test_file_name = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name)
tmp_file = {}
agents.each do |agent|
tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment)
end
teardown do
step 'clean out produced resources' do
agents.each do |agent|
if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != ''
on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)
end
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
end
step 'create file resource - site.pp to verify corrective change flag' do
file_contents = 'this is a test'
manifest = <<-MANIFEST
file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$facts["networking"]["fqdn"] ? #{tmp_file}
file { \$test_path:
content => @(UTF8)
#{file_contents}
| UTF8
}
',
}
MANIFEST
apply_manifest_on(master, manifest, :catch_failures => true)
end
step 'run agent(s)' do
with_puppet_running_on(master, {}) do
agents.each do |agent|
#Run agent once to create new File resource
step 'Run agent once to create new File resource' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
#Verify the file resource is created
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result|
assert_equal(file_contents, file_result, 'file contents did not match accepted')
end
end
end
end
end
# Open last_run_report.yaml
step 'Check report' do
agents.each do |agent|
on(agent, puppet('config print statedir')) do |command_result|
report_path = command_result.stdout.chomp + '/last_run_report.yaml'
on(agent, "cat '#{report_path}'").stdout do |report_contents|
yaml_data = YAML::parse(report_contents)
# Remove any Ruby class tags from the yaml
yaml_data.root.each do |o|
if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby")
o.tag = nil
end
end
report_yaml = yaml_data.to_ruby
file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"]
assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing')
corrective_change_value = file_resource_details["corrective_change"]
assert_equal(false, corrective_change_value, 'corrective_change flag should be false')
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/reports/agent_sends_json_report_for_cached_catalog.rb | acceptance/tests/reports/agent_sends_json_report_for_cached_catalog.rb | test_name "C100533: Agent sends json report for cached catalog" do
tag 'risk:high',
'audit:high',
'audit:integration',
'server'
with_puppet_running_on(master, :main => {}) do
expected_format = 'json'
step "Perform agent run to ensure that catalog is cached" do
agents.each do |agent|
on(agent, puppet('agent', '-t'), :acceptable_exit_codes => [0,2])
end
end
step "Ensure agent sends #{expected_format} report for cached catalog" do
agents.each do |agent|
on(agent, puppet('agent', '-t',
'--http_debug'), :acceptable_exit_codes => [0,2]) do |res|
# Expected content-type should be in the headers of the
# HTTP report payload being PUT to the server by the agent.
unless res.stderr =~ /<- "PUT \/puppet\/v[3-9]\/report.*Content-Type: .*\/#{expected_format}/
fail_test("Report was not submitted in #{expected_format} format")
end
end
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/yum_semantic_versioning.rb | acceptance/tests/provider/package/yum_semantic_versioning.rb | test_name "yum provider should use semantic versioning for ensuring desired version" do
confine :to, :platform => /el-7/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = 'yum-utils'
lower_package_version = '1.1.31-34.el7'
middle_package_version = '1.1.31-42.el7'
higher_package_version = '1.1.31-45.el7'
agents.each do |agent|
yum_command = 'yum'
step "Setup: Skip test if box already has the package installed" do
on(agent, "rpm -q #{package}", :acceptable_exit_codes => [1,0]) do |result|
skip_test "package #{package} already installed on this box" unless result.output =~ /package #{package} is not installed/
end
end
step "Setup: Skip test if package versions are not available" do
on(agent, "yum list #{package} --showduplicates", :acceptable_exit_codes => [1,0]) do |result|
versions_available = [lower_package_version, middle_package_version, higher_package_version].all? {
|needed_versions| result.output.include? needed_versions }
skip_test "package #{package} versions not available on the box" unless versions_available
end
end
step "Using semantic versioning to downgrade to a desired version <= X" do
on(agent, "#{yum_command} install #{package} -y")
package_manifest = resource_manifest('package', package, { ensure: "<=#{lower_package_version}", provider: 'yum' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(/#{lower_package_version}/, installed_version)
end
# idempotency test
package_manifest = resource_manifest('package', package, { ensure: "<=#{lower_package_version}", provider: 'yum' } )
apply_manifest_on(agent, package_manifest, :catch_changes => true)
on(agent, "#{yum_command} remove #{package} -y")
end
step "Using semantic versioning to ensure a version >X <=Y" do
on(agent, "#{yum_command} install #{package} -y")
package_manifest = resource_manifest('package', package, { ensure: ">#{lower_package_version} <=#{higher_package_version}", provider: 'yum' } )
apply_manifest_on(agent, package_manifest) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(/#{higher_package_version}/, installed_version)
end
on(agent, "#{yum_command} remove #{package} -y")
end
step "Using semantic versioning to install a version >X <Y" do
package_manifest = resource_manifest('package', package, { ensure: ">#{lower_package_version} <#{higher_package_version}", provider: 'yum' } )
# installing a version >X <Y will install the highet version in between
apply_manifest_on(agent, package_manifest) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(/#{middle_package_version}/, installed_version)
end
on(agent, "#{yum_command} remove #{package} -y")
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/dpkg_hold_true_package_is_latest.rb | acceptance/tests/provider/package/dpkg_hold_true_package_is_latest.rb | test_name "dpkg ensure hold package is latest installed" do
confine :to, :platform => /debian-9-amd64/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "nginx"
agents.each do |agent|
teardown do
package_absent(agent, package, '--force-yes')
end
end
step"Ensure that package is installed first if not present" do
expected_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Candidate: //p'").stdout
package_manifest = resource_manifest('package', package, mark: "hold")
apply_manifest_on(agent, package_manifest) do |result|
installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout
assert_match(expected_package_version, installed_package_version)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/dnfmodule_enable_only.rb | acceptance/tests/provider/package/dnfmodule_enable_only.rb | test_name "dnfmodule can change flavors" do
confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
without_profile = '389-ds'
with_profile = 'swig'
agents.each do |agent|
skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream')
teardown do
apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'absent', provider: 'dnfmodule'))
apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'absent', provider: 'dnfmodule'))
end
end
step "Enable module with no default profile: #{without_profile}" do
apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'present', provider: 'dnfmodule'), expect_changes: true)
on(agent, "dnf module list --enabled | grep #{without_profile}")
end
step "Ensure idempotency for: #{without_profile}" do
apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'present', provider: 'dnfmodule'), catch_changes: true)
end
step "Enable module with a profile: #{with_profile}" do
apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', enable_only: true, provider: 'dnfmodule'), expect_changes: true)
on(agent, "dnf module list --enabled | grep #{with_profile}")
end
step "Ensure idempotency for: #{with_profile}" do
apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', enable_only: true, provider: 'dnfmodule'), catch_changes: true)
end
step "Install a flavor for: #{with_profile}" do
apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', flavor: 'common', provider: 'dnfmodule'), expect_changes: true)
on(agent, "dnf module list --installed | grep #{with_profile}")
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/dnfmodule_manages_flavors.rb | acceptance/tests/provider/package/dnfmodule_manages_flavors.rb | test_name "dnfmodule can change flavors" do
confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "postgresql"
agents.each do |agent|
skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream')
teardown do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'absent', provider: 'dnfmodule'))
end
end
step "Install the client #{package} flavor" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', flavor: 'client', provider: 'dnfmodule'))
on(agent, "dnf module list --installed | grep #{package} | sed -E 's/\\[d\\] //g'") do |output|
assert_match('client [i]', output.stdout, 'installed flavor not correct')
end
end
step "Install the server #{package} flavor" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', flavor: 'server', provider: 'dnfmodule'))
on(agent, "dnf module list --installed | grep #{package} | sed -E 's/\\[d\\] //g'") do |output|
assert_match('server [i]', output.stdout, 'installed flavor not correct')
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/dpkg_hold_true_should_preserve_version.rb | acceptance/tests/provider/package/dpkg_hold_true_should_preserve_version.rb | test_name "dpkg ensure hold package should preserve version if package is already installed" do
confine :to, :platform => /debian-9-amd64/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "openssl"
step "Ensure hold should lock to specific installed version" do
existing_installed_version = on(agent.name, "dpkg -s #{package} | sed -n -e 's/Version: //p'").stdout
existing_installed_version.delete!(' ')
package_manifest_hold = resource_manifest('package', package, mark: "hold")
apply_manifest_on(agent, package_manifest_hold) do
installed_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout
installed_version.delete!(' ')
assert_match(existing_installed_version, installed_version)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/puppetserver_gem.rb | acceptance/tests/provider/package/puppetserver_gem.rb | test_name "puppetserver_gem provider should install and uninstall" do
tag 'audit:high',
'server'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
skip_test 'puppetserver_gem is only suitable on server nodes' unless master
package = 'world_airports'
teardown do
# Ensure the gem is uninstalled if anything goes wrong
# TODO maybe execute this only if something fails, as it takes time
on(master, "puppetserver gem uninstall #{package}")
end
step "Installing a gem executes without error" do
package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'puppetserver_gem' } )
apply_manifest_on(master, package_manifest, catch_failures: true) do
list = on(master, "puppetserver gem list").stdout
assert_match(/#{package} \(/, list)
end
# Run again for idempotency
apply_manifest_on(master, package_manifest, catch_changes: true)
end
step "Uninstalling a gem executes without error" do
package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'puppetserver_gem' } )
apply_manifest_on(master, package_manifest, catch_failures: true) do
list = on(master, "puppetserver gem list").stdout
refute_match(/#{package} \(/, list)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/dnfmodule_ensure_versionable.rb | acceptance/tests/provider/package/dnfmodule_ensure_versionable.rb | test_name "dnfmodule is versionable" do
confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "postgresql"
agents.each do |agent|
skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream')
teardown do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'absent', provider: 'dnfmodule'))
end
end
step "Ensure we get the newer version by default" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', provider: 'dnfmodule'))
on(agent, 'postgres --version') do |version|
assert_match('postgres (PostgreSQL) 10', version.stdout, 'package version not correct')
end
end
step "Ensure we get a specific version if we want it" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: '9.6', provider: 'dnfmodule'))
on(agent, 'postgres --version') do |version|
assert_match('postgres (PostgreSQL) 9.6', version.stdout, 'package version not correct')
end
end
step "Ensure we can disable a package" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: :disabled, provider: 'dnfmodule'))
on(agent, "dnf module list | grep #{package}") do |output|
output.stdout.each_line do |line|
assert_match("\[x\]", line, 'package not disabled')
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/dpkg_ensure_latest_virtual_packages.rb | acceptance/tests/provider/package/dpkg_ensure_latest_virtual_packages.rb | test_name "dpkg ensure latest with allow_virtual set to true, the virtual package should detect and install a real package" do
confine :to, :platform => /debian/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
pkg = "rubygems"
agents.each do |agent|
ruby_present = on(agent, 'dpkg -s ruby', accept_all_exit_codes: true).exit_code == 0
teardown do
if ruby_present
apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'present'))
else
apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'absent'))
end
end
step "Uninstall system ruby if already present" do
apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'absent')) if ruby_present
end
step "Ensure latest should install ruby instead of rubygems when allow_virtual is set to true" do
package_manifest_with_allow_virtual = resource_manifest('package', pkg, ensure: 'latest', allow_virtual: true)
apply_manifest_on(agent, package_manifest_with_allow_virtual, expect_changes: true)
output = on(agent, "dpkg-query -W --showformat='${Status} ${Package} ${Version} [${Provides}]\n' ").output
lines = output.split("\n")
matched_line = lines.find { |package| package.match(/[\[ ](#{Regexp.escape(pkg)})[\],]/)}
package_line_info = matched_line.split
real_package_name = package_line_info[3]
real_package_installed_version = package_line_info[4]
installed_version = on(agent, "apt-cache policy #{real_package_name} | sed -n -e 's/Installed: //p'").stdout.strip
assert_match(real_package_installed_version, installed_version)
end
step "Ensure latest should not install ruby package if it's already installed and exit code should be 0" do
package_manifest_with_allow_virtual = resource_manifest('package', pkg, ensure: 'latest', allow_virtual: true)
apply_manifest_on(agent, package_manifest_with_allow_virtual, :catch_changes => true)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/pip.rb | acceptance/tests/provider/package/pip.rb | test_name "pip provider should install, use install_options with latest, and uninstall" do
confine :to, :template => /centos/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = 'colorize'
pip_command = 'pip'
teardown do
on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes", :accept_all_exit_codes => true)
end
agents.each do |agent|
step "Setup: Install EPEL Repository, Python and Pip" do
package_present(agent, 'epel-release')
if agent.platform =~ /el-8/
package_present(agent, 'python2')
package_present(agent, 'python2-pip')
pip_command = 'pip2'
else
package_present(agent, 'python')
package_present(agent, 'python-pip')
end
end
step "Ensure presence of a pip package" do
package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'pip' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout
assert_match(/#{package} \(/, list)
end
on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes")
end
step "Install a pip package using version range" do
package_manifest1 = resource_manifest('package', package, { ensure: '<=1.1.0', provider: 'pip' } )
package_manifest2 = resource_manifest('package', package, { ensure: '<1.0.4', provider: 'pip' } )
# Make a fresh package install (with version lower than or equal to 1.1.0)
apply_manifest_on(agent, package_manifest1, :expect_changes => true) do
list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout
match = list.match(/#{package} \((.+)\)/)
installed_version = match[1] if match
assert_match(installed_version, '1.1.0')
end
# Reapply same manifest and expect no changes
apply_manifest_on(agent, package_manifest1, :catch_changes => true)
# Reinstall over existing package (with version lower than 1.0.4) and expect changes (to be 1.0.3)
apply_manifest_on(agent, package_manifest2, :expect_changes => true) do
list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout
match = list.match(/#{package} \((.+)\)/)
installed_version = match[1] if match
assert_match(installed_version, '1.0.3')
end
on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes")
end
step "Ensure latest with pip uses install_options" do
on(agent, "#{pip_command} install #{package} --disable-pip-version-check")
package_manifest = resource_manifest('package', package, { ensure: 'latest', provider: 'pip', install_options: { '--index' => 'https://pypi.python.org/simple' } } )
result = apply_manifest_on(agent, package_manifest, { :catch_failures => true, :debug => true } )
assert_match(/--index=https:\/\/pypi.python.org\/simple/, result.stdout)
on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes")
end
step "Uninstall a pip package" do
on(agent, "#{pip_command} install #{package} --disable-pip-version-check")
package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'pip' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout
refute_match(/#{package} \(/, list)
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/zypper_install_package_with_range.rb | acceptance/tests/provider/package/zypper_install_package_with_range.rb | test_name "zypper can install range if package is not installed" do
confine :to, :platform => /sles/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "helloworld"
available_package_versions = ['1.0-2', '1.19-2', '2.0-2']
repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'sles-repo')
repo_content = <<-REPO
[local]
name=local - test packages
baseurl=file:///tmp/sles-repo
enabled=1
gpgcheck=0
REPO
agents.each do |agent|
scp_to(agent, repo_fixture_path, '/tmp')
file_manifest = resource_manifest('file', '/etc/zypp/repos.d/local.repo', ensure: 'present', content: repo_content)
apply_manifest_on(agent, file_manifest)
teardown do
package_absent(agent, package, '--force-yes')
file_manifest = resource_manifest('file', '/etc/zypp/repos.d/local.repo', ensure: 'absent')
apply_manifest_on(agent, file_manifest)
on(agent, 'rm -rf /tmp/sles-repo')
end
step "Ensure that package is installed first if not present" do
package_manifest = resource_manifest('package', package, ensure: "<=#{available_package_versions[1]}")
apply_manifest_on(agent, package_manifest)
installed_package_version = on(agent, "rpm -q #{package}").stdout
assert_match(available_package_versions[1], installed_package_version)
end
step "Ensure that package is updated" do
package_manifest = resource_manifest('package', package, ensure: ">#{available_package_versions[1]}")
apply_manifest_on(agent, package_manifest)
installed_package_version = on(agent, "rpm -q #{package}").stdout
assert_match(available_package_versions[2], installed_package_version)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/apt_install_package_with_range.rb | acceptance/tests/provider/package/apt_install_package_with_range.rb | test_name "apt can install range if package is not installed" do
confine :to, :platform => /debian|ubuntu/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "helloworld"
available_package_versions = ['1.0-1', '1.19-1', '2.0-1']
repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'debian-repo')
agents.each do |agent|
scp_to(agent, repo_fixture_path, '/tmp')
file_manifest = resource_manifest('file', '/etc/apt/sources.list.d/tmp.list', ensure: 'present', content: 'deb [trusted=yes] file:/tmp/debian-repo ./')
apply_manifest_on(agent, file_manifest)
on(agent, 'apt-get update')
teardown do
package_absent(agent, package, '--force-yes')
file_manifest = resource_manifest('file', '/etc/apt/sources.list.d/tmp.list', ensure: 'absent')
apply_manifest_on(agent, file_manifest)
on(agent, 'rm -rf /tmp/debian-repo')
on(agent, 'apt-get update')
end
step "Ensure that package is installed first if not present" do
package_manifest = resource_manifest('package', package, ensure: "<=#{available_package_versions[1]}")
apply_manifest_on(agent, package_manifest)
installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout
assert_match(available_package_versions[1], installed_package_version)
end
step "Ensure that package is updated" do
package_manifest = resource_manifest('package', package, ensure: ">#{available_package_versions[1]}")
apply_manifest_on(agent, package_manifest)
installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout
assert_match(available_package_versions[2], installed_package_version)
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/gem.rb | acceptance/tests/provider/package/gem.rb | test_name "gem provider should install and uninstall" do
confine :to, :template => /centos-7-x86_64|redhat-7-x86_64/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = 'colorize'
agents.each do |agent|
# On a Linux host with only the 'agent' role, the puppet command fails when another Ruby is installed earlier in the PATH:
#
# [root@agent ~]# env PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/puppetlabs/bin" puppet apply -e ' notify { "Hello": }'
# Activating bundler (2.0.2) failed:
# Could not find 'bundler' (= 2.0.2) among 5 total gem(s)
# To install the version of bundler this project requires, run `gem install bundler -v '2.0.2'`
#
# Magically, the puppet command succeeds on a Linux host with both the 'master' and 'agent' roles.
#
# Puppet's Ruby makes a fine target. Unfortunately, it's first in the PATH on Windows: PUP-6134.
# Also, privatebindir isn't a directory on Windows, it's a PATH:
# https://github.com/puppetlabs/beaker-puppet/blob/master/lib/beaker-puppet/install_utils/aio_defaults.rb
#
# These tests depend upon testing being confined to /centos-7-x86_64|redhat-7-x86_64/.
if agent['roles'].include?('master')
original_path = agent.get_env_var('PATH').split('=').last
# https://github.com/puppetlabs/puppet-agent/blob/master/resources/files/puppet-agent.sh
puppet_agent_sh_path = '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/puppetlabs/bin'
system_gem_command = '/usr/bin/gem'
teardown do
step "Teardown: Uninstall System Ruby, and reset PATH" do
package_absent(agent, 'ruby')
agent.clear_env_var('PATH')
agent.add_env_var('PATH', original_path)
end
end
step "Setup: Install System Ruby, and set PATH to place System Ruby ahead of Puppet Ruby" do
package_present(agent, 'ruby')
agent.add_env_var('PATH', puppet_agent_sh_path)
end
step "Install a gem package in System Ruby" do
package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'gem' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{system_gem_command} list").stdout
assert_match(/#{package} \(/, list)
end
on(agent, "#{system_gem_command} uninstall #{package}")
end
step "Uninstall a gem package in System Ruby" do
on(agent, "/usr/bin/gem install #{package}")
package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'gem' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{system_gem_command} list").stdout
refute_match(/#{package} \(/, list)
end
on(agent, "#{system_gem_command} uninstall #{package}")
end
step "Uninstall System Ruby, and reset PATH" do
package_absent(agent, 'ruby')
agent.add_env_var('PATH', original_path)
end
end
puppet_gem_command = "#{agent['privatebindir']}/gem"
step "Install a gem package with a target command" do
package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'gem', command: puppet_gem_command } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{puppet_gem_command} list").stdout
assert_match(/#{package} \(/, list)
end
on(agent, "#{puppet_gem_command} uninstall #{package}")
end
step "Install a gem package in a certain min max range" do
package_manifest1 = resource_manifest('package', package, { ensure: '>0.5 <0.7', provider: 'gem' } )
package_manifest2 = resource_manifest('package', package, { ensure: '>0.7 <0.8.1', provider: 'gem' } )
# Install package (with version between 0.5 and 0.7)
apply_manifest_on(agent, package_manifest1, :expect_changes => true) do
list = on(agent, "#{puppet_gem_command} list").stdout
assert_match(/#{package} \((0.6.0)\)/, list)
end
# Reapply same manifest and expect no changes
apply_manifest_on(agent, package_manifest1, :catch_changes => true)
# Install besides existing package (with version between 0.7 and 0.8.1) and expect changes
apply_manifest_on(agent, package_manifest2, :expect_changes => true) do
list = on(agent, "#{puppet_gem_command} list").stdout
assert_match(/#{package} \((0.8.0, 0.6.0)\)/, list)
end
on(agent, "#{puppet_gem_command} uninstall #{package} --all")
end
step "Uninstall a gem package with a target command" do
on(agent, "#{puppet_gem_command} install #{package}")
package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'gem', command: puppet_gem_command } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{puppet_gem_command} list").stdout
refute_match(/#{package} \(/, list)
end
on(agent, "#{puppet_gem_command} uninstall #{package}")
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/provider/package/rpm_ensure_install_multiversion_package.rb | acceptance/tests/provider/package/rpm_ensure_install_multiversion_package.rb | test_name "rpm should install packages with multiple versions" do
confine :to, :platform => /redhat|centos|el|fedora/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "kernel-devel-puppet"
repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'el-repo')
repo_content = <<-REPO
[local]
name=EL-releasever - test packages
baseurl=file:///tmp/el-repo
enabled=1
gpgcheck=0
protect=1
REPO
agents.each do |agent|
initially_installed_versions = []
scp_to(agent, repo_fixture_path, '/tmp')
file_manifest = resource_manifest('file', '/etc/yum.repos.d/local.repo', ensure: 'present', content: repo_content)
apply_manifest_on(agent, file_manifest)
teardown do
on(agent, 'rm -rf /tmp/el-repo')
on(agent, 'rm -f /etc/yum.repos.d/local.repo')
available_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | awk '{print $2}'").stdout
initially_installed_versions.each do |version|
if available_versions.include? version
package_manifest = resource_manifest('package', package, ensure: version, install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true)
end
end
end
step "Uninstall package versions for clean setup" do
initially_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout.split("\n")
package_manifest = resource_manifest('package', package, ensure: 'absent', install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
remaining_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout
assert(remaining_installed_versions.empty?)
end
available_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | awk '{print $2}'").stdout.split("\n")
if available_versions.size < 2
skip_test "we need at least two package versions to perform the multiversion rpm test"
end
end
step "Ensure oldest version of multiversion package is installed" do
oldest_version = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | head -1 | awk '{print $2}'").stdout.strip
package_manifest = resource_manifest('package', package, ensure: oldest_version, install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(oldest_version, installed_version)
end
end
step "Ensure newest package multiversion package in installed" do
newest_version = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | tail -1 | awk '{print $2}'").stdout.strip
package_manifest = resource_manifest('package', package, ensure: newest_version, install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(newest_version, installed_version)
end
end
step "Ensure rpm will uninstall multiversion package" do
package_manifest = resource_manifest('package', package, ensure: 'absent', install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
remaining_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout
assert(remaining_installed_versions.empty?)
end
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/parser_functions/hiera_in_templates.rb | acceptance/tests/parser_functions/hiera_in_templates.rb | test_name "Calling Hiera function from inside templates"
tag 'audit:high',
'audit:integration',
'audit:refactor' # Master is not required for this test. Replace with agents.each
@module_name = "hieratest"
@coderoot = master.tmpdir("#{@module_name}")
@msg_default = 'message from default.yaml'
@msg_production = 'message from production.yaml'
@msg1os = 'message1 from {osfamily}.yaml'
@msg2os = 'message2 from {osfamily}.yaml'
@msg_fqdn = 'messsage from {fqdn}.yaml'
@k1 = 'key1'
@k2 = 'key2'
@k3 = 'key3'
@hval2p = 'hash_value2 from production.yaml'
@hval3p = 'hash_value3 from production.yaml'
@hval1os = 'hash_value1 from {osfamily}.yaml'
@hval2os = 'hash_value2 from {osfamily}.yaml'
@h_m_call = "hiera\\('message'\\)"
@h_h_call = "hiera\\('hash_value'\\)"
@h_i_call = "hiera\\('includes'\\)"
@ha_m_call = "hiera_array\\('message'\\)"
@ha_i_call = "hiera_array\\('includes'\\)"
@hh_h_call = "hiera_hash\\('hash_value'\\)"
@mod_default_msg = 'This file created by mod_default.'
@mod_osfamily_msg = 'This file created by mod_osfamily.'
@mod_production_msg = 'This file created by mod_production.'
@mod_fqdn_msg = 'This file created by mod_fqdn.'
@master_opts = {
'main' => {
'environmentpath' => "#{@coderoot}/environments",
'hiera_config' => "#{@coderoot}/hiera.yaml",
},
}
def create_environment(osfamilies, tmp_dirs)
envroot = "#{@coderoot}/environments"
production = "#{envroot}/production"
modroot = "#{production}/modules"
moduledir = "#{modroot}/#{@module_name}"
hieradir = "#{@coderoot}/hieradata"
osfamily_yamls = ""
osfamilies.each do |osf|
new_yaml = <<NEW_YAML
file {"#{hieradir}/#{osf}.yaml":
content => "
---
message: [
'#{@msg1os}',
'#{@msg2os}',
]
includes: '#{@module_name}::mod_osfamily'
hash_value:
#{@k1}: '#{@hval1os}'
#{@k2}: '#{@hval2os}'
"
}
NEW_YAML
osfamily_yamls += new_yaml
end
environ = <<ENV
File {
ensure => file,
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
mode => "0644",
}
file {
[
"#{@coderoot}",
"#{envroot}",
"#{production}",
"#{production}/modules",
"#{production}/manifests",
"#{hieradir}",
"#{moduledir}",
"#{moduledir}/examples",
"#{moduledir}/manifests",
"#{moduledir}/templates",
] :
ensure => directory,
}
file { '#{production}/manifests/site.pp':
ensure => file,
content => "
node default {
\\$msgs = hiera_array('message')
notify {\\$msgs:}
class {'#{@module_name}':
result_dir => hiera('result_dir')[\\$facts['networking']['hostname']],
}
}
",
}
file {"#{@coderoot}/hiera.yaml":
content => "
---
:backends:
- yaml
:yaml:
:datadir: #{@coderoot}/hieradata
:hierarchy:
- \\"%{clientcert}\\"
- \\"%{environment}\\"
- \\"%{os.family}\\"
- \\"default\\"
"
}
file {"#{hieradir}/default.yaml":
content => "
---
message: '#{@msg_default}'
includes: '#{@module_name}::mod_default'
result_dir:
#{tmp_dirs}
"
}
#{osfamily_yamls}
file {"#{hieradir}/production.yaml":
content => "
---
message: '#{@msg_production}'
includes: '#{@module_name}::mod_production'
hash_value:
#{@k2}: '#{@hval2p}'
#{@k3}: '#{@hval3p}'
"
}
file {"#{hieradir}/#{$fqdn}.yaml":
content => "
---
message: '#{@msg_fqdn}'
includes: '#{@module_name}::mod_fqdn'
"
}
file {"#{moduledir}/examples/init.pp":
content => "
include #{@module_name}
"
}
file { "#{moduledir}/manifests/init.pp":
content => "
class #{@module_name} (
\\$result_dir,
) {
file { \\$result_dir:
ensure => directory,
mode => '0755',
}
file {\\\"\\\${result_dir}/#{@module_name}_results_epp\\\":
ensure => file,
mode => '0644',
content => epp('#{@module_name}/hieratest_results_epp.epp'),
}
file {\\\"\\\${result_dir}/#{@module_name}_results_erb\\\":
ensure => file,
mode => '0644',
content => template('#{@module_name}/hieratest_results_erb.erb'),
}
}
"
}
file { "#{moduledir}/manifests/mod_default.pp":
content => "
class #{@module_name}::mod_default {
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_default invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_default\\\":
ensure => 'file',
mode => '0644',
content => \\\"#{@mod_default_msg}\\\\n\\\",
}
}
"
}
file { "#{moduledir}/manifests/mod_osfamily.pp":
content => "
class #{@module_name}::mod_osfamily {
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_osfamily invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_osfamily\\\":
ensure => 'file',
mode => '0644',
content => \\\"#{@mod_osfamily_msg}\\\\n\\\",
}
}
"
}
file { "#{moduledir}/manifests/mod_production.pp":
content => "
class #{@module_name}::mod_production {
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_production invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_production\\\":
ensure => 'file',
mode => '0644',
content => '#{@mod_production_msg}',
}
}
"
}
file { "#{moduledir}/manifests/mod_fqdn.pp":
content => "
class #{@module_name}::mod_fqdn {
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_fqdn invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_fqdn\\\":
ensure => 'file',
mode => '0644',
content => \\\"#{@mod_fqdn_msg}\\\\n\\\",
}
}
"
}
file { "#{moduledir}/templates/hieratest_results_epp.epp":
content => "
hiera('message'): <%= hiera('message') %>
hiera('hash_value'): <%= hiera('hash_value') %>
hiera('includes'): <%= hiera('includes') %>
hiera_array('message'): <%= hiera_array('message') %>
hiera_array('includes'): <%= hiera_array('includes') %>
hiera_hash('hash_value'): <%= hiera_hash('hash_value') %>
hiera_include('includes'): <%= hiera_include('includes') %>
"
}
file { "#{moduledir}/templates/hieratest_results_erb.erb":
content => "
hiera('message'): <%= scope().call_function('hiera', ['message']) %>
hiera('hash_value'): <%= scope().call_function('hiera', ['hash_value']) %>
hiera('includes'): <%= scope().call_function('hiera', ['includes']) %>
hiera_array('message'): <%= scope().call_function('hiera_array', ['message']) %>
hiera_array('includes'): <%= scope().call_function('hiera_array', ['includes']) %>
hiera_hash('hash_value'): <%= scope().call_function('hiera_hash', ['hash_value']) %>
"
}
ENV
environ
end
def find_osfamilies
family_hash = {}
agents.each do |agent|
res = on(agent, facter("os.family"))
osf = res.stdout.chomp
family_hash[osf] = 1
end
family_hash.keys
end
def find_tmp_dirs
tmp_dirs = ""
host_to_result_dir = {}
agents.each do |agent|
h = on(agent, facter("networking.hostname")).stdout.chomp
t = agent.tmpdir("#{@module_name}_results")
tmp_dirs += " #{h}: '#{t}'\n"
host_to_result_dir[h] = t
end
result = {
'tmp_dirs' => tmp_dirs,
'host_to_result_dir' => host_to_result_dir
}
result
end
step 'Setup'
with_puppet_running_on master, @master_opts, @coderoot do
res = find_tmp_dirs
tmp_dirs = res['tmp_dirs']
host_to_result_dir = res['host_to_result_dir']
env_manifest = create_environment(find_osfamilies, tmp_dirs)
apply_manifest_on(master, env_manifest, :catch_failures => true)
agents.each do |agent|
resultdir = host_to_result_dir[on(agent, facter("networking.hostname")).stdout.chomp]
step "Applying catalog to agent: #{agent}. result files in #{resultdir}"
on(
agent,
puppet('agent', "-t"),
:acceptable_exit_codes => [2]
)
step "####### Verifying hiera calls from erb template #######"
r1 = on(agent, "cat #{resultdir}/hieratest_results_erb")
result = r1.stdout
step "Verifying hiera() call #1."
assert_match(
/#{@h_m_call}: #{@msg_production}/,
result,
"#{@h_m_call} failed. Expected: '#{@msg_production}'"
)
step "Verifying hiera() call #2."
assert_match(
/#{@h_h_call}.*\"#{@k3}\"=>\"#{@hval3p}\"/,
result,
"#{@h_h_call} failed. Expected: '\"#{@k3}\"=>\"#{@hval3p}\"'"
)
step "Verifying hiera() call #3."
assert_match(
/#{@h_h_call}.*\"#{@k2}\"=>\"#{@hval2p}\"/,
result,
"#{@h_h_call} failed. Expected: '\"#{@k2}\"=>\"#{@hval2p}\"'"
)
step "Verifying hiera() call #4."
assert_match(
/#{@h_i_call}: #{@module_name}::mod_production/,
result,
"#{@h_i_call} failed. Expected:'#{@module_name}::mod_production'"
)
step "Verifying hiera_array() call. #1"
assert_match(
/#{@ha_m_call}: \[\"#{@msg_production}\", \"#{@msg1os}\", \"#{@msg2os}\", \"#{@msg_default}\"\]/,
result,
"#{@ha_m_call} failed. Expected: '[\"#{@msg_production}\", \"#{@msg1os}\", \"#{@msg2os}\", \"#{@msg_default}\"]'"
)
step "Verifying hiera_array() call. #2"
assert_match(
/#{@ha_i_call}: \[\"#{@module_name}::mod_production\", \"#{@module_name}::mod_osfamily\", \"#{@module_name}::mod_default\"\]/,
result,
"#{@ha_i_call} failed. Expected: '[\"#{@module_name}::mod_production\", \"#{@module_name}::mod_osfamily\", \"#{@module_name}::mod_default\"]'"
)
step "Verifying hiera_hash() call. #1"
assert_match(
/#{@hh_h_call}:.*\"#{@k3}\"=>\"#{@hval3p}\"/,
result,
"#{@hh_h_call} failed. Expected: '\"#{@k3}\"=>\"#{@hval3p}\"'"
)
step "Verifying hiera_hash() call. #2"
assert_match(
/#{@hh_h_call}:.*\"#{@k2}\"=>\"#{@hval2p}\"/,
result,
"#{@hh_h_call} failed. Expected: '\"#{@k2}\"=>\"#{@hval2p}\"'"
)
step "Verifying hiera_hash() call. #3"
assert_match(
/#{@hh_h_call}:.*\"#{@k1}\"=>\"#{@hval1os}\"/,
result,
"#{@hh_h_call} failed. Expected: '\"#{@k1}\"=>\"#{@hval1os}\"'"
)
r2 = on(agent, "cat #{resultdir}/mod_default")
result = r2.stdout
step "Verifying hiera_include() call. #1"
assert_match(
"#{@mod_default_msg}",
result,
"#{@hi_i_call} failed. Expected: '#{@mod_default_msg}'"
)
r3 = on(agent, "cat #{resultdir}/mod_osfamily")
result = r3.stdout
step "Verifying hiera_include() call. #2"
assert_match(
"#{@mod_osfamily_msg}",
result,
"#{@hi_i_call} failed. Expected: '#{@mod_osfamily_msg}'"
)
r4 = on(agent, "cat #{resultdir}/mod_production")
result = r4.stdout
step "Verifying hiera_include() call. #3"
assert_match(
"#{@mod_production_msg}",
result,
"#{@hi_i_call} failed. Expected: '#{@mod_production_msg}'"
)
step "####### Verifying hiera calls from epp template #######"
r5 = on(agent, "cat #{resultdir}/hieratest_results_epp")
result = r5.stdout
step "Verifying hiery() call #1."
assert_match(
/#{@h_m_call}: #{@msg_production}/,
result,
"#{@hi_m_call} failed. Expected '#{@msg_production}'"
)
step "Verifying hiera() call #2."
assert_match(
/#{@h_h_call}.*#{@k3} => #{@hval3p}/,
result,
"#{@h_h_call} failed. Expected '#{@k3} => #{@hval3p}'"
)
step "Verifying hiera() call #3."
assert_match(/#{@h_h_call}.*#{@k2} => #{@hval2p}/,
result,
"#{@h_h_call} failed. Expected '#{@k2} => #{@hval2p}'"
)
step "Verifying hiera() call #4."
assert_match(
/#{@h_i_call}: #{@module_name}::mod_production/,
result,
"#{@h_i_call} failed. Expected: '#{@module_name}::mod_production'"
)
step "Verifying hiera_array() call. #1"
assert_match(
/#{@ha_m_call}: \[#{@msg_production}, #{@msg1os}, #{@msg2os}, #{@msg_default}\]/,
result,
"#{@ha_m_call} failed. Expected: '[#{@msg_production}, #{@msg1os}, #{@msg2os}, #{@msg_default}]'"
)
step "Verifying hiera_array() call. #2"
assert_match(
/#{@ha_i_call}: \[#{@module_name}::mod_production, #{@module_name}::mod_osfamily, #{@module_name}::mod_default\]/,
result,
"#{@ha_i_call} failed. Expected: '[#{@module_name}::mod_production, #{@module_name}::mod_osfamily, #{@module_name}::mod_default'"
)
step "Verifying hiera_hash() call. #1"
assert_match(
/#{@hh_h_call}:.*#{@k3} => #{@hval3p}/,
result,
"#{@hh_h_call} failed. Expected: '{@k3} => #{@hval3p}'"
)
step "Verifying hiera_hash() call. #2"
assert_match(
/#{@hh_h_call}:.*#{@k2} => #{@hval2p}/,
result,
"#{@hh_h_call} failed. Expected '#{@k2} => #{@hval2p}'",
)
step "Verifying hiera_hash() call. #3"
assert_match(
/#{@hh_h_call}:.*#{@k1} => #{@hval1os}/,
result,
"#{@hh_h_call}: failed. Expected: '#{@k1} => #{@hval1os}'"
)
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
OpenVoxProject/openvox | https://github.com/OpenVoxProject/openvox/blob/9336df16a11679d701a2bd9ebe1308d4fb669f57/acceptance/tests/parser_functions/no_exception_in_reduce_with_bignum.rb | acceptance/tests/parser_functions/no_exception_in_reduce_with_bignum.rb | test_name 'C97760: Integer in reduce() should not cause exception' do
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:unit'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
step 'On master, create site.pp with integer' do
create_sitepp(master, tmp_environment, <<-SITEPP)
$data = [
{
"certname"=>"xxxxxxxxx.some.domain",
"parameters"=>{
"admin_auth_keys"=>{
"keyname1"=>{
"key"=>"ABCDEF",
"options"=>["from=\\"10.0.0.0/8\\""]
},
"keyname2"=>{
"key"=>"ABCDEF",
},
"keyname3"=>{
"key"=>"ABCDEF",
"options"=>["from=\\"10.0.0.0/8\\""],
"type"=>"ssh-xxx"
},
"keyname4"=>{
"key"=>"ABCDEF",
"options"=>["from=\\"10.0.0.0/8\\""]
}
},
"admin_user"=>"ertxa",
"admin_hosts"=>["1.2.3.4",
"1.2.3.4",
"1.2.3.4"],
"admin_password"=>"ABCDEF",
"sshd_ports"=>[22,
22, 24],
"sudo_no_password_all"=>false,
"sudo_no_password_commands"=>[],
"sshd_config_template"=>"cfauth/sshd_config.epp",
"sudo_env_keep"=>[]
},
"exported"=>false},
]
$data_reduced = $data.reduce({}) |$m, $r|{
$cn = $r['certname']
notice({ $cn => $r['parameters'] })
}
SITEPP
end
with_puppet_running_on(master, {}) do
agents.each do |agent|
on(agent, puppet("agent -t --environment #{tmp_environment}"))
end
end
end
| ruby | Apache-2.0 | 9336df16a11679d701a2bd9ebe1308d4fb669f57 | 2026-01-04T17:47:45.967003Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.