Skip to content

Commit

Permalink
Merge branch 'issues/master/pup-3277-more-acceptance-fixes'
Browse files Browse the repository at this point in the history
* issues/master/pup-3277-more-acceptance-fixes:
  (PUP-3277) Use single quotes for cve injection test file content
  (maint) Release hosts that are listed with domain
  (PUP-3277) Use classifier enc for some enc tests on pe
  (PUP-3277) Filter group properties before PUT
  (PUP-3277) Remove classifier_utils from no_enc test
  • Loading branch information
jpartlow committed Oct 8, 2014
2 parents 7ce59ba + e2032d1 commit 2ee0ba5
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 40 deletions.
2 changes: 1 addition & 1 deletion acceptance/Rakefile
Expand Up @@ -200,7 +200,7 @@ def list_preserved_hosts(secs_ago = ONE_DAY_IN_SECS)
File.open(log, 'r') do |file|
if file.ctime > yesterday
file.each_line do |line|
matchdata = /^(\w+) \(.*?\) \d\d:\d\d:\d\d\$/.match(line.encode!('UTF-8', 'UTF-8', :invalid => :replace))
matchdata = /^(\w+)(?:\.[\w.]+)? \(.*?\) \d\d:\d\d:\d\d\$/.match(line.encode!('UTF-8', 'UTF-8', :invalid => :replace))
hosts.add(matchdata[1]) if matchdata
end
end
Expand Down
21 changes: 10 additions & 11 deletions acceptance/bin/ci-rerun-pe-puppet.sh
Expand Up @@ -14,8 +14,8 @@ exit 1
fi

if [ -z "$platform" ]; then
echo "'platform' not set: assuming 'el-6-x86_64'"
platform="el-6-x86_64"
echo "'platform' not set: should be 'el-6-x86_64' or 'ubuntu-1204-i386' or some other platform string acceptable to Beaker"
exit 1
fi

if [ -z "$1" ]; then
Expand All @@ -28,7 +28,7 @@ if [ -z "$2" ]; then
cat > hosts-immediate.cfg << EOHOSTS
---
HOSTS:
${1}:
${1}.delivery.puppetlabs.net:
roles:
- agent
- master
Expand All @@ -51,14 +51,14 @@ else
cat > hosts-immediate.cfg << EOHOSTS
---
HOSTS:
${1}:
${1}.delivery.puppetlabs.net:
roles:
- agent
- dashboard
- database
- master
platform: ${platform}
${2}:
${2}.delivery.puppetlabs.net:
roles:
- agent
platform: ${platform}
Expand All @@ -76,20 +76,19 @@ EOHOSTS
cat > hosts-immediate.cfg << EOHOSTS
---
HOSTS:
${1}:
${1}.delivery.puppetlabs.net:
roles:
- agent
- master
- dashboard
- database
platform: ${platform}
${2}:
${2}.delivery.puppetlabs.net:
roles:
- agent
- dashboard
platform: ${platform}
${3}:
${3}.delivery.puppetlabs.net:
roles:
- agent
- database
platform: ${platform}
CONFIG:
nfs_server: none
Expand Down
18 changes: 14 additions & 4 deletions acceptance/lib/puppet/acceptance/classifier_utils.rb
Expand Up @@ -42,6 +42,7 @@ def create_group_for_nodes(nodes, group_hash)
end

hostnames = nodes.map { |n| n.hostname }
step "Add group #{group_uuid} for #{hostnames.join(", ")}"
rule = hostnames.inject(["or"]) do |r,name|
r << ["~", "name", name]
r
Expand All @@ -65,22 +66,31 @@ def create_group_for_nodes(nodes, group_hash)
def disable_pe_enterprise_mcollective_agent_classes
return if !master.is_pe?

step "Get classifier groups so we can locate the PE MCollective group"
response = classifier_handle.get("/v1/groups")
assert_equal(200, response.code, "Unable to get classifer groups: #{response.body}")

groups_json = response.body
groups = JSON.parse(groups_json)
pe_mcollective = groups.find { |g| g['name'] == 'PE MCollective' }
assert_not_nil pe_mcollective, "Unable to find the 'PE MCollective' group in: #{groups.pretty_inspect}"
select_properties_we_can_put = lambda do |group|
group.select { |k,v| ['id','name','environment','environment_trumps','rule','description','classes','variables','parent'].include?(k) }
end
pe_mcollective = select_properties_we_can_put.call(pe_mcollective)

