moose-inventory 1.0.7 → 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.
Files changed (81) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +35 -0
  3. data/.gitignore +1 -1
  4. data/BACKLOG.md +184 -0
  5. data/Gemfile.lock +60 -0
  6. data/README.md +23 -5
  7. data/bin/moose-inventory +1 -1
  8. data/docs/release/publishing.md +113 -0
  9. data/docs/release/release-readiness.md +41 -0
  10. data/docs/security-audit-2026-05-21.md +71 -0
  11. data/lib/moose_inventory/cli/formatter.rb +16 -17
  12. data/lib/moose_inventory/cli/group.rb +1 -1
  13. data/lib/moose_inventory/cli/group_add.rb +19 -21
  14. data/lib/moose_inventory/cli/group_addchild.rb +36 -40
  15. data/lib/moose_inventory/cli/group_addhost.rb +14 -18
  16. data/lib/moose_inventory/cli/group_addvar.rb +37 -37
  17. data/lib/moose_inventory/cli/group_get.rb +23 -26
  18. data/lib/moose_inventory/cli/group_list.rb +12 -15
  19. data/lib/moose_inventory/cli/group_listvars.rb +12 -14
  20. data/lib/moose_inventory/cli/group_rm.rb +36 -21
  21. data/lib/moose_inventory/cli/group_rmchild.rb +5 -6
  22. data/lib/moose_inventory/cli/group_rmhost.rb +12 -16
  23. data/lib/moose_inventory/cli/group_rmvar.rb +5 -5
  24. data/lib/moose_inventory/cli/host.rb +1 -1
  25. data/lib/moose_inventory/cli/host_add.rb +18 -18
  26. data/lib/moose_inventory/cli/host_addgroup.rb +9 -9
  27. data/lib/moose_inventory/cli/host_addvar.rb +6 -6
  28. data/lib/moose_inventory/cli/host_get.rb +15 -18
  29. data/lib/moose_inventory/cli/host_list.rb +3 -3
  30. data/lib/moose_inventory/cli/host_listvars.rb +21 -23
  31. data/lib/moose_inventory/cli/host_rm.rb +9 -9
  32. data/lib/moose_inventory/cli/host_rmgroup.rb +5 -5
  33. data/lib/moose_inventory/cli/host_rmvar.rb +3 -3
  34. data/lib/moose_inventory/config/config.rb +43 -40
  35. data/lib/moose_inventory/db/db.rb +70 -50
  36. data/lib/moose_inventory/db/models.rb +11 -12
  37. data/lib/moose_inventory/version.rb +1 -1
  38. data/moose-inventory.gemspec +35 -20
  39. data/scripts/check.sh +8 -0
  40. data/scripts/ci/check_permissions.sh +32 -0
  41. data/scripts/ci/check_security.sh +50 -0
  42. data/scripts/ci/package_sanity.sh +46 -0
  43. data/scripts/files.rb +1 -4
  44. data/scripts/install_dependencies.sh +17 -0
  45. data/scripts/reports.sh +2 -2
  46. data/spec/lib/moose_inventory/cli/cli_spec.rb +13 -14
  47. data/spec/lib/moose_inventory/cli/group_add_spec.rb +118 -119
  48. data/spec/lib/moose_inventory/cli/group_addchild_spec.rb +49 -51
  49. data/spec/lib/moose_inventory/cli/group_addhost_spec.rb +80 -83
  50. data/spec/lib/moose_inventory/cli/group_addvar_spec.rb +91 -91
  51. data/spec/lib/moose_inventory/cli/group_get_spec.rb +22 -23
  52. data/spec/lib/moose_inventory/cli/group_list_spec.rb +19 -20
  53. data/spec/lib/moose_inventory/cli/group_listvar_spec.rb +35 -36
  54. data/spec/lib/moose_inventory/cli/group_rm_spec.rb +103 -49
  55. data/spec/lib/moose_inventory/cli/group_rmchild_spec.rb +41 -45
  56. data/spec/lib/moose_inventory/cli/group_rmhost_spec.rb +43 -46
  57. data/spec/lib/moose_inventory/cli/group_rmvar_spec.rb +131 -131
  58. data/spec/lib/moose_inventory/cli/group_spec.rb +9 -9
  59. data/spec/lib/moose_inventory/cli/host_add_spec.rb +103 -43
  60. data/spec/lib/moose_inventory/cli/host_addgroup_spec.rb +78 -80
  61. data/spec/lib/moose_inventory/cli/host_addvar_spec.rb +122 -122
  62. data/spec/lib/moose_inventory/cli/host_get_spec.rb +16 -16
  63. data/spec/lib/moose_inventory/cli/host_list_spec.rb +8 -8
  64. data/spec/lib/moose_inventory/cli/host_listvar_spec.rb +50 -52
  65. data/spec/lib/moose_inventory/cli/host_rm_spec.rb +12 -12
  66. data/spec/lib/moose_inventory/cli/host_rmgroup_spec.rb +48 -51
  67. data/spec/lib/moose_inventory/cli/host_rmvar_spec.rb +136 -136
  68. data/spec/lib/moose_inventory/config/config_spec.rb +16 -3
  69. data/spec/lib/moose_inventory/db/db_spec.rb +224 -2
  70. data/spec/lib/moose_inventory/db/models_spec.rb +10 -11
  71. data/spec/shared/shared_config_setup.rb +2 -2
  72. data/spec/spec_helper.rb +7 -8
  73. metadata +99 -136
  74. data/.coveralls.yml +0 -0
  75. data/.rubocop.yml +0 -793
  76. data/Guardfile +0 -38
  77. data/config/dotfiles/coveralls.yml +0 -0
  78. data/config/dotfiles/gitignore +0 -20
  79. data/config/dotfiles/rubocop.yml +0 -793
  80. data/scripts/guard_quality.sh +0 -3
  81. data/scripts/guard_test.sh +0 -2
