-
Notifications
You must be signed in to change notification settings - Fork 93
/
foreman_remote_execution_factories.rb
142 lines (120 loc) · 3.68 KB
/
foreman_remote_execution_factories.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
FactoryBot.define do
factory :job_template do
sequence(:name) { |n| "Job template #{n}" }
sequence(:job_category) { |n| "Job name #{n}" }
template 'id'
provider_type 'SSH'
organizations { [Organization.find_by(name: 'Organization 1')] } if SETTINGS[:organizations_enabled]
locations { [Location.find_by(name: 'Location 1')] } if SETTINGS[:locations_enabled]
trait :with_input do
after(:build) do |template, evaluator|
template.template_inputs << FactoryBot.build(:template_input)
end
end
trait :with_description_format do
description_format 'Factory-built %{job_category}'
end
trait :with_feature do
remote_execution_feature
end
end
factory :template_input do |f|
f.sequence(:name) { |n| "Template input #{n}" }
f.input_type 'user'
end
factory :foreign_input_set
factory :targeting do |f|
search_query 'name = foo'
targeting_type 'static_query'
user
end
factory :job_invocation do |f|
targeting
f.sequence(:job_category) { |n| "Job name #{n}" }
f.description_format '%{job_category}'
trait :with_template do
after(:build) do |invocation, evaluator|
invocation.pattern_template_invocations << FactoryBot.build(:template_invocation)
end
end
trait :with_failed_task do
after(:build) do |invocation, _evaluator|
invocation.template_invocations << FactoryBot.build(:template_invocation, :with_failed_task, :with_host)
invocation.task = FactoryBot.build(:some_task)
end
end
trait :with_task do
after(:build) do |invocation, _evaluator|
invocation.template_invocations << FactoryBot.build(:template_invocation, :with_task, :with_host)
invocation.task = FactoryBot.build(:some_task)
end
end
end
factory :remote_execution_provider do |f|
f.sequence(:name) { |n| "Provider #{n}" }
end
factory :template_invocation do |f|
job_invocation
association :template, :factory => :job_template
trait :with_task do
after(:build) do |template, _evaluator|
template.run_host_job_task = FactoryBot.build(:some_task)
end
end
trait :with_failed_task do
after(:build) do |template, _evaluator|
template.run_host_job_task = FactoryBot.build(:some_task, :result => 'error')
end
end
trait :with_host do
after(:build) do |template, _evaluator|
template.host = FactoryBot.build(:host)
end
end
end
factory :template_invocation_input_value do |f|
f.sequence(:value) { |n| "Input Value #{n}" }
end
factory :remote_execution_feature do |f|
f.sequence(:label) { |n| "remote_execution_feature_#{n}" }
f.sequence(:name) { |n| "Remote Execution Feature #{n}" }
end
end
FactoryBot.modify do
factory :feature do
trait :ssh do
name 'SSH'
end
end
factory :smart_proxy do
trait :ssh do
features { [FactoryBot.create(:feature, :ssh)] }
pubkey 'ssh-rsa AAAAB3N...'
end
end
factory :subnet do
trait :execution do
remote_execution_proxies { [FactoryBot.build(:smart_proxy, :ssh)] }
end
end
factory :host do
trait :with_execution do
managed
domain
subnet do
overrides = {
:remote_execution_proxies => [FactoryBot.create(:smart_proxy, :ssh)]
}
overrides[:locations] = [location] unless location.nil?
overrides[:organizations] = [organization] unless organization.nil?
FactoryBot.create(
:subnet_ipv4,
overrides
)
end
interfaces do
[FactoryBot.build(:nic_primary_and_provision, :ip => subnet.network.sub(/0\Z/, '1'), :execution => true)]
end
end
end
end