teardown do
groups = JSON.parse(groups_json)
original_pe_mcollective = groups.find { |g| g['name'] == 'PE MCollective' }
response = classifier_handle.put("/v1/groups/#{original_pe_mcollective['id']}", :body => original_pe_mcollective.to_json)
assert_equal(201, response.code, "Unable to restore 'PE MCollective' group: #{response.code}:#{response.body}")
step "Restore original PE MCollective group" do
groups = JSON.parse(groups_json)
original_pe_mcollective = groups.find { |g| g['name'] == 'PE MCollective' }
original_pe_mcollective = select_properties_we_can_put.call(original_pe_mcollective)
response = classifier_handle.put("/v1/groups/#{original_pe_mcollective['id']}", :body => original_pe_mcollective.to_json)
assert_equal(201, response.code, "Unable to restore 'PE MCollective' group: #{response.code}:#{response.body}")
end if response.code == 201
end

hostnames = agents.map { |n| n.hostname }
step "Adjust PE MCollective not to match for #{hostnames.join(", ")}"
host_matching_rule = hostnames.inject(["or"]) do |r,name|
r << ["~", "name", name]
r
Expand Down
@@ -1,8 +1,4 @@
test_name "Agent should use agent environment if there is no enc-specified environment"
require 'puppet/acceptance/classifier_utils'
extend Puppet::Acceptance::ClassifierUtils

classify_nodes_as_agent_specified_if_classifer_present

testdir = create_tmpdir_for_user master, 'use_agent_env'

Expand Down
22 changes: 18 additions & 4 deletions acceptance/tests/environment/use_enc_environment.rb
@@ -1,7 +1,19 @@
test_name "Agent should use environment given by ENC"
require 'puppet/acceptance/classifier_utils.rb'
extend Puppet::Acceptance::ClassifierUtils

testdir = create_tmpdir_for_user master, 'use_enc_env'

if master.is_pe?
group = {
'name' => 'Special Environment',
'description' => 'Classify our test agent nodes in the special environment.',
'environment' => 'special',
'environment_trumps' => true,
}
create_group_for_nodes(agents, group)
else

create_remote_file master, "#{testdir}/enc.rb", <<END
#!#{master['puppetbindir']}/ruby
puts <<YAML
Expand All @@ -11,6 +23,8 @@
END
on master, "chmod 755 #{testdir}/enc.rb"

end

apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
Expand Down Expand Up @@ -41,11 +55,11 @@
'main' => {
'environmentpath' => "#{testdir}/environments",
},
'master' => {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
},
}
master_opts['master'] = {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
} if !master.is_pe?

with_puppet_running_on master, master_opts, testdir do

Expand Down
Expand Up @@ -21,10 +21,10 @@ def create_exploit_manifest(path, exploit_path_expression)
'#{path}/environments/production/manifests':;
'#{path}/environments/production/manifests/site.pp':
ensure => file,
content => "
$enc_data = '#{exploit_path_expression}'
content => '
$enc_data = "#{exploit_path_expression}"
include $enc_data
",
',
mode => "0640",
}
MANIFEST
Expand Down
@@ -1,4 +1,6 @@
test_name "ENC node information is used when store configs enabled (#16698)"
require 'puppet/acceptance/classifier_utils.rb'
extend Puppet::Acceptance::ClassifierUtils

confine :to, :platform => ['debian', 'ubuntu']
confine :except, :platform => 'lucid'
Expand All @@ -7,6 +9,34 @@

testdir = master.tmpdir('use_enc')

apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
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 { $data: }';
}
MANIFEST

if master.is_pe?
group = {
'name' => 'Data',
'description' => 'A group to test that data is passed from the enc',
'variables' => { :data => 'data from enc' }
}
create_group_for_nodes(agents, group)
else

create_remote_file master, "#{testdir}/enc.rb", <<END
#!#{master['puppetbindir']}/ruby
require 'yaml'
Expand All @@ -19,11 +49,6 @@
END
on master, "chmod 755 #{testdir}/enc.rb"

create_remote_file(master, "#{testdir}/site.pp", 'notify { $data: }')

on master, "chown -R #{master['user']}:#{master['group']} #{testdir}"
on master, "chmod -R g+rwX #{testdir}"

create_remote_file master, "#{testdir}/setup.pp", <<END
$active_record_version = $osfamily ? {
Expand Down Expand Up @@ -104,16 +129,20 @@
on master, puppet_apply("#{testdir}/setup.pp")
on master, puppet_apply("#{testdir}/setup_sqlite_gem.pp")

end

master_opts = {
'master' => {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
'storeconfigs' => true,
'dbadapter' => 'sqlite3',
'dblocation' => "#{testdir}/store_configs.sqlite3",
'manifest' => "#{testdir}/site.pp"
}
'main' => {
'environmentpath' => "#{testdir}/environments",
},
}
master_opts['master'] = {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
'storeconfigs' => true,
'dbadapter' => 'sqlite3',
'dblocation' => "#{testdir}/store_configs.sqlite3",
} if !master.is_pe?

with_puppet_running_on master, master_opts, testdir do
agents.each do |agent|
Expand Down

0 comments on commit 2ee0ba5

Please sign in to comment.