Best Python code snippet using autotest_python
test_netmiko_config_acl.py
Source:test_netmiko_config_acl.py
...5from network_utilities import generate_cisco_nxos_acl # noqa6from network_utilities import generate_cisco_xr_acl # noqa7from network_utilities import generate_arista_eos_acl # noqa8from network_utilities import generate_juniper_junos_acl # noqa9def remove_acl(net_connect, cmd, commit=False):10 """Ensure ACL is removed."""11 net_connect.send_config_set(cmd)12 if commit:13 net_connect.commit()14 net_connect.exit_config_mode()15def test_large_acl(net_connect, commands, expected_responses, acl_entries=100):16 """Test configuring a large ACL."""17 if commands.get("config_long_acl"):18 acl_config = commands.get("config_long_acl")19 base_cmd = acl_config["base_cmd"]20 verify_cmd = acl_config["verify_cmd"]21 delete_cmd = acl_config.get("delete_cmd")22 offset = acl_config["offset"]23 else:24 pytest.skip("Platform not supported for ACL test")25 platform = net_connect.device_type26 support_commit = commands.get("support_commit")27 if "juniper_junos" in platform:28 cmd = delete_cmd29 else:30 cmd = f"no {base_cmd}"31 remove_acl(net_connect, cmd=cmd, commit=support_commit)32 # Generate the ACL33 platform = net_connect.device_type34 if "cisco_ios" in net_connect.device_type or "cisco_xe" in net_connect.device_type:35 cfg_lines = generate_ios_acl()36 else:37 func_name = f"generate_{platform}_acl"38 acl_func = globals()[func_name]39 cfg_lines = acl_func()40 # Send ACL to remote devices41 result = net_connect.send_config_set(cfg_lines)42 if support_commit:43 net_connect.commit()44 net_connect.exit_config_mode()45 # send_config_set should return same num lines + offset lines for entering/exiting cfg-mode46 # NX-OS is will have more than one newline (per line)47 result_list = re.split(r"\n+", result)48 assert len(result_list) == len(cfg_lines) + offset49 # Check that length of lines in show of the acl matches lines configured50 verify = net_connect.send_command(verify_cmd)51 verify_list = re.split(r"\n+", verify.strip())52 # IOS-XR potentially has a timestamp on the show command53 if "UTC" in verify_list[0]:54 verify_list.pop(0)55 if "juniper_junos" in platform:56 offset = 657 assert len(verify_list) - offset == len(cfg_lines)58 else:59 assert len(verify_list) == len(cfg_lines)60 if "juniper_junos" in platform:61 cmd = delete_cmd62 else:63 cmd = f"no {base_cmd}"64 remove_acl(net_connect, cmd=cmd, commit=support_commit)...
remove-device.py
Source:remove-device.py
1#!/usr/bin/python32import os3import argparse4import manage_capabilities5if __name__ == "__main__":6 path, _ = os.path.split(os.path.realpath(__file__))7 os.chdir(path)8 parser = argparse.ArgumentParser(9 description="Utility to remove devices exposed by the bundle box.")10 parser.add_argument("-i", "--ip", metavar="device_ip", type=str, required=True,11 help="The IP address of the to-be-removed device.")12 parser.add_argument('-a', "--acl", dest="remove_acl", action='store_true',13 help="Use -a flag to remove the device from the ACL, the device will no longer be connected to the Federated Lab in any way.")14 args = parser.parse_args()15 manage_capabilities.remove_device(args.ip, args.remove_acl)...
urls.py
Source:urls.py
1from django.conf.urls import url2from django.contrib.auth.decorators import login_required3from . import views4from django.conf import settings5urlpatterns = [6 url(r'^acl/add/$', login_required(views.add_acl), name="add_acl"),7 url(r'^acl/remove/$', login_required(views.remove_acl), name="remove_acl")8]9urlpatterns += [10 url(r'^api/validate_user_permissions/$', views.api_validate_user_permissions),11 url(r'^api/validate_user_roles/$', views.api_validate_user_roles),12 url(r'^api/auth/$', views.api_auth_user),13 url(r'^api/query_user/(?P<username>[\w.-]+)/$', views.api_query_user),14 url(r'^api/urls/$', views.api_urls),15 url(r'^api/permissions/add/$', views.api_permissions_add),16 url(r'^api/user/$', views.api_user),17 url(r'^api/users/', views.api_users)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!