Merge remote-tracking branch 'EdgeJ/add_multiple_node_option' into 1-5-4

This commit is contained in:
Kevin Paulisse 2018-12-06 21:49:27 -06:00
Родитель e04026f42e 395ba139c9
Коммит 759607538d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 66DA91D838188671
6 изменённых файлов: 54 добавлений и 14 удалений

Просмотреть файл

@ -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
@ -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>

Просмотреть файл

@ -11,6 +11,7 @@ require_relative 'util/util'
require_relative 'version'
require 'logger'
require 'parallel'
require 'socket'
module OctocatalogDiff
@ -116,16 +117,34 @@ module OctocatalogDiff
end
# Compile catalogs and do catalog-diff
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options.merge(logger: logger))
diffs = catalog_diff.diffs
node_set = options.delete(:node)
node_set = [node_set] unless node_set.is_a?(Array)
catalog_diff = nil
all_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)
# 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.

Просмотреть файл

@ -11,7 +11,7 @@ module OctocatalogDiff
# 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

Просмотреть файл

@ -1,6 +1,9 @@
# 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.
@ -8,8 +11,16 @@ 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

Просмотреть файл

@ -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'

Просмотреть файл

@ -8,5 +8,10 @@ describe OctocatalogDiff::Cli::Options do
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