-
Notifications
You must be signed in to change notification settings - Fork 3
/
task61_labpyats.py
executable file
·78 lines (60 loc) · 2.04 KB
/
task61_labpyats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# To get a logger for the script
import logging
from pyats import aetest
from pyats.log.utils import banner
# To handle errors with connections to devices
from unicon.core import errors
import argparse
from pyats.topology import loader
# Get your logger for your script
global log
log = logging.getLogger(__name__)
log.level = logging.ERROR
class MyCommonSetup(aetest.CommonSetup):
"""
CommonSetup class to prepare for testcases
Establishes connections to all devices in testbed
"""
@aetest.subsection
def establish_connections(self, pyats_testbed):
"""
Establishes connections to all devices in testbed
:param testbed:
:return:
"""
device_list = []
for device in pyats_testbed.devices.values():
log.info(banner(
f"Connect to device '{device.name}'"))
try:
device.connect(log_stdout=False)
except errors.ConnectionError:
self.failed(f"Failed to establish "
f"connection to '{device.name}'")
device_list.append(device)
# Pass list of devices to testcases
self.parent.parameters.update(dev=device_list)
class VerifyLogging(aetest.Testcase):
"""
VerifyLogging Testcase - collect show logging information from devices
Verify that all devices do not have 'ERROR|WARN' messages in logs
"""
@aetest.setup
def setup(self):
pass
@aetest.test
def error_logs(self):
any_device = self.parent.parameters['dev'][0]
any_device.log_user(enable=True)
output = any_device.execute('show logging | i ERROR|WARN')
if len(output) > 0:
self.failed('Found ERROR in log, review logs first')
else:
pass
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--testbed', dest='pyats_testbed',
type=loader.load)
args, unknown = parser.parse_known_args()
aetest.main(**vars(args))