Skip to content

Commit

Permalink
Merge pull request #1066 from rahkumar651991/rpc_reply_reboot
Browse files Browse the repository at this point in the history
Output in rpc-reply for reboot parsing changes
  • Loading branch information
Nitin Kr committed Aug 6, 2020
2 parents 3d0ebcf + 8be9920 commit b0fb992
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/jnpr/junos/utils/sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,11 @@ def _system_operation(
# REs produces <output> messages and
# <request-reboot-status> messages.
output_msg = "\n".join(
[i.text for i in rsp.xpath("//output") if i.text is not None]
[
i.text
for i in rsp.getparent().xpath("//output")
if i.text is not None
]
)
if output_msg is not "":
got = output_msg
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/utils/rpc-reply/request-reboot-output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<rpc-reply>
<output>
Initiating vmhost reboot...
</output>
<rpc-error>
<error-severity>warning</error-severity>
<error-message>
Rebooting re0 in 1 min
</error-message>
</rpc-error>
<rpc-error>
<error-severity>warning</error-severity>
<error-message>
Initiating Junos shutdown...
</error-message>
</rpc-error>
<output>
shutdown: [pid 13192]
Shutdown at Thu Aug 6 09:27:13 2020.
</output>
</rpc-reply>
10 changes: 9 additions & 1 deletion tests/unit/utils/test_sw.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,12 @@ def test_sw_reboot(self, mock_execute):
self.sw._multi_MX = True
self.assertTrue("Shutdown NOW" in self.sw.reboot())

@patch("jnpr.junos.Device.execute")
def test_sw_reboot_output_in_reply(self, mock_execute):
mock_execute.side_effect = self._mock_manager
self.sw._multi_MX = True
self.assertTrue("shutdown: [pid 13192]" in self.sw.reboot())

@patch("jnpr.junos.Device.execute")
def test_sw_reboot_at(self, mock_execute):
mock_execute.side_effect = self._mock_manager
Expand Down Expand Up @@ -1001,7 +1007,9 @@ def _mock_manager(self, *args, **kwargs):
session = SSHSession(device_handler)
return Manager(session, device_handler)
elif args:
if args[0].find("at") is not None:
if self._testMethodName == "test_sw_reboot_output_in_reply":
return self._read_file("request-reboot-output.xml")
elif 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":
Expand Down

0 comments on commit b0fb992

Please sign in to comment.