foreman_salt 13.1.0 → 13.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dce5a18cef1f569ee315e5260928b43cc24a059b895f6cf2c4bbc6c98592cac8
4
- data.tar.gz: 864b8551057471a940a44b5d0447502040558fc0b697339a7ca28a09f1256203
3
+ metadata.gz: 01e9df6381c6f711af6e6a24f692bbb6241d073f67e9914087982e4ea5f97301
4
+ data.tar.gz: 9c041d7bacf1da063ed09dfc087267541ef678b5eeda256fcf69fe258e37e3f7
5
5
  SHA512:
6
- metadata.gz: d4ed7429fd288b8d07677e7bc28091262c5acc2f751fc511fa0a4b223bb8e9b257177a91098b94ef0e68dd660e704fbbe70ec37e0135d04a8e8a2ff6d9507445
7
- data.tar.gz: 82aa1176e433e8223e8ceb8003bfc22eb2d207ada21cdfd0e98a106e78ec7338f484db96fa315a303757a910b91d65247f7edbb66719090570c69397b8a2d9b6
6
+ metadata.gz: 859ca388dcebfc6614017feacbf20ebf52c4b1e3dbc8191d5378af6ec1dc97a40a52eba6897bdb858860bdc7315724eecdbb4478980c396cd5775122721a45b0
7
+ data.tar.gz: b3ad5e94db738522e58df0fdec82fea191f6b4518a33c818af79a2c60df2784b37f0c37dfff5224de57fe686ada2fce0ad6ffe088fed376414a4b920d473b4e9
@@ -7,6 +7,9 @@ module ForemanSalt
7
7
  include ::Foreman::Controller::SmartProxyAuth
8
8
  add_smart_proxy_filters :upload, :features => 'Salt'
9
9
 
10
+ include ::Foreman::Controller::FilterParameters
11
+ filter_parameters :job
12
+
10
13
  def_param_group :job do
11
14
  param :job, Hash, :required => true, :action_aware => true do
12
15
  param :job_id, Integer, :required => true, :desc => N_('JID')
@@ -12,6 +12,7 @@ module ForemanSalt
12
12
  enc['classes'] = @minion.salt_modules_for_enc
13
13
 
14
14
  pillars = @minion.info['parameters']
15
+ pillars['saltenv'] = env
15
16
  pillars.merge!(@minion.salt_params)
16
17
 
17
18
  enc['parameters'] = Setting[:salt_namespace_pillars] ? { 'foreman' => pillars } : pillars
@@ -1,13 +1,2 @@
1
1
  # Create feature for Smart Proxy
2
2
  Feature.where(:name => 'Salt').first_or_create
3
-
4
- # Add new viewing permissions to Viewer role
5
- viewer = Role.find_by_name('Viewer')
6
-
7
- if viewer
8
- Permission.where(:name => [:view_smart_proxies_salt_keys, :view_smart_proxies_salt_autosign, :view_salt_modules]).each do |permission|
9
- viewer.ignore_locking do
10
- viewer.add_permissions!([permission.name]) unless viewer.permissions.include? permission
11
- end
12
- end
13
- end
@@ -22,8 +22,8 @@ if ForemanSalt.with_remote_execution?
22
22
  :default => true,
23
23
  :locked => true,
24
24
  :update => sync)
25
- template.organizations = organizations if SETTINGS[:organizations_enabled] && template.present?
26
- template.locations = locations if SETTINGS[:locations_enabled] && template.present?
25
+ template.organizations = organizations if template.present?
26
+ template.locations = locations if template.present?
27
27
  end
28
28
  end
29
29
  end
@@ -165,6 +165,11 @@ Foreman::Plugin.register :foreman_salt do
165
165
  :create_salt_variables, :view_salt_variables,
166
166
  :edit_salt_variables, :destroy_salt_variables]
167
167
 
168
+ role 'Salt viewer', [:view_smart_proxies_salt_keys,
169
+ :view_smart_proxies_salt_autosign,
170
+ :view_salt_variables,
171
+ :view_salt_environments,
172
+ :view_salt_modules]
168
173
 
169
174
  # Parameter filters
170
175
  parameter_filter Hostgroup,
@@ -1,3 +1,3 @@
1
1
  module ForemanSalt
2
- VERSION = '13.1.0'
2
+ VERSION = '13.2.0'
3
3
  end
@@ -11,7 +11,9 @@ module ForemanSalt
11
11
  @proxy = FactoryBot.create(:smart_proxy, :with_salt_feature)
12
12
  Resolv.any_instance.stubs(:getnames).returns([@proxy.to_s])
13
13
 
14
+ @hostgroup = FactoryBot.create(:hostgroup)
14
15
  @host = FactoryBot.create(:host, salt_environment: FactoryBot.create(:salt_environment), salt_proxy: @proxy)
16
+ @host2 = FactoryBot.create(:host, :hostgroup => @hostgroup, salt_environment: FactoryBot.create(:salt_environment), salt_proxy: @proxy)
15
17
  FactoryBot.create(:host_parameter, name: "parameter1", value: "different", host: @host)
16
18
  end
17
19
 
@@ -34,39 +36,39 @@ module ForemanSalt
34
36
  end
35
37
 
36
38
  test 'salt variable is available' do
