Skip to content

Commit fd134ce

Browse files
authored
Merge pull request #201 from github/1-5-4
Release 1.5.4
2 parents ea513b6 + 3eb7093 commit fd134ce

File tree

33 files changed

+234
-72
lines changed

33 files changed

+234
-72
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.3
1+
1.5.4

doc/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
</tr>
99
</thead><tbody>
1010

11+
<tr valign=top>
12+
<td>1.5.4</td>
13+
<td>2018-12-11</td>
14+
<td>
15+
<li><a href="https://github.com/github/octocatalog-diff/pull/190">#190</a>: (Enhancement) Additional filtered out cases for compilation directory</li>
16+
<li><a href="https://github.com/github/octocatalog-diff/pull/195">#195</a>: (Enhancement) Parallel catalog-diff when multiple hostnames are passed</li>
17+
<li><a href="https://github.com/github/octocatalog-diff/pull/198">#198</a>: (Bug Fix) Portability fixes</li>
18+
<li><a href="https://github.com/github/octocatalog-diff/pull/200">#200</a>: (Bug Fix) Support name parameter when validating references</li>
19+
</td>
20+
</tr>
21+
1122
<tr valign=top>
1223
<td>1.5.3</td>
1324
<td>2018-03-05</td>

doc/dev/api/v1/objects/diff.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ Returns the value of the resource from the new catalog.
9494
}
9595
}
9696
97-
# Demonstrates structure and old_value
97+
# Demonstrates structure and new_value
9898
diff.structure #=> ['parameters', 'content']
99-
diff.old_value #=> 'This is the NEW FILE!!!!!'
99+
diff.new_value #=> 'This is the NEW FILE!!!!!'
100100
```
101101

102102
#### `#old_file` (String)
@@ -107,7 +107,7 @@ Note that this is a pass-through of information provided in the Puppet catalog,
107107

108108
Note also that if the diff represents addition of a resource, this will return `nil`, because the resource does not exist in the old catalog.
109109

110-
#### `#old_file` (String)
110+
#### `#old_line` (String)
111111

112112
Returns the line number within the Puppet manifest giving rise to the resource as it exists in the old catalog. (See `#old_file` for the filename of the Puppet manifest.)
113113

doc/dev/releasing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The project maintainers are responsible for bumping the version number, regenera
99
To test the new version of `octocatalog-diff` in the GitHub Puppet repository, check out `github/puppet` and:
1010

1111
- Start a new branch based off master
12-
- Run `script/update-octocatalog-diff -r <ocd_branch_name>`
12+
- Run `script/update-octocatalog-diff <ocd_branch_name>`
1313
- Confirm and commit the result
1414
- Make sure all CI jobs pass
1515
- Run the `puppet-catalog-diff` CI job and make sure it passes and shows expected results

