blob: 0c7029ad868778976c237ade7c82b9071e9ba018 [file] [log] [blame]
Matteo Scandolo67654fa2017-06-09 09:33:17 -07001import unittest
2from xosgenx.generator import XOSGenerator
3from helpers import FakeArgs, XProtoTestHelpers
Sapan Bhatia1e397df2017-05-24 12:17:28 +02004
Matteo Scandolo67654fa2017-06-09 09:33:17 -07005class XProtoRlinkTests(unittest.TestCase):
Sapan Bhatia1e397df2017-05-24 12:17:28 +02006 def test_proto_generator(self):
Matteo Scandolo67654fa2017-06-09 09:33:17 -07007 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 Bhatia1e397df2017-05-24 12:17:28 +020015 xproto = \
16"""
17message 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
24message 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
31message 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 Bhatia1e397df2017-05-24 12:17:28 +020039
Matteo Scandolo67654fa2017-06-09 09:33:17 -070040 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 Bhatia1e397df2017-05-24 12:17:28 +020046
47if __name__ == '__main__':
48 unittest.main()
49
50