foreman_remote_execution 16.0.3 → 16.0.5
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 +4 -4
- data/app/controllers/api/v2/job_templates_controller.rb +2 -1
- data/app/controllers/cockpit_controller.rb +2 -2
- data/app/controllers/job_invocations_controller.rb +28 -1
- data/app/controllers/template_invocations_controller.rb +1 -1
- data/app/helpers/hosts_extensions_helper.rb +1 -1
- data/app/lib/actions/remote_execution/run_host_job.rb +5 -28
- data/app/models/concerns/foreman_remote_execution/host_extensions.rb +7 -1
- data/app/models/job_template.rb +5 -0
- data/app/models/{ssh_execution_provider.rb → script_execution_provider.rb} +2 -4
- data/config/initializers/inflections.rb +0 -1
- data/config/routes.rb +1 -0
- data/lib/foreman_remote_execution/engine.rb +10 -257
- data/lib/foreman_remote_execution/plugin.rb +246 -0
- data/lib/foreman_remote_execution/version.rb +1 -1
- data/test/functional/api/v2/job_invocations_controller_test.rb +1 -1
- data/test/functional/api/v2/job_templates_controller_test.rb +29 -0
- data/test/unit/actions/run_host_job_test.rb +1 -1
- data/test/unit/job_invocation_report_template_test.rb +6 -6
- data/test/unit/remote_execution_provider_test.rb +19 -19
- data/webpack/JobInvocationDetail/CheckboxesActions.js +196 -0
- data/webpack/JobInvocationDetail/{JobInvocationHostTableToolbar.js → DropdownFilter.js} +3 -6
- data/webpack/JobInvocationDetail/JobInvocationConstants.js +7 -7
- data/webpack/JobInvocationDetail/JobInvocationDetail.scss +32 -0
- data/webpack/JobInvocationDetail/JobInvocationHostTable.js +221 -91
- data/webpack/JobInvocationDetail/JobInvocationSelectors.js +30 -3
- data/webpack/JobInvocationDetail/JobInvocationSystemStatusChart.js +8 -22
- data/webpack/JobInvocationDetail/JobInvocationToolbarButtons.js +20 -27
- data/webpack/JobInvocationDetail/OpenAllInvocationsModal.js +118 -0
- data/webpack/JobInvocationDetail/TemplateInvocation.js +54 -24
- data/webpack/JobInvocationDetail/TemplateInvocationComponents/TemplateActionButtons.js +8 -10
- data/webpack/JobInvocationDetail/TemplateInvocationPage.js +1 -1
- data/webpack/JobInvocationDetail/__tests__/MainInformation.test.js +1 -1
- data/webpack/JobInvocationDetail/__tests__/TableToolbarActions.test.js +202 -0
- data/webpack/JobInvocationDetail/__tests__/TemplateInvocation.test.js +34 -28
- data/webpack/JobInvocationDetail/index.js +64 -31
- data/webpack/JobWizard/steps/HostsAndInputs/buildHostQuery.js +26 -7
- data/webpack/react_app/components/TargetingHosts/TargetingHostsLabelsRow.scss +1 -1
- metadata +9 -7
- data/webpack/JobInvocationDetail/OpenAlInvocations.js +0 -111
- data/webpack/JobInvocationDetail/__tests__/OpenAlInvocations.test.js +0 -110
@@ -0,0 +1,246 @@
|
|
1
|
+
Foreman::Plugin.register :foreman_remote_execution do
|
2
|
+
requires_foreman '>= 3.15'
|
3
|
+
register_global_js_file 'global'
|
4
|
+
register_gettext
|
5
|
+
|
6
|
+
apipie_documented_controllers ["#{ForemanRemoteExecution::Engine.root}/app/controllers/api/v2/*.rb"]
|
7
|
+
ApipieDSL.configuration.dsl_classes_matchers += [
|
8
|
+
"#{ForemanRemoteExecution::Engine.root}/app/lib/foreman_remote_execution/renderer/**/*.rb",
|
9
|
+
]
|
10
|
+
automatic_assets(false)
|
11
|
+
precompile_assets(ForemanRemoteExecution::Engine.assets_to_precompile)
|
12
|
+
|
13
|
+
# Add settings to a Remote Execution category
|
14
|
+
settings do
|
15
|
+
category :remote_execution, N_('Remote Execution') do
|
16
|
+
setting 'remote_execution_fallback_proxy',
|
17
|
+
type: :boolean,
|
18
|
+
description: N_('Search the host for any proxy with Remote Execution, useful when the host has no subnet or the subnet does not have an execution proxy'),
|
19
|
+
default: false,
|
20
|
+
full_name: N_('Fallback to Any Proxy')
|
21
|
+
setting 'remote_execution_global_proxy',
|
22
|
+
type: :boolean,
|
23
|
+
description: N_('Search for remote execution proxy outside of the proxies assigned to the host. The search will be limited to the host\'s organization and location.'),
|
24
|
+
default: true,
|
25
|
+
full_name: N_('Enable Global Proxy')
|
26
|
+
setting 'remote_execution_ssh_user',
|
27
|
+
type: :string,
|
28
|
+
description: N_('Default user to use for SSH. You may override per host by setting a parameter called remote_execution_ssh_user.'),
|
29
|
+
default: 'root',
|
30
|
+
full_name: N_('SSH User')
|
31
|
+
setting 'remote_execution_effective_user',
|
32
|
+
type: :string,
|
33
|
+
description: N_('Default user to use for executing the script. If the user differs from the SSH user, su or sudo is used to switch the user.'),
|
34
|
+
default: 'root',
|
35
|
+
full_name: N_('Effective User')
|
36
|
+
setting 'remote_execution_effective_user_method',
|
37
|
+
type: :string,
|
38
|
+
description: N_('What command should be used to switch to the effective user. One of %s') % ::ScriptExecutionProvider::EFFECTIVE_USER_METHODS.inspect,
|
39
|
+
default: 'sudo',
|
40
|
+
full_name: N_('Effective User Method'),
|
41
|
+
collection: proc { Hash[::ScriptExecutionProvider::EFFECTIVE_USER_METHODS.map { |method| [method, method] }] }
|
42
|
+
setting 'remote_execution_effective_user_password',
|
43
|
+
type: :string,
|
44
|
+
description: N_('Effective user password'),
|
45
|
+
default: '',
|
46
|
+
full_name: N_('Effective user password'),
|
47
|
+
encrypted: true
|
48
|
+
setting 'remote_execution_sync_templates',
|
49
|
+
type: :boolean,
|
50
|
+
description: N_('Whether we should sync templates from disk when running db:seed.'),
|
51
|
+
default: true,
|
52
|
+
full_name: N_('Sync Job Templates')
|
53
|
+
setting 'remote_execution_ssh_port',
|
54
|
+
type: :integer,
|
55
|
+
description: N_('Port to use for SSH communication. Default port 22. You may override per host by setting a parameter called remote_execution_ssh_port.'),
|
56
|
+
default: 22,
|
57
|
+
full_name: N_('SSH Port')
|
58
|
+
setting 'remote_execution_connect_by_ip',
|
59
|
+
type: :boolean,
|
60
|
+
description: N_('Should the ip addresses on host interfaces be preferred over the fqdn? '\
|
61
|
+
'It is useful when DNS not resolving the fqdns properly. You may override this per host by setting a parameter called remote_execution_connect_by_ip. '\
|
62
|
+
'For dual-stacked hosts you should consider the remote_execution_connect_by_ip_prefer_ipv6 setting'),
|
63
|
+
default: false,
|
64
|
+
full_name: N_('Connect by IP')
|
65
|
+
setting 'remote_execution_connect_by_ip_prefer_ipv6',
|
66
|
+
type: :boolean,
|
67
|
+
description: N_('When connecting using ip address, should the IPv6 addresses be preferred? '\
|
68
|
+
'If no IPv6 address is set, it falls back to IPv4 automatically. You may override this per host by setting a parameter called remote_execution_connect_by_ip_prefer_ipv6. '\
|
69
|
+
'By default and for compatibility, IPv4 will be preferred over IPv6 by default'),
|
70
|
+
default: false,
|
71
|
+
full_name: N_('Prefer IPv6 over IPv4')
|
72
|
+
setting 'remote_execution_ssh_password',
|
73
|
+
type: :string,
|
74
|
+
description: N_('Default password to use for SSH. You may override per host by setting a parameter called remote_execution_ssh_password'),
|
75
|
+
default: nil,
|
76
|
+
full_name: N_('Default SSH password'),
|
77
|
+
encrypted: true
|
78
|
+
setting 'remote_execution_ssh_key_passphrase',
|
79
|
+
type: :string,
|
80
|
+
description: N_('Default key passphrase to use for SSH. You may override per host by setting a parameter called remote_execution_ssh_key_passphrase'),
|
81
|
+
default: nil,
|
82
|
+
full_name: N_('Default SSH key passphrase'),
|
83
|
+
encrypted: true
|
84
|
+
setting 'remote_execution_cleanup_working_dirs',
|
85
|
+
type: :boolean,
|
86
|
+
description: N_('When enabled, working directories will be removed after task completion. You may override this per host by setting a parameter called remote_execution_cleanup_working_dirs.'),
|
87
|
+
default: true,
|
88
|
+
full_name: N_('Cleanup working directories')
|
89
|
+
setting 'remote_execution_cockpit_url',
|
90
|
+
type: :string,
|
91
|
+
description: N_('Where to find the Cockpit instance for the Web Console button. By default, no button is shown.'),
|
92
|
+
default: nil,
|
93
|
+
full_name: N_('Cockpit URL')
|
94
|
+
setting 'remote_execution_form_job_template',
|
95
|
+
type: :string,
|
96
|
+
description: N_('Choose a job template that is pre-selected in job invocation form'),
|
97
|
+
default: 'Run Command - Script Default',
|
98
|
+
full_name: N_('Form Job Template'),
|
99
|
+
collection: proc { Hash[JobTemplate.unscoped.map { |template| [template.name, template.name] }] }
|
100
|
+
setting 'remote_execution_job_invocation_report_template',
|
101
|
+
type: :string,
|
102
|
+
description: N_('Select a report template used for generating a report for a particular remote execution job'),
|
103
|
+
default: 'Job - Invocation Report',
|
104
|
+
full_name: N_('Job Invocation Report Template'),
|
105
|
+
collection: proc { ForemanRemoteExecution.job_invocation_report_templates_select }
|
106
|
+
setting 'remote_execution_time_to_pickup',
|
107
|
+
type: :integer,
|
108
|
+
description: N_('Time in seconds within which the host has to pick up a job. If the job is not picked up within this limit, the job will be cancelled. Defaults to 1 day. Applies only to pull-mqtt based jobs.'),
|
109
|
+
default: 24 * 60 * 60,
|
110
|
+
full_name: N_('Time to pickup')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Add permissions
|
115
|
+
security_block :foreman_remote_execution do
|
116
|
+
permission :view_job_templates, { :job_templates => [:index, :show, :revision, :auto_complete_search, :auto_complete_job_category, :preview, :export],
|
117
|
+
:'api/v2/job_templates' => [:index, :show, :revision, :export],
|
118
|
+
:'api/v2/template_inputs' => [:index, :show],
|
119
|
+
:'api/v2/foreign_input_sets' => [:index, :show],
|
120
|
+
:ui_job_wizard => [:categories, :template, :resources, :job_invocation]}, :resource_type => 'JobTemplate'
|
121
|
+
permission :create_job_templates, { :job_templates => [:new, :create, :clone_template, :import],
|
122
|
+
:'api/v2/job_templates' => [:create, :clone, :import] }, :resource_type => 'JobTemplate'
|
123
|
+
permission :edit_job_templates, { :job_templates => [:edit, :update],
|
124
|
+
:'api/v2/job_templates' => [:update],
|
125
|
+
:'api/v2/template_inputs' => [:create, :update, :destroy],
|
126
|
+
:'api/v2/foreign_input_sets' => [:create, :update, :destroy]}, :resource_type => 'JobTemplate'
|
127
|
+
permission :view_remote_execution_features, { :remote_execution_features => [:index, :show],
|
128
|
+
:'api/v2/remote_execution_features' => [:index, :show, :available_remote_execution_features]},
|
129
|
+
:resource_type => 'RemoteExecutionFeature'
|
130
|
+
permission :edit_remote_execution_features, { :remote_execution_features => [:update],
|
131
|
+
:'api/v2/remote_execution_features' => [:update]}, :resource_type => 'RemoteExecutionFeature'
|
132
|
+
permission :destroy_job_templates, { :job_templates => [:destroy],
|
133
|
+
:'api/v2/job_templates' => [:destroy] }, :resource_type => 'JobTemplate'
|
134
|
+
permission :lock_job_templates, { :job_templates => [:lock, :unlock] }, :resource_type => 'JobTemplate'
|
135
|
+
permission :create_job_invocations, { :job_invocations => [:new, :create, :legacy_create, :refresh, :rerun, :preview_hosts],
|
136
|
+
'api/v2/job_invocations' => [:create, :rerun] }, :resource_type => 'JobInvocation'
|
137
|
+
permission :view_job_invocations, { :job_invocations => [:index, :chart, :show, :auto_complete_search, :preview_job_invocations_per_host, :list_jobs_hosts], :template_invocations => [:show, :show_template_invocation_by_host],
|
138
|
+
'api/v2/job_invocations' => [:index, :show, :output, :raw_output, :outputs, :hosts] }, :resource_type => 'JobInvocation'
|
139
|
+
permission :view_template_invocations, { :template_invocations => [:show, :template_invocation_preview, :show_template_invocation_by_host], :job_invocations => [:list_jobs_hosts],
|
140
|
+
'api/v2/template_invocations' => [:template_invocations], :ui_job_wizard => [:job_invocation] }, :resource_type => 'TemplateInvocation'
|
141
|
+
permission :create_template_invocations, {}, :resource_type => 'TemplateInvocation'
|
142
|
+
permission :execute_jobs_on_infrastructure_hosts, {}, :resource_type => 'JobInvocation'
|
143
|
+
permission :cancel_job_invocations, { :job_invocations => [:cancel], 'api/v2/job_invocations' => [:cancel] }, :resource_type => 'JobInvocation'
|
144
|
+
# this permissions grants user to get auto completion hints when setting up filters
|
145
|
+
permission :filter_autocompletion_for_template_invocation, { :template_invocations => [:auto_complete_search, :index] },
|
146
|
+
:resource_type => 'TemplateInvocation'
|
147
|
+
permission :cockpit_hosts, { 'cockpit' => [:redirect, :host_ssh_params] }, :resource_type => 'Host'
|
148
|
+
end
|
149
|
+
|
150
|
+
user_permissions = [
|
151
|
+
:view_job_templates,
|
152
|
+
:view_job_invocations,
|
153
|
+
:create_job_invocations,
|
154
|
+
:create_template_invocations,
|
155
|
+
:view_hosts,
|
156
|
+
:view_smart_proxies,
|
157
|
+
:view_remote_execution_features,
|
158
|
+
].freeze
|
159
|
+
manager_permissions = user_permissions + [
|
160
|
+
:cancel_job_invocations,
|
161
|
+
:destroy_job_templates,
|
162
|
+
:edit_job_templates,
|
163
|
+
:create_job_templates,
|
164
|
+
:lock_job_templates,
|
165
|
+
:view_audit_logs,
|
166
|
+
:filter_autocompletion_for_template_invocation,
|
167
|
+
:edit_remote_execution_features,
|
168
|
+
]
|
169
|
+
|
170
|
+
# Add a new role called 'Remote Execution User ' if it doesn't exist
|
171
|
+
role 'Remote Execution User', user_permissions, 'Role with permissions to run remote execution jobs against hosts'
|
172
|
+
role 'Remote Execution Manager', manager_permissions, 'Role with permissions to manage job templates, remote execution features, cancel jobs and view audit logs'
|
173
|
+
|
174
|
+
add_all_permissions_to_default_roles(except: [:execute_jobs_on_infrastructure_hosts])
|
175
|
+
add_permissions_to_default_roles({
|
176
|
+
Role::MANAGER => [:execute_jobs_on_infrastructure_hosts],
|
177
|
+
Role::SITE_MANAGER => user_permissions + [:execute_jobs_on_infrastructure_hosts],
|
178
|
+
})
|
179
|
+
|
180
|
+
# add menu entry
|
181
|
+
menu :top_menu, :job_templates,
|
182
|
+
url_hash: { controller: :job_templates, action: :index },
|
183
|
+
caption: N_('Job Templates'),
|
184
|
+
parent: :hosts_menu,
|
185
|
+
after: :provisioning_templates
|
186
|
+
menu :admin_menu, :remote_execution_features,
|
187
|
+
url_hash: { controller: :remote_execution_features, action: :index },
|
188
|
+
caption: N_('Remote Execution Features'),
|
189
|
+
parent: :administer_menu,
|
190
|
+
after: :bookmarks
|
191
|
+
|
192
|
+
menu :top_menu, :job_invocations,
|
193
|
+
url_hash: { controller: :job_invocations, action: :index },
|
194
|
+
caption: N_('Jobs'),
|
195
|
+
parent: :monitor_menu,
|
196
|
+
after: :audits
|
197
|
+
|
198
|
+
menu :labs_menu, :job_invocations_detail,
|
199
|
+
url_hash: { controller: :job_invocations, action: :show },
|
200
|
+
caption: N_('Job invocations detail'),
|
201
|
+
parent: :lab_features_menu,
|
202
|
+
url: '/experimental/job_invocations_detail/1'
|
203
|
+
|
204
|
+
register_custom_status HostStatus::ExecutionStatus
|
205
|
+
# add dashboard widget
|
206
|
+
# widget 'foreman_remote_execution_widget', name: N_('Foreman plugin template widget'), sizex: 4, sizey: 1
|
207
|
+
widget 'dashboard/latest-jobs', :name => N_('Latest Jobs'), :sizex => 6, :sizey => 1
|
208
|
+
|
209
|
+
parameter_filter Subnet, :remote_execution_proxies, :remote_execution_proxy_ids => []
|
210
|
+
parameter_filter Nic::Interface do |ctx|
|
211
|
+
ctx.permit :execution
|
212
|
+
end
|
213
|
+
|
214
|
+
register_graphql_query_field :job_invocations, '::Types::JobInvocation', :collection_field
|
215
|
+
register_graphql_query_field :job_invocation, '::Types::JobInvocation', :record_field
|
216
|
+
|
217
|
+
register_graphql_mutation_field :create_job_invocation, ::Mutations::JobInvocations::Create
|
218
|
+
|
219
|
+
extend_template_helpers ForemanRemoteExecution::RendererMethods
|
220
|
+
|
221
|
+
extend_rabl_template 'api/v2/smart_proxies/main', 'api/v2/smart_proxies/pubkey'
|
222
|
+
extend_rabl_template 'api/v2/interfaces/main', 'api/v2/interfaces/execution_flag'
|
223
|
+
extend_rabl_template 'api/v2/subnets/show', 'api/v2/subnets/remote_execution_proxies'
|
224
|
+
extend_rabl_template 'api/v2/hosts/main', 'api/v2/host/main'
|
225
|
+
parameter_filter ::Subnet, :remote_execution_proxy_ids
|
226
|
+
|
227
|
+
describe_host do
|
228
|
+
multiple_actions_provider :rex_hosts_multiple_actions
|
229
|
+
overview_buttons_provider :rex_host_overview_buttons
|
230
|
+
end
|
231
|
+
|
232
|
+
# Extend Registration module
|
233
|
+
extend_allowed_registration_vars :remote_execution_interface
|
234
|
+
extend_allowed_registration_vars :setup_remote_execution_pull
|
235
|
+
ForemanTasks.dynflow.eager_load_actions!
|
236
|
+
extend_observable_events(
|
237
|
+
::Dynflow::Action.descendants.select do |klass|
|
238
|
+
klass <= ::Actions::ObservableAction
|
239
|
+
end.map(&:namespaced_event_names) +
|
240
|
+
RemoteExecutionFeature.all.pluck(:label).flat_map do |label|
|
241
|
+
[::Actions::RemoteExecution::RunHostJob, ::Actions::RemoteExecution::RunHostsJob].map do |klass|
|
242
|
+
klass.feature_job_event_names(label)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
)
|
246
|
+
end
|
@@ -91,7 +91,7 @@ module Api
|
|
91
91
|
end
|
92
92
|
|
93
93
|
test 'should create with schedule' do
|
94
|
-
@attrs[:scheduling] = { start_at: Time.now.to_s }
|
94
|
+
@attrs[:scheduling] = { start_at: (Time.now + 1.hour).to_s }
|
95
95
|
post :create, params: { job_invocation: @attrs }
|
96
96
|
invocation = ActiveSupport::JSON.decode(@response.body)
|
97
97
|
assert_equal invocation['mode'], 'future'
|
@@ -90,6 +90,35 @@ module Api
|
|
90
90
|
assert_response :unprocessable_entity
|
91
91
|
end
|
92
92
|
|
93
|
+
test 'should clone locked template' do
|
94
|
+
@template.locked = true
|
95
|
+
@template.save!
|
96
|
+
post :clone, params: { :id => @template.to_param, :job_template => {:name => 'MyClone'} }
|
97
|
+
assert_response :success
|
98
|
+
|
99
|
+
template = ActiveSupport::JSON.decode(@response.body)
|
100
|
+
assert_equal(template['locked'], false)
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'should clone template with associations' do
|
104
|
+
template2 = FactoryBot.create(:job_template)
|
105
|
+
@template.organizations << FactoryBot.create(:organization)
|
106
|
+
@template.locations << FactoryBot.create(:location)
|
107
|
+
@template.foreign_input_sets << FactoryBot.build(:foreign_input_set).tap { |fis| fis.target_template_id = template2.id }
|
108
|
+
@template.effective_user.value = 'toor'
|
109
|
+
@template.save!
|
110
|
+
|
111
|
+
post :clone, params: { :id => @template.to_param, :job_template => {:name => 'MyClone'} }
|
112
|
+
template = ActiveSupport::JSON.decode(@response.body)
|
113
|
+
|
114
|
+
clone = JobTemplate.unscoped.find(template['id'])
|
115
|
+
assert_equal(clone.organizations.sort, @template.organizations.sort)
|
116
|
+
assert_equal(clone.locations.sort, @template.locations.sort)
|
117
|
+
assert_equal(clone.foreign_input_sets.map(&:target_template_id), [template2.id])
|
118
|
+
assert_equal(clone.effective_user.value, 'toor')
|
119
|
+
assert_equal(clone.cloned_from.id, @template.id)
|
120
|
+
end
|
121
|
+
|
93
122
|
test 'should export template' do
|
94
123
|
get :export, params: { :id => @template.to_param }
|
95
124
|
User.current = users(:admin)
|
@@ -10,7 +10,7 @@ module ForemanRemoteExecution
|
|
10
10
|
let(:job_invocation) { FactoryBot.create(:job_invocation, :with_task) }
|
11
11
|
let(:host) { job_invocation.template_invocations.first.host }
|
12
12
|
let(:provider) do
|
13
|
-
provider = ::
|
13
|
+
provider = ::ScriptExecutionProvider
|
14
14
|
provider.expects(:ssh_password).with(host).returns('sshpass')
|
15
15
|
provider.expects(:effective_user_password).with(host).returns('sudopass')
|
16
16
|
provider.expects(:ssh_key_passphrase).with(host).returns('keypass')
|
@@ -28,9 +28,9 @@ class JobReportTemplateTest < ActiveSupport::TestCase
|
|
28
28
|
describe 'task reporting' do
|
29
29
|
let(:fake_outputs) do
|
30
30
|
[
|
31
|
-
{ 'output_type' => 'stderr', 'output' => "error" },
|
32
|
-
{ 'output_type' => 'stdout', 'output' => "output" },
|
33
|
-
{ 'output_type' => 'debug', 'output' => "debug" },
|
31
|
+
{ 'output_type' => 'stderr', 'output' => "error\n" },
|
32
|
+
{ 'output_type' => 'stdout', 'output' => "output\n" },
|
33
|
+
{ 'output_type' => 'debug', 'output' => "debug\n" },
|
34
34
|
]
|
35
35
|
end
|
36
36
|
let(:fake_task) { FakeTask.new(result: 'success', action_continuous_output: fake_outputs, :ended_at => Time.new(2020, 12, 1, 0, 0, 0).utc) }
|
@@ -50,9 +50,9 @@ class JobReportTemplateTest < ActiveSupport::TestCase
|
|
50
50
|
row = rows.first
|
51
51
|
assert_equal host.name, row['Host']
|
52
52
|
assert_equal 'success', row['Result']
|
53
|
-
assert_equal
|
54
|
-
assert_equal
|
55
|
-
assert_equal
|
53
|
+
assert_equal "error\n", row['stderr']
|
54
|
+
assert_equal "output\n", row['stdout']
|
55
|
+
assert_equal "debug\n", row['debug']
|
56
56
|
assert_kind_of Time, Time.zone.parse(row['Finished']), 'Parsing of time column failed'
|
57
57
|
end
|
58
58
|
end
|
@@ -5,11 +5,11 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
5
5
|
let(:providers) { RemoteExecutionProvider.providers }
|
6
6
|
it { assert_kind_of HashWithIndifferentAccess, providers }
|
7
7
|
it 'makes providers accessible using symbol' do
|
8
|
-
assert_equal
|
8
|
+
assert_equal ScriptExecutionProvider, providers[:SSH]
|
9
9
|
assert_equal ScriptExecutionProvider, providers[:script]
|
10
10
|
end
|
11
11
|
it 'makes providers accessible using string' do
|
12
|
-
assert_equal
|
12
|
+
assert_equal ScriptExecutionProvider, providers['SSH']
|
13
13
|
assert_equal ScriptExecutionProvider, providers['script']
|
14
14
|
end
|
15
15
|
end
|
@@ -27,11 +27,11 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
27
27
|
|
28
28
|
describe '.provider_for' do
|
29
29
|
it 'accepts symbols' do
|
30
|
-
assert_equal
|
30
|
+
assert_equal ScriptExecutionProvider, RemoteExecutionProvider.provider_for(:SSH)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'accepts strings' do
|
34
|
-
assert_equal
|
34
|
+
assert_equal ScriptExecutionProvider, RemoteExecutionProvider.provider_for('SSH')
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'returns a default one if unknown value is provided' do
|
@@ -81,7 +81,7 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
81
81
|
describe '.provider_proxy_features' do
|
82
82
|
it 'returns correct values' do
|
83
83
|
RemoteExecutionProvider.stubs(:providers).returns(
|
84
|
-
:SSH =>
|
84
|
+
:SSH => ScriptExecutionProvider,
|
85
85
|
:script => ScriptExecutionProvider
|
86
86
|
)
|
87
87
|
|
@@ -112,15 +112,15 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
describe
|
115
|
+
describe ScriptExecutionProvider do
|
116
116
|
before { User.current = FactoryBot.build(:user, :admin) }
|
117
117
|
after { User.current = nil }
|
118
118
|
|
119
119
|
let(:job_invocation) { FactoryBot.create(:job_invocation, :with_template) }
|
120
120
|
let(:template_invocation) { job_invocation.pattern_template_invocations.first }
|
121
121
|
let(:host) { FactoryBot.create(:host) }
|
122
|
-
let(:proxy_options) {
|
123
|
-
let(:secrets) {
|
122
|
+
let(:proxy_options) { ScriptExecutionProvider.proxy_command_options(template_invocation, host) }
|
123
|
+
let(:secrets) { ScriptExecutionProvider.secrets(host) }
|
124
124
|
|
125
125
|
describe 'effective user' do
|
126
126
|
it 'takes the effective user from value from the template invocation' do
|
@@ -153,11 +153,11 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
153
153
|
assert_equal 'sudo', proxy_options[:effective_user_method]
|
154
154
|
method_param.update!(:value => 'su')
|
155
155
|
host.clear_host_parameters_cache!
|
156
|
-
proxy_options =
|
156
|
+
proxy_options = ScriptExecutionProvider.proxy_command_options(template_invocation, host)
|
157
157
|
assert_equal 'su', proxy_options[:effective_user_method]
|
158
158
|
method_param.update!(:value => 'dzdo')
|
159
159
|
host.clear_host_parameters_cache!
|
160
|
-
proxy_options =
|
160
|
+
proxy_options = ScriptExecutionProvider.proxy_command_options(template_invocation, host)
|
161
161
|
assert_equal 'dzdo', proxy_options[:effective_user_method]
|
162
162
|
end
|
163
163
|
end
|
@@ -219,7 +219,7 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
219
219
|
|
220
220
|
it 'gets fqdn from flagged interfaces if not preferring ips' do
|
221
221
|
# falling to primary interface
|
222
|
-
assert_equal 'somehost.somedomain.org',
|
222
|
+
assert_equal 'somehost.somedomain.org', ScriptExecutionProvider.find_ip_or_hostname(host)
|
223
223
|
|
224
224
|
# execution wins if present
|
225
225
|
execution_interface = FactoryBot.build(:nic_managed,
|
@@ -228,13 +228,13 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
228
228
|
host.primary_interface.update(:execution => false)
|
229
229
|
host.interfaces.each(&:save)
|
230
230
|
host.reload
|
231
|
-
assert_equal execution_interface.fqdn,
|
231
|
+
assert_equal execution_interface.fqdn, ScriptExecutionProvider.find_ip_or_hostname(host)
|
232
232
|
end
|
233
233
|
|
234
234
|
it 'gets ip from flagged interfaces' do
|
235
235
|
host.host_params['remote_execution_connect_by_ip'] = true
|
236
236
|
# no ip address set on relevant interface - fallback to fqdn
|
237
|
-
assert_equal 'somehost.somedomain.org',
|
237
|
+
assert_equal 'somehost.somedomain.org', ScriptExecutionProvider.find_ip_or_hostname(host)
|
238
238
|
|
239
239
|
# provision interface with ip while primary without
|
240
240
|
provision_interface = FactoryBot.build(:nic_managed,
|
@@ -243,12 +243,12 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
243
243
|
host.primary_interface.update(:provision => false)
|
244
244
|
host.interfaces.each(&:save)
|
245
245
|
host.reload
|
246
|
-
assert_equal provision_interface.ip,
|
246
|
+
assert_equal provision_interface.ip, ScriptExecutionProvider.find_ip_or_hostname(host)
|
247
247
|
|
248
248
|
# both primary and provision interface have IPs: the primary wins
|
249
249
|
host.primary_interface.update(:ip => '10.0.0.2', :execution => false)
|
250
250
|
host.reload
|
251
|
-
assert_equal host.primary_interface.ip,
|
251
|
+
assert_equal host.primary_interface.ip, ScriptExecutionProvider.find_ip_or_hostname(host)
|
252
252
|
|
253
253
|
# there is an execution interface with IP: it wins
|
254
254
|
execution_interface = FactoryBot.build(:nic_managed,
|
@@ -257,7 +257,7 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
257
257
|
host.primary_interface.update(:execution => false)
|
258
258
|
host.interfaces.each(&:save)
|
259
259
|
host.reload
|
260
|
-
assert_equal execution_interface.ip,
|
260
|
+
assert_equal execution_interface.ip, ScriptExecutionProvider.find_ip_or_hostname(host)
|
261
261
|
|
262
262
|
# there is an execution interface with both IPv6 and IPv4: IPv4 is being preferred over IPv6 by default
|
263
263
|
execution_interface = FactoryBot.build(:nic_managed,
|
@@ -265,7 +265,7 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
265
265
|
host.interfaces = [execution_interface]
|
266
266
|
host.interfaces.each(&:save)
|
267
267
|
host.reload
|
268
|
-
assert_equal execution_interface.ip,
|
268
|
+
assert_equal execution_interface.ip, ScriptExecutionProvider.find_ip_or_hostname(host)
|
269
269
|
end
|
270
270
|
|
271
271
|
it 'gets ipv6 from flagged interfaces with IPv6 preference' do
|
@@ -278,7 +278,7 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
278
278
|
host.interfaces = [execution_interface]
|
279
279
|
host.interfaces.each(&:save)
|
280
280
|
host.reload
|
281
|
-
assert_equal execution_interface.ip6,
|
281
|
+
assert_equal execution_interface.ip6, ScriptExecutionProvider.find_ip_or_hostname(host)
|
282
282
|
end
|
283
283
|
|
284
284
|
it 'gets ipv6 from flagged interfaces with IPv4 preference but without IPv4 address' do
|
@@ -291,7 +291,7 @@ class RemoteExecutionProviderTest < ActiveSupport::TestCase
|
|
291
291
|
host.interfaces = [execution_interface]
|
292
292
|
host.interfaces.each(&:save)
|
293
293
|
host.reload
|
294
|
-
assert_equal execution_interface.ip6,
|
294
|
+
assert_equal execution_interface.ip6, ScriptExecutionProvider.find_ip_or_hostname(host)
|
295
295
|
end
|
296
296
|
end
|
297
297
|
end
|