Skip to content

Commit

Permalink
Merge pull request #613 from vnitinv/issu-sw-install
Browse files Browse the repository at this point in the history
reboot to take a bool param all_re to decide if only connected dev to…
  • Loading branch information
vnitinv committed Oct 19, 2016
2 parents 20990ca + f25e8b4 commit b52e6dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/jnpr/junos/utils/sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def _progress(report):
# reboot - system reboot
# -------------------------------------------------------------------------

def reboot(self, in_min=0, at=None):
def reboot(self, in_min=0, at=None, all_re=True):
"""
Perform a system reboot, with optional delay (in minutes) or at
a specified date and time.
Expand All @@ -585,6 +585,9 @@ def reboot(self, in_min=0, at=None):
:param str at: date and time the reboot should take place. The
string must match the junos cli reboot syntax
:param bool all_re: In case of dual re or VC setup, function by default
will reboot all. If all is False will only reboot connected device
:returns:
* reboot message (string) if command successful
Expand All @@ -597,10 +600,11 @@ def reboot(self, in_min=0, at=None):
else:
cmd = E('request-reboot', E('at', str(at)))

if self._multi_RE is True and self._multi_VC is False:
cmd.append(E('both-routing-engines'))
elif self._mixed_VC is True:
cmd.append(E('all-members'))
if all_re is True:
if self._multi_RE is True and self._multi_VC is False:
cmd.append(E('both-routing-engines'))
elif self._mixed_VC is True:
cmd.append(E('all-members'))
try:
rsp = self.rpc(cmd)
got = rsp.getparent().findtext('.//request-reboot-status').strip()
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/utils/test_sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,15 @@ def test_sw_reboot_mixed_vc(self, mock_execute):
self.assertTrue('all-members' in
(etree.tostring(mock_execute.call_args[0][0]).decode('utf-8')))

@patch('jnpr.junos.Device.execute')
def test_sw_reboot_mixed_vc_all_re_false(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw._mixed_VC = True
self.sw._multi_VC = True
self.sw.reboot(all_re=False)
self.assertTrue('all-members' not in
(etree.tostring(mock_execute.call_args[0][0]).decode('utf-8')))

@patch('jnpr.junos.Device.execute')
def test_sw_reboot_exception(self, mock_execute):
rsp = etree.XML('<rpc-reply><a>test</a></rpc-reply>')
Expand Down

0 comments on commit b52e6dd

Please sign in to comment.