blob: a20295bab31467fce729f9ab7840de12d31fb3cc [file] [log] [blame]
Matteo Scandolo67654fa2017-06-09 09:33:17 -07001import unittest
2import os
3from xosgenx.generator import XOSGenerator
4from helpers import FakeArgs, XProtoTestHelpers
Sapan Bhatia3cfdf632017-06-08 05:14:03 +02005
Matteo Scandolo67654fa2017-06-09 09:33:17 -07006class XProtoPackageTest(unittest.TestCase):
Sapan Bhatia3cfdf632017-06-08 05:14:03 +02007 def test_package_fqn(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -07008 args = FakeArgs()
9 target = XProtoTestHelpers.write_tmp_target(
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020010"""
11 {% for m in proto.messages %}
12 {{ m.name }},{{ m.package }},{{ m.fqn }}
13 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -070014""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020015
Matteo Scandolo67654fa2017-06-09 09:33:17 -070016 xproto =\
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020017"""
18package xos.core;
19
20message Port (PlCoreBase,ParameterMixin) {
21 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
22 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
23 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
24 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
25 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
26 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
27}
28"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -070029 args = FakeArgs()
30 args.inputs = xproto
31 args.target = target
32
33 output = XOSGenerator.generate(args)
34
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020035 self.assertIn('Port,xos.core,xos.core.Port', output)
36
37 def test_cross_model(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -070038 target = XProtoTestHelpers.write_tmp_target( \
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020039"""
40 {% for m in proto.messages %}
41 {{ m.fqn }} {
42 {%- for l in m.links %}
43 {%- if proto.message_table[l.peer.fqn] %}
44 {{ l.peer.name }} {
45 {%- set model = proto.message_table[l.peer.fqn] %}
46 {% for f in model.fields %}
47 {{ f.type }} {{ f.name }};
48 {% endfor %}
49 }
50 {%- endif -%}
51 {%- if proto.message_table[m.package + '.' + l.peer.name] %}
52 {{ l.peer.name }} {
53 {%- set model = proto.message_table[m.package + '.' + l.peer.name] %}
54 {% for f in model.fields %}
55 {{ f.type }} {{ f.name }};
56 {% endfor %}
57 }
58 {%- endif -%}
59 {% endfor %}
60 }
61 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -070062""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020063
Matteo Scandolo67654fa2017-06-09 09:33:17 -070064 xproto = \
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020065"""
66package xos.network;
67
68message Port (PlCoreBase,ParameterMixin){
69 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
70 optional manytoone instance->xos.core.Instance:ports = 2 [db_index = True, null = True, blank = True];
71 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
72 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
73 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
74 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
75}
76
77
78package xos.core;
79
80message Instance (PlCoreBase){
81 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
82 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
83 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
84 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
85 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
86 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
87 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
88 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
89 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
90 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
91 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
92 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
93 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
94 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];
95 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
96 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
97 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
98}
99
100package xos.network;
101
102message Network (PlCoreBase,ParameterMixin) {
103 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
104 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
105 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
106 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
107 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
108 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
109 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
110 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
111 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
112 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
113 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
114 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
115 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
116 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
117 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
118 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
119 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];
120 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
121 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
122 required manytomany instances->xos.core.Instance/xos.network.Port:networks = 20 [db_index = False, null = False, blank = True];
123}
124
125message Slice (PlCoreBase){
126 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
127 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
128 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
129 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];
130 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
131 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
132 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
133 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
134 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'))"];
135 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
136 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
137 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
138 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
139 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
140 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
141 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
142 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];
143 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
144}
145"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700146 args = FakeArgs()
147 args.inputs = xproto
148 args.target = target
149 output = XOSGenerator.generate(args)
150
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200151 self.assertIn('numberCores', output) # Instance showed up via cross-package call
152 self.assertIn('ip;', output) # Network showed up via cross-package call
153 self.assertIn('max_instances', output) # Slice showed up via implicit in-package call
154
155 def test_base_class_fields(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700156 target = XProtoTestHelpers.write_tmp_target(
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200157"""
158 {% for m in proto.messages %}
159 {{ m.name }} {
160 {%- for b in m.bases %}
161 {%- if proto.message_table[b.fqn] -%}
162 {%- set model = proto.message_table[b.fqn] %}
163 {% for f in model.fields %}
164 {{ f.type }} {{ f.name }};
165 {% endfor %}
166 {%- endif -%}
167 {% endfor %}
168 }
169 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700170""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200171
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700172 xproto =\
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200173"""
174package xos.network;
175
176message Port (PlCoreBase,ParameterMixin){
177 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
178 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
179 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
180 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
181 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
182 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
183}
184
185package xos.someotherpackage;
186
187message Instance (xos.network.Port){
188 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
189 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
190 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
191 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
192 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
193 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
194 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
195 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
196 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
197 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
198 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
199 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
200 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
201 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];
202 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
203 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
204 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
205}
206"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700207 args = FakeArgs()
208 args.inputs = xproto
209 args.target = target
210 output = XOSGenerator.generate(args)
211
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200212 self.assertIn('xos_created', output)
213
214 def test_from_base(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700215 target = XProtoTestHelpers.write_tmp_target( \
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200216"""
217 {% for f in xproto_base_fields(proto.messages.3, proto.message_table) %}
218 {{ f.type }} {{ f.name }};
219 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700220""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200221
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700222 xproto =\
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200223"""
224option app_name = "firstapp";
225
226message Port (PlCoreBase,ParameterMixin){
227 required string easter_egg = 1;
228 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
229 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
230 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
231 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
232 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
233 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
234}
235
236package A;
237
238message Instance (Port){
239 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
240 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
241 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
242 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
243 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
244 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
245 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
246 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
247 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
248 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
249 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
250 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
251 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
252 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];
253 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
254 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
255 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
256}
257
258package B;
259
260option app_name="networkapp";
261
262message Network (A.Instance) {
263 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
264 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
265 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
266 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
267 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
268 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
269 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
270 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
271 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
272 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
273 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
274 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
275 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
276 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
277 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
278 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
279 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];
280 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
281 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
282 required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True];
283}
284
285option app_name="sliceapp";
286
287message Slice (Network){
288 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
289 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
290 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
291 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];
292 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
293 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
294 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
295 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
296 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'))"];
297 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
298 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
299 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
300 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
301 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
302 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
303 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
304 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];
305 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
306}
307"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700308 args = FakeArgs()
309 args.inputs = xproto
310 args.target = target
311 output = XOSGenerator.generate(args)
312
313 self.assertIn('easter_egg', output)
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200314
315 def test_model_options(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700316 target = XProtoTestHelpers.write_tmp_target(
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200317"""
318 Options:
319
320 {{ proto.options }}
321 {% for m in proto.messages %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200322 {{ m.options.app_name }}
323 {% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700324""")
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200325
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700326 xproto =\
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200327"""
328option app_name = "firstapp";
329
330message Port (PlCoreBase,ParameterMixin){
331 required string easter_egg = 1;
332 required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
333 optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
334 optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
335 optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
336 optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
337 required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
338}
339
340package A;
341
342message Instance (Port){
343 optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
344 optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
345 required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
346 optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
347 optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
348 required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
349 optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
350 required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
351 required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
352 required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
353 required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
354 required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
355 optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
356 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];
357 optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
358 optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
359 required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
360}
361
362package B;
363
364option app_name = "networkapp";
365
366message Network (A.Instance) {
367 required string name = 1 [db_index = False, max_length = 32, null = False, blank = False];
368 required manytoone template->NetworkTemplate:network = 2 [db_index = True, null = False, blank = False];
369 required string subnet = 3 [db_index = False, max_length = 32, null = False, blank = True];
370 required string start_ip = 4 [db_index = False, max_length = 32, null = False, blank = True];
371 required string end_ip = 5 [db_index = False, max_length = 32, null = False, blank = True];
372 optional string ports = 6 [db_index = False, max_length = 1024, null = True, blank = True];
373 optional string labels = 7 [db_index = False, max_length = 1024, null = True, blank = True];
374 required manytoone owner->Slice:ownedNetworks = 8 [help_text = "Slice that owns control of this Network", null = False, db_index = True, blank = False];
375 required int32 guaranteed_bandwidth = 9 [default = 0, null = False, db_index = False, blank = False];
376 required bool permit_all_slices = 10 [default = False, null = False, db_index = False, blank = True];
377 optional string topology_parameters = 11 [db_index = False, null = True, blank = True];
378 optional string controller_url = 12 [db_index = False, max_length = 1024, null = True, blank = True];
379 optional string controller_parameters = 13 [db_index = False, null = True, blank = True];
380 optional string network_id = 14 [help_text = "Quantum network", max_length = 256, null = True, db_index = False, blank = True];
381 optional string router_id = 15 [help_text = "Quantum router id", max_length = 256, null = True, db_index = False, blank = True];
382 optional string subnet_id = 16 [help_text = "Quantum subnet id", max_length = 256, null = True, db_index = False, blank = True];
383 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];
384 required manytomany permitted_slices->Slice/Network_permitted_slices:availableNetworks = 18 [db_index = False, null = False, blank = True];
385 required manytomany slices->Slice/NetworkSlice:networks = 19 [db_index = False, null = False, blank = True];
386 required manytomany instances->Instance/Port:networks = 20 [db_index = False, null = False, blank = True];
387}
388
389
390option app_name = "networkapp";
391
392message Slice (Network){
393 required string name = 1 [max_length = 80, content_type = "stripped", blank = False, help_text = "The Name of the Slice", null = False, db_index = False];
394 required bool enabled = 2 [help_text = "Status for this Slice", default = True, null = False, db_index = False, blank = True];
395 required bool omf_friendly = 3 [default = False, null = False, db_index = False, blank = True];
396 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];
397 required string slice_url = 5 [db_index = False, max_length = 512, null = False, content_type = "url", blank = True];
398 required manytoone site->Site:slices = 6 [help_text = "The Site this Slice belongs to", null = False, db_index = True, blank = False];
399 required int32 max_instances = 7 [default = 10, null = False, db_index = False, blank = False];
400 optional manytoone service->Service:slices = 8 [db_index = True, null = True, blank = True];
401 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'))"];
402 optional string exposed_ports = 10 [db_index = False, max_length = 256, null = True, blank = True];
403 optional manytoone serviceClass->ServiceClass:slices = 11 [db_index = True, null = True, blank = True];
404 optional manytoone creator->User:slices = 12 [db_index = True, null = True, blank = True];
405 optional manytoone default_flavor->Flavor:slices = 13 [db_index = True, null = True, blank = True];
406 optional manytoone default_image->Image:slices = 14 [db_index = True, null = True, blank = True];
407 optional manytoone default_node->Node:slices = 15 [db_index = True, null = True, blank = True];
408 optional string mount_data_sets = 16 [default = "GenBank", max_length = 256, content_type = "stripped", blank = True, null = True, db_index = False];
409 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];
410 required manytomany tags->Tag = 18 [db_index = False, null = False, blank = True];
411}
412"""
Matteo Scandolo67654fa2017-06-09 09:33:17 -0700413
414 args = FakeArgs()
415 args.inputs = xproto
416 args.target = target
417 output = XOSGenerator.generate(args)
418
Sapan Bhatia3cfdf632017-06-08 05:14:03 +0200419 self.assertEqual(output.count('firstapp'), 2)
420 self.assertEqual(output.count('networkapp'), 2)
421
422
423if __name__ == '__main__':
424 unittest.main()
425
426