blob: 03911bd1c2a2946d290e65bcb2c045235dca2e1d [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
Matteo Scandolo67654fa2017-06-09 09:33:17 -070016import unittest
17import os
Scott Baker1f7791d2018-10-04 13:21:20 -070018from xosgenx.generator import XOSProcessor, XOSProcessorArgs
19from helpers import XProtoTestHelpers
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020020
Zack Williams045b63d2019-01-22 16:30:57 -070021
Matteo Scandolo67654fa2017-06-09 09:33:17 -070022class XProtoPackageTest(unittest.TestCase):
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020023 def test_package_fqn(self):
Scott Baker1f7791d2018-10-04 13:21:20 -070024 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -070025 target = XProtoTestHelpers.write_tmp_target(
Zack Williams045b63d2019-01-22 16:30:57 -070026 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020027 {% for m in proto.messages %}
28 {{ m.name }},{{ m.package }},{{ m.fqn }}
29 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020030"""
Zack Williams045b63d2019-01-22 16:30:57 -070031 )
32
33 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020034package xos.core;
35
36message Port (PlCoreBase,ParameterMixin) {
37 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
38 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
39 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
40 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
41 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
42 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
43}
44"""
Scott Baker1f7791d2018-10-04 13:21:20 -070045 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -070046 args.inputs = xproto
47 args.target = target
48
Sapan Bhatiabfb233a2018-02-09 14:53:09 -080049 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -070050
Zack Williams045b63d2019-01-22 16:30:57 -070051 self.assertIn("Port,xos.core,xos.core.Port", output)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020052
53 def test_cross_model(self):
Zack Williams045b63d2019-01-22 16:30:57 -070054 target = XProtoTestHelpers.write_tmp_target(
55 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020056 {% for m in proto.messages %}
57 {{ m.fqn }} {
58 {%- for l in m.links %}
59 {%- if proto.message_table[l.peer.fqn] %}
60 {{ l.peer.name }} {
61 {%- set model = proto.message_table[l.peer.fqn] %}
62 {% for f in model.fields %}
63 {{ f.type }} {{ f.name }};
64 {% endfor %}
65 }
66 {%- endif -%}
67 {%- if proto.message_table[m.package + '.' + l.peer.name] %}
68 {{ l.peer.name }} {
69 {%- set model = proto.message_table[m.package + '.' + l.peer.name] %}
70 {% for f in model.fields %}
71 {{ f.type }} {{ f.name }};
72 {% endfor %}
73 }
74 {%- endif -%}
75 {% endfor %}
76 }
77 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020078"""
Zack Williams045b63d2019-01-22 16:30:57 -070079 )
80
81 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020082package xos.network;
83
84message Port (PlCoreBase,ParameterMixin){
85 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
86 optional manytoone instance->xos.core.Instance:ports = 2 [db_index = True, null = True, blank = True];
87 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
88 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
89 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
90 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
91}
92
93
94package xos.core;
95
96message Instance (PlCoreBase){
97 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
98 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
99 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
100 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
101 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
102 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
103 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
104 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
105 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
106 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
107 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
108 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
109 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
110 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];
111 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
112 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
113 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
114}
115
116package xos.network;
117
118message Network (PlCoreBase,ParameterMixin) {
119 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
120 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
121 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
122 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
123 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
124 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
125 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
126 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
127 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
128 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
129 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
130 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
131 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
132 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
133 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
134 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
135 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];
136 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
137 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
138 required manytomany instances->xos.core.Instance/xos.network.Port:networks = 20 [db_index = False, null = False, blank = True];
139}
140
141message Slice (PlCoreBase){
142 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
143 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
144 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
145 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];
146 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
147 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
148 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
149 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
150 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'))"];
151 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
152 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
153 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
154 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
155 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
156 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
157 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
158 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];
159 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
160}
161"""
Scott Baker1f7791d2018-10-04 13:21:20 -0700162 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700163 args.inputs = xproto
164 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -0800165 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700166
Zack Williams045b63d2019-01-22 16:30:57 -0700167 self.assertIn(
168 "numberCores", output
169 ) # Instance showed up via cross-package call
170 self.assertIn("ip;", output) # Network showed up via cross-package call
171 self.assertIn(
172 "max_instances", output
173 ) # Slice showed up via implicit in-package call
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200174
175 def test_base_class_fields(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700176 target = XProtoTestHelpers.write_tmp_target(
Zack Williams045b63d2019-01-22 16:30:57 -0700177 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200178 {% for m in proto.messages %}
179 {{ m.name }} {
180 {%- for b in m.bases %}
181 {%- if proto.message_table[b.fqn] -%}
182 {%- set model = proto.message_table[b.fqn] %}
183 {% for f in model.fields %}
184 {{ f.type }} {{ f.name }};
185 {% endfor %}
186 {%- endif -%}
187 {% endfor %}
188 }
189 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200190"""
Zack Williams045b63d2019-01-22 16:30:57 -0700191 )
192
193 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200194package xos.network;
195
196message Port (PlCoreBase,ParameterMixin){
197 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
198 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
199 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
200 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
201 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
202 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
203}
204
205package xos.someotherpackage;
206
207message Instance (xos.network.Port){
208 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
209 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
210 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
211 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
212 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
213 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
214 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
215 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
216 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
217 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
218 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
219 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
220 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
221 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];
222 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
223 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
224 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
225}
226"""
Scott Baker1f7791d2018-10-04 13:21:20 -0700227 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700228 args.inputs = xproto
229 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -0800230 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700231
Zack Williams045b63d2019-01-22 16:30:57 -0700232 self.assertIn("xos_created", output)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200233
234 def test_from_base(self):
Zack Williams045b63d2019-01-22 16:30:57 -0700235 target = XProtoTestHelpers.write_tmp_target(
236 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200237 {% for f in xproto_base_fields(proto.messages.3, proto.message_table) %}
238 {{ f.type }} {{ f.name }};
239 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200240"""
Zack Williams045b63d2019-01-22 16:30:57 -0700241 )
242
243 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200244option app_name = "firstapp";
245
246message Port (PlCoreBase,ParameterMixin){
247 required string easter_egg = 1;
248 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
249 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
250 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
251 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
252 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
253 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
254}
255
256package A;
257
258message Instance (Port){
259 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
260 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
261 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
262 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
263 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
264 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
265 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
266 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
267 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
268 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
269 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
270 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
271 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
272 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];
273 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
274 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
275 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
276}
277
278package B;
279
280option app_name="networkapp";
281
282message Network (A.Instance) {
283 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
284 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
285 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
286 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
287 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
288 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
289 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
290 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
291 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
292 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
293 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
294 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
295 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
296 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
297 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
298 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
299 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];
300 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
301 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
302 required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True];
303}
304
305option app_name="sliceapp";
306
307message Slice (Network){
308 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
309 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
310 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
311 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];
312 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
313 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
314 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
315 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
316 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'))"];
317 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
318 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
319 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
320 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
321 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
322 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
323 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
324 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];
325 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
326}
327"""
Scott Baker1f7791d2018-10-04 13:21:20 -0700328 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700329 args.inputs = xproto
330 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -0800331 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700332
Zack Williams045b63d2019-01-22 16:30:57 -0700333 self.assertIn("easter_egg", output)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200334
335 def test_model_options(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700336 target = XProtoTestHelpers.write_tmp_target(
Zack Williams045b63d2019-01-22 16:30:57 -0700337 """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200338 Options:
339
340 {{ proto.options }}
341 {% for m in proto.messages %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200342 {{ m.options.app_name }}
343 {% endfor %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200344"""
Zack Williams045b63d2019-01-22 16:30:57 -0700345 )
346
347 xproto = """
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200348option app_name = "firstapp";
349
350message Port (PlCoreBase,ParameterMixin){
351 required string easter_egg = 1;
352 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
353 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
354 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
355 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
356 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
357 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
358}
359
360package A;
361
362message Instance (Port){
363 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
364 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
365 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
366 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
367 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
368 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
369 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
370 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
371 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
372 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
373 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
374 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
375 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
376 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];
377 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
378 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
379 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
380}
381
382package B;
383
384option app_name = "networkapp";
385
386message Network (A.Instance) {
387 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
388 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
389 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
390 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
391 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
392 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
393 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
394 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
395 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
396 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
397 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
398 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
399 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
400 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
401 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
402 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
403 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];
404 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
405 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
406 required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True];
407}
408
409
410option app_name = "networkapp";
411
412message Slice (Network){
413 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
414 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
415 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
416 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];
417 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
418 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
419 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
420 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
421 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'))"];
422 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
423 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
424 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
425 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
426 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
427 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
428 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
429 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];
430 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
431}
432"""
Zack Williams045b63d2019-01-22 16:30:57 -0700433
Scott Baker1f7791d2018-10-04 13:21:20 -0700434 args = XOSProcessorArgs()
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700435 args.inputs = xproto
436 args.target = target
Sapan Bhatiabfb233a2018-02-09 14:53:09 -0800437 output = XOSProcessor.process(args)
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700438
Zack Williams045b63d2019-01-22 16:30:57 -0700439 self.assertEqual(output.count("firstapp"), 2)
440 self.assertEqual(output.count("networkapp"), 2)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200441
442
Zack Williams045b63d2019-01-22 16:30:57 -0700443if __name__ == "__main__":
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200444 unittest.main()