moose-inventory 1.0.8 → 1.0.9
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 +35 -0
- data/.gitignore +1 -1
- data/BACKLOG.md +184 -0
- data/Gemfile.lock +60 -0
- data/README.md +14 -5
- data/bin/moose-inventory +1 -1
- data/docs/release/publishing.md +113 -0
- data/docs/release/release-readiness.md +41 -0
- data/docs/security-audit-2026-05-21.md +71 -0
- data/lib/moose_inventory/cli/formatter.rb +16 -17
- data/lib/moose_inventory/cli/group.rb +1 -1
- data/lib/moose_inventory/cli/group_add.rb +19 -21
- data/lib/moose_inventory/cli/group_addchild.rb +36 -40
- data/lib/moose_inventory/cli/group_addhost.rb +14 -18
- 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 +21 -23
- data/lib/moose_inventory/cli/group_rmchild.rb +5 -6
- data/lib/moose_inventory/cli/group_rmhost.rb +12 -16
- data/lib/moose_inventory/cli/group_rmvar.rb +5 -5
- data/lib/moose_inventory/cli/host.rb +1 -1
- data/lib/moose_inventory/cli/host_add.rb +18 -18
- data/lib/moose_inventory/cli/host_addgroup.rb +9 -9
- 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 +5 -5
- 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 +70 -50
- data/lib/moose_inventory/db/models.rb +11 -12
- data/lib/moose_inventory/version.rb +1 -1
- data/moose-inventory.gemspec +35 -20
- data/scripts/check.sh +8 -0
- data/scripts/ci/check_permissions.sh +32 -0
- data/scripts/ci/check_security.sh +50 -0
- data/scripts/ci/package_sanity.sh +46 -0
- data/scripts/files.rb +1 -4
- data/scripts/install_dependencies.sh +17 -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 +75 -78
- data/spec/lib/moose_inventory/cli/group_rmchild_spec.rb +41 -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 +224 -2
- data/spec/lib/moose_inventory/db/models_spec.rb +10 -11
- data/spec/shared/shared_config_setup.rb +2 -2
- data/spec/spec_helper.rb +7 -8
- metadata +99 -136
- data/.coveralls.yml +0 -0
- data/.rubocop.yml +0 -793
- 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
|
@@ -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 = []
|
|
@@ -40,96 +40,96 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
40
40
|
result = @group.instance_methods(false).include?(:addvar)
|
|
41
41
|
expect(result).to eq(true)
|
|
42
42
|
end
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
#-----------------
|
|
45
45
|
it '<missing args> ... should abort with an error' do
|
|
46
46
|
actual = runner do
|
|
47
47
|
@app.start(%w(group addvar)) # <- no group given
|
|
48
48
|
end
|
|
49
49
|
# @console.out(actual, 'y')
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
# Check output
|
|
52
|
-
desired = { aborted: true}
|
|
52
|
+
desired = { aborted: true }
|
|
53
53
|
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 2 or more.\n"
|
|
54
54
|
expected(actual, desired)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
#------------------------
|
|
58
58
|
it 'GROUP key=value ... should abort if the group does not exist' do
|
|
59
|
-
group_name ='not-a-group'
|
|
60
|
-
group_var =
|
|
61
|
-
|
|
59
|
+
group_name = 'not-a-group'
|
|
60
|
+
group_var = 'foo=bar'
|
|
61
|
+
|
|
62
62
|
actual = runner do
|
|
63
63
|
@app.start(%W(group addvar #{group_name} #{group_var}))
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# Check output
|
|
67
|
-
desired = { aborted: true}
|
|
68
|
-
desired[:STDOUT] =
|
|
67
|
+
desired = { aborted: true }
|
|
68
|
+
desired[:STDOUT] =
|
|
69
69
|
"Add variables '#{group_var}' to group '#{group_name}':\n"\
|
|
70
70
|
" - retrieve group '#{group_name}'...\n"
|
|
71
|
-
desired[:STDERR] =
|
|
71
|
+
desired[:STDERR] =
|
|
72
72
|
"An error occurred during a transaction, any changes have been rolled back.\n"\
|
|
73
73
|
"ERROR: The group '#{group_name}' does not exist.\n"
|
|
74
74
|
expected(actual, desired)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
#------------------------
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
78
|
+
it 'GROUP <malformed> ... should abort with an error' do
|
|
79
|
+
# 1. Should add the var to the db
|
|
80
|
+
# 2. Should associate the host with the var
|
|
81
|
+
|
|
82
|
+
group_name = 'test_group'
|
|
83
|
+
@db.models[:group].create(name: group_name)
|
|
84
|
+
|
|
85
|
+
var = { name: 'var1', value: 'testval' }
|
|
86
|
+
cases = %w(
|
|
87
|
+
testvar
|
|
88
|
+
testvar=
|
|
89
|
+
=testval
|
|
90
|
+
testvar=testval=
|
|
91
|
+
=testvar=testval
|
|
92
|
+
testvar=testval=extra
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
cases.each do |args|
|
|
96
|
+
actual = runner do
|
|
97
|
+
@app.start(%W(group addvar #{group_name} #{args}))
|
|
98
|
+
end
|
|
99
|
+
# @console.out(actual,'p')
|
|
100
|
+
|
|
101
|
+
desired = { aborted: true }
|
|
102
|
+
desired[:STDOUT] =
|
|
103
|
+
"Add variables '#{args}' to group '#{group_name}':\n"\
|
|
104
|
+
" - retrieve group '#{group_name}'...\n"\
|
|
105
|
+
" - OK\n"\
|
|
106
|
+
" - add variable '#{args}'...\n"
|
|
107
|
+
|
|
108
|
+
desired[:STDERR] =
|
|
109
|
+
"An error occurred during a transaction, any changes have been rolled back.\n"\
|
|
110
|
+
"ERROR: Incorrect format in '{#{args}}'. Expected 'key=value'.\n"
|
|
111
|
+
|
|
112
|
+
expected(actual, desired)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
116
|
#------------------------
|
|
117
117
|
it 'GROUP key=value ... should associate the group with the key/value pair' do
|
|
118
118
|
# 1. Should add the var to the db
|
|
119
119
|
# 2. Should associate the host with the var
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
group_name = 'test1'
|
|
122
|
-
var
|
|
122
|
+
var = { name: 'var1', value: 'testval' }
|
|
123
123
|
|
|
124
124
|
@db.models[:group].create(name: group_name)
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
actual = runner do
|
|
127
|
-
@app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]}
|
|
127
|
+
@app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]}))
|
|
128
128
|
end
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
desired = { aborted: false}
|
|
132
|
-
desired[:STDOUT] =
|
|
129
|
+
# @console.out(actual,'p')
|
|
130
|
+
|
|
131
|
+
desired = { aborted: false }
|
|
132
|
+
desired[:STDOUT] =
|
|
133
133
|
"Add variables '#{var[:name]}=#{var[:value]}' to group '#{group_name}':\n"\
|
|
134
134
|
" - retrieve group '#{group_name}'...\n"\
|
|
135
135
|
" - OK\n"\
|
|
@@ -146,71 +146,71 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
146
146
|
expect(groupvars[name: var[:name]]).not_to be_nil
|
|
147
147
|
expect(groupvars[name: var[:name]][:value]).to eq(var[:value])
|
|
148
148
|
end
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
#------------------------
|
|
151
151
|
it 'GROUP key1=value1 key2=value2 ... should associate the group with multiple key/value pairs' do
|
|
152
152
|
# 1. Should add the var to the db
|
|
153
153
|
# 2. Should associate the host with the var
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
group_name = 'test1'
|
|
156
156
|
varsarray = [
|
|
157
|
-
{name: 'var1', value:
|
|
158
|
-
{name: 'var2', value:
|
|
157
|
+
{ name: 'var1', value: 'val1' },
|
|
158
|
+
{ name: 'var2', value: 'val2' },
|
|
159
159
|
]
|
|
160
|
-
|
|
160
|
+
|
|
161
161
|
vars = []
|
|
162
162
|
varsarray.each do |var|
|
|
163
163
|
vars << "#{var[:name]}=#{var[:value]}"
|
|
164
164
|
end
|
|
165
|
-
|
|
165
|
+
|
|
166
166
|
@db.models[:group].create(name: group_name)
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
actual = runner do
|
|
169
|
-
@app.start(%W(group addvar #{group_name}) + vars
|
|
169
|
+
@app.start(%W(group addvar #{group_name}) + vars)
|
|
170
170
|
end
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
desired = { aborted: false}
|
|
175
|
-
desired[:STDOUT] =
|
|
171
|
+
|
|
172
|
+
# @console.out(actual,'y')
|
|
173
|
+
|
|
174
|
+
desired = { aborted: false }
|
|
175
|
+
desired[:STDOUT] =
|
|
176
176
|
"Add variables '#{vars.join(',')}' to group '#{group_name}':\n"\
|
|
177
177
|
" - retrieve group '#{group_name}'...\n"\
|
|
178
178
|
" - OK\n"
|
|
179
179
|
vars.each do |var|
|
|
180
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
181
|
+
" - add variable '#{var}'...\n"\
|
|
182
|
+
" - OK\n"
|
|
183
183
|
end
|
|
184
|
-
desired[:STDOUT] =
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
185
|
+
" - all OK\n"\
|
|
186
|
+
"Succeeded.\n"
|
|
187
187
|
expected(actual, desired)
|
|
188
|
-
|
|
188
|
+
|
|
189
189
|
# We should have the correct hostvar associations
|
|
190
190
|
group = @db.models[:group].find(name: group_name)
|
|
191
191
|
groupvars = group.groupvars_dataset
|
|
192
192
|
expect(vars.count).to eq(vars.length)
|
|
193
|
-
end
|
|
193
|
+
end
|
|
194
194
|
|
|
195
195
|
#------------------------
|
|
196
196
|
it 'GROUP key=value ... should update an already existing association' do
|
|
197
197
|
# 1. Should add the var to the db
|
|
198
198
|
# 2. Should associate the host with the var
|
|
199
|
-
|
|
199
|
+
|
|
200
200
|
group_name = 'test1'
|
|
201
|
-
var
|
|
202
|
-
|
|
201
|
+
var = { name: 'var1', value: 'testval' }
|
|
202
|
+
|
|
203
203
|
@db.models[:group].create(name: group_name)
|
|
204
|
-
runner { @app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]}
|
|
205
|
-
|
|
206
|
-
var[:value]
|
|
204
|
+
runner { @app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]})) }
|
|
205
|
+
|
|
206
|
+
var[:value] = 'newtestval'
|
|
207
207
|
actual = runner do
|
|
208
|
-
@app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]}
|
|
208
|
+
@app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]}))
|
|
209
209
|
end
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
desired = { aborted: false}
|
|
213
|
-
desired[:STDOUT] =
|
|
210
|
+
# @console.out(actual,'y')
|
|
211
|
+
|
|
212
|
+
desired = { aborted: false }
|
|
213
|
+
desired[:STDOUT] =
|
|
214
214
|
"Add variables '#{var[:name]}=#{var[:value]}' to group '#{group_name}':\n"\
|
|
215
215
|
" - retrieve group '#{group_name}'...\n"\
|
|
216
216
|
" - OK\n"\
|
|
@@ -220,16 +220,16 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
220
220
|
" - all OK\n"\
|
|
221
221
|
"Succeeded.\n"
|
|
222
222
|
expected(actual, desired)
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
# We should have the correct hostvar associations
|
|
225
225
|
group = @db.models[:group].find(name: group_name)
|
|
226
226
|
groupvars = group.groupvars_dataset
|
|
227
227
|
expect(groupvars.count).to eq(1)
|
|
228
228
|
expect(groupvars[name: var[:name]]).not_to be_nil
|
|
229
229
|
expect(groupvars[name: var[:name]][:value]).to eq(var[:value])
|
|
230
|
-
|
|
230
|
+
|
|
231
231
|
groupvars = @db.models[:groupvar].all
|
|
232
|
-
expect(groupvars.count).to eq(1)
|
|
232
|
+
expect(groupvars.count).to eq(1)
|
|
233
233
|
end
|
|
234
234
|
end
|
|
235
235
|
end
|
|
@@ -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 = []
|
|
@@ -21,7 +21,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
21
21
|
@config = Moose::Inventory::Config
|
|
22
22
|
@config.init(@mockargs)
|
|
23
23
|
@console = Moose::Inventory::Cli::Formatter
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
@db = Moose::Inventory::DB
|
|
26
26
|
@db.init if @db.db.nil?
|
|
27
27
|
|
|
@@ -43,23 +43,23 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
43
43
|
|
|
44
44
|
#---------------------
|
|
45
45
|
it '<missing args> ... should abort with an error' do
|
|
46
|
-
actual = runner { @app.start(%
|
|
46
|
+
actual = runner { @app.start(%w(group get)) }
|
|
47
|
+
|
|
48
|
+
# @console.out(actual,'y')
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
desired = {aborted: true}
|
|
50
|
+
desired = { aborted: true }
|
|
51
51
|
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 1 or more\n"
|
|
52
52
|
|
|
53
53
|
expected(actual, desired)
|
|
54
54
|
end
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
#---------------------
|
|
57
57
|
it "GROUP ... should return an empty set when GROUP doesn't exist" do
|
|
58
58
|
group_name = 'does-not-exist'
|
|
59
|
-
actual = runner { @app.start(%W(group get #{
|
|
59
|
+
actual = runner { @app.start(%W(group get #{group_name})) }
|
|
60
|
+
|
|
61
|
+
# @console.out(actual, 'y')
|
|
60
62
|
|
|
61
|
-
#@console.out(actual, 'y')
|
|
62
|
-
|
|
63
63
|
desired = {}
|
|
64
64
|
desired[:STDOUT] = {}.to_yaml
|
|
65
65
|
|
|
@@ -69,14 +69,14 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
69
69
|
#---------------------
|
|
70
70
|
it 'GROUP ... should get a group from the db' do
|
|
71
71
|
name = 'test_group'
|
|
72
|
-
runner { @app.start(%W(group add #{
|
|
72
|
+
runner { @app.start(%W(group add #{name})) }
|
|
73
73
|
|
|
74
|
-
actual = runner { @app.start(%W(group get #{
|
|
74
|
+
actual = runner { @app.start(%W(group get #{name})) }
|
|
75
75
|
|
|
76
76
|
mock = {}
|
|
77
77
|
mock[name.to_sym] = {}
|
|
78
|
-
# mock[name.to_sym][:hosts] = [] # TODO: Should this be present or not?
|
|
79
|
-
|
|
78
|
+
# mock[name.to_sym][:hosts] = [] # TODO: Should this be present or not?
|
|
79
|
+
|
|
80
80
|
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
|
81
81
|
desired[:STDOUT] = mock.to_yaml
|
|
82
82
|
|
|
@@ -87,21 +87,20 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
87
87
|
it 'GROUP ... should display groupvars, if any are set' do
|
|
88
88
|
name = 'test_group'
|
|
89
89
|
var = 'foo=bar'
|
|
90
|
-
tmp = runner { @app.start(%W(group add #{
|
|
91
|
-
tmp = runner { @app.start(%W(group addvar #{
|
|
90
|
+
tmp = runner { @app.start(%W(group add #{name})) }
|
|
91
|
+
tmp = runner { @app.start(%W(group addvar #{name} #{var})) }
|
|
92
|
+
|
|
93
|
+
actual = runner { @app.start(%W(group get #{name})) }
|
|
94
|
+
# @console.out(actual, 'y')
|
|
92
95
|
|
|
93
|
-
actual = runner { @app.start(%W(group get #{ name })) }
|
|
94
|
-
#@console.out(actual, 'y')
|
|
95
|
-
|
|
96
96
|
mock = {}
|
|
97
97
|
mock[name.to_sym] = {}
|
|
98
|
-
mock[name.to_sym][:groupvars] = {foo: 'bar'}
|
|
99
|
-
|
|
98
|
+
mock[name.to_sym][:groupvars] = { foo: 'bar' }
|
|
99
|
+
|
|
100
100
|
desired = {}
|
|
101
101
|
desired[:STDOUT] = mock.to_yaml
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
expected(actual, desired)
|
|
104
104
|
end
|
|
105
|
-
|
|
106
105
|
end
|
|
107
106
|
end
|
|
@@ -6,7 +6,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
6
6
|
@mockarg_parts = {
|
|
7
7
|
config: File.join(spec_root, 'config/config.yml'),
|
|
8
8
|
format: 'yaml',
|
|
9
|
-
env: 'test'
|
|
9
|
+
env: 'test',
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
@mockargs = []
|
|
@@ -23,7 +23,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
23
23
|
|
|
24
24
|
@console = Moose::Inventory::Cli::Formatter
|
|
25
25
|
@group = Moose::Inventory::Cli::Group
|
|
26
|
-
@cli = Moose::Inventory::Cli
|
|
26
|
+
@cli = Moose::Inventory::Cli
|
|
27
27
|
@app = Moose::Inventory::Cli::Application
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -42,7 +42,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
42
42
|
#---------------------
|
|
43
43
|
it 'should return an empty set when no results' do
|
|
44
44
|
# no items in the db
|
|
45
|
-
actual = runner { @app.start(%
|
|
45
|
+
actual = runner { @app.start(%w(group list)) }
|
|
46
46
|
|
|
47
47
|
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
|
48
48
|
desired[:STDOUT] = {}.to_yaml
|
|
@@ -59,14 +59,14 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
59
59
|
groups = %w(group1 group2 group3)
|
|
60
60
|
groups.each do |name|
|
|
61
61
|
runner { @app.start(%W(group add #{name})) }
|
|
62
|
-
runner { @app.start(%W(group addvar #{
|
|
62
|
+
runner { @app.start(%W(group addvar #{name} #{var})) }
|
|
63
63
|
mock[name.to_sym] = {}
|
|
64
|
-
mock[name.to_sym][:groupvars] = {foo: 'bar'}
|
|
64
|
+
mock[name.to_sym][:groupvars] = { foo: 'bar' }
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
# items should now be in the db
|
|
68
|
-
actual = runner{ @app.start(%w(group list)) }
|
|
69
|
-
|
|
68
|
+
actual = runner { @app.start(%w(group list)) }
|
|
69
|
+
|
|
70
70
|
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
|
71
71
|
desired[:STDOUT] = mock.to_yaml
|
|
72
72
|
|
|
@@ -75,28 +75,27 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
75
75
|
|
|
76
76
|
#---------------------
|
|
77
77
|
it 'should be an alias of --list (i.e. Ansible parameter)' do
|
|
78
|
-
|
|
79
78
|
host_name = 'test_host'
|
|
80
79
|
|
|
81
80
|
mock = {}
|
|
82
81
|
groups = %w(group1 group2 group3)
|
|
83
82
|
groups.each do |name|
|
|
84
83
|
runner { @app.start(%W(group add #{name})) }
|
|
85
|
-
mock[name.to_sym] = {}
|
|
84
|
+
mock[name.to_sym] = { hosts: [] }
|
|
86
85
|
end
|
|
87
|
-
|
|
86
|
+
|
|
88
87
|
args = @mockargs.clone
|
|
89
|
-
args <<
|
|
90
|
-
|
|
91
|
-
actual = runner{ @cli.start(args) }
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
args << '--list'
|
|
89
|
+
|
|
90
|
+
actual = runner { @cli.start(args) }
|
|
91
|
+
|
|
92
|
+
# @console.out(actual, 'y')
|
|
93
|
+
|
|
95
94
|
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
|
96
95
|
desired[:STDOUT] = mock.to_json + "\n"
|
|
97
|
-
|
|
96
|
+
|
|
98
97
|
expected(actual, desired)
|
|
99
|
-
end
|
|
100
|
-
|
|
98
|
+
end
|
|
99
|
+
end
|
|
101
100
|
end
|
|
102
|
-
|
|
101
|
+
|
|
@@ -6,7 +6,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
6
6
|
@mockarg_parts = {
|
|
7
7
|
config: File.join(spec_root, 'config/config.yml'),
|
|
8
8
|
format: 'yaml',
|
|
9
|
-
env: 'test'
|
|
9
|
+
env: 'test',
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
@mockargs = []
|
|
@@ -23,12 +23,12 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
23
23
|
|
|
24
24
|
@console = Moose::Inventory::Cli::Formatter
|
|
25
25
|
@group = Moose::Inventory::Cli::Group
|
|
26
|
-
@cli = Moose::Inventory::Cli
|
|
26
|
+
@cli = Moose::Inventory::Cli
|
|
27
27
|
@app = Moose::Inventory::Cli::Application
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
before(:each) do
|
|
31
|
-
# We make some @cli calls, which changes config,
|
|
31
|
+
# We make some @cli calls, which changes config,
|
|
32
32
|
# so we must reset config on each pass
|
|
33
33
|
@config.init(@mockargs)
|
|
34
34
|
@db.reset
|
|
@@ -41,79 +41,78 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
41
41
|
result = @group.instance_methods(false).include?(:listvars)
|
|
42
42
|
expect(result).to eq(true)
|
|
43
43
|
end
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
#-----------------
|
|
46
46
|
it '<missing args> ... should abort with an error' do
|
|
47
|
-
actual = runner {
|
|
47
|
+
actual = runner { @app.start(%w(group listvars)) }
|
|
48
48
|
|
|
49
49
|
# Check output
|
|
50
|
-
desired = { aborted: true}
|
|
50
|
+
desired = { aborted: true }
|
|
51
51
|
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 1 or more.\n"
|
|
52
52
|
expected(actual, desired)
|
|
53
53
|
end
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
#-----------------
|
|
56
56
|
it '--ansible <missing args> ... should abort with an error' do
|
|
57
|
-
|
|
58
57
|
args = @mockargs.clone
|
|
59
|
-
args.concat(
|
|
60
|
-
|
|
61
|
-
actual = runner{ @cli.start(args) }
|
|
62
|
-
|
|
58
|
+
args.concat(%w(--ansible group listvars)).flatten
|
|
59
|
+
|
|
60
|
+
actual = runner { @cli.start(args) }
|
|
61
|
+
|
|
63
62
|
# Check output
|
|
64
|
-
desired = { aborted: true}
|
|
63
|
+
desired = { aborted: true }
|
|
65
64
|
desired[:STDERR] = "ERROR: Wrong number of arguments for Ansible mode, 0 for 1.\n"
|
|
66
65
|
expected(actual, desired)
|
|
67
66
|
end
|
|
68
|
-
|
|
67
|
+
|
|
69
68
|
#------------------------
|
|
70
69
|
it 'GROUP ... should return a list of group variables grouped by group' do
|
|
71
|
-
group_name ='test_group'
|
|
70
|
+
group_name = 'test_group'
|
|
72
71
|
group_vars = %w(foo=bar cow=chicken)
|
|
73
|
-
|
|
74
|
-
tmp = runner { @app.start(%W(group add #{group_name}
|
|
72
|
+
|
|
73
|
+
tmp = runner { @app.start(%W(group add #{group_name})) }
|
|
75
74
|
tmp = runner { @app.start(%W(group addvar #{group_name} #{group_vars[0]} #{group_vars[1]})) }
|
|
76
|
-
|
|
75
|
+
|
|
77
76
|
actual = runner do
|
|
78
77
|
@app.start(%W(group listvars #{group_name}))
|
|
79
78
|
end
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
# @console.out(actual, 'y')
|
|
81
|
+
|
|
83
82
|
# Check output
|
|
84
83
|
mock = {}
|
|
85
|
-
mock[group_name.to_sym] = {}
|
|
84
|
+
mock[group_name.to_sym] = {}
|
|
86
85
|
group_vars.each do |hv|
|
|
87
|
-
hv_array = hv.split('=')
|
|
88
|
-
mock[group_name.to_sym][hv_array[0].to_sym] = hv_array[1]
|
|
86
|
+
hv_array = hv.split('=')
|
|
87
|
+
mock[group_name.to_sym][hv_array[0].to_sym] = hv_array[1]
|
|
89
88
|
end
|
|
90
|
-
|
|
89
|
+
|
|
91
90
|
desired = {}
|
|
92
91
|
desired[:STDOUT] = mock.to_yaml
|
|
93
92
|
expected(actual, desired)
|
|
94
93
|
end
|
|
95
|
-
|
|
94
|
+
|
|
96
95
|
#------------------------
|
|
97
96
|
it '--ansible GROUP ... should return a list of group variables, in a style akin to Ansible\'s \'--host HOSTNAME\'' do
|
|
98
|
-
group_name ='test_group'
|
|
97
|
+
group_name = 'test_group'
|
|
99
98
|
group_vars = %w(foo=bar cow=chicken)
|
|
100
|
-
|
|
101
|
-
tmp = runner { @app.start(%W(group add #{group_name}
|
|
99
|
+
|
|
100
|
+
tmp = runner { @app.start(%W(group add #{group_name})) }
|
|
102
101
|
tmp = runner { @app.start(%W(group addvar #{group_name} #{group_vars[0]} #{group_vars[1]})) }
|
|
103
|
-
|
|
102
|
+
|
|
104
103
|
actual = runner do
|
|
105
|
-
@cli.start(%W(--ansible group listvars #{group_name}))
|
|
104
|
+
@cli.start(%W(--config #{@mockarg_parts[:config]} --ansible group listvars #{group_name}))
|
|
106
105
|
end
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
|
|
107
|
+
# @console.out(actual, 'y')
|
|
108
|
+
|
|
110
109
|
# Check output
|
|
111
110
|
mock = {}
|
|
112
111
|
group_vars.each do |hv|
|
|
113
|
-
hv_array = hv.split('=')
|
|
114
|
-
mock[hv_array[0].to_sym] = hv_array[1]
|
|
112
|
+
hv_array = hv.split('=')
|
|
113
|
+
mock[hv_array[0].to_sym] = hv_array[1]
|
|
115
114
|
end
|
|
116
|
-
|
|
115
|
+
|
|
117
116
|
desired = {}
|
|
118
117
|
desired[:STDOUT] = mock.to_json + "\n"
|
|
119
118
|
expected(actual, desired)
|