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::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 = []
|
|
@@ -21,7 +21,7 @@ RSpec.describe Moose::Inventory::Cli::Host 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
|
|
|
@@ -45,19 +45,19 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
45
45
|
it 'host get <missing args> ... should abort with an error' do
|
|
46
46
|
# no items in the db
|
|
47
47
|
name = 'not-in-db'
|
|
48
|
-
actual = runner { @app.start(%
|
|
48
|
+
actual = runner { @app.start(%w(host get)) }
|
|
49
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 'host get HOST ... should return an empty set when HOST doesn\'t exist' do
|
|
58
58
|
# no items in the db
|
|
59
59
|
name = 'not-in-db'
|
|
60
|
-
actual = runner { @app.start(%W(host get #{
|
|
60
|
+
actual = runner { @app.start(%W(host get #{name})) }
|
|
61
61
|
|
|
62
62
|
desired = {}
|
|
63
63
|
desired[:STDOUT] = {}.to_yaml
|
|
@@ -68,14 +68,14 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
68
68
|
#---------------------
|
|
69
69
|
it 'host get HOST ... should get a host from the db' do
|
|
70
70
|
name = 'test-host-add'
|
|
71
|
-
runner { @app.start(%W(host add #{
|
|
71
|
+
runner { @app.start(%W(host add #{name})) }
|
|
72
72
|
|
|
73
|
-
actual = runner { @app.start(%W(host get #{
|
|
73
|
+
actual = runner { @app.start(%W(host get #{name})) }
|
|
74
74
|
|
|
75
75
|
mock = {}
|
|
76
76
|
mock[name.to_sym] = {}
|
|
77
77
|
mock[name.to_sym][:groups] = ['ungrouped']
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
|
80
80
|
desired[:STDOUT] = mock.to_yaml
|
|
81
81
|
|
|
@@ -86,19 +86,19 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
86
86
|
it 'host get HOST ... should display hostvars, if any are set' do
|
|
87
87
|
name = 'test-host-add'
|
|
88
88
|
var = 'foo=bar'
|
|
89
|
-
runner { @app.start(%W(host add #{
|
|
90
|
-
runner { @app.start(%W(host addvar #{
|
|
89
|
+
runner { @app.start(%W(host add #{name})) }
|
|
90
|
+
runner { @app.start(%W(host addvar #{name} #{var})) }
|
|
91
|
+
|
|
92
|
+
actual = runner { @app.start(%W(host get #{name})) }
|
|
91
93
|
|
|
92
|
-
actual = runner { @app.start(%W(host get #{ name })) }
|
|
93
|
-
|
|
94
94
|
mock = {}
|
|
95
95
|
mock[name.to_sym] = {}
|
|
96
96
|
mock[name.to_sym][:groups] = ['ungrouped']
|
|
97
|
-
mock[name.to_sym][:hostvars] = {foo: 'bar'}
|
|
98
|
-
|
|
97
|
+
mock[name.to_sym][:hostvars] = { foo: 'bar' }
|
|
98
|
+
|
|
99
99
|
desired = {}
|
|
100
100
|
desired[:STDOUT] = mock.to_yaml
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
expected(actual, desired)
|
|
103
103
|
end
|
|
104
104
|
end
|
|
@@ -9,14 +9,14 @@ 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 = []
|
|
16
16
|
@mockarg_parts.each do |key, val|
|
|
17
17
|
@mockargs << "--#{key}"
|
|
18
18
|
@mockargs << val
|
|
19
|
-
end
|
|
19
|
+
end
|
|
20
20
|
|
|
21
21
|
@config = Moose::Inventory::Config
|
|
22
22
|
@config.init(@mockargs)
|
|
@@ -45,7 +45,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
45
45
|
it 'should return an empty set when no results' do
|
|
46
46
|
# no items in the db
|
|
47
47
|
name = 'not-in-db'
|
|
48
|
-
actual = runner { @app.start(%
|
|
48
|
+
actual = runner { @app.start(%w(host list)) }
|
|
49
49
|
|
|
50
50
|
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
|
51
51
|
desired[:STDOUT] = {}.to_yaml
|
|
@@ -56,20 +56,20 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
56
56
|
#---------------------
|
|
57
57
|
it 'should get a list of hosts from the db' do
|
|
58
58
|
var = 'foo=bar'
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
mock = {}
|
|
61
61
|
hosts = %w(host1 host2 host3)
|
|
62
62
|
hosts.each do |name|
|
|
63
63
|
runner { @app.start(%W(host add #{name})) }
|
|
64
|
-
runner { @app.start(%W(host addvar #{
|
|
64
|
+
runner { @app.start(%W(host addvar #{name} foo=bar)) }
|
|
65
65
|
mock[name.to_sym] = {}
|
|
66
66
|
mock[name.to_sym][:groups] = ['ungrouped']
|
|
67
|
-
mock[name.to_sym][:hostvars] = {foo: 'bar'}
|
|
67
|
+
mock[name.to_sym][:hostvars] = { foo: 'bar' }
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
# items should now be in the db
|
|
71
|
-
actual = runner{ @app.start(%w(host list)) }
|
|
72
|
-
|
|
71
|
+
actual = runner { @app.start(%w(host list)) }
|
|
72
|
+
|
|
73
73
|
desired = { aborted: false, STDOUT: '', STDERR: '' }
|
|
74
74
|
desired[:STDOUT] = mock.to_yaml
|
|
75
75
|
|
|
@@ -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 = []
|
|
@@ -18,7 +18,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
18
18
|
@mockargs << val
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
@config = Moose::Inventory::Config
|
|
21
|
+
@config = Moose::Inventory::Config
|
|
22
22
|
@config.init(@mockargs)
|
|
23
23
|
|
|
24
24
|
@db = Moose::Inventory::DB
|
|
@@ -26,12 +26,12 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
26
26
|
|
|
27
27
|
@console = Moose::Inventory::Cli::Formatter
|
|
28
28
|
@host = Moose::Inventory::Cli::Host
|
|
29
|
-
@cli = Moose::Inventory::Cli
|
|
29
|
+
@cli = Moose::Inventory::Cli
|
|
30
30
|
@app = Moose::Inventory::Cli::Application
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
before(:each) do
|
|
34
|
-
# We make some @cli calls, which changes config,
|
|
34
|
+
# We make some @cli calls, which changes config,
|
|
35
35
|
# so we must reset config on each pass
|
|
36
36
|
@config.init(@mockargs)
|
|
37
37
|
@db.reset
|
|
@@ -44,72 +44,71 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
44
44
|
result = @host.instance_methods(false).include?(:listvars)
|
|
45
45
|
expect(result).to eq(true)
|
|
46
46
|
end
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
#-----------------
|
|
49
49
|
it '<missing args> ... should abort with an error' do
|
|
50
|
-
actual = runner {
|
|
50
|
+
actual = runner { @app.start(%w(host listvars)) }
|
|
51
51
|
|
|
52
52
|
# Check output
|
|
53
|
-
desired = { aborted: true}
|
|
53
|
+
desired = { aborted: true }
|
|
54
54
|
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 1 or more.\n"
|
|
55
55
|
expected(actual, desired)
|
|
56
56
|
end
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
#-----------------
|
|
59
59
|
it '--ansible <missing args> ... should abort with an error' do
|
|
60
|
-
|
|
61
60
|
args = @mockargs.clone
|
|
62
|
-
args.concat(
|
|
63
|
-
|
|
64
|
-
actual = runner{ @cli.start(args) }
|
|
65
|
-
|
|
61
|
+
args.concat(%w(--ansible host listvars)).flatten
|
|
62
|
+
|
|
63
|
+
actual = runner { @cli.start(args) }
|
|
64
|
+
|
|
66
65
|
# Check output
|
|
67
|
-
desired = { aborted: true}
|
|
66
|
+
desired = { aborted: true }
|
|
68
67
|
desired[:STDERR] = "ERROR: Wrong number of arguments for Ansible mode, 0 for 1.\n"
|
|
69
68
|
expected(actual, desired)
|
|
70
69
|
end
|
|
71
|
-
|
|
70
|
+
|
|
72
71
|
#------------------------
|
|
73
72
|
it 'HOST ... should return a list of host variables grouped by host' do
|
|
74
|
-
host_name ='test_host'
|
|
73
|
+
host_name = 'test_host'
|
|
75
74
|
host_vars = %w(foo=bar cow=chicken)
|
|
76
|
-
|
|
77
|
-
tmp = runner { @app.start(%W(host add #{host_name}
|
|
75
|
+
|
|
76
|
+
tmp = runner { @app.start(%W(host add #{host_name})) }
|
|
78
77
|
tmp = runner { @app.start(%W(host addvar #{host_name} #{host_vars[0]} #{host_vars[1]})) }
|
|
79
|
-
|
|
78
|
+
|
|
80
79
|
actual = runner do
|
|
81
80
|
@app.start(%W(host listvars #{host_name}))
|
|
82
81
|
end
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
# @console.out(actual, 'y')
|
|
84
|
+
|
|
86
85
|
# Check output
|
|
87
86
|
mock = {}
|
|
88
|
-
mock[host_name.to_sym] = {}
|
|
87
|
+
mock[host_name.to_sym] = {}
|
|
89
88
|
host_vars.each do |hv|
|
|
90
|
-
hv_array = hv.split('=')
|
|
91
|
-
mock[host_name.to_sym][hv_array[0].to_sym] = hv_array[1]
|
|
89
|
+
hv_array = hv.split('=')
|
|
90
|
+
mock[host_name.to_sym][hv_array[0].to_sym] = hv_array[1]
|
|
92
91
|
end
|
|
93
|
-
|
|
92
|
+
|
|
94
93
|
desired = {}
|
|
95
94
|
desired[:STDOUT] = mock.to_yaml
|
|
96
95
|
expected(actual, desired)
|
|
97
96
|
end
|
|
98
|
-
|
|
97
|
+
|
|
99
98
|
#------------------------
|
|
100
99
|
it '--ansible HOST ... should return a list of host variables per Ansible specs' do
|
|
101
|
-
host_name ='test_host'
|
|
100
|
+
host_name = 'test_host'
|
|
102
101
|
host_vars = %w(foo=bar cow=chicken)
|
|
103
|
-
|
|
104
|
-
tmp = runner { @app.start(%W(host add #{host_name}
|
|
102
|
+
|
|
103
|
+
tmp = runner { @app.start(%W(host add #{host_name})) }
|
|
105
104
|
tmp = runner { @app.start(%W(host addvar #{host_name} #{host_vars[0]} #{host_vars[1]})) }
|
|
106
|
-
|
|
105
|
+
|
|
107
106
|
actual = runner do
|
|
108
|
-
@cli.start(%W(--ansible host listvars #{host_name}))
|
|
107
|
+
@cli.start(%W(--config #{@mockarg_parts[:config]} --ansible host listvars #{host_name}))
|
|
109
108
|
end
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
|
|
110
|
+
# @console.out(actual, 'y')
|
|
111
|
+
|
|
113
112
|
# Check output
|
|
114
113
|
meta = {}
|
|
115
114
|
meta['hostvars'.to_sym] = {}
|
|
@@ -117,48 +116,47 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
117
116
|
|
|
118
117
|
mock = {}
|
|
119
118
|
host_vars.each do |hv|
|
|
120
|
-
hv_array = hv.split('=')
|
|
119
|
+
hv_array = hv.split('=')
|
|
121
120
|
mock[hv_array[0].to_sym] = hv_array[1]
|
|
122
|
-
meta['hostvars'.to_sym][host_name.to_sym][hv_array[0].to_sym] = hv_array[1]
|
|
121
|
+
meta['hostvars'.to_sym][host_name.to_sym][hv_array[0].to_sym] = hv_array[1]
|
|
123
122
|
end
|
|
124
123
|
mock['_meta'.to_sym] = meta
|
|
125
|
-
|
|
124
|
+
|
|
126
125
|
desired = {}
|
|
127
126
|
desired[:STDOUT] = mock.to_json + "\n"
|
|
128
127
|
expected(actual, desired)
|
|
129
128
|
end
|
|
130
|
-
|
|
129
|
+
|
|
131
130
|
#------------------------
|
|
132
131
|
it '--ansible HOST ... should be an alias for Ansible\'s --host HOST' do
|
|
133
|
-
host_name ='test_host'
|
|
132
|
+
host_name = 'test_host'
|
|
134
133
|
host_vars = %w(foo=bar cow=chicken)
|
|
135
|
-
|
|
136
|
-
tmp = runner { @app.start(%W(host add #{host_name}
|
|
134
|
+
|
|
135
|
+
tmp = runner { @app.start(%W(host add #{host_name})) }
|
|
137
136
|
tmp = runner { @app.start(%W(host addvar #{host_name} #{host_vars[0]} #{host_vars[1]})) }
|
|
138
|
-
|
|
137
|
+
|
|
139
138
|
actual = runner do
|
|
140
|
-
@cli.start(%W(--host #{host_name}))
|
|
139
|
+
@cli.start(%W(--config #{@mockarg_parts[:config]} --host #{host_name}))
|
|
141
140
|
end
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
|
|
142
|
+
# @console.out(actual, 'y')
|
|
143
|
+
|
|
145
144
|
# Check output
|
|
146
|
-
meta = {}
|
|
145
|
+
meta = {}
|
|
147
146
|
meta['hostvars'.to_sym] = {}
|
|
148
147
|
meta['hostvars'.to_sym][host_name.to_sym] = {}
|
|
149
148
|
|
|
150
149
|
mock = {}
|
|
151
150
|
host_vars.each do |hv|
|
|
152
|
-
hv_array = hv.split('=')
|
|
153
|
-
mock[hv_array[0].to_sym] = hv_array[1]
|
|
154
|
-
meta['hostvars'.to_sym][host_name.to_sym][hv_array[0].to_sym] = hv_array[1]
|
|
151
|
+
hv_array = hv.split('=')
|
|
152
|
+
mock[hv_array[0].to_sym] = hv_array[1]
|
|
153
|
+
meta['hostvars'.to_sym][host_name.to_sym][hv_array[0].to_sym] = hv_array[1]
|
|
155
154
|
end
|
|
156
155
|
mock['_meta'.to_sym] = meta
|
|
157
|
-
|
|
156
|
+
|
|
158
157
|
desired = {}
|
|
159
158
|
desired[:STDOUT] = mock.to_json + "\n"
|
|
160
159
|
expected(actual, desired)
|
|
161
160
|
end
|
|
162
|
-
|
|
163
161
|
end
|
|
164
162
|
end
|
|
@@ -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 = []
|
|
@@ -58,8 +58,8 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
58
58
|
# already exists.
|
|
59
59
|
|
|
60
60
|
# no items in the db
|
|
61
|
-
name =
|
|
62
|
-
actual = runner {
|
|
61
|
+
name = 'fake'
|
|
62
|
+
actual = runner { @app.start(%W(host rm #{name})) }
|
|
63
63
|
|
|
64
64
|
desired = {}
|
|
65
65
|
desired[:STDOUT] =
|
|
@@ -92,7 +92,7 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
92
92
|
" - OK\n"\
|
|
93
93
|
" - All OK\n"\
|
|
94
94
|
"Succeeded.\n"
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
expected(actual, desired)
|
|
97
97
|
|
|
98
98
|
# Check db
|
|
@@ -113,15 +113,15 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
113
113
|
desired = { aborted: false, STDERR: '', STDOUT: '' }
|
|
114
114
|
names.each do |name|
|
|
115
115
|
desired[:STDOUT] = desired[:STDOUT] +
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
"Remove host '#{name}':\n"\
|
|
117
|
+
" - Retrieve host '#{name}'...\n"\
|
|
118
|
+
" - OK\n"\
|
|
119
|
+
" - Destroy host '#{name}'...\n"\
|
|
120
|
+
" - OK\n"\
|
|
121
|
+
" - All OK\n"
|
|
122
122
|
end
|
|
123
|
-
desired[:STDOUT] = desired[:STDOUT] +
|
|
124
|
-
|
|
123
|
+
desired[:STDOUT] = desired[:STDOUT] +
|
|
124
|
+
"Succeeded.\n"
|
|
125
125
|
expected(actual, desired)
|
|
126
126
|
|
|
127
127
|
# Check db
|
|
@@ -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,17 +40,17 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
40
40
|
result = @host.instance_methods(false).include?(:rmgroup)
|
|
41
41
|
expect(result).to eq(true)
|
|
42
42
|
end
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
#----------------
|
|
45
45
|
|
|
46
46
|
#------------------------
|
|
47
47
|
it 'host rmgroup <missing args> ... should abort with an error' do
|
|
48
|
-
actual = runner
|
|
48
|
+
actual = runner do
|
|
49
49
|
@app.start(%w(host rmgroup)) # <- no group given
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
# Check output
|
|
53
|
-
desired = { aborted: true}
|
|
53
|
+
desired = { aborted: true }
|
|
54
54
|
desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 2 or more.\n"
|
|
55
55
|
expected(actual, desired)
|
|
56
56
|
end
|
|
@@ -64,41 +64,41 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
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
|
"Dissociate host '#{host_name}' from groups '#{group_name}':\n"\
|
|
70
70
|
" - Retrieve host '#{host_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 host '#{host_name}' was not found in the database.\n"
|
|
74
74
|
expected(actual, desired)
|
|
75
75
|
end
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
#------------------------
|
|
78
78
|
it 'host rmgroup HOST GROUP ... should dissociate the host from an existing group' do
|
|
79
79
|
# 1. Should rm the host to the group
|
|
80
80
|
# 2. Should add the host from the 'ungrouped' automatic group
|
|
81
|
-
# if it has no other groups.
|
|
82
|
-
|
|
81
|
+
# if it has no other groups.
|
|
82
|
+
|
|
83
83
|
host_name = 'test1'
|
|
84
84
|
runner { @app.start(%W(host add #{host_name})) }
|
|
85
85
|
|
|
86
86
|
group_names = %w(group1 group2)
|
|
87
|
-
tmp = runner { @app.start(%W(host addgroup #{host_name} #{group_names[0]} #{group_names[1]}
|
|
87
|
+
tmp = runner { @app.start(%W(host addgroup #{host_name} #{group_names[0]} #{group_names[1]})) }
|
|
88
88
|
|
|
89
89
|
#
|
|
90
90
|
# Dissociate from the first group
|
|
91
91
|
# 1. expect that the group association is removed
|
|
92
92
|
# 2. expect that no association with ungrouped is made.
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
actual = runner do
|
|
95
|
-
@app.start(%W(host rmgroup #{host_name} #{group_names[0]}
|
|
95
|
+
@app.start(%W(host rmgroup #{host_name} #{group_names[0]}))
|
|
96
96
|
end
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
# @console.dump(actual, 'y')
|
|
98
|
+
|
|
99
99
|
# rubocop:disable Metrics/LineLength
|
|
100
|
-
desired = { aborted: false}
|
|
101
|
-
desired[:STDOUT] =
|
|
100
|
+
desired = { aborted: false }
|
|
101
|
+
desired[:STDOUT] =
|
|
102
102
|
"Dissociate host '#{host_name}' from groups '#{group_names[0]}':\n"\
|
|
103
103
|
" - Retrieve host '#{host_name}'...\n"\
|
|
104
104
|
" - OK\n"\
|
|
@@ -115,19 +115,19 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
115
115
|
expect(groups.count).to eq(1)
|
|
116
116
|
expect(groups[name: group_names[0]]).to be_nil
|
|
117
117
|
expect(groups[name: group_names[1]]).not_to be_nil
|
|
118
|
-
expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
|
|
118
|
+
expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
|
|
119
119
|
|
|
120
120
|
#
|
|
121
121
|
# Remove the second group
|
|
122
122
|
# 1. expect that the group association is removed
|
|
123
123
|
# 2. expect that an association will be made with 'ungrouped'.
|
|
124
124
|
actual = runner do
|
|
125
|
-
@app.start(args = %W(host rmgroup #{host_name} #{group_names[1]}
|
|
125
|
+
@app.start(args = %W(host rmgroup #{host_name} #{group_names[1]}))
|
|
126
126
|
end
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
# rubocop:disable Metrics/LineLength
|
|
129
|
-
desired = { aborted: false}
|
|
130
|
-
desired[:STDOUT] =
|
|
129
|
+
desired = { aborted: false }
|
|
130
|
+
desired[:STDOUT] =
|
|
131
131
|
"Dissociate host '#{host_name}' from groups '#{group_names[1]}':\n"\
|
|
132
132
|
" - Retrieve host '#{host_name}'...\n"\
|
|
133
133
|
" - OK\n"\
|
|
@@ -139,61 +139,60 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
139
139
|
"Succeeded\n"
|
|
140
140
|
expected(actual, desired)
|
|
141
141
|
# rubocop:enable Metrics/LineLength
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
# We should have the correct group associations
|
|
144
144
|
host = @db.models[:host].find(name: host_name)
|
|
145
145
|
groups = host.groups_dataset
|
|
146
146
|
expect(groups.count).to eq(1)
|
|
147
147
|
expect(groups[name: group_names[0]]).to be_nil
|
|
148
148
|
expect(groups[name: group_names[1]]).to be_nil
|
|
149
|
-
expect(groups[name: 'ungrouped']).not_to be_nil
|
|
149
|
+
expect(groups[name: 'ungrouped']).not_to be_nil
|
|
150
150
|
end
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
#------------------------
|
|
153
153
|
it 'host rmgroup HOST GROUP ... should warn about non-existing associations' do
|
|
154
154
|
# 1. Should warn that the group doesn't exist.
|
|
155
|
-
# 2. Should complete with success. (desired state == actual state)
|
|
156
|
-
|
|
155
|
+
# 2. Should complete with success. (desired state == actual state)
|
|
156
|
+
|
|
157
157
|
host_name = 'test1'
|
|
158
158
|
group_name = 'no-group'
|
|
159
159
|
runner { @app.start(%W(host add #{host_name})) }
|
|
160
|
-
|
|
160
|
+
|
|
161
161
|
actual = runner do
|
|
162
|
-
@app.start(%W(host rmgroup #{host_name} #{group_name}
|
|
162
|
+
@app.start(%W(host rmgroup #{host_name} #{group_name}))
|
|
163
163
|
end
|
|
164
|
-
|
|
164
|
+
|
|
165
165
|
# rubocop:disable Metrics/LineLength
|
|
166
|
-
desired = { aborted: false}
|
|
167
|
-
desired[:STDOUT] =
|
|
166
|
+
desired = { aborted: false }
|
|
167
|
+
desired[:STDOUT] =
|
|
168
168
|
"Dissociate host '#{host_name}' from groups '#{group_name}':\n"\
|
|
169
169
|
" - Retrieve host \'#{host_name}\'...\n"\
|
|
170
170
|
" - OK\n"\
|
|
171
|
-
" - Remove association {host:#{host_name} <-> group:#{group_name
|
|
171
|
+
" - Remove association {host:#{host_name} <-> group:#{group_name}}...\n"\
|
|
172
172
|
" - Doesn't exist, skipping.\n"\
|
|
173
173
|
" - OK\n"\
|
|
174
174
|
" - All OK\n"\
|
|
175
175
|
"Succeeded\n"
|
|
176
|
-
desired[:STDERR] = "WARNING: Association {host:#{host_name} <-> group:#{group_name
|
|
176
|
+
desired[:STDERR] = "WARNING: Association {host:#{host_name} <-> group:#{group_name}} doesn't exist, skipping.\n"
|
|
177
177
|
|
|
178
178
|
expected(actual, desired)
|
|
179
|
-
end
|
|
179
|
+
end
|
|
180
180
|
|
|
181
181
|
#------------------------
|
|
182
182
|
it 'host rmgroup HOST \'ungrouped\' ... should abort with an error' do
|
|
183
|
-
|
|
184
183
|
name = 'test1'
|
|
185
184
|
groupname = 'ungrouped'
|
|
186
185
|
|
|
187
186
|
runner { @app.start(%W(host add #{name})) }
|
|
188
187
|
|
|
189
|
-
actual = runner { @app.start(%W(host rmgroup #{name} #{groupname}
|
|
188
|
+
actual = runner { @app.start(%W(host rmgroup #{name} #{groupname})) }
|
|
190
189
|
|
|
191
|
-
desired = { aborted: true}
|
|
190
|
+
desired = { aborted: true }
|
|
192
191
|
desired[:STDERR] =
|
|
193
|
-
|
|
192
|
+
"ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
|
|
194
193
|
expected(actual, desired)
|
|
195
194
|
end
|
|
196
|
-
|
|
195
|
+
|
|
197
196
|
#------------------------
|
|
198
197
|
it 'host rmgroup GROUP1 GROUP1 ... should dissociate the host from'\
|
|
199
198
|
' multiple groups at once' do
|
|
@@ -206,29 +205,27 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
206
205
|
|
|
207
206
|
group_names = %w(group1 group2)
|
|
208
207
|
group_names.each do |group|
|
|
209
|
-
runner { @app.start(%W(host addgroup #{host_name} #{group}
|
|
208
|
+
runner { @app.start(%W(host addgroup #{host_name} #{group})) }
|
|
210
209
|
end
|
|
211
210
|
|
|
212
211
|
actual = runner do
|
|
213
212
|
@app.start(%W(host rmgroup #{host_name}) + group_names)
|
|
214
213
|
end
|
|
215
|
-
|
|
216
|
-
# rubocop:disable Metrics/LineLength
|
|
217
|
-
desired = { aborted: false}
|
|
214
|
+
desired = { aborted: false }
|
|
218
215
|
desired[:STDOUT] =
|
|
219
216
|
"Dissociate host '#{host_name}' from groups '#{group_names.join(',')}':\n"\
|
|
220
217
|
" - Retrieve host \'#{host_name}\'...\n"\
|
|
221
218
|
" - OK\n"
|
|
222
219
|
group_names.each do |group|
|
|
223
220
|
desired[:STDOUT] = desired[:STDOUT] +
|
|
224
|
-
|
|
225
|
-
|
|
221
|
+
" - Remove association {host:#{host_name} <-> group:#{group}}...\n"\
|
|
222
|
+
" - OK\n"\
|
|
226
223
|
end
|
|
227
224
|
desired[:STDOUT] = desired[:STDOUT] +
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
225
|
+
" - Add automatic association {host:#{host_name} <-> group:ungrouped}...\n"\
|
|
226
|
+
" - OK\n"\
|
|
227
|
+
" - All OK\n"\
|
|
228
|
+
"Succeeded\n"
|
|
232
229
|
expected(actual, desired)
|
|
233
230
|
# rubocop:enable Metrics/LineLength
|
|
234
231
|
|
|
@@ -240,6 +237,6 @@ RSpec.describe Moose::Inventory::Cli::Host do
|
|
|
240
237
|
expect(groups[name: group]).to be_nil
|
|
241
238
|
end
|
|
242
239
|
expect(groups[name: 'ungrouped']).not_to be_nil # redundant, but for clarity!
|
|
243
|
-
end
|
|
240
|
+
end
|
|
244
241
|
end
|
|
245
242
|
end
|