foreman_puppet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +38 -0
- data/Rakefile +31 -0
- data/app/assets/stylesheets/foreman_puppet.scss +117 -0
- data/app/controllers/concerns/foreman_puppet/api/import_puppetclasses_common_controller.rb +139 -0
- data/app/controllers/concerns/foreman_puppet/environments_import.rb +61 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +40 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +48 -0
- data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +58 -0
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +228 -0
- data/app/controllers/concerns/foreman_puppet/extensions/operatingsystems_controller.rb +11 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +75 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +70 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_template_combination.rb +21 -0
- data/app/controllers/concerns/foreman_puppet/parameters/config_group.rb +17 -0
- data/app/controllers/concerns/foreman_puppet/parameters/environment.rb +21 -0
- data/app/controllers/concerns/foreman_puppet/parameters/puppetclass.rb +24 -0
- data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +24 -0
- data/app/controllers/foreman_puppet/api/v2/base_controller.rb +26 -0
- data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +57 -0
- data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +91 -0
- data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +59 -0
- data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +46 -0
- data/app/controllers/foreman_puppet/api/v2/lookups_common_controller.rb +114 -0
- data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +99 -0
- data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +99 -0
- data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +76 -0
- data/app/controllers/foreman_puppet/config_groups_controller.rb +46 -0
- data/app/controllers/foreman_puppet/environments_controller.rb +51 -0
- data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +39 -0
- data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +33 -0
- data/app/controllers/foreman_puppet/puppetclasses_controller.rb +113 -0
- data/app/controllers/foreman_puppet/react_controller.rb +19 -0
- data/app/helpers/concerns/foreman_puppet/template_renderer_scope.rb +14 -0
- data/app/helpers/foreman_puppet/environments_helper.rb +17 -0
- data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +96 -0
- data/app/helpers/foreman_puppet/hosts_helper.rb +32 -0
- data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +8 -0
- data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +135 -0
- data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +55 -0
- data/app/helpers/foreman_puppet/puppetclasses_helper.rb +59 -0
- data/app/helpers/foreman_puppet/template_combinations_helper.rb +33 -0
- data/app/models/concerns/foreman_puppet/extensions/host.rb +88 -0
- data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +40 -0
- data/app/models/concerns/foreman_puppet/extensions/nic_managed.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +64 -0
- data/app/models/concerns/foreman_puppet/extensions/report.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +19 -0
- data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +23 -0
- data/app/models/concerns/foreman_puppet/extensions/user.rb +22 -0
- data/app/models/concerns/foreman_puppet/host_common.rb +90 -0
- data/app/models/concerns/foreman_puppet/puppet_lookup_value_extensions.rb +13 -0
- data/app/models/foreman_puppet/config_group.rb +45 -0
- data/app/models/foreman_puppet/config_group_class.rb +19 -0
- data/app/models/foreman_puppet/environment.rb +63 -0
- data/app/models/foreman_puppet/environment_class.rb +40 -0
- data/app/models/foreman_puppet/host_class.rb +23 -0
- data/app/models/foreman_puppet/host_config_group.rb +15 -0
- data/app/models/foreman_puppet/host_puppet_facet.rb +130 -0
- data/app/models/foreman_puppet/hostgroup_class.rb +23 -0
- data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +98 -0
- data/app/models/foreman_puppet/puppetclass.rb +132 -0
- data/app/models/foreman_puppet/puppetclass_lookup_key.rb +58 -0
- data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +10 -0
- data/app/services/foreman_puppet/host_info_providers/puppet_info.rb +92 -0
- data/app/services/foreman_puppet/input_type/puppet_parameter_input.rb +35 -0
- data/app/services/foreman_puppet/proxy_status/puppet.rb +17 -0
- data/app/services/foreman_puppet/puppet_class_importer.rb +355 -0
- data/app/views/api/v2/template_combinations/base.json.erb +9 -0
- data/app/views/foreman_puppet/api/v2/config_groups/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/main.json.rabl +8 -0
- data/app/views/foreman_puppet/api/v2/config_groups/show.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/main.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/environments/show.json.rabl +15 -0
- data/app/views/foreman_puppet/api/v2/environments/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/base.json.rabl +1 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_single.json.rabl +17 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/show.json.rabl +11 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single.json.rabl +16 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/show.json.rabl +11 -0
- data/app/views/foreman_puppet/api/v2/import_puppetclasses/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/import_puppetclasses/show.json.rabl +36 -0
- data/app/views/foreman_puppet/api/v2/override_values/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/show.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/index.json.rabl +4 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/list.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/main.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/show.json.rabl +15 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/base.json.rabl +4 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/destroy.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/main.json.rabl +23 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/show.json.rabl +19 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/update.json.rabl +3 -0
- data/app/views/foreman_puppet/config_groups/_config_group.html.erb +34 -0
- data/app/views/foreman_puppet/config_groups/_config_groups_selection.html.erb +36 -0
- data/app/views/foreman_puppet/config_groups/_form.html.erb +9 -0
- data/app/views/foreman_puppet/config_groups/edit.html.erb +3 -0
- data/app/views/foreman_puppet/config_groups/index.html.erb +31 -0
- data/app/views/foreman_puppet/config_groups/new.html.erb +3 -0
- data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -0
- data/app/views/foreman_puppet/environments/_form.html.erb +20 -0
- data/app/views/foreman_puppet/environments/edit.html.erb +8 -0
- data/app/views/foreman_puppet/environments/index.html.erb +32 -0
- data/app/views/foreman_puppet/environments/new.html.erb +7 -0
- data/app/views/foreman_puppet/environments/welcome.html.erb +16 -0
- data/app/views/foreman_puppet/layouts/application_react.html.erb +15 -0
- data/app/views/foreman_puppet/puppet_smart_proxies/_dashboard.html.erb +9 -0
- data/app/views/foreman_puppet/puppet_smart_proxies/_environments.html.erb +30 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/edit.html.erb +3 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/index.html.erb +22 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +9 -0
- data/app/views/foreman_puppet/puppetclasses/_class_parameters.html.erb +37 -0
- data/app/views/foreman_puppet/puppetclasses/_class_selection.html.erb +70 -0
- data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +22 -0
- data/app/views/foreman_puppet/puppetclasses/_classes_in_groups.html.erb +5 -0
- data/app/views/foreman_puppet/puppetclasses/_classes_parameters.html.erb +16 -0
- data/app/views/foreman_puppet/puppetclasses/_form.html.erb +62 -0
- data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +4 -0
- data/app/views/foreman_puppet/puppetclasses/edit.html.erb +4 -0
- data/app/views/foreman_puppet/puppetclasses/index.html.erb +47 -0
- data/app/views/hosts/_form_puppet_enc_tab.html.erb +24 -0
- data/app/views/hosts/foreman_puppet/_form_main_tab_fields.html.erb +1 -0
- data/app/views/hosts/select_multiple_environment.html.erb +8 -0
- data/app/views/provisioning_templates/_combination.html.erb +5 -0
- data/app/views/provisioning_templates/_combinations.html.erb +6 -0
- data/app/views/smart_proxies/plugins/_puppet.html.erb +24 -0
- data/config/api_routes.rb +81 -0
- data/config/routes.rb +89 -0
- data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +9 -0
- data/db/migrate/20200720123005_migrate_puppet_core_types.foreman_puppet.rb +19 -0
- data/db/migrate/20200722171017_create_host_puppet_facet.foreman_puppet.rb +10 -0
- data/db/migrate/20200803113531_create_hostgroup_puppet_facet.foreman_puppet.rb +10 -0
- data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +22 -0
- data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +29 -0
- data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +47 -0
- data/db/migrate_foreman/20090722141107_create_environments.rb +17 -0
- data/db/migrate_foreman/20120905095532_create_environment_classes.rb +15 -0
- data/db/migrate_foreman/20140407161817_create_config_groups.rb +9 -0
- data/db/migrate_foreman/20140407162007_create_config_group_classes.rb +10 -0
- data/db/migrate_foreman/20140407162059_create_host_config_groups.rb +11 -0
- data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +10 -0
- data/db/migrate_foreman/20170109115157_fix_lookup_key_auditable_type.rb +15 -0
- data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +35 -0
- data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +7 -0
- data/db/migrate_foreman/20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb +6 -0
- data/db/seeds.d/111_puppet_proxy_feature.rb +8 -0
- data/lib/foreman_puppet.rb +10 -0
- data/lib/foreman_puppet/engine.rb +82 -0
- data/lib/foreman_puppet/register.rb +218 -0
- data/lib/foreman_puppet/version.rb +3 -0
- data/lib/tasks/foreman_puppet_tasks.rake +31 -0
- data/locale/Makefile +60 -0
- data/locale/action_names.rb +5 -0
- data/locale/en/foreman_puppet.edit.po +911 -0
- data/locale/en/foreman_puppet.po +690 -0
- data/locale/en/foreman_puppet.po.time_stamp +0 -0
- data/locale/foreman_puppet.pot +1076 -0
- data/locale/gemspec.rb +2 -0
- data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +28 -0
- data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +346 -0
- data/test/controllers/foreman_puppet/api/v2/host_classes_controller_test.rb +48 -0
- data/test/controllers/foreman_puppet/api/v2/hostgroup_classes_controller_test.rb +41 -0
- data/test/controllers/foreman_puppet/api/v2/hostgroups_controller_test.rb +79 -0
- data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +101 -0
- data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +29 -0
- data/test/controllers/foreman_puppet/api/v2/override_values_controller_test.rb +169 -0
- data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +144 -0
- data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +557 -0
- data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +81 -0
- data/test/controllers/foreman_puppet/config_groups_controller_test.rb +47 -0
- data/test/controllers/foreman_puppet/environments_controller_test.rb +230 -0
- data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -0
- data/test/controllers/foreman_puppet/hosts_controller_test.rb +346 -0
- data/test/controllers/foreman_puppet/puppet_smart_proxies_controller_test.rb +29 -0
- data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +59 -0
- data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +235 -0
- data/test/controllers/provisioning_templates_controller_test.rb +70 -0
- data/test/factories/foreman_puppet_factories.rb +134 -0
- data/test/factories/host_puppet_enhancements.rb +61 -0
- data/test/factories/proxy_puppet_enhancements.rb +33 -0
- data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +65 -0
- data/test/helpers/foreman_puppet/puppetclasses_helper_test.rb +33 -0
- data/test/integration/foreman_puppet/environment_js_test.rb +27 -0
- data/test/integration/foreman_puppet/host_js_test.rb +371 -0
- data/test/integration/foreman_puppet/hostgroup_js_test.rb +100 -0
- data/test/integration/foreman_puppet/puppetclass_js_test.rb +37 -0
- data/test/integration/foreman_puppet/smartclass_parameter_js_test.rb +84 -0
- data/test/models/foreman_puppet/config_group_class_test.rb +9 -0
- data/test/models/foreman_puppet/config_group_test.rb +8 -0
- data/test/models/foreman_puppet/environment_test.rb +92 -0
- data/test/models/foreman_puppet/host_config_group_test.rb +39 -0
- data/test/models/foreman_puppet/host_puppet_facet_test.rb +116 -0
- data/test/models/foreman_puppet/host_test.rb +288 -0
- data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +200 -0
- data/test/models/foreman_puppet/hostgroup_test.rb +14 -0
- data/test/models/foreman_puppet/lookup_value_test.rb +69 -0
- data/test/models/foreman_puppet/provisioning_template_test.rb +124 -0
- data/test/models/foreman_puppet/puppetclass_lookup_key_test.rb +81 -0
- data/test/models/foreman_puppet/puppetclass_test.rb +144 -0
- data/test/models/foreman_puppet/smart_proxy_test.rb +28 -0
- data/test/qraphql/queries/host_puppet_query_test.rb +36 -0
- data/test/qraphql/queries/hostgroup_puppet_query_test.rb +36 -0
- data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +791 -0
- data/test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb +14 -0
- data/test/test_puppet_helper.rb +30 -0
- data/test/unit/foreman_puppet/access_permissions_test.rb +16 -0
- data/test/unit/foreman_puppet/puppet_class_importer_test.rb +247 -0
- data/test/unit/foreman_puppet/template_rendering_test.rb +20 -0
- data/test/unit/foreman_puppet_test.rb +11 -0
- data/webpack/__mocks__/foremanReact/common/I18n.js +7 -0
- data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +2 -0
- data/webpack/__mocks__/foremanReact/readme.md +11 -0
- data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
- data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
- data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
- data/webpack/__mocks__/foremanReact/redux/index.js +1 -0
- data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
- data/webpack/fills_index.js +30 -0
- data/webpack/index.js +18 -0
- data/webpack/src/ForemanPuppet.js +11 -0
- data/webpack/src/Router/__snapshots__/routes.test.js.snap +3 -0
- data/webpack/src/Router/index.js +14 -0
- data/webpack/src/Router/routes.js +3 -0
- data/webpack/src/Router/routes.test.js +16 -0
- data/webpack/src/foreman_class_edit.js +224 -0
- data/webpack/src/foreman_puppet_host_form.js +140 -0
- data/webpack/src/foreman_puppet_host_form.test.js +65 -0
- data/webpack/src/index.js +1 -0
- data/webpack/src/reducers.js +7 -0
- metadata +340 -0
data/locale/gemspec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
module ForemanPuppet
|
3
|
+
module Api
|
4
|
+
module V2
|
5
|
+
class ConfigGroupsControllerTest < ActionController::TestCase
|
6
|
+
setup do
|
7
|
+
@routes = ForemanPuppet::Engine.routes
|
8
|
+
end
|
9
|
+
test 'should create config group' do
|
10
|
+
assert_difference('ConfigGroup.count') do
|
11
|
+
post :create, params: { config_group: { name: 'config-group', puppetclass_ids: [puppetclasses(:one).id, puppetclasses(:four).id] } }
|
12
|
+
end
|
13
|
+
assert_response :created
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'should update config group' do
|
17
|
+
name = 'new name'
|
18
|
+
put :update, params: { id: config_groups(:one).to_param,
|
19
|
+
config_group: { name: name,
|
20
|
+
puppetclass_ids: [puppetclasses(:one).id, puppetclasses(:four).id] } }
|
21
|
+
assert_response :success
|
22
|
+
response = JSON.parse(@response.body)
|
23
|
+
assert_equal 2, response['puppetclasses'].count
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,346 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
|
3
|
+
module ForemanPuppet
|
4
|
+
module Api
|
5
|
+
module V2
|
6
|
+
class EnvironmentsControllerTest < ActionController::TestCase
|
7
|
+
setup do
|
8
|
+
@routes = ForemanPuppet::Engine.routes
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:environment_attrs) { { name: 'Development' } }
|
12
|
+
let(:environment) { FactoryBot.create(:environment) }
|
13
|
+
|
14
|
+
test 'should get index' do
|
15
|
+
environment
|
16
|
+
get :index
|
17
|
+
assert_response :success
|
18
|
+
assert_not_nil assigns(:environments)
|
19
|
+
envs = ActiveSupport::JSON.decode(@response.body)
|
20
|
+
assert_not envs.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should show environment by id or name' do
|
24
|
+
get :show, params: { id: environment.id }
|
25
|
+
assert_response :success
|
26
|
+
assert_equal environment.name, JSON.parse(@response.body)['name']
|
27
|
+
|
28
|
+
get :show, params: { id: environment.to_param }
|
29
|
+
assert_response :success
|
30
|
+
assert_equal environment.name, JSON.parse(@response.body)['name']
|
31
|
+
|
32
|
+
get :show, params: { id: environment.name }
|
33
|
+
assert_response :success
|
34
|
+
assert_equal environment.name, JSON.parse(@response.body)['name']
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'should create environment' do
|
38
|
+
assert_difference('Environment.unscoped.count') do
|
39
|
+
post :create, params: { environment: environment_attrs }
|
40
|
+
end
|
41
|
+
assert_response :created
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'should create new environment with organization' do
|
45
|
+
organization = Organization.first
|
46
|
+
assert_difference 'Environment.unscoped.count' do
|
47
|
+
post :create, params: { environment: { name: 'some_environment', organization_ids: [organization.id] } }, session: set_session_user
|
48
|
+
response = JSON.parse(@response.body)
|
49
|
+
assert_equal(1, response['organizations'].length)
|
50
|
+
assert_equal response['organizations'][0]['id'], organization.id
|
51
|
+
end
|
52
|
+
assert_response :created, "Can't create environment with organization #{organization.name}"
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'should create new environment with location' do
|
56
|
+
location = Location.first
|
57
|
+
assert_difference 'Environment.unscoped.count' do
|
58
|
+
post :create, params: { environment: { name: 'some_environment', location_ids: [location.id] } }, session: set_session_user
|
59
|
+
response = JSON.parse(@response.body)
|
60
|
+
assert_equal(1, response['locations'].length)
|
61
|
+
assert_equal response['locations'][0]['id'], location.id
|
62
|
+
end
|
63
|
+
assert_response :created, "Can't create environment with location #{location.name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'should not create with invalid name' do
|
67
|
+
name = ''
|
68
|
+
post :create, params: { environment: { name: name } }
|
69
|
+
assert_response :unprocessable_entity, "Can create environment with invalid name #{name}"
|
70
|
+
end
|
71
|
+
|
72
|
+
test 'should update with valid name' do
|
73
|
+
new_environment_name = RFauxFactory.gen_alphanumeric
|
74
|
+
post :update, params: { id: environment.id, environment: { name: new_environment_name } }, session: set_session_user
|
75
|
+
assert_equal JSON.parse(@response.body)['name'], new_environment_name, "Can't update environment with valid name #{name}"
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'should not update with invalid name' do
|
79
|
+
name = ''
|
80
|
+
put :update, params: { id: environment.to_param, environment: { name: name } }
|
81
|
+
assert_response :unprocessable_entity, "Can update environment with invalid name #{name}"
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'should update environment' do
|
85
|
+
put :update, params: { id: environment.to_param, environment: environment_attrs }
|
86
|
+
assert_response :success
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'should update environment with organization' do
|
90
|
+
organization = Organization.first
|
91
|
+
put :update, params: { id: environment.id, environment: { organization_ids: [organization.id] } }
|
92
|
+
response = JSON.parse(@response.body)
|
93
|
+
assert_equal(1, response['organizations'].length)
|
94
|
+
assert_equal response['organizations'][0]['id'], organization.id
|
95
|
+
assert_response :success, "Can't update environment with organization #{organization.name}"
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'should update environment with location' do
|
99
|
+
location = Location.first
|
100
|
+
put :update, params: { id: environment.id, environment: { location_ids: [location.id] } }
|
101
|
+
response = JSON.parse(@response.body)
|
102
|
+
assert_equal(1, response['locations'].length)
|
103
|
+
assert_equal response['locations'][0]['id'], location.id
|
104
|
+
assert_response :success, "Can't update environment with location #{location.name}"
|
105
|
+
end
|
106
|
+
|
107
|
+
test 'should destroy environments' do
|
108
|
+
environment
|
109
|
+
assert_difference('Environment.unscoped.count', -1) do
|
110
|
+
delete :destroy, params: { id: environment.to_param }
|
111
|
+
end
|
112
|
+
assert_response :success
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'POST #import_puppetclasses' do
|
116
|
+
# puppetmaster proxy - import_puppetclasses tests
|
117
|
+
|
118
|
+
let(:proxy) { FactoryBot.create(:puppet_smart_proxy) }
|
119
|
+
|
120
|
+
test 'should import new environments' do
|
121
|
+
setup_import_classes
|
122
|
+
as_admin do
|
123
|
+
Host::Managed.update_all(environment_id: nil)
|
124
|
+
Hostgroup.update_all(environment_id: nil)
|
125
|
+
Puppetclass.destroy_all
|
126
|
+
Environment.destroy_all
|
127
|
+
end
|
128
|
+
assert_difference('Environment.unscoped.count', 2) do
|
129
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
130
|
+
end
|
131
|
+
assert_response :success
|
132
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
133
|
+
assert_equal 2, response['environments_with_new_puppetclasses']
|
134
|
+
end
|
135
|
+
|
136
|
+
# this is intentional: put test_attributes only for the first generated test eg: dryrun_param = {}
|
137
|
+
test_attributes pid: '385efd1b-6146-47bf-babf-0127ce5955ed'
|
138
|
+
[{}, { dryrun: false }, { dryrun: 'false' }].each do |dryrun_param|
|
139
|
+
test 'should import new puppetclasses' do
|
140
|
+
setup_import_classes
|
141
|
+
as_admin do
|
142
|
+
Host::Managed.update_all(environment_id: nil)
|
143
|
+
Hostgroup.update_all(environment_id: nil)
|
144
|
+
Puppetclass.destroy_all
|
145
|
+
Environment.destroy_all
|
146
|
+
assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 1) do
|
147
|
+
post :import_puppetclasses,
|
148
|
+
params: { id: proxy.id }.merge(dryrun_param),
|
149
|
+
session: set_session_user
|
150
|
+
end
|
151
|
+
end
|
152
|
+
assert_response :success
|
153
|
+
assert_match 'Successfully updated environment and puppetclasses from the on-disk puppet installation', @response.body
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
test 'should not import new puppetclasses when dryrun' do
|
158
|
+
setup_import_classes
|
159
|
+
as_admin do
|
160
|
+
Host::Managed.update_all(environment_id: nil)
|
161
|
+
Hostgroup.update_all(environment_id: nil)
|
162
|
+
Puppetclass.destroy_all
|
163
|
+
Environment.destroy_all
|
164
|
+
assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 0) do
|
165
|
+
post :import_puppetclasses, params: { id: proxy.id, dryrun: true }, session: set_session_user
|
166
|
+
end
|
167
|
+
end
|
168
|
+
assert_response :success
|
169
|
+
end
|
170
|
+
|
171
|
+
test 'should obsolete environment' do
|
172
|
+
setup_import_classes
|
173
|
+
as_admin do
|
174
|
+
Environment.create!(name: 'xyz')
|
175
|
+
end
|
176
|
+
assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, -1) do
|
177
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
178
|
+
end
|
179
|
+
assert_response :success
|
180
|
+
end
|
181
|
+
|
182
|
+
test 'should obsolete puppetclasses' do
|
183
|
+
setup_import_classes
|
184
|
+
as_admin do
|
185
|
+
assert_difference(-> { ForemanPuppet::Environment.unscoped.find_by(name: 'env1').puppetclasses.count }, -2) do
|
186
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
187
|
+
end
|
188
|
+
end
|
189
|
+
assert_response :success
|
190
|
+
end
|
191
|
+
|
192
|
+
test 'should update puppetclass smart class parameters' do
|
193
|
+
setup_import_classes
|
194
|
+
LookupKey.destroy_all
|
195
|
+
assert_difference(-> { LookupKey.unscoped.count }, 1) do
|
196
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
197
|
+
end
|
198
|
+
assert_response :success
|
199
|
+
end
|
200
|
+
|
201
|
+
test 'no changes on import_puppetclasses' do
|
202
|
+
setup_import_classes
|
203
|
+
Puppetclass.find_by(name: 'b').destroy
|
204
|
+
Puppetclass.find_by(name: 'c').destroy
|
205
|
+
assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, 0) do
|
206
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
207
|
+
end
|
208
|
+
assert_response :success
|
209
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
210
|
+
assert_equal 'Successfully updated environment and puppetclasses from the on-disk puppet installation', response['message']
|
211
|
+
end
|
212
|
+
|
213
|
+
test 'should import new environment that does not exist in db' do
|
214
|
+
setup_import_classes
|
215
|
+
as_admin do
|
216
|
+
env_name = 'env1'
|
217
|
+
assert Environment.find_by(name: env_name).destroy
|
218
|
+
assert_difference('Environment.unscoped.count', 1) do
|
219
|
+
post :import_puppetclasses, params: { id: proxy.id, environment_id: env_name }, session: set_session_user
|
220
|
+
end
|
221
|
+
assert_response :success
|
222
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
223
|
+
assert_equal env_name, response['results']['name']
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
test 'should NOT delete environment if pass ?except=obsolete' do
|
228
|
+
setup_import_classes
|
229
|
+
as_admin do
|
230
|
+
Environment.create!(name: 'xyz')
|
231
|
+
end
|
232
|
+
assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, 0) do
|
233
|
+
post :import_puppetclasses, params: { id: proxy.id, except: 'obsolete' }, session: set_session_user
|
234
|
+
end
|
235
|
+
assert_response :success
|
236
|
+
end
|
237
|
+
|
238
|
+
test 'should NOT add or update puppetclass smart class parameters if pass ?except=new,updated' do
|
239
|
+
setup_import_classes
|
240
|
+
LookupKey.destroy_all
|
241
|
+
assert_difference(-> { LookupKey.unscoped.count }, 0) do
|
242
|
+
post :import_puppetclasses, params: { id: proxy.id, except: 'new,updated' }, session: set_session_user
|
243
|
+
end
|
244
|
+
assert_response :success
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'import puppetclasses' do
|
248
|
+
setup do
|
249
|
+
ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
|
250
|
+
classes_env1 = { 'a' => Foreman::ImporterPuppetclass.new('name' => 'a') }
|
251
|
+
classes_env2 = { 'b' => Foreman::ImporterPuppetclass.new('name' => 'b') }
|
252
|
+
ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes_env1.merge(classes_env2))
|
253
|
+
ProxyAPI::Puppet.any_instance.stubs(:classes).with('env1').returns(classes_env1)
|
254
|
+
ProxyAPI::Puppet.any_instance.stubs(:classes).with('env2').returns(classes_env2)
|
255
|
+
end
|
256
|
+
|
257
|
+
test 'should render templates according to api version 2' do
|
258
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
259
|
+
assert_template 'foreman_puppet/api/v2/import_puppetclasses/index'
|
260
|
+
end
|
261
|
+
|
262
|
+
test 'should import puppetclasses for specified environment only' do
|
263
|
+
assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 1) do
|
264
|
+
post :import_puppetclasses, params: { id: proxy.id, environment_id: 'env1' }, session: set_session_user
|
265
|
+
assert_includes Puppetclass.pluck(:name), 'a'
|
266
|
+
assert_not_includes Puppetclass.pluck(:name), 'b'
|
267
|
+
end
|
268
|
+
assert_response :success
|
269
|
+
end
|
270
|
+
|
271
|
+
test 'should import puppetclasses for all environments if none specified' do
|
272
|
+
assert_difference(-> { ForemanPuppet::Puppetclass.unscoped.count }, 2) do
|
273
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
274
|
+
end
|
275
|
+
assert_includes Puppetclass.pluck(:name), 'a'
|
276
|
+
assert_includes Puppetclass.pluck(:name), 'b'
|
277
|
+
assert_response :success
|
278
|
+
end
|
279
|
+
|
280
|
+
context 'ignored entvironments or classes are set' do
|
281
|
+
setup do
|
282
|
+
setup_import_classes
|
283
|
+
end
|
284
|
+
|
285
|
+
test 'should contain ignored environments' do
|
286
|
+
env_name = 'env1'
|
287
|
+
PuppetClassImporter.any_instance.stubs(:ignored_environments).returns([env_name])
|
288
|
+
|
289
|
+
as_admin do
|
290
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
291
|
+
assert_response :success
|
292
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
293
|
+
assert_equal env_name, response['results'][0]['ignored_environment']
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
test 'should contain ignored puppet_classes' do
|
298
|
+
PuppetClassImporter.any_instance.stubs(:ignored_classes).returns([/^a$/])
|
299
|
+
|
300
|
+
as_admin do
|
301
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
302
|
+
assert_response :success
|
303
|
+
response = ActiveSupport::JSON.decode(@response.body)
|
304
|
+
assert_includes response['results'][0]['ignored_puppetclasses'], 'a'
|
305
|
+
assert_not_includes response['results'][0]['ignored_puppetclasses'], 'c'
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
private
|
313
|
+
|
314
|
+
def setup_import_classes
|
315
|
+
as_admin do
|
316
|
+
Host::Managed.update_all(environment_id: nil)
|
317
|
+
Hostgroup.update_all(environment_id: nil)
|
318
|
+
HostClass.destroy_all
|
319
|
+
HostgroupClass.destroy_all
|
320
|
+
Puppetclass.destroy_all
|
321
|
+
Environment.destroy_all
|
322
|
+
end
|
323
|
+
orgs = [taxonomies(:organization1)]
|
324
|
+
locs = [taxonomies(:location1)]
|
325
|
+
# This is the database status
|
326
|
+
# and should result in a db_tree of {"env1" => ["a", "b", "c"], "env2" => ["a", "b", "c"]}
|
327
|
+
as_admin do
|
328
|
+
%w[a b c].each { |name| Puppetclass.create name: name }
|
329
|
+
%w[env1 env2].each do |name|
|
330
|
+
e = Environment.create!(name: name, organizations: orgs, locations: locs)
|
331
|
+
e.puppetclasses = Puppetclass.all
|
332
|
+
end
|
333
|
+
end
|
334
|
+
# This is the on-disk status
|
335
|
+
# and should result in a disk_tree of {"env1" => ["a", "b", "c"],"env2" => ["a", "b", "c"]}
|
336
|
+
envs = HashWithIndifferentAccess.new(env1: %w[a b c], env2: %w[a b c])
|
337
|
+
pcs = [HashWithIndifferentAccess.new('a' => { 'name' => 'a', 'module' => nil, 'params' => { 'key' => 'special' } })]
|
338
|
+
classes = Hash[pcs.map { |k| [k.keys.first, Foreman::ImporterPuppetclass.new(k.values.first)] }]
|
339
|
+
Environment.expects(:puppetEnvs).returns(envs).at_least(0)
|
340
|
+
ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
|
341
|
+
ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
|
3
|
+
module ForemanPuppet
|
4
|
+
module Api
|
5
|
+
module V2
|
6
|
+
class HostClassesControllerTest < ActionController::TestCase
|
7
|
+
setup do
|
8
|
+
@routes = ForemanPuppet::Engine.routes
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:host) { FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass) }
|
12
|
+
|
13
|
+
test 'should get puppetclass ids for host' do
|
14
|
+
get :index, params: { host_id: host.to_param }
|
15
|
+
assert_response :success
|
16
|
+
result_json = ActiveSupport::JSON.decode(response.body)
|
17
|
+
assert_not result_json['results'].empty?
|
18
|
+
assert_equal(1, result_json['results'].length)
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'should add a puppetclass to a host' do
|
22
|
+
puppetclass = FactoryBot.create(:puppetclass)
|
23
|
+
assert_difference('host.puppet.host_classes.count') do
|
24
|
+
post :create, params: { host_id: host.to_param, puppetclass_id: puppetclass.id }
|
25
|
+
end
|
26
|
+
assert_response :success
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'should remove a puppetclass from a host' do
|
30
|
+
assert_difference('host.puppet.host_classes.count', -1) do
|
31
|
+
delete :destroy, params: { host_id: host.to_param, id: host.puppet.host_classes.first.puppetclass_id }
|
32
|
+
end
|
33
|
+
assert_response :success
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'should not add a puppetclass that does not exist to a host' do
|
37
|
+
post :create, params: { host_id: host.to_param, puppetclass_id: 'invalid_id' }
|
38
|
+
assert_response :unprocessable_entity
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'should not delete a puppetclass that does not exist from a host' do
|
42
|
+
post :destroy, params: { host_id: host.to_param, id: 'invalid_id' }
|
43
|
+
assert_response :unprocessable_entity
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
|
3
|
+
module ForemanPuppet
|
4
|
+
module Api
|
5
|
+
module V2
|
6
|
+
class HostgroupClassesControllerTest < ActionController::TestCase
|
7
|
+
setup do
|
8
|
+
@routes = ForemanPuppet::Engine.routes
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:hostgroup) { FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass) }
|
12
|
+
let(:puppetclass) { FactoryBot.create(:puppetclass) }
|
13
|
+
|
14
|
+
test 'should get puppetclass ids for hostgroup' do
|
15
|
+
get :index, params: { hostgroup_id: hostgroup.id }
|
16
|
+
assert_response :success
|
17
|
+
json_response = ActiveSupport::JSON.decode(response.body)
|
18
|
+
assert_not json_response['results'].empty?
|
19
|
+
assert_equal(1, json_response['results'].length)
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'should add a puppetclass to a hostgroup' do
|
23
|
+
hostgroup
|
24
|
+
puppetclass
|
25
|
+
assert_difference('hostgroup.puppet.hostgroup_classes.count') do
|
26
|
+
post :create, params: { hostgroup_id: hostgroup.id, puppetclass_id: puppetclass.id }
|
27
|
+
end
|
28
|
+
assert_response :success
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'should remove a puppetclass from a hostgroup' do
|
32
|
+
hostgroup
|
33
|
+
assert_difference('hostgroup.puppet.hostgroup_classes.count', -1) do
|
34
|
+
delete :destroy, params: { hostgroup_id: hostgroup.id, id: hostgroup.puppet.puppetclass_ids.first }
|
35
|
+
end
|
36
|
+
assert_response :success
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|