foreman_puppet 0.1.0 → 1.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/foreman_puppet/extensions/api_base_controller.rb +28 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +1 -1
- data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +5 -1
- data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +1 -2
- data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +5 -1
- data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +5 -1
- data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +1 -2
- data/app/controllers/foreman_puppet/api/v2/{base_controller.rb → puppet_base_controller.rb} +2 -3
- data/app/controllers/foreman_puppet/api/v2/{lookups_common_controller.rb → puppet_lookups_common_controller.rb} +6 -2
- data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +5 -1
- data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +1 -2
- data/app/controllers/foreman_puppet/puppetclasses_controller.rb +9 -2
- data/app/graphgl/concerns/foreman_puppet/mutations/hosts/create_extensions.rb +29 -0
- data/app/graphgl/concerns/foreman_puppet/types/host_extensions.rb +13 -0
- data/app/graphgl/concerns/foreman_puppet/types/hostgroup_extensions.rb +13 -0
- data/app/graphgl/concerns/foreman_puppet/types/location_extensions.rb +14 -0
- data/app/graphgl/concerns/foreman_puppet/types/organization_extensions.rb +14 -0
- data/app/graphgl/foreman_puppet/types/environment.rb +20 -0
- data/app/graphgl/foreman_puppet/types/puppetclass.rb +20 -0
- data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +1 -1
- data/app/helpers/foreman_puppet/puppetclasses_helper.rb +2 -2
- data/app/models/concerns/foreman_puppet/extensions/host.rb +6 -4
- data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +6 -2
- data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +1 -1
- data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +16 -10
- data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +1 -1
- data/app/models/foreman_puppet/environment.rb +2 -0
- data/app/models/foreman_puppet/host_puppet_facet.rb +1 -1
- data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +1 -1
- data/app/models/{concerns/foreman_puppet/host_common.rb → foreman_puppet/puppet_facet_common.rb} +1 -1
- data/app/models/foreman_puppet/puppetclass.rb +2 -0
- data/app/{views/api/v2/template_combinations/base.json.erb → prepend_views/api/v2/template_combinations/base.json.rabl} +0 -0
- data/app/services/foreman_puppet/puppet_class_importer.rb +3 -4
- data/app/views/foreman_puppet/config_groups/index.html.erb +2 -2
- data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -11
- data/app/views/foreman_puppet/environments/welcome.html.erb +3 -15
- data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +10 -8
- data/config/initializers/api_reroute.rb +13 -0
- data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +16 -10
- data/lib/foreman_puppet.rb +1 -1
- data/lib/foreman_puppet/engine.rb +48 -16
- data/lib/foreman_puppet/register.rb +5 -0
- data/lib/foreman_puppet/version.rb +1 -1
- data/locale/en/foreman_puppet.edit.po +927 -0
- data/locale/en/foreman_puppet.po.time_stamp +0 -0
- data/locale/en/foreman_puppet.pox +0 -0
- data/locale/messages.mo +0 -0
- data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +7 -3
- data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +17 -15
- data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +2 -1
- data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +1 -1
- data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +3 -0
- data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +7 -1
- data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/config_groups_controller_test.rb +7 -3
- data/test/controllers/foreman_puppet/environments_controller_test.rb +1 -1
- data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +5 -6
- data/test/factories/host_puppet_enhancements.rb +6 -6
- data/test/graphql/mutations/hosts/create_mutation_test.rb +66 -0
- data/test/graphql/queries/environment_query_test.rb +54 -0
- data/test/graphql/queries/environments_query_test.rb +43 -0
- data/test/{qraphql → graphql}/queries/host_puppet_query_test.rb +3 -8
- data/test/{qraphql → graphql}/queries/hostgroup_puppet_query_test.rb +1 -6
- data/test/graphql/queries/location_query_test.rb +52 -0
- data/test/graphql/queries/organization_query_test.rb +52 -0
- data/test/graphql/queries/puppetclass_query_test.rb +68 -0
- data/test/graphql/queries/puppetclasses_query_test.rb +43 -0
- data/test/integration/foreman_puppet/environment_js_test.rb +4 -1
- data/test/integration/foreman_puppet/host_js_test.rb +1 -1
- data/test/integration/foreman_puppet/puppetclass_js_test.rb +1 -0
- data/test/models/foreman_puppet/config_group_class_test.rb +3 -1
- data/test/models/foreman_puppet/environment_test.rb +2 -0
- data/test/models/foreman_puppet/host_test.rb +3 -2
- data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +2 -3
- data/test/models/foreman_puppet/provisioning_template_test.rb +23 -23
- data/test/models/foreman_puppet/smart_proxy_test.rb +1 -1
- data/test/models/foreman_puppet/user_test.rb +13 -5
- data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +0 -36
- data/test/unit/foreman_puppet/puppet_class_importer_test.rb +3 -1
- data/webpack/index.js +3 -4
- data/webpack/src/Components/Environments/Welcome.js +37 -0
- metadata +78 -50
File without changes
|
File without changes
|
data/locale/messages.mo
ADDED
Binary file
|
@@ -6,18 +6,22 @@ module ForemanPuppet
|
|
6
6
|
setup do
|
7
7
|
@routes = ForemanPuppet::Engine.routes
|
8
8
|
end
|
9
|
+
|
10
|
+
let(:puppetclasses) { FactoryBot.create_list(:puppetclass, 2) }
|
11
|
+
let(:config_group) { FactoryBot.create(:config_group) }
|
12
|
+
|
9
13
|
test 'should create config group' do
|
10
14
|
assert_difference('ConfigGroup.count') do
|
11
|
-
post :create, params: { config_group: { name: 'config-group', puppetclass_ids:
|
15
|
+
post :create, params: { config_group: { name: 'config-group', puppetclass_ids: puppetclasses.map(&:id) } }
|
12
16
|
end
|
13
17
|
assert_response :created
|
14
18
|
end
|
15
19
|
|
16
20
|
test 'should update config group' do
|
17
21
|
name = 'new name'
|
18
|
-
put :update, params: { id:
|
22
|
+
put :update, params: { id: config_group.to_param,
|
19
23
|
config_group: { name: name,
|
20
|
-
puppetclass_ids:
|
24
|
+
puppetclass_ids: puppetclasses.map(&:id) } }
|
21
25
|
assert_response :success
|
22
26
|
response = JSON.parse(@response.body)
|
23
27
|
assert_equal 2, response['puppetclasses'].count
|
@@ -106,7 +106,7 @@ module ForemanPuppet
|
|
106
106
|
|
107
107
|
test 'should destroy environments' do
|
108
108
|
environment
|
109
|
-
assert_difference(
|
109
|
+
assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, -1) do
|
110
110
|
delete :destroy, params: { id: environment.to_param }
|
111
111
|
end
|
112
112
|
assert_response :success
|
@@ -171,12 +171,14 @@ module ForemanPuppet
|
|
171
171
|
test 'should obsolete environment' do
|
172
172
|
setup_import_classes
|
173
173
|
as_admin do
|
174
|
-
|
175
|
-
end
|
176
|
-
assert_difference(-> { ForemanPuppet::Environment.unscoped.count }, -1) do
|
177
|
-
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
174
|
+
FactoryBot.create(:environment, name: 'xyz')
|
178
175
|
end
|
176
|
+
|
177
|
+
post :import_puppetclasses, params: { id: proxy.id }, session: set_session_user
|
179
178
|
assert_response :success
|
179
|
+
as_admin do
|
180
|
+
assert_nil ForemanPuppet::Environment.find_by(name: 'xyz')
|
181
|
+
end
|
180
182
|
end
|
181
183
|
|
182
184
|
test 'should obsolete puppetclasses' do
|
@@ -313,22 +315,22 @@ module ForemanPuppet
|
|
313
315
|
|
314
316
|
def setup_import_classes
|
315
317
|
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
|
318
|
+
::Host::Managed.update_all(environment_id: nil)
|
319
|
+
::Hostgroup.update_all(environment_id: nil)
|
320
|
+
ForemanPuppet::HostClass.destroy_all
|
321
|
+
ForemanPuppet::HostgroupClass.destroy_all
|
322
|
+
ForemanPuppet::Puppetclass.destroy_all
|
323
|
+
ForemanPuppet::Environment.destroy_all
|
322
324
|
end
|
323
325
|
orgs = [taxonomies(:organization1)]
|
324
326
|
locs = [taxonomies(:location1)]
|
325
327
|
# This is the database status
|
326
328
|
# and should result in a db_tree of {"env1" => ["a", "b", "c"], "env2" => ["a", "b", "c"]}
|
327
329
|
as_admin do
|
328
|
-
%w[a b c].each { |name| Puppetclass.create name: name }
|
330
|
+
%w[a b c].each { |name| ForemanPuppet::Puppetclass.create name: name }
|
329
331
|
%w[env1 env2].each do |name|
|
330
|
-
e = Environment.create!(name: name, organizations: orgs, locations: locs)
|
331
|
-
e.puppetclasses = Puppetclass.all
|
332
|
+
e = ForemanPuppet::Environment.create!(name: name, organizations: orgs, locations: locs)
|
333
|
+
e.puppetclasses = ForemanPuppet::Puppetclass.all
|
332
334
|
end
|
333
335
|
end
|
334
336
|
# This is the on-disk status
|
@@ -336,7 +338,7 @@ module ForemanPuppet
|
|
336
338
|
envs = HashWithIndifferentAccess.new(env1: %w[a b c], env2: %w[a b c])
|
337
339
|
pcs = [HashWithIndifferentAccess.new('a' => { 'name' => 'a', 'module' => nil, 'params' => { 'key' => 'special' } })]
|
338
340
|
classes = pcs.map { |k| [k.keys.first, Foreman::ImporterPuppetclass.new(k.values.first)] }.to_h
|
339
|
-
Environment.expects(:puppetEnvs).returns(envs).at_least(0)
|
341
|
+
ForemanPuppet::Environment.expects(:puppetEnvs).returns(envs).at_least(0)
|
340
342
|
ProxyAPI::Puppet.any_instance.stubs(:environments).returns(%w[env1 env2])
|
341
343
|
ProxyAPI::Puppet.any_instance.stubs(:classes).returns(classes)
|
342
344
|
end
|
@@ -61,10 +61,11 @@ module ForemanPuppet
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#create' do
|
64
|
-
test 'should create with puppet proxy' do
|
64
|
+
test 'should create with puppet proxy and environment' do
|
65
65
|
host_params = FactoryBot.attributes_for(:host, managed: false).merge(environment_id: environment.id, puppet_proxy_id: puppet_proxy.to_param)
|
66
66
|
post :create, params: { host: host_params }
|
67
67
|
assert_response :created
|
68
|
+
assert_equal environment.name, JSON.parse(@response.body)['environment_name'], "Can't create host environment #{environment}"
|
68
69
|
assert_equal puppet_proxy.name, JSON.parse(@response.body)['puppet_proxy']['name'], "Can't create host with puppet proxy #{puppet_proxy}"
|
69
70
|
end
|
70
71
|
end
|
@@ -3,7 +3,7 @@ require 'test_puppet_helper'
|
|
3
3
|
module ForemanPuppet
|
4
4
|
module Api
|
5
5
|
module V2
|
6
|
-
class DummyLookupController < ForemanPuppet::Api::V2::
|
6
|
+
class DummyLookupController < ForemanPuppet::Api::V2::PuppetLookupsCommonController
|
7
7
|
attr_accessor :params
|
8
8
|
end
|
9
9
|
|
@@ -35,18 +35,21 @@ module ForemanPuppet
|
|
35
35
|
|
36
36
|
context 'with taxonomy given' do
|
37
37
|
test 'index should return puppetclasses only in Organization' do
|
38
|
+
puppetclass
|
38
39
|
get :index, params: { organization_id: default_organization.id }
|
39
40
|
assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
|
40
41
|
assert_response :success
|
41
42
|
end
|
42
43
|
|
43
44
|
test 'index should return puppetclasses only in Organization' do
|
45
|
+
puppetclass
|
44
46
|
get :index, params: { location_id: default_location.id }
|
45
47
|
assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
|
46
48
|
assert_response :success
|
47
49
|
end
|
48
50
|
|
49
51
|
test 'index should return puppetclasses only in Organization' do
|
52
|
+
puppetclass
|
50
53
|
get :index, params: { location_id: default_location.id, organization_id: default_organization.id }
|
51
54
|
assert_include json_response['results'].map { |_, v| v[0]['id'] }, puppetclass.id
|
52
55
|
assert_response :success
|
@@ -207,11 +207,17 @@ module ForemanPuppet
|
|
207
207
|
|
208
208
|
test_attributes pid: 'd7b1c336-bd9f-40a3-a573-939f2a021cdc'
|
209
209
|
test 'should not set merge overrides for non supported types' do
|
210
|
+
expected_error = if Gem::Version.new(SETTINGS[:version].notag) < Gem::Version.new('2.6')
|
211
|
+
'Validation failed: Merge overrides can only be set for array or hash'
|
212
|
+
else
|
213
|
+
'Validation failed: Merge overrides can only be set for array, hash, json or yaml'
|
214
|
+
end
|
215
|
+
|
210
216
|
put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
|
211
217
|
default_value: RFauxFactory.gen_alpha,
|
212
218
|
merge_overrides: true } }
|
213
219
|
assert_response :internal_server_error, 'Can set merge overrides for non supported types'
|
214
|
-
assert_error_message(
|
220
|
+
assert_error_message(expected_error)
|
215
221
|
assert_not(lookup_key.reload.merge_overrides)
|
216
222
|
end
|
217
223
|
|
@@ -64,8 +64,8 @@ module ForemanPuppet
|
|
64
64
|
environment_id: template_combination.environment.id, id: template_combination.id }
|
65
65
|
|
66
66
|
json_response = ActiveSupport::JSON.decode(@response.body)
|
67
|
-
assert_equal(json_response['environment_id']
|
68
|
-
assert_equal(
|
67
|
+
assert_equal(environment.id, json_response['environment_id'])
|
68
|
+
assert_equal(hostgroups(:common).id, json_response['hostgroup_id'])
|
69
69
|
assert_response :success
|
70
70
|
end
|
71
71
|
|
@@ -9,7 +9,10 @@ module ForemanPuppet
|
|
9
9
|
basic_pagination_per_page_test
|
10
10
|
basic_pagination_rendered_test
|
11
11
|
|
12
|
+
let(:config_group) { FactoryBot.create(:config_group) }
|
13
|
+
|
12
14
|
test 'should get index' do
|
15
|
+
config_group
|
13
16
|
get :index, session: set_session_user
|
14
17
|
assert_response :success
|
15
18
|
assert_not_empty assigns(:config_groups)
|
@@ -28,18 +31,19 @@ module ForemanPuppet
|
|
28
31
|
end
|
29
32
|
|
30
33
|
test 'should get edit' do
|
31
|
-
get :edit, params: { id:
|
34
|
+
get :edit, params: { id: config_group }, session: set_session_user
|
32
35
|
assert_response :success
|
33
36
|
end
|
34
37
|
|
35
38
|
test 'should update config_group' do
|
36
|
-
put :update, params: { id:
|
39
|
+
put :update, params: { id: config_group, config_group: { name: 'new name' } }, session: set_session_user
|
37
40
|
assert_redirected_to config_groups_path
|
38
41
|
end
|
39
42
|
|
40
43
|
test 'should destroy config_group' do
|
44
|
+
config_group
|
41
45
|
assert_difference('ForemanPuppet::ConfigGroup.count', -1) do
|
42
|
-
delete :destroy, params: { id:
|
46
|
+
delete :destroy, params: { id: config_group }, session: set_session_user
|
43
47
|
end
|
44
48
|
assert_redirected_to config_groups_path
|
45
49
|
end
|
@@ -170,7 +170,7 @@ module ForemanPuppet
|
|
170
170
|
|
171
171
|
test 'user with viewer rights should fail to edit an environment' do
|
172
172
|
setup_user
|
173
|
-
get :edit, params: { id:
|
173
|
+
get :edit, params: { id: FactoryBot.create(:environment).name }, session: set_session_user.merge(user: users(:one).id)
|
174
174
|
assert_equal(403, @response.status)
|
175
175
|
end
|
176
176
|
|
@@ -4,10 +4,10 @@ module ForemanPuppet
|
|
4
4
|
class PuppetclassLookupKeysControllerTest < ActionController::TestCase
|
5
5
|
setup do
|
6
6
|
@routes = ForemanPuppet::Engine.routes
|
7
|
-
@factory_options = [{ puppetclass:
|
7
|
+
@factory_options = [{ puppetclass: FactoryBot.create(:puppetclass), override: true, default_value: 'test' }]
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key,
|
10
|
+
let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, override: true) }
|
11
11
|
|
12
12
|
basic_pagination_rendered_test
|
13
13
|
basic_pagination_per_page_test
|
@@ -60,23 +60,22 @@ module ForemanPuppet
|
|
60
60
|
|
61
61
|
test 'new db rows are not added to HostClass when POST to parameters' do
|
62
62
|
host = FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)
|
63
|
-
host_puppetclass_ids = host.host_classes.pluck(:puppetclass_id)
|
63
|
+
host_puppetclass_ids = host.puppet.host_classes.pluck(:puppetclass_id)
|
64
64
|
params = { id: puppetclass.id,
|
65
65
|
host_id: host.id,
|
66
|
-
host: { puppetclass_ids: (host_puppetclass_ids + [puppetclass.id]) } }
|
67
|
-
assert_difference(
|
66
|
+
host: { puppet: { puppetclass_ids: (host_puppetclass_ids + [puppetclass.id]) } } }
|
67
|
+
assert_difference(-> { ForemanPuppet::HostClass.count }, 0) do
|
68
68
|
post :parameters, params: params, session: set_session_user
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
test 'new db rows are not added to HostgroupClass when POST to parameters' do
|
73
|
-
skip 'dont know how to achieve for now' unless ForemanPuppet.extracted_from_core?
|
74
73
|
hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
|
75
74
|
hostgroup_puppetclass_ids = hostgroup.puppet.hostgroup_classes.pluck(:puppetclass_id)
|
76
75
|
params = { id: puppetclass.id,
|
77
76
|
host_id: hostgroup.id,
|
78
|
-
hostgroup: { puppetclass_ids: (hostgroup_puppetclass_ids + [puppetclass.id]) } }
|
79
|
-
assert_difference(
|
77
|
+
hostgroup: { puppet: { puppetclass_ids: (hostgroup_puppetclass_ids + [puppetclass.id]) } } }
|
78
|
+
assert_difference(-> { ForemanPuppet::HostgroupClass.count }, 0) do
|
80
79
|
post :parameters, params: params, session: set_session_user
|
81
80
|
end
|
82
81
|
end
|
@@ -2,21 +2,21 @@ FactoryBot.modify do
|
|
2
2
|
factory :host do
|
3
3
|
trait :with_puppetclass do
|
4
4
|
transient do
|
5
|
-
environment
|
5
|
+
environment { FactoryBot.create(:environment) }
|
6
6
|
puppetclasses { [FactoryBot.create(:puppetclass, environments: [environment])] }
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
trait :with_config_group do
|
11
11
|
transient do
|
12
|
-
environment
|
12
|
+
environment { FactoryBot.create(:environment) }
|
13
13
|
config_groups { [FactoryBot.create(:config_group, :with_puppetclass, class_environments: [environment])] }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
trait :with_puppet_enc do
|
18
18
|
transient do
|
19
|
-
environment
|
19
|
+
environment { FactoryBot.create(:environment) }
|
20
20
|
puppetclasses { [] }
|
21
21
|
config_groups { [] }
|
22
22
|
end
|
@@ -30,14 +30,14 @@ FactoryBot.modify do
|
|
30
30
|
factory :hostgroup do
|
31
31
|
trait :with_puppetclass do
|
32
32
|
transient do
|
33
|
-
environment
|
33
|
+
environment { FactoryBot.create(:environment) }
|
34
34
|
puppetclasses { [FactoryBot.create(:puppetclass, environments: [environment])] }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
trait :with_puppet_enc do
|
39
39
|
transient do
|
40
|
-
environment
|
40
|
+
environment { FactoryBot.create(:environment) }
|
41
41
|
puppetclasses { [] }
|
42
42
|
config_groups { [] }
|
43
43
|
end
|
@@ -49,7 +49,7 @@ FactoryBot.modify do
|
|
49
49
|
|
50
50
|
trait :with_config_group do
|
51
51
|
transient do
|
52
|
-
environment
|
52
|
+
environment { FactoryBot.create(:environment) }
|
53
53
|
config_groups { [FactoryBot.create(:config_group, :with_puppetclass, class_environments: [environment])] }
|
54
54
|
end
|
55
55
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
|
3
|
+
module ForemanPuppet
|
4
|
+
module Mutations
|
5
|
+
module Hosts
|
6
|
+
class CreateMutationTest < GraphQLQueryTestCase
|
7
|
+
let(:hostname) { 'my-graphql-host' }
|
8
|
+
let(:tax_location) { FactoryBot.create(:location) }
|
9
|
+
let(:organization) { FactoryBot.create(:organization) }
|
10
|
+
let(:environment) { FactoryBot.create(:environment, locations: [tax_location], organizations: [organization]) }
|
11
|
+
let(:environment_id) { Foreman::GlobalId.for(environment) }
|
12
|
+
let(:puppetclass) { FactoryBot.create(:puppetclass) }
|
13
|
+
let(:puppetclass_id) { Foreman::GlobalId.for(puppetclass) }
|
14
|
+
|
15
|
+
let(:variables) do
|
16
|
+
{
|
17
|
+
name: hostname,
|
18
|
+
environmentId: environment_id,
|
19
|
+
puppetclassIds: [puppetclass_id],
|
20
|
+
}
|
21
|
+
end
|
22
|
+
let(:context_user) { FactoryBot.create(:user, :admin, locations: [tax_location], organizations: [organization]) }
|
23
|
+
let(:data) { result['data']['createHost']['host'] }
|
24
|
+
|
25
|
+
let(:query) do
|
26
|
+
<<-GRAPHQL
|
27
|
+
mutation createHostMutation(
|
28
|
+
$name: String!,
|
29
|
+
$environmentId: ID,
|
30
|
+
$puppetclassIds: [ID!],
|
31
|
+
) {
|
32
|
+
createHost(input: {
|
33
|
+
name: $name,
|
34
|
+
environmentId: $environmentId,
|
35
|
+
puppetclassIds: $puppetclassIds,
|
36
|
+
}) {
|
37
|
+
host {
|
38
|
+
id
|
39
|
+
},
|
40
|
+
errors {
|
41
|
+
path
|
42
|
+
message
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
GRAPHQL
|
47
|
+
end
|
48
|
+
|
49
|
+
setup :disable_orchestration
|
50
|
+
|
51
|
+
it 'creates a host with puppet parameters' do
|
52
|
+
assert_difference(-> { Host.count }, +1) do
|
53
|
+
assert_empty result['errors']
|
54
|
+
assert_empty result['data']['createHost']['errors']
|
55
|
+
|
56
|
+
host = Host.find(Foreman::GlobalId.decode(data['id'])[2])
|
57
|
+
assert_equal environment.id, host.puppet.environment_id
|
58
|
+
assert_equal [puppetclass.id], host.puppet.puppetclasses.pluck(:id)
|
59
|
+
|
60
|
+
assert_not_nil data
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_puppet_helper'
|
2
|
+
|
3
|
+
module Queries
|
4
|
+
class EnvironmentQueryTest < GraphQLQueryTestCase
|
5
|
+
let(:query) do
|
6
|
+
<<-GRAPHQL
|
7
|
+
query (
|
8
|
+
$id: String!
|
9
|
+
) {
|
10
|
+
environment(id: $id) {
|
11
|
+
id
|
12
|
+
createdAt
|
13
|
+
updatedAt
|
14
|
+
name
|
15
|
+
locations {
|
16
|
+
totalCount
|
17
|
+
edges {
|
18
|
+
node {
|
19
|
+
id
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
organizations {
|
24
|
+
totalCount
|
25
|
+
edges {
|
26
|
+
node {
|
27
|
+
id
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
GRAPHQL
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:environment) { FactoryBot.create(:environment) }
|
37
|
+
|
38
|
+
let(:global_id) { Foreman::GlobalId.for(environment) }
|
39
|
+
let(:variables) { { id: global_id } }
|
40
|
+
let(:data) { result['data']['environment'] }
|
41
|
+
|
42
|
+
test 'fetching environment attributes' do
|
43
|
+
assert_empty result['errors']
|
44
|
+
|
45
|
+
assert_equal global_id, data['id']
|
46
|
+
assert_equal environment.created_at.utc.iso8601, data['createdAt']
|
47
|
+
assert_equal environment.updated_at.utc.iso8601, data['updatedAt']
|
48
|
+
assert_equal environment.name, data['name']
|
49
|
+
|
50
|
+
assert_collection environment.locations, data['locations']
|
51
|
+
assert_collection environment.organizations, data['organizations']
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Queries
|
4
|
+
class EnvironmentsQueryTest < GraphQLQueryTestCase
|
5
|
+
let(:query) do
|
6
|
+
<<-GRAPHQL
|
7
|
+
query {
|
8
|
+
environments {
|
9
|
+
totalCount
|
10
|
+
pageInfo {
|
11
|
+
startCursor
|
12
|
+
endCursor
|
13
|
+
hasNextPage
|
14
|
+
hasPreviousPage
|
15
|
+
}
|
16
|
+
edges {
|
17
|
+
cursor
|
18
|
+
node {
|
19
|
+
id
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
GRAPHQL
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:data) { result['data']['environments'] }
|
28
|
+
|
29
|
+
setup do
|
30
|
+
FactoryBot.create_list(:environment, 2)
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'fetching environments attributes' do
|
34
|
+
assert_empty result['errors']
|
35
|
+
|
36
|
+
expected_count = ForemanPuppet::Environment.count
|
37
|
+
|
38
|
+
assert_not_equal 0, expected_count
|
39
|
+
assert_equal expected_count, data['totalCount']
|
40
|
+
assert_equal expected_count, data['edges'].count
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|