From: Thierry Parmentelat Date: Mon, 3 Mar 2008 07:50:54 +0000 (+0000) Subject: check locality more appropriately X-Git-Tag: tests-4.2-4~220 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=69f11b3ec62477fde6291df69ab3ef7fb10ae5b9;p=tests.git check locality more appropriately --- diff --git a/system/TestBox.py b/system/TestBox.py index 63300ed..e5c3e48 100644 --- a/system/TestBox.py +++ b/system/TestBox.py @@ -9,8 +9,11 @@ class TestBox: self.hostname=hostname self.key=key + def is_local(self): + return utils.is_local (self.hostname) + def run (self,command): - if self.hostname == "localhost": + if self.is_local(): return utils.system(command) else: if self.key: @@ -22,7 +25,7 @@ class TestBox: return utils.system(to_run) def copy (self,local_file): - if self.hostname == "localhost": + if self.is_local(): return 0 else: if self.key: diff --git a/system/utils.py b/system/utils.py index a30b004..b246b18 100644 --- a/system/utils.py +++ b/system/utils.py @@ -125,3 +125,11 @@ def backslash_shell_specials (command): result +=char return result +# check main IP address against the provided hostname +def is_local (hostname): + if hostname == "localhost": + return True + import socket + local_ip = socket.gethostbyname(socket.gethostname()) + remote_ip = socket.gethostbyname(hostname) + return local_ip==remote_ip