Repository: Juniper/py-junos-eznc

Issue:
wrong device version when fetching pyez facts for nfx250ha-c
Hi,
The pyez version info received for this particular device:nfx250ha-c for is coming wrong.

{'2RE': False, 'HOME': '/var/home/regress', 'RE0': {'status': 'OK', 'up_time': '10 hours, 35 minutes, 48 seconds', 'mastership_state': 'master', 'model': 'RE-NFX250-S2', 'last_reboot_reason': '0x1:power cycle/failure'}, 'RE1': None, 'RE_hw_mi': True, 'current_re': ['master', 'fpc0', 'node', 'fwdd', 'member', 'pfem', 're0', 'fpc0.pic0'], 'domain': 'englab.juniper.net', 'fqdn': None, 'hostname': None, 'hostname_info': {'node0': 'nfx250ha-c', 'node1': 'nfx250ha-d'}, 'ifd_style': 'CLASSIC', 'junos_info': {'node0': {'text': '20.2I-20200427.0.0631', 'object': junos.version_info(major=(20, 2), type=I, minor=-20200427, build=0)}, 'node1': {'text': '20.2I-20200427.0.0631', 'object': junos.version_info(major=(20, 2), type=I, minor=-20200427, build=0)}}, 'master': 'RE0', 'model': None, 'model_info': {'node0': 'NFX250_S2_10_T', 'node1': 'NFX250_S2_10_T'}, 'personality': None, 're_info': {'node0': {'0': {'status': 'OK', 'mastership_state': 'master', 'model': 'RE-NFX250-S2', 'last_reboot_reason': '0x1:power cycle/failure'}, 'default': {'status': 'OK', 'mastership_state': 'master', 'model': 'RE-NFX250-S2', 'last_reboot_reason': '0x1:power cycle/failure'}}, 'default': {'0': {'status': 'OK', 'mastership_state': 'master', 'model': 'RE-NFX250-S2', 'last_reboot_reason': '0x1:power cycle/failure'}, 'default': {'status': 'OK', 'mastership_state': 'master', 'model': 'RE-NFX250-S2', 'last_reboot_reason': '0x1:power cycle/failure'}}}, 're_master': {'node0': '0', 'default': '0'}, 'serialnumber': 'DD1917AF0016', 'srx_cluster': True, 'srx_cluster_id': '255', 'srx_cluster_redundancy_group': {'0': {'cluster_id': '255', 'node0': {'status': 'primary', 'failover_mode': 'no', 'priority': '1', 'preempt': 'no'}, 'failover_count': '1', 'node1': {'status': 'disabled', 'failover_mode': 'no', 'priority': '1', 'preempt': 'no'}}}, 'switch_style': 'VLAN_L2NG', 'vc_capable': False, 'vc_fabric': None, 'vc_master': None, 'vc_mode': None, '**_version': '0.0I0.0_**', 'version_RE0': '20.2I-20200427.0.0631', 'version_RE1': '20.2I-20200427.0.0631', 'version_info': junos.version_info(major=(0, 0), type=I, minor=0, build=0), 'virtual': None}. 

Here the version seems to be incorrect 0.0I0.0, as the right version is 20.3I. 


Discussion:

Patch:
diff --git a/lib/jnpr/junos/facts/current_re.py b/lib/jnpr/junos/facts/current_re.py
index c32ec3d1..e59b7a59 100644
--- a/lib/jnpr/junos/facts/current_re.py
+++ b/lib/jnpr/junos/facts/current_re.py
@@ -64,7 +64,7 @@ def get_facts(device):
                                 octets = ip.split(".", 3)
                                 # The 2nd octet will be cluster-id << 4
                                 cluster_id_octet = str(
-                                    int(device.facts["srx_cluster_id"]) << 4
+                                    (int(device.facts["srx_cluster_id"]) & 0x000F) << 4
                                 )
                                 # node0 will have an IP of
                                 #     129.<cluster_id_octet>.0.1


Test patch:
diff --git a/tests/unit/facts/test_current_re.py b/tests/unit/facts/test_current_re.py
index 1a112376..52d10a6b 100644
--- a/tests/unit/facts/test_current_re.py
+++ b/tests/unit/facts/test_current_re.py
@@ -43,6 +43,18 @@ class TestCurrentRe(unittest.TestCase):
         self.dev.facts._cache["srx_cluster_id"] = "15"
         self.assertEqual(self.dev.facts["current_re"], ["node0", "primary"])
 
+    @patch("jnpr.junos.Device.execute")
+    def test_current_re_fact_srx_cluster_primary_id_255(self, mock_execute):
+        mock_execute.side_effect = self._mock_manager_current_re_srx_primary
+        self.dev.facts._cache["srx_cluster_id"] = "255"
+        self.assertEqual(self.dev.facts["current_re"], ["node0", "primary"])
+
+    @patch("jnpr.junos.Device.execute")
+    def test_current_re_fact_srx_cluster_primary_id_31(self, mock_execute):
+        mock_execute.side_effect = self._mock_manager_current_re_srx_primary
+        self.dev.facts._cache["srx_cluster_id"] = "31"
+        self.assertEqual(self.dev.facts["current_re"], ["node0", "primary"])
+
     @patch("jnpr.junos.Device.execute")
     def test_current_re_fact_srx_cluster_secondary(self, mock_execute):
         mock_execute.side_effect = self._mock_manager_current_re_srx_secondary