Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 17 | import unittest |
| 18 | import os |
| 19 | from xosgenx.generator import XOSGenerator |
| 20 | from helpers import FakeArgs, XProtoTestHelpers |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 21 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 22 | class XProtoPackageTest(unittest.TestCase): |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 23 | def test_package_fqn(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 24 | args = FakeArgs() |
| 25 | target = XProtoTestHelpers.write_tmp_target( |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 26 | """ |
| 27 | {% for m in proto.messages %} |
| 28 | {{ m.name }},{{ m.package }},{{ m.fqn }} |
| 29 | {% endfor %} |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 30 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 31 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 32 | xproto =\ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 33 | """ |
| 34 | package xos.core; |
| 35 | |
| 36 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 45 | args = FakeArgs() |
| 46 | args.inputs = xproto |
| 47 | args.target = target |
| 48 | |
| 49 | output = XOSGenerator.generate(args) |
| 50 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 51 | self.assertIn('Port,xos.core,xos.core.Port', output) |
| 52 | |
| 53 | def test_cross_model(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 54 | target = XProtoTestHelpers.write_tmp_target( \ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 55 | """ |
| 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 78 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 79 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 80 | xproto = \ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 81 | """ |
| 82 | package xos.network; |
| 83 | |
| 84 | message 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 | |
| 94 | package xos.core; |
| 95 | |
| 96 | message 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 | |
| 116 | package xos.network; |
| 117 | |
| 118 | message 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 | |
| 141 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 162 | args = FakeArgs() |
| 163 | args.inputs = xproto |
| 164 | args.target = target |
| 165 | output = XOSGenerator.generate(args) |
| 166 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 167 | 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 172 | target = XProtoTestHelpers.write_tmp_target( |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 173 | """ |
| 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 186 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 187 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 188 | xproto =\ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 189 | """ |
| 190 | package xos.network; |
| 191 | |
| 192 | message 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 | |
| 201 | package xos.someotherpackage; |
| 202 | |
| 203 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 223 | args = FakeArgs() |
| 224 | args.inputs = xproto |
| 225 | args.target = target |
| 226 | output = XOSGenerator.generate(args) |
| 227 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 228 | self.assertIn('xos_created', output) |
| 229 | |
| 230 | def test_from_base(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 231 | target = XProtoTestHelpers.write_tmp_target( \ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 232 | """ |
| 233 | {% for f in xproto_base_fields(proto.messages.3, proto.message_table) %} |
| 234 | {{ f.type }} {{ f.name }}; |
| 235 | {% endfor %} |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 236 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 237 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 238 | xproto =\ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 239 | """ |
| 240 | option app_name = "firstapp"; |
| 241 | |
| 242 | message 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 | |
| 252 | package A; |
| 253 | |
| 254 | message 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 | |
| 274 | package B; |
| 275 | |
| 276 | option app_name="networkapp"; |
| 277 | |
| 278 | message 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 | |
| 301 | option app_name="sliceapp"; |
| 302 | |
| 303 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 324 | args = FakeArgs() |
| 325 | args.inputs = xproto |
| 326 | args.target = target |
| 327 | output = XOSGenerator.generate(args) |
| 328 | |
| 329 | self.assertIn('easter_egg', output) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 330 | |
| 331 | def test_model_options(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 332 | target = XProtoTestHelpers.write_tmp_target( |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 333 | """ |
| 334 | Options: |
| 335 | |
| 336 | {{ proto.options }} |
| 337 | {% for m in proto.messages %} |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 338 | {{ m.options.app_name }} |
| 339 | {% endfor %} |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 340 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 341 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 342 | xproto =\ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 343 | """ |
| 344 | option app_name = "firstapp"; |
| 345 | |
| 346 | message 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 | |
| 356 | package A; |
| 357 | |
| 358 | message 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 | |
| 378 | package B; |
| 379 | |
| 380 | option app_name = "networkapp"; |
| 381 | |
| 382 | message 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 | |
| 406 | option app_name = "networkapp"; |
| 407 | |
| 408 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 429 | |
| 430 | args = FakeArgs() |
| 431 | args.inputs = xproto |
| 432 | args.target = target |
| 433 | output = XOSGenerator.generate(args) |
| 434 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 435 | self.assertEqual(output.count('firstapp'), 2) |
| 436 | self.assertEqual(output.count('networkapp'), 2) |
| 437 | |
| 438 | |
| 439 | if __name__ == '__main__': |
| 440 | unittest.main() |
| 441 | |
| 442 | |