forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorchestration_template_dialog_service_spec.rb
238 lines (197 loc) · 9.86 KB
/
orchestration_template_dialog_service_spec.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
describe OrchestrationTemplateDialogService do
let(:dialog_service) { described_class.new }
let(:template_hot) { FactoryGirl.create(:orchestration_template_hot_with_content) }
let(:template_azure) { FactoryGirl.create(:orchestration_template_azure_with_content) }
let(:empty_template) { FactoryGirl.create(:orchestration_template_cfn) }
let(:template_vapp) { FactoryGirl.create(:orchestration_template_vmware_cloud_with_content) }
describe "#create_dialog" do
it "creates a dialog from hot template with stack basic info and parameters" do
dialog = dialog_service.create_dialog("test", template_hot)
expect(dialog).to have_attributes(
:label => "test",
:buttons => "submit,cancel"
)
tabs = dialog.dialog_tabs
expect(tabs.size).to eq(1)
assert_stack_tab(tabs[0])
end
it "creates a dialog from azure template with stack basic info and parameters" do
dialog = dialog_service.create_dialog("test", template_azure)
tabs = dialog.dialog_tabs
assert_tab_attributes(tabs[0])
assert_azure_stack_group(tabs[0].dialog_groups[0])
end
it "creates a dialog from a template without parameters" do
dialog = dialog_service.create_dialog("test", empty_template)
tabs = dialog.dialog_tabs
assert_tab_attributes(tabs[0])
assert_aws_openstack_stack_group(tabs[0].dialog_groups[0])
end
it "creates a dialog from VMware vCloud vApp template with stack basic info and parameters" do
dialog = dialog_service.create_dialog("test", template_vapp)
tabs = dialog.dialog_tabs
assert_tab_attributes(tabs[0])
expect(tabs[0].dialog_groups.size).to eq(2)
assert_vmware_cloud_stack_group(tabs[0].dialog_groups[0])
assert_vmware_cloud_parameters_group(tabs[0].dialog_groups[1])
end
end
describe "creation of dropdown parameter fields" do
context "when allowed values are given" do
it "creates a dropdown field with pairs of values" do
# Create a simple dialog with one dropdown parameter.
constraint = OrchestrationTemplate::OrchestrationParameterAllowed.new(:allowed_values => %w(val1 val2))
param_groups = create_dropdown_param(constraint)
allow(empty_template).to receive(:parameter_groups).and_return(param_groups)
dialog = dialog_service.create_dialog("test", empty_template)
# Get the dropdown field
field = dropdown_field(dialog)
# Ensure the allowed values are properly stored.
assert_field(field, DialogFieldDropDownList, :name => "param_dropdown", :default_value => "val1", :values => [%w(val1 val1), %w(val2 val2)])
end
end
context "when a hash of allowed values is given" do
it "creates pairs from hashes" do
# Create a simple dialog with one dropdown parameter.
constraint = OrchestrationTemplate::OrchestrationParameterAllowed.new(:allowed_values => {"key1" => "val1", "key2" => "val2"})
param_groups = create_dropdown_param(constraint)
allow(empty_template).to receive(:parameter_groups).and_return(param_groups)
dialog = dialog_service.create_dialog("test", empty_template)
# Get the dropdown field
field = dropdown_field(dialog)
# Ensure the allowed values are properly stored.
assert_field(field, DialogFieldDropDownList, :name => "param_dropdown", :default_value => "val1", :values => [%w(key1 val1), %w(key2 val2)])
end
end
context "when automate method is given" do
it "creates a dropdown field requested resource_action" do
# Create a simple dialog with one dropdown parameter.
constraint = OrchestrationTemplate::OrchestrationParameterAllowedDynamic.new(:fqname => "/Path/To/Method")
param_groups = create_dropdown_param(constraint)
allow(empty_template).to receive(:parameter_groups).and_return(param_groups)
dialog = dialog_service.create_dialog("test", empty_template)
# Get the dropdown field
field = dropdown_field(dialog)
# Ensure the field is properly defined with the resource action.
expect(field.resource_action.fqname).to eq("/Path/To/Method")
assert_field(field, DialogFieldDropDownList, :name => "param_dropdown")
end
end
end
def assert_stack_tab(tab)
assert_tab_attributes(tab)
groups = tab.dialog_groups
expect(groups.size).to eq(3)
assert_aws_openstack_stack_group(groups[0])
assert_parameter_group1(groups[1])
assert_parameter_group2(groups[2])
end
def assert_tab_attributes(tab)
expect(tab).to have_attributes(
:label => "Basic Information",
:display => "edit"
)
end
def assert_aws_openstack_stack_group(group)
expect(group).to have_attributes(
:label => "Options",
:display => "edit",
)
fields = group.dialog_fields
expect(fields.size).to eq(4)
expect(fields[0].resource_action.fqname).to eq("/Cloud/Orchestration/Operations/Methods/Available_Tenants")
assert_field(fields[0], DialogFieldDropDownList, :name => "tenant_name", :dynamic => true)
assert_field(fields[1], DialogFieldTextBox, :name => "stack_name", :validator_rule => '^[A-Za-z][A-Za-z0-9\-]*$')
assert_field(fields[2], DialogFieldDropDownList, :name => "stack_onfailure", :values => [%w(DO_NOTHING Do\ nothing), %w(ROLLBACK Rollback)])
assert_field(fields[3], DialogFieldTextBox, :name => "stack_timeout", :data_type => 'integer')
end
def assert_azure_stack_group(group)
expect(group).to have_attributes(
:label => "Options",
:display => "edit",
)
fields = group.dialog_fields
expect(fields.size).to eq(5)
expect(fields[0].resource_action.fqname).to eq("/Cloud/Orchestration/Operations/Methods/Available_Tenants")
assert_field(fields[0], DialogFieldDropDownList, :name => "tenant_name", :dynamic => true)
assert_field(fields[1], DialogFieldTextBox, :name => "stack_name", :validator_rule => '^[A-Za-z][A-Za-z0-9\-]*$')
assert_field(fields[2], DialogFieldDropDownList, :name => "resource_group", :dynamic => true)
assert_field(fields[3], DialogFieldTextBox, :name => "new_resource_group", :validator_rule => '^[A-Za-z][A-Za-z0-9\-_]*$')
mode_values = [["Complete", "Complete (Delete other resources in the group)"],
["Incremental", "Incremental (Default)"]]
assert_field(fields[4], DialogFieldDropDownList, :name => "deploy_mode", :values => mode_values)
expect(fields[4].default_value).to eq("Incremental")
end
def assert_vmware_cloud_stack_group(group)
expect(group).to have_attributes(
:label => "Options",
:display => "edit",
)
fields = group.dialog_fields
expect(fields.size).to eq(3)
expect(fields[0].resource_action.fqname).to eq("/Cloud/Orchestration/Operations/Methods/Available_Tenants")
assert_field(fields[0], DialogFieldDropDownList, :name => "tenant_name", :dynamic => true)
assert_field(fields[1], DialogFieldTextBox, :name => "stack_name", :validator_rule => '^[A-Za-z][A-Za-z0-9\-]*$')
expect(fields[2].resource_action.fqname).to eq("/Cloud/Orchestration/Operations/Methods/Available_Availability_Zones")
assert_field(fields[2], DialogFieldDropDownList, :name => "availability_zone", :dynamic => true)
end
def assert_vmware_cloud_parameters_group(group)
expect(group).to have_attributes(
:label => "vApp Parameters",
:display => "edit",
)
fields = group.dialog_fields
expect(fields.size).to eq(2)
assert_field(fields[0], DialogFieldCheckBox, :name => "param_deploy", :default_value => "t", :data_type => "boolean")
assert_field(fields[1], DialogFieldCheckBox, :name => "param_powerOn", :default_value => "f", :data_type => "boolean")
end
def assert_field(field, clss, attributes)
expect(field).to be_kind_of clss
expect(field).to have_attributes(attributes)
end
def assert_parameter_group1(group)
expect(group).to have_attributes(
:label => "General parameters",
:display => "edit",
)
fields = group.dialog_fields
expect(fields.size).to eq(3)
assert_field(fields[0], DialogFieldTextBox, :name => "param_flavor", :default_value => "m1.small")
assert_field(fields[1], DialogFieldDropDownList, :name => "param_image_id", :default_value => "F18-x86_64-cfntools", :values => [%w(F18-i386-cfntools F18-i386-cfntools), %w(F18-x86_64-cfntools F18-x86_64-cfntools)])
assert_field(fields[2], DialogFieldTextBox, :name => "param_cartridges", :default_value => "cron,diy,haproxy,mysql,nodejs,perl,php,postgresql,python,ruby")
end
def assert_parameter_group2(group)
expect(group).to have_attributes(
:label => "Parameter Group2",
:display => "edit",
)
fields = group.dialog_fields
expect(fields.size).to eq(3)
assert_field(fields[0], DialogFieldTextBox, :name => "param_admin_pass", :validator_rule => '[a-zA-Z0-9]+')
assert_field(fields[1], DialogFieldTextBox, :name => "param_db_port", :label => 'Port Number')
assert_field(fields[2], DialogFieldTextAreaBox, :name => "param_metadata")
end
def dropdown_field(dialog)
# First ensure that the dialog is properly constructed.
tabs = dialog.dialog_tabs
expect(tabs.size).to eq(1)
expect(tabs[0].dialog_groups.size).to eq(2)
expect(tabs[0].dialog_groups[1].dialog_fields.size).to eq(1)
fields = tabs[0].dialog_groups[1].dialog_fields
# Return the first field; it should be the only field.
fields[0]
end
def create_dropdown_param(constraint)
[OrchestrationTemplate::OrchestrationParameterGroup.new(
:label => "group",
:parameters => [
OrchestrationTemplate::OrchestrationParameter.new(
:name => "dropdown",
:label => "Drop down",
:data_type => "string",
:default_value => "val1",
:constraints => [constraint])
])
]
end
end