moose-inventory 1.0.8 → 2.0
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 +5 -5
- data/.github/workflows/ci.yml +49 -0
- data/.github/workflows/release.yml +58 -0
- data/.gitignore +1 -1
- data/.gitleaks.toml +9 -0
- data/.rubocop.yml +19 -784
- data/BACKLOG.md +290 -0
- data/Gemfile.lock +95 -0
- data/README.md +38 -9
- data/Rakefile +1 -1
- data/bin/moose-inventory +1 -1
- data/docs/release/publishing.md +109 -0
- data/docs/release/release-readiness.md +55 -0
- data/docs/security-audit-2026-05-21.md +71 -0
- data/docs/security-audit-2026-05-26-rerun.md +75 -0
- data/docs/security-audit-2026-05-26.md +63 -0
- data/lib/moose_inventory/cli/formatter.rb +16 -17
- data/lib/moose_inventory/cli/group.rb +4 -1
- data/lib/moose_inventory/cli/group_add.rb +89 -75
- data/lib/moose_inventory/cli/group_addchild.rb +84 -71
- data/lib/moose_inventory/cli/group_addhost.rb +78 -69
- data/lib/moose_inventory/cli/group_addvar.rb +37 -37
- data/lib/moose_inventory/cli/group_get.rb +23 -26
- data/lib/moose_inventory/cli/group_list.rb +12 -15
- data/lib/moose_inventory/cli/group_listvars.rb +12 -14
- data/lib/moose_inventory/cli/group_rm.rb +104 -76
- data/lib/moose_inventory/cli/group_rmchild.rb +99 -54
- data/lib/moose_inventory/cli/group_rmhost.rb +64 -60
- data/lib/moose_inventory/cli/group_rmvar.rb +5 -5
- data/lib/moose_inventory/cli/helpers.rb +76 -0
- data/lib/moose_inventory/cli/host.rb +4 -1
- data/lib/moose_inventory/cli/host_add.rb +51 -66
- data/lib/moose_inventory/cli/host_addgroup.rb +77 -68
- data/lib/moose_inventory/cli/host_addvar.rb +6 -6
- data/lib/moose_inventory/cli/host_get.rb +15 -18
- data/lib/moose_inventory/cli/host_list.rb +3 -3
- data/lib/moose_inventory/cli/host_listvars.rb +21 -23
- data/lib/moose_inventory/cli/host_rm.rb +9 -9
- data/lib/moose_inventory/cli/host_rmgroup.rb +63 -60
- data/lib/moose_inventory/cli/host_rmvar.rb +3 -3
- data/lib/moose_inventory/config/config.rb +43 -40
- data/lib/moose_inventory/db/db.rb +92 -52
- data/lib/moose_inventory/db/models.rb +11 -12
- data/lib/moose_inventory/inventory_context.rb +50 -0
- data/lib/moose_inventory/operations/add_associations.rb +127 -0
- data/lib/moose_inventory/operations/add_groups.rb +115 -0
- data/lib/moose_inventory/operations/add_hosts.rb +110 -0
- data/lib/moose_inventory/operations/group_child_relations.rb +118 -0
- data/lib/moose_inventory/operations/group_cleanup.rb +55 -0
- data/lib/moose_inventory/operations/remove_associations.rb +101 -0
- data/lib/moose_inventory/operations/remove_groups.rb +79 -0
- data/lib/moose_inventory/version.rb +1 -1
- data/moose-inventory.gemspec +38 -20
- data/scripts/check.sh +10 -0
- data/scripts/ci/check_permissions.sh +35 -0
- data/scripts/ci/check_rubocop.sh +28 -0
- data/scripts/ci/check_secrets.sh +26 -0
- data/scripts/ci/check_security.sh +68 -0
- data/scripts/ci/install_security_tools.sh +47 -0
- data/scripts/ci/package_sanity.sh +46 -0
- data/scripts/files.rb +1 -4
- data/scripts/install_dependencies.sh +19 -0
- data/scripts/reports.sh +2 -2
- data/spec/lib/moose_inventory/cli/cli_spec.rb +13 -14
- data/spec/lib/moose_inventory/cli/group_add_spec.rb +118 -119
- data/spec/lib/moose_inventory/cli/group_addchild_spec.rb +49 -51
- data/spec/lib/moose_inventory/cli/group_addhost_spec.rb +80 -83
- data/spec/lib/moose_inventory/cli/group_addvar_spec.rb +91 -91
- data/spec/lib/moose_inventory/cli/group_get_spec.rb +22 -23
- data/spec/lib/moose_inventory/cli/group_list_spec.rb +19 -20
- data/spec/lib/moose_inventory/cli/group_listvar_spec.rb +35 -36
- data/spec/lib/moose_inventory/cli/group_rm_spec.rb +115 -78
- data/spec/lib/moose_inventory/cli/group_rmchild_spec.rb +86 -45
- data/spec/lib/moose_inventory/cli/group_rmhost_spec.rb +43 -46
- data/spec/lib/moose_inventory/cli/group_rmvar_spec.rb +131 -131
- data/spec/lib/moose_inventory/cli/group_spec.rb +9 -9
- data/spec/lib/moose_inventory/cli/host_add_spec.rb +103 -43
- data/spec/lib/moose_inventory/cli/host_addgroup_spec.rb +78 -80
- data/spec/lib/moose_inventory/cli/host_addvar_spec.rb +122 -122
- data/spec/lib/moose_inventory/cli/host_get_spec.rb +16 -16
- data/spec/lib/moose_inventory/cli/host_list_spec.rb +8 -8
- data/spec/lib/moose_inventory/cli/host_listvar_spec.rb +50 -52
- data/spec/lib/moose_inventory/cli/host_rm_spec.rb +12 -12
- data/spec/lib/moose_inventory/cli/host_rmgroup_spec.rb +48 -51
- data/spec/lib/moose_inventory/cli/host_rmvar_spec.rb +136 -136
- data/spec/lib/moose_inventory/config/config_spec.rb +16 -3
- data/spec/lib/moose_inventory/db/db_spec.rb +386 -2
- data/spec/lib/moose_inventory/db/models_spec.rb +10 -11
- data/spec/lib/moose_inventory/operations/add_associations_spec.rb +77 -0
- data/spec/lib/moose_inventory/operations/add_groups_spec.rb +65 -0
- data/spec/lib/moose_inventory/operations/add_hosts_spec.rb +69 -0
- data/spec/lib/moose_inventory/operations/group_child_relations_spec.rb +76 -0
- data/spec/lib/moose_inventory/operations/remove_associations_spec.rb +78 -0
- data/spec/lib/moose_inventory/operations/remove_groups_spec.rb +57 -0
- data/spec/shared/shared_config_setup.rb +2 -2
- data/spec/spec_helper.rb +7 -8
- metadata +157 -105
- data/.coveralls.yml +0 -0
- data/Guardfile +0 -38
- data/config/dotfiles/coveralls.yml +0 -0
- data/config/dotfiles/gitignore +0 -20
- data/config/dotfiles/rubocop.yml +0 -793
- data/scripts/guard_quality.sh +0 -3
- data/scripts/guard_test.sh +0 -2
|
@@ -12,20 +12,20 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
12
12
|
env: 'test',
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
@mockargs = []
|
|
15
|
+
@mockargs = []
|
|
16
16
|
@mockarg_parts.each do |key, val|
|
|
17
17
|
@mockargs << "--#{key}"
|
|
18
18
|
@mockargs << val
|
|
19
19
|
end
|
|
20
20
|
@mockargs << '--trace' # extra info for debugging
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
@console = Moose::Inventory::Cli::Formatter
|
|
23
23
|
|
|
24
24
|
@config = Moose::Inventory::Config
|
|
25
25
|
@config.init(@mockargs)
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
@db = Moose::Inventory::DB
|
|
28
|
-
@db.init if @db.db.nil?
|
|
28
|
+
@db.init if @db.db.nil?
|
|
29
29
|
|
|
30
30
|
@host = Moose::Inventory::Cli::Host
|
|
31
31
|
@group = Moose::Inventory::Cli::Group
|
|
@@ -48,29 +48,29 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
48
48
|
it '<no arguments> ... should bail with an error' do
|
|
49
49
|
actual = runner { @app.start(%w(group add)) }
|
|
50
50
|
|
|
51
|
-
desired = {aborted: true}
|
|
51
|
+
desired = { aborted: true }
|
|
52
52
|
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 1 or more.\n"
|
|
53
53
|
expected(actual, desired)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
# --------------------
|
|
57
57
|
it 'ungrouped ... should abort with an error' do
|
|
58
|
-
actual = runner { @app.start(%
|
|
58
|
+
actual = runner { @app.start(%w(group add ungrouped)) }
|
|
59
59
|
|
|
60
60
|
# Check output
|
|
61
|
-
desired = {aborted: true}
|
|
61
|
+
desired = { aborted: true }
|
|
62
62
|
desired[:STDERR] =
|
|
63
63
|
"ERROR: Cannot manually manipulate the automatic group 'ungrouped'\n"
|
|
64
64
|
expected(actual, desired)
|
|
65
|
-
end
|
|
65
|
+
end
|
|
66
66
|
|
|
67
67
|
# --------------------
|
|
68
68
|
it 'GROUP ... should add a group to the db' do
|
|
69
69
|
name = 'test'
|
|
70
70
|
actual = runner { @app.start(%W(group add #{name})) }
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
# @console.out(actual)
|
|
73
|
+
|
|
74
74
|
# Check output
|
|
75
75
|
desired = {}
|
|
76
76
|
desired[:STDOUT] =
|
|
@@ -94,8 +94,8 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
94
94
|
|
|
95
95
|
actual = runner { @app.start(%W(group add #{name})) }
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
# @console.out(actual)
|
|
98
|
+
|
|
99
99
|
# Check output
|
|
100
100
|
desired = {}
|
|
101
101
|
desired[:STDOUT] =
|
|
@@ -105,12 +105,11 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
105
105
|
" - OK\n"\
|
|
106
106
|
" - all OK\n"\
|
|
107
107
|
"Succeeded, with warnings.\n"
|
|
108
|
-
desired[:STDERR] =
|
|
108
|
+
desired[:STDERR] =
|
|
109
109
|
"WARNING: Group '#{name}' already exists, skipping creation.\n"
|
|
110
110
|
|
|
111
111
|
expected(actual, desired)
|
|
112
112
|
|
|
113
|
-
|
|
114
113
|
expected(actual, desired)
|
|
115
114
|
end
|
|
116
115
|
|
|
@@ -120,16 +119,16 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
120
119
|
|
|
121
120
|
actual = runner { @app.start(%w(group add) + names) }
|
|
122
121
|
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
# @console.out(actual)
|
|
123
|
+
|
|
125
124
|
# Check output
|
|
126
|
-
desired = {STDOUT: ''}
|
|
125
|
+
desired = { STDOUT: '' }
|
|
127
126
|
names.each do |name|
|
|
128
|
-
desired[:STDOUT] =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
128
|
+
"Add group '#{name}':\n"\
|
|
129
|
+
" - create group...\n"\
|
|
130
|
+
" - OK\n"\
|
|
131
|
+
" - all OK\n"\
|
|
133
132
|
end
|
|
134
133
|
desired[:STDOUT] = desired[:STDOUT] + "Succeeded\n"
|
|
135
134
|
|
|
@@ -145,7 +144,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
145
144
|
# --------------------
|
|
146
145
|
it 'GROUP1 --hosts HOST1 ... should add the '\
|
|
147
146
|
'group and associate it with existing hosts' do
|
|
148
|
-
|
|
147
|
+
|
|
149
148
|
host_name = 'test-host'
|
|
150
149
|
@db.models[:host].create(name: host_name)
|
|
151
150
|
|
|
@@ -154,8 +153,8 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
154
153
|
@app.start(%W(group add #{group_name} --hosts #{host_name}))
|
|
155
154
|
end
|
|
156
155
|
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
# @console.out(actual)
|
|
157
|
+
|
|
159
158
|
# Check output
|
|
160
159
|
desired = {}
|
|
161
160
|
desired[:STDOUT] =
|
|
@@ -179,57 +178,57 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
179
178
|
|
|
180
179
|
# --------------------
|
|
181
180
|
it 'GROUP1 --hosts HOST ... should create HOST if necessary, and warn' do
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
181
|
+
host_name = 'test-host'
|
|
182
|
+
|
|
183
|
+
# DON'T CREATE THE HOST! That's the point!
|
|
184
|
+
|
|
185
|
+
group_name = 'test-group'
|
|
186
|
+
actual = runner do
|
|
187
|
+
@app.start(%W(group add #{group_name} --hosts #{host_name}))
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# @console.out(actual)
|
|
191
|
+
|
|
192
|
+
# Check output
|
|
193
|
+
desired = {}
|
|
194
|
+
desired[:STDOUT] =
|
|
195
|
+
"Add group '#{group_name}':\n"\
|
|
196
|
+
" - create group...\n"\
|
|
197
|
+
" - OK\n"\
|
|
198
|
+
" - add association {group:#{group_name} <-> host:#{host_name}}...\n"\
|
|
199
|
+
" - host doesn't exist, creating now...\n"\
|
|
200
|
+
" - OK\n"\
|
|
201
|
+
" - OK\n"\
|
|
202
|
+
" - all OK\n"\
|
|
203
|
+
"Succeeded, with warnings.\n"
|
|
204
|
+
desired[:STDERR] =
|
|
205
|
+
"WARNING: Host '#{host_name}' doesn't exist, but will be created.\n"
|
|
206
|
+
|
|
207
|
+
expected(actual, desired)
|
|
208
|
+
|
|
209
|
+
# Check db
|
|
210
|
+
group = @db.models[:group].find(name: group_name)
|
|
211
|
+
hosts = group.hosts_dataset
|
|
212
|
+
expect(hosts).not_to be_nil
|
|
213
|
+
expect(hosts.count).to eq(1)
|
|
214
|
+
expect(hosts[name: host_name]).not_to be_nil
|
|
216
215
|
end
|
|
217
216
|
|
|
218
217
|
# --------------------
|
|
219
218
|
it 'GROUP1 --hosts HOST ... should skip if association already exists, and warn' do
|
|
220
219
|
host_name = 'test-host'
|
|
221
220
|
group_name = 'test-group'
|
|
222
|
-
|
|
221
|
+
|
|
223
222
|
# Create group and association
|
|
224
223
|
runner { @app.start(%W(group add #{group_name} --hosts #{host_name})) }
|
|
225
|
-
|
|
224
|
+
|
|
226
225
|
# Do it again, to prove that we skip
|
|
227
226
|
actual = runner do
|
|
228
227
|
@app.start(%W(group add #{group_name} --hosts #{host_name}))
|
|
229
228
|
end
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
|
|
230
|
+
# @console.out(actual, 'y')
|
|
231
|
+
|
|
233
232
|
# Check output
|
|
234
233
|
desired = {}
|
|
235
234
|
desired[:STDOUT] =
|
|
@@ -242,12 +241,12 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
242
241
|
" - OK\n"\
|
|
243
242
|
" - all OK\n"\
|
|
244
243
|
"Succeeded, with warnings.\n"
|
|
245
|
-
desired[:STDERR] =
|
|
244
|
+
desired[:STDERR] =
|
|
246
245
|
"WARNING: Group '#{group_name}' already exists, skipping creation.\n"\
|
|
247
246
|
"WARNING: Association {group:#{group_name} <-> host:#{host_name}} already exists, skipping creation.\n"
|
|
248
|
-
|
|
247
|
+
|
|
249
248
|
expected(actual, desired)
|
|
250
|
-
|
|
249
|
+
|
|
251
250
|
# Check db
|
|
252
251
|
group = @db.models[:group].find(name: group_name)
|
|
253
252
|
hosts = group.hosts_dataset
|
|
@@ -255,35 +254,35 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
255
254
|
expect(hosts.count).to eq(1)
|
|
256
255
|
expect(hosts[name: host_name]).not_to be_nil
|
|
257
256
|
end
|
|
258
|
-
|
|
257
|
+
|
|
259
258
|
# --------------------
|
|
260
259
|
it 'GROUP --hosts HOST1,HOST2 ... should add the group and '\
|
|
261
260
|
'associate it with multiple hosts' do
|
|
262
|
-
|
|
261
|
+
|
|
263
262
|
# The group should be added
|
|
264
263
|
# Each host should be associated with the group
|
|
265
264
|
# Each host should be removed from the automatic 'ungrouped' group
|
|
266
|
-
|
|
265
|
+
|
|
267
266
|
group_name = 'test-group'
|
|
268
267
|
host_names = %w(host1 host2 host3)
|
|
269
|
-
|
|
268
|
+
|
|
270
269
|
# Add just the first host. This ensure that we cover paths for both
|
|
271
270
|
# and existing host (with an 'ungrouped' association) and for none
|
|
272
|
-
# existing groups.
|
|
271
|
+
# existing groups.
|
|
273
272
|
tmp = runner { @app.start(%W(host add #{host_names[0]})) }
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
# Now run the actual group addition
|
|
273
|
+
|
|
274
|
+
# @console.out(tmp, 'y')
|
|
275
|
+
|
|
276
|
+
# Now run the actual group addition
|
|
278
277
|
actual = runner do
|
|
279
278
|
@app.start(%W(group add #{group_name} --hosts #{host_names.join(',')}))
|
|
280
279
|
end
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
280
|
+
|
|
281
|
+
# @console.out(actual,'y')
|
|
282
|
+
|
|
284
283
|
# Check output
|
|
285
284
|
desired = { aborted: false, STDERR: '', STDOUT: '' }
|
|
286
|
-
desired[:STDOUT] =
|
|
285
|
+
desired[:STDOUT] =
|
|
287
286
|
"Add group '#{group_name}':\n"\
|
|
288
287
|
" - create group...\n"\
|
|
289
288
|
" - OK\n"\
|
|
@@ -291,22 +290,22 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
291
290
|
" - OK\n"\
|
|
292
291
|
" - remove automatic association {group:ungrouped <-> host:#{host_names[0]}}...\n"\
|
|
293
292
|
" - OK\n"
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
293
|
+
|
|
294
|
+
host_names.slice(1, host_names.length - 1).each do |host_name|
|
|
295
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
296
|
+
" - add association {group:#{group_name} <-> host:#{host_name}}...\n"\
|
|
297
|
+
" - host doesn't exist, creating now...\n"\
|
|
298
|
+
" - OK\n"\
|
|
299
|
+
" - OK\n"
|
|
300
|
+
desired[:STDERR] = desired[:STDERR] +
|
|
301
|
+
"WARNING: Host '#{host_name}' doesn't exist, but will be created.\n"
|
|
303
302
|
end
|
|
304
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
303
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
304
|
+
" - all OK\n"\
|
|
305
|
+
"Succeeded, with warnings.\n"
|
|
306
|
+
|
|
308
307
|
expected(actual, desired)
|
|
309
|
-
|
|
308
|
+
|
|
310
309
|
# Check db
|
|
311
310
|
group = @db.models[:group].find(name: group_name)
|
|
312
311
|
hosts = group.hosts_dataset
|
|
@@ -323,16 +322,16 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
323
322
|
'with an error' do
|
|
324
323
|
name = 'testhost'
|
|
325
324
|
group_names = %w(group1 ungrouped)
|
|
326
|
-
|
|
325
|
+
|
|
327
326
|
actual = runner do
|
|
328
327
|
@app.start(%W(host add #{name} --groups #{group_names.join(',')}))
|
|
329
328
|
end
|
|
330
|
-
|
|
329
|
+
|
|
331
330
|
# Check output
|
|
332
331
|
desired = { aborted: true, STDERR: '', STDOUT: '' }
|
|
333
332
|
desired[:STDERR] =
|
|
334
|
-
|
|
335
|
-
|
|
333
|
+
"ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
|
|
334
|
+
|
|
336
335
|
expected(actual, desired)
|
|
337
336
|
end
|
|
338
337
|
|
|
@@ -347,38 +346,38 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
347
346
|
actual = runner do
|
|
348
347
|
@app.start(%w(group add) + group_names + %W(--hosts #{host_names.join(',')}))
|
|
349
348
|
end
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
349
|
+
|
|
350
|
+
# @console.out(actual,'y')
|
|
351
|
+
|
|
353
352
|
# Check output
|
|
354
353
|
desired = { aborted: false, STDERR: '', STDOUT: '' }
|
|
355
354
|
first_pass = true
|
|
356
355
|
group_names.each do |group|
|
|
357
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
356
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
357
|
+
"Add group '#{group}':\n"\
|
|
358
|
+
" - create group...\n"\
|
|
359
|
+
" - OK\n"
|
|
360
|
+
|
|
362
361
|
host_names.each do |host|
|
|
363
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
364
|
-
|
|
362
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
363
|
+
" - add association {group:#{group} <-> host:#{host}}...\n"
|
|
365
364
|
if first_pass
|
|
366
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
367
|
-
|
|
368
|
-
|
|
365
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
366
|
+
" - host doesn't exist, creating now...\n"\
|
|
367
|
+
" - OK\n"
|
|
369
368
|
end
|
|
370
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
371
|
-
|
|
369
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
370
|
+
" - OK\n"
|
|
372
371
|
end
|
|
373
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
374
|
-
|
|
372
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
373
|
+
" - all OK\n"
|
|
375
374
|
first_pass = false
|
|
376
|
-
end
|
|
377
|
-
|
|
375
|
+
end
|
|
376
|
+
|
|
378
377
|
desired[:STDOUT] = desired[:STDOUT] + "Succeeded, with warnings.\n"
|
|
379
378
|
host_names.each do |host|
|
|
380
|
-
desired[:STDERR] =
|
|
381
|
-
|
|
379
|
+
desired[:STDERR] = desired[:STDERR] +
|
|
380
|
+
"WARNING: Host '#{host}' doesn't exist, but will be created.\n"
|
|
382
381
|
end
|
|
383
382
|
expected(actual, desired)
|
|
384
383
|
|
|
@@ -9,7 +9,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
9
9
|
@mockarg_parts = {
|
|
10
10
|
config: File.join(spec_root, 'config/config.yml'),
|
|
11
11
|
format: 'yaml',
|
|
12
|
-
env: 'test'
|
|
12
|
+
env: 'test',
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
@mockargs = []
|
|
@@ -19,7 +19,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
@console = Moose::Inventory::Cli::Formatter
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
@config = Moose::Inventory::Config
|
|
24
24
|
@config.init(@mockargs)
|
|
25
25
|
|
|
@@ -49,66 +49,65 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
49
49
|
@app.start(%w(group addchild))
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
# @console.out(actual, 'y')
|
|
53
|
+
|
|
54
54
|
# Check output
|
|
55
|
-
desired = { aborted: true}
|
|
55
|
+
desired = { aborted: true }
|
|
56
56
|
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 2 or more.\n"
|
|
57
57
|
expected(actual, desired)
|
|
58
58
|
end
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
#------------------------
|
|
61
61
|
it 'ungrouped ... should abort with an error' do
|
|
62
|
-
parent_name =
|
|
63
|
-
child_name =
|
|
64
|
-
|
|
65
|
-
actual = runner
|
|
62
|
+
parent_name = 'ungrouped'
|
|
63
|
+
child_name = 'fake'
|
|
64
|
+
|
|
65
|
+
actual = runner do
|
|
66
66
|
@app.start(%W(group addchild #{parent_name} #{child_name}))
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
# @console.out(actual, 'y')
|
|
70
|
+
|
|
71
71
|
# Check output
|
|
72
|
-
desired = { aborted: true}
|
|
72
|
+
desired = { aborted: true }
|
|
73
73
|
desired[:STDERR] = "ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
|
|
74
74
|
expected(actual, desired)
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
############################
|
|
77
|
-
# Should work the other way round too, when the child in the ungrouped item
|
|
78
|
-
parent_name =
|
|
79
|
-
child_name =
|
|
80
|
-
|
|
81
|
-
actual = runner
|
|
77
|
+
# Should work the other way round too, when the child in the ungrouped item
|
|
78
|
+
parent_name = 'fake'
|
|
79
|
+
child_name = 'ungrouped'
|
|
80
|
+
|
|
81
|
+
actual = runner do
|
|
82
82
|
@app.start(%W(group addchild #{parent_name} #{child_name}))
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
# @console.out(actual, 'y')
|
|
86
|
+
|
|
87
87
|
# Check output
|
|
88
|
-
desired = { aborted: true}
|
|
88
|
+
desired = { aborted: true }
|
|
89
89
|
desired[:STDERR] = "ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
|
|
90
90
|
expected(actual, desired)
|
|
91
|
-
|
|
92
|
-
end
|
|
91
|
+
end
|
|
93
92
|
|
|
94
93
|
#------------------------
|
|
95
94
|
it 'GROUP CHILDGROUP ... should abort if GROUP does not exist' do
|
|
96
95
|
# TODO: Why don't we just create GROUP? Likewise for all similar functions?
|
|
97
|
-
|
|
96
|
+
|
|
98
97
|
pname = 'parent_group'
|
|
99
98
|
cname = 'child group'
|
|
100
|
-
|
|
99
|
+
|
|
101
100
|
actual = runner do
|
|
102
101
|
@app.start(%W(group addchild #{pname} #{cname}))
|
|
103
102
|
end
|
|
104
103
|
|
|
105
|
-
|
|
104
|
+
# @console.out(actual, 'y')
|
|
106
105
|
# Check output
|
|
107
|
-
desired = { aborted: true}
|
|
108
|
-
desired[:STDOUT] =
|
|
106
|
+
desired = { aborted: true }
|
|
107
|
+
desired[:STDOUT] =
|
|
109
108
|
"Associate parent group '#{pname}' with child group(s) '#{cname}':\n"\
|
|
110
109
|
" - retrieve group '#{pname}'...\n"
|
|
111
|
-
desired[:STDERR] =
|
|
110
|
+
desired[:STDERR] =
|
|
112
111
|
"ERROR: The group '#{pname}' does not exist.\n"\
|
|
113
112
|
"An error occurred during a transaction, any changes have been rolled back.\n"
|
|
114
113
|
expected(actual, desired)
|
|
@@ -121,12 +120,12 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
121
120
|
|
|
122
121
|
runner { @app.start(%W(group add #{pname} #{cname})) }
|
|
123
122
|
|
|
124
|
-
actual = runner { @app.start(%W(group addchild #{pname} #{cname}
|
|
123
|
+
actual = runner { @app.start(%W(group addchild #{pname} #{cname})) }
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
desired = { aborted: false}
|
|
129
|
-
desired[:STDOUT] =
|
|
125
|
+
# @console.out(actual, 'y')
|
|
126
|
+
|
|
127
|
+
desired = { aborted: false }
|
|
128
|
+
desired[:STDOUT] =
|
|
130
129
|
"Associate parent group '#{pname}' with child group(s) '#{cname}':\n"\
|
|
131
130
|
" - retrieve group '#{pname}'...\n"\
|
|
132
131
|
" - OK\n"\
|
|
@@ -138,26 +137,26 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
138
137
|
|
|
139
138
|
# We should have the correct group associations
|
|
140
139
|
pgroup = @db.models[:group].find(name: pname)
|
|
141
|
-
cgroups = pgroup.children_dataset
|
|
140
|
+
cgroups = pgroup.children_dataset
|
|
142
141
|
expect(cgroups.count).to eq(1)
|
|
143
142
|
expect(cgroups[name: cname]).not_to be_nil
|
|
144
143
|
end
|
|
145
|
-
|
|
144
|
+
|
|
146
145
|
#------------------------
|
|
147
146
|
it 'GROUP CHILDGROUP... should associate GROUP with a CHILDGROUP '\
|
|
148
147
|
'creating it if necessary' do
|
|
149
|
-
#
|
|
148
|
+
#
|
|
150
149
|
pname = 'parent_group'
|
|
151
|
-
cname = 'child_group'
|
|
152
|
-
|
|
150
|
+
cname = 'child_group'
|
|
151
|
+
|
|
153
152
|
runner { @app.start(%W(group add #{pname})) } # <- don't pre-create the child
|
|
154
|
-
|
|
155
|
-
actual = runner { @app.start(%W(group addchild #{pname} #{cname}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
desired = { aborted: false}
|
|
160
|
-
desired[:STDOUT] =
|
|
153
|
+
|
|
154
|
+
actual = runner { @app.start(%W(group addchild #{pname} #{cname})) }
|
|
155
|
+
|
|
156
|
+
# @console.out(actual, 'y')
|
|
157
|
+
|
|
158
|
+
desired = { aborted: false }
|
|
159
|
+
desired[:STDOUT] =
|
|
161
160
|
"Associate parent group '#{pname}' with child group(s) '#{cname}':\n"\
|
|
162
161
|
" - retrieve group '#{pname}'...\n"\
|
|
163
162
|
" - OK\n"\
|
|
@@ -167,15 +166,14 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
167
166
|
" - OK\n"\
|
|
168
167
|
" - all OK\n"\
|
|
169
168
|
"Succeeded, with warnings.\n"
|
|
170
|
-
desired[:STDERR] = "WARNING: Group '#{cname}' does not exist and will be created.\n"
|
|
169
|
+
desired[:STDERR] = "WARNING: Group '#{cname}' does not exist and will be created.\n"
|
|
171
170
|
expected(actual, desired)
|
|
172
|
-
|
|
171
|
+
|
|
173
172
|
# We should have the correct group associations
|
|
174
173
|
pgroup = @db.models[:group].find(name: pname)
|
|
175
|
-
cgroups = pgroup.children_dataset
|
|
174
|
+
cgroups = pgroup.children_dataset
|
|
176
175
|
expect(cgroups.count).to eq(1)
|
|
177
176
|
expect(cgroups[name: cname]).not_to be_nil
|
|
178
177
|
end
|
|
179
|
-
|
|
180
178
|
end
|
|
181
179
|
end
|