Merge lp:~ensoft-opensource/ensoft-sextant/minor_bugfixes into lp:ensoft-sextant

Proposed by Patrick Stevens
Status: Merged
Approved by: ChrisD
Approved revision: 15
Merged at revision: 16
Proposed branch: lp:~ensoft-opensource/ensoft-sextant/minor_bugfixes
Merge into: lp:ensoft-sextant
Diff against target: 53 lines (+15/-6)
1 file modified
src/sextant/__main__.py (+15/-6)
To merge this branch: bzr merge lp:~ensoft-opensource/ensoft-sextant/minor_bugfixes
Reviewer Review Type Date Requested Status
ChrisD Approve
Review via email: mp+233027@code.launchpad.net

Commit message

Suppress the "Exit request sent." message SSH prints when it closes a tunnel.

Description of the change

Suppress the "Exit request sent." message SSH prints when it closes a tunnel.

To post a comment you must log in.
Revision history for this message
ChrisD (gingerchris) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sextant/__main__.py'
2--- src/sextant/__main__.py 2014-09-01 16:02:04 +0000
3+++ src/sextant/__main__.py 2014-09-02 11:05:02 +0000
4@@ -3,10 +3,11 @@
5 # Copyright 2014, Ensoft Ltd.
6 # Author: James Harkin, using work from Patrick Stevens and James Harkin
7 # -----------------------------------------
8-#invokes Sextant and argparse
9+# Invokes Sextant and argparse
10
11 from __future__ import absolute_import, print_function
12
13+import io
14 import sys
15 import random
16 import socket
17@@ -14,6 +15,7 @@
18 import logging.config
19 import argparse
20 import requests
21+import contextlib
22 import subprocess
23
24 try:
25@@ -311,16 +313,23 @@
26 cmd = ['ssh',
27 '-S', 'sextantcontroller{}'.format(local_port),
28 '-O', 'exit',
29+ '-q', # for quiet
30 remote_host]
31
32- return_code = subprocess.call(cmd)
33- if return_code == 0:
34+ # SSH has a bug on some systems which causes it to ignore the -q flag
35+ # meaning it prints "Exit request sent." to stderr.
36+ # To avoid this, we grab stderr temporarily, and see if it's that string;
37+ # if it is, suppress it.
38+ pr = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
39+ stdout, stderr = pr.communicate()
40+ if stderr.rstrip() != 'Exit request sent.':
41+ print(stderr, file=sys.stderr)
42+ if pr.returncode == 0:
43 logging.debug('Shut down successfully.')
44 else:
45 logging.warning(
46- 'SSH tunnel shutdown returned error code {}'.format(return_code))
47- logging.warning(
48- 'You may need to close sextantcontroller{} manually.'.format(local_port))
49+ 'SSH tunnel shutdown returned error code {}'.format(pr.returncode))
50+ logging.warning(stderr)
51
52
53 def _is_port_used(port):

Subscribers

People subscribed via source and target branches