From 4ed0c50159b851897aa9aac1160369710c51b089 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 27 Apr 2022 11:24:04 -0700 Subject: [PATCH] Fix deprecated regex format (#2763) --- netmiko/juniper/juniper.py | 8 ++++---- tests/test_juniper_junos/add_delay_juniper_junos.sh | 9 +++++++++ tests/test_netmiko_show.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100755 tests/test_juniper_junos/add_delay_juniper_junos.sh diff --git a/netmiko/juniper/juniper.py b/netmiko/juniper/juniper.py index e793e3531..45ee1b573 100644 --- a/netmiko/juniper/juniper.py +++ b/netmiko/juniper/juniper.py @@ -68,12 +68,12 @@ def enter_cli_mode(self) -> None: return def check_config_mode( - self, check_string: str = "]", pattern: str = r"(?m)[>#] $" + self, check_string: str = "]", pattern: str = r"(?m:[>#] $)" ) -> bool: """ Checks if the device is in configuration mode or not. - (?m) = Use multiline matching + ?m = Use multiline matching Juniper unfortunately will use # as a message indicator when not in config mode For example, with commit confirmed. @@ -84,13 +84,13 @@ def check_config_mode( def config_mode( self, config_command: str = "configure", - pattern: str = r"(?s)Entering configuration mode.*\].*#", + pattern: str = r"(?s:Entering configuration mode.*\].*#)", re_flags: int = 0, ) -> str: """ Enter configuration mode. - (?s) enables re.DOTALL in regex pattern. + ?s = enables re.DOTALL in regex pattern. """ return super().config_mode( config_command=config_command, pattern=pattern, re_flags=re_flags diff --git a/tests/test_juniper_junos/add_delay_juniper_junos.sh b/tests/test_juniper_junos/add_delay_juniper_junos.sh new file mode 100755 index 000000000..9650a6882 --- /dev/null +++ b/tests/test_juniper_junos/add_delay_juniper_junos.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Add delay for cisco3; must be root or sudo to execute +sudo -s /sbin/tc qdisc del dev eth0 root +sudo -s /sbin/tc qdisc add dev eth0 root handle 1: prio +sudo -s /sbin/tc qdisc add dev eth0 parent 1:3 handle 30: tbf rate 20kbit buffer 1600 limit 3000 +sudo -s /sbin/tc qdisc add dev eth0 parent 30:1 handle 31: netem delay 1000ms 10ms distribution normal loss 10% +sudo -s /sbin/tc filter add dev eth0 protocol ip parent 1:0 prio 3 u32 match ip dst 52.53.154.237 flowid 1:3 + diff --git a/tests/test_netmiko_show.py b/tests/test_netmiko_show.py index f85acba27..87cc74f74 100755 --- a/tests/test_netmiko_show.py +++ b/tests/test_netmiko_show.py @@ -332,7 +332,7 @@ def test_clear_buffer(net_connect, commands, expected_responses): enter = net_connect.RETURN # Manually send a command down the channel so that data needs read. net_connect.write_channel(f"{commands['basic']}{enter}") - time.sleep(1) + time.sleep(4) net_connect.clear_buffer() time.sleep(2)