aboutsummaryrefslogtreecommitdiff
path: root/spec/acceptance/hosts.rb
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppet.com>2018-06-27 22:06:49 -0700
committerJosh Cooper <josh@puppet.com>2018-06-27 22:08:47 -0700
commit69f941224a43275896218807fd91c8e5b912f8d1 (patch)
tree06311b92c16f40868be7a106e3e831b6c97b7d51 /spec/acceptance/hosts.rb
parentc051e86b350329bc1a7cd1c9c239ec29212b8e56 (diff)
downloadpuppet-augeas_core-69f941224a43275896218807fd91c8e5b912f8d1.tar.gz
puppet-augeas_core-69f941224a43275896218807fd91c8e5b912f8d1.tar.bz2
Initial augeas import from puppet#2b83deb189
Diffstat (limited to 'spec/acceptance/hosts.rb')
-rw-r--r--spec/acceptance/hosts.rb78
1 files changed, 78 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