-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(maint) Add testing around exec via Puppet #583
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
require 'pxp-agent/test_helper.rb' | ||
require 'puppet/acceptance/environment_utils' | ||
|
||
test_name 'C98107 - Run puppet with an exec' do | ||
|
||
extend Puppet::Acceptance::EnvironmentUtils | ||
|
||
env_name = test_file_name = File.basename(__FILE__, '.*') | ||
environment_name = mk_tmp_environment(env_name) | ||
|
||
step 'On master, create a new environment that execs hostname' do | ||
site_manifest = "#{environmentpath}/#{environment_name}/manifests/site.pp" | ||
create_remote_file(master, site_manifest, <<-SITEPP) | ||
node default { | ||
exec { "hostname": | ||
path => ["/bin", "/usr/bin", "C:/cygwin32/bin", "C:/cygwin64/bin"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MikaelSmith this is failing CI when running 32-bit puppet/ruby on 32-bit windows (using the Note the puppet-agent pipelines alternate architectures, which is why it was failing yesterday, but not today: https://jenkins-master-prod-1.delivery.puppetlabs.net/view/puppet-agent/view/master/view/Suite/job/platform_puppet-agent_intn-van-sys_suite-daily-pxp-agent-master/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
logoutput => true, | ||
} | ||
} | ||
SITEPP | ||
on(master, "chmod 644 #{site_manifest}") | ||
end | ||
|
||
step 'Ensure each agent host has pxp-agent running and associated' do | ||
agents.each do |agent| | ||
on agent, puppet('resource service pxp-agent ensure=stopped') | ||
create_remote_file(agent, pxp_agent_config_file(agent), pxp_config_json_using_puppet_certs(master, agent).to_s) | ||
on agent, puppet('resource service pxp-agent ensure=running') | ||
|
||
assert(is_associated?(master, "pcp://#{agent}/agent"), | ||
"Agent #{agent} with PCP identity pcp://#{agent}/agent should be associated with pcp-broker") | ||
end | ||
end | ||
|
||
def last_run_report(h) | ||
if h['platform'] =~ /windows/ | ||
'C:/ProgramData/PuppetLabs/puppet/cache' | ||
else | ||
'/opt/puppetlabs/puppet/cache' | ||
end + '/state/last_run_report.yaml' | ||
end | ||
|
||
step "Send an rpc_blocking_request to all agents" do | ||
target_identities = [] | ||
agents.each do |agent| | ||
target_identities << "pcp://#{agent}/agent" | ||
end | ||
responses = nil # Declare here so not local to begin/rescue below | ||
begin | ||
responses = rpc_blocking_request(master, target_identities, | ||
'pxp-module-puppet', 'run', | ||
{:env => [], :flags => ['--environment', environment_name]}) | ||
rescue => exception | ||
fail("Exception occurred when trying to run Puppet on all agents: #{exception.message}") | ||
end | ||
agents.each_with_index do |agent| | ||
step "Check Run Puppet response for #{agent}" do | ||
identity = "pcp://#{agent}/agent" | ||
assert(responses[identity][:data].has_key?("results"), | ||
"Agent #{agent} received a response for rpc_blocking_request but it is missing a 'results' entry: #{responses[identity]}") | ||
action_result = responses[identity][:data]["results"] | ||
# The test's pass/fail criteria is only the value of 'status'. However, if something goes wrong and Puppet needs to default | ||
# the environment to 'production' and results in 'unchanged' then it's better to fail specifically on the environment. | ||
assert(action_result.has_key?('environment'), "Results for pxp-module-puppet run on #{agent} should contain an 'environment' field") | ||
assert_equal(environment_name, action_result['environment'], "Result of pxp-module-puppet run on #{agent} should run with the "\ | ||
"#{environment_name} environment") | ||
assert(action_result.has_key?('status'), "Results for pxp-module-puppet run on #{agent} should contain a 'status' field") | ||
assert_equal('changed', action_result['status'], "Result of pxp-module-puppet run on #{agent} should be 'changed'") | ||
end | ||
|
||
step "Check run report for #{agent}" do | ||
result = on(agent, "cat #{last_run_report(agent)}") | ||
|
||
# Parse the last run report, ignoring object tags | ||
data = YAML.parse(result.stdout) | ||
data.root.each do |o| | ||
o.tag = nil if o.respond_to?(:tag=) | ||
end | ||
data = data.to_ruby | ||
|
||
hostname = on(agent, 'hostname').stdout.chomp | ||
expected = data['logs'].select {|log| log['source'] =~ /Exec\[hostname\]/}.select {|log| log['message'] == hostname} | ||
assert_equal(1, expected.count, 'puppet failed to exec hostname') | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we get rid of the
message_expiry
variable altogether?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's no longer needed, so we could remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tempted to ignore it for now though.