foreman_salt 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -3
- data/app/controllers/foreman_salt/api/v2/base_controller.rb +13 -0
- data/app/controllers/foreman_salt/api/v2/jobs_controller.rb +9 -17
- data/app/controllers/foreman_salt/api/v2/salt_autosign_controller.rb +64 -0
- data/app/controllers/foreman_salt/api/v2/salt_environments_controller.rb +46 -0
- data/app/controllers/foreman_salt/api/v2/salt_keys_controller.rb +79 -0
- data/app/controllers/foreman_salt/api/v2/salt_minions_controller.rb +44 -0
- data/app/controllers/foreman_salt/api/v2/salt_states_controller.rb +46 -0
- data/app/controllers/foreman_salt/application_controller.rb +0 -1
- data/app/controllers/foreman_salt/concerns/hosts_controller_extensions.rb +0 -41
- data/app/controllers/foreman_salt/minions_controller.rb +54 -0
- data/app/controllers/foreman_salt/salt_autosign_controller.rb +8 -9
- data/app/controllers/foreman_salt/salt_environments_controller.rb +1 -1
- data/app/controllers/foreman_salt/salt_keys_controller.rb +10 -11
- data/app/controllers/foreman_salt/salt_modules_controller.rb +1 -1
- data/app/helpers/concerns/foreman_salt/hosts_helper_extensions.rb +10 -10
- data/app/helpers/concerns/foreman_salt/smart_proxies_helper_extensions.rb +2 -2
- data/app/helpers/foreman_salt/salt_keys_helper.rb +2 -3
- data/app/lib/actions/foreman_salt/report_import.rb +1 -2
- data/app/lib/proxy_api/salt.rb +1 -1
- data/app/models/foreman_salt/concerns/host_managed_extensions.rb +4 -4
- data/app/models/foreman_salt/concerns/hostgroup_extensions.rb +2 -2
- data/app/models/foreman_salt/concerns/orchestration/salt.rb +1 -1
- data/app/models/foreman_salt/fact_name.rb +0 -1
- data/app/models/foreman_salt/salt_environment.rb +2 -0
- data/app/models/foreman_salt/salt_module.rb +3 -1
- data/app/models/setting/salt.rb +12 -0
- data/app/overrides/salt_modules_selector.rb +12 -12
- data/app/services/foreman_salt/fact_importer.rb +10 -7
- data/app/services/foreman_salt/fact_parser.rb +100 -0
- data/app/services/foreman_salt/report_importer.rb +17 -14
- data/app/services/foreman_salt/smart_proxies/salt_keys.rb +26 -29
- data/app/views/foreman_salt/api/v2/salt_autosign/base.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_autosign/create.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_autosign/index.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_autosign/main.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_environments/base.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_environments/create.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_environments/index.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_environments/main.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_environments/show.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_keys/base.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_keys/index.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_keys/main.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_keys/update.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_minions/base.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_minions/index.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_minions/main.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_minions/show.json.rabl +8 -0
- data/app/views/foreman_salt/api/v2/salt_states/base.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_states/create.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_states/index.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_states/main.json.rabl +3 -0
- data/app/views/foreman_salt/api/v2/salt_states/show.json.rabl +3 -0
- data/config/routes.rb +25 -12
- data/db/migrate/20140813081913_add_salt_proxy_to_host_and_host_group.rb +0 -1
- data/db/migrate/20140817210214_create_salt_modules.rb +1 -1
- data/db/migrate/20150220122707_fix_incorrect_report_metrics.rb +22 -0
- data/lib/foreman_salt/engine.rb +114 -57
- data/lib/foreman_salt/version.rb +1 -1
- data/lib/tasks/foreman_salt_tasks.rake +2 -2
- data/test/functional/api/v2/salt_autosign_controller_test.rb +27 -0
- data/test/functional/api/v2/salt_environments_controller_test.rb +33 -0
- data/test/functional/api/v2/salt_keys_controller_test.rb +29 -0
- data/test/functional/api/v2/salt_states_controller_test.rb +33 -0
- data/test/functional/minions_controller_test.rb +18 -0
- data/test/integration/salt_environment_test.rb +0 -1
- data/test/integration/salt_keys_test.rb +4 -6
- data/test/integration/salt_module_test.rb +0 -1
- data/test/unit/grains_centos.json +4 -1
- data/test/unit/grains_importer_test.rb +39 -13
- data/test/unit/salt_keys_test.rb +4 -6
- metadata +44 -5
- data/app/controllers/foreman_salt/concerns/smart_proxy_auth_extensions.rb +0 -24
- data/test/functional/hosts_controller_test.rb +0 -16
@@ -0,0 +1,22 @@
|
|
1
|
+
class FixIncorrectReportMetrics < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
Report.all.each do |report|
|
4
|
+
next unless report.metrics && report.metrics['time']
|
5
|
+
metrics = report.metrics.dup
|
6
|
+
|
7
|
+
report.metrics['time'].each do |resource, time|
|
8
|
+
metrics['time'][resource] = if time.is_a? String
|
9
|
+
Float(time.delete(' ms')) rescue nil
|
10
|
+
else
|
11
|
+
time
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
report.update_attributes(:metrics => metrics) if metrics != report.metrics
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def down
|
20
|
+
# Nothing
|
21
|
+
end
|
22
|
+
end
|
data/lib/foreman_salt/engine.rb
CHANGED
@@ -2,7 +2,6 @@ require 'deface'
|
|
2
2
|
|
3
3
|
module ForemanSalt
|
4
4
|
class Engine < ::Rails::Engine
|
5
|
-
|
6
5
|
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
7
6
|
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
8
7
|
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
@@ -11,82 +10,145 @@ module ForemanSalt
|
|
11
10
|
config.autoload_paths += Dir["#{config.root}/app/lib"]
|
12
11
|
|
13
12
|
if defined? ForemanTasks
|
14
|
-
initializer 'foreman_salt.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |
|
13
|
+
initializer 'foreman_salt.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |_app|
|
15
14
|
ForemanTasks.dynflow.require!
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
19
|
-
|
18
|
+
initializer 'foreman_salt.load_default_settings', :before => :load_config_initializers do
|
19
|
+
require_dependency File.expand_path('../../../app/models/setting/salt.rb', __FILE__) if (Setting.table_exists? rescue(false))
|
20
|
+
end
|
21
|
+
|
20
22
|
initializer 'foreman_salt.load_app_instance_data' do |app|
|
21
23
|
app.config.paths['db/migrate'] += ForemanSalt::Engine.paths['db/migrate'].existent
|
22
24
|
end
|
23
25
|
|
24
|
-
initializer 'foreman_salt.
|
26
|
+
initializer 'foreman_salt.apipie' do
|
27
|
+
Apipie.configuration.api_controllers_matcher << "#{ForemanSalt::Engine.root}/app/controllers/foreman_salt/api/v2/*.rb"
|
28
|
+
Apipie.configuration.checksum_path += ['/salt/api/']
|
29
|
+
end
|
30
|
+
|
31
|
+
initializer 'foreman_salt.register_plugin', :after => :finisher_hook do |_app|
|
25
32
|
Foreman::Plugin.register :foreman_salt do
|
26
|
-
requires_foreman '>= 1.
|
33
|
+
requires_foreman '>= 1.8'
|
27
34
|
|
35
|
+
## Menus
|
28
36
|
menu :top_menu, :salt_environments,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
37
|
+
:url_hash => { :controller => :'foreman_salt/salt_environments', :action => :index },
|
38
|
+
:caption => 'Environments',
|
39
|
+
:parent => :configure_menu,
|
40
|
+
:after => :common_parameters
|
33
41
|
|
34
42
|
menu :top_menu, :salt_modules,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
:url_hash => { :controller => :'foreman_salt/salt_modules', :action => :index },
|
44
|
+
:caption => 'States',
|
45
|
+
:parent => :configure_menu,
|
46
|
+
:after => :common_parameters
|
39
47
|
|
40
48
|
divider :top_menu, :parent => :configure_menu,
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
permission :
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
permission :
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
permission :
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
permission :
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
49
|
+
:caption => 'Salt',
|
50
|
+
:after => :common_parameters
|
51
|
+
|
52
|
+
# Permissions
|
53
|
+
security_block :foreman_salt do |_map|
|
54
|
+
permission :destroy_smart_proxies_salt_autosign,
|
55
|
+
{ :'foreman_salt/salt_autosign' => [:destroy],
|
56
|
+
:'foreman_salt/api/v2/salt_autosign' => [:destroy] },
|
57
|
+
:resource_type => 'SmartProxy'
|
58
|
+
|
59
|
+
permission :create_smart_proxies_salt_autosign,
|
60
|
+
{ :'foreman_salt/salt_autosign' => [:new, :create],
|
61
|
+
:'foreman_salt/api/v2/salt_autosign' => [:create] },
|
62
|
+
:resource_type => 'SmartProxy'
|
63
|
+
|
64
|
+
permission :view_smart_proxies_salt_autosign,
|
65
|
+
{ :'foreman_salt/salt_autosign' => [:index],
|
66
|
+
:'foreman_salt/api/v2/salt_autosign' => [:index] },
|
67
|
+
:resource_type => 'SmartProxy'
|
68
|
+
|
69
|
+
permission :create_salt_environments,
|
70
|
+
{ :'foreman_salt/salt_environments' => [:new, :create],
|
71
|
+
:'foreman_salt/api/v2/salt_environments' => [:create] },
|
72
|
+
:resource_type => 'ForemanSalt::SaltEnvironment'
|
73
|
+
|
74
|
+
permission :view_salt_environments,
|
75
|
+
{ :'foreman_salt/salt_environments' => [:index, :show, :auto_complete_search],
|
76
|
+
:'foreman_salt/api/v2/salt_environments' => [:index, :show] },
|
77
|
+
:resource_type => 'ForemanSalt::SaltEnvironment'
|
78
|
+
|
79
|
+
permission :edit_salt_environments,
|
80
|
+
{ :'foreman_salt/salt_environments' => [:update, :edit] },
|
81
|
+
:resource_type => 'ForemanSalt::SaltEnvironment'
|
82
|
+
|
83
|
+
permission :destroy_salt_environments,
|
84
|
+
{ :'foreman_salt/salt_environments' => [:destroy],
|
85
|
+
:'foreman_salt/api/v2/salt_environments' => [:destroy] },
|
86
|
+
:resource_type => 'ForemanSalt::SaltEnvironment'
|
87
|
+
|
88
|
+
permission :create_reports,
|
89
|
+
{ :'foreman_salt/api/v2/jobs' => [:upload] },
|
90
|
+
:resource_type => 'Report'
|
91
|
+
|
92
|
+
permission :saltrun_hosts,
|
93
|
+
{ :'foreman_salt/minions' => [:run] },
|
94
|
+
:resource_type => 'Host'
|
95
|
+
|
96
|
+
permission :edit_hosts,
|
97
|
+
{ :'foreman_salt/api/v2/salt_minions' => [:update] },
|
98
|
+
:resource_type => 'Host'
|
99
|
+
|
100
|
+
permission :view_hosts,
|
101
|
+
{ :'foreman_salt/minions' => [:node],
|
102
|
+
:'foreman_salt/api/v2/salt_minions' => [:index, :show] },
|
103
|
+
:resource_type => 'Host'
|
104
|
+
|
105
|
+
permission :view_smart_proxies_salt_keys,
|
106
|
+
{ :'foreman_salt/salt_keys' => [:index],
|
107
|
+
:'foreman_salt/api/v2/salt_keys' => [:index] },
|
108
|
+
:resource_type => 'SmartProxy'
|
109
|
+
|
110
|
+
permission :destroy_smart_proxies_salt_keys,
|
111
|
+
{ :'foreman_salt/salt_keys' => [:destroy],
|
112
|
+
:'foreman_salt/api/v2/salt_keys' => [:destroy] },
|
113
|
+
:resource_type => 'SmartProxy'
|
114
|
+
|
115
|
+
permission :edit_smart_proxies_salt_keys,
|
116
|
+
{ :'foreman_salt/salt_keys' => [:accept, :reject],
|
117
|
+
:'foreman_salt/api/v2/salt_keys' => [:update] },
|
118
|
+
:resource_type => 'SmartProxy'
|
119
|
+
|
120
|
+
permission :create_salt_modules,
|
121
|
+
{ :'foreman_salt/salt_modules' => [:new, :create],
|
122
|
+
:'foreman_salt/api/v2/salt_states' => [:create] },
|
123
|
+
:resource_type => 'ForemanSalt::SaltModule'
|
124
|
+
|
125
|
+
permission :view_salt_modules,
|
126
|
+
{ :'foreman_salt/salt_modules' => [:index, :show, :auto_complete_search],
|
127
|
+
:'foreman_salt/api/v2/salt_states' => [:index, :show] },
|
128
|
+
:resource_type => 'ForemanSalt::SaltModule'
|
129
|
+
|
130
|
+
permission :edit_salt_modules,
|
131
|
+
{ :'foreman_salt/salt_modules' => [:update, :edit] },
|
132
|
+
:resource_type => 'ForemanSalt::SaltModule'
|
133
|
+
|
134
|
+
permission :destroy_salt_modules,
|
135
|
+
{ :'foreman_salt/salt_modules' => [:destroy],
|
136
|
+
:'foreman_salt/api/v2/salt_states' => [:destroy] },
|
137
|
+
:resource_type => 'ForemanSalt::SaltModule'
|
77
138
|
end
|
78
139
|
|
140
|
+
## Roles
|
79
141
|
role 'Salt admin', [:saltrun_hosts, :create_salt_modules, :view_salt_modules, :edit_salt_modules, :destroy_salt_modules,
|
80
142
|
:view_smart_proxies_salt_keys, :destroy_smart_proxies_salt_keys, :edit_smart_proxies_salt_keys,
|
81
143
|
:create_smart_proxies_salt_autosign, :view_smart_proxies_salt_autosign, :destroy_smart_proxies_salt_autosign,
|
82
144
|
:create_salt_environments, :view_salt_environments, :edit_salt_environments, :destroy_salt_environments]
|
83
|
-
|
84
145
|
end
|
85
146
|
end
|
86
147
|
|
87
148
|
config.to_prepare do
|
88
149
|
begin
|
89
150
|
::FactImporter.register_fact_importer(:foreman_salt, ForemanSalt::FactImporter)
|
151
|
+
::FactParser.register_fact_importer(:foreman_salt, ForemanSalt::FactParser)
|
90
152
|
|
91
153
|
# Helper Extensions
|
92
154
|
::HostsHelper.send :include, ForemanSalt::HostsHelperExtensions
|
@@ -99,13 +161,8 @@ module ForemanSalt
|
|
99
161
|
|
100
162
|
# Controller Extensions
|
101
163
|
::UnattendedController.send :include, ForemanSalt::Concerns::UnattendedControllerExtensions
|
102
|
-
::HostsController.send
|
103
|
-
::
|
104
|
-
::HostgroupsController.send :include, ForemanSalt::Concerns::HostgroupsControllerExtensions
|
105
|
-
|
106
|
-
# API Extensions
|
107
|
-
::Api::V2::HostsController.send :include, ForemanSalt::Concerns::SmartProxyAuthExtensions
|
108
|
-
::Api::V2::ReportsController.send :include, ForemanSalt::Concerns::SmartProxyAuthExtensions
|
164
|
+
::HostsController.send :include, ForemanSalt::Concerns::HostsControllerExtensions
|
165
|
+
::HostgroupsController.send :include, ForemanSalt::Concerns::HostgroupsControllerExtensions
|
109
166
|
rescue => e
|
110
167
|
puts "ForemanSalt: skipping engine hook (#{e})"
|
111
168
|
end
|
data/lib/foreman_salt/version.rb
CHANGED
@@ -8,7 +8,7 @@ namespace :foreman_salt do
|
|
8
8
|
"#{ForemanSalt::Engine.root}/test/**/*.rb"]
|
9
9
|
end
|
10
10
|
rescue
|
11
|
-
puts
|
11
|
+
puts 'Rubocop not loaded.'
|
12
12
|
end
|
13
13
|
|
14
14
|
Rake::Task['rubocop_salt'].invoke
|
@@ -19,7 +19,7 @@ namespace :test do
|
|
19
19
|
desc 'Test ForemanSalt'
|
20
20
|
Rake::TestTask.new(:foreman_salt) do |t|
|
21
21
|
test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
|
22
|
-
t.libs << ['test',test_dir]
|
22
|
+
t.libs << ['test', test_dir]
|
23
23
|
t.pattern = "#{test_dir}/**/*_test.rb"
|
24
24
|
t.verbose = true
|
25
25
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanSalt
|
4
|
+
class Api::V2::SaltAutosignControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@proxy = FactoryGirl.create(:smart_proxy, :with_salt_feature)
|
7
|
+
ProxyAPI::Salt.any_instance.stubs(:autosign_list).returns((%w(foo bar baz)))
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'should get index' do
|
11
|
+
get :index, :smart_proxy_id => @proxy.id
|
12
|
+
assert_response :success
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'should create autosign' do
|
16
|
+
ProxyAPI::Salt.any_instance.expects(:autosign_create).once.returns(true)
|
17
|
+
post :create, :smart_proxy_id => @proxy.id, :record => 'unicorn.example.com'
|
18
|
+
assert_response :success
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'should delete autosign' do
|
22
|
+
ProxyAPI::Salt.any_instance.expects(:autosign_remove).once.returns(true)
|
23
|
+
delete :destroy, :smart_proxy_id => @proxy.id, :record => 'unicorn.example.com'
|
24
|
+
assert_response :success
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanSalt
|
4
|
+
class Api::V2::SaltEnvironmentsControllerTest < ActionController::TestCase
|
5
|
+
test 'should get index' do
|
6
|
+
get :index, {}
|
7
|
+
assert_response :success
|
8
|
+
assert_template 'api/v2/salt_environments/index'
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'should show environment' do
|
12
|
+
environment = ForemanSalt::SaltEnvironment.create(:name => 'foo')
|
13
|
+
get :show, :id => environment.id
|
14
|
+
assert_response :success
|
15
|
+
assert_template 'api/v2/salt_environments/show'
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'should create environment' do
|
19
|
+
post :create, :environment => { :name => 'unicorn' }
|
20
|
+
assert_response :success
|
21
|
+
assert ForemanSalt::SaltEnvironment.find_by_name('unicorn')
|
22
|
+
assert_template 'api/v2/salt_environments/create'
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'should delete environment' do
|
26
|
+
environment = ForemanSalt::SaltEnvironment.create(:name => 'foo.bar.baz')
|
27
|
+
assert_difference('ForemanSalt::SaltEnvironment.count', -1) do
|
28
|
+
delete :destroy, :id => environment.id
|
29
|
+
end
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanSalt
|
4
|
+
class Api::V2::SaltKeysControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@proxy = FactoryGirl.create(:smart_proxy, :with_salt_feature)
|
7
|
+
|
8
|
+
ProxyAPI::Salt.any_instance.stubs(:key_list).returns('saltstack.example.com' => { 'state' => 'unaccepted',
|
9
|
+
'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' })
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'should get index' do
|
13
|
+
get :index, :smart_proxy_id => @proxy.id
|
14
|
+
assert_response :success
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'should update keys' do
|
18
|
+
ProxyAPI::Salt.any_instance.expects(:key_accept).once.returns(true)
|
19
|
+
put :update, :smart_proxy_id => @proxy.id, :name => 'saltstack.example.com', :key => { :state => 'accepted' }
|
20
|
+
assert_response :success
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should delete keys' do
|
24
|
+
ProxyAPI::Salt.any_instance.expects(:key_delete).once.returns(true)
|
25
|
+
delete :destroy, :smart_proxy_id => @proxy.id, :name => 'saltstack.example.com'
|
26
|
+
assert_response :success
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanSalt
|
4
|
+
class Api::V2::SaltStatesControllerTest < ActionController::TestCase
|
5
|
+
test 'should get index' do
|
6
|
+
get :index, {}
|
7
|
+
assert_response :success
|
8
|
+
assert_template 'api/v2/salt_states/index'
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'should show state' do
|
12
|
+
state = ForemanSalt::SaltModule.create(:name => 'foo.bar.baz')
|
13
|
+
get :show, :id => state.id
|
14
|
+
assert_response :success
|
15
|
+
assert_template 'api/v2/salt_states/show'
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'should create state' do
|
19
|
+
post :create, :state => { :name => 'unicorn' }
|
20
|
+
assert_response :success
|
21
|
+
assert ForemanSalt::SaltModule.find_by_name('unicorn')
|
22
|
+
assert_template 'api/v2/salt_states/create'
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'should delete state' do
|
26
|
+
state = ForemanSalt::SaltModule.create(:name => 'foo.bar.baz')
|
27
|
+
assert_difference('ForemanSalt::SaltModule.count', -1) do
|
28
|
+
delete :destroy, :id => state.id
|
29
|
+
end
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanSalt
|
4
|
+
class MinionsControllerTest < ActionController::TestCase
|
5
|
+
test 'salt smart proxy should get salt external node' do
|
6
|
+
User.current = nil
|
7
|
+
Setting[:restrict_registered_smart_proxies] = true
|
8
|
+
Setting[:require_ssl_smart_proxies] = false
|
9
|
+
|
10
|
+
proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
|
11
|
+
Resolv.any_instance.stubs(:getnames).returns([proxy.to_s])
|
12
|
+
|
13
|
+
host = FactoryGirl.create :host
|
14
|
+
get :node, :id => host, :format => 'yml'
|
15
|
+
assert_response :success
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,7 +2,6 @@ require 'test_plugin_helper'
|
|
2
2
|
|
3
3
|
module ForemanSalt
|
4
4
|
class SaltEnvironmentTest < ActionDispatch::IntegrationTest
|
5
|
-
|
6
5
|
test 'index page' do
|
7
6
|
FactoryGirl.create_list :salt_environment, 50
|
8
7
|
assert_index_page(salt_environments_path, 'Salt Environment', 'New Salt Environment')
|
@@ -6,12 +6,10 @@ module ForemanSalt
|
|
6
6
|
@proxy = FactoryGirl.create :smart_proxy, :with_salt_feature
|
7
7
|
|
8
8
|
::ProxyAPI::Salt.any_instance.stubs(:key_list).returns(
|
9
|
-
{
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
'saltclient03.example.com' => {'state'=>'rejected', 'fingerprint'=>'98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3'}
|
14
|
-
}
|
9
|
+
'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
|
10
|
+
'saltclient01.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c1' },
|
11
|
+
'saltclient02.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c2' },
|
12
|
+
'saltclient03.example.com' => { 'state' => 'rejected', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3' }
|
15
13
|
)
|
16
14
|
end
|
17
15
|
|
@@ -102,7 +102,10 @@
|
|
102
102
|
"os_family": "RedHat",
|
103
103
|
"operatingsystemrelease": "6.5",
|
104
104
|
"gpus::0::vendor": "unknown",
|
105
|
-
"lsb_distrib_codename": "Final"
|
105
|
+
"lsb_distrib_codename": "Final",
|
106
|
+
"fqdn_ip4::0": "10.7.13.141",
|
107
|
+
"ip_interfaces::eth1::0": "1.2.3.4",
|
108
|
+
"hwaddr_interfaces::eth1": "DE:AD:BE:EF:07:13"
|
106
109
|
},
|
107
110
|
"name": "saltclient01.example.com"
|
108
111
|
}
|
@@ -6,33 +6,59 @@ module ForemanSalt
|
|
6
6
|
User.current = User.find_by_login 'admin'
|
7
7
|
Setting[:create_new_host_when_facts_are_uploaded] = true
|
8
8
|
|
9
|
-
|
10
|
-
# in development, and even on the Rails test console but not here
|
11
|
-
# in the test itself...
|
12
|
-
::FactImporter.stubs(:importer_for).returns(ForemanSalt::FactImporter)
|
9
|
+
Operatingsystem.where(:name => 'CentOS', :major => '6', :minor => '5').delete_all
|
13
10
|
|
14
11
|
grains = JSON.parse(File.read(File.join(Engine.root, 'test', 'unit', 'grains_centos.json')))
|
15
|
-
|
16
|
-
|
12
|
+
host = grains['name']
|
13
|
+
facts = HashWithIndifferentAccess.new(grains['facts'])
|
14
|
+
|
15
|
+
(@imported_host, _) = ::Host::Managed.import_host_and_facts host, facts
|
17
16
|
end
|
18
17
|
|
19
18
|
test 'importing salt grains creates a host' do
|
20
|
-
|
21
|
-
::Host::Managed.import_host_and_facts @host, @facts
|
22
|
-
assert Host.find_by_name(@host)
|
19
|
+
assert @imported_host
|
23
20
|
end
|
24
21
|
|
25
22
|
test 'grains are successfully imported for a host' do
|
26
|
-
|
27
|
-
assert_equal 'CentOS', host.facts_hash['operatingsystem']
|
23
|
+
assert_equal 'CentOS', @imported_host.facts_hash['operatingsystem']
|
28
24
|
end
|
29
25
|
|
30
26
|
test 'nested facts have valid parents' do
|
31
|
-
(host, _) = ::Host::Managed.import_host_and_facts @host, @facts
|
32
27
|
parent = ::FactName.find_by_name('cpu_flags')
|
33
|
-
children =
|
28
|
+
children = @imported_host.fact_values.with_fact_parent_id(parent)
|
34
29
|
assert_not_empty children
|
35
30
|
assert_empty children.map(&:fact_name).reject { |fact| fact.name =~ /\Acpu_flags#{FactName::SEPARATOR}[0-9]+/ }
|
36
31
|
end
|
32
|
+
|
33
|
+
# Parser
|
34
|
+
test 'imported host has operating system' do
|
35
|
+
assert_equal @imported_host.os.to_label, 'CentOS 6.5'
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'imported host operating system has deduced family' do
|
39
|
+
assert_equal @imported_host.os.family, 'Redhat'
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'imported host has hardware model' do
|
43
|
+
assert_equal @imported_host.model.name, 'KVM'
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'imported host has architecture' do
|
47
|
+
assert_equal @imported_host.arch.name, 'x86_64'
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'imported host has primary ip' do
|
51
|
+
assert_equal @imported_host.ip, '10.7.13.141'
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'imported host has primary mac' do
|
55
|
+
assert_equal @imported_host.mac, '52:54:00:35:30:2a'
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'imported host has additional interface' do
|
59
|
+
nic = @imported_host.interfaces.find_by_identifier('eth1')
|
60
|
+
assert_equal nic.mac, 'de:ad:be:ef:07:13'
|
61
|
+
assert_equal nic.ip, '1.2.3.4'
|
62
|
+
end
|
37
63
|
end
|
38
64
|
end
|
data/test/unit/salt_keys_test.rb
CHANGED
@@ -10,12 +10,10 @@ class SaltKeysTest < ActiveSupport::TestCase
|
|
10
10
|
@proxy = OpenStruct.new(:id => 1, :url => 'http://dummy.example.com:9090')
|
11
11
|
|
12
12
|
ProxyAPI::Salt.any_instance.stubs(:key_list).returns(
|
13
|
-
{
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
'saltclient03.example.com' => {'state'=>'rejected', 'fingerprint'=>'98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3'}
|
18
|
-
}
|
13
|
+
'saltstack.example.com' => { 'state' => 'accepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c0' },
|
14
|
+
'saltclient01.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c1' },
|
15
|
+
'saltclient02.example.com' => { 'state' => 'unaccepted', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c2' },
|
16
|
+
'saltclient03.example.com' => { 'state' => 'rejected', 'fingerprint' => '98:c2:63:c1:57:59:bc:bd:f1:ef:5a:38:b2:e9:71:c3' }
|
19
17
|
)
|
20
18
|
end
|
21
19
|
|