4 # test_zebra_seg6_route.py
6 # Copyright (c) 2020 by
7 # LINE Corporation, Hiroki Shirokura <slank.dev@gmail.com>
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 test_zebra_seg6_route.py: Test seg6 route addition with zapi.
34 from functools
import partial
36 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
37 sys
.path
.append(os
.path
.join(CWD
, "../"))
39 # pylint: disable=C0413
40 from lib
import topotest
41 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
42 from lib
.topolog
import logger
43 from lib
.common_config
import shutdown_bringup_interface
44 from mininet
.topo
import Topo
47 def open_json_file(filename
):
49 with
open(filename
, "r") as f
:
52 assert False, "Could not read file {}".format(filename
)
55 class TemplateTopo(Topo
):
56 def build(self
, **_opts
):
57 tgen
= get_topogen(self
)
61 def setup_module(mod
):
62 tgen
= Topogen(TemplateTopo
, mod
.__name
__)
64 router_list
= tgen
.routers()
65 for rname
, router
in tgen
.routers().items():
66 router
.run("/bin/bash {}".format(os
.path
.join(CWD
, "{}/setup.sh".format(rname
))))
67 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, '{}/zebra.conf'.format(rname
)))
68 router
.load_config(TopoRouter
.RD_SHARP
, os
.path
.join(CWD
, "{}/sharpd.conf".format(rname
)))
72 def teardown_module(_mod
):
77 def test_zebra_seg6local_routes():
79 if tgen
.routers_have_failure():
80 pytest
.skip(tgen
.errors
)
81 logger
.info("Test for seg6local route install via ZAPI was start.")
84 def check(router
, dest
, nh
, sid
, expected
):
85 router
.vtysh_cmd("sharp install seg6-routes {} "\
86 "nexthop-seg6 {} encap {} 1".format(dest
, nh
, sid
))
87 output
= json
.loads(router
.vtysh_cmd("show ipv6 route {} json".format(dest
)))
88 output
= output
.get('{}/128'.format(dest
))
91 return topotest
.json_cmp(output
, expected
)
93 manifests
= open_json_file(os
.path
.join(CWD
, "{}/routes.json".format("r1")))
94 for manifest
in manifests
:
95 logger
.info("CHECK {} {} {}".format(manifest
['in']['dest'],
97 manifest
['in']['sid']))
98 test_func
= partial(check
, r1
,
99 manifest
['in']['dest'],
100 manifest
['in']['nh'],
101 manifest
['in']['sid'],
103 success
, result
= topotest
.run_and_expect(test_func
, None, count
=5, wait
=1)
104 assert result
is None, 'Failed'
107 if __name__
== "__main__":
108 args
= ["-s"] + sys
.argv
[1:]
109 sys
.exit(pytest
.main(args
))