Skip to content

Commit

Permalink
Merge pull request #53 from tcezard/EVA3403_check_port_fw
Browse files Browse the repository at this point in the history
EVA-3403 Check port forwarding is running
  • Loading branch information
apriltuesday authored Apr 2, 2024
2 parents 5501f54 + 8e6100f commit f64793f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ebi_eva_common_pyutils/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import time

import requests
import subprocess
Expand Down Expand Up @@ -43,6 +43,13 @@ def forward_remote_port_to_local_port(remote_host: str, remote_port: int, local_
port_forward_command = 'ssh -N -L{0}:localhost:{1} {2}'.format(local_port, remote_port, remote_host)
logger.info("Forwarding port to local port using command: " + port_forward_command)
proc = subprocess.Popen(port_forward_command.split(" "))
time.sleep(5)
# Ensure that the process is still running
poll = proc.poll()
if poll is not None:
# The process already completed which mean it most likely crashed
logger.error(f'Port Forwarding {remote_host}:{remote_port} -> {local_port} failed!')
raise subprocess.CalledProcessError(proc.returncode, proc.args)
return proc.pid


Expand Down

0 comments on commit f64793f

Please sign in to comment.