blob: 127fc07a153010ba64f197746c7f9d5c5c04f4e3 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Matteo Scandolo67654fa2017-06-09 09:33:17 -070017import unittest
18import os
19from xosgenx.generator import XOSGenerator
20from helpers import FakeArgs, XProtoTestHelpers
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020021
Matteo Scandolo67654fa2017-06-09 09:33:17 -070022class XProtoPackageTest(unittest.TestCase):
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020023 def test_package_fqn(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -070024 args = FakeArgs()
25 target = XProtoTestHelpers.write_tmp_target(
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020026"""
27 {% for m in proto.messages %}
28 {{ m.name }},{{ m.package }},{{ m.fqn }}
29 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -070030""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020031
Matteo Scandolo67654fa2017-06-09 09:33:17 -070032 xproto =\
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020033"""
34package 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"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -070045 args = FakeArgs()
46 args.inputs = xproto
47 args.target = target
48
49 output = XOSGenerator.generate(args)
50
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020051 self.assertIn('Port,xos.core,xos.core.Port', output)
52
53 def test_cross_model(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -070054 target = XProtoTestHelpers.write_tmp_target( \
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020055"""
56 {% 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 %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -070078""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020079
Matteo Scandolo67654fa2017-06-09 09:33:17 -070080 xproto = \
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020081"""
82package 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"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700162 args = FakeArgs()
163 args.inputs = xproto
164 args.target = target
165 output = XOSGenerator.generate(args)
166
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200167 self.assertIn('numberCores', output) # Instance showed up via cross-package call
168 self.assertIn('ip;', output) # Network showed up via cross-package call
169 self.assertIn('max_instances', output) # Slice showed up via implicit in-package call
170
171 def test_base_class_fields(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700172 target = XProtoTestHelpers.write_tmp_target(
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200173"""
174 {% for m in proto.messages %}
175 {{ m.name }} {
176 {%- for b in m.bases %}
177 {%- if proto.message_table[b.fqn] -%}
178 {%- set model = proto.message_table[b.fqn] %}
179 {% for f in model.fields %}
180 {{ f.type }} {{ f.name }};
181 {% endfor %}
182 {%- endif -%}
183 {% endfor %}
184 }
185 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700186""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200187
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700188 xproto =\
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200189"""
190package xos.network;
191
192message Port (PlCoreBase,ParameterMixin){
193 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
194 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
195 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
196 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
197 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
198 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
199}
200
201package xos.someotherpackage;
202
203message Instance (xos.network.Port){
204 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
205 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
206 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
207 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
208 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
209 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
210 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
211 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
212 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
213 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
214 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
215 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
216 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
217 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];
218 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
219 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
220 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
221}
222"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700223 args = FakeArgs()
224 args.inputs = xproto
225 args.target = target
226 output = XOSGenerator.generate(args)
227
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200228 self.assertIn('xos_created', output)
229
230 def test_from_base(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700231 target = XProtoTestHelpers.write_tmp_target( \
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200232"""
233 {% for f in xproto_base_fields(proto.messages.3, proto.message_table) %}
234 {{ f.type }} {{ f.name }};
235 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700236""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200237
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700238 xproto =\
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200239"""
240option app_name = "firstapp";
241
242message Port (PlCoreBase,ParameterMixin){
243 required string easter_egg = 1;
244 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
245 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
246 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
247 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
248 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
249 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
250}
251
252package A;
253
254message Instance (Port){
255 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
256 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
257 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
258 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
259 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
260 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
261 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
262 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
263 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
264 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
265 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
266 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
267 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
268 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];
269 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
270 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
271 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
272}
273
274package B;
275
276option app_name="networkapp";
277
278message Network (A.Instance) {
279 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
280 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
281 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
282 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
283 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
284 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
285 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
286 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
287 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
288 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
289 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
290 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
291 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
292 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
293 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
294 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
295 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];
296 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
297 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
298 required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True];
299}
300
301option app_name="sliceapp";
302
303message Slice (Network){
304 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
305 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
306 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
307 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];
308 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
309 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
310 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
311 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
312 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'))"];
313 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
314 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
315 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
316 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
317 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
318 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
319 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
320 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];
321 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
322}
323"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700324 args = FakeArgs()
325 args.inputs = xproto
326 args.target = target
327 output = XOSGenerator.generate(args)
328
329 self.assertIn('easter_egg', output)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200330
331 def test_model_options(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700332 target = XProtoTestHelpers.write_tmp_target(
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200333"""
334 Options:
335
336 {{ proto.options }}
337 {% for m in proto.messages %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200338 {{ m.options.app_name }}
339 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700340""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200341
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700342 xproto =\
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200343"""
344option app_name = "firstapp";
345
346message Port (PlCoreBase,ParameterMixin){
347 required string easter_egg = 1;
348 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
349 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
350 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
351 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
352 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
353 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
354}
355
356package A;
357
358message Instance (Port){
359 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
360 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
361 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
362 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
363 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
364 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
365 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
366 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
367 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
368 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
369 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
370 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
371 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
372 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];
373 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
374 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
375 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
376}
377
378package B;
379
380option app_name = "networkapp";
381
382message Network (A.Instance) {
383 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
384 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
385 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
386 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
387 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
388 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
389 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
390 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
391 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
392 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
393 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
394 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
395 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
396 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
397 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
398 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
399 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];
400 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
401 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
402 required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True];
403}
404
405
406option app_name = "networkapp";
407
408message Slice (Network){
409 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
410 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
411 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
412 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];
413 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
414 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
415 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
416 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
417 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'))"];
418 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
419 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
420 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
421 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
422 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
423 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
424 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
425 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];
426 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
427}
428"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700429
430 args = FakeArgs()
431 args.inputs = xproto
432 args.target = target
433 output = XOSGenerator.generate(args)
434
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200435 self.assertEqual(output.count('firstapp'), 2)
436 self.assertEqual(output.count('networkapp'), 2)
437
438
439if __name__ == '__main__':
440 unittest.main()
441
442