@@ -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 = []
@@ -42,12 +42,12 @@ RSpec.describe Moose::Inventory::Cli::Host do
42
42
 
43
43
  #------------------------
44
44
  it 'host addgroup <missing args> ... should abort with an error' do
45
- actual = runner do
45
+ actual = runner do
46
46
  @app.start(%w(host addgroup)) # <- no group given
47
47
  end
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 2 or more.\n"
52
52
  expected(actual, desired)
53
53
  end
@@ -59,11 +59,11 @@ RSpec.describe Moose::Inventory::Cli::Host do
59
59
  end
60
60
 
61
61
  # Check output
62
- desired = { aborted: true}
63
- desired[:STDOUT] =
62
+ desired = { aborted: true }
63
+ desired[:STDOUT] =
64
64
  "Associate host 'not-a-host' with groups 'example':\n"\
65
65
  " - Retrieve host 'not-a-host'...\n"
66
- desired[:STDERR] =
66
+ desired[:STDERR] =
67
67
  "An error occurred during a transaction, any changes have been rolled back.\n"\
68
68
  "ERROR: The host 'not-a-host' was not found in the database.\n"
69
69
  expected(actual, desired)
@@ -73,18 +73,18 @@ RSpec.describe Moose::Inventory::Cli::Host do
73
73
  it 'host addgroup HOST GROUP ... should add the host to an existing group' do
74
74
  # 1. Should add the host to the group
75
75
  # 2. Should remove the host from the 'ungrouped' automatic group
76
-
76
+
77
77
  name = 'test1'
78
78
  group_name = 'testgroup1'
79
79
 
