diff --git a/lib/jnpr/junos/utils/sw.py b/lib/jnpr/junos/utils/sw.py
index f2d19eca6..cc3ac3c70 100644
--- a/lib/jnpr/junos/utils/sw.py
+++ b/lib/jnpr/junos/utils/sw.py
@@ -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
# ---------------------------------------------------------------------
diff --git a/tests/unit/utils/rpc-reply/request-package-check-pending-install-error.xml b/tests/unit/utils/rpc-reply/request-package-check-pending-install-error.xml
new file mode 100644
index 000000000..a743a0297
--- /dev/null
+++ b/tests/unit/utils/rpc-reply/request-package-check-pending-install-error.xml
@@ -0,0 +1,10 @@
+
+
+
+1
+
+
\ No newline at end of file
diff --git a/tests/unit/utils/rpc-reply/request-package-check-pending-install.xml b/tests/unit/utils/rpc-reply/request-package-check-pending-install.xml
new file mode 100644
index 000000000..d2e701dff
--- /dev/null
+++ b/tests/unit/utils/rpc-reply/request-package-check-pending-install.xml
@@ -0,0 +1,7 @@
+
+
+
+0
+
+
\ No newline at end of file
diff --git a/tests/unit/utils/test_sw.py b/tests/unit/utils/test_sw.py
index f91e86e8e..717a77604 100644
--- a/tests/unit/utils/test_sw.py
+++ b/tests/unit/utils/test_sw.py
@@ -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
@@ -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 = '''
+ protocol
+ operation-failed
+ error
+ syntax error
+
+ request-package-check-pendings-install
+
+ '''
+ return RpcError(rsp=etree.fromstring(xml))
else:
return self._read_file(args[0].tag + '.xml')