Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
language: ruby
install: true
script: "script/cibuild"
before_install: gem install bundler

matrix:
include:
Expand Down
14 changes: 9 additions & 5 deletions doc/optionsref.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

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

<tr>
<td valign=top>
<pre><code>-n HOSTNAME
--hostname HOSTNAME</code></pre>
<pre><code>-n HOSTNAME1[,HOSTNAME2[,...]]
--hostname HOSTNAME1[,HOSTNAME2[,...]]</code></pre>
</td>
<td valign=top>
Use PuppetDB facts from last run of hostname
Use PuppetDB facts from last run of a hostname or a comma separated list of multiple hostnames
</td>
<td valign=top>
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>)
Set hostname, which is used to look up facts in PuppetDB, and in the header of diff display.
This option can recieve a single hostname, or a comma separated list of
multiple hostnames, which are split into an Array. Multiple hostnames do not
work with the `catalog-only` or `bootstrap-then-exit` options. (<a href="../lib/octocatalog-diff/cli/options/hostname.rb">hostname.rb</a>)
</td>
</tr>

Expand Down
33 changes: 26 additions & 7 deletions lib/octocatalog-diff/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_relative 'version'

require 'logger'
require 'parallel'
require 'socket'

module OctocatalogDiff
Expand Down Expand Up @@ -116,16 +117,34 @@ def self.cli(argv = ARGV, logger = Logger.new(STDERR), opts = {})
end

# Compile catalogs and do catalog-diff
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options.merge(logger: logger))
diffs = catalog_diff.diffs

# Display diffs
printer_obj = OctocatalogDiff::Cli::Printer.new(options, logger)
printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir)
node_set = options.delete(:node)
node_set = [node_set] unless node_set.is_a?(Array)
catalog_diff = nil
all_diffs = []

# run multiple node diffs in parallel
Parallel.map(node_set, in_threads: 4) do |node|
options[:node] = node
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options.merge(logger: logger))
diffs = catalog_diff.diffs

# Display diffs
printer_obj = OctocatalogDiff::Cli::Printer.new(options, logger)
printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir)

# Append any diffs for final exit status
all_diffs << diffs
end

# Return the resulting diff object if requested (generally for testing) or otherwise return exit code
return catalog_diff if opts[:INTEGRATION]
diffs.any? ? EXITCODE_SUCCESS_WITH_DIFFS : EXITCODE_SUCCESS_NO_DIFFS

all_diffs.each do |diff|
next unless diff.any?
return EXITCODE_SUCCESS_WITH_DIFFS
end

EXITCODE_SUCCESS_NO_DIFFS
end

# Parse command line options with 'optparse'. Returns a hash with the parsed arguments.
Expand Down
2 changes: 1 addition & 1 deletion lib/octocatalog-diff/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Cli
# This class contains the option parser. 'parse_options' is the external entry point.
class Options
# The usage banner.
BANNER = 'Usage: catalog-diff -n <hostname> [-f <from environment>] [-t <to environment>]'.freeze
BANNER = 'Usage: catalog-diff -n <hostname>[,<hostname>...] [-f <from environment>] [-t <to environment>]'.freeze

# An error class specifically for passing information to the document build task.
class DocBuildError < RuntimeError; end
Expand Down
15 changes: 13 additions & 2 deletions lib/octocatalog-diff/cli/options/hostname.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# frozen_string_literal: true

# Set hostname, which is used to look up facts in PuppetDB, and in the header of diff display.
# This option can recieve a single hostname, or a comma separated list of
# multiple hostnames, which are split into an Array. Multiple hostnames do not
# work with the `catalog-only` or `bootstrap-then-exit` options.
# @param parser [OptionParser object] The OptionParser argument
# @param options [Hash] Options hash being constructed; this is modified in this method.

OctocatalogDiff::Cli::Options::Option.newoption(:hostname) do
has_weight 1

def parse(parser, options)
parser.on('--hostname HOSTNAME', '-n', 'Use PuppetDB facts from last run of hostname') do |hostname|
options[:node] = hostname
parser.on(
'--hostname HOSTNAME1[,HOSTNAME2[,...]]',
'-n',
'Use PuppetDB facts from last run of a hostname or a comma separated list of multiple hostnames'
) do |hostname|
options[:node] = if hostname.include?(',')
hostname.split(',')
else
hostname
end
end
end
end
1 change: 1 addition & 0 deletions octocatalog-diff.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ EOF
s.add_runtime_dependency 'diffy', '>= 3.1.0'
s.add_runtime_dependency 'httparty', '>= 0.11.0'
s.add_runtime_dependency 'hashdiff', '>= 0.3.0'
s.add_runtime_dependency 'parallel', '>= 1.12.0'
s.add_runtime_dependency 'rugged', '>= 0.25.0b2'

s.add_development_dependency 'rspec', '~> 3.4.0'
Expand Down
5 changes: 5 additions & 0 deletions spec/octocatalog-diff/tests/cli/options/hostname_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
result = run_optparse(['-n', 'octonode.rspec'])
expect(result.fetch(:node, 'key-not-defined')).to eq('octonode.rspec')
end

it 'should set multiple nodes when passed a series of nodes' do
result = run_optparse(['-n', 'octonode1.rspec,octonode2.rspec'])
expect(result.fetch(:node, 'key-not-defined')).to eq(%w[octonode1.rspec octonode2.rspec])
end
end
end