Skip to content

Commit 6e66c62

Browse files
authored
Merge branch 'master' into kpaulisse-remove-time-based-tests
2 parents 5fcca80 + 4aceadc commit 6e66c62

26 files changed

Lines changed: 503 additions & 22 deletions

File tree

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.4
1+
0.5.7

doc/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
</tr>
99
</thead><tbody>
1010
<tr valign=top>
11+
<td>0.5.6</td>
12+
<td>2016-11-16</td>
13+
<td>
14+
<ul>
15+
<li><a href="https://github.com/github/octocatalog-diff/pull/20">https://github.com/github/octocatalog-diff/pull/20</a>: Use modulepath from environment.conf to inform lookup directories for <code>--compare-file-text</code> feature</li>
16+
</ul>
17+
</td>
18+
</tr>
19+
<tr valign=top>
20+
<td>0.5.5</td>
21+
<td>-</td>
22+
<td>
23+
Unreleased internal version
24+
</td>
25+
</tr>
26+
<tr valign=top>
1127
<td>0.5.4</td>
1228
<td>2016-11-07</td>
1329
<td>

doc/advanced-bootstrap.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,28 @@ The [example configuration file](/examples/octocatalog-diff.cfg.rb) contains an
3131
# settings[:bootstrap_script] = '/etc/puppetlabs/repo-bootstrap.sh' # Absolute path
3232
# settings[:bootstrap_script] = 'script/bootstrap' # Relative path
3333
```
34+
35+
## Bootstrap environment
36+
37+
When the bootstrap script runs, a limited set of environment variables are passed from the shell running octocatalog-diff. Only these variables are set:
38+
39+
- `HOME`
40+
- `PATH`
41+
- `PWD` (set to the base directory of your Puppet checkout)
42+
- `BASEDIR` (as explicitly set with `--basedir` CLI option or `settings[:basedir]` setting)
43+
44+
If you wish to set additional environment variables for your bootstrap script, you may do so via the `--bootstrap-environment VAR=value` command line flag, or by defining `settings[:bootstrap_environment] = { 'VAR' => 'value' }` in your configuration file.
45+
46+
As an example, consider that your bootstrap script is written in Python, and needs the `PYTHONPATH` variable set to `/usr/local/lib/python-custom`. Even if this environment variable is set when octocatalog-diff is run, it will not be available to the bootstrap script. You may supply it via the command line:
47+
48+
```
49+
octocatalog-diff --bootstrap-environment PYTHONPATH=/usr/local/lib/python-custom ...
50+
```
51+
52+
Or you may specify it in your configuration file:
53+
54+
```
55+
settings[:bootstrap_environment] = {
56+
'PYTHONPATH' => '/usr/local/lib/python-custom'
57+
}
58+
```

doc/advanced-hiera-path-stripping.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ bin/octocatalog-diff --hiera-config hiera.yaml --hiera-path-strip /etc/puppetlab
3737
:yaml:
3838
:datadir: /var/tmp/puppet-compile-dir-92347829847/environments/%{environment}/hieradata
3939
```
40+
41+
:warning: Be sure that you do NOT include a trailing slash on `--hiera-path-strip` or `settings[:hiera_path_strip]`.

