Skip to content

Commit

Permalink
Merge pull request #1248 from chidanandpujar/ex_member_id_fix1
Browse files Browse the repository at this point in the history
Fix for ansible  issue 613 to support member_id
  • Loading branch information
dineshbaburam91 authored Aug 2, 2023
2 parents a106028 + 4197431 commit e19a768
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
65 changes: 62 additions & 3 deletions lib/jnpr/junos/utils/sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def __init__(self, dev):
and dev.facts.get("vc_capable") is True
and dev.facts.get("vc_mode") != "Disabled"
)
self._multi_VC_nsync = bool(
self._multi_RE is False
and dev.facts.get("vc_capable") is True
and dev.facts.get("vc_mode") != "Disabled"
)
self._mixed_VC = bool(dev.facts.get("vc_mode") == "Mixed")
# The devices which currently support single-RE ISSU, communicate with
# the new Junos VM using internal IP 128.0.0.63.
Expand Down Expand Up @@ -702,6 +707,7 @@ def install(
checksum_algorithm="md5",
force_copy=False,
all_re=True,
member_id=None,
vmhost=False,
**kwargs
):
Expand Down Expand Up @@ -985,6 +991,29 @@ def _progress(report):
elif nssu is True:
_progress("NSSU: installing software ... please be patient ...")
return self.pkgaddNSSU(remote_package, dev_timeout=timeout, **kwargs)
elif member_id is not None:
ok = True, ""
if self._multi_VC_nsync is True or self._multi_VC is True:
vc_members = [
re.search(r"(\d+)", x).group(1)
for x in self._RE_list
if re.search(r"(\d+)", x)
]
for vc_id in vc_members:
if vc_id in member_id:
_progress(
"installing software on VC member: {} ... please "
"be patient ...".format(vc_id)
)
bool_ret, msg = self.pkgadd(
remote_package,
vmhost=vmhost,
member=vc_id,
dev_timeout=timeout,
**kwargs
)
ok = ok[0] and bool_ret, ok[1] + "\n" + msg
return ok
elif self._multi_RE is False or all_re is False:
# simple case of single RE upgrade.
_progress("installing software ... please be patient ...")
Expand Down Expand Up @@ -1046,7 +1075,14 @@ def _progress(report):
return add_ok

def _system_operation(
self, cmd, in_min=0, at=None, all_re=True, other_re=False, vmhost=False
self,
cmd,
in_min=0,
at=None,
all_re=True,
other_re=False,
vmhost=False,
member_id=None,
):
"""
Send the rpc for actions like shutdown, reboot, halt with optional
Expand All @@ -1071,6 +1107,10 @@ def _system_operation(
(Optional) A boolean indicating to run 'request vmhost reboot'.
The default is ``vmhost=False``.
:param list member_id:
(optional) install software on the specified members ids of VC.
The default is ``member_id=None``.
:returns:
* rpc response message (string) if command successful
Expand All @@ -1086,6 +1126,12 @@ def _system_operation(
cmd.append(E("both-routing-engines"))
elif self._mixed_VC is True:
cmd.append(E("all-members"))
elif (
self._multi_VC_nsync is True
or self._multi_VC is True
and member_id is not None
):
cmd.append(E("member", str(member_id)))
if in_min >= 0 and at is None:
cmd.append(E("in", str(in_min)))
elif at is not None:
Expand Down Expand Up @@ -1117,7 +1163,14 @@ def _system_operation(
# reboot - system reboot
# -------------------------------------------------------------------------
def reboot(
self, in_min=0, at=None, all_re=True, on_node=None, vmhost=False, other_re=False
self,
in_min=0,
at=None,
all_re=True,
on_node=None,
vmhost=False,
other_re=False,
member_id=None,
):
"""
Perform a system reboot, with optional delay (in minutes) or at
Expand Down Expand Up @@ -1145,6 +1198,10 @@ def reboot(
:param str other_re: If the system has dual Routing Engines and this option is C(true),
then the action is performed on the other REs in the system.
:param list member_id:
(optional) install software on the specified members ids of VC.
The default is ``member_id=None``.
:returns:
* reboot message (string) if command successful
"""
Expand All @@ -1160,7 +1217,9 @@ def reboot(
cmd = E("request-reboot")

try:
return self._system_operation(cmd, in_min, at, all_re, other_re, vmhost)
return self._system_operation(
cmd, in_min, at, all_re, other_re, vmhost, member_id
)
except RpcTimeoutError as err:
raise err
except Exception as err:
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/utils/test_sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,22 @@ def test_sw_install_multi_vc(self, mock_pkgadd):
self.sw._RE_list = ("version_RE0", "version_RE1")
self.assertTrue(self.sw.install("file", no_copy=True)[0])

@patch("jnpr.junos.utils.sw.SW.pkgadd")
def test_sw_install_multi_vc_member_id(self, mock_pkgadd):
mock_pkgadd.return_value = True, "msg"
self.sw._multi_RE = True
self.sw._multi_VC = True
self.sw._RE_list = ("version_RE0", "version_RE1")
self.assertTrue(self.sw.install("file", member_id=['1'], no_copy=True)[0])

@patch("jnpr.junos.utils.sw.SW.pkgadd")
def test_sw_install_multi_vc_multiple_member_id(self, mock_pkgadd):
mock_pkgadd.return_value = True, "msg"
self.sw._multi_RE = False
self.sw._multi_VC_nsync = True
self.sw._RE_list = ("version_RE0", "version_RE1")
self.assertTrue(self.sw.install("file", member_id=['0','1'], no_copy=True)[0])

@patch("jnpr.junos.utils.sw.SW.pkgadd")
def test_sw_install_mixed_vc(self, mock_pkgadd):
mock_pkgadd.return_value = True
Expand Down

0 comments on commit e19a768

Please sign in to comment.