Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 1 | import unittest |
| 2 | from xosgenx.generator import XOSGenerator |
| 3 | from helpers import FakeArgs, XProtoTestHelpers |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 4 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 5 | class XProtoRlinkTests(unittest.TestCase): |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 6 | def test_proto_generator(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 7 | target = XProtoTestHelpers.write_tmp_target(""" |
| 8 | {% for m in proto.messages %} |
| 9 | {% for r in m.rlinks %} |
| 10 | {{ r }} |
| 11 | {% endfor %} |
| 12 | {% endfor %} |
| 13 | """) |
| 14 | |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 15 | xproto = \ |
| 16 | """ |
| 17 | message VRouterPort (PlCoreBase){ |
| 18 | optional string name = 1 [help_text = "port friendly name", max_length = 20, null = True, db_index = False, blank = True]; |
| 19 | required string openflow_id = 2 [help_text = "port identifier in ONOS", max_length = 21, null = False, db_index = False, blank = False]; |
| 20 | required manytoone vrouter_device->VRouterDevice:ports = 3 [db_index = True, null = False, blank = False]; |
| 21 | required manytoone vrouter_service->VRouterService:device_ports = 4 [db_index = True, null = False, blank = False]; |
| 22 | } |
| 23 | |
| 24 | message VRouterService (Service) { |
| 25 | optional string rest_hostname = 1 [db_index = False, max_length = 255, null = True, content_type = "stripped", blank = True]; |
| 26 | required int32 rest_port = 2 [default = 8181, null = False, db_index = False, blank = False]; |
| 27 | required string rest_user = 3 [default = "onos", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False]; |
| 28 | required string rest_pass = 4 [default = "rocks", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False]; |
| 29 | } |
| 30 | |
| 31 | message VRouterDevice (PlCoreBase){ |
| 32 | optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True]; |
| 33 | required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False]; |
| 34 | required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False]; |
| 35 | required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False]; |
| 36 | required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False]; |
| 37 | } |
| 38 | """ |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 39 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 40 | args = FakeArgs() |
| 41 | args.inputs = xproto |
| 42 | args.target = target |
| 43 | output = XOSGenerator.generate(args) |
| 44 | self.assertIn("'src_port': 'device_ports'", output) |
| 45 | self.assertIn("'src_port': 'ports'", output) |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 46 | |
| 47 | if __name__ == '__main__': |
| 48 | unittest.main() |
| 49 | |
| 50 | |