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
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
|
3
|
+
module Queries
|
4
|
+
class HostPuppetQueryTest < GraphQLQueryTestCase
|
5
|
+
let(:query) do
|
6
|
+
<<-GRAPHQL
|
7
|
+
query (
|
8
|
+
$id: String!
|
9
|
+
) {
|
10
|
+
host(id: $id) {
|
11
|
+
id
|
12
|
+
environment {
|
13
|
+
id
|
14
|
+
}
|
15
|
+
puppetProxy {
|
16
|
+
id
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
GRAPHQL
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:host) { FactoryBot.create(:host, :with_puppet_enc) }
|
24
|
+
let(:global_id) { Foreman::GlobalId.encode('Host', host.id) }
|
25
|
+
let(:variables) { { id: global_id } }
|
26
|
+
|
27
|
+
test 'fetching host attributes' do
|
28
|
+
skip 'GraphQL is TODO'
|
29
|
+
host_data = result['data']['host']
|
30
|
+
assert_empty result['errors']
|
31
|
+
assert_equal global_id, host_data['id']
|
32
|
+
assert_record host.environment, host_data['environment']
|
33
|
+
assert_record host.puppet_proxy, host_data['puppetProxy']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
|
3
|
+
module Queries
|
4
|
+
class HostgroupPuppetQueryTest < GraphQLQueryTestCase
|
5
|
+
let(:query) do
|
6
|
+
<<-GRAPHQL
|
7
|
+
query (
|
8
|
+
$id: String!
|
9
|
+
) {
|
10
|
+
hostgroup(id: $id) {
|
11
|
+
id
|
12
|
+
environment {
|
13
|
+
id
|
14
|
+
}
|
15
|
+
puppetProxy {
|
16
|
+
id
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
GRAPHQL
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:hostgroup) { FactoryBot.create(:hostgroup, :with_puppet_enc) }
|
24
|
+
let(:global_id) { Foreman::GlobalId.encode('Hostgroup', hostgroup.id) }
|
25
|
+
let(:variables) { { id: global_id } }
|
26
|
+
|
27
|
+
test 'fetching host attributes' do
|
28
|
+
skip 'GraphQL is TODO'
|
29
|
+
hostgroup_data = result['data']['hostgroup']
|
30
|
+
assert_empty result['errors']
|
31
|
+
assert_equal global_id, hostgroup_data['id']
|
32
|
+
assert_record hostgroup.puppet.environment, hostgroup_data['environment']
|
33
|
+
assert_record hostgroup.puppet_proxy, hostgroup_data['puppetProxy']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,791 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
|
3
|
+
module ForemanPuppet
|
4
|
+
class PuppetInfoTest < ActiveSupport::TestCase
|
5
|
+
let(:environment) { FactoryBot.create(:environment) }
|
6
|
+
let(:puppetclass) { FactoryBot.create(:puppetclass, environments: [environment]) }
|
7
|
+
let(:puppetclass_two) { FactoryBot.create(:puppetclass, environments: [environment]) }
|
8
|
+
let(:key_lookup_path) { "fqdn\norganization,location\nhostgroup\nos" }
|
9
|
+
let(:puppetclass_lookup_key) do
|
10
|
+
FactoryBot.create(
|
11
|
+
:puppetclass_lookup_key,
|
12
|
+
puppetclass: puppetclass,
|
13
|
+
default_value: 'secret',
|
14
|
+
path: key_lookup_path
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@host = FactoryBot.build(:host, :with_puppet_enc,
|
20
|
+
location: taxonomies(:location1),
|
21
|
+
organization: taxonomies(:organization1),
|
22
|
+
operatingsystem: operatingsystems(:redhat),
|
23
|
+
puppetclasses: [puppetclass],
|
24
|
+
environment: environment)
|
25
|
+
puppetclass_lookup_key
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'enc_should_return_param_default_value' do
|
29
|
+
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
30
|
+
assert_equal 'secret', enc[puppetclass.name][puppetclass_lookup_key.key]
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'enc_should_return_updated_cluster_param' do
|
34
|
+
assert_equal "fqdn\norganization,location\nhostgroup\nos", puppetclass_lookup_key.path
|
35
|
+
assert_equal taxonomies(:location1), @host.location
|
36
|
+
assert_equal taxonomies(:organization1), @host.organization
|
37
|
+
|
38
|
+
value = as_admin do
|
39
|
+
LookupValue.create! lookup_key_id: puppetclass_lookup_key.id,
|
40
|
+
match: "organization=#{taxonomies(:organization1)},location=#{taxonomies(:location1)}",
|
41
|
+
value: 'test',
|
42
|
+
omit: false
|
43
|
+
end
|
44
|
+
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
45
|
+
|
46
|
+
assert_equal value.value, enc[puppetclass.name][puppetclass_lookup_key.key]
|
47
|
+
end
|
48
|
+
|
49
|
+
test '#enc should return hash of class to nil for classes without parameters' do
|
50
|
+
env = FactoryBot.build(:environment)
|
51
|
+
pc = FactoryBot.build(:puppetclass, environments: [env])
|
52
|
+
assert_equal({ pc.name => nil }, get_classparam(env, pc).puppetclass_parameters)
|
53
|
+
end
|
54
|
+
|
55
|
+
test '#enc should not return class parameters where override is false' do
|
56
|
+
pc = FactoryBot.create(:puppetclass, :with_parameters, environments: [environment])
|
57
|
+
assert_not pc.class_params.first.override
|
58
|
+
assert_equal({ pc.name => nil }, get_classparam(environment, pc).puppetclass_parameters)
|
59
|
+
end
|
60
|
+
|
61
|
+
test '#enc should return default value of class parameters without lookup_values' do
|
62
|
+
pc = FactoryBot.create(:puppetclass, environments: [environment])
|
63
|
+
lkey = FactoryBot.create(:puppetclass_lookup_key, puppetclass: pc, default_value: 'test')
|
64
|
+
assert_equal({ pc.name => { lkey.key => lkey.default_value } }, get_classparam(environment, pc).puppetclass_parameters)
|
65
|
+
end
|
66
|
+
|
67
|
+
test '#enc should return override value of class parameters' do
|
68
|
+
pc = FactoryBot.create(:puppetclass, :with_parameters, environments: [environment]).reload
|
69
|
+
lkey = FactoryBot.create(:puppetclass_lookup_key, puppetclass: pc, path: 'comment', overrides: { 'comment=override' => 'overridden value' })
|
70
|
+
classparam = get_classparam(environment, pc)
|
71
|
+
host = classparam.send(:host)
|
72
|
+
host.expects(:comment).returns('override')
|
73
|
+
assert_equal({ pc.name => { lkey.key => 'overridden value' } }, classparam.puppetclass_parameters)
|
74
|
+
end
|
75
|
+
|
76
|
+
test "#values_hash should contain element's name and managed element for puppet key" do
|
77
|
+
lkey = FactoryBot.create(:puppetclass_lookup_key, :with_override, puppetclass: puppetclass)
|
78
|
+
host = FactoryBot.build_stubbed(:host, :with_puppet_enc, environment: environment, puppetclasses: [puppetclass])
|
79
|
+
Classification::MatchesGenerator.any_instance.expects(:attr_to_value).with('comment').returns('override')
|
80
|
+
|
81
|
+
assert_equal(
|
82
|
+
{
|
83
|
+
lkey.id => {
|
84
|
+
lkey.key => {
|
85
|
+
value: 'overridden value',
|
86
|
+
element: 'comment',
|
87
|
+
element_name: 'override',
|
88
|
+
managed: false,
|
89
|
+
},
|
90
|
+
},
|
91
|
+
},
|
92
|
+
Classification::ValuesHashQuery.values_hash(host, LookupKey.where(id: [lkey])).raw
|
93
|
+
)
|
94
|
+
|
95
|
+
Classification::MatchesGenerator.any_instance.unstub(:attr_to_value)
|
96
|
+
end
|
97
|
+
|
98
|
+
test '#enc should not return class parameters when default value should use puppet default' do
|
99
|
+
lkey = FactoryBot.create(:puppetclass_lookup_key, :with_override, :with_omit,
|
100
|
+
puppetclass: puppetclass)
|
101
|
+
|
102
|
+
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
103
|
+
assert enc[puppetclass.name][lkey.key].nil?
|
104
|
+
end
|
105
|
+
|
106
|
+
test '#enc should not return class parameters when lookup_value should use puppet default' do
|
107
|
+
lkey = FactoryBot.create(:puppetclass_lookup_key, :with_override, :with_omit,
|
108
|
+
puppetclass: puppetclass, path: "location\ncomment")
|
109
|
+
as_admin do
|
110
|
+
LookupValue.create! lookup_key_id: lkey.id,
|
111
|
+
match: "location=#{taxonomies(:location1)}",
|
112
|
+
value: 'test',
|
113
|
+
omit: true
|
114
|
+
end
|
115
|
+
|
116
|
+
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
117
|
+
|
118
|
+
assert enc[puppetclass.name][lkey.key].nil?
|
119
|
+
end
|
120
|
+
|
121
|
+
test '#enc should return class parameters when default value and lookup_values should not use puppet default' do
|
122
|
+
lkey = FactoryBot.create(:puppetclass_lookup_key, :with_override, omit: false,
|
123
|
+
puppetclass: puppetclass,
|
124
|
+
path: "location\ncomment")
|
125
|
+
lvalue = as_admin do
|
126
|
+
LookupValue.create! lookup_key_id: lkey.id,
|
127
|
+
match: "location=#{taxonomies(:location1)}",
|
128
|
+
value: 'test',
|
129
|
+
omit: false
|
130
|
+
end
|
131
|
+
|
132
|
+
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
133
|
+
|
134
|
+
assert_equal lvalue.value, enc[puppetclass.name][lkey.key]
|
135
|
+
end
|
136
|
+
|
137
|
+
test '#enc should not return class parameters when merged lookup_values and default are all using puppet default' do
|
138
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
139
|
+
key_type: 'hash', merge_overrides: true,
|
140
|
+
default_value: {}, path: "organization\nos\nlocation",
|
141
|
+
puppetclass: puppetclass)
|
142
|
+
|
143
|
+
as_admin do
|
144
|
+
LookupValue.create! lookup_key_id: key.id,
|
145
|
+
match: "location=#{taxonomies(:location1)}",
|
146
|
+
value: { example: { a: 'test' } },
|
147
|
+
omit: true
|
148
|
+
end
|
149
|
+
as_admin do
|
150
|
+
LookupValue.create! lookup_key_id: key.id,
|
151
|
+
match: "organization=#{taxonomies(:organization1)}",
|
152
|
+
value: { example: { b: 'test2' } },
|
153
|
+
omit: true
|
154
|
+
end
|
155
|
+
|
156
|
+
as_admin do
|
157
|
+
LookupValue.create! lookup_key_id: key.id,
|
158
|
+
match: "os=#{operatingsystems(:redhat)}",
|
159
|
+
value: { example: { a: 'test3' } },
|
160
|
+
omit: true
|
161
|
+
end
|
162
|
+
|
163
|
+
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
164
|
+
|
165
|
+
assert enc[puppetclass.name][key.key].nil?
|
166
|
+
end
|
167
|
+
|
168
|
+
test '#enc should return correct merged override to host when multiple overrides for inherited hostgroups exist' do
|
169
|
+
FactoryBot.create(:setting,
|
170
|
+
name: 'matchers_inheritance',
|
171
|
+
value: true)
|
172
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
173
|
+
key_type: 'array', merge_overrides: true,
|
174
|
+
path: "organization\nhostgroup\nlocation",
|
175
|
+
puppetclass: puppetclass_two)
|
176
|
+
|
177
|
+
parent_hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc,
|
178
|
+
puppetclasses: [puppetclass_two],
|
179
|
+
environment: environment)
|
180
|
+
child_hostgroup = FactoryBot.build(:hostgroup, :with_puppet_enc, parent: parent_hostgroup)
|
181
|
+
|
182
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment, organization: taxonomies(:organization1),
|
183
|
+
puppetclasses: [puppetclass], hostgroup: child_hostgroup)
|
184
|
+
|
185
|
+
as_admin do
|
186
|
+
LookupValue.create! lookup_key_id: key.id,
|
187
|
+
match: "hostgroup=#{parent_hostgroup}",
|
188
|
+
value: ['parent'],
|
189
|
+
omit: false
|
190
|
+
LookupValue.create! lookup_key_id: key.id,
|
191
|
+
match: "organization=#{taxonomies(:organization1)}",
|
192
|
+
value: ['org'],
|
193
|
+
omit: false
|
194
|
+
end
|
195
|
+
|
196
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
197
|
+
|
198
|
+
assert_equal %w[org parent], enc[puppetclass_two.name][key.key]
|
199
|
+
end
|
200
|
+
|
201
|
+
test '#enc should return correct merged override to host when multiple overrides for inherited organizations exist' do
|
202
|
+
FactoryBot.create(:setting,
|
203
|
+
name: 'matchers_inheritance',
|
204
|
+
value: true)
|
205
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
206
|
+
key_type: 'array', merge_overrides: true,
|
207
|
+
path: "location\norganization\nhostgroup",
|
208
|
+
puppetclass: puppetclass_two)
|
209
|
+
|
210
|
+
parent_org = taxonomies(:organization1)
|
211
|
+
child_org = taxonomies(:organization2)
|
212
|
+
child_org.update(parent: parent_org)
|
213
|
+
|
214
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment,
|
215
|
+
puppetclasses: [puppetclass_two],
|
216
|
+
organization: child_org,
|
217
|
+
location: taxonomies(:location1))
|
218
|
+
|
219
|
+
as_admin do
|
220
|
+
LookupValue.create! lookup_key_id: key.id,
|
221
|
+
match: "organization=#{parent_org}",
|
222
|
+
value: ['parent'],
|
223
|
+
omit: false
|
224
|
+
LookupValue.create! lookup_key_id: key.id,
|
225
|
+
match: "location=#{taxonomies(:location1)}",
|
226
|
+
value: ['loc'],
|
227
|
+
omit: false
|
228
|
+
end
|
229
|
+
|
230
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
231
|
+
|
232
|
+
assert_equal %w[loc parent], enc[puppetclass_two.name][key.key]
|
233
|
+
end
|
234
|
+
|
235
|
+
test '#enc should return correct merged override to host when multiple overrides for inherited locations exist' do
|
236
|
+
FactoryBot.create(:setting,
|
237
|
+
name: 'matchers_inheritance',
|
238
|
+
value: true)
|
239
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
240
|
+
key_type: 'array', merge_overrides: true,
|
241
|
+
path: "organization\nhostgroup\nlocation",
|
242
|
+
puppetclass: puppetclass_two)
|
243
|
+
|
244
|
+
parent_loc = taxonomies(:location1)
|
245
|
+
child_loc = taxonomies(:location2)
|
246
|
+
child_loc.update(parent: parent_loc)
|
247
|
+
|
248
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment,
|
249
|
+
puppetclasses: [puppetclass_two],
|
250
|
+
organization: taxonomies(:organization1),
|
251
|
+
location: child_loc)
|
252
|
+
|
253
|
+
as_admin do
|
254
|
+
LookupValue.create! lookup_key_id: key.id,
|
255
|
+
match: "location=#{parent_loc}",
|
256
|
+
value: ['parent'],
|
257
|
+
omit: false
|
258
|
+
LookupValue.create! lookup_key_id: key.id,
|
259
|
+
match: "organization=#{taxonomies(:organization1)}",
|
260
|
+
value: ['org'],
|
261
|
+
omit: false
|
262
|
+
end
|
263
|
+
|
264
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
265
|
+
|
266
|
+
assert_equal %w[org parent], enc[puppetclass_two.name][key.key]
|
267
|
+
end
|
268
|
+
|
269
|
+
test '#enc should return correct merged override to host when multiple overrides for inherited hostgroups exist' do
|
270
|
+
FactoryBot.create(:setting,
|
271
|
+
name: 'matchers_inheritance',
|
272
|
+
value: true)
|
273
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
274
|
+
key_type: 'array', merge_overrides: true,
|
275
|
+
path: "organization\nhostgroup\nlocation",
|
276
|
+
puppetclass: puppetclass_two)
|
277
|
+
|
278
|
+
parent_hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc,
|
279
|
+
puppetclasses: [puppetclass_two],
|
280
|
+
environment: environment)
|
281
|
+
child_hostgroup = FactoryBot.build(:hostgroup, :with_puppet_enc, parent: parent_hostgroup)
|
282
|
+
|
283
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment, organization: taxonomies(:organization1),
|
284
|
+
puppetclasses: [puppetclass], hostgroup: child_hostgroup)
|
285
|
+
|
286
|
+
as_admin do
|
287
|
+
LookupValue.create! lookup_key_id: key.id,
|
288
|
+
match: "hostgroup=#{parent_hostgroup}",
|
289
|
+
value: ['parent'],
|
290
|
+
omit: false
|
291
|
+
LookupValue.create! lookup_key_id: key.id,
|
292
|
+
match: "hostgroup=#{child_hostgroup}",
|
293
|
+
value: ['child'],
|
294
|
+
omit: false
|
295
|
+
LookupValue.create! lookup_key_id: key.id,
|
296
|
+
match: "organization=#{taxonomies(:organization1)}",
|
297
|
+
value: ['org'],
|
298
|
+
omit: false
|
299
|
+
end
|
300
|
+
|
301
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
302
|
+
|
303
|
+
assert_equal %w[org child parent], enc[puppetclass_two.name][key.key]
|
304
|
+
end
|
305
|
+
|
306
|
+
test '#enc should return correct merged override to host when multiple overrides for inherited organizations exist' do
|
307
|
+
FactoryBot.create(:setting,
|
308
|
+
name: 'matchers_inheritance',
|
309
|
+
value: true)
|
310
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
311
|
+
key_type: 'array', merge_overrides: true,
|
312
|
+
path: "location\norganization\nhostgroup",
|
313
|
+
puppetclass: puppetclass_two)
|
314
|
+
|
315
|
+
parent_org = taxonomies(:organization1)
|
316
|
+
child_org = taxonomies(:organization2)
|
317
|
+
child_org.update(parent: parent_org)
|
318
|
+
|
319
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment,
|
320
|
+
puppetclasses: [puppetclass_two],
|
321
|
+
organization: child_org,
|
322
|
+
location: taxonomies(:location1))
|
323
|
+
|
324
|
+
as_admin do
|
325
|
+
LookupValue.create! lookup_key_id: key.id,
|
326
|
+
match: "organization=#{parent_org}",
|
327
|
+
value: ['parent'],
|
328
|
+
omit: false
|
329
|
+
LookupValue.create! lookup_key_id: key.id,
|
330
|
+
match: "organization=#{child_org}",
|
331
|
+
value: ['child'],
|
332
|
+
omit: false
|
333
|
+
LookupValue.create! lookup_key_id: key.id,
|
334
|
+
match: "location=#{taxonomies(:location1)}",
|
335
|
+
value: ['loc'],
|
336
|
+
omit: false
|
337
|
+
end
|
338
|
+
|
339
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
340
|
+
|
341
|
+
assert_equal %w[loc child parent], enc[puppetclass_two.name][key.key]
|
342
|
+
end
|
343
|
+
|
344
|
+
test '#enc should return correct merged override to host when multiple overrides for inherited locations exist' do
|
345
|
+
FactoryBot.create(:setting,
|
346
|
+
name: 'matchers_inheritance',
|
347
|
+
value: true)
|
348
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
349
|
+
key_type: 'array', merge_overrides: true,
|
350
|
+
path: "organization\nhostgroup\nlocation",
|
351
|
+
puppetclass: puppetclass_two)
|
352
|
+
|
353
|
+
parent_loc = taxonomies(:location1)
|
354
|
+
child_loc = taxonomies(:location2)
|
355
|
+
child_loc.update(parent: parent_loc)
|
356
|
+
|
357
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment,
|
358
|
+
puppetclasses: [puppetclass_two],
|
359
|
+
organization: taxonomies(:organization1),
|
360
|
+
location: child_loc)
|
361
|
+
|
362
|
+
as_admin do
|
363
|
+
LookupValue.create! lookup_key_id: key.id,
|
364
|
+
match: "location=#{parent_loc}",
|
365
|
+
value: ['parent'],
|
366
|
+
omit: false
|
367
|
+
LookupValue.create! lookup_key_id: key.id,
|
368
|
+
match: "location=#{child_loc}",
|
369
|
+
value: ['child'],
|
370
|
+
omit: false
|
371
|
+
LookupValue.create! lookup_key_id: key.id,
|
372
|
+
match: "organization=#{taxonomies(:organization1)}",
|
373
|
+
value: ['org'],
|
374
|
+
omit: false
|
375
|
+
end
|
376
|
+
|
377
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
378
|
+
|
379
|
+
assert_equal %w[org child parent], enc[puppetclass_two.name][key.key]
|
380
|
+
end
|
381
|
+
|
382
|
+
test '#enc should return correct override to host when multiple overrides for inherited hostgroups exist' do
|
383
|
+
FactoryBot.create(:setting,
|
384
|
+
name: 'matchers_inheritance',
|
385
|
+
value: true)
|
386
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
387
|
+
merge_overrides: false,
|
388
|
+
path: "organization\nhostgroup\nlocation",
|
389
|
+
puppetclass: puppetclass_two)
|
390
|
+
|
391
|
+
parent_hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc,
|
392
|
+
puppetclasses: [puppetclass_two],
|
393
|
+
environment: environment)
|
394
|
+
child_hostgroup = FactoryBot.build(:hostgroup, :with_puppet_enc, parent: parent_hostgroup)
|
395
|
+
|
396
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment, organization: taxonomies(:organization1),
|
397
|
+
puppetclasses: [puppetclass], hostgroup: child_hostgroup)
|
398
|
+
|
399
|
+
value2 = as_admin do
|
400
|
+
LookupValue.create! lookup_key_id: key.id,
|
401
|
+
match: "hostgroup=#{parent_hostgroup}",
|
402
|
+
value: 'parent',
|
403
|
+
omit: false
|
404
|
+
LookupValue.create! lookup_key_id: key.id,
|
405
|
+
match: "hostgroup=#{child_hostgroup}",
|
406
|
+
value: 'child',
|
407
|
+
omit: false
|
408
|
+
LookupValue.create! lookup_key_id: key.id,
|
409
|
+
match: "organization=#{taxonomies(:organization1)}",
|
410
|
+
value: 'org',
|
411
|
+
omit: false
|
412
|
+
end
|
413
|
+
|
414
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
415
|
+
|
416
|
+
assert_equal value2.value, enc[puppetclass_two.name][key.key]
|
417
|
+
end
|
418
|
+
|
419
|
+
test '#enc should return correct override to host when multiple overrides for inherited organizations exist' do
|
420
|
+
FactoryBot.create(:setting,
|
421
|
+
name: 'matchers_inheritance',
|
422
|
+
value: true)
|
423
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
424
|
+
merge_overrides: false,
|
425
|
+
path: "location\norganization\nhostgroup",
|
426
|
+
puppetclass: puppetclass_two)
|
427
|
+
|
428
|
+
parent_org = taxonomies(:organization1)
|
429
|
+
child_org = taxonomies(:organization2)
|
430
|
+
child_org.update(parent: parent_org)
|
431
|
+
|
432
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment, organization: child_org,
|
433
|
+
puppetclasses: [puppetclass_two], location: taxonomies(:location1))
|
434
|
+
|
435
|
+
value2 = as_admin do
|
436
|
+
LookupValue.create! lookup_key_id: key.id,
|
437
|
+
match: "organization=#{parent_org}",
|
438
|
+
value: 'parent',
|
439
|
+
omit: false
|
440
|
+
LookupValue.create! lookup_key_id: key.id,
|
441
|
+
match: "organization=#{child_org}",
|
442
|
+
value: 'child',
|
443
|
+
omit: false
|
444
|
+
LookupValue.create! lookup_key_id: key.id,
|
445
|
+
match: "location=#{taxonomies(:location1)}",
|
446
|
+
value: 'loc',
|
447
|
+
omit: false
|
448
|
+
end
|
449
|
+
|
450
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
451
|
+
|
452
|
+
assert_equal value2.value, enc[puppetclass_two.name][key.key]
|
453
|
+
end
|
454
|
+
|
455
|
+
test '#enc should return correct override to host when multiple overrides for inherited locations exist' do
|
456
|
+
FactoryBot.create(:setting,
|
457
|
+
name: 'matchers_inheritance',
|
458
|
+
value: true)
|
459
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
460
|
+
merge_overrides: false,
|
461
|
+
path: "organization\nlocation\nhostgroup",
|
462
|
+
puppetclass: puppetclass_two)
|
463
|
+
|
464
|
+
parent_loc = taxonomies(:location1)
|
465
|
+
child_loc = taxonomies(:location2)
|
466
|
+
child_loc.update(parent: parent_loc)
|
467
|
+
|
468
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment, organization: taxonomies(:organization1),
|
469
|
+
puppetclasses: [puppetclass_two], location: child_loc)
|
470
|
+
|
471
|
+
value2 = as_admin do
|
472
|
+
LookupValue.create! lookup_key_id: key.id,
|
473
|
+
match: "location=#{parent_loc}",
|
474
|
+
value: 'parent',
|
475
|
+
omit: false
|
476
|
+
LookupValue.create! lookup_key_id: key.id,
|
477
|
+
match: "location=#{child_loc}",
|
478
|
+
value: 'child',
|
479
|
+
omit: false
|
480
|
+
LookupValue.create! lookup_key_id: key.id,
|
481
|
+
match: "organization=#{taxonomies(:organization1)}",
|
482
|
+
value: 'org',
|
483
|
+
omit: false
|
484
|
+
end
|
485
|
+
|
486
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
487
|
+
|
488
|
+
assert_equal value2.value, enc[puppetclass_two.name][key.key]
|
489
|
+
end
|
490
|
+
|
491
|
+
test '#enc should return correct override to host when multiple overrides for inherited hostgroups exist' do
|
492
|
+
FactoryBot.create(:setting,
|
493
|
+
name: 'matchers_inheritance',
|
494
|
+
value: true)
|
495
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
496
|
+
merge_overrides: false,
|
497
|
+
path: "organization\nhostgroup\nlocation",
|
498
|
+
puppetclass: puppetclass_two)
|
499
|
+
|
500
|
+
parent_hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc,
|
501
|
+
puppetclasses: [puppetclass_two],
|
502
|
+
environment: environment)
|
503
|
+
child_hostgroup = FactoryBot.build(:hostgroup, parent: parent_hostgroup)
|
504
|
+
|
505
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment, puppetclasses: [puppetclass], hostgroup: child_hostgroup)
|
506
|
+
|
507
|
+
value2 = as_admin do
|
508
|
+
LookupValue.create! lookup_key_id: key.id,
|
509
|
+
match: "hostgroup=#{parent_hostgroup}",
|
510
|
+
value: 'parent',
|
511
|
+
omit: false
|
512
|
+
LookupValue.create! lookup_key_id: key.id,
|
513
|
+
match: "location=#{taxonomies(:location1)}",
|
514
|
+
value: 'loc',
|
515
|
+
omit: true
|
516
|
+
LookupValue.create! lookup_key_id: key.id,
|
517
|
+
match: "hostgroup=#{child_hostgroup}",
|
518
|
+
value: 'child',
|
519
|
+
omit: false
|
520
|
+
end
|
521
|
+
|
522
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
523
|
+
|
524
|
+
assert_equal value2.value, enc[puppetclass_two.name][key.key]
|
525
|
+
end
|
526
|
+
|
527
|
+
test '#enc should return correct override to host when multiple overrides for inherited organizations exist' do
|
528
|
+
FactoryBot.create(:setting,
|
529
|
+
name: 'matchers_inheritance',
|
530
|
+
value: true)
|
531
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
532
|
+
merge_overrides: false,
|
533
|
+
path: "organization\nhostgroup\nlocation",
|
534
|
+
puppetclass: puppetclass_two)
|
535
|
+
|
536
|
+
parent_org = taxonomies(:organization1)
|
537
|
+
child_org = taxonomies(:organization2)
|
538
|
+
child_org.update(parent: parent_org)
|
539
|
+
|
540
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment,
|
541
|
+
puppetclasses: [puppetclass_two],
|
542
|
+
organization: child_org,
|
543
|
+
location: taxonomies(:location1))
|
544
|
+
|
545
|
+
value2 = as_admin do
|
546
|
+
LookupValue.create! lookup_key_id: key.id,
|
547
|
+
match: "organization=#{parent_org}",
|
548
|
+
value: 'parent',
|
549
|
+
omit: false
|
550
|
+
LookupValue.create! lookup_key_id: key.id,
|
551
|
+
match: "location=#{taxonomies(:location1)}",
|
552
|
+
value: 'loc',
|
553
|
+
omit: true
|
554
|
+
LookupValue.create! lookup_key_id: key.id,
|
555
|
+
match: "organization=#{child_org}",
|
556
|
+
value: 'child',
|
557
|
+
omit: false
|
558
|
+
end
|
559
|
+
|
560
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
561
|
+
|
562
|
+
assert_equal value2.value, enc[puppetclass_two.name][key.key]
|
563
|
+
end
|
564
|
+
|
565
|
+
test '#enc should return correct override to host when multiple overrides for inherited locations exist' do
|
566
|
+
FactoryBot.create(:setting,
|
567
|
+
name: 'matchers_inheritance',
|
568
|
+
value: true)
|
569
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
570
|
+
merge_overrides: false,
|
571
|
+
path: "location\norganization\nhostgroup",
|
572
|
+
puppetclass: puppetclass_two)
|
573
|
+
|
574
|
+
parent_loc = taxonomies(:location1)
|
575
|
+
child_loc = taxonomies(:location2)
|
576
|
+
child_loc.update(parent: parent_loc)
|
577
|
+
|
578
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment,
|
579
|
+
puppetclasses: [puppetclass_two],
|
580
|
+
organization: taxonomies(:organization1),
|
581
|
+
location: child_loc)
|
582
|
+
|
583
|
+
value2 = as_admin do
|
584
|
+
LookupValue.create! lookup_key_id: key.id,
|
585
|
+
match: "location=#{parent_loc}",
|
586
|
+
value: 'parent',
|
587
|
+
omit: false
|
588
|
+
LookupValue.create! lookup_key_id: key.id,
|
589
|
+
match: "organization=#{taxonomies(:organization1)}",
|
590
|
+
value: 'org',
|
591
|
+
omit: true
|
592
|
+
LookupValue.create! lookup_key_id: key.id,
|
593
|
+
match: "location=#{child_loc}",
|
594
|
+
value: 'child',
|
595
|
+
omit: false
|
596
|
+
end
|
597
|
+
|
598
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
599
|
+
|
600
|
+
assert_equal value2.value, enc[puppetclass_two.name][key.key]
|
601
|
+
end
|
602
|
+
|
603
|
+
test 'enc should return correct values for multi-key matchers' do
|
604
|
+
key = FactoryBot.create(:puppetclass_lookup_key,
|
605
|
+
default_value: '',
|
606
|
+
path: "organization\norganization,location\nlocation",
|
607
|
+
puppetclass: puppetclass)
|
608
|
+
|
609
|
+
value2 = as_admin do
|
610
|
+
LookupValue.create! lookup_key_id: key.id,
|
611
|
+
match: "location=#{taxonomies(:location1)}",
|
612
|
+
value: 'test_incorrect',
|
613
|
+
omit: false
|
614
|
+
LookupValue.create! lookup_key_id: key.id,
|
615
|
+
match: "organization=#{taxonomies(:organization1)},location=#{taxonomies(:location1)}",
|
616
|
+
value: 'test_correct',
|
617
|
+
omit: false
|
618
|
+
end
|
619
|
+
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
620
|
+
key.reload
|
621
|
+
|
622
|
+
assert_equal value2.value, enc[puppetclass.name][key.key]
|
623
|
+
end
|
624
|
+
|
625
|
+
test 'enc should return correct values for multi-key matchers with more specific first' do
|
626
|
+
key = FactoryBot.create(:puppetclass_lookup_key,
|
627
|
+
default_value: '',
|
628
|
+
path: "organization,location\norganization",
|
629
|
+
puppetclass: puppetclass)
|
630
|
+
|
631
|
+
value = as_admin do
|
632
|
+
LookupValue.create! lookup_key_id: key.id,
|
633
|
+
match: "organization=#{taxonomies(:organization1)},location=#{taxonomies(:location1)}",
|
634
|
+
value: 'test_correct',
|
635
|
+
omit: false
|
636
|
+
end
|
637
|
+
as_admin do
|
638
|
+
LookupValue.create! lookup_key_id: key.id,
|
639
|
+
match: "organization=#{taxonomies(:organization1)}",
|
640
|
+
value: 'test_incorrect',
|
641
|
+
omit: false
|
642
|
+
end
|
643
|
+
enc = HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters
|
644
|
+
|
645
|
+
assert_equal value.value, enc[puppetclass.name][key.key]
|
646
|
+
end
|
647
|
+
|
648
|
+
test 'enc should return correct values for multi-key matchers with hostgroup inheritance' do
|
649
|
+
key = FactoryBot.create(:puppetclass_lookup_key, omit: true,
|
650
|
+
merge_overrides: false,
|
651
|
+
path: "hostgroup,organization\nlocation",
|
652
|
+
puppetclass: puppetclass_two)
|
653
|
+
|
654
|
+
parent_hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc,
|
655
|
+
puppetclasses: [puppetclass_two],
|
656
|
+
environment: environment)
|
657
|
+
child_hostgroup = FactoryBot.build(:hostgroup, :with_puppet_enc, parent: parent_hostgroup)
|
658
|
+
|
659
|
+
host = FactoryBot.create(:host, :with_puppet_enc, environment: environment,
|
660
|
+
location: taxonomies(:location1), organization: taxonomies(:organization1),
|
661
|
+
puppetclasses: [puppetclass], hostgroup: child_hostgroup)
|
662
|
+
|
663
|
+
as_admin do
|
664
|
+
LookupValue.create! lookup_key_id: key.id,
|
665
|
+
match: "hostgroup=#{parent_hostgroup},organization=#{taxonomies(:organization1)}",
|
666
|
+
value: 'parent',
|
667
|
+
omit: false
|
668
|
+
end
|
669
|
+
value2 = as_admin do
|
670
|
+
LookupValue.create! lookup_key_id: key.id,
|
671
|
+
match: "hostgroup=#{child_hostgroup},organization=#{taxonomies(:organization1)}",
|
672
|
+
value: 'child',
|
673
|
+
omit: false
|
674
|
+
end
|
675
|
+
|
676
|
+
as_admin do
|
677
|
+
LookupValue.create! lookup_key_id: key.id,
|
678
|
+
match: "location=#{taxonomies(:location1)}",
|
679
|
+
value: 'loc',
|
680
|
+
omit: false
|
681
|
+
end
|
682
|
+
|
683
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
684
|
+
key.reload
|
685
|
+
assert_equal value2.value, enc[puppetclass_two.name][key.key]
|
686
|
+
end
|
687
|
+
|
688
|
+
test 'smart class parameter should accept string with erb for arrays and evaluate it properly' do
|
689
|
+
key = FactoryBot.create(:puppetclass_lookup_key,
|
690
|
+
key_type: 'array', merge_overrides: false,
|
691
|
+
default_value: '<%= [1,2] %>', path: "organization\nos\nlocation",
|
692
|
+
puppetclass: puppetclass)
|
693
|
+
assert_equal [1, 2], HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters[puppetclass.name][key.key]
|
694
|
+
|
695
|
+
as_admin do
|
696
|
+
LookupValue.create! lookup_key_id: key.id,
|
697
|
+
match: "location=#{taxonomies(:location1)}",
|
698
|
+
value: '<%= [2,3] %>',
|
699
|
+
omit: false
|
700
|
+
end
|
701
|
+
as_admin do
|
702
|
+
LookupValue.create! lookup_key_id: key.id,
|
703
|
+
match: "organization=#{taxonomies(:organization1)}",
|
704
|
+
value: '<%= [3,4] %>',
|
705
|
+
omit: false
|
706
|
+
end
|
707
|
+
as_admin do
|
708
|
+
LookupValue.create! lookup_key_id: key.id,
|
709
|
+
match: "os=#{operatingsystems(:redhat)}",
|
710
|
+
value: '<%= [4,5] %>',
|
711
|
+
omit: false
|
712
|
+
end
|
713
|
+
|
714
|
+
key.reload
|
715
|
+
|
716
|
+
assert_equal({ key.id => { key.key => { value: '<%= [3,4] %>',
|
717
|
+
element: 'organization',
|
718
|
+
element_name: 'Organization 1',
|
719
|
+
managed: false } } },
|
720
|
+
Classification::ValuesHashQuery.values_hash(@host, LookupKey.where(id: [key])).raw)
|
721
|
+
assert_equal [3, 4], HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters[puppetclass.name][key.key]
|
722
|
+
end
|
723
|
+
|
724
|
+
test 'enc should return correct values for multi-key matchers' do
|
725
|
+
hostgroup = FactoryBot.build(:hostgroup, :with_puppet_enc)
|
726
|
+
|
727
|
+
key = FactoryBot.create(:puppetclass_lookup_key, :with_omit,
|
728
|
+
merge_overrides: false,
|
729
|
+
path: "hostgroup,organization\nlocation",
|
730
|
+
puppetclass: puppetclass_two)
|
731
|
+
|
732
|
+
parent_hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc,
|
733
|
+
puppetclasses: [puppetclass_two],
|
734
|
+
environment: environment)
|
735
|
+
hostgroup.update(parent: parent_hostgroup)
|
736
|
+
|
737
|
+
FactoryBot.build(:lookup_value, lookup_key_id: key.id, match: "hostgroup=#{parent_hostgroup},organization=#{taxonomies(:organization1)}")
|
738
|
+
lv = FactoryBot.create(:lookup_value, lookup_key_id: key.id, match: "hostgroup=#{hostgroup},organization=#{taxonomies(:organization1)}")
|
739
|
+
FactoryBot.build(:lookup_value, lookup_key_id: key.id, match: "location=#{taxonomies(:location1)}")
|
740
|
+
|
741
|
+
host = FactoryBot.build_stubbed(:host, :with_puppet_enc, hostgroup: hostgroup,
|
742
|
+
environment: environment,
|
743
|
+
location: taxonomies(:location1),
|
744
|
+
organization: taxonomies(:organization1))
|
745
|
+
|
746
|
+
enc = HostInfoProviders::PuppetInfo.new(host).puppetclass_parameters
|
747
|
+
key.reload
|
748
|
+
assert_equal lv.value, enc[puppetclass_two.name][key.key]
|
749
|
+
end
|
750
|
+
|
751
|
+
test 'smart class parameter with erb values is validated after erb is evaluated' do
|
752
|
+
key = FactoryBot.create(:puppetclass_lookup_key,
|
753
|
+
merge_overrides: false,
|
754
|
+
default_value: '<%= "a" %>', path: "organization\nos\nlocation",
|
755
|
+
puppetclass: puppetclass,
|
756
|
+
validator_type: 'list', validator_rule: 'b')
|
757
|
+
|
758
|
+
assert_raise RuntimeError do
|
759
|
+
HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters[puppetclass.name][key.key]
|
760
|
+
end
|
761
|
+
|
762
|
+
key.update(default_value: '<%= "b" %>')
|
763
|
+
assert_equal 'b', HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters[puppetclass.name][key.key]
|
764
|
+
|
765
|
+
as_admin do
|
766
|
+
LookupValue.create! lookup_key_id: key.id,
|
767
|
+
match: "location=#{taxonomies(:location1)}",
|
768
|
+
value: '<%= "c" %>',
|
769
|
+
omit: false
|
770
|
+
end
|
771
|
+
|
772
|
+
key.reload
|
773
|
+
|
774
|
+
assert_raise RuntimeError do
|
775
|
+
HostInfoProviders::PuppetInfo.new(@host).puppetclass_parameters[puppetclass.name][key.key]
|
776
|
+
end
|
777
|
+
end
|
778
|
+
|
779
|
+
private
|
780
|
+
|
781
|
+
def get_classparam(env, classes)
|
782
|
+
host = Host.new
|
783
|
+
puppet_mock = mock('HostPuppetFacet')
|
784
|
+
puppet_mock.stubs(environment: env, environment_id: env.id)
|
785
|
+
host.stubs(:puppet).returns(puppet_mock)
|
786
|
+
puppet_mock.expects(:classes).returns(Array.wrap(classes))
|
787
|
+
puppet_mock.expects(:puppetclass_ids).returns(Array.wrap(classes).map(&:id))
|
788
|
+
HostInfoProviders::PuppetInfo.new(host)
|
789
|
+
end
|
790
|
+
end
|
791
|
+
end
|