nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: napalm-automation/napalm
Pull request #1925 (2023-05-19 16:52:01)

Fixing IOS-XR with no BGP configured (xml agent)


Patch:
diff --git a/napalm/iosxr/iosxr.py b/napalm/iosxr/iosxr.py
index 2ef1f6cb..383e8ae0 100644
--- a/napalm/iosxr/iosxr.py
+++ b/napalm/iosxr/iosxr.py
@@ -987,6 +987,13 @@ class IOSXRDriver(NetworkDriver):
         <InstanceName>default</InstanceName></Naming></Instance></BGP></Configuration></Get>"
         result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))
 
+        # Check if BGP is not configured.
+        get_tag = result_tree.find("./Get")
+        if get_tag is not None:
+            bgp_not_found = get_tag.attrib.get("ItemNotFound")
+            if bgp_not_found:
+                return {}
+
         bgp_asn = napalm.base.helpers.convert(
             int,
             napalm.base.helpers.find_txt(


Test patch:
diff --git a/test/iosxr/mocked_data/test_get_bgp_config/no_bgp/_Get__Configuration__BGP__Instance__Naming__________InstanceName_default__InstanceName___Naming___Instance___BGP___Configuration___Get_.txt b/test/iosxr/mocked_data/test_get_bgp_config/no_bgp/_Get__Configuration__BGP__Instance__Naming__________InstanceName_default__InstanceName___Naming___Instance___BGP___Configuration___Get_.txt
new file mode 100644
index 00000000..1bcd305b
--- /dev/null
+++ b/test/iosxr/mocked_data/test_get_bgp_config/no_bgp/_Get__Configuration__BGP__Instance__Naming__________InstanceName_default__InstanceName___Naming___Instance___BGP___Configuration___Get_.txt
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Response MajorVersion="1" MinorVersion="0"><Get ItemNotFound="true"><Configuration><BGP MajorVersion="40" MinorVersion="9"><Instance NotFound="true"><Naming><InstanceName>default</InstanceName></Naming></Instance></BGP></Configuration></Get><ResultSummary ErrorCount="0" ItemNotFound="true"/></Response>
diff --git a/test/iosxr/mocked_data/test_get_bgp_config/no_bgp/expected_result.json b/test/iosxr/mocked_data/test_get_bgp_config/no_bgp/expected_result.json
new file mode 100644
index 00000000..0967ef42
--- /dev/null
+++ b/test/iosxr/mocked_data/test_get_bgp_config/no_bgp/expected_result.json
@@ -0,0 +1,1 @@
+{}