blob: d3644315909a5065281adb1a51b18af2e59de705 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
Zack Williams9a42f872019-02-15 17:56:04 -070016from __future__ import absolute_import
Matteo Scandolo67654fa2017-06-09 09:33:17 -070017import unittest
18import os
Scott Baker1f7791d2018-10-04 13:21:20 -070019from xosgenx.generator import XOSProcessor, XOSProcessorArgs
20from helpers import XProtoTestHelpers
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020021
Zack Williams045b63d2019-01-22 16:30:57 -070022
Matteo Scandolo67654fa2017-06-09 09:33:17 -070023class XProtoPackageTest(unittest.TestCase):
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020024 def test_package_fqn(self):
Scott Baker1f7791d2018-10-04 13:21:20 -070025 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -070026 target = XProtoTestHelpers.write_tmp_target(
Zack Williams045b63d2019-01-22 16:30:57 -070027 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020028 {% for m in proto.messages %}
29 {{ m.name }},{{ m.package }},{{ m.fqn }}
30 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020031"""
Zack Williams045b63d2019-01-22 16:30:57 -070032 )
33
34 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020035package xos.core;
36
37message Port (PlCoreBase,ParameterMixin) {
38 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
39 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
40 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
41 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
42 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
43 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
44}
45"""
Scott Baker1f7791d2018-10-04 13:21:20 -070046 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -070047 args.inputs = xproto
48 args.target = target
49
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080050 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070051
Zack Williams045b63d2019-01-22 16:30:57 -070052 self.assertIn("Port,xos.core,xos.core.Port", output)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020053
54 def test_cross_model(self):
Zack Williams045b63d2019-01-22 16:30:57 -070055 target = XProtoTestHelpers.write_tmp_target(
56 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020057 {% for m in proto.messages %}
58 {{ m.fqn }} {
59 {%- for l in m.links %}
60 {%- if proto.message_table[l.peer.fqn] %}
61 {{ l.peer.name }} {
62 {%- set model = proto.message_table[l.peer.fqn] %}
63 {% for f in model.fields %}
64 {{ f.type }} {{ f.name }};
65 {% endfor %}
66 }
67 {%- endif -%}
68 {%- if proto.message_table[m.package + '.' + l.peer.name] %}
69 {{ l.peer.name }} {
70 {%- set model = proto.message_table[m.package + '.' + l.peer.name] %}
71 {% for f in model.fields %}
72 {{ f.type }} {{ f.name }};
73 {% endfor %}
74 }
75 {%- endif -%}
76 {% endfor %}
77 }
78 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020079"""
Zack Williams045b63d2019-01-22 16:30:57 -070080 )
81
82 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020083package xos.network;
84
85message Port (PlCoreBase,ParameterMixin){
86 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
87 optional manytoone instance->xos.core.Instance:ports = 2 [db_index = True, null = True, blank = True];
88 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
89 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
90 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
91 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
92}
93
94
95package xos.core;
96
97message Instance (PlCoreBase){
98 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
99 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
100 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
101 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
102 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
103 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
104 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
105 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
106 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
107 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
108 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
109 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
110 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
111 required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
112 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
113 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
114 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
115}
116
117package xos.network;
118
119message Network (PlCoreBase,ParameterMixin) {
120 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
121 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
122 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
123 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
124 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
125 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
126 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
127 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
128 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
129 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
130 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
131 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
132 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
133 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
134 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
135 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
136 required bool autoconnect = 17 [help_text = "This network can be autoconnected to the slice that owns it", default = True, null = False, db_index = False, blank = True];
137 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
138 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
139 required manytomany instances->xos.core.Instance/xos.network.Port:networks = 20 [db_index = False, null = False, blank = True];
140}
141
142message Slice (PlCoreBase){
143 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
144 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
145 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
146 required string description = 4 [help_text = "High level description of the slice and expected activities", max_length = 1024, null = False, db_index = False, blank = True];
147 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
148 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
149 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
150 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
151 optional string network = 9 [blank = True, max_length = 256, null = True, db_index = False, choices = "((None, 'Default'), ('host', 'Host'), ('bridged', 'Bridged'), ('noauto', 'No Automatic Networks'))"];
152 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
153 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
154 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
155 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
156 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
157 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
158 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
159 required string default_isolation = 17 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
160 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
161}
162"""
Scott Baker1f7791d2018-10-04 13:21:20 -0700163 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700164 args.inputs = xproto
165 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -0800166 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700167
Zack Williams045b63d2019-01-22 16:30:57 -0700168 self.assertIn(
169 "numberCores", output
170 ) # Instance showed up via cross-package call
171 self.assertIn("ip;", output) # Network showed up via cross-package call
172 self.assertIn(
173 "max_instances", output
174 ) # Slice showed up via implicit in-package call
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200175
176 def test_base_class_fields(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700177 target = XProtoTestHelpers.write_tmp_target(
Zack Williams045b63d2019-01-22 16:30:57 -0700178 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200179 {% for m in proto.messages %}
180 {{ m.name }} {
181 {%- for b in m.bases %}
182 {%- if proto.message_table[b.fqn] -%}
183 {%- set model = proto.message_table[b.fqn] %}
184 {% for f in model.fields %}
185 {{ f.type }} {{ f.name }};
186 {% endfor %}
187 {%- endif -%}
188 {% endfor %}
189 }
190 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200191"""
Zack Williams045b63d2019-01-22 16:30:57 -0700192 )
193
194 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200195package xos.network;
196
197message Port (PlCoreBase,ParameterMixin){
198 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
199 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
200 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
201 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
202 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
203 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
204}
205
206package xos.someotherpackage;
207
208message Instance (xos.network.Port){
209 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
210 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
211 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
212 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
213 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
214 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
215 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
216 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
217 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
218 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
219 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
220 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
221 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
222 required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
223 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
224 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
225 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
226}
227"""
Scott Baker1f7791d2018-10-04 13:21:20 -0700228 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700229 args.inputs = xproto
230 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -0800231 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700232
Zack Williams045b63d2019-01-22 16:30:57 -0700233 self.assertIn("xos_created", output)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200234
235 def test_from_base(self):
Zack Williams045b63d2019-01-22 16:30:57 -0700236 target = XProtoTestHelpers.write_tmp_target(
237 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200238 {% for f in xproto_base_fields(proto.messages.3, proto.message_table) %}
239 {{ f.type }} {{ f.name }};
240 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200241"""
Zack Williams045b63d2019-01-22 16:30:57 -0700242 )
243
244 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200245option app_name = "firstapp";
246
247message Port (PlCoreBase,ParameterMixin){
248 required string easter_egg = 1;
249 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
250 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
251 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
252 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
253 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
254 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
255}
256
257package A;
258
259message Instance (Port){
260 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
261 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
262 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
263 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
264 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
265 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
266 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
267 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
268 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
269 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
270 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
271 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
272 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
273 required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
274 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
275 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
276 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
277}
278
279package B;
280
281option app_name="networkapp";
282
283message Network (A.Instance) {
284 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
285 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
286 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
287 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
288 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
289 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
290 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
291 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
292 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
293 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
294 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
295 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
296 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
297 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
298 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
299 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
300 required bool autoconnect = 17 [help_text = "This network can be autoconnected to the slice that owns it", default = True, null = False, db_index = False, blank = True];
301 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
302 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
303 required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True];
304}
305
306option app_name="sliceapp";
307
308message Slice (Network){
309 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
310 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
311 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
312 required string description = 4 [help_text = "High level description of the slice and expected activities", max_length = 1024, null = False, db_index = False, blank = True];
313 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
314 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
315 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
316 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
317 optional string network = 9 [blank = True, max_length = 256, null = True, db_index = False, choices = "((None, 'Default'), ('host', 'Host'), ('bridged', 'Bridged'), ('noauto', 'No Automatic Networks'))"];
318 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
319 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
320 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
321 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
322 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
323 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
324 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
325 required string default_isolation = 17 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
326 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
327}
328"""
Scott Baker1f7791d2018-10-04 13:21:20 -0700329 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700330 args.inputs = xproto
331 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -0800332 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700333
Zack Williams045b63d2019-01-22 16:30:57 -0700334 self.assertIn("easter_egg", output)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200335
336 def test_model_options(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700337 target = XProtoTestHelpers.write_tmp_target(
Zack Williams045b63d2019-01-22 16:30:57 -0700338 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200339 Options:
340
341 {{ proto.options }}
342 {% for m in proto.messages %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200343 {{ m.options.app_name }}
344 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200345"""
Zack Williams045b63d2019-01-22 16:30:57 -0700346 )
347
348 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200349option app_name = "firstapp";
350
351message Port (PlCoreBase,ParameterMixin){
352 required string easter_egg = 1;
353 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
354 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
355 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
356 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
357 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
358 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
359}
360
361package A;
362
363message Instance (Port){
364 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
365 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
366 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
367 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
368 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
369 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
370 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
371 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
372 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
373 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
374 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
375 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
376 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
377 required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
378 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
379 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
380 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
381}
382
383package B;
384
385option app_name = "networkapp";
386
387message Network (A.Instance) {
388 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
389 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
390 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
391 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
392 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
393 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
394 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
395 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
396 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
397 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
398 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
399 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
400 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
401 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
402 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
403 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
404 required bool autoconnect = 17 [help_text = "This network can be autoconnected to the slice that owns it", default = True, null = False, db_index = False, blank = True];
405 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
406 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
407 required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True];
408}
409
410
411option app_name = "networkapp";
412
413message Slice (Network){
414 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
415 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
416 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
417 required string description = 4 [help_text = "High level description of the slice and expected activities", max_length = 1024, null = False, db_index = False, blank = True];
418 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
419 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
420 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
421 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
422 optional string network = 9 [blank = True, max_length = 256, null = True, db_index = False, choices = "((None, 'Default'), ('host', 'Host'), ('bridged', 'Bridged'), ('noauto', 'No Automatic Networks'))"];
423 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
424 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
425 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
426 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
427 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
428 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
429 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
430 required string default_isolation = 17 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
431 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
432}
433"""
Zack Williams045b63d2019-01-22 16:30:57 -0700434
Scott Baker1f7791d2018-10-04 13:21:20 -0700435 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700436 args.inputs = xproto
437 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -0800438 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700439
Zack Williams045b63d2019-01-22 16:30:57 -0700440 self.assertEqual(output.count("firstapp"), 2)
441 self.assertEqual(output.count("networkapp"), 2)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200442
443
Zack Williams045b63d2019-01-22 16:30:57 -0700444if __name__ == "__main__":
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200445 unittest.main()