knife-tidy 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +27 -0
- data/CHANGELOG.md +17 -11
- data/README.md +3 -3
- data/TODO.md +5 -0
- data/knife-tidy.gemspec +1 -1
- data/lib/chef/knife/tidy_backup_clean.rb +3 -4
- data/lib/chef/knife/tidy_base.rb +14 -1
- data/lib/chef/knife/tidy_server_clean.rb +138 -0
- data/lib/chef/knife/tidy_server_report.rb +77 -13
- data/lib/chef/tidy_common.rb +8 -2
- data/lib/knife-tidy/version.rb +1 -1
- data/spec/chef/knife/tidy_backup_clean_spec.rb +25 -0
- data/spec/chef/knife/tidy_base_spec.rb +25 -0
- data/spec/spec_helper.rb +17 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15b086bc7f2ebb5d3fe13ff649521b1e01d13df9
|
4
|
+
data.tar.gz: 1f32091c52ff24644a51df7f51474861446e5590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c88961a22947d751cab5e39bf8305076b2f89b53d6035d1f13bd5041ebe89b937fd4ac07a8a49488ee719cba91a642b5593a4ec2472fd9224ae1c6c0b2af01b
|
7
|
+
data.tar.gz: 52027a5cc0720febbee5c141e8db6b94245c8f5c07f73dca50a98adbedbea6f9d96bbb369ea205c197c6243b22d778df264efff304d016f2786770358b729fd0
|
data/.travis.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
dist: trusty
|
4
|
+
sudo: false
|
5
|
+
|
6
|
+
# Early warning system to catch if Rubygems breaks something
|
7
|
+
before_install:
|
8
|
+
- gem update --system
|
9
|
+
- gem uninstall bundler -a -x
|
10
|
+
- gem install bundler
|
11
|
+
- rm -f .bundle/config
|
12
|
+
|
13
|
+
rvm:
|
14
|
+
- 2.2.7
|
15
|
+
- 2.3.4
|
16
|
+
- 2.4.1
|
17
|
+
- ruby-head
|
18
|
+
|
19
|
+
matrix:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: ruby-head
|
22
|
+
|
23
|
+
script: bundle exec rake spec
|
24
|
+
|
25
|
+
branches:
|
26
|
+
only:
|
27
|
+
- master
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
|
4
|
-
[
|
3
|
+
|
4
|
+
## [0.2.1](https://github.com/chef-customers/knife-tidy/tree/0.2.1) (2017-09-01)
|
5
|
+
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.2.0...0.2.1)
|
5
6
|
|
6
7
|
**Merged pull requests:**
|
7
8
|
|
8
|
-
-
|
9
|
+
- first round of tests [\#10](https://github.com/chef-customers/knife-tidy/pull/10) ([jeremymv2](https://github.com/jeremymv2))
|
10
|
+
- Add environment checking for unused cookbook list [\#9](https://github.com/chef-customers/knife-tidy/pull/9) ([nsdavidson](https://github.com/nsdavidson))
|
11
|
+
- disable [\#8](https://github.com/chef-customers/knife-tidy/pull/8) ([jeremymv2](https://github.com/jeremymv2))
|
12
|
+
- server object deletion [\#7](https://github.com/chef-customers/knife-tidy/pull/7) ([jeremymv2](https://github.com/jeremymv2))
|
13
|
+
- bump version to 0.2.0 [\#6](https://github.com/chef-customers/knife-tidy/pull/6) ([jeremymv2](https://github.com/jeremymv2))
|
9
14
|
|
10
|
-
## [0.2.0](https://github.com/
|
11
|
-
[Full Changelog](https://github.com/
|
15
|
+
## [0.2.0](https://github.com/chef-customers/knife-tidy/tree/0.2.0) (2017-08-16)
|
16
|
+
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.1.1...0.2.0)
|
12
17
|
|
13
18
|
**Merged pull requests:**
|
14
19
|
|
15
|
-
- moved all common functions to tidy\_common.rb [\#5](https://github.com/
|
16
|
-
- Jeremymv2/acl items [\#4](https://github.com/
|
17
|
-
- updated changelog [\#3](https://github.com/
|
18
|
-
- bump version to 0.1.1 [\#2](https://github.com/
|
19
|
-
|
20
|
+
- moved all common functions to tidy\_common.rb [\#5](https://github.com/chef-customers/knife-tidy/pull/5) ([jeremymv2](https://github.com/jeremymv2))
|
21
|
+
- Jeremymv2/acl items [\#4](https://github.com/chef-customers/knife-tidy/pull/4) ([jeremymv2](https://github.com/jeremymv2))
|
22
|
+
- updated changelog [\#3](https://github.com/chef-customers/knife-tidy/pull/3) ([jeremymv2](https://github.com/jeremymv2))
|
23
|
+
- bump version to 0.1.1 [\#2](https://github.com/chef-customers/knife-tidy/pull/2) ([jeremymv2](https://github.com/jeremymv2))
|
20
24
|
|
25
|
+
## [0.1.0](https://github.com/chef-customers/knife-tidy/tree/0.1.0) (2017-09-01)
|
26
|
+
[Full Changelog](https://github.com/chef-customers/knife-tidy/compare/0.2.1...0.1.0)
|
21
27
|
|
22
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
28
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -55,10 +55,10 @@ org_unused_cookbooks.json | List of cookbooks and versions that do not appear to
|
|
55
55
|
|
56
56
|
## Options
|
57
57
|
|
58
|
-
* `--
|
58
|
+
* `--backup-path /path/to/an-ec-backup`:
|
59
59
|
The Chef Repo to tidy up (such as one created from a [knife-ec-backup](https://github.com/chef/knife-ec-backup)
|
60
60
|
|
61
|
-
* `--gsub-file path/to/gsub/file`:
|
61
|
+
* `--gsub-file /path/to/gsub/file`:
|
62
62
|
The path to the file used for substitutions. If non-existant, a boiler plate one will be created.
|
63
63
|
|
64
64
|
## Notes
|
@@ -78,7 +78,7 @@ org_unused_cookbooks.json | List of cookbooks and versions that do not appear to
|
|
78
78
|
},
|
79
79
|
{
|
80
80
|
"pattern":"version *Chef::Sugar::VERSION",
|
81
|
-
"replace":"
|
81
|
+
"replace":"version !COOKBOOK_VERSION!"
|
82
82
|
}
|
83
83
|
]
|
84
84
|
}
|
data/TODO.md
ADDED
data/knife-tidy.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["jmiller@chef.io"]
|
11
11
|
s.summary = "Report on stale Chef Server nodes and cookbooks and clean up data integrity issues in a knife-ec-backup object based backup"
|
12
12
|
s.description = s.summary
|
13
|
-
s.homepage = "https://github.com/
|
13
|
+
s.homepage = "https://github.com/chef-customers/knife-tidy"
|
14
14
|
s.license = "Apache License, v2.0"
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.require_paths = ["lib"]
|
@@ -9,10 +9,11 @@ class Chef
|
|
9
9
|
require 'chef/cookbook/metadata'
|
10
10
|
require 'chef/tidy_substitutions'
|
11
11
|
require 'chef/tidy_acls'
|
12
|
-
require 'chef/tidy_common'
|
13
12
|
require 'ffi_yajl'
|
14
13
|
end
|
15
14
|
|
15
|
+
banner "knife tidy backup clean (OPTIONS)"
|
16
|
+
|
16
17
|
include Knife::TidyBase
|
17
18
|
|
18
19
|
option :backup_path,
|
@@ -48,10 +49,8 @@ class Chef
|
|
48
49
|
load_cookbooks(org)
|
49
50
|
generate_new_metadata(org)
|
50
51
|
end
|
51
|
-
end
|
52
52
|
|
53
|
-
|
54
|
-
@tidy ||= Chef::TidyCommon.new(config[:backup_path])
|
53
|
+
completion_message
|
55
54
|
end
|
56
55
|
|
57
56
|
def validate_user_emails
|
data/lib/chef/knife/tidy_base.rb
CHANGED
@@ -27,6 +27,7 @@ class Chef
|
|
27
27
|
|
28
28
|
deps do
|
29
29
|
require 'chef/tidy_server'
|
30
|
+
require 'chef/tidy_common'
|
30
31
|
end
|
31
32
|
|
32
33
|
option :org_list,
|
@@ -45,7 +46,19 @@ class Chef
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def rest
|
48
|
-
@rest ||= Chef::ServerAPI.new(server.root_url,
|
49
|
+
@rest ||= Chef::ServerAPI.new(server.root_url, keepalives: true)
|
50
|
+
end
|
51
|
+
|
52
|
+
def tidy
|
53
|
+
@tidy ||= if config[:backup_path].nil?
|
54
|
+
Chef::TidyCommon.new
|
55
|
+
else
|
56
|
+
Chef::TidyCommon.new(config[:backup_path])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def completion_message
|
61
|
+
puts "#{ui.color("** Finished **", :magenta)}"
|
49
62
|
end
|
50
63
|
end
|
51
64
|
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# not enabled
|
2
|
+
return
|
3
|
+
|
4
|
+
require 'chef/knife/tidy_base'
|
5
|
+
|
6
|
+
class Chef
|
7
|
+
class Knife
|
8
|
+
class TidyServerClean < Knife
|
9
|
+
|
10
|
+
include Knife::TidyBase
|
11
|
+
|
12
|
+
deps do
|
13
|
+
require 'ffi_yajl'
|
14
|
+
require 'chef/util/threaded_job_queue'
|
15
|
+
end
|
16
|
+
|
17
|
+
banner "knife tidy server clean (options)"
|
18
|
+
|
19
|
+
option :concurrency,
|
20
|
+
:long => '--concurrency THREADS',
|
21
|
+
:default => 10,
|
22
|
+
:description => 'Maximum number of simultaneous requests to send (default: 10)'
|
23
|
+
|
24
|
+
option :only_cookbooks,
|
25
|
+
:long => '--only-cookbooks',
|
26
|
+
:description => 'Only delete unused cookbooks from Chef Server.'
|
27
|
+
|
28
|
+
option :only_nodes,
|
29
|
+
:long => '--only-nodes',
|
30
|
+
:description => 'Only delete stale nodes from Chef Server.'
|
31
|
+
|
32
|
+
def run
|
33
|
+
STDOUT.sync = true
|
34
|
+
|
35
|
+
ensure_reports_dir
|
36
|
+
ui.info "Reading from #{tidy.reports_dir} directory"
|
37
|
+
|
38
|
+
ui.info "Using thread concurrency #{config[:concurrency]}"
|
39
|
+
configure_chef
|
40
|
+
|
41
|
+
if config[:only_cookbooks] && config[:only_nodes]
|
42
|
+
ui.error 'Cannot use --only-cookbooks AND --only-nodes'
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
ui.confirm('This operation will delete items on Chef Server, continue') unless config[:unattended]
|
47
|
+
|
48
|
+
orgs = if config[:org_list]
|
49
|
+
config[:org_list].split(',')
|
50
|
+
else
|
51
|
+
all_orgs
|
52
|
+
end
|
53
|
+
|
54
|
+
orgs.each do |org|
|
55
|
+
clean_cookbooks(org) unless config[:only_nodes]
|
56
|
+
clean_nodes(org) unless config[:only_cookbooks]
|
57
|
+
end
|
58
|
+
|
59
|
+
completion_message
|
60
|
+
end
|
61
|
+
|
62
|
+
def clean_cookbooks(org)
|
63
|
+
queue = Chef::Util::ThreadedJobQueue.new
|
64
|
+
unused_cookbooks_file = ::File.join(tidy.reports_dir, "#{org}_unused_cookbooks.json")
|
65
|
+
return unless ::File.exist?(unused_cookbooks_file)
|
66
|
+
ui.info "Cleaning cookbooks for Org: #{org}, using #{unused_cookbooks_file}"
|
67
|
+
unused_cookbooks = FFI_Yajl::Parser.parse(::File.read(unused_cookbooks_file), symbolize_names: true)
|
68
|
+
unused_cookbooks.keys.each do |cookbook|
|
69
|
+
versions = unused_cookbooks[cookbook]
|
70
|
+
versions.each do |version|
|
71
|
+
queue << lambda { delete_cookbook_job(org, cookbook, version) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
queue.process(config[:concurrency].to_i)
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete_cookbook_job(org, cookbook, version)
|
78
|
+
path = "/organizations/#{org}/cookbooks/#{cookbook}/#{version}"
|
79
|
+
rest.delete(path)
|
80
|
+
response = '200'
|
81
|
+
rescue Net::HTTPServerException
|
82
|
+
response = $!.response.code
|
83
|
+
ensure
|
84
|
+
formatted = response == '200' ?
|
85
|
+
ui.color(' Deleting %-20s %-10s %10s', :green) :
|
86
|
+
ui.color(' Deleting %-20s %-10s %10s', :red)
|
87
|
+
printf("#{formatted}\n", cookbook, version, response)
|
88
|
+
end
|
89
|
+
|
90
|
+
def clean_nodes(org)
|
91
|
+
queue = Chef::Util::ThreadedJobQueue.new
|
92
|
+
stale_nodes_file = ::File.join(tidy.reports_dir, "#{org}_stale_nodes.json")
|
93
|
+
return unless ::File.exist?(stale_nodes_file)
|
94
|
+
ui.info "Cleaning stale nodes for Org: #{org}, using #{stale_nodes_file}"
|
95
|
+
stale_nodes = FFI_Yajl::Parser.parse(::File.read(stale_nodes_file), symbolize_names: true)
|
96
|
+
stale_nodes[:list].each do |node|
|
97
|
+
queue << lambda { delete_node_job(org, node) }
|
98
|
+
end
|
99
|
+
queue.process(config[:concurrency].to_i)
|
100
|
+
end
|
101
|
+
|
102
|
+
def delete_node_job(org, node)
|
103
|
+
path = "/organizations/#{org}/nodes/#{node}"
|
104
|
+
rest.delete(path)
|
105
|
+
response = '200'
|
106
|
+
rescue Net::HTTPServerException
|
107
|
+
response = $!.response.code
|
108
|
+
ensure
|
109
|
+
formatted = response == '200' ?
|
110
|
+
ui.color(' Deleting %-20s %10s', :green) :
|
111
|
+
ui.color(' Deleting %-20s %10s', :red)
|
112
|
+
printf("#{formatted}\n", node, response)
|
113
|
+
end
|
114
|
+
|
115
|
+
def ensure_reports_dir
|
116
|
+
unless ::File.directory?(tidy.reports_dir)
|
117
|
+
ui.error "#{tidy.reports_dir} not found!"
|
118
|
+
exit 1
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def report_files
|
123
|
+
Dir[::File.join(tidy.reports_dir, '**')]
|
124
|
+
end
|
125
|
+
|
126
|
+
def all_orgs
|
127
|
+
orgs = []
|
128
|
+
report_files.each do |file|
|
129
|
+
org = ::File.basename(file).match(/^(.*?)_/).captures[0]
|
130
|
+
if org
|
131
|
+
orgs.push(org) unless orgs.include?(org)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
orgs
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -10,7 +10,7 @@ class Chef
|
|
10
10
|
require 'ffi_yajl'
|
11
11
|
end
|
12
12
|
|
13
|
-
banner "knife tidy server report (
|
13
|
+
banner "knife tidy server report (options)"
|
14
14
|
|
15
15
|
option :node_threshold,
|
16
16
|
:long => '--node-threshold NUM_DAYS',
|
@@ -20,7 +20,8 @@ class Chef
|
|
20
20
|
def run
|
21
21
|
ensure_reports_dir!
|
22
22
|
|
23
|
-
ui.warn "Writing to #{reports_dir} directory"
|
23
|
+
ui.warn "Writing to #{tidy.reports_dir} directory"
|
24
|
+
delete_existing_reports
|
24
25
|
|
25
26
|
orgs = if config[:org_list]
|
26
27
|
config[:org_list].split(',')
|
@@ -49,6 +50,11 @@ class Chef
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
53
|
+
Chef::Log.debug("Used cookbook list before checking environments: #{used_cookbooks}")
|
54
|
+
pins = environment_constraints(org)
|
55
|
+
used_cookbooks = check_environment_pins(used_cookbooks, pins, cb_list)
|
56
|
+
Chef::Log.debug("Used cookbook list after checking environments: #{used_cookbooks}")
|
57
|
+
|
52
58
|
stale_nodes = []
|
53
59
|
nodes.each do |n|
|
54
60
|
if (Time.now.to_i - n['ohai_time'].to_i) >= node_threshold * 86400
|
@@ -59,23 +65,25 @@ class Chef
|
|
59
65
|
stale_nodes_hash = {'threshold_days': node_threshold, 'count': stale_nodes.count, 'list': stale_nodes}
|
60
66
|
stale_orgs.push(org) if stale_nodes.count == nodes.count
|
61
67
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
tidy.write_new_file(unused_cookbooks(used_cookbooks, cb_list), ::File.join(tidy.reports_dir, "#{org}_unused_cookbooks.json"))
|
69
|
+
tidy.write_new_file(unused_cookbooks(used_cookbooks, cb_list), ::File.join(tidy.reports_dir, "#{org}_unused_cookbooks.json"))
|
70
|
+
tidy.write_new_file(version_count, ::File.join(tidy.reports_dir, "#{org}_cookbook_count.json"))
|
71
|
+
tidy.write_new_file(stale_nodes_hash, ::File.join(tidy.reports_dir, "#{org}_stale_nodes.json"))
|
66
72
|
end
|
67
|
-
end
|
68
73
|
|
69
|
-
|
70
|
-
::File.write(::File.join(reports_dir, file_name), FFI_Yajl::Encoder.encode(content, pretty: true))
|
74
|
+
completion_message
|
71
75
|
end
|
72
76
|
|
73
|
-
def
|
74
|
-
|
77
|
+
def ensure_reports_dir!
|
78
|
+
Dir.mkdir(tidy.reports_dir) unless Dir.exist?(tidy.reports_dir)
|
75
79
|
end
|
76
80
|
|
77
|
-
def
|
78
|
-
|
81
|
+
def delete_existing_reports
|
82
|
+
files = Dir[::File.join(tidy.reports_dir, '*.json')]
|
83
|
+
unless files.empty?
|
84
|
+
ui.confirm("You have existing reports in #{tidy.reports_dir}. Remove")
|
85
|
+
FileUtils.rm(files, :force => true)
|
86
|
+
end
|
79
87
|
end
|
80
88
|
|
81
89
|
def nodes_list(org)
|
@@ -127,6 +135,62 @@ class Chef
|
|
127
135
|
def all_orgs
|
128
136
|
rest.get('organizations').keys
|
129
137
|
end
|
138
|
+
|
139
|
+
def all_environments(org)
|
140
|
+
rest.get("/organizations/#{org}/environments").values
|
141
|
+
end
|
142
|
+
|
143
|
+
def environment_constraints(org)
|
144
|
+
constraints = {}
|
145
|
+
all_environments(org).each do |env|
|
146
|
+
e = rest.get(env)
|
147
|
+
e['cookbook_versions'].each do |cb, version|
|
148
|
+
if constraints[cb]
|
149
|
+
constraints[cb].push(version) unless constraints[cb].include?(version)
|
150
|
+
else
|
151
|
+
constraints[cb] = [version]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
constraints
|
156
|
+
end
|
157
|
+
|
158
|
+
def check_cookbook_list(cb_list, cb, version)
|
159
|
+
cb_list[cb].each do |v|
|
160
|
+
if Gem::Dependency.new('', version).match?('', v)
|
161
|
+
Chef::Log.debug("Pin of #{cb} can be satisfied by #{v}, adding to used list")
|
162
|
+
return [v]
|
163
|
+
else
|
164
|
+
Chef::Log.debug("Pin of #{cb} version #{version} not satisfied by #{v}")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
return nil
|
168
|
+
end
|
169
|
+
|
170
|
+
def check_environment_pins(used_cookbooks, pins, cb_list)
|
171
|
+
pins.each do |cb, versions|
|
172
|
+
versions.each do |version|
|
173
|
+
if used_cookbooks[cb]
|
174
|
+
# This pinned cookbook is in the used list, now check for a matching version.
|
175
|
+
used_cookbooks[cb].each do |v|
|
176
|
+
if Gem::Dependency.new('', version).match?('', v)
|
177
|
+
# This version in used_cookbooks satisfies the pin
|
178
|
+
Chef::Log.debug("Pin of #{cb}: #{version} is satisfied by #{v}")
|
179
|
+
break
|
180
|
+
end
|
181
|
+
end
|
182
|
+
result = check_cookbook_list(cb_list, cb, version)
|
183
|
+
used_cookbooks[cb].push(result[0]) if result
|
184
|
+
else
|
185
|
+
# No cookbook version for that pin, look through the full cookbook list for a match
|
186
|
+
Chef::Log.debug("No used cookbook #{cb}, checking the full cookbook list")
|
187
|
+
result = check_cookbook_list(cb_list, cb, version)
|
188
|
+
used_cookbooks[cb] = result if result
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
used_cookbooks
|
193
|
+
end
|
130
194
|
end
|
131
195
|
end
|
132
196
|
end
|
data/lib/chef/tidy_common.rb
CHANGED
@@ -5,7 +5,7 @@ class Chef
|
|
5
5
|
class TidyCommon
|
6
6
|
attr_accessor :backup_path
|
7
7
|
|
8
|
-
def initialize(backup_path)
|
8
|
+
def initialize(backup_path = Dir.pwd)
|
9
9
|
@backup_path = ::File.expand_path(backup_path)
|
10
10
|
end
|
11
11
|
|
@@ -53,7 +53,9 @@ class Chef
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def write_new_file(contents, path)
|
56
|
-
|
56
|
+
if ::File.exist?(path)
|
57
|
+
FileUtils.cp(path, "#{path}.orig") unless ::File.exist?("#{path}.orig")
|
58
|
+
end
|
57
59
|
::File.open(path, 'w+') do |f|
|
58
60
|
f.write(FFI_Yajl::Encoder.encode(contents, pretty: true))
|
59
61
|
end
|
@@ -66,5 +68,9 @@ class Chef
|
|
66
68
|
def global_user_names
|
67
69
|
@global_user_names ||= Dir[::File.join(@backup_path, 'users', '*')].map { |dir| ::File.basename(dir, '.json') }
|
68
70
|
end
|
71
|
+
|
72
|
+
def reports_dir
|
73
|
+
@reports_dir ||= ::File.join(Dir.pwd, 'reports')
|
74
|
+
end
|
69
75
|
end
|
70
76
|
end
|
data/lib/knife-tidy/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
|
2
|
+
require 'chef/knife/tidy_backup_clean'
|
3
|
+
require 'chef/knife'
|
4
|
+
require 'chef/config'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
class Tester < Chef::Knife
|
8
|
+
include Chef::Knife::TidyBackupClean
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Chef::Knife::TidyBackupClean do
|
12
|
+
let(:t) { Tester.new }
|
13
|
+
before(:each) do
|
14
|
+
@rest = double('rest')
|
15
|
+
@stderr = StringIO.new
|
16
|
+
allow(t.ui).to receive(:stderr).and_return(@stderr)
|
17
|
+
allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "completion_message" do
|
21
|
+
it "lets the user know we're Finished" do
|
22
|
+
expect{t.completion_message}.to output("** Finished **\n").to_stdout
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
|
2
|
+
require 'chef/knife/tidy_base'
|
3
|
+
require 'chef/knife'
|
4
|
+
require 'chef/config'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
class Tester < Chef::Knife
|
8
|
+
include Chef::Knife::TidyBase
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Chef::Knife::TidyBase do
|
12
|
+
let(:t) { Tester.new }
|
13
|
+
before(:each) do
|
14
|
+
@rest = double('rest')
|
15
|
+
@stderr = StringIO.new
|
16
|
+
allow(t.ui).to receive(:stderr).and_return(@stderr)
|
17
|
+
allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "completion_message" do
|
21
|
+
it "lets the user know we're Finished" do
|
22
|
+
expect{t.completion_message}.to output("** Finished **\n").to_stdout
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'chef'
|
3
|
+
require 'chef/knife/tidy_base'
|
4
|
+
require 'chef/knife/tidy_backup_clean'
|
5
|
+
require 'chef/knife/tidy_server_report'
|
6
|
+
require 'chef/knife/tidy_server_clean'
|
7
|
+
|
8
|
+
# Clear config between each example
|
9
|
+
# to avoid dependencies between examples
|
10
|
+
RSpec.configure do |c|
|
11
|
+
c.raise_errors_for_deprecations!
|
12
|
+
c.filter_run_excluding :exclude => true
|
13
|
+
c.before(:each) do
|
14
|
+
Chef::Config.reset
|
15
|
+
Chef::Config[:knife] ={}
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-tidy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -103,22 +103,28 @@ extensions: []
|
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
105
|
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
106
107
|
- CHANGELOG.md
|
107
108
|
- Gemfile
|
108
109
|
- LICENSE
|
109
110
|
- README.md
|
110
111
|
- Rakefile
|
112
|
+
- TODO.md
|
111
113
|
- conf/substitutions.json.example
|
112
114
|
- knife-tidy.gemspec
|
113
115
|
- lib/chef/knife/tidy_backup_clean.rb
|
114
116
|
- lib/chef/knife/tidy_base.rb
|
117
|
+
- lib/chef/knife/tidy_server_clean.rb
|
115
118
|
- lib/chef/knife/tidy_server_report.rb
|
116
119
|
- lib/chef/tidy_acls.rb
|
117
120
|
- lib/chef/tidy_common.rb
|
118
121
|
- lib/chef/tidy_server.rb
|
119
122
|
- lib/chef/tidy_substitutions.rb
|
120
123
|
- lib/knife-tidy/version.rb
|
121
|
-
|
124
|
+
- spec/chef/knife/tidy_backup_clean_spec.rb
|
125
|
+
- spec/chef/knife/tidy_base_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
homepage: https://github.com/chef-customers/knife-tidy
|
122
128
|
licenses:
|
123
129
|
- Apache License, v2.0
|
124
130
|
metadata: {}
|