onceover-octocatalog-diff 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/onceover/octocatalog/diff.rb +17 -0
- data/lib/onceover/octocatalog/diff/cli.rb +108 -0
- data/lib/onceover/octocatalog/diff/version.rb +7 -0
- data/onceover-octocatalog-diff.gemspec +28 -0
- data/templates/change_manifest.rb.erb +22 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 691c97a6f9063f49509f7c24f7e6a969ca77e59f
|
4
|
+
data.tar.gz: 393491acfe7f393c47222b2b170cd2e92e01cee2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33dee3aa8d06df1571bce554905711bd3c67109d4a5d6a8c417a362344078090396fa303b0484f3e70765151e092fa07ad0d259c67327f4ba1a076aff3511739
|
7
|
+
data.tar.gz: 024e1ecb4bc1eaabd600e90b7749c12436b728ced60f98eb1ad970dcd29ab338b53f37b4308d33c57ce7f78dc9abf29082e239021e7eddc918576a28b977462c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dylan Ratcliffe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Octocatalog-diff Onceover plugin
|
2
|
+
|
3
|
+
This plugin adds the `onceover run diff` command to onceover. Instead of testing that all if your catalogs compile, it compiles two versions of each catalog and returns you the differences. This is great for ensuring that changed that you were intending to make have had the desired effect and scope.
|
4
|
+
|
5
|
+
Kudos to Kevin and the team at GitHub for actually building [octocatalog-diff](https://github.com/github/octocatalog-diff)!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'onceover-octocatalog-diff'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install onceover-octocatalog-diff
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
`onceover run diff`
|
26
|
+
|
27
|
+
All config follows the normal [onceover](https://github.com/dylanratcliffe/onceover) configuration.
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dylanratcliffe/onceover-octocatalog-diff.
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "onceover/octocatalog/diff"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "onceover/octocatalog/diff/version"
|
2
|
+
require "onceover/octocatalog/diff/cli"
|
3
|
+
|
4
|
+
class Onceover
|
5
|
+
module Octocatalog
|
6
|
+
module Diff
|
7
|
+
def self.create_facts_yaml(repo,output_location)
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
repo.facts_files.each do |facts_file|
|
11
|
+
facts = JSON.load(File.read(facts_file))
|
12
|
+
File.open("#{output_location}/#{File.basename(facts_file,'.*')}.yaml", 'w') {|f| f.write facts.to_yaml }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
class Onceover
|
2
|
+
class CLI
|
3
|
+
class Run
|
4
|
+
class Diff
|
5
|
+
def self.command
|
6
|
+
@cmd ||= Cri::Command.define do
|
7
|
+
name 'diff'
|
8
|
+
usage 'diff'
|
9
|
+
summary "Diff two versions of the controlrepo's compiled catalogs"
|
10
|
+
description <<-DESCRIPTION
|
11
|
+
This uses octocatalog-diff to run diffs on all things in the test matrix
|
12
|
+
instead of actually testing them. Requires two branches, tags or
|
13
|
+
revisions to compare between.
|
14
|
+
DESCRIPTION
|
15
|
+
|
16
|
+
option :f, :from, 'branch to compare from', argument: :required
|
17
|
+
option :t, :to, 'branch to compare to', argument: :required
|
18
|
+
|
19
|
+
run do |opts, args, cmd|
|
20
|
+
require 'pry'
|
21
|
+
require 'facter'
|
22
|
+
require 'colored'
|
23
|
+
|
24
|
+
#TODO: Allow for custom arguments
|
25
|
+
repo = Onceover::Controlrepo.new(opts)
|
26
|
+
test_config = Onceover::TestConfig.new(repo.onceover_yaml, opts)
|
27
|
+
num_threads = (Facter.value('processors')['count'] / 2)
|
28
|
+
#runner.prepare!
|
29
|
+
tests = test_config.run_filters(Onceover::Test.deduplicate(test_config.spec_tests))
|
30
|
+
@queue = tests.inject(Queue.new, :push)
|
31
|
+
@results = []
|
32
|
+
|
33
|
+
@threads = Array.new(num_threads) do
|
34
|
+
Thread.new do
|
35
|
+
until @queue.empty?
|
36
|
+
test = @queue.shift
|
37
|
+
|
38
|
+
logger.info "Preparing environment for #{test.classes[0].name} on #{test.nodes[0].name}"
|
39
|
+
logger.debug "Creating temp directory"
|
40
|
+
tempdir = Dir.mktmpdir(test.to_s)
|
41
|
+
logger.debug "Temp directory created at #{tempdir}"
|
42
|
+
|
43
|
+
logger.debug "Copying controlrepo to #{tempdir}"
|
44
|
+
FileUtils.copy_entry(repo.root,tempdir)
|
45
|
+
|
46
|
+
logger.debug "Converting facts to yaml"
|
47
|
+
Onceover::Octocatalog::Diff.create_facts_yaml(repo,"#{tempdir}/spec/factsets")
|
48
|
+
|
49
|
+
logger.info "Deploying Puppetfile for #{test.classes[0].name} on #{test.nodes[0].name}"
|
50
|
+
r10k_cmd = "r10k puppetfile install --verbose --color --puppetfile #{repo.puppetfile}"
|
51
|
+
Open3.popen3(r10k_cmd) do |stdin, stdout, stderr, wait_thr|
|
52
|
+
exit_status = wait_thr.value
|
53
|
+
if exit_status.exitstatus != 0
|
54
|
+
throw stderr
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# TODO: Improve the way this works so that it doesn't blat site.pp
|
59
|
+
logger.debug "Creating before script that overwrites site.pp"
|
60
|
+
class_name = test.classes[0].name
|
61
|
+
template_dir = File.expand_path('../../../../templates',File.dirname(__FILE__))
|
62
|
+
template = File.read(File.expand_path("./change_manifest.rb.erb",template_dir))
|
63
|
+
File.write("#{tempdir}/bootstrap_script.rb",ERB.new(template, nil, '-').result(binding))
|
64
|
+
FileUtils.chmod("u=rwx","#{tempdir}/bootstrap_script.rb")
|
65
|
+
|
66
|
+
logger.debug "Getting Puppet binary"
|
67
|
+
binary = `which puppet`.chomp
|
68
|
+
|
69
|
+
logger.debug "Running Octocatalog diff"
|
70
|
+
logger.debug "Command: octocatalog-diff --fact-file #{tempdir}/spec/factsets/#{test.nodes[0].name}.yaml -f #{opts[:from]} -t #{opts[:to]} --basedir #{tempdir} --puppet-binary #{binary} --bootstrap-script #{tempdir}/bootstrap_script.rb"
|
71
|
+
logger.info "Compiling catalogs for #{test.classes[0].name} on #{test.nodes[0].name}"
|
72
|
+
cmd = "octocatalog-diff --fact-file #{tempdir}/spec/factsets/#{test.nodes[0].name}.yaml -f #{opts[:from]} -t #{opts[:to]} --basedir #{tempdir} --puppet-binary #{binary} --bootstrap-script '#{tempdir}/bootstrap_script.rb'"
|
73
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
74
|
+
exit_status = wait_thr.value
|
75
|
+
@results << {
|
76
|
+
stdout: stdout.read,
|
77
|
+
stderr: stderr.read,
|
78
|
+
exit_status: exit_status.exitstatus,
|
79
|
+
test: test
|
80
|
+
}
|
81
|
+
end
|
82
|
+
logger.info "Storing results for #{test.classes[0].name} on #{test.nodes[0].name}"
|
83
|
+
FileUtils.rm_r(tempdir)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
@threads.each(&:join)
|
89
|
+
@results.each do |result|
|
90
|
+
puts "#{"Test:".bold} #{result[:test].classes[0].name} on #{result[:test].nodes[0].name}"
|
91
|
+
puts "#{"Exit:".bold} #{result[:exit_status]}"
|
92
|
+
puts "#{"Status:".bold} #{"changes".yellow}" if result[:exit_status] == 2
|
93
|
+
puts "#{"Status:".bold} #{"no differences".green}" if result[:exit_status] == 0
|
94
|
+
puts "#{"Status:".bold} #{"failed".red}" if result[:exit_status] == 1
|
95
|
+
puts "#{"Results:".bold}\n#{result[:stdout]}\n" if result[:exit_status] == 2
|
96
|
+
puts "#{"Errors:".bold}\n#{result[:stderr]}\n" if result[:exit_status] == 1
|
97
|
+
puts ""
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Register itself
|
108
|
+
Onceover::CLI::Run.command.add_command(Onceover::CLI::Run::Diff.command)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'onceover/octocatalog/diff/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "onceover-octocatalog-diff"
|
8
|
+
spec.version = Onceover::Octocatalog::Diff::VERSION
|
9
|
+
spec.authors = ["Dylan Ratcliffe"]
|
10
|
+
spec.email = ["dylan.ratcliffe@puppet.com"]
|
11
|
+
|
12
|
+
spec.summary = "Adds octocatalog-diff functionality to onceover"
|
13
|
+
spec.description = "Allows Onceover users to use their existing factsets to check what affect given changes will have on a role's compiled catalog"
|
14
|
+
spec.homepage = "https://github.com/dylanratcliffe/onceover-octocatalog-diff"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_runtime_dependency 'octocatalog-diff', '~> 1.0'
|
27
|
+
spec.add_runtime_dependency 'onceover', '>= 3.2.0'
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'onceover/controlrepo'
|
4
|
+
|
5
|
+
repo = Onceover::Controlrepo.new()
|
6
|
+
tempdir = Dir.pwd
|
7
|
+
|
8
|
+
FileUtils.copy_entry("<%= tempdir %>/modules","#{tempdir}/modules")
|
9
|
+
system("r10k puppetfile install --verbose --color --puppetfile '<%= repo.puppetfile %>'")
|
10
|
+
|
11
|
+
|
12
|
+
if repo.config['manifest']
|
13
|
+
manifest_dir = "#{tempdir}/#{repo.config['manifest']}"
|
14
|
+
else
|
15
|
+
manifest_dir = "#{tempdir}/manifests"
|
16
|
+
end
|
17
|
+
|
18
|
+
FileUtils.rm_r(Dir["#{manifest_dir}/*"])
|
19
|
+
|
20
|
+
somefile = File.open("#{manifest_dir}/site.pp", "w")
|
21
|
+
somefile.puts "include <%= class_name %>"
|
22
|
+
somefile.close
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onceover-octocatalog-diff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dylan Ratcliffe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: octocatalog-diff
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: onceover
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.0
|
69
|
+
description: Allows Onceover users to use their existing factsets to check what affect
|
70
|
+
given changes will have on a role's compiled catalog
|
71
|
+
email:
|
72
|
+
- dylan.ratcliffe@puppet.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/onceover/octocatalog/diff.rb
|
85
|
+
- lib/onceover/octocatalog/diff/cli.rb
|
86
|
+
- lib/onceover/octocatalog/diff/version.rb
|
87
|
+
- onceover-octocatalog-diff.gemspec
|
88
|
+
- templates/change_manifest.rb.erb
|
89
|
+
homepage: https://github.com/dylanratcliffe/onceover-octocatalog-diff
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.5.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Adds octocatalog-diff functionality to onceover
|
113
|
+
test_files: []
|