diff options
author | Josh Cooper <josh@puppet.com> | 2018-06-27 22:06:49 -0700 |
---|---|---|
committer | Josh Cooper <josh@puppet.com> | 2018-06-27 22:08:47 -0700 |
commit | 69f941224a43275896218807fd91c8e5b912f8d1 (patch) | |
tree | 06311b92c16f40868be7a106e3e831b6c97b7d51 /spec/acceptance | |
parent | c051e86b350329bc1a7cd1c9c239ec29212b8e56 (diff) | |
download | puppet-augeas_core-69f941224a43275896218807fd91c8e5b912f8d1.tar.gz puppet-augeas_core-69f941224a43275896218807fd91c8e5b912f8d1.tar.bz2 |
Initial augeas import from puppet#2b83deb189
Diffstat (limited to 'spec/acceptance')
-rw-r--r-- | spec/acceptance/hosts.rb | 78 | ||||
-rw-r--r-- | spec/acceptance/puppet.rb | 46 | ||||
-rw-r--r-- | spec/acceptance/services.rb | 73 |
3 files changed, 197 insertions, 0 deletions
diff --git a/spec/acceptance/hosts.rb b/spec/acceptance/hosts.rb new file mode 100644 index 0000000..a7f526a --- /dev/null +++ b/spec/acceptance/hosts.rb @@ -0,0 +1,78 @@ +test_name "Augeas hosts file" do + +tag 'risk:medium', + 'audit:medium', + 'audit:acceptance', + 'audit:refactor' # move to puppet types test directory, this is not testing puppet apply + # reduce to a single manifest and apply + +skip_test 'requires augeas which is included in AIO' if @options[:type] != 'aio' + + confine :except, :platform => [ + 'windows', + 'cisco_ios', # PUP-7380 + ] + confine :to, {}, hosts.select { |host| ! host[:roles].include?('master') } + + step "Backup the hosts file" do + on hosts, 'cp /etc/hosts /tmp/hosts.bak' + end + + # We have a begin/ensure block here to clean up the hosts file in case + # of test failure. + begin + + step "Create an entry in the hosts file" do + manifest = <<EOF +augeas { 'add_hosts_entry': + context => '/files/etc/hosts', + incl => '/etc/hosts', + lens => 'Hosts.lns', + changes => [ + 'set 01/ipaddr 192.168.0.1', + 'set 01/canonical pigiron.example.com', + 'set 01/alias[1] pigiron', + 'set 01/alias[2] piggy' + ] +} +EOF + on hosts, puppet_apply('--verbose'), :stdin => manifest + on hosts, "fgrep '192.168.0.1\tpigiron.example.com pigiron piggy' /etc/hosts" + end + + step "Modify an entry in the hosts file" do + manifest = <<EOF +augeas { 'mod_hosts_entry': + context => '/files/etc/hosts', + incl => '/etc/hosts', + lens => 'Hosts.lns', + changes => [ + 'set *[canonical = "pigiron.example.com"]/alias[last()+1] oinker' + ] +} +EOF + + on hosts, puppet_apply('--verbose'), :stdin => manifest + on hosts, "fgrep '192.168.0.1\tpigiron.example.com pigiron piggy oinker' /etc/hosts" + end + + step "Remove an entry from the hosts file" do + manifest = <<EOF +augeas { 'del_hosts_entry': + context => '/files/etc/hosts', + incl => '/etc/hosts', + lens => 'Hosts.lns', + changes => [ + 'rm *[canonical = "pigiron.example.com"]' + ] +} +EOF + + on hosts, puppet_apply('--verbose'), :stdin => manifest + on hosts, "fgrep 'pigiron.example.com' /etc/hosts", :acceptable_exit_codes => [1] + end + + ensure + on hosts, 'cat /tmp/hosts.bak > /etc/hosts && rm /tmp/hosts.bak' + end +end diff --git a/spec/acceptance/puppet.rb b/spec/acceptance/puppet.rb new file mode 100644 index 0000000..10fb159 --- /dev/null +++ b/spec/acceptance/puppet.rb @@ -0,0 +1,46 @@ +test_name "Augeas puppet configuration" do + + tag 'risk:medium', + 'audit:medium', + 'audit:acceptance', + 'audit:refactor' # move to types test dir + + skip_test 'requires augeas which is included in AIO' if @options[:type] != 'aio' + + confine :except, :platform => 'windows' + confine :to, {}, hosts.select { |host| ! host[:roles].include?('master') } + + teardown do + agents.each do |agent| + on agent, "cat /tmp/puppet.conf.bak > #{agent.puppet['confdir']}/puppet.conf && rm /tmp/puppet.conf.bak" + end + end + + agents.each do |agent| + step "Backup the puppet config" do + on agent, "mv #{agent.puppet['confdir']}/puppet.conf /tmp/puppet.conf.bak" + end + step "Create a new puppet config that has a master and agent section" do + puppet_conf = <<-CONF + [main] + CONF + on agent, "echo \"#{puppet_conf}\" >> #{agent.puppet['confdir']}/puppet.conf" + end + + step "Modify the puppet.conf file" do + manifest = <<-EOF + augeas { 'puppet agent noop mode': + context => "/files#{agent.puppet['confdir']}/puppet.conf/agent", + incl => "/etc/puppetlabs/puppet/puppet.conf", + lens => 'Puppet.lns', + changes => 'set noop true', + } + EOF + on agent, puppet_apply('--verbose'), :stdin => manifest + + on agent, "grep 'noop=true' #{agent.puppet['confdir']}/puppet.conf" + end + + end + +end diff --git a/spec/acceptance/services.rb b/spec/acceptance/services.rb new file mode 100644 index 0000000..ec87316 --- /dev/null +++ b/spec/acceptance/services.rb @@ -0,0 +1,73 @@ +test_name "Augeas services file" do + + tag 'risk:medium', + 'audit:medium', + 'audit:acceptance', + 'audit:refactor' # move to types test dir + # use single manifest/apply + + skip_test 'requires augeas which is included in AIO' if @options[:type] != 'aio' + + confine :except, :platform => 'windows' + confine :except, :platform => 'osx' + confine :to, {}, hosts.select { |host| ! host[:roles].include?('master') } + + step "Backup the services file" do + on hosts, "cp /etc/services /tmp/services.bak" + end + + begin + step "Add an entry to the services file" do + manifest = <<EOF +augeas { 'add_services_entry': + context => '/files/etc/services', + incl => '/etc/services', + lens => 'Services.lns', + changes => [ + 'ins service-name after service-name[last()]', + 'set service-name[last()] "Doom"', + 'set service-name[. = "Doom"]/port "666"', + 'set service-name[. = "Doom"]/protocol "udp"' + ] +} +EOF + + on hosts, puppet_apply('--verbose'), :stdin => manifest + on hosts, "fgrep 'Doom 666/udp' /etc/services" + end + + step "Change the protocol to udp" do + manifest = <<EOF +augeas { 'change_service_protocol': + context => '/files/etc/services', + incl => '/etc/services', + lens => 'Services.lns', + changes => [ + 'set service-name[. = "Doom"]/protocol "tcp"' + ] +} +EOF + + on hosts, puppet_apply('--verbose'), :stdin => manifest + on hosts, "fgrep 'Doom 666/tcp' /etc/services" + end + + step "Remove the services entry" do + manifest = <<EOF +augeas { 'del_service_entry': + context => '/files/etc/services', + incl => '/etc/services', + lens => 'Services.lns', + changes => [ + 'rm service-name[. = "Doom"]' + ] +} +EOF + + on hosts, puppet_apply('--verbose'), :stdin => manifest + on hosts, "fgrep 'Doom 666/tcp' /etc/services", :acceptable_exit_codes => [1] + end + ensure + on hosts, "mv /tmp/services.bak /etc/services" + end +end |