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 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 16 | import unittest |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 17 | from xosgenx.generator import XOSProcessor, XOSProcessorArgs |
| 18 | from helpers import XProtoTestHelpers |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 19 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 20 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 21 | class XProtoRlinkTests(unittest.TestCase): |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 22 | def test_proto_generator(self): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 23 | target = XProtoTestHelpers.write_tmp_target( |
| 24 | """ |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 25 | {% for m in proto.messages %} |
| 26 | {% for r in m.rlinks %} |
| 27 | {{ r }} |
| 28 | {% endfor %} |
| 29 | {% endfor %} |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 30 | """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 31 | ) |
| 32 | |
| 33 | xproto = """ |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 34 | message VRouterPort (PlCoreBase){ |
| 35 | optional string name = 1 [help_text = "port friendly name", max_length = 20, null = True, db_index = False, blank = True]; |
| 36 | required string openflow_id = 2 [help_text = "port identifier in ONOS", max_length = 21, null = False, db_index = False, blank = False]; |
| 37 | required manytoone vrouter_device->VRouterDevice:ports = 3 [db_index = True, null = False, blank = False]; |
| 38 | required manytoone vrouter_service->VRouterService:device_ports = 4 [db_index = True, null = False, blank = False]; |
| 39 | } |
| 40 | |
| 41 | message VRouterService (Service) { |
| 42 | optional string rest_hostname = 1 [db_index = False, max_length = 255, null = True, content_type = "stripped", blank = True]; |
| 43 | required int32 rest_port = 2 [default = 8181, null = False, db_index = False, blank = False]; |
| 44 | required string rest_user = 3 [default = "onos", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False]; |
| 45 | required string rest_pass = 4 [default = "rocks", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False]; |
| 46 | } |
| 47 | |
| 48 | message VRouterDevice (PlCoreBase){ |
| 49 | optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True]; |
| 50 | required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False]; |
| 51 | required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False]; |
| 52 | required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False]; |
| 53 | required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False]; |
| 54 | } |
| 55 | """ |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 56 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 57 | args = XOSProcessorArgs() |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 58 | args.inputs = xproto |
| 59 | args.target = target |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 60 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 61 | self.assertIn("'src_port': 'device_ports'", output) |
| 62 | self.assertIn("'src_port': 'ports'", output) |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 63 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame^] | 64 | |
| 65 | if __name__ == "__main__": |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 66 | unittest.main() |