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