80
80
  runner { @app.start(%W(host add #{name})) }
81
81
  @db.models[:group].create(name: group_name)
82
82
 
83
- actual = runner { @app.start(%W(host addgroup #{name} #{group_name} )) }
83
+ actual = runner { @app.start(%W(host addgroup #{name} #{group_name})) }
84
84
 
85
85
  # rubocop:disable Metrics/LineLength
86
- desired = { aborted: false}
87
- desired[:STDOUT] =
86
+ desired = { aborted: false }
87
+ desired[:STDOUT] =
88
88
  "Associate host '#{name}' with groups '#{group_name}':\n"\
89
89
  " - Retrieve host '#{name}'...\n"\
90
90
  " - OK\n"\
@@ -102,25 +102,24 @@ RSpec.describe Moose::Inventory::Cli::Host do
102
102
  groups = host.groups_dataset
103
103
  expect(groups.count).to eq(1)
104
104
  expect(groups[name: group_name]).not_to be_nil
105
- expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
105
+ expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
106
106
  end
107
107
 
108
108
  #------------------------
109
109
  it 'HOST \'ungrouped\' ... should abort with an error' do
110
-
111
110
  name = 'test1'
112
111
  group_name = 'ungrouped'
113
-
112
+
114
113
  runner { @app.start(%W(host add #{name})) }
115
-
116
- actual = runner { @app.start(%W(host addgroup #{name} #{group_name} )) }
117
-
118
- desired = { aborted: true}
119
- desired[:STDERR] =
114
+
115
+ actual = runner { @app.start(%W(host addgroup #{name} #{group_name})) }
116
+
117
+ desired = { aborted: true }
118
+ desired[:STDERR] =
120
119
  "ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
121
120
  expected(actual, desired)
122
- end
123
-
121
+ end
122
+
124
123
  #------------------------
125
124
  it 'HOST GROUP ... should add the host to an group, creating the group if necessary' do
126
125
  name = 'test1'
@@ -130,11 +129,11 @@ RSpec.describe Moose::Inventory::Cli::Host do
130
129
 
131
130
  # DON'T CREATE THE GROUP! That's the point of the test. ;o)
132
131
 
133
- actual = runner { @app.start(%W(host addgroup #{name} #{group_name} )) }
132
+ actual = runner { @app.start(%W(host addgroup #{name} #{group_name})) }
134
133
 
135
134
  # Check output
136
- desired = { aborted: false}
137
- desired[:STDOUT] =
135
+ desired = { aborted: false }
136
+ desired[:STDOUT] =
138
137
  "Associate host '#{name}' with groups '#{group_name}':\n"\
139
138
  " - Retrieve host '#{name}'...\n"\
140
139
  " - OK\n"\
@@ -147,56 +146,56 @@ RSpec.describe Moose::Inventory::Cli::Host do
147
146
  " - All OK\n"\
148
147
  "Succeeded\n"
149
148
  desired[:STDERR] =
150
- "WARNING: Group '#{group_name}' does not exist and will be created."
149
+ "WARNING: Group '#{group_name}' does not exist and will be created."
151
150
  expected(actual, desired)
152
151
 
153
- # Check db
152
+ # Check db
154
153
  host = @db.models[:host].find(name: name)
155
154
  groups = host.groups_dataset
156
155
  expect(groups.count).to eq(1)
157
156
  expect(groups[name: group_name]).not_to be_nil
158
- expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
157
+ expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
159
158
  end
160
-
159
+
161
160
  #------------------------
162
- it 'HOST GROUP ... should skip associations that already '\
163
- ' exist, but raise a warning.' do
164
- name = 'test1'
165
- group_name = 'testgroup1'
166
-
167
- runner { @app.start(%W(host add #{name})) }
168
-
169
- # DON'T CREATE THE GROUP! That's the point of the test. ;o)
170
-
171
- # Run once to make the association
172
- runner { @app.start(%W(host addgroup #{name} #{group_name} )) }
173
-
174
- # Run again, to prove expected result
175
- actual = runner { @app.start(%W(host addgroup #{name} #{group_name} )) }
176
-
177
- # Check output
178
- # Note: This time, we don't expect to see any messages about
179
- # dissociation from 'ungrouped'
180
- desired = { aborted: false}
181
- desired[:STDOUT] =
182
- "Associate host '#{name}' with groups '#{group_name}':\n"\
183
- " - Retrieve host \'#{name}\'...\n"\
184
- " - OK\n"\
185
- " - Add association {host:#{name} <-> group:#{group_name}}...\n"\
186
- " - Already exists, skipping.\n"\
187
- " - OK\n"\
188
- " - All OK\n"\
189
- "Succeeded\n"
190
- desired[:STDERR] = "WARNING: Association {host:#{name} <-> group:#{group_name}} already exists, skipping."
191
- expected(actual, desired)
192
-
193
- # Check db
194
- host = @db.models[:host].find(name: name)
195
- groups = host.groups_dataset
196
- expect(groups.count).to eq(1)
197
- expect(groups[name: group_name]).not_to be_nil
198
- expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
199
- end
161
+ it 'HOST GROUP ... should skip associations that already '\
162
+ ' exist, but raise a warning.' do
163
+ name = 'test1'
164
+ group_name = 'testgroup1'
165
+
166
+ runner { @app.start(%W(host add #{name})) }
167
+
168
+ # DON'T CREATE THE GROUP! That's the point of the test. ;o)
169
+
170
+ # Run once to make the association
171
+ runner { @app.start(%W(host addgroup #{name} #{group_name})) }
172
+
173
+ # Run again, to prove expected result
174
+ actual = runner { @app.start(%W(host addgroup #{name} #{group_name})) }
175
+
176
+ # Check output
177
+ # Note: This time, we don't expect to see any messages about
178
+ # dissociation from 'ungrouped'
179
+ desired = { aborted: false }
180
+ desired[:STDOUT] =
181
+ "Associate host '#{name}' with groups '#{group_name}':\n"\
182
+ " - Retrieve host \'#{name}\'...\n"\
183
+ " - OK\n"\
184
+ " - Add association {host:#{name} <-> group:#{group_name}}...\n"\
185
+ " - Already exists, skipping.\n"\
186
+ " - OK\n"\
187
+ " - All OK\n"\
188
+ "Succeeded\n"
189
+ desired[:STDERR] = "WARNING: Association {host:#{name} <-> group:#{group_name}} already exists, skipping."
190
+ expected(actual, desired)
191
+
192
+ # Check db
193
+ host = @db.models[:host].find(name: name)
194
+ groups = host.groups_dataset
195
+ expect(groups.count).to eq(1)
196
+ expect(groups[name: group_name]).not_to be_nil
197
+ expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
198
+ end
200
199
 
201
200
  #------------------------
202
201
  it 'host addgroup GROUP1 GROUP1 ... should add the host to'\
@@ -209,28 +208,27 @@ RSpec.describe Moose::Inventory::Cli::Host do
209
208
  actual = runner { @app.start(%W(host addgroup #{name}) + group_names) }
210
209
 
211
210
  # Check output
212
- desired = { aborted: false, STDERR: ''}
211
+ desired = { aborted: false, STDERR: '' }
213
212
  desired[:STDOUT] =
214
213
  "Associate host '#{name}' with groups '#{group_names.join(',')}':\n"\
215
214
  " - Retrieve host '#{name}'...\n"\
216
215
  " - OK\n"
217
216
  group_names.each do |group|
218
- desired[:STDOUT] = desired[:STDOUT] +
219
- " - Add association {host:#{name} <-> group:#{group}}...\n"\
220
- " - Group does not exist, creating now...\n"\
221
- " - OK\n"\
222
- " - OK\n"
223
-
224
- desired[:STDERR] = desired[:STDERR] +
225
- "WARNING: Group '#{group}' does not exist and will be created."
217
+ desired[:STDOUT] = desired[:STDOUT] +
218
+ " - Add association {host:#{name} <-> group:#{group}}...\n"\
219
+ " - Group does not exist, creating now...\n"\
220
+ " - OK\n"\
221
+ " - OK\n"
222
+
223
+ desired[:STDERR] = desired[:STDERR] +
224
+ "WARNING: Group '#{group}' does not exist and will be created."
226
225
  end
227
- desired[:STDOUT] = desired[:STDOUT] +
228
- " - Remove automatic association {host:#{name} <-> group:ungrouped}...\n"\
229
- " - OK\n"\
230
- " - All OK\n"\
231
- "Succeeded\n"
226
+ desired[:STDOUT] = desired[:STDOUT] +
227
+ " - Remove automatic association {host:#{name} <-> group:ungrouped}...\n"\
228
+ " - OK\n"\
229
+ " - All OK\n"\
230
+ "Succeeded\n"
232
231
  expected(actual, desired)
233
-
234
232
 
235
233
  # We should have group associations
236
234
  host = @db.models[:host].find(name: name)
@@ -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 = []
@@ -40,95 +40,95 @@ RSpec.describe Moose::Inventory::Cli::Host do
40
40
  result = @host.instance_methods(false).include?(:addvar)
41
41
  expect(result).to eq(true)
42
42
  end
43
-
43
+
44
44
  #-----------------
45
45
  it 'host addvar <missing args> ... should abort with an error' do
46
- actual = runner do
46
+ actual = runner do
47
47
  @app.start(%w(host addvar)) # <- no group given
48
48
  end
49
49
 
50
50
  # Check output
51
- desired = { aborted: true}
51
+ desired = { aborted: true }
52
52
  desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 2 or more.\n"
53
53
  expected(actual, desired)
54
54
  end
55
55
 
56
56
  #------------------------
57
57
  it 'host addvar HOST key=value ... should abort if the host does not exist' do
58
- host_name ='not-a-host'
59
- host_var = "foo=bar"
60
-
58
+ host_name = 'not-a-host'
59
+ host_var = 'foo=bar'
60
+
61
61
  actual = runner do
62
62
  @app.start(%W(host addvar #{host_name} #{host_var}))
63
63
  end
64
64
 
65
65
  # Check output
66
- desired = { aborted: true}
67
- desired[:STDOUT] =
66
+ desired = { aborted: true }
67
+ desired[:STDOUT] =
68
68
  "Add variables '#{host_var}' to host '#{host_name}':\n"\
69
69
  " - retrieve host '#{host_name}'...\n"
70
- desired[:STDERR] =
70
+ desired[:STDERR] =
71
71
  "An error occurred during a transaction, any changes have been rolled back.\n"\
72
72
  "ERROR: The host '#{host_name}' does not exist.\n"
73
73
  expected(actual, desired)
74
74
  end
75
75
 
76
76
  #------------------------
77
- it 'host addvar HOST <malformed> ... should abort with an error' do
78
- # 1. Should add the var to the db
79
- # 2. Should associate the host with the var
80
-
81
- host_name = 'test1'
82
- @db.models[:host].create(name: host_name)
83
-
84
- var = {name: 'var1', value: "testval"}
85
- cases = %W(
86
- testvar
87
- testvar=
88
- =testval
89
- testvar=testval=
90
- =testvar=testval
91
- testvar=testval=extra
92
- )
93
-
94
- cases.each do |args|
95
- actual = runner do
96
- @app.start(%W(host addvar #{host_name} #{args} ))
97
- end
98
- #@console.out(actual,'p')
99
-
100
- desired = { aborted: true}
101
- desired[:STDOUT] =
102
- "Add variables '#{args}' to host '#{host_name}':\n"\
103
- " - retrieve host '#{host_name}'...\n"\
104
- " - OK\n"\
105
- " - add variable '#{args}'...\n"
106
-
107
- desired[:STDERR] =
108
- "An error occurred during a transaction, any changes have been rolled back.\n"\
109
- "ERROR: Incorrect format in '{#{args}}'. Expected 'key=value'.\n"
110
-
111
- expected(actual, desired)
112
- end
113
- end
114
-
77
+ it 'host addvar HOST <malformed> ... should abort with an error' do
78
+ # 1. Should add the var to the db
79
+ # 2. Should associate the host with the var
80
+
81
+ host_name = 'test1'
82
+ @db.models[:host].create(name: host_name)
83
+
84
+ var = { name: 'var1', value: 'testval' }
85
+ cases = %w(
86
+ testvar
87
+ testvar=
88
+ =testval
89
+ testvar=testval=
90
+ =testvar=testval
91
+ testvar=testval=extra
92
+ )
93
+
94
+ cases.each do |args|
95
+ actual = runner do
96
+ @app.start(%W(host addvar #{host_name} #{args}))
97
+ end
98
+ # @console.out(actual,'p')
99
+
100
+ desired = { aborted: true }
101
+ desired[:STDOUT] =
102
+ "Add variables '#{args}' to host '#{host_name}':\n"\
103
+ " - retrieve host '#{host_name}'...\n"\
104
+ " - OK\n"\
105
+ " - add variable '#{args}'...\n"
106
+
107
+ desired[:STDERR] =
108
+ "An error occurred during a transaction, any changes have been rolled back.\n"\
109
+ "ERROR: Incorrect format in '{#{args}}'. Expected 'key=value'.\n"
110
+
111
+ expected(actual, desired)
112
+ end
113
+ end
114
+
115
115
  #------------------------
116
116
  fit 'host addvar HOST key=value ... should associate the host with the key/value pair' do
117
117
  # 1. Should add the var to the db
118
118
  # 2. Should associate the host with the var
119
-
119
+
120
120
  host_name = 'test1'
121
- var = {name: 'var1', value: "testval"}
121
+ var = { name: 'var1', value: 'testval' }
122
122
 
123
123
  @db.models[:host].create(name: host_name)
124
-
124
+
125
125
  actual = runner do
126
- @app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]} ))
126
+ @app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]}))
127
127
  end
128
- #@console.out(actual,'p')
129
-
130
- desired = { aborted: false}
131
- desired[:STDOUT] =
128
+ # @console.out(actual,'p')
129
+
130
+ desired = { aborted: false }
131
+ desired[:STDOUT] =
132
132
  "Add variables '#{var[:name]}=#{var[:value]}' to host '#{host_name}':\n"\
133
133
  " - retrieve host '#{host_name}'...\n"\
134
134
  " - OK\n"\
@@ -150,19 +150,19 @@ RSpec.describe Moose::Inventory::Cli::Host do
150
150
  fit 'host addvar HOST "my val"="hello world" ... should associate the host with the key/value pair' do
151
151
  # 1. Should add the var to the db
152
152
  # 2. Should associate the host with the var
153
-
153
+
154
154
  host_name = 'test1'
155
- var = {name: 'my val', value: "hello world"}
156
-
155
+ var = { name: 'my val', value: 'hello world' }
156
+
157
157
  @db.models[:host].create(name: host_name)
158
-
158
+
159
159
  actual = runner do
160
- @app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]} ))
160
+ @app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]}))
161
161
  end
162
- #@console.out(actual,'p')
163
-
164
- desired = { aborted: false}
165
- desired[:STDOUT] =
162
+ # @console.out(actual,'p')
163
+
164
+ desired = { aborted: false }
165
+ desired[:STDOUT] =
166
166
  "Add variables '#{var[:name]}=#{var[:value]}' to host '#{host_name}':\n"\
167
167
  " - retrieve host '#{host_name}'...\n"\
168
168
  " - OK\n"\
@@ -171,7 +171,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
171
171
  " - all OK\n"\
172
172
  "Succeeded.\n"
173
173
  expected(actual, desired)
174
-
174
+
175
175
  # We should have the correct hostvar associations
176
176
  host = @db.models[:host].find(name: host_name)
177
177
  hostvars = host.hostvars_dataset
@@ -179,70 +179,70 @@ RSpec.describe Moose::Inventory::Cli::Host do
179
179
  expect(hostvars[name: var[:name]]).not_to be_nil
180
180
  expect(hostvars[name: var[:name]][:value]).to eq(var[:value])
181
181
  end
182
-
183
- #------------------------
184
- it 'host addvar HOST key1=value1 key2=value2 ... should associate the host with multiple key/value pairs' do
185
- # 1. Should add the var to the db
186
- # 2. Should associate the host with the var
187
-
188
- host_name = 'test1'
189
- varsarray = [
190
- {name: 'var1', value: "val1"},
191
- {name: 'var2', value: "val2"}
192
- ]
193
-
194
- vars = []
195
- varsarray.each do |var|
196
- vars << "#{var[:name]}=#{var[:value]}"
197
- end
198
-
199
- @db.models[:host].create(name: host_name)
200
-
201
- actual = runner do
202
- @app.start(%W(host addvar #{host_name}) + vars )
203
- end
204
- #@console.out(actual,'p')
205
-
206
- desired = { aborted: false}
207
- desired[:STDOUT] =
208
- "Add variables '#{vars.join(',')}' to host '#{host_name}':\n"\
209
- " - retrieve host '#{host_name}'...\n"\
210
- " - OK\n"
211
- vars.each do |var|
212
- desired[:STDOUT] = desired[:STDOUT] +
213
- " - add variable '#{var}'...\n"\
182
+
183
+ #------------------------
184
+ it 'host addvar HOST key1=value1 key2=value2 ... should associate the host with multiple key/value pairs' do
185
+ # 1. Should add the var to the db
186
+ # 2. Should associate the host with the var
187
+
188
+ host_name = 'test1'
189
+ varsarray = [
190
+ { name: 'var1', value: 'val1' },
191
+ { name: 'var2', value: 'val2' },
192
+ ]
193
+
194
+ vars = []
195
+ varsarray.each do |var|
196
+ vars << "#{var[:name]}=#{var[:value]}"
197
+ end
198
+
199
+ @db.models[:host].create(name: host_name)
200
+
201
+ actual = runner do
202
+ @app.start(%W(host addvar #{host_name}) + vars)
203
+ end
204
+ # @console.out(actual,'p')
205
+
206
+ desired = { aborted: false }
207
+ desired[:STDOUT] =
208
+ "Add variables '#{vars.join(',')}' to host '#{host_name}':\n"\
209
+ " - retrieve host '#{host_name}'...\n"\
214
210
  " - OK\n"
211
+ vars.each do |var|
212
+ desired[:STDOUT] = desired[:STDOUT] +
213
+ " - add variable '#{var}'...\n"\
214
+ " - OK\n"
215
+ end
216
+ desired[:STDOUT] = desired[:STDOUT] +
217
+ " - all OK\n"\
218
+ "Succeeded.\n"
219
+ expected(actual, desired)
220
+
221
+ # We should have the correct hostvar associations
222
+ host = @db.models[:host].find(name: host_name)
223
+ hostvars = host.hostvars_dataset
224
+ expect(hostvars.count).to eq(vars.length)
215
225
  end
216
- desired[:STDOUT] = desired[:STDOUT] +
217
- " - all OK\n"\
218
- "Succeeded.\n"
219
- expected(actual, desired)
220
-
221
- # We should have the correct hostvar associations
222
- host = @db.models[:host].find(name: host_name)
223
- hostvars = host.hostvars_dataset
224
- expect(hostvars.count).to eq(vars.length)
225
- end
226
226
 
227
227
  #------------------------
228
228
  it 'host addvar HOST key=value ... should update an already existing association' do
229
229
  # 1. Should add the var to the db
230
230
  # 2. Should associate the host with the var
231
-
231
+
232
232
  host_name = 'test1'
233
- var = {name: 'var1', value: "testval"}
234
-
233
+ var = { name: 'var1', value: 'testval' }
234
+
235
235
  @db.models[:host].create(name: host_name)
236
- runner { @app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]} )) }
237
-
238
- var[:value] = "newtestval"
236
+ runner { @app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]})) }
237
+
238
+ var[:value] = 'newtestval'
239
239
  actual = runner do
240
- @app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]} ))
240
+ @app.start(%W(host addvar #{host_name} #{var[:name]}=#{var[:value]}))
241
241
  end
242
- #@console.out(actual,'p')
243
-
244
- desired = { aborted: false}
245
- desired[:STDOUT] =
242
+ # @console.out(actual,'p')
243
+
244
+ desired = { aborted: false }
245
+ desired[:STDOUT] =
246
246
  "Add variables '#{var[:name]}=#{var[:value]}' to host '#{host_name}':\n"\
247
247
  " - retrieve host '#{host_name}'...\n"\
248
248
  " - OK\n"\
@@ -252,16 +252,16 @@ RSpec.describe Moose::Inventory::Cli::Host do
252
252
  " - all OK\n"\
253
253
  "Succeeded.\n"
254
254
  expected(actual, desired)
255
-
255
+
256
256
  # We should have the correct hostvar associations
257
257
  host = @db.models[:host].find(name: host_name)
258
258
  hostvars = host.hostvars_dataset
259
259
  expect(hostvars.count).to eq(1)
260
260
  expect(hostvars[name: var[:name]]).not_to be_nil
261
261
  expect(hostvars[name: var[:name]][:value]).to eq(var[:value])
262
-
262
+
263
263
  hostvars = @db.models[:hostvar].all
264
- expect(hostvars.count).to eq(1)
264
+ expect(hostvars.count).to eq(1)
265
265
  end
266
266
  end
267
267
  end