Yi Tseng | 0cb9b56 | 2021-09-22 17:13:58 -0700 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: Copyright 2021-present Open Networking Foundation. |
| 2 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
Yi Tseng | dda7e32 | 2021-09-20 14:21:20 -0700 | [diff] [blame] | 4 | import os |
Yi Tseng | 0cb9b56 | 2021-09-22 17:13:58 -0700 | [diff] [blame] | 5 | from tests.dependencies.Network import Network |
Jon Hall | dd05bbc | 2022-01-27 12:14:50 -0800 | [diff] [blame] | 6 | from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \ |
| 7 | Testcaselib as run |
Yi Tseng | 0cb9b56 | 2021-09-22 17:13:58 -0700 | [diff] [blame] | 8 | |
| 9 | class IntTest: |
| 10 | |
| 11 | def __init__(self, scapy=False): |
| 12 | self.hosts = ["h1", "h2", "h3"] |
| 13 | self.scapy = scapy |
| 14 | |
| 15 | def setUpTest(self, main): |
| 16 | main.Network = Network() |
| 17 | main.Network.connectToNet() |
Yi Tseng | dda7e32 | 2021-09-20 14:21:20 -0700 | [diff] [blame] | 18 | main.configPath = os.path.join(os.path.dirname(main.testFile), "dependencies") |
Yi Tseng | 0cb9b56 | 2021-09-22 17:13:58 -0700 | [diff] [blame] | 19 | |
| 20 | for host in self.hosts: |
| 21 | main.Network.createHostComponent(host) |
| 22 | if self.scapy: |
| 23 | hostHandle = getattr(main, host) |
| 24 | hostHandle.sudoRequired = True |
| 25 | hostHandle.startScapy() |
| 26 | |
| 27 | def cleanUp(self, main): |
Jon Hall | dd05bbc | 2022-01-27 12:14:50 -0800 | [diff] [blame] | 28 | run.saveOnosDiagsIfFailure(main) |
Yi Tseng | 0cb9b56 | 2021-09-22 17:13:58 -0700 | [diff] [blame] | 29 | for host in self.hosts: |
| 30 | if self.scapy: |
| 31 | hostHandle = getattr(main, host) |
| 32 | hostHandle.stopScapy() |
| 33 | main.Network.removeHostComponent(host) |
| 34 | main.Network.disconnectFromNet() |