doc/optionsref.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
```
1111
Usage: octocatalog-diff [command line options]
12-
-n, --hostname HOSTNAME Use PuppetDB facts from last run of hostname
12+
-n HOSTNAME1[,HOSTNAME2[,...]], Use PuppetDB facts from last run of a hostname or a comma separated list of multiple hostnames
13+
--hostname
1314
--basedir DIRNAME Use an alternate base directory (git checkout of puppet repository)
1415
-f, --from FROM_BRANCH Branch you are coming from
1516
-t, --to TO_BRANCH Branch you are going to
@@ -856,14 +857,17 @@ Puppet control repo template, the value of this should be 'hieradata', which is
856857

857858
<tr>
858859
<td valign=top>
859-
<pre><code>-n HOSTNAME
860-
--hostname HOSTNAME</code></pre>
860+
<pre><code>-n HOSTNAME1[,HOSTNAME2[,...]]
861+
--hostname HOSTNAME1[,HOSTNAME2[,...]]</code></pre>
861862
</td>
862863
<td valign=top>
863-
Use PuppetDB facts from last run of hostname
864+
Use PuppetDB facts from last run of a hostname or a comma separated list of multiple hostnames
864865
</td>
865866
<td valign=top>
866-
Set hostname, which is used to look up facts in PuppetDB, and in the header of diff display. (<a href="../lib/octocatalog-diff/cli/options/hostname.rb">hostname.rb</a>)
867+
Set hostname, which is used to look up facts in PuppetDB, and in the header of diff display.
868+
This option can recieve a single hostname, or a comma separated list of
869+
multiple hostnames, which are split into an Array. Multiple hostnames do not
870+
work with the `catalog-only` or `bootstrap-then-exit` options. (<a href="../lib/octocatalog-diff/cli/options/hostname.rb">hostname.rb</a>)
867871
</td>
868872
</tr>
869873

examples/script-overrides/git-extract-submodules/git-extract.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# This script is called from lib/octocatalog-diff/catalog-util/git.rb and is used to
44
# archive and extract a certain branch of a git repository into a target directory.

lib/octocatalog-diff/catalog-diff/filter/compilation_dir.rb

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative '../filter'
4+
require_relative '../../util/util'
45

56
module OctocatalogDiff
67
module CatalogDiff
@@ -35,43 +36,46 @@ def filtered?(diff, options = {})
3536

3637
# Check for a change where the difference in a parameter exactly corresponds to the difference in the
3738
# compilation directory.
38-
if diff.change? && (diff.old_value.is_a?(String) || diff.new_value.is_a?(String))
39-
from_before = nil
40-
from_after = nil
41-
from_match = false
42-
to_before = nil
43-
to_after = nil
44-
to_match = false
39+
if diff.change?
40+
o = remove_compilation_dir(diff.old_value, dir2)
41+
n = remove_compilation_dir(diff.new_value, dir1)
4542

46-
if diff.old_value =~ /^(.*)#{dir2}(.*)$/m
47-
from_before = Regexp.last_match(1) || ''
48-
from_after = Regexp.last_match(2) || ''
49-
from_match = true
50-
end
51-
52-
if diff.new_value =~ /^(.*)#{dir1}(.*)$/m
53-
to_before = Regexp.last_match(1) || ''
54-
to_after = Regexp.last_match(2) || ''
55-
to_match = true
56-
end
57-
58-
if from_match && to_match && to_before == from_before && to_after == from_after
43+
if o != diff.old_value || n != diff.new_value
5944
message = "Resource key #{diff.type}[#{diff.title}] #{diff.structure.join(' => ')}"
60-
message += ' appears to depend on catalog compilation directory. Suppressed from results.'
45+
message += ' may depend on catalog compilation directory, but there may be differences.'
46+
message += ' This is included in results for now, but please verify.'
6147
@logger.warn message
62-
return true
6348
end
6449

65-
if from_match || to_match
50+
if o == n
6651
message = "Resource key #{diff.type}[#{diff.title}] #{diff.structure.join(' => ')}"
67-
message += ' may depend on catalog compilation directory, but there may be differences.'
68-
message += ' This is included in results for now, but please verify.'
52+
message += ' appears to depend on catalog compilation directory. Suppressed from results.'
6953
@logger.warn message
54+
return true
7055
end
7156
end
7257

7358
false
7459
end
60+
61+
def remove_compilation_dir(v, dir)
62+
value = OctocatalogDiff::Util::Util.deep_dup(v)
63+
traverse(value) do |e|
64+
e.gsub!(dir, '') if e.respond_to?(:gsub!)
65+
end
66+
value
67+
end
68+
69+
def traverse(a)
70+
case a
71+
when Array
72+
a.map { |v| traverse(v, &Proc.new) }
73+
when Hash
74+
traverse(a.values, &Proc.new)
75+
else
76+
yield a
77+
end
78+
end
7579
end
7680
end
7781
end

lib/octocatalog-diff/catalog.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ def build_resource_hash
331331
title = normalized_title(resource['title'], resource['type'])
332332
@resource_hash[resource['type']][title] = resource
333333

334-
if resource.key?('parameters') && resource['parameters'].key?('alias')
335-
@resource_hash[resource['type']][resource['parameters']['alias']] = resource
334+
if resource.key?('parameters')
335+
@resource_hash[resource['type']][resource['parameters']['alias']] = resource if resource['parameters'].key?('alias')
336+
@resource_hash[resource['type']][resource['parameters']['name']] = resource if resource['parameters'].key?('name')
336337
end
337338
end
338339
end

lib/octocatalog-diff/cli.rb

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
require_relative 'version'
1212

1313
require 'logger'
14+
require 'parallel'
1415
require 'socket'
1516

1617
module OctocatalogDiff
@@ -116,16 +117,46 @@ def self.cli(argv = ARGV, logger = Logger.new(STDERR), opts = {})
116117
end
117118

118119
# Compile catalogs and do catalog-diff
119-
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options.merge(logger: logger))
120+
node_set = options.delete(:node)
121+
node_set = [node_set] unless node_set.is_a?(Array)
122+
123+
# run multiple node diffs in parallel
124+
catalog_diffs = if node_set.size == 1
125+
[run_octocatalog_diff(node_set.first, options, logger)]
126+
else
127+
::Parallel.map(node_set, in_threads: 4) { |node| run_octocatalog_diff(node, options, logger) }
128+
end
129+
130+
# Return the resulting diff object if requested (generally for testing)
131+
# or otherwise return exit code
132+
return catalog_diffs.first if opts[:INTEGRATION]
133+
134+
all_diffs = catalog_diffs.map(&:diffs)
135+
136+
all_diffs.each do |diff|
137+
next unless diff.any?
138+
return EXITCODE_SUCCESS_WITH_DIFFS
139+
end
140+
141+
EXITCODE_SUCCESS_NO_DIFFS
142+
end
143+
144+
# Run the octocatalog-diff process for a given node. Return the diffs for a contribution to
145+
# the final exit status.
146+
# node - String with the node
147+
# options - All of the currently defined options
148+
# logger - Logger object
149+
def self.run_octocatalog_diff(node, options, logger)
150+
options_copy = options.merge(node: node)
151+
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options_copy.merge(logger: logger))
120152
diffs = catalog_diff.diffs
121153

122154
# Display diffs
123-
printer_obj = OctocatalogDiff::Cli::Printer.new(options, logger)
155+
printer_obj = OctocatalogDiff::Cli::Printer.new(options_copy, logger)
124156
printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir)
125157

126-
# Return the resulting diff object if requested (generally for testing) or otherwise return exit code
127-
return catalog_diff if opts[:INTEGRATION]
128-
diffs.any? ? EXITCODE_SUCCESS_WITH_DIFFS : EXITCODE_SUCCESS_NO_DIFFS
158+
# Return catalog-diff object.
159+
catalog_diff
129160
end
130161

131162
# Parse command line options with 'optparse'. Returns a hash with the parsed arguments.

lib/octocatalog-diff/cli/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Cli
1111
# This class contains the option parser. 'parse_options' is the external entry point.
1212
class Options
1313
# The usage banner.
14-
BANNER = 'Usage: catalog-diff -n <hostname> [-f <from environment>] [-t <to environment>]'.freeze
14+
BANNER = 'Usage: catalog-diff -n <hostname>[,<hostname>...] [-f <from environment>] [-t <to environment>]'.freeze
1515

1616
# An error class specifically for passing information to the document build task.
1717
class DocBuildError < RuntimeError; end

0 commit comments

Comments
 (0)