File: lookup_data.rb

package info (click to toggle)
puppet-agent 8.10.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,404 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (108 lines) | stat: -rw-r--r-- 2,357 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
test_name "Lookup data using the hiera_array parser function"

tag 'audit:high',
    'audit:acceptance',
    'audit:refactor'    # Master is not required for this test. Replace with agents.each

testdir = master.tmpdir('hiera')

step 'Setup'

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':;
}

file { '#{testdir}/hiera.yaml':
  ensure  => file,
  content => '---
    :backends:
      - "yaml"
    :logger: "console"
    :hierarchy:
      - "%{environment}"
      - "global"

    :yaml:
      :datadir: "#{testdir}/hieradata"
  ',
  mode => "0640";
}

file { '#{testdir}/hieradata/global.yaml':
  ensure  => file,
  content => "---
    port: '8080'
    ntpservers: ['global.ntp.puppetlabs.com']
  ",
  mode => "0640";
}

file { '#{testdir}/hieradata/production.yaml':
  ensure  => file,
  content => "---
    ntpservers: ['production.ntp.puppetlabs.com']
  ",
  mode => "0640";
}

file {
  '#{testdir}/environments/production/modules/ntp':;
  '#{testdir}/environments/production/modules/ntp/manifests':;
}

file { '#{testdir}/environments/production/modules/ntp/manifests/init.pp':
  ensure => file,
  content => '
    class ntp {
      $ntpservers = hiera_array("ntpservers")

      define print {
        $server = $name
        notify { "ntpserver ${server}": }
      }

      ntp::print { $ntpservers: }
    }',
  mode => "0640";
}

file { '#{testdir}/environments/production/manifests/site.pp':
  ensure => file,
  content => "
    node default {
      include ntp
    }",
  mode => "0640";
}
PP

step "Try to lookup array data"

master_opts = {
  'main' => {
    'environmentpath' => "#{testdir}/environments",
    'hiera_config' => "#{testdir}/hiera.yaml",
  },
}

with_puppet_running_on master, master_opts, testdir do
  agents.each do |agent|
    on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result|
      assert_match('ntpserver global.ntp.puppetlabs.com', result.stdout)
      assert_match('ntpserver production.ntp.puppetlabs.com', result.stdout)
    end
  end
end