Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 1 | import unittest |
| 2 | import os |
| 3 | from xosgenx.generator import XOSGenerator |
| 4 | from helpers import FakeArgs, XProtoTestHelpers |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 5 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 6 | class XProtoPackageTest(unittest.TestCase): |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 7 | def test_package_fqn(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 8 | args = FakeArgs() |
| 9 | target = XProtoTestHelpers.write_tmp_target( |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 10 | """ |
| 11 | {% for m in proto.messages %} |
| 12 | {{ m.name }},{{ m.package }},{{ m.fqn }} |
| 13 | {% endfor %} |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 14 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 15 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 16 | xproto =\ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 17 | """ |
| 18 | package xos.core; |
| 19 | |
| 20 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 29 | args = FakeArgs() |
| 30 | args.inputs = xproto |
| 31 | args.target = target |
| 32 | |
| 33 | output = XOSGenerator.generate(args) |
| 34 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 35 | self.assertIn('Port,xos.core,xos.core.Port', output) |
| 36 | |
| 37 | def test_cross_model(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 38 | target = XProtoTestHelpers.write_tmp_target( \ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 39 | """ |
| 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 62 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 63 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 64 | xproto = \ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 65 | """ |
| 66 | package xos.network; |
| 67 | |
| 68 | message 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 | |
| 78 | package xos.core; |
| 79 | |
| 80 | message 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 | |
| 100 | package xos.network; |
| 101 | |
| 102 | message 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 | |
| 125 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 146 | args = FakeArgs() |
| 147 | args.inputs = xproto |
| 148 | args.target = target |
| 149 | output = XOSGenerator.generate(args) |
| 150 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 151 | 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 156 | target = XProtoTestHelpers.write_tmp_target( |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 157 | """ |
| 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 170 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 171 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 172 | xproto =\ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 173 | """ |
| 174 | package xos.network; |
| 175 | |
| 176 | message 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 | |
| 185 | package xos.someotherpackage; |
| 186 | |
| 187 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 207 | args = FakeArgs() |
| 208 | args.inputs = xproto |
| 209 | args.target = target |
| 210 | output = XOSGenerator.generate(args) |
| 211 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 212 | self.assertIn('xos_created', output) |
| 213 | |
| 214 | def test_from_base(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 215 | target = XProtoTestHelpers.write_tmp_target( \ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 216 | """ |
| 217 | {% for f in xproto_base_fields(proto.messages.3, proto.message_table) %} |
| 218 | {{ f.type }} {{ f.name }}; |
| 219 | {% endfor %} |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 220 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 221 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 222 | xproto =\ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 223 | """ |
| 224 | option app_name = "firstapp"; |
| 225 | |
| 226 | message 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 | |
| 236 | package A; |
| 237 | |
| 238 | message 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 | |
| 258 | package B; |
| 259 | |
| 260 | option app_name="networkapp"; |
| 261 | |
| 262 | message 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 | |
| 285 | option app_name="sliceapp"; |
| 286 | |
| 287 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 308 | args = FakeArgs() |
| 309 | args.inputs = xproto |
| 310 | args.target = target |
| 311 | output = XOSGenerator.generate(args) |
| 312 | |
| 313 | self.assertIn('easter_egg', output) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 314 | |
| 315 | def test_model_options(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 316 | target = XProtoTestHelpers.write_tmp_target( |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 317 | """ |
| 318 | Options: |
| 319 | |
| 320 | {{ proto.options }} |
| 321 | {% for m in proto.messages %} |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 322 | {{ m.options.app_name }} |
| 323 | {% endfor %} |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 324 | """) |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 325 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 326 | xproto =\ |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 327 | """ |
| 328 | option app_name = "firstapp"; |
| 329 | |
| 330 | message 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 | |
| 340 | package A; |
| 341 | |
| 342 | message 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 | |
| 362 | package B; |
| 363 | |
| 364 | option app_name = "networkapp"; |
| 365 | |
| 366 | message 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 | |
| 390 | option app_name = "networkapp"; |
| 391 | |
| 392 | message 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 Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame^] | 413 | |
| 414 | args = FakeArgs() |
| 415 | args.inputs = xproto |
| 416 | args.target = target |
| 417 | output = XOSGenerator.generate(args) |
| 418 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 419 | self.assertEqual(output.count('firstapp'), 2) |
| 420 | self.assertEqual(output.count('networkapp'), 2) |
| 421 | |
| 422 | |
| 423 | if __name__ == '__main__': |
| 424 | unittest.main() |
| 425 | |
| 426 | |