37
- @var = FactoryBot.create(:salt_variable, override: true)
38
- @var.salt_module.salt_environments << @host.salt_environment
39
- @host.salt_modules << @var.salt_module
39
+ var = FactoryBot.create(:salt_variable, override: true)
40
+ var.salt_module.salt_environments << @host.salt_environment
41
+ @host.salt_modules << var.salt_module
40
42
 
41
43
  get :node, params: { :id => @host, :format => 'yml' }
42
44
  assert_response :success
43
45
 
44
46
  res = YAML.safe_load(@response.body)
45
- assert_equal res['parameters'][@var.key], @var.value
47
+ assert_equal res['parameters'][var.key], var.value
46
48
  end
47
49
 
48
50
  test 'salt variable overrides host parameter' do
49
- @var = FactoryBot.create(:salt_variable, key: 'parameter1', override: true)
50
- @var.salt_module.salt_environments << @host.salt_environment
51
- @host.salt_modules << @var.salt_module
51
+ var = FactoryBot.create(:salt_variable, key: 'parameter1', override: true)
52
+ var.salt_module.salt_environments << @host.salt_environment
53
+ @host.salt_modules << var.salt_module
52
54
 
53
55
  get :node, params: { :id => @host, :format => 'yml' }
54
56
  assert_response :success
55
57
 
56
58
  res = YAML.safe_load(@response.body)
57
- assert_equal res['parameters']['parameter1'], @var.value
59
+ assert_equal res['parameters']['parameter1'], var.value
58
60
  end
59
61
 
60
- test 'salt variable matching host' do
61
- @var = FactoryBot.create(:salt_variable, key: 'parameter1', override: true)
62
+ test 'salt variable matching host with host specific value' do
63
+ var = FactoryBot.create(:salt_variable, key: 'parameter1', value: "default", override: true)
62
64
  # rubocop:disable Lint/UselessAssignment
63
- value1 = LookupValue.create(:lookup_key => @var, :match => "os=debian", :value => "aaa")
64
- value2 = LookupValue.create(:lookup_key => @var, :match => "fqdn=#{@host.fqdn}", :value => "myval")
65
- value3 = LookupValue.create(:lookup_key => @var, :match => "hostgroup=Unusual", :value => "bbbb")
65
+ value1 = LookupValue.create(:lookup_key => var, :match => "os=debian", :value => "aaa")
66
+ value2 = LookupValue.create(:lookup_key => var, :match => "fqdn=#{@host.fqdn}", :value => "myval")
67
+ value3 = LookupValue.create(:lookup_key => var, :match => "hostgroup=Unusual", :value => "bbbb")
66
68
  # rubocop:enable Lint/UselessAssignment
67
69
 
68
- @var.salt_module.salt_environments << @host.salt_environment
69
- @host.salt_modules << @var.salt_module
70
+ var.salt_module.salt_environments << @host.salt_environment
71
+ @host.salt_modules << var.salt_module
70
72
 
71
73
  get :node, params: { :id => @host, :format => 'yml' }
72
74
  assert_response :success
@@ -74,5 +76,39 @@ module ForemanSalt
74
76
  res = YAML.safe_load(@response.body)
75
77
  assert_equal res['parameters']['parameter1'], value2.value
76
78
  end
79
+
80
+ test 'salt variable matching host with hostgroup specific value' do
81
+ var = FactoryBot.create(:salt_variable, key: 'parameter1', value: "default", override: true)
82
+ # rubocop:disable Lint/UselessAssignment
83
+ value1 = LookupValue.create(:lookup_key => var, :match => "os=debian", :value => "aaa")
84
+ value2 = LookupValue.create(:lookup_key => var, :match => @hostgroup.lookup_value_matcher, :value => "bbbb")
85
+ # rubocop:enable Lint/UselessAssignment
86
+
87
+ var.salt_module.salt_environments << @host2.salt_environment
88
+ @host2.salt_modules << var.salt_module
89
+
90
+ get :node, params: { :id => @host2, :format => 'yml' }
91
+ assert_response :success
92
+
93
+ res = YAML.safe_load(@response.body)
94
+ assert_equal res['parameters']['parameter1'], value2.value
95
+ end
96
+
97
+ test 'salt variable matching host with default value' do
98
+ var = FactoryBot.create(:salt_variable, key: 'parameter1', value: "default", override: true)
99
+ # rubocop:disable Lint/UselessAssignment
100
+ value1 = LookupValue.create(:lookup_key => var, :match => "os=debian", :value => "aaa")
101
+ value2 = LookupValue.create(:lookup_key => var, :match => "fqdn=#{@host.fqdn}", :value => "myval")
102
+ value3 = LookupValue.create(:lookup_key => var, :match => "hostgroup=Unusual", :value => "bbbb")
103
+ # rubocop:enable Lint/UselessAssignment
104
+
105
+ var.salt_module.salt_environments << @host2.salt_environment
106
+ @host2.salt_modules << var.salt_module
107
+ get :node, params: { :id => @host2, :format => 'yml' }
108
+ assert_response :success
109
+
110
+ res = YAML.safe_load(@response.body)
111
+ assert_equal res['parameters']['parameter1'], var.value
112
+ end
77
113
  end
78
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_salt
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.1.0
4
+ version: 13.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Benjamin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-31 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface