foreman_acd 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +75 -0
- data/app/controllers/foreman_acd/app_instances_controller.rb +19 -2
- data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +1 -1
- data/app/controllers/foreman_acd/remote_execution_controller.rb +37 -21
- data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +12 -7
- data/app/lib/actions/foreman_acd/run_configurator.rb +10 -7
- data/app/models/concerns/foreman_acd/host_managed_extensions.rb +2 -2
- data/app/models/foreman_acd/acd_provider.rb +7 -1
- data/app/models/foreman_acd/ansible_playbook.rb +2 -1
- data/app/models/foreman_acd/app_instance.rb +1 -1
- data/app/services/foreman_acd/acd_proxy_proxy_selector.rb +17 -0
- data/app/services/foreman_acd/app_configurator.rb +59 -15
- data/app/services/foreman_acd/app_deployer.rb +8 -2
- data/app/services/foreman_acd/inventory_creator.rb +14 -0
- data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +41 -7
- data/app/views/foreman_acd/app_definitions/_form.html.erb +1 -1
- data/app/views/foreman_acd/app_instances/_form.html.erb +1 -1
- data/app/views/foreman_acd/app_instances/index.html.erb +5 -3
- data/app/views/foreman_acd/app_instances/report.html.erb +1 -1
- data/app/views/templates/job/run_acd_ansible_playbook.erb +1 -1
- data/config/routes.rb +3 -0
- data/db/migrate/20210316151145_add_git_commit_to_ansible_playbooks.rb +8 -0
- data/db/migrate/20210503122809_add_git_url_to_ansible_playbooks.rb +8 -0
- data/db/seeds.d/75-job_templates.rb +1 -1
- data/lib/foreman_acd.rb +12 -0
- data/lib/foreman_acd/engine.rb +26 -4
- data/lib/foreman_acd/plugin.rb +0 -9
- data/lib/foreman_acd/version.rb +1 -1
- data/lib/tasks/foreman_acd_tasks.rake +0 -12
- data/package.json +8 -8
- data/test/controllers/ansible_playbooks_controller_test.rb +1 -1
- data/test/controllers/app_instances_controller_test.rb +8 -3
- data/test/controllers/ui_acd_controller_test.rb +22 -6
- data/test/factories/foreman_acd_factories.rb +18 -4
- data/test/models/acd_provider_test.rb +37 -0
- data/test/models/ansible_playbook_test.rb +11 -0
- data/test/models/app_definition_test.rb +1 -1
- data/test/models/app_instance_test.rb +2 -0
- data/test/models/concerns/host_extensions_test.rb +26 -0
- data/test/models/foreman_host_test.rb +12 -0
- data/webpack/__mocks__/foremanReact/API.js +2 -0
- data/webpack/__mocks__/foremanReact/common/I18n.js +3 -0
- data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
- data/webpack/__mocks__/foremanReact/components/ForemanModal.js +7 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js +2 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/TextInput.js +2 -0
- data/webpack/__mocks__/foremanReact/components/hosts/powerStatus.js +1 -0
- data/webpack/__snapshots__/helper.test.js.snap +14 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +1 -1
- data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionConfData_1.fixtures.js +288 -0
- data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionReducer.fixtures.js +79 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +25 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionReducer.test.js +119 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +41 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +200 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionReducer.test.js.snap +3033 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +299 -0
- data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +1 -0
- data/webpack/components/ApplicationDefinition/components/__tests__/AnsiblePlaybookSelector.test.js +41 -0
- data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +121 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.js +3 -5
- data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceConfData_1.fixtures.js +263 -0
- data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +78 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +23 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +119 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +44 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +209 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +2719 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +276 -0
- data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportData_1.fixtures.js +349 -0
- data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportReducer.fixtures.js +20 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js +47 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportReducer.test.js +41 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportSelectors.test.js +26 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +130 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap +718 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportSelectors.test.js.snap +347 -0
- data/webpack/components/ApplicationInstanceReport/components/__tests__/ReportViewer.test.js +24 -0
- data/webpack/components/ApplicationInstanceReport/components/__tests__/__snapshots__/ReportViewer.test.js.snap +24 -0
- data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +2 -21
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +116 -84
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +10 -4
- data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +36 -46
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +31 -25
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +2 -126
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +1483 -872
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +117 -79
- data/webpack/components/SyncGitRepo/SyncGitRepo.js +210 -0
- data/webpack/components/SyncGitRepo/SyncGitRepo.scss +1 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +124 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +9 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoReducer.js +80 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoSelectors.js +6 -0
- data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoConfData_1.fixtures.js +7 -0
- data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoReducer.fixtures.js +44 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepo.test.js +27 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoReducer.test.js +95 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoSelectors.test.js +32 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +30 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoReducer.test.js.snap +137 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoSelectors.test.js.snap +13 -0
- data/webpack/components/SyncGitRepo/components/FormTextInput.js +42 -0
- data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +46 -0
- data/webpack/components/SyncGitRepo/index.js +28 -0
- data/webpack/components/common/ExtTextInput.js +43 -0
- data/webpack/components/common/__tests__/EditTableEntry.test.js +53 -0
- data/webpack/components/common/__tests__/LockTableEntry.test.js +35 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +2 -2
- data/webpack/components/common/__tests__/__snapshots__/EditTableEntry.test.js.snap +81 -0
- data/webpack/components/common/__tests__/__snapshots__/LockTableEntry.test.js.snap +60 -0
- data/webpack/helper.js +15 -1
- data/webpack/helper.test.js +37 -0
- data/webpack/index.js +2 -0
- data/webpack/reducer.js +4 -0
- metadata +92 -11
- data/webpack/components/common/EasyHeaderFormatter.js +0 -18
- data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +0 -35
- data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +0 -41
@@ -9,12 +9,18 @@ module ForemanAcd
|
|
9
9
|
@app_instance = app_instance
|
10
10
|
end
|
11
11
|
|
12
|
-
def deploy
|
12
|
+
def deploy(safe_deploy)
|
13
13
|
output = []
|
14
14
|
services = JSON.parse(@app_instance.app_definition.services)
|
15
15
|
all_hosts = []
|
16
16
|
|
17
|
-
|
17
|
+
foreman_hosts = if safe_deploy
|
18
|
+
@app_instance.foreman_hosts.find(safe_deploy)
|
19
|
+
else
|
20
|
+
@app_instance.foreman_hosts
|
21
|
+
end
|
22
|
+
|
23
|
+
foreman_hosts.each do |foreman_host|
|
18
24
|
service_data = services.select { |k| k['id'] == foreman_host.service.to_i }.first
|
19
25
|
host_params = set_host_params(foreman_host, service_data)
|
20
26
|
|
@@ -36,6 +36,7 @@ module ForemanAcd
|
|
36
36
|
|
37
37
|
# in case there is no ansible_user defined, set "root" as default.
|
38
38
|
ansible_vars['ansible_user'] = 'root' unless ansible_vars.key?('ansible_user')
|
39
|
+
ansible_vars['ansible_ssh_private_key_file'] = ansible_or_rex_ssh_private_key(foreman_host.host)
|
39
40
|
|
40
41
|
children[ansible_group]['hosts'][foreman_host.host.name] = ansible_vars
|
41
42
|
end
|
@@ -45,6 +46,19 @@ module ForemanAcd
|
|
45
46
|
|
46
47
|
private
|
47
48
|
|
49
|
+
def ansible_or_rex_ssh_private_key(host)
|
50
|
+
ansible_private_file = host_setting(host, 'ansible_ssh_private_key_file')
|
51
|
+
if !ansible_private_file.empty?
|
52
|
+
ansible_private_file
|
53
|
+
else
|
54
|
+
ForemanRemoteExecutionCore.settings[:ssh_identity_key_file]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def host_setting(host, setting)
|
59
|
+
host.params[setting] || Setting[setting]
|
60
|
+
end
|
61
|
+
|
48
62
|
def inventory_all_vars
|
49
63
|
JSON.parse(@app_instance.ansible_vars_all).map do |a|
|
50
64
|
{ a['name'] => a['value'] }
|
@@ -1,3 +1,39 @@
|
|
1
|
+
<% content_for(:javascripts) do %>
|
2
|
+
<%= webpacked_plugins_js_for :foreman_acd %>
|
3
|
+
<% end %>
|
4
|
+
<% content_for(:stylesheets) do %>
|
5
|
+
<%= webpacked_plugins_css_for :foreman_acd %>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<%
|
9
|
+
if @ansible_playbook.new_record?
|
10
|
+
json = {
|
11
|
+
"scmTypes": {"directory" => "directory", "git" => "git"},
|
12
|
+
"mode": "newPlaybook",
|
13
|
+
"organization": current_organization,
|
14
|
+
"location": current_location,
|
15
|
+
"path": "",
|
16
|
+
"gitUrl": "",
|
17
|
+
"gitCommit": "",
|
18
|
+
"scmType": "",
|
19
|
+
"appDefinitions": [],
|
20
|
+
}
|
21
|
+
|
22
|
+
else
|
23
|
+
json = {
|
24
|
+
"scmTypes": {"directory" => "directory", "git" => "git"},
|
25
|
+
"mode": "editPlaybook",
|
26
|
+
"organization": current_organization,
|
27
|
+
"location": current_location,
|
28
|
+
"path": @ansible_playbook.path,
|
29
|
+
"gitUrl": @ansible_playbook.git_url,
|
30
|
+
"gitCommit": @ansible_playbook.git_commit,
|
31
|
+
"scmType": @ansible_playbook.scm_type,
|
32
|
+
"appDefinitions": @ansible_playbook.app_definitions
|
33
|
+
}
|
34
|
+
end
|
35
|
+
%>
|
36
|
+
|
1
37
|
<%= form_for @ansible_playbook, :url => (@ansible_playbook.new_record? ? ansible_playbooks_path : ansible_playbook_path(:id => @ansible_playbook.id)) do |f| %>
|
2
38
|
<%= base_errors_for @ansible_playbook %>
|
3
39
|
|
@@ -13,18 +49,16 @@
|
|
13
49
|
|
14
50
|
<div class="tab-content">
|
15
51
|
<div class="tab-pane active" id="primary">
|
52
|
+
|
16
53
|
<%= text_f f, :name %>
|
17
54
|
<%= text_f f, :description %>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
%>
|
22
|
-
<%= text_f f, :path, :required => true %>
|
55
|
+
<div id='ansible_playbook'>
|
56
|
+
<%= react_component('SyncGitRepo', :data => json,) %>
|
57
|
+
</div>
|
23
58
|
<%= text_f f, :playfile, :required => true %>
|
24
59
|
</div>
|
25
|
-
|
60
|
+
|
26
61
|
<%= render 'taxonomies/loc_org_tabs', :f => f, :obj => @ansible_playbook %>
|
27
62
|
</div>
|
28
|
-
|
29
63
|
<%= submit_or_cancel f %>
|
30
64
|
<% end %>
|
@@ -44,7 +44,7 @@
|
|
44
44
|
<%= text_f f, :description %>
|
45
45
|
|
46
46
|
<div id='app_definition'></div>
|
47
|
-
<%=
|
47
|
+
<%= react_component('ApplicationDefinition', :data => json) %>
|
48
48
|
</div>
|
49
49
|
|
50
50
|
<%= render 'taxonomies/loc_org_tabs', :f => f, :obj => @app_definition %>
|
@@ -89,10 +89,12 @@
|
|
89
89
|
<div class="modal-body">
|
90
90
|
<p><%= _('Confirm to deploy ') %><%= app_instance%></p>
|
91
91
|
<%= form_tag deploy_app_instance_path(:id => app_instance.id), :method => :post do %>
|
92
|
-
<!-- TODO: Add safe-deploy method with delete all hosts option
|
93
92
|
<% if app_instance.foreman_hosts.where.not(:host_id => [nil, false]).any? %>
|
94
|
-
|
95
|
-
|
93
|
+
<ul>
|
94
|
+
<li><%= check_box_tag 'delete_hosts'-%><%= _('Delete all hosts before deploying ') %><%= app_instance%></li>
|
95
|
+
<li><%= check_box_tag 'safe_deploy' -%><%= _('Deploy only new and changed hosts for ') %><%= app_instance%></li>
|
96
|
+
</ul>
|
97
|
+
<% end %>
|
96
98
|
</div>
|
97
99
|
<div class="modal-footer">
|
98
100
|
<button type="button" class="btn btn-danger" data-dismiss="modal"><%= _('Cancel') %></button>
|
@@ -3,7 +3,7 @@ kind: job_template
|
|
3
3
|
name: Run ACD Ansible Playbook - ACD Default
|
4
4
|
model: JobTemplate
|
5
5
|
job_category: Application Centric Deployment
|
6
|
-
description_format: "Run Ansible playbook
|
6
|
+
description_format: "Run Ansible playbook to configure ACD application %{application_name}"
|
7
7
|
feature: run_acd_ansible_playbook
|
8
8
|
provider_type: ACD
|
9
9
|
template_inputs:
|
data/config/routes.rb
CHANGED
@@ -5,9 +5,12 @@ Rails.application.routes.draw do
|
|
5
5
|
resources :ansible_playbooks, :controller => 'foreman_acd/ansible_playbooks' do
|
6
6
|
collection do
|
7
7
|
get 'auto_complete_search'
|
8
|
+
put 'sync_git_repo'
|
9
|
+
post 'sync_git_repo'
|
8
10
|
end
|
9
11
|
|
10
12
|
member do
|
13
|
+
post 'sync_git_repo'
|
11
14
|
get 'import_vars'
|
12
15
|
end
|
13
16
|
end
|
@@ -4,7 +4,7 @@ User.as_anonymous_admin do
|
|
4
4
|
JobTemplate.without_auditing do
|
5
5
|
Dir[File.join("#{ForemanAcd::Engine.root}/app/views/templates/**/*.erb")].each do |template|
|
6
6
|
sync = !Rails.env.test? && Setting[:remote_execution_sync_templates]
|
7
|
-
template = JobTemplate.import_raw!(File.read(template), :default => true, :
|
7
|
+
template = JobTemplate.import_raw!(File.read(template), :default => true, :lock => true, :update => sync)
|
8
8
|
|
9
9
|
template.organizations << Organization.unscoped.all if template&.organizations&.empty?
|
10
10
|
template.locations << Location.unscoped.all if template&.locations&.empty?
|
data/lib/foreman_acd.rb
CHANGED
@@ -4,4 +4,16 @@ require 'foreman_acd/engine'
|
|
4
4
|
|
5
5
|
# Module required to start the Foreman Rails engine
|
6
6
|
module ForemanAcd
|
7
|
+
def self.acd_base_path
|
8
|
+
'/var/lib/foreman/foreman_acd/'
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.ansible_playbook_path
|
12
|
+
File.join(acd_base_path, 'ansible-playbooks')
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.proxy_setting
|
16
|
+
HttpProxy.default_global_content_proxy&.full_url ||
|
17
|
+
Setting[:http_proxy]
|
18
|
+
end
|
7
19
|
end
|
data/lib/foreman_acd/engine.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'foreman_remote_execution'
|
4
|
+
require 'git'
|
4
5
|
|
6
|
+
# The ForemanAcd module
|
5
7
|
module ForemanAcd
|
6
8
|
# This engine connects ForemanAcd with Foreman core
|
7
9
|
class Engine < ::Rails::Engine
|
@@ -49,13 +51,33 @@ module ForemanAcd
|
|
49
51
|
end
|
50
52
|
|
51
53
|
config.to_prepare do
|
52
|
-
RemoteExecutionProvider.register(:ACD, AcdProvider)
|
53
54
|
::Taxonomy.include ForemanAcd::TaxonomyExtensions
|
54
55
|
::Host::Managed.prepend ForemanAcd::HostManagedExtensions
|
55
|
-
end
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
RemoteExecutionProvider.register(:ACD, AcdProvider)
|
58
|
+
ForemanAcd.register_rex_feature
|
59
59
|
end
|
60
60
|
end
|
61
|
+
|
62
|
+
def self.with_katello?
|
63
|
+
defined?(::Katello)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.with_remote_execution?
|
67
|
+
RemoteExecutionFeature
|
68
|
+
rescue StandardError
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.register_rex_feature
|
73
|
+
return unless ForemanAcd.with_remote_execution?
|
74
|
+
RemoteExecutionFeature.register(
|
75
|
+
:run_acd_ansible_playbook,
|
76
|
+
N_('Run playbook for ACD'),
|
77
|
+
{
|
78
|
+
:description => N_('Run an Ansible playbook to configure ACD application'),
|
79
|
+
:provided_inputs => %w[application_name playbook_name playbook_path inventory_path]
|
80
|
+
}
|
81
|
+
)
|
82
|
+
end
|
61
83
|
end
|
data/lib/foreman_acd/plugin.rb
CHANGED
@@ -160,13 +160,4 @@ Foreman::Plugin.register :foreman_acd do
|
|
160
160
|
:acd_foreman_hosts, :view_smart_proxies]
|
161
161
|
|
162
162
|
add_all_permissions_to_default_roles
|
163
|
-
|
164
|
-
RemoteExecutionFeature.register(
|
165
|
-
:run_acd_ansible_playbook,
|
166
|
-
N_('Run playbook for ACD'),
|
167
|
-
{
|
168
|
-
:description => N_('Run an Ansible playbook to configure ACD application'),
|
169
|
-
:provided_inputs => %w[application_name playbook_name playbook_path inventory_path]
|
170
|
-
}
|
171
|
-
)
|
172
163
|
end
|
data/lib/foreman_acd/version.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'rake/testtask'
|
4
|
-
|
5
|
-
# Tasks
|
6
|
-
namespace :foreman_acd do
|
7
|
-
namespace :example do
|
8
|
-
desc 'Example Task'
|
9
|
-
task :task => :environment do
|
10
|
-
# Task goes here
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
3
|
# Tests
|
16
4
|
namespace :test do
|
17
5
|
desc 'Test ForemanAcd'
|
data/package.json
CHANGED
@@ -14,26 +14,26 @@
|
|
14
14
|
"@theforeman/vendor-dev": "^1.7.0",
|
15
15
|
"babel-eslint": "^8.2.1",
|
16
16
|
"babel-jest": "^23.6.0",
|
17
|
-
"babel-plugin-dynamic-import-node": "^2.
|
17
|
+
"babel-plugin-dynamic-import-node": "^2.3.3",
|
18
|
+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
18
19
|
"babel-plugin-transform-class-properties": "^6.24.1",
|
19
20
|
"babel-plugin-transform-object-assign": "^6.22.0",
|
20
21
|
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
21
|
-
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
22
22
|
"babel-preset-env": "^1.6.0",
|
23
23
|
"babel-preset-react": "^6.24.1",
|
24
|
-
"enzyme": "^3.
|
25
|
-
"enzyme-adapter-react-16": "^1.
|
26
|
-
"enzyme-to-json": "^3.
|
24
|
+
"enzyme": "^3.11.0",
|
25
|
+
"enzyme-adapter-react-16": "^1.15.6",
|
26
|
+
"enzyme-to-json": "^3.6.1",
|
27
27
|
"eslint": "^4.18.1",
|
28
|
-
"eslint-plugin-import": "^2.
|
28
|
+
"eslint-plugin-import": "^2.22.1",
|
29
29
|
"eslint-plugin-jest": "^21.2.0",
|
30
30
|
"eslint-plugin-patternfly-react": "^0.2.1",
|
31
|
-
"eslint-plugin-react": "^7.
|
31
|
+
"eslint-plugin-react": "^7.22.0",
|
32
32
|
"identity-obj-proxy": "^3.0.0",
|
33
|
-
"lodash": "^4.17.11",
|
34
33
|
"jest": "^23.6.0",
|
35
34
|
"jest-cli": "^23.6.0",
|
36
35
|
"jest-prop-type-error": "^1.1.0",
|
36
|
+
"lodash": "^4.17.21",
|
37
37
|
"react-redux-test-utils": "^0.1.1",
|
38
38
|
"sortabular": "~1.5.1",
|
39
39
|
"table-resolver": "~3.2.0"
|
@@ -11,17 +11,22 @@ module ForemanAcd
|
|
11
11
|
@model = ForemanAcd::AppInstance.first
|
12
12
|
end
|
13
13
|
|
14
|
+
def set_session_user
|
15
|
+
org_a = Organization.find_by(:name => 'Organization 1')
|
16
|
+
loc_a = Location.find_by(:name => 'Location 1')
|
17
|
+
super.merge(:location_id => loc_a.id, :organization_id => org_a.id)
|
18
|
+
end
|
19
|
+
|
14
20
|
basic_index_test('app_instances')
|
15
21
|
basic_new_test
|
16
|
-
basic_edit_test('app_instance')
|
22
|
+
# basic_edit_test('app_instance')
|
17
23
|
|
18
24
|
test 'should destroy app instance' do
|
19
25
|
assert_difference('AppInstance.count', -1) do
|
20
|
-
delete :
|
26
|
+
delete :destroy_with_hosts,
|
21
27
|
:params => { :id => @model.id },
|
22
28
|
:session => set_session_user
|
23
29
|
end
|
24
|
-
assert_redirected_to app_instances_url
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -19,20 +19,36 @@ class UiAcdControllerTest < ActionController::TestCase
|
|
19
19
|
get :app, :params => { :id => app_def.id }, :session => set_session_user
|
20
20
|
assert_response :success
|
21
21
|
|
22
|
+
json_app_services = JSON.parse(app_def.services)
|
23
|
+
json_app_all = JSON.parse(app_def.ansible_vars_all)
|
24
|
+
parsed_services_response = JSON.parse(json_response['app_definition']['services'])
|
25
|
+
parsed_all_response = JSON.parse(json_response['app_definition']['ansible_vars_all'])
|
26
|
+
|
22
27
|
assert_equal app_def.name, json_response['app_definition']['name']
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
25
|
-
assert_equal
|
26
|
-
assert_equal app_def.hostgroup.ptable.name, json_response['fdata']['ptables'][0]['name']
|
28
|
+
assert_equal json_app_services.first['name'], parsed_services_response.first['name']
|
29
|
+
assert_equal json_app_services.first['ansibleGroup'], parsed_services_response.first['ansibleGroup']
|
30
|
+
assert_equal json_app_all.first['name'], parsed_all_response.first['name']
|
27
31
|
end
|
28
32
|
|
29
|
-
test 'get
|
33
|
+
test 'get foreman data json' do
|
30
34
|
hostgroup = FactoryBot.create(:hostgroup, :with_domain, :with_os, :with_environment)
|
31
|
-
get :
|
35
|
+
get :foreman_data, :params => { :id => hostgroup.id }, :session => set_session_user
|
32
36
|
assert_response :success
|
33
37
|
|
38
|
+
assert_equal hostgroup.id, json_response['hostgroup_id']
|
34
39
|
assert_equal hostgroup.environment.name, json_response['environments'][0]['name']
|
35
40
|
assert_equal hostgroup.domain.name, json_response['domains'][0]['name']
|
36
41
|
assert_equal hostgroup.ptable.name, json_response['ptables'][0]['name']
|
37
42
|
end
|
43
|
+
|
44
|
+
test 'get ansible data json' do
|
45
|
+
ansible_playbook = FactoryBot.create(:ansible_playbook)
|
46
|
+
get :ansible_data, :params => { :id => ansible_playbook.id }, :session => set_session_user
|
47
|
+
assert_response :success
|
48
|
+
|
49
|
+
json_playbook = JSON.parse(ansible_playbook.vars)
|
50
|
+
assert_equal ansible_playbook.name, json_response['name']
|
51
|
+
assert_equal json_playbook['dbservers']['mysqlservice'], json_response['groups']['dbservers']['mysqlservice']
|
52
|
+
assert_equal json_playbook['all']['repository'], json_response['groups']['all']['repository']
|
53
|
+
end
|
38
54
|
end
|
@@ -1,17 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
FactoryBot.define do
|
4
|
+
factory :ansible_playbook, :class => 'ForemanAcd::AnsiblePlaybook' do
|
5
|
+
sequence(:name) { |n| "ansible_playbook#{n}" }
|
6
|
+
sequence(:description) { |n| "description#{n}" }
|
7
|
+
scm_type { 'directory' }
|
8
|
+
path { '/home/vagrant/acd_examples/ansible-playbook' }
|
9
|
+
playfile { 'site.yml' }
|
10
|
+
vars { '{"dbservers":{"mysqlservice":"mysqld","mysql_port":3306,"dbuser":"webapp","dbname":"ANSAP01","upassword":"Bond@007","masterpassword":"MySQL@007"},"all":{"repository":"https://github.com/bennojoy/mywebapp.git"},"webservers":{"dummy_var":0}}' }
|
11
|
+
end
|
12
|
+
|
4
13
|
factory :app_definition, :class => 'ForemanAcd::AppDefinition' do
|
5
14
|
sequence(:name) { |n| "app_definition#{n}" }
|
6
15
|
sequence(:description) { |n| "description#{n}" }
|
7
|
-
|
8
|
-
|
16
|
+
ansible_playbook
|
17
|
+
services do
|
18
|
+
'[{"id":1,"name":"DB","description":"","hostgroup":"1","ansibleGroup":"dbservers","minCount":"","maxCount":"","foremanParameters":[],"ansibleParameters":[{"id":0,"name":"mysqlservice","value":"mysqld"},{"id":1,"name":"mysql_port","value":"3306"},{"id":2,"name":"dbuser","value":"webapp"},{"id":3,"name":"dbname","value":"ANSAP01"},{"id":4,"name":"upassword","value":"Bond@007"},{"id":5,"name":"masterpassword","value":"MySQL@007"}]},{"id":2,"name":"Web","description":"","hostgroup":"1","ansibleGroup":"webservers","minCount":"","maxCount":"","foremanParameters":[],"ansibleParameters":[{"id":0,"name":"dummy_var","value":"0"}]}]'
|
19
|
+
end
|
20
|
+
ansible_vars_all { '[{"id":0,"name":"repository","value":"https://github.com/bennojoy/mywebapp.git"}]' }
|
9
21
|
end
|
10
22
|
|
11
23
|
factory :app_instance, :class => 'ForemanAcd::AppInstance' do
|
12
24
|
sequence(:name) { |n| "app_instance#{n}" }
|
13
|
-
app_definition { FactoryBot.create(:app_definition) }
|
14
25
|
sequence(:description) { |n| "description#{n}" }
|
15
|
-
|
26
|
+
app_definition
|
27
|
+
location { Location.find_by(:name => 'Location 1') }
|
28
|
+
organization { Organization.find_by(:name => 'Organization 1') }
|
29
|
+
ansible_vars_all { '[{"id":0,"name":"repository","value":"https://github.com/bennojoy/mywebapp.git"}]' }
|
16
30
|
end
|
17
31
|
end
|