Skip to content

Commit

Permalink
Merge pull request #966 from vnitinv/check-pending-install
Browse files Browse the repository at this point in the history
Check pending install
  • Loading branch information
Nitin Kr authored Oct 23, 2019
2 parents 4b3f693 + fd10cf7 commit 595dc70
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/jnpr/junos/utils/sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,23 @@ def _progress(report):

self.log = _progress

# ---------------------------------------------------------------------
# Before doing anything, Do check if any pending install exists.
# ---------------------------------------------------------------------
try:
pending_install = self._dev.rpc.request_package_checks_pending_install()
msg = pending_install.text
if msg and msg.strip() != '' and pending_install.getparent().findtext(
'package-result').strip() == '1':
_progress(msg)
return False
except RpcError:
_progress("request-package-check-pending-install rpc is not "
"supported on given device")
except Exception as ex:
_progress("check pending install failed with exception: %s" % ex)
# Continue with software installation

# ---------------------------------------------------------------------
# perform a 'safe-copy' of the image to the remote device
# ---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<rpc-reply>
<output>
There is already an install pending.
Use the 'request system reboot' command to complete the install,
or the 'request system software rollback' command to back it out.
</output>
<package-result>
1
</package-result>
</rpc-reply>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<rpc-reply>
<output>
</output>
<package-result>
0
</package-result>
</rpc-reply>
27 changes: 27 additions & 0 deletions tests/unit/utils/test_sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,17 @@ def test_sw_poweroff_multi_re_vc(self, mock_execute):
self.sw._multi_VC = False
self.assertTrue('Shutdown NOW' in self.sw.poweroff())

@patch('jnpr.junos.Device.execute')
def test_sw_check_pending_install(self, mock_execute):
mock_execute.side_effect = self._mock_manager
package = 'test.tgz'
self.assertFalse(self.sw.install(package))

@patch('jnpr.junos.utils.sw.SW.pkgadd')
def test_sw_check_pending_install_RpcError_continue(self, mock_pkgadd):
mock_pkgadd.return_value = True
self.assertTrue(self.sw.install('test.tgz', no_copy=True))

def _myprogress(self, dev, report):
pass

Expand Down Expand Up @@ -889,6 +900,22 @@ def _mock_manager(self, *args, **kwargs):
elif args:
if args[0].find('at') is not None:
return self._read_file('request-reboot-at.xml')
elif self._testMethodName == 'test_sw_check_pending_install':
if args[0].text == 'request-package-check-pending-install':
return self._read_file(
'request-package-check-pending-install-error.xml')
elif self._testMethodName == 'test_sw_check_pending_install_RpcError_continue':
if args[0].text == 'request-package-check-pending-install':
xml = '''<rpc-error>
<error-type>protocol</error-type>
<error-tag>operation-failed</error-tag>
<error-severity>error</error-severity>
<error-message>syntax error</error-message>
<error-info>
<bad-element>request-package-check-pendings-install</bad-element>
</error-info>
</rpc-error>'''
return RpcError(rsp=etree.fromstring(xml))
else:
return self._read_file(args[0].tag + '.xml')

Expand Down

0 comments on commit 595dc70

Please sign in to comment.