From 52aabf8e9d673fda7a3a320480088079c76a0736 Mon Sep 17 00:00:00 2001 From: zhangwenqing Date: Tue, 7 Apr 2020 14:10:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(Common)=EF=BC=9A=E4=BF=AE=E6=AD=A3"testClen?= =?UTF-8?q?tIP"=E5=8F=98=E9=87=8F=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tsg_common/LoginAndLogoutTypeSwitch.robot | 7 ++++-- .../ExtensionLibrary/mytool.py | 24 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/02-Keyword/tsg_common/LoginAndLogoutTypeSwitch.robot b/02-Keyword/tsg_common/LoginAndLogoutTypeSwitch.robot index 2300e80..05805bd 100644 --- a/02-Keyword/tsg_common/LoginAndLogoutTypeSwitch.robot +++ b/02-Keyword/tsg_common/LoginAndLogoutTypeSwitch.robot @@ -2,6 +2,7 @@ Resource ../../03-Variable/BifangApiVariable.txt Library REST http://${host}:${port} Library Collections +Library ExtensionLibrary Resource ../tsg_bfapi/LoginLogout.robot Resource ../tsg_ui/Logout/Logout.robot Resource ../tsg_ui/Login/Login.robot @@ -9,8 +10,10 @@ Resource ../tsg_ui/Login/Login.robot *** Keywords *** LoginAndAddLocalIP # 获取主机IP - #${ip} Get Host IP - #Set Global Variable ${testClentIP} ${ip} + ${ip} Get Host IP + Set Global Variable ${testClentIP} ${ip} + Should Not Be Empty ${testClentIP} + Run Keyword If '${loginType}' == 'api' ApiLoginAndAddLocalIP aa ... ELSE IF '${loginType}' == 'cli' CliLogin ... ELSE UiLoginAndAaddLocalIP bb diff --git a/04-CustomLibrary/ExtensionPackages/ExtensionLibrary/mytool.py b/04-CustomLibrary/ExtensionPackages/ExtensionLibrary/mytool.py index c399544..03de99d 100644 --- a/04-CustomLibrary/ExtensionPackages/ExtensionLibrary/mytool.py +++ b/04-CustomLibrary/ExtensionPackages/ExtensionLibrary/mytool.py @@ -6,11 +6,21 @@ class mytool(): def __init__(self): pass - def get_host_IP(self): - try: - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect(('8.8.8.8', 80)) - ip = s.getsockname()[0] - finally: - s.close() + def get_host_IP(self, flag="50"): + #try: + #s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + #s.connect(('8.8.8.8', 80)) + #ip = s.getsockname()[0] + #finally: + #s.close() + hostname = socket.gethostname() + ipTriple = socket.gethostbyname_ex(hostname) + ips = list(ipTriple[2:]) + ip = "" + for i in ips: + ipList = list(i) + for ip1 in ipList: + if "."+flag+"." in ip1: + ip = ip1 + break return ip \ No newline at end of file