From c8899f4de78256c1003e8b56240f1030680cd57a Mon Sep 17 00:00:00 2001 From: Fedor Suchkov Date: Sat, 30 Nov 2024 08:55:15 -0500 Subject: [PATCH 1/3] Fix regex to catch `master` and `backup` Juniper Junos prompt parts. --- scrapli/driver/core/juniper_junos/base_driver.py | 8 ++++---- .../core/juniper_junos/test_juniper_junos_base_driver.py | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scrapli/driver/core/juniper_junos/base_driver.py b/scrapli/driver/core/juniper_junos/base_driver.py index 68cf7998..ef6627b5 100644 --- a/scrapli/driver/core/juniper_junos/base_driver.py +++ b/scrapli/driver/core/juniper_junos/base_driver.py @@ -5,7 +5,7 @@ PRIVS = { "exec": ( PrivilegeLevel( - pattern=r"^({\w+:\d}\n){0,1}[\w\-@()/:\.]{1,63}>\s?$", + pattern=r"^({\w+(:\d){0,1}}\n){0,1}[\w\-@()/:\.]{1,63}>\s?$", name="exec", previous_priv="", deescalate="", @@ -16,7 +16,7 @@ ), "configuration": ( PrivilegeLevel( - pattern=r"^({\w+:\d}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", + pattern=r"^({\w+(:\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", name="configuration", previous_priv="exec", deescalate="exit configuration-mode", @@ -27,7 +27,7 @@ ), "configuration_exclusive": ( PrivilegeLevel( - pattern=r"^({\w+:\d}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", + pattern=r"^({\w+(:\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", name="configuration_exclusive", previous_priv="exec", deescalate="exit configuration-mode", @@ -38,7 +38,7 @@ ), "configuration_private": ( PrivilegeLevel( - pattern=r"^({\w+:\d}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", + pattern=r"^({\w+(:\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", name="configuration_private", previous_priv="exec", deescalate="exit configuration-mode", diff --git a/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py b/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py index 6a544990..bdfb6779 100644 --- a/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py +++ b/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py @@ -12,7 +12,11 @@ ("configuration", "boxen# "), ("exec", "box_en> "), ("exec", "rancid@router2.xyz6> "), + ("exec", "{master}\nusername@MX-960-PE1>"), + ("exec", "{backup}\nusername@MX-480-PE2>"), ("configuration", "rancid@router2.xyz6# "), + ("configuration", "{master}[edit]\nusername@MX-960-PE1#"), + ("configuration", "{backup}[edit]\nusername@MX-480-PE2#"), ("shell", "asdfklsdjlf\n%"), ("shell", "[vrf:foo] regress@EVOvFOOBAR_RE0-re0:~$"), ("root_shell", "root@%"), @@ -24,7 +28,11 @@ "configuration", "exec_underscore", "exec_w_period", + "exec-mx-master-re", + "exec-mx-backup-re", "configuration_w_period", + "configuration-mx-master-re", + "configuration-mx-backup-re", "shell", "shell-re0", "root", From 1b94b0ae3133617a2c0b2a034ceffa5cb63c1206 Mon Sep 17 00:00:00 2001 From: Fedor Suchkov Date: Sat, 30 Nov 2024 09:04:48 -0500 Subject: [PATCH 2/3] Fix regex to catch Juniper SRX multichassis node status prompt parts. --- scrapli/driver/core/juniper_junos/base_driver.py | 8 ++++---- .../core/juniper_junos/test_juniper_junos_base_driver.py | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scrapli/driver/core/juniper_junos/base_driver.py b/scrapli/driver/core/juniper_junos/base_driver.py index ef6627b5..7371bef3 100644 --- a/scrapli/driver/core/juniper_junos/base_driver.py +++ b/scrapli/driver/core/juniper_junos/base_driver.py @@ -5,7 +5,7 @@ PRIVS = { "exec": ( PrivilegeLevel( - pattern=r"^({\w+(:\d){0,1}}\n){0,1}[\w\-@()/:\.]{1,63}>\s?$", + pattern=r"^({\w+(:(\w+){0,1}\d){0,1}}\n){0,1}[\w\-@()/:\.]{1,63}>\s?$", name="exec", previous_priv="", deescalate="", @@ -16,7 +16,7 @@ ), "configuration": ( PrivilegeLevel( - pattern=r"^({\w+(:\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", + pattern=r"^({\w+(:(\w+){0,1}\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", name="configuration", previous_priv="exec", deescalate="exit configuration-mode", @@ -27,7 +27,7 @@ ), "configuration_exclusive": ( PrivilegeLevel( - pattern=r"^({\w+(:\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", + pattern=r"^({\w+(:(\w+){0,1}\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", name="configuration_exclusive", previous_priv="exec", deescalate="exit configuration-mode", @@ -38,7 +38,7 @@ ), "configuration_private": ( PrivilegeLevel( - pattern=r"^({\w+(:\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", + pattern=r"^({\w+(:(\w+){0,1}\d){0,1}}\[edit\]\n){0,1}[\w\-@()/:\.]{1,63}#\s?$", name="configuration_private", previous_priv="exec", deescalate="exit configuration-mode", diff --git a/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py b/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py index bdfb6779..35652290 100644 --- a/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py +++ b/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py @@ -14,9 +14,11 @@ ("exec", "rancid@router2.xyz6> "), ("exec", "{master}\nusername@MX-960-PE1>"), ("exec", "{backup}\nusername@MX-480-PE2>"), + ("exec", "{primary:node0}\nusername@SRX-4600-FW1>"), ("configuration", "rancid@router2.xyz6# "), ("configuration", "{master}[edit]\nusername@MX-960-PE1#"), ("configuration", "{backup}[edit]\nusername@MX-480-PE2#"), + ("configuration", "{primary:node0}\nusername@SRX-4600-FW1#"), ("shell", "asdfklsdjlf\n%"), ("shell", "[vrf:foo] regress@EVOvFOOBAR_RE0-re0:~$"), ("root_shell", "root@%"), @@ -30,9 +32,11 @@ "exec_w_period", "exec-mx-master-re", "exec-mx-backup-re", + "exec-srx-primary-node", "configuration_w_period", "configuration-mx-master-re", "configuration-mx-backup-re", + "configuration-srx-primary-node", "shell", "shell-re0", "root", From 031e5aca67412abcae9b879e535191930bd4ecbd Mon Sep 17 00:00:00 2001 From: Fedor Suchkov Date: Sat, 30 Nov 2024 09:12:34 -0500 Subject: [PATCH 3/3] Fix SRX unit test pattern --- .../driver/core/juniper_junos/test_juniper_junos_base_driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py b/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py index 35652290..5fc54ac8 100644 --- a/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py +++ b/tests/unit/driver/core/juniper_junos/test_juniper_junos_base_driver.py @@ -18,7 +18,7 @@ ("configuration", "rancid@router2.xyz6# "), ("configuration", "{master}[edit]\nusername@MX-960-PE1#"), ("configuration", "{backup}[edit]\nusername@MX-480-PE2#"), - ("configuration", "{primary:node0}\nusername@SRX-4600-FW1#"), + ("configuration", "{primary:node0}[edit]\nusername@SRX-4600-FW1#"), ("shell", "asdfklsdjlf\n%"), ("shell", "[vrf:foo] regress@EVOvFOOBAR_RE0-re0:~$"), ("root_shell", "root@%"),