doc/configuration-enc.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,37 @@ For example, when compiling the catalog for `some-node.github.net`, Puppet will
6767
```
6868
6969
Sometimes the ENC script requires credentials or makes other assumptions about the system on which it is running. To be able to run the ENC script on systems other than your Puppet master, you will need to ensure that any such credentials are supplied and other assumptions are met.
70+
71+
## Environment
72+
73+
When the ENC is executed, the following environment variables are set to match the environment of the shell in which octocatalog-diff executes:
74+
75+
- `HOME`
76+
- `PATH`
77+
- `PWD` (set to the temporary directory as previously described)
78+
79+
No other environment variables are passed from the shell. If you wish to pass additional environment variables, you must explicitly list them with the `--pass-env-vars` CLI flag or `settings[:pass_env_vars]` array in your configuration file.
80+
81+
As an example, consider that your ENC is written in Python, and needs the `PYTHONPATH` variable set to `/usr/local/lib/python-custom`. Even if this environment variable is set when octocatalog-diff is run, it will not be available to the ENC script. You may pass the variable via the command line:
82+
83+
```
84+
octocatalog-diff --pass-env-vars PYTHONPATH ...
85+
```
86+
87+
Or you may specify it in your configuration file:
88+
89+
```
90+
settings[:pass_env_vars] = [ 'PYTHONPATH' ]
91+
```
92+
93+
If you wish to specify multiple environment variables to pass:
94+
95+
```
96+
octocatalog-diff --pass-env-vars PYTHONPATH,SECONDVAR,THIRDVAR ...
97+
```
98+
99+
or
100+
101+
```
102+
settings[:pass_env_vars] = [ 'PYTHONPATH', 'SECONDVAR', 'THIRDVAR' ]
103+
```

examples/octocatalog-diff.cfg.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def self.config
5656
# In this case, you desire to strip `/etc/puppetlabs/code` from the beginning of the path,
5757
# in order that octocatalog-diff can find your hiera datafiles in the compilation
5858
# location, which is {temporary directory}/environments/production/hieradata.
59+
# If you use this, be sure that you do NOT include a trailing slash!
5960
#
6061
# More: https://github.com/github/octocatalog-diff/blob/master/doc/configuration-hiera.md
6162
##############################################################################################

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def install_hiera_config(logger, options)
197197

198198
# Munge datadir in hiera config file
199199
obj = YAML.load_file(file_src)
200-
%w(yaml json).each do |key|
200+
(obj[:backends] || %w(yaml json)).each do |key|
201201
next unless obj.key?(key.to_sym)
202202
if options[:hiera_path_strip].is_a?(String)
203203
next if obj[key.to_sym][:datadir].nil?

lib/octocatalog-diff/catalog-util/fileresources.rb

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,45 @@ def self.convert_file_resources(obj)
2121
end
2222
end
2323

24+
# Internal method: Locate a file that is referenced at puppet:///modules/xxx/yyy using the
25+
# module path that is specified within the environment.conf file (assuming the default 'modules'
26+
# directory doesn't exist or the module isn't found in there). If the file can't be found then
27+
# this returns nil which may trigger an error.
28+
# @param src [String] A file reference: puppet:///modules/xxx/yyy
29+
# @param modulepaths [Array] Cached module path
30+
# @return [String] File system path to referenced file
31+
def self.file_path(src, modulepaths)
32+
unless src =~ %r{^puppet:///modules/([^/]+)/(.+)}
33+
raise ArgumentError, "Bad parameter source #{src}"
34+
end
35+
36+
path = File.join(Regexp.last_match(1), 'files', Regexp.last_match(2))
37+
modulepaths.each do |mp|
38+
file = File.join(mp, path)
39+
return file if File.exist?(file)
40+
end
41+
42+
nil
43+
end
44+
45+
# Internal method: Parse environment.conf to find the modulepath
46+
# @param compilation_dir [String] Compilation directory
47+
# @return [Array] Module paths
48+
def self.module_path(compilation_dir)
49+
environment_conf = File.join(compilation_dir, 'environment.conf')
50+
unless File.file?(environment_conf)
51+
return [File.join(compilation_dir, 'modules')]
52+
end
53+
54+
# This doesn't support multi-line, continuations with backslash, etc.
55+
# Does it need to??
56+
if File.read(environment_conf) =~ /^modulepath\s*=\s*(.+)/
57+
Regexp.last_match(1).split(/:/).map(&:strip).reject { |x| x =~ /^\$/ }.map { |x| File.join(compilation_dir, x) }
58+
else
59+
[File.join(compilation_dir, 'modules')]
60+
end
61+
end
62+
2463
# Internal method: Static method to convert file resources. The compilation directory is
2564
# required, or else this is a no-op. The passed-in array of resources is modified by this method.
2665
# @param resources [Array<Hash>] Array of catalog resources
@@ -34,18 +73,15 @@ def self._convert_file_resources(resources, compilation_dir)
3473
# that compilation_dir/environments/production is pointing at the right place). Otherwise, try to find
3574
# compilation_dir/modules. If neither of those exist, this code can't run.
3675
env_dir = File.join(compilation_dir, 'environments', 'production')
37-
unless File.directory?(File.join(env_dir, 'modules'))
38-
return unless File.directory?(File.join(compilation_dir, 'modules'))
39-
env_dir = compilation_dir
40-
end
76+
modulepaths = module_path(env_dir) + module_path(compilation_dir)
77+
modulepaths.select! { |x| File.directory?(x) }
78+
return if modulepaths.empty?
4179

42-
# Modify the resources
80+
# At least one existing module path was found! Run the code to modify the resources.
4381
resources.map! do |resource|
4482
if resource_convertible?(resource)
45-
# Parse the 'source' parameter into a file on disk
46-
src = resource['parameters']['source']
47-
raise "Bad parameter source #{src}" unless src =~ %r{^puppet:///modules/([^/]+)/(.+)}
48-
path = File.join(env_dir, 'modules', Regexp.last_match(1), 'files', Regexp.last_match(2))
83+
path = file_path(resource['parameters']['source'], modulepaths)
84+
raise Errno::ENOENT, "Unable to resolve '#{resource['parameters']['source']}'!" if path.nil?
4985

5086
if File.file?(path)
5187
# If the file is found, read its content. If the content is all ASCII, substitute it into
@@ -60,7 +96,10 @@ def self._convert_file_resources(resources, compilation_dir)
6096
# However, the fact that we found *something* at this location indicates that the catalog
6197
# is probably correct. Hence, the very general .exist? check.
6298
else
63-
raise Errno::ENOENT, "Unable to find '#{src}' at #{path}!"
99+
# This is probably a bug
100+
# :nocov:
101+
raise "Unable to find '#{resource['parameters']['source']}' at #{path}!"
102+
# :nocov:
64103
end
65104
end
66105
resource

lib/octocatalog-diff/catalog/puppetmaster.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ def build(logger = Logger.new(StringIO.new))
6868

6969
# Returns a hash of parameters for each supported version of the Puppet Server Catalog API.
7070
# @return [Hash] Hash of parameters
71+
#
72+
# Note: The double escaping of the facts here is implemented to correspond to a long standing
73+
# bug in the Puppet code. See https://github.com/puppetlabs/puppet/pull/1818 and
74+
# https://docs.puppet.com/puppet/latest/http_api/http_catalog.html#parameters for explanation.
7175
def puppet_catalog_api
7276
{
7377
2 => {
7478
url: "https://#{@options[:puppet_master]}/#{@options[:branch]}/catalog/#{@node}",
7579
parameters: {
7680
'facts_format' => 'pson',
77-
'facts' => @facts.fudge_timestamp.without('trusted').to_pson,
81+
'facts' => CGI.escape(@facts.fudge_timestamp.without('trusted').to_pson),
7882
'transaction_uuid' => SecureRandom.uuid
7983
}
8084
},
@@ -83,7 +87,7 @@ def puppet_catalog_api
8387
parameters: {
8488
'environment' => @options[:branch],
8589
'facts_format' => 'pson',
86-
'facts' => @facts.fudge_timestamp.without('trusted').to_pson,
90+
'facts' => CGI.escape(@facts.fudge_timestamp.without('trusted').to_pson),
8791
'transaction_uuid' => SecureRandom.uuid
8892
}
8993
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"document_type": "Catalog",
3+
"tags": ["settings","test"],
4+
"name": "my.rspec.node",
5+
"version": "production",
6+
"environment": "production",
7+
"resources": [
8+
{
9+
"type": "Stage",
10+
"title": "main",
11+
"tags": ["stage"],
12+
"exported": false,
13+
"parameters": {
14+
"name": "main"
15+
}
16+
},
17+
{
18+
"type": "Class",
19+
"title": "Settings",
20+
"tags": ["class","settings"],
21+
"exported": false
22+
},
23+
{
24+
"type": "File",
25+
"title": "/tmp/foo",
26+
"tags": ["file","class"],
27+
"file": "/x/modules/modulestest/manifests/init.pp",
28+
"line": 37,
29+
"exported": false,
30+
"parameters": {
31+
"backup": false,
32+
"mode": "0440",
33+
"owner": "root",
34+
"group": "root",
35+
"source": "puppet:///modules/modulestest/tmp/modulestest"
36+
}
37+
},
38+
{
39+
"type": "File",
40+
"title": "/tmp/foobaz",
41+
"tags": ["file","class"],
42+
"file": "/x/modules/modulestest/manifests/init.pp",
43+
"line": 37,
44+
"exported": false,
45+
"parameters": {
46+
"backup": false,
47+
"ensure": "directory",
48+
"mode": "0755",
49+
"owner": "root",
50+
"group": "root",
51+
"source": "puppet:///modules/modulestest/foo"
52+
}
53+
}
54+
],
55+
"classes": [
56+
"test"
57+
]
58+
}

0 commit comments

Comments
 (0)