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 = []
|
|
@@ -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
|
|
@@ -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
|
|
|
@@ -45,35 +45,34 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
45
45
|
|
|
46
46
|
#------------------------
|
|
47
47
|
it 'addhost <missing args> ... should abort with an error' do
|
|
48
|
-
actual = runner
|
|
48
|
+
actual = runner do
|
|
49
49
|
@app.start(%w(group addhost)) # <- no group given
|
|
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 'GROUP HOST ... should abort if the group does not exist' do
|
|
62
|
-
|
|
63
62
|
host_name = 'example'
|
|
64
63
|
group_name = 'not-a-group'
|
|
65
|
-
|
|
64
|
+
|
|
66
65
|
actual = runner do
|
|
67
66
|
@app.start(%W(group addhost #{group_name} #{host_name}))
|
|
68
67
|
end
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
# @console.out(actual, 'y')
|
|
71
70
|
# Check output
|
|
72
|
-
desired = { aborted: true}
|
|
73
|
-
desired[:STDOUT] =
|
|
71
|
+
desired = { aborted: true }
|
|
72
|
+
desired[:STDOUT] =
|
|
74
73
|
"Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
|
|
75
74
|
" - retrieve group '#{group_name}'...\n"
|
|
76
|
-
desired[:STDERR] =
|
|
75
|
+
desired[:STDERR] =
|
|
77
76
|
"ERROR: The group '#{group_name}' does not exist.\n"\
|
|
78
77
|
"An error occurred during a transaction, any changes have been rolled back.\n"
|
|
79
78
|
expected(actual, desired)
|
|
@@ -83,18 +82,18 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
83
82
|
it 'GROUP HOST... should add the host to an existing group' do
|
|
84
83
|
# 1. Should add the host to the group
|
|
85
84
|
# 2. Should remove the host from the 'ungrouped' automatic group
|
|
86
|
-
|
|
85
|
+
|
|
87
86
|
host_name = 'test1'
|
|
88
87
|
group_name = 'testgroup1'
|
|
89
88
|
|
|
90
89
|
runner { @app.start(%W(host add #{host_name})) }
|
|
91
90
|
@db.models[:group].create(name: group_name)
|
|
92
91
|
|
|
93
|
-
actual = runner { @app.start(%W(group addhost #{group_name} #{host_name}
|
|
92
|
+
actual = runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
|
|
94
93
|
|
|
95
94
|
# rubocop:disable Metrics/LineLength
|
|
96
|
-
desired = { aborted: false}
|
|
97
|
-
desired[:STDOUT] =
|
|
95
|
+
desired = { aborted: false }
|
|
96
|
+
desired[:STDOUT] =
|
|
98
97
|
"Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
|
|
99
98
|
" - retrieve group '#{group_name}'...\n"\
|
|
100
99
|
" - OK\n"\
|
|
@@ -109,28 +108,27 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
109
108
|
|
|
110
109
|
# We should have the correct group associations
|
|
111
110
|
host = @db.models[:host].find(name: host_name)
|
|
112
|
-
groups = host.groups_dataset
|
|
111
|
+
groups = host.groups_dataset
|
|
113
112
|
expect(groups.count).to eq(1)
|
|
114
113
|
expect(groups[name: group_name]).not_to be_nil
|
|
115
|
-
expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
|
|
114
|
+
expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
|
|
116
115
|
end
|
|
117
116
|
|
|
118
117
|
#------------------------
|
|
119
118
|
it '\'ungrouped\' HOST... should abort with an error' do
|
|
120
|
-
|
|
121
119
|
host_name = 'test1'
|
|
122
120
|
group_name = 'ungrouped'
|
|
123
|
-
|
|
121
|
+
|
|
124
122
|
runner { @app.start(%W(host add #{host_name})) }
|
|
125
|
-
|
|
126
|
-
actual = runner { @app.start(%W(group addhost #{group_name} #{host_name}
|
|
127
|
-
|
|
128
|
-
desired = { aborted: true}
|
|
129
|
-
desired[:STDERR] =
|
|
123
|
+
|
|
124
|
+
actual = runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
|
|
125
|
+
|
|
126
|
+
desired = { aborted: true }
|
|
127
|
+
desired[:STDERR] =
|
|
130
128
|
"ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
|
|
131
129
|
expected(actual, desired)
|
|
132
|
-
end
|
|
133
|
-
|
|
130
|
+
end
|
|
131
|
+
|
|
134
132
|
#------------------------
|
|
135
133
|
it 'GROUP HOST ... should add the host to an group, creating the host if necessary' do
|
|
136
134
|
host_name = 'test1'
|
|
@@ -140,11 +138,11 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
140
138
|
|
|
141
139
|
# DON'T CREATE THE HOST! That's the point of the test. ;o)
|
|
142
140
|
|
|
143
|
-
actual = runner { @app.start(%W(group addhost #{group_name} #{host_name}
|
|
141
|
+
actual = runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
|
|
144
142
|
|
|
145
143
|
# Check output
|
|
146
144
|
desired = {}
|
|
147
|
-
desired[:STDOUT] =
|
|
145
|
+
desired[:STDOUT] =
|
|
148
146
|
"Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
|
|
149
147
|
" - retrieve group '#{group_name}'...\n"\
|
|
150
148
|
" - OK\n"\
|
|
@@ -155,54 +153,54 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
155
153
|
" - all OK\n"\
|
|
156
154
|
"Succeeded, with warnings.\n"
|
|
157
155
|
desired[:STDERR] =
|
|
158
|
-
"WARNING: Host '#{host_name}' does not exist and will be created.\n"
|
|
156
|
+
"WARNING: Host '#{host_name}' does not exist and will be created.\n"
|
|
159
157
|
expected(actual, desired)
|
|
160
158
|
|
|
161
|
-
# Check db
|
|
159
|
+
# Check db
|
|
162
160
|
group = @db.models[:group].find(name: group_name)
|
|
163
161
|
hosts = group.hosts_dataset
|
|
164
162
|
expect(hosts.count).to eq(1)
|
|
165
163
|
expect(hosts[name: host_name]).not_to be_nil
|
|
166
164
|
end
|
|
167
|
-
|
|
165
|
+
|
|
168
166
|
#------------------------
|
|
169
167
|
it 'GROUP HOST... should skip associations that already '\
|
|
170
168
|
' exist, but raise a warning.' do
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
169
|
+
host_name = 'test1'
|
|
170
|
+
group_name = 'testgroup1'
|
|
171
|
+
|
|
172
|
+
runner { @app.start(%W(group add #{group_name})) }
|
|
173
|
+
runner { @app.start(%W(host add #{host_name})) }
|
|
174
|
+
|
|
175
|
+
# Run once to make the initial association
|
|
176
|
+
runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
|
|
177
|
+
|
|
178
|
+
# Run again, to prove expected result
|
|
179
|
+
actual = runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
|
|
180
|
+
|
|
181
|
+
# @console.out(actual,'y')
|
|
182
|
+
|
|
183
|
+
# Check output
|
|
184
|
+
desired = {}
|
|
185
|
+
desired[:STDOUT] =
|
|
186
|
+
"Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
|
|
187
|
+
" - retrieve group \'#{group_name}\'...\n"\
|
|
188
|
+
" - OK\n"\
|
|
189
|
+
" - add association {group:#{group_name} <-> host:#{host_name}}...\n"\
|
|
190
|
+
" - already exists, skipping.\n"\
|
|
191
|
+
" - OK\n"\
|
|
192
|
+
" - all OK\n"\
|
|
193
|
+
"Succeeded, with warnings.\n"
|
|
194
|
+
desired[:STDERR] =
|
|
195
|
+
"WARNING: Association {group:#{group_name} <-> host:#{host_name}} already exists, skipping.\n"
|
|
196
|
+
expected(actual, desired)
|
|
197
|
+
|
|
198
|
+
# Check db
|
|
199
|
+
group = @db.models[:group].find(name: group_name)
|
|
200
|
+
hosts = group.hosts_dataset
|
|
201
|
+
expect(hosts.count).to eq(1)
|
|
202
|
+
expect(hosts[name: host_name]).not_to be_nil
|
|
203
|
+
end
|
|
206
204
|
|
|
207
205
|
#------------------------
|
|
208
206
|
it 'GROUP HOST1 HOST2 ... should associate the group with '\
|
|
@@ -214,32 +212,31 @@ RSpec.describe Moose::Inventory::Cli::Group do
|
|
|
214
212
|
host_names.each do |host|
|
|
215
213
|
runner { @app.start(%W(host add #{host})) }
|
|
216
214
|
end
|
|
217
|
-
|
|
215
|
+
|
|
218
216
|
actual = runner { @app.start(%W(group addhost #{group_name}) + host_names) }
|
|
219
217
|
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
# @console.out(actual, 'y')
|
|
219
|
+
|
|
222
220
|
# Check output
|
|
223
|
-
desired = { aborted: false, STDERR: ''}
|
|
221
|
+
desired = { aborted: false, STDERR: '' }
|
|
224
222
|
desired[:STDOUT] =
|
|
225
223
|
"Associate group '#{group_name}' with host(s) '#{host_names.join(',')}':\n"\
|
|
226
224
|
" - retrieve group '#{group_name}'...\n"\
|
|
227
225
|
" - OK\n"
|
|
228
226
|
host_names.each do |host|
|
|
229
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
#desired[:STDERR] = desired[:STDERR] +
|
|
236
|
-
# "WARNING: Host '#{host}' does not exist and will be created.\n"
|
|
227
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
228
|
+
" - add association {group:#{group_name} <-> host:#{host}}...\n"\
|
|
229
|
+
" - OK\n"\
|
|
230
|
+
" - remove automatic association {group:ungrouped <-> host:#{host}}...\n"\
|
|
231
|
+
" - OK\n"\
|
|
232
|
+
|
|
233
|
+
# desired[:STDERR] = desired[:STDERR] +
|
|
234
|
+
# "WARNING: Host '#{host}' does not exist and will be created.\n"
|
|
237
235
|
end
|
|
238
|
-
desired[:STDOUT]
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
237
|
+
" - all OK\n"\
|
|
238
|
+
"Succeeded.\n"
|
|
241
239
|
expected(actual, desired)
|
|
242
|
-
|
|
243
240
|
|
|
244
241
|
# We should have group associations
|
|
245
242
|
group = @db.models[:group].find(name: group_name)
|