foreman_acd 0.2.1 → 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/README.md +107 -56
- data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +199 -0
- data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +72 -0
- data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -0
- data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +62 -0
- data/app/controllers/foreman_acd/app_definitions_controller.rb +19 -10
- data/app/controllers/foreman_acd/app_instances_controller.rb +111 -137
- data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
- data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
- data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
- data/app/controllers/foreman_acd/remote_execution_controller.rb +62 -0
- data/app/controllers/ui_acd_controller.rb +20 -3
- data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +47 -0
- data/app/lib/actions/foreman_acd/run_configurator.rb +44 -0
- data/app/models/concerns/foreman_acd/host_managed_extensions.rb +51 -0
- data/app/models/foreman_acd/acd_provider.rb +36 -0
- data/app/models/foreman_acd/ansible_playbook.rb +68 -0
- data/app/models/foreman_acd/app_definition.rb +25 -0
- data/app/models/foreman_acd/app_instance.rb +42 -0
- data/app/models/foreman_acd/foreman_host.rb +23 -0
- data/app/models/foreman_acd/taxonomy_extensions.rb +17 -0
- data/app/services/foreman_acd/acd_proxy_proxy_selector.rb +17 -0
- data/app/services/foreman_acd/app_configurator.rb +98 -0
- data/app/services/foreman_acd/app_deployer.rb +157 -0
- data/app/services/foreman_acd/inventory_creator.rb +68 -0
- data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +64 -0
- data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +11 -0
- data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
- data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +9 -0
- data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +9 -0
- data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +5 -0
- data/app/views/foreman_acd/app_definitions/_form.html.erb +34 -12
- data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -0
- data/app/views/foreman_acd/app_definitions/index.html.erb +4 -4
- data/app/views/foreman_acd/app_instances/_form.html.erb +11 -9
- data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
- data/app/views/foreman_acd/app_instances/index.html.erb +89 -10
- data/app/views/foreman_acd/app_instances/report.html.erb +6 -3
- data/app/views/templates/job/run_acd_ansible_playbook.erb +62 -0
- data/app/views/ui_acd/ansible_data.json.rabl +6 -0
- data/app/views/ui_acd/app.json.rabl +6 -2
- data/app/views/ui_acd/app_definition.json.rabl +1 -1
- data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
- data/config/routes.rb +32 -2
- data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
- data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
- data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +8 -0
- data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +8 -0
- data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
- data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
- data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
- data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
- data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
- data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
- data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -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/62_acd_proxy_feature.rb +4 -0
- data/db/seeds.d/75-job_templates.rb +13 -0
- data/lib/foreman_acd.rb +12 -0
- data/lib/foreman_acd/engine.rb +43 -3
- data/lib/foreman_acd/plugin.rb +88 -22
- data/lib/foreman_acd/version.rb +1 -1
- data/lib/tasks/foreman_acd_tasks.rake +0 -12
- data/locale/en/foreman_acd.edit.po +326 -0
- data/locale/en/foreman_acd.po +232 -2
- data/locale/en/foreman_acd.po.time_stamp +0 -0
- data/locale/foreman_acd.pot +343 -8
- data/package.json +9 -9
- data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
- 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 +159 -29
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +106 -14
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +8 -2
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +143 -21
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +3 -0
- 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 +50 -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/ApplicationDefinition/index.js +6 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.js +151 -44
- data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +47 -10
- data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +5 -2
- data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +114 -28
- data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +3 -1
- 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/ApplicationInstance/components/Service.js +1 -1
- data/webpack/components/ApplicationInstance/index.js +4 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +53 -60
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +17 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +7 -51
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -4
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +4 -18
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +0 -1
- 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/ReportViewer.js +1 -1
- 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/ApplicationInstanceReport/index.js +0 -2
- data/webpack/components/ParameterSelection/ParameterSelection.js +85 -50
- data/webpack/components/ParameterSelection/ParameterSelectionActions.js +68 -62
- data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +6 -3
- data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +0 -32
- data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +47 -35
- data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +2 -2
- 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/ParameterSelection/index.js +4 -4
- 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/DeleteTableEntry.js +3 -3
- data/webpack/components/common/EditTableEntry.js +50 -0
- data/webpack/components/common/ExtTextInput.js +43 -0
- data/webpack/components/common/LockTableEntry.js +60 -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 +18 -11
- metadata +184 -10
- data/app/views/foreman_acd/app_instances/deploy.html.erb +0 -19
- data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +0 -35
- data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +0 -41
@@ -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
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanAcd
|
6
|
+
# ACD Provider Test
|
7
|
+
class AcdProviderTest < ActiveSupport::TestCase
|
8
|
+
describe '.provider_names' do
|
9
|
+
let(:provider_names) { AcdProvider.provider_names }
|
10
|
+
|
11
|
+
it 'returns only strings' do
|
12
|
+
provider_names.each do |name|
|
13
|
+
_(name).must_be_kind_of String
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'provider is registetered under :custom symbol' do
|
18
|
+
before { AcdProvider.register(:ACD, String) }
|
19
|
+
it { _(provider_names).must_include 'ACD' }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe AcdProvider do
|
24
|
+
before { User.current = FactoryBot.build(:user, :admin) }
|
25
|
+
after { User.current = nil }
|
26
|
+
|
27
|
+
before do
|
28
|
+
Setting::RemoteExecution.load_defaults
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:job_invocation) { FactoryBot.create(:job_invocation, :with_template) }
|
32
|
+
let(:template_invocation) { job_invocation.pattern_template_invocations.first }
|
33
|
+
let(:host) { FactoryBot.create(:host) }
|
34
|
+
let(:proxy_options) { AcdProvider.proxy_command_options(template_invocation, host) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanAcd
|
6
|
+
# Ansible Playbook Model tests
|
7
|
+
class AnsiblePlaybookTest < ActiveSupport::TestCase
|
8
|
+
should validate_presence_of(:name)
|
9
|
+
should validate_uniqueness_of(:name)
|
10
|
+
end
|
11
|
+
end
|
@@ -7,7 +7,7 @@ module ForemanAcd
|
|
7
7
|
class AppDefinitionTest < ActiveSupport::TestCase
|
8
8
|
should validate_presence_of(:name)
|
9
9
|
should validate_uniqueness_of(:name)
|
10
|
-
should belong_to(:
|
10
|
+
should belong_to(:ansible_playbook)
|
11
11
|
should have_many(:app_instances).dependent(:destroy)
|
12
12
|
end
|
13
13
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanAcd
|
6
|
+
# Host Extensions Test
|
7
|
+
class HostExtensionsTest < ActiveSupport::TestCase
|
8
|
+
setup do
|
9
|
+
User.current = users :admin
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'host was deployed via acd?' do
|
13
|
+
host = FactoryBot.create :host
|
14
|
+
app = FactoryBot.create :app_instance
|
15
|
+
|
16
|
+
foreman_host = app.foreman_hosts.create(:hostname => host.name,
|
17
|
+
:service => 'DB',
|
18
|
+
:description => 'Description',
|
19
|
+
:foremanParameters => nil,
|
20
|
+
:ansibleParameters => nil)
|
21
|
+
foreman_host.host = host
|
22
|
+
foreman_host.save
|
23
|
+
assert host.deployed_via_acd?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module ForemanAcd
|
6
|
+
# ForemanHost Model tests
|
7
|
+
class ForemanHostTest < ActiveSupport::TestCase
|
8
|
+
should validate_presence_of(:hostname)
|
9
|
+
should belong_to(:app_instance)
|
10
|
+
should belong_to(:host)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
export const PowerStatus = () => jest.fn();
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import $ from 'jquery';
|
1
2
|
import React, { useState } from 'react'
|
2
3
|
import PropTypes from 'prop-types';
|
3
4
|
import {
|
@@ -10,7 +11,10 @@ import Select from 'foremanReact/components/common/forms/Select';
|
|
10
11
|
import ParameterSelection from '../ParameterSelection';
|
11
12
|
import AddTableEntry from '../common/AddTableEntry';
|
12
13
|
import DeleteTableEntry from '../common/DeleteTableEntry';
|
13
|
-
import RailsData from '../common/RailsData'
|
14
|
+
import RailsData from '../common/RailsData';
|
15
|
+
import AnsiblePlaybookSelector from './components/AnsiblePlaybookSelector';
|
16
|
+
import { translate as __ } from 'foremanReact/common/I18n';
|
17
|
+
import { EasyHeaderFormatter } from '../../helper';
|
14
18
|
|
15
19
|
import {
|
16
20
|
Table,
|
@@ -18,6 +22,11 @@ import {
|
|
18
22
|
inlineEditFormatterFactory,
|
19
23
|
} from 'patternfly-react';
|
20
24
|
|
25
|
+
import {
|
26
|
+
PARAMETER_SELECTION_PARAM_TYPE_FOREMAN,
|
27
|
+
PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE,
|
28
|
+
} from '../ParameterSelection/ParameterSelectionConstants';
|
29
|
+
|
21
30
|
class ApplicationDefinition extends React.Component {
|
22
31
|
|
23
32
|
constructor(props) {
|
@@ -28,16 +37,34 @@ class ApplicationDefinition extends React.Component {
|
|
28
37
|
return (rowData.backup !== undefined);
|
29
38
|
}
|
30
39
|
|
40
|
+
createAnsibleGroupObject(ansibleGroups, withAll=false) {
|
41
|
+
const ansibleGroupObj = {};
|
42
|
+
|
43
|
+
const ansibleGroupArray = Object.keys(ansibleGroups);
|
44
|
+
ansibleGroupArray.forEach(e => (ansibleGroupObj[e] = e));
|
45
|
+
|
46
|
+
if ((withAll === false) && (ansibleGroupObj.hasOwnProperty('all'))) {
|
47
|
+
delete ansibleGroupObj.all;
|
48
|
+
}
|
49
|
+
|
50
|
+
return ansibleGroupObj;
|
51
|
+
}
|
52
|
+
|
53
|
+
addTableEntryAllowed() {
|
54
|
+
return this.props.editMode || this.props.ansiblePlaybook.id == ''
|
55
|
+
}
|
56
|
+
|
31
57
|
componentDidMount() {
|
32
58
|
const {
|
33
|
-
data: { services, hostgroups },
|
59
|
+
data: { mode, ansiblePlaybook, ansibleDataUrl, services, ansibleVarsAll, hostgroups },
|
34
60
|
initApplicationDefinition,
|
35
61
|
addApplicationDefinitionService,
|
36
62
|
deleteApplicationDefinitionService,
|
37
63
|
activateEditApplicationDefinitionService,
|
38
64
|
changeEditApplicationDefinitionService,
|
39
|
-
|
40
|
-
|
65
|
+
openForemanParameterSelectionModal,
|
66
|
+
openAnsibleParameterSelectionModal,
|
67
|
+
loadAnsibleData,
|
41
68
|
} = this.props;
|
42
69
|
|
43
70
|
const inlineEditButtonsFormatter = inlineEditFormatterFactory({
|
@@ -48,14 +75,23 @@ class ApplicationDefinition extends React.Component {
|
|
48
75
|
bsStyle="default"
|
49
76
|
onClick={() => activateEditApplicationDefinitionService(additionalData)}
|
50
77
|
>
|
51
|
-
<Icon type="pf" name="edit" />
|
78
|
+
<Icon type="pf" name="edit" title={__("edit entry")} />
|
52
79
|
</Button>
|
80
|
+
|
53
81
|
<Button
|
54
82
|
bsStyle="default"
|
55
|
-
onClick={() =>
|
83
|
+
onClick={() => openForemanParameterSelectionModal(additionalData)}
|
56
84
|
>
|
57
|
-
<Icon type="pf" name="settings" />
|
85
|
+
<Icon type="pf" name="settings" title={__("change parameters")} />
|
58
86
|
</Button>
|
87
|
+
|
88
|
+
<Button
|
89
|
+
bsStyle="default"
|
90
|
+
onClick={() => openAnsibleParameterSelectionModal(additionalData)}
|
91
|
+
>
|
92
|
+
<span title={__("change ansible variables")}>A</span>
|
93
|
+
</Button>
|
94
|
+
|
59
95
|
<DeleteTableEntry
|
60
96
|
hidden={false}
|
61
97
|
disabled={false}
|
@@ -67,11 +103,18 @@ class ApplicationDefinition extends React.Component {
|
|
67
103
|
renderEdit: (value, additionalData) => (
|
68
104
|
<td style={{ padding: '2px' }}>
|
69
105
|
<Button bsStyle="default" disabled>
|
70
|
-
<Icon type="pf" name="edit" />
|
106
|
+
<Icon type="pf" name={__("edit")} />
|
71
107
|
</Button>
|
108
|
+
|
72
109
|
<Button bsStyle="default" disabled>
|
73
|
-
<Icon type="pf" name="settings" />
|
110
|
+
<Icon type="pf" name={__("settings")} />
|
74
111
|
</Button>
|
112
|
+
|
113
|
+
<Button
|
114
|
+
bsStyle="default" disabled>
|
115
|
+
<span>A</span>
|
116
|
+
</Button>
|
117
|
+
|
75
118
|
<DeleteTableEntry
|
76
119
|
hidden={false}
|
77
120
|
disabled={true}
|
@@ -83,8 +126,7 @@ class ApplicationDefinition extends React.Component {
|
|
83
126
|
});
|
84
127
|
this.inlineEditButtonsFormatter = inlineEditButtonsFormatter;
|
85
128
|
|
86
|
-
|
87
|
-
this.headerFormatter = headerFormatter;
|
129
|
+
this.headerFormatter = EasyHeaderFormatter;
|
88
130
|
|
89
131
|
const inlineEditFormatterImpl = {
|
90
132
|
renderValue: (value, additionalData) => (
|
@@ -121,6 +163,10 @@ class ApplicationDefinition extends React.Component {
|
|
121
163
|
if (additionalData.property == 'hostgroup') {
|
122
164
|
prettyValue = hostgroups[value];
|
123
165
|
}
|
166
|
+
else if (additionalData.property == 'ansibleGroup') {
|
167
|
+
const ag = this.createAnsibleGroupObject(this.props.ansiblePlaybook.groups);
|
168
|
+
prettyValue = ag[value];
|
169
|
+
}
|
124
170
|
return inlineEditFormatterImpl.renderValue(prettyValue, additionalData)
|
125
171
|
},
|
126
172
|
renderEdit: (value, additionalData) => {
|
@@ -130,13 +176,23 @@ class ApplicationDefinition extends React.Component {
|
|
130
176
|
}
|
131
177
|
return inlineEditFormatterImpl.renderValue(hostgroups[value], additionalData)
|
132
178
|
}
|
179
|
+
else if (additionalData.property == 'ansibleGroup') {
|
180
|
+
const ag = this.createAnsibleGroupObject(this.props.ansiblePlaybook.groups);
|
181
|
+
|
182
|
+
if (additionalData.rowData.newEntry === true) {
|
183
|
+
return inlineEditFormatterImpl.renderEditSelect(value, additionalData, ag);
|
184
|
+
}
|
185
|
+
return inlineEditFormatterImpl.renderValue(ag[value], additionalData);
|
186
|
+
}
|
133
187
|
return inlineEditFormatterImpl.renderEditText(value, additionalData);
|
134
188
|
}
|
135
189
|
});
|
136
190
|
this.inlineEditFormatter = inlineEditFormatter;
|
137
191
|
|
138
192
|
initApplicationDefinition(
|
193
|
+
ansiblePlaybook,
|
139
194
|
services,
|
195
|
+
ansibleVarsAll,
|
140
196
|
this.headerFormatter,
|
141
197
|
this.inlineEditFormatter,
|
142
198
|
this.inlineEditButtonsFormatter,
|
@@ -145,25 +201,42 @@ class ApplicationDefinition extends React.Component {
|
|
145
201
|
|
146
202
|
render() {
|
147
203
|
const {
|
148
|
-
data: { organization, location,
|
204
|
+
data: { organization, location, mode, ansiblePlaybooks, foremanDataUrl, ansibleDataUrl },
|
205
|
+
ansiblePlaybook,
|
149
206
|
services,
|
150
207
|
columns,
|
151
208
|
addApplicationDefinitionService,
|
152
209
|
confirmEditApplicationDefinitionService,
|
153
210
|
cancelEditApplicationDefinitionService,
|
154
|
-
|
155
|
-
|
211
|
+
closeForemanParameterSelectionModal,
|
212
|
+
openAnsibleParameterSelectionModal,
|
213
|
+
closeAnsibleParameterSelectionModal,
|
214
|
+
changeParameterSelectionMode,
|
156
215
|
ParameterSelectionModal,
|
216
|
+
loadAnsibleData,
|
157
217
|
} = this.props;
|
158
218
|
|
219
|
+
|
159
220
|
return (
|
160
221
|
<span>
|
161
|
-
<div
|
162
|
-
<
|
163
|
-
|
164
|
-
|
165
|
-
|
222
|
+
<div>
|
223
|
+
<AnsiblePlaybookSelector
|
224
|
+
label="Ansible Playbook"
|
225
|
+
editable={ mode == 'newDefinition' }
|
226
|
+
viewText={ ansiblePlaybook.name }
|
227
|
+
options={ ansiblePlaybooks }
|
228
|
+
onChange={ loadAnsibleData }
|
229
|
+
selectValue={ ansiblePlaybook.id.toString() }
|
230
|
+
additionalData={{url: ansibleDataUrl }}
|
166
231
|
/>
|
232
|
+
{ansiblePlaybook.id == '' ? (
|
233
|
+
<p style={{ paddingTop: 25 }}>
|
234
|
+
<pre>{ "Ansible Playbook can't be blank" }</pre>
|
235
|
+
</p>
|
236
|
+
) : (<div></div>)}
|
237
|
+
|
238
|
+
</div>
|
239
|
+
<div className="form-group">
|
167
240
|
<Table.PfProvider
|
168
241
|
striped
|
169
242
|
bordered
|
@@ -192,33 +265,75 @@ class ApplicationDefinition extends React.Component {
|
|
192
265
|
/>
|
193
266
|
</Table.PfProvider>
|
194
267
|
<AddTableEntry
|
195
|
-
|
196
|
-
|
197
|
-
|
268
|
+
hidden={ false }
|
269
|
+
disabled={ this.addTableEntryAllowed() }
|
270
|
+
onAddTableEntry={ addApplicationDefinitionService }
|
198
271
|
/>
|
272
|
+
<span style={{ marginLeft: 30 }}>
|
273
|
+
Ansible group vars 'all':
|
274
|
+
<Button
|
275
|
+
style={{ marginLeft: 10 }}
|
276
|
+
bsStyle="default"
|
277
|
+
disabled={ this.props.editMode }
|
278
|
+
onClick={() => openAnsibleParameterSelectionModal({
|
279
|
+
isAllGroup: true
|
280
|
+
})}
|
281
|
+
>
|
282
|
+
<span title={__("change ansible variables for 'all'")}>A</span>
|
283
|
+
</Button>
|
284
|
+
</span>
|
285
|
+
</div>
|
286
|
+
<div>
|
287
|
+
<ForemanModal
|
288
|
+
id="AppDefinitionForemanParamSelection"
|
289
|
+
dialogClassName="param_selection_modal"
|
290
|
+
title={__("Foreman Parameter definition for Application Definition")}
|
291
|
+
>
|
292
|
+
<ForemanModal.Header closeButton={false}>
|
293
|
+
Parameter definition
|
294
|
+
</ForemanModal.Header>
|
295
|
+
{this.props.parametersData ? (
|
296
|
+
<ParameterSelection
|
297
|
+
editModeCallback={ (hide) => changeParameterSelectionMode({ mode: hide })}
|
298
|
+
paramType={ PARAMETER_SELECTION_PARAM_TYPE_FOREMAN }
|
299
|
+
location={ location }
|
300
|
+
organization={ organization }
|
301
|
+
paramDataUrl= { foremanDataUrl }
|
302
|
+
data={ this.props.parametersData }
|
303
|
+
/>
|
304
|
+
) : (<span>Empty</span>)
|
305
|
+
}
|
306
|
+
<ForemanModal.Footer>
|
307
|
+
<div>
|
308
|
+
<Button bsStyle="primary" disabled={this.props.paramEditMode} onClick={() => closeForemanParameterSelectionModal({ mode: 'save' })}>{__("Save")}</Button>
|
309
|
+
<Button bsStyle="default" disabled={this.props.paramEditMode} onClick={() => closeForemanParameterSelectionModal({ mode: 'cancel' })}>{__("Cancel")}</Button>
|
310
|
+
</div>
|
311
|
+
</ForemanModal.Footer>
|
312
|
+
</ForemanModal>
|
199
313
|
</div>
|
200
314
|
<div>
|
201
315
|
<ForemanModal
|
202
|
-
id="
|
316
|
+
id="AppDefinitionAnsibleParamSelection"
|
203
317
|
dialogClassName="param_selection_modal"
|
204
|
-
title="
|
318
|
+
title={__("Ansible variables for Application Definition")}
|
205
319
|
>
|
206
320
|
<ForemanModal.Header closeButton={false}>
|
207
321
|
Parameter definition
|
208
322
|
</ForemanModal.Header>
|
209
323
|
{this.props.parametersData ? (
|
210
324
|
<ParameterSelection
|
325
|
+
editModeCallback={ (hide) => changeParameterSelectionMode({ mode: hide })}
|
326
|
+
paramType={ PARAMETER_SELECTION_PARAM_TYPE_ANSIBLE }
|
211
327
|
location={ location }
|
212
328
|
organization={ organization }
|
213
|
-
loadForemanDataUrl= { loadForemanDataUrl }
|
214
329
|
data={ this.props.parametersData }
|
215
330
|
/>
|
216
331
|
) : (<span>Empty</span>)
|
217
332
|
}
|
218
333
|
<ForemanModal.Footer>
|
219
334
|
<div>
|
220
|
-
<Button bsStyle="primary" onClick={() =>
|
221
|
-
<Button bsStyle="default" onClick={() =>
|
335
|
+
<Button bsStyle="primary" disabled={this.props.paramEditMode} onClick={() => closeAnsibleParameterSelectionModal({ mode: 'save' })}>{__("Save")}</Button>
|
336
|
+
<Button bsStyle="default" disabled={this.props.paramEditMode} onClick={() => closeAnsibleParameterSelectionModal({ mode: 'cancel' })}>{__("Cancel")}</Button>
|
222
337
|
</div>
|
223
338
|
</ForemanModal.Footer>
|
224
339
|
</ForemanModal>
|
@@ -229,6 +344,12 @@ class ApplicationDefinition extends React.Component {
|
|
229
344
|
parameter='services'
|
230
345
|
value={JSON.stringify(this.props.services)}
|
231
346
|
/>
|
347
|
+
<RailsData
|
348
|
+
key='applications_definition'
|
349
|
+
view='app_definition'
|
350
|
+
parameter='ansible_vars_all'
|
351
|
+
value={JSON.stringify(this.props.ansibleVarsAll)}
|
352
|
+
/>
|
232
353
|
</span>
|
233
354
|
)};
|
234
355
|
}
|
@@ -236,16 +357,21 @@ class ApplicationDefinition extends React.Component {
|
|
236
357
|
ApplicationDefinition.defaultProps = {
|
237
358
|
error: {},
|
238
359
|
editMode: false,
|
360
|
+
ansiblePlaybook: { "id": '', "name": '' },
|
239
361
|
services: [],
|
362
|
+
ansibleVarsAll: [],
|
240
363
|
parametersData: {},
|
241
364
|
columns: [],
|
242
365
|
editParamsOfRowId: null,
|
366
|
+
paramEditMode: false,
|
243
367
|
}
|
244
368
|
|
245
369
|
ApplicationDefinition.propTypes = {
|
246
370
|
initApplicationDefinition: PropTypes.func,
|
247
371
|
editMode: PropTypes.bool.isRequired,
|
372
|
+
ansiblePlaybook: PropTypes.object,
|
248
373
|
services: PropTypes.array,
|
374
|
+
ansibleVarsAll: PropTypes.array,
|
249
375
|
columns: PropTypes.array,
|
250
376
|
addApplicationDefinitionService: PropTypes.func,
|
251
377
|
deleteApplicationDefinitionService: PropTypes.func,
|
@@ -253,9 +379,13 @@ ApplicationDefinition.propTypes = {
|
|
253
379
|
confirmEditApplicationDefinitionService: PropTypes.func,
|
254
380
|
cancelEditApplicationDefinitionService: PropTypes.func,
|
255
381
|
changeEditApplicationDefinitionService: PropTypes.func,
|
256
|
-
|
257
|
-
|
382
|
+
openForemanParameterSelectionModal: PropTypes.func,
|
383
|
+
closeForemanParameterSelectionModal: PropTypes.func,
|
384
|
+
openAnsibleParameterSelectionModal: PropTypes.func,
|
385
|
+
closeAnsibleParameterSelectionModal: PropTypes.func,
|
386
|
+
changeParameterSelectionMode: PropTypes.func,
|
258
387
|
parametersData: PropTypes.object,
|
388
|
+
paramEditMode: PropTypes.bool,
|
259
389
|
};
|
260
390
|
|
261
391
|
export default ApplicationDefinition;
|