Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 17 | import unittest |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 18 | from xosgenx.generator import XOSProcessor |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 19 | from helpers import FakeArgs, XProtoTestHelpers |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [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): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 23 | target = XProtoTestHelpers.write_tmp_target(""" |
| 24 | {% for m in proto.messages %} |
| 25 | {% for r in m.rlinks %} |
| 26 | {{ r }} |
| 27 | {% endfor %} |
| 28 | {% endfor %} |
| 29 | """) |
| 30 | |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 31 | xproto = \ |
| 32 | """ |
| 33 | message VRouterPort (PlCoreBase){ |
| 34 | optional string name = 1 [help_text = "port friendly name", max_length = 20, null = True, db_index = False, blank = True]; |
| 35 | required string openflow_id = 2 [help_text = "port identifier in ONOS", max_length = 21, null = False, db_index = False, blank = False]; |
| 36 | required manytoone vrouter_device->VRouterDevice:ports = 3 [db_index = True, null = False, blank = False]; |
| 37 | required manytoone vrouter_service->VRouterService:device_ports = 4 [db_index = True, null = False, blank = False]; |
| 38 | } |
| 39 | |
| 40 | message VRouterService (Service) { |
| 41 | optional string rest_hostname = 1 [db_index = False, max_length = 255, null = True, content_type = "stripped", blank = True]; |
| 42 | required int32 rest_port = 2 [default = 8181, null = False, db_index = False, blank = False]; |
| 43 | required string rest_user = 3 [default = "onos", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False]; |
| 44 | required string rest_pass = 4 [default = "rocks", max_length = 255, content_type = "stripped", blank = False, null = False, db_index = False]; |
| 45 | } |
| 46 | |
| 47 | message VRouterDevice (PlCoreBase){ |
| 48 | optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True]; |
| 49 | required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False]; |
| 50 | required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False]; |
| 51 | required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False]; |
| 52 | required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False]; |
| 53 | } |
| 54 | """ |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 55 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 56 | args = FakeArgs() |
| 57 | args.inputs = xproto |
| 58 | args.target = target |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 59 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 60 | self.assertIn("'src_port': 'device_ports'", output) |
| 61 | self.assertIn("'src_port': 'ports'", output) |
Sapan Bhatia | 1e397df | 2017-05-24 12:17:28 +0200 | [diff] [blame] | 62 | |
| 63 | if __name__ == '__main__': |
| 64 | unittest.main() |
| 65 | |
| 66 | |