Vane API¶
tests_tools
¶
This module has the TestOps class which provides an array of different operations that a test case can perform. It also consists of standalone functions which provide utility operations while executing test cases.
Classes¶
TestOps
¶
The TestOps class introduces the API which lets you execute common testcase operations like running show commands on devices, generating test reports, writing evidence files and generating test steps. These operations get called from within the test case.
Source code in vane/tests_tools.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 |
|
Functions¶
__init__
¶
Initializes the TestOps Object with test specific and dut specific data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tests_definitions |
str
|
YAML representation of tests |
required |
test_suite |
str
|
name of test suite |
required |
dut |
dict
|
device under test |
required |
Source code in vane/tests_tools.py
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
|
add_cmds_evidence
¶
API to update non-netmiko and non-pyeapi command execution outputs in the the docx and html report. The user must provide output in the desired format to this utility function. The function does not handle the formatting of the output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmds |
list
|
List of commands that are executed on the device. |
required |
cmds_output |
list
|
List of command outputs corresponding to cmds. |
required |
device_name |
str
|
Name of the device on which the commands were executed. |
required |
Source code in vane/tests_tools.py
generate_report
¶
Utility to generate report
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut_name |
str
|
name of the device |
required |
output |
str
|
Output of commands executed on a device.Default value is an empty string. |
''
|
Source code in vane/tests_tools.py
get_cmd_output_from_device_details
¶
Utility to get the output of the command mentioned in arguments. Args: command(str): Command to collect the output from device output details. Return: str: Filtered output string
Source code in vane/tests_tools.py
get_eapi_connection
¶
Return the eapi connection if it exists otherwise initialise a new eapi connection
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut |
dict
|
device whose eapi connection should be returned |
required |
Returns:
Name | Type | Description |
---|---|---|
conn |
paramiko connection
|
eapi connection for the device |
Source code in vane/tests_tools.py
get_new_conn
¶
Returns a new connection to the dut of type 'conn_type' with read timeout set to timeout
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut |
dict
|
the device to get the connection to |
required |
conn_type |
pyeapi/netmiko conn
|
eapi or ssh |
required |
timeout |
int
|
Read time out for the connection |
required |
Returns:
Name | Type | Description |
---|---|---|
conn |
pyeapi / netmiko
|
a new eapi or ssh connection to dut |
Source code in vane/tests_tools.py
get_ssh_connection
¶
Return the ssh connection if it exists otherwise initialise a new ssh connection
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut |
dict
|
device whose ssh connection should be returned |
required |
Returns:
Name | Type | Description |
---|---|---|
conn |
netmiko connection
|
ssh connection for the device |
Source code in vane/tests_tools.py
parse_test_steps
¶
Returns a list of all the test steps in the given function. Inspects functions and finds statements with TS: and organizes them into a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
obj
|
function reference with body to inspect for test steps |
required |
Source code in vane/tests_tools.py
run_cfg_cmds
¶
A wrapper which runs the configuration cmds if no dut is passed then cmds are run on TestOps dut object, if conn_type is eapi then pyeapi is used to connect to dut, if conn_type is ssh then netmiko is used to connect to dut, if timeout is non-zero then a new connection is created with new timeout, if new_conn is True a new connection to dut is created.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg_cmds |
list
|
list of configuration cmds to run |
required |
dut |
dict
|
device on which cfg_cmds have to run |
None
|
conn_type |
pyeapi / netmiko
|
connection type to dut - either pyeapi or netmiko |
'eapi'
|
timeout |
int
|
read timeout for dut connection |
0
|
new_conn |
boolean
|
whether to get a new conn to dut |
False
|
Returns:
Name | Type | Description |
---|---|---|
obj |
dict
|
A dict object that includes the response for each command |
Source code in vane/tests_tools.py
run_show_cmds
¶
A wrapper which runs the 'show_cmds' conn_type determines how the cmds are being run if conn_type is eapi then pyeapi is used on specified dut, if conn_type is ssh then netmiko connection in dut object is used if no dut is passed then cmds are run on TestOps dut object. It returns the output of these 'show_cmds' in the encoding requested. Also it checks show_clock_flag to see if 'show_clock' cmd needs to be run. It stores the text output for 'show_cmds' list in 'show_cmds_txt' list for the specific dut. Also 'show_cmds' list is appended to object's 'show_cmds' list. If timeout is non-zero then a new connection is created with new timeout. If new_conn is set to True then new connection is created.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_cmds |
list
|
list of show commands to be run |
required |
dut |
dict
|
the device to run the show command on |
None
|
encoding |
str
|
json or text, with json being default |
'json'
|
conn_type |
pyeapi / netmiko
|
eapi or ssh, with eapi being default |
'eapi'
|
timeout |
int
|
timeout to be used for connection to DUT |
0
|
new_conn |
boolean
|
whether or not to create a new conn to DUT |
False
|
Returns:
Name | Type | Description |
---|---|---|
obj |
dict
|
A dict object that includes the response for each command along with the encoding |
Source code in vane/tests_tools.py
set_evidence_default
¶
Initializes evidence values for neighbor duts since init only initializes for primary dut
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut_name |
str
|
Name of the dut |
required |
Source code in vane/tests_tools.py
setup_and_run_traffic
¶
Module to call respective traffic generator based on the type of traffic generator being used in the test case
Parameters:
Name | Type | Description | Default |
---|---|---|---|
traffic_generator_type |
str
|
type of the traffic generator being used |
required |
configuration_file |
.ixcng file
|
traffic profile file to pass to the traffic generator |
required |
Source code in vane/tests_tools.py
setup_ixia
¶
Module to authenticate into Ixia Web Api, configure a session with passed in configuration file, generate traffic and return traffic and flow stats to validate test criteria
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ixia_configuration |
str
|
path of ixia config file |
required |
Source code in vane/tests_tools.py
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 |
|
transfer_file
¶
Transfers filename to/from the the dut depending on the operation mentioned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut |
dict
|
device to/from which file needs to be transferred |
None
|
src_file |
str
|
full filename of src file |
required |
dest_file |
str
|
full filename of dest file |
required |
operation |
str
|
'get' or 'put' |
required |
sftp |
boolean
|
whether to use sftp transport or not |
False
|
Returns:
Name | Type | Description |
---|---|---|
result |
dict
|
boolean values for file_exists, file_transferred and file_verified |
Source code in vane/tests_tools.py
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 |
|
valid_xml_char_ordinal
¶
Utility to filter the string as per XML standard Args: char(ste): characters to filter out Return: str: Filtered string
Source code in vane/tests_tools.py
Functions¶
authenticate_and_setup_conn
¶
Method to setup and authenticate setting up PyEapi or Netmiko connection based on conn object passed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut |
dict
|
device data |
required |
conn_object |
pyeapi / netmiko
|
type of connection |
required |
Source code in vane/tests_tools.py
check_duts_reachability
¶
Check if duts are reachable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_duts |
dict
|
Dictionary of duts |
required |
Returns:
Name | Type | Description |
---|---|---|
reachability |
boolean
|
result of if duts are reachable |
reachable_duts |
dict
|
reachable duts |
unreachable_duts |
dict
|
unreachable duts |
Source code in vane/tests_tools.py
create_duts_file
¶
Automatically generate a DUTs file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topology_file |
str
|
Name and path of topology file |
required |
inventory_file |
str
|
Name and path of inventory file |
required |
Returns:
Name | Type | Description |
---|---|---|
filename |
str
|
duts file name |
Source code in vane/tests_tools.py
dut_worker
¶
Execute inputted show commands on dut. Update dut structured data with show output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut |
dict
|
structured data of a dut output data, hostname, and |
required |
show_cmds |
list
|
List of show commands |
required |
reachable_duts |
dict
|
Abstraction of duts |
required |
Source code in vane/tests_tools.py
export_text
¶
Export python data structure as a TEXT file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text_file |
str
|
Name of TEXT file |
required |
text_data |
dict
|
output of show command in python dictionary |
required |
dut_name |
str
|
Primary dut name |
required |
Source code in vane/tests_tools.py
export_yaml
¶
Export python data structure as a YAML file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_file |
str
|
Name of YAML file |
required |
yaml_data |
dict
|
Data to be written to yaml file |
required |
Source code in vane/tests_tools.py
filter_duts
¶
Filter duts based on a user provided criteria and a filter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
duts |
dict
|
Full global duts dictionary |
required |
criteria |
str
|
Type of filtering required. Valid options are name, role, regex, or names. Defaults to "". |
''
|
dut_filter |
str
|
Filter for DUTs. Defaults to "". |
''
|
Returns:
Name | Type | Description |
---|---|---|
subset_duts |
list(dict)
|
Filtered subset of global dictionary of duts |
dut_names |
list(str)
|
Filtered subset of global dictionary of dut names |
Source code in vane/tests_tools.py
get_parameters
¶
Return test parameters for a test case
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tests_parameters |
dict
|
Abstraction of testing parameters |
required |
test_suite |
str
|
test suite of the test case |
required |
Returns:
Name | Type | Description |
---|---|---|
case_parameters |
list
|
test parameters for a test case |
Source code in vane/tests_tools.py
import_config
¶
Check for setup file. If setup file exists import configuration for reporting
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir_path |
str
|
Path to test case directory |
required |
test_suite |
dict
|
Test case definition parameters |
required |
Source code in vane/tests_tools.py
import_config_from_name
¶
Import configuration from a device name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
setup_config |
dict
|
Setup file data structure |
required |
testcase |
dict
|
test case defintions data structure |
required |
Source code in vane/tests_tools.py
import_config_from_role
¶
Import configuration from a device role
Parameters:
Name | Type | Description | Default |
---|---|---|---|
setup_config |
dict
|
Setup file data structure |
required |
testcase |
dict
|
test case defintions data structure |
required |
Source code in vane/tests_tools.py
import_yaml
¶
Import YAML file as python data structure
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_file |
str
|
Name of YAML file |
required |
Returns:
Name | Type | Description |
---|---|---|
yaml_data |
dict
|
Dictionary containing yaml data |
Source code in vane/tests_tools.py
init_duts
¶
Use PS LLD spreadsheet to find interesting duts and then execute inputted show commands on each dut. Return structured data of dut's output data, hostname, and connection. Using threading to make method more efficient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_cmds |
str
|
list of interesting show commands |
required |
test_parameters |
dict
|
Abstraction of testing parameters |
required |
test_duts |
dict
|
Dictionary of duts |
required |
Returns:
Name | Type | Description |
---|---|---|
duts |
dict
|
structured data of duts output data, hostname, and connection |
Source code in vane/tests_tools.py
login_duts
¶
Use eapi to connect to Arista switches for testing
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_parameters |
dict
|
Abstraction of testing parameters |
required |
duts |
dict
|
Dictionary of duts |
required |
Returns:
Name | Type | Description |
---|---|---|
reachable_duts |
list
|
List of dictionaries representing dut objects which are reachable |
unreachable_duts |
list
|
List of dictionaries representing dut objects which are unreachable (due to bad authentication) |
Source code in vane/tests_tools.py
parametrize_duts
¶
Use a filter to create input variables for PyTest parametrize
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_fname |
str
|
Test suite path and file name |
required |
test_defs |
dict
|
Dictionary with global test definitions |
required |
dut_objs |
dict
|
Full global dictionary duts dictionary |
required |
Returns:
Name | Type | Description |
---|---|---|
dut_parameters |
dict
|
Dictionary with variables PyTest parametrize for each test case. |
Source code in vane/tests_tools.py
post_process_skip
¶
Post processing for test case that encounters a PyTest Skip Args: tops (obj): Test case object steps (func): Test case output (str): Test case show output
Source code in vane/tests_tools.py
remove_cmd
¶
Remove command that is not supported by pyeapi
Parameters:
Name | Type | Description | Default |
---|---|---|---|
err |
str
|
Error string |
required |
show_cmds |
list
|
List of pre-processed commands |
required |
Returns:
Name | Type | Description |
---|---|---|
show_cmds |
list
|
List of post-processed commands |
Source code in vane/tests_tools.py
return_duts_with_role
¶
Create a list of duts with a role
Parameters:
Name | Type | Description | Default |
---|---|---|---|
role_name |
str
|
Role to match in duts data structure |
required |
Returns:
Name | Type | Description |
---|---|---|
dev_names |
list
|
Hostnames of DUTs with role |
Source code in vane/tests_tools.py
return_interfaces
¶
Parse reachable_duts for interface connections and return them to test
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hostname |
str
|
hostname of dut |
required |
reachable_duts |
dict
|
Abstraction of reachable_duts |
required |
Returns:
Name | Type | Description |
---|---|---|
interface_list |
list
|
list of interesting interfaces based on PS LLD spreadsheet |
Source code in vane/tests_tools.py
return_show_cmds
¶
Return show commands from the test_definitions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_parameters |
dict
|
Abstraction of testing parameters |
required |
Returns:
Name | Type | Description |
---|---|---|
show_cmds |
list
|
show commands from the test_definitions |
Source code in vane/tests_tools.py
return_test_defs
¶
Return test_definitions from the test_parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_parameters |
dict
|
Abstraction of testing parameters |
required |
Returns:
Name | Type | Description |
---|---|---|
test_defs |
dict
|
test definitions |
Source code in vane/tests_tools.py
send_cmds
¶
Send show commands to duts and recurse on failure
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_cmds |
list
|
List of pre-processed commands |
required |
conn |
obj
|
connection |
required |
encoding |
str
|
encoding type of show commands: either json or text |
required |
Returns:
Name | Type | Description |
---|---|---|
show_cmd_list |
list
|
list of show command outputs |
show_cmds |
list
|
list of show commands |
Source code in vane/tests_tools.py
verify_show_cmd
¶
Verify if show command was successfully executed on dut
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show_cmd |
str
|
show command |
required |
dut |
dict
|
data structure of dut parameters |
required |
Source code in vane/tests_tools.py
verify_tacacs
¶
Verify if tacacs servers are configured
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut |
dict
|
data structure of dut parameters |
required |
Returns:
Name | Type | Description |
---|---|---|
tacacs_bool |
bool
|
boolean representing if tacacs server(s) are configured or not |
Source code in vane/tests_tools.py
verify_veos
¶
Verify if DUT is a VEOS instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dut |
dict
|
data structure of dut parameters |
required |
Returns:
Name | Type | Description |
---|---|---|
veos_bool |
bool
|
boolean representing if the dut is a VEOS instance or not. |
Source code in vane/tests_tools.py
yaml_read
¶
Return yaml data read from the yaml file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_file |
file
|
Input yaml file to be read |
required |
Returns:
Name | Type | Description |
---|---|---|
yaml_data |
dict
|
Yaml data read from the file |