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
|
@@ -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 = []
|
|
@@ -38,165 +38,165 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
38
38
|
result = @group.instance_methods(false).include?(:rmvar)
|
|
39
39
|
expect(result).to eq(true)
|
|
40
40
|
end
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
#-----------------
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
end
|
|
93
|
-
#@console.out(actual,'p')
|
|
94
|
-
|
|
95
|
-
desired = { aborted: true}
|
|
96
|
-
desired[:STDOUT] =
|
|
97
|
-
"Remove variable(s) '#{args}' from group '#{group_name}':\n"\
|
|
98
|
-
" - retrieve group '#{group_name}'...\n"\
|
|
99
|
-
" - OK\n"\
|
|
100
|
-
" - remove variable '#{args}'...\n"
|
|
101
|
-
desired[:STDERR] =
|
|
102
|
-
"An error occurred during a transaction, any changes have been rolled back.\n"\
|
|
103
|
-
"ERROR: Incorrect format in {#{args}}. Expected 'key' or 'key=value'.\n"
|
|
104
|
-
|
|
105
|
-
expected(actual, desired)
|
|
43
|
+
it '<missing args> ... should abort with an error' do
|
|
44
|
+
actual = runner do
|
|
45
|
+
@app.start(%w(group rmvar))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Check output
|
|
49
|
+
desired = { aborted: true }
|
|
50
|
+
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 2 or more.\n"
|
|
51
|
+
expected(actual, desired)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#------------------------
|
|
55
|
+
it 'GROUP key=value ... should abort if the group does not exist' do
|
|
56
|
+
group_name = 'does-not-exist'
|
|
57
|
+
var_name = 'foo=bar'
|
|
58
|
+
actual = runner do
|
|
59
|
+
@app.start(%W(group rmvar #{group_name} #{var_name}))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Check output
|
|
63
|
+
desired = { aborted: true }
|
|
64
|
+
desired[:STDOUT] =
|
|
65
|
+
"Remove variable(s) '#{var_name}' from group '#{group_name}':\n"\
|
|
66
|
+
" - retrieve group '#{group_name}'...\n"
|
|
67
|
+
desired[:STDERR] =
|
|
68
|
+
"An error occurred during a transaction, any changes have been rolled back.\n"\
|
|
69
|
+
"ERROR: The group '#{group_name}' does not exist.\n"
|
|
70
|
+
expected(actual, desired)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#------------------------
|
|
74
|
+
it '<malformed> ... should abort with an error' do
|
|
75
|
+
# 1. Should add the var to the db
|
|
76
|
+
# 2. Should associate the host with the var
|
|
77
|
+
|
|
78
|
+
group_name = 'test1'
|
|
79
|
+
@db.models[:group].create(name: group_name)
|
|
80
|
+
|
|
81
|
+
var = { name: 'foo', value: 'bar' }
|
|
82
|
+
cases = %w(
|
|
83
|
+
=bar
|
|
84
|
+
foo=bar=
|
|
85
|
+
=foo=bar
|
|
86
|
+
foo=bar=extra
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
cases.each do |args|
|
|
90
|
+
actual = runner do
|
|
91
|
+
@app.start(%W(group rmvar #{group_name} #{args}))
|
|
106
92
|
end
|
|
93
|
+
# @console.out(actual,'p')
|
|
94
|
+
|
|
95
|
+
desired = { aborted: true }
|
|
96
|
+
desired[:STDOUT] =
|
|
97
|
+
"Remove variable(s) '#{args}' from group '#{group_name}':\n"\
|
|
98
|
+
" - retrieve group '#{group_name}'...\n"\
|
|
99
|
+
" - OK\n"\
|
|
100
|
+
" - remove variable '#{args}'...\n"
|
|
101
|
+
desired[:STDERR] =
|
|
102
|
+
"An error occurred during a transaction, any changes have been rolled back.\n"\
|
|
103
|
+
"ERROR: Incorrect format in {#{args}}. Expected 'key' or 'key=value'.\n"
|
|
104
|
+
|
|
105
|
+
expected(actual, desired)
|
|
107
106
|
end
|
|
108
|
-
|
|
107
|
+
end
|
|
108
|
+
|
|
109
109
|
#------------------------
|
|
110
110
|
it 'GROUP <valid args> ... should remove the group variable' do
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
111
|
+
group_name = 'group_test'
|
|
112
|
+
var = { name: 'foo', value: 'bar' }
|
|
113
|
+
cases = %W(
|
|
114
|
+
#{var[:name]}
|
|
115
|
+
#{var[:name]}=
|
|
116
|
+
#{var[:name]}=#{var[:value]}
|
|
117
|
+
)
|
|
118
|
+
cases.each do |example|
|
|
119
|
+
# reset the db
|
|
120
|
+
@db.reset
|
|
121
|
+
|
|
122
|
+
# Add an initial group and groupvar
|
|
123
|
+
@db.models[:group].create(name: group_name)
|
|
124
|
+
runner do
|
|
125
|
+
@app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]}))
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Try to remove the groupvar using the case example valid args
|
|
129
|
+
actual = runner do
|
|
130
|
+
@app.start(%W(group rmvar #{group_name} #{example}))
|
|
131
|
+
end
|
|
132
|
+
# @console.out(actual,'p')
|
|
133
|
+
|
|
134
|
+
# Check the output
|
|
135
|
+
desired = { aborted: false }
|
|
136
|
+
desired[:STDOUT] =
|
|
137
|
+
"Remove variable(s) '#{example}' from group '#{group_name}':\n"\
|
|
138
|
+
" - retrieve group '#{group_name}'...\n"\
|
|
139
|
+
" - OK\n"\
|
|
140
|
+
" - remove variable '#{example}'...\n"\
|
|
141
|
+
" - OK\n"\
|
|
142
|
+
" - all OK\n"\
|
|
143
|
+
"Succeeded.\n"
|
|
144
|
+
|
|
145
|
+
# @console.out(desired,'p')
|
|
146
|
+
expected(actual, desired)
|
|
147
|
+
|
|
148
|
+
# Check the db
|
|
149
|
+
group = @db.models[:group].find(name: group_name)
|
|
150
|
+
groupvars = group.groupvars_dataset
|
|
151
|
+
expect(groupvars.count).to eq(0)
|
|
152
|
+
|
|
153
|
+
groupvars = @db.models[:groupvar].all
|
|
154
|
+
expect(groupvars.count).to eq(0)
|
|
155
|
+
end
|
|
156
156
|
end
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
#------------------------
|
|
159
159
|
it 'GROUP key1=value1 key2=value2 ... should remove multiple key/value pairs' do
|
|
160
160
|
group_name = 'test_group'
|
|
161
161
|
varsarray = [
|
|
162
|
-
{name: 'var1', value:
|
|
163
|
-
{name: 'var2', value:
|
|
162
|
+
{ name: 'var1', value: 'val1' },
|
|
163
|
+
{ name: 'var2', value: 'val2' },
|
|
164
164
|
]
|
|
165
|
-
|
|
165
|
+
|
|
166
166
|
vars = []
|
|
167
167
|
varsarray.each do |var|
|
|
168
168
|
vars << "#{var[:name]}=#{var[:value]}"
|
|
169
169
|
end
|
|
170
|
-
|
|
170
|
+
|
|
171
171
|
@db.models[:group].create(name: group_name)
|
|
172
172
|
actual = runner do
|
|
173
|
-
@app.start(%W(group addvar #{group_name}) + vars
|
|
173
|
+
@app.start(%W(group addvar #{group_name}) + vars)
|
|
174
174
|
end
|
|
175
|
-
|
|
175
|
+
|
|
176
176
|
actual = runner do
|
|
177
|
-
@app.start(%W(group rmvar #{group_name}) + vars
|
|
177
|
+
@app.start(%W(group rmvar #{group_name}) + vars)
|
|
178
178
|
end
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
desired = { aborted: false}
|
|
182
|
-
desired[:STDOUT] =
|
|
179
|
+
# @console.out(actual,'y')
|
|
180
|
+
|
|
181
|
+
desired = { aborted: false }
|
|
182
|
+
desired[:STDOUT] =
|
|
183
183
|
"Remove variable(s) '#{vars.join(',')}' from group '#{group_name}':\n"\
|
|
184
184
|
" - retrieve group '#{group_name}'...\n"\
|
|
185
185
|
" - OK\n"
|
|
186
186
|
vars.each do |var|
|
|
187
|
-
desired[:STDOUT] =
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
188
|
+
" - remove variable '#{var}'...\n"\
|
|
189
|
+
" - OK\n"
|
|
190
190
|
end
|
|
191
|
-
desired[:STDOUT] =
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
192
|
+
" - all OK\n"\
|
|
193
|
+
"Succeeded.\n"
|
|
194
194
|
expected(actual, desired)
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
# We should have the correct hostvar associations
|
|
197
197
|
group = @db.models[:group].find(name: group_name)
|
|
198
198
|
groupvars = group.groupvars_dataset
|
|
199
199
|
expect(groupvars.count).to eq(0)
|
|
200
|
-
end
|
|
200
|
+
end
|
|
201
201
|
end
|
|
202
202
|
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
require_relative 'group_add_spec'
|
|
4
|
-
#require_relative 'group_get_spec'
|
|
5
|
-
#require_relative 'group_list_spec'
|
|
6
|
-
#require_relative 'group_rm_spec'
|
|
4
|
+
# require_relative 'group_get_spec'
|
|
5
|
+
# require_relative 'group_list_spec'
|
|
6
|
+
# require_relative 'group_rm_spec'
|
|
7
7
|
#
|
|
8
|
-
#require_relative 'group_addchild_spec'
|
|
9
|
-
#require_relative 'grpi_rmchild_spec'
|
|
8
|
+
# require_relative 'group_addchild_spec'
|
|
9
|
+
# require_relative 'grpi_rmchild_spec'
|
|
10
10
|
#
|
|
11
|
-
#require_relative 'group_addhost_spec'
|
|
12
|
-
#require_relative 'group_rmhost_spec'
|
|
11
|
+
# require_relative 'group_addhost_spec'
|
|
12
|
+
# require_relative 'group_rmhost_spec'
|
|
13
13
|
#
|
|
14
|
-
#require_relative 'group_addvar_spec'
|
|
15
|
-
#require_relative 'group_rmvar_spec'
|
|
14
|
+
# require_relative 'group_addvar_spec'
|
|
15
|
+
# require_relative 'group_rmvar_spec'
|
|
@@ -9,7 +9,7 @@ RSpec.describe Moose::Inventory::Cli::Host 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 = []
|
|
@@ -44,8 +44,8 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
44
44
|
# --------------------
|
|
45
45
|
it '<no arguments> ... should bail with an error' do
|
|
46
46
|
actual = runner { @app.start(%w(host add)) }
|
|
47
|
-
|
|
48
|
-
desired = { aborted: true}
|
|
47
|
+
|
|
48
|
+
desired = { aborted: true }
|
|
49
49
|
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 1 or more.\n"
|
|
50
50
|
expected(actual, desired)
|
|
51
51
|
end
|
|
@@ -55,8 +55,8 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
55
55
|
name = 'test-host-add'
|
|
56
56
|
|
|
57
57
|
actual = runner { @app.start(%W(host add #{name})) }
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
# @console.out(actual,'y')
|
|
59
|
+
|
|
60
60
|
# Check output
|
|
61
61
|
desired = {}
|
|
62
62
|
desired[:STDOUT] =
|
|
@@ -88,13 +88,13 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
88
88
|
|
|
89
89
|
# Check output
|
|
90
90
|
desired = {}
|
|
91
|
-
desired[:STDOUT] =
|
|
91
|
+
desired[:STDOUT] =
|
|
92
92
|
"Add host '#{name}':\n"\
|
|
93
93
|
" - Creating host '#{name}'...\n"\
|
|
94
94
|
" - OK\n"\
|
|
95
95
|
" - All OK\n"\
|
|
96
96
|
"Succeeded\n"
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
desired[:STDERR] =
|
|
99
99
|
"WARNING: The host '#{name}' already exists, skipping creation.\n"
|
|
100
100
|
|
|
@@ -108,15 +108,15 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
108
108
|
actual = runner { @app.start(%w(host add) + names) }
|
|
109
109
|
|
|
110
110
|
# Check output
|
|
111
|
-
desired = {STDOUT: ''}
|
|
111
|
+
desired = { STDOUT: '' }
|
|
112
112
|
names.each do |name|
|
|
113
|
-
desired[:STDOUT] =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
114
|
+
"Add host '#{name}':\n"\
|
|
115
|
+
" - Creating host '#{name}'...\n"\
|
|
116
|
+
" - OK\n"\
|
|
117
|
+
" - Adding automatic association {host:#{name} <-> group:ungrouped}...\n"\
|
|
118
|
+
" - OK\n"\
|
|
119
|
+
" - All OK\n"
|
|
120
120
|
end
|
|
121
121
|
desired[:STDOUT] = desired[:STDOUT] + "Succeeded\n"
|
|
122
122
|
|
|
@@ -189,7 +189,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
189
189
|
"Succeeded\n"
|
|
190
190
|
desired[:STDERR] =
|
|
191
191
|
"WARNING: The group '#{group_name}' doesn't exist, but will be created.\n"
|
|
192
|
-
|
|
192
|
+
|
|
193
193
|
expected(actual, desired)
|
|
194
194
|
|
|
195
195
|
# Check db
|
|
@@ -200,6 +200,66 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
200
200
|
expect(groups[name: group_name]).not_to be_nil # i.e. not 'ungrouped'
|
|
201
201
|
end
|
|
202
202
|
|
|
203
|
+
# --------------------
|
|
204
|
+
it 'existing HOST --groups NEWGROUP should associate the host with the new group' do
|
|
205
|
+
name = 'testhost'
|
|
206
|
+
initial_group = 'initialgroup'
|
|
207
|
+
new_group = 'newgroup'
|
|
208
|
+
|
|
209
|
+
runner { @app.start(%W(host add #{name} --groups #{initial_group})) }
|
|
210
|
+
actual = runner { @app.start(%W(host add #{name} --groups #{new_group})) }
|
|
211
|
+
|
|
212
|
+
desired = {}
|
|
213
|
+
desired[:STDOUT] =
|
|
214
|
+
"Add host '#{name}':\n"\
|
|
215
|
+
" - Creating host '#{name}'...\n"\
|
|
216
|
+
" - OK\n"\
|
|
217
|
+
" - Adding association {host:#{name} <-> group:#{new_group}}...\n"\
|
|
218
|
+
" - OK\n"\
|
|
219
|
+
" - All OK\n"\
|
|
220
|
+
"Succeeded\n"
|
|
221
|
+
desired[:STDERR] =
|
|
222
|
+
"WARNING: The host '#{name}' already exists, skipping creation.\n"\
|
|
223
|
+
"WARNING: The group '#{new_group}' doesn't exist, but will be created.\n"
|
|
224
|
+
|
|
225
|
+
expected(actual, desired)
|
|
226
|
+
|
|
227
|
+
host = @db.models[:host].find(name: name)
|
|
228
|
+
groups = host.groups_dataset
|
|
229
|
+
expect(groups.count).to eq(2)
|
|
230
|
+
expect(groups[name: initial_group]).not_to be_nil
|
|
231
|
+
expect(groups[name: new_group]).not_to be_nil
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# --------------------
|
|
235
|
+
it 'existing HOST --groups EXISTINGGROUP should skip existing associations' do
|
|
236
|
+
name = 'testhost'
|
|
237
|
+
group_name = 'testgroup'
|
|
238
|
+
|
|
239
|
+
runner { @app.start(%W(host add #{name} --groups #{group_name})) }
|
|
240
|
+
actual = runner { @app.start(%W(host add #{name} --groups #{group_name})) }
|
|
241
|
+
|
|
242
|
+
desired = {}
|
|
243
|
+
desired[:STDOUT] =
|
|
244
|
+
"Add host '#{name}':\n"\
|
|
245
|
+
" - Creating host '#{name}'...\n"\
|
|
246
|
+
" - OK\n"\
|
|
247
|
+
" - Adding association {host:#{name} <-> group:#{group_name}}...\n"\
|
|
248
|
+
" - OK\n"\
|
|
249
|
+
" - All OK\n"\
|
|
250
|
+
"Succeeded\n"
|
|
251
|
+
desired[:STDERR] =
|
|
252
|
+
"WARNING: The host '#{name}' already exists, skipping creation.\n"\
|
|
253
|
+
"WARNING: Association {host:#{name} <-> group:#{group_name}} already exists, skipping creation.\n"
|
|
254
|
+
|
|
255
|
+
expected(actual, desired)
|
|
256
|
+
|
|
257
|
+
host = @db.models[:host].find(name: name)
|
|
258
|
+
groups = host.groups_dataset
|
|
259
|
+
expect(groups.count).to eq(1)
|
|
260
|
+
expect(groups[name: group_name]).not_to be_nil
|
|
261
|
+
end
|
|
262
|
+
|
|
203
263
|
# --------------------
|
|
204
264
|
it 'HOST1 --groups ungrouped ... should abort with an error' do
|
|
205
265
|
name = 'testhost'
|
|
@@ -208,7 +268,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
208
268
|
end
|
|
209
269
|
|
|
210
270
|
# Check output
|
|
211
|
-
desired = { aborted: true}
|
|
271
|
+
desired = { aborted: true }
|
|
212
272
|
desired[:STDERR] =
|
|
213
273
|
"ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
|
|
214
274
|
expected(actual, desired)
|
|
@@ -227,26 +287,26 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
227
287
|
actual = runner do
|
|
228
288
|
@app.start(%W(host add #{name} --groups #{group_names.join(',')}))
|
|
229
289
|
end
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
290
|
+
|
|
291
|
+
# @console.out(actual,'y')
|
|
292
|
+
|
|
233
293
|
# Check output
|
|
234
|
-
desired = {STDOUT: '', STDERR: ''}
|
|
235
|
-
desired[:STDOUT] =
|
|
294
|
+
desired = { STDOUT: '', STDERR: '' }
|
|
295
|
+
desired[:STDOUT] =
|
|
236
296
|
"Add host '#{name}':\n"\
|
|
237
297
|
" - Creating host '#{name}'...\n"\
|
|
238
298
|
" - OK\n"\
|
|
239
|
-
|
|
299
|
+
|
|
240
300
|
group_names.each do |group|
|
|
241
301
|
desired[:STDOUT] = desired[:STDOUT] +
|
|
242
|
-
|
|
243
|
-
|
|
302
|
+
" - Adding association {host:#{name} <-> group:#{group}}...\n"\
|
|
303
|
+
" - OK\n"
|
|
244
304
|
desired[:STDERR] = desired[:STDERR] +
|
|
245
|
-
|
|
305
|
+
"WARNING: The group '#{group}' doesn't exist, but will be created.\n"
|
|
246
306
|
end
|
|
247
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
248
|
-
|
|
249
|
-
|
|
307
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
308
|
+
" - All OK\n"\
|
|
309
|
+
"Succeeded\n"
|
|
250
310
|
|
|
251
311
|
expected(actual, desired)
|
|
252
312
|
|
|
@@ -270,7 +330,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
270
330
|
end
|
|
271
331
|
|
|
272
332
|
# Check output
|
|
273
|
-
desired = { aborted: true}
|
|
333
|
+
desired = { aborted: true }
|
|
274
334
|
desired[:STDERR] =
|
|
275
335
|
"ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
|
|
276
336
|
|
|
@@ -291,27 +351,27 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
291
351
|
# Check output
|
|
292
352
|
desired = { aborted: false, STDERR: '', STDOUT: '' }
|
|
293
353
|
names.each do |name|
|
|
294
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
354
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
355
|
+
"Add host '#{name}':\n"\
|
|
356
|
+
" - Creating host '#{name}'...\n"\
|
|
357
|
+
" - OK\n"
|
|
298
358
|
group_names.each do |group|
|
|
299
|
-
desired[:STDOUT] =
|
|
300
|
-
|
|
301
|
-
|
|
359
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
360
|
+
" - Adding association {host:#{name} <-> group:#{group}}...\n"\
|
|
361
|
+
" - OK\n"
|
|
302
362
|
end
|
|
303
363
|
desired[:STDOUT] = desired[:STDOUT] +
|
|
304
|
-
|
|
364
|
+
" - All OK\n"
|
|
305
365
|
end
|
|
306
|
-
|
|
366
|
+
|
|
307
367
|
group_names.each do |group|
|
|
308
|
-
desired[:STDERR] =
|
|
309
|
-
|
|
368
|
+
desired[:STDERR] = desired[:STDERR] +
|
|
369
|
+
"WARNING: The group '#{group}' doesn't exist, but will be created.\n"
|
|
310
370
|
end
|
|
311
371
|
desired[:STDOUT] = desired[:STDOUT] + "Succeeded\n"
|
|
312
372
|
|
|
313
|
-
|
|
314
|
-
|
|
373
|
+
# @console.out(desired,'y')
|
|
374
|
+
|
|
315
375
|
expected(actual, desired)
|
|
316
376
|
|
|
317
377
|
# Check db
|