未验证 提交 68223077 编写于 作者: 1 123malin 提交者: GitHub

test=develop, rm netifaces (#27581)

* test=develop, rm netifaces
上级 9704582e
...@@ -253,26 +253,33 @@ class Gloo(object): ...@@ -253,26 +253,33 @@ class Gloo(object):
""" """
get default physical interface get default physical interface
""" """
import netifaces res = os.popen("route -A inet").read().strip().split("\n")
gateways = netifaces.gateways()
if gateways.get(netifaces.AF_INET) != None: gateway_idx = None
gateway = gateways[netifaces.AF_INET] iface_idx = None
if len(gateway) > 0 and len(gateway[0]) > 1: for item in res:
return gateway[0][1] item = item.split()
if "Gateway" in item and "Iface" in item:
gateway_idx = item.index("Gateway")
iface_idx = item.index("Iface")
elif gateway_idx != None and iface_idx != None:
gateway = None
if len(item) > gateway_idx:
gateway = item[gateway_idx]
if gateway and gateway != '*' and gateway != "0.0.0.0" and len(
item) > iface_idx:
return item[iface_idx]
return "lo" return "lo"
def __get_default_iface_from_interfaces(self): def __get_default_iface_from_interfaces(self):
""" """
get default physical interface get default physical interface
""" """
import netifaces res = os.popen("ip -f inet addr | awk NR%3==1").read().strip().split(
for intf_name in netifaces.interfaces(): "\n")
addresses = netifaces.ifaddresses(intf_name) for item in res:
if netifaces.AF_INET in addresses: if "BROADCAST" in item:
ipv4_addresses = addresses[netifaces.AF_INET] return item.split(":")[1].strip()
for ipv4_address in ipv4_addresses:
if 'broadcast' in ipv4_address:
return intf_name
return "lo" return "lo"
def barrier(self, comm_world): def barrier(self, comm_world):
......
...@@ -955,26 +955,33 @@ class GeneralRoleMaker(RoleMakerBase): ...@@ -955,26 +955,33 @@ class GeneralRoleMaker(RoleMakerBase):
""" """
get default physical interface get default physical interface
""" """
import netifaces res = os.popen("route -A inet").read().strip().split("\n")
gateways = netifaces.gateways()
if gateways.get(netifaces.AF_INET) != None: gateway_idx = None
gateway = gateways[netifaces.AF_INET] iface_idx = None
if len(gateway) > 0 and len(gateway[0]) > 1: for item in res:
return gateway[0][1] item = item.split()
if "Gateway" in item and "Iface" in item:
gateway_idx = item.index("Gateway")
iface_idx = item.index("Iface")
elif gateway_idx != None and iface_idx != None:
gateway = None
if len(item) > gateway_idx:
gateway = item[gateway_idx]
if gateway and gateway != '*' and gateway != "0.0.0.0" and len(
item) > iface_idx:
return item[iface_idx]
return "lo" return "lo"
def __get_default_iface_from_interfaces(self): def __get_default_iface_from_interfaces(self):
""" """
get default physical interface get default physical interface
""" """
import netifaces res = os.popen("ip -f inet addr | awk NR%3==1").read().strip().split(
for intf_name in netifaces.interfaces(): "\n")
addresses = netifaces.ifaddresses(intf_name) for item in res:
if netifaces.AF_INET in addresses: if "BROADCAST" in item:
ipv4_addresses = addresses[netifaces.AF_INET] return item.split(":")[1].strip()
for ipv4_address in ipv4_addresses:
if 'broadcast' in ipv4_address:
return intf_name
return "lo" return "lo"
def __start_kv_server(self, http_server_d, size_d): def __start_kv_server(self, http_server_d, size_d):
......
...@@ -37,11 +37,7 @@ class TestFleet1(unittest.TestCase): ...@@ -37,11 +37,7 @@ class TestFleet1(unittest.TestCase):
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib
from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker
try:
import netifaces
except:
print("warning: no netifaces, skip test_pslib_1")
return
os.environ["POD_IP"] = "127.0.0.1" os.environ["POD_IP"] = "127.0.0.1"
os.environ["PADDLE_PORT"] = "36001" os.environ["PADDLE_PORT"] = "36001"
os.environ["TRAINING_ROLE"] = "TRAINER" os.environ["TRAINING_ROLE"] = "TRAINER"
......
...@@ -36,11 +36,7 @@ class TestFleet1(unittest.TestCase): ...@@ -36,11 +36,7 @@ class TestFleet1(unittest.TestCase):
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib
from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker
try:
import netifaces
except:
print("warning: no netifaces, skip test_pslib_1")
return
os.environ["POD_IP"] = "127.0.0.1" os.environ["POD_IP"] = "127.0.0.1"
os.environ["PADDLE_PORT"] = "36001" os.environ["PADDLE_PORT"] = "36001"
os.environ["TRAINING_ROLE"] = "TRAINER" os.environ["TRAINING_ROLE"] = "TRAINER"
......
...@@ -64,11 +64,7 @@ class TestCloudRoleMaker(unittest.TestCase): ...@@ -64,11 +64,7 @@ class TestCloudRoleMaker(unittest.TestCase):
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib
from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker
try:
import netifaces
except:
print("warning: no netifaces, skip test_pslib_1")
return
os.environ["POD_IP"] = "127.0.0.1" os.environ["POD_IP"] = "127.0.0.1"
os.environ["PADDLE_PORT"] = "36001" os.environ["PADDLE_PORT"] = "36001"
os.environ["TRAINING_ROLE"] = "TRAINER" os.environ["TRAINING_ROLE"] = "TRAINER"
......
...@@ -36,11 +36,7 @@ class TestCloudRoleMaker2(unittest.TestCase): ...@@ -36,11 +36,7 @@ class TestCloudRoleMaker2(unittest.TestCase):
from paddle.fluid.incubate.fleet.parameter_server.distribute_transpiler import fleet from paddle.fluid.incubate.fleet.parameter_server.distribute_transpiler import fleet
from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker
from paddle.fluid.incubate.fleet.base.role_maker import RoleMakerBase from paddle.fluid.incubate.fleet.base.role_maker import RoleMakerBase
try:
import netifaces
except:
print("warning: no netifaces, skip test_pslib_2")
return
os.environ["POD_IP"] = "127.0.0.1" os.environ["POD_IP"] = "127.0.0.1"
os.environ["PADDLE_PORT"] = "36001" os.environ["PADDLE_PORT"] = "36001"
os.environ["TRAINING_ROLE"] = "TRAINER" os.environ["TRAINING_ROLE"] = "TRAINER"
......
...@@ -36,11 +36,7 @@ class TestCloudRoleMaker(unittest.TestCase): ...@@ -36,11 +36,7 @@ class TestCloudRoleMaker(unittest.TestCase):
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib
from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker
try:
import netifaces
except:
print("warning: no netifaces, skip test_pslib_1")
return
os.environ["POD_IP"] = "127.0.0.1" os.environ["POD_IP"] = "127.0.0.1"
os.environ["PADDLE_PORT"] = "36001" os.environ["PADDLE_PORT"] = "36001"
os.environ["TRAINING_ROLE"] = "TRAINER" os.environ["TRAINING_ROLE"] = "TRAINER"
......
...@@ -47,12 +47,6 @@ class TestCloudRoleMaker(unittest.TestCase): ...@@ -47,12 +47,6 @@ class TestCloudRoleMaker(unittest.TestCase):
print("warning: no fleet, skip test_pslib_4") print("warning: no fleet, skip test_pslib_4")
return return
try:
import netifaces
except:
print("warning: no netifaces, skip test_pslib_4")
return
class FakeStream(): class FakeStream():
""" """
it is a fake stream only for test. it is a fake stream only for test.
......
...@@ -70,12 +70,6 @@ class TestCloudRoleMaker(unittest.TestCase): ...@@ -70,12 +70,6 @@ class TestCloudRoleMaker(unittest.TestCase):
os.environ["TRAINING_ROLE"] = "TRAINER" os.environ["TRAINING_ROLE"] = "TRAINER"
os.environ["PADDLE_TRAINER_ID"] = "0" os.environ["PADDLE_TRAINER_ID"] = "0"
try:
import netifaces
except:
print("warning: no netifaces, skip test_tr_rolemaker")
return
ro = role_maker.PaddleCloudRoleMaker(is_collective=False) ro = role_maker.PaddleCloudRoleMaker(is_collective=False)
self.assertTrue(ro._is_worker()) self.assertTrue(ro._is_worker())
ro = role_maker.PaddleCloudRoleMaker(is_collective=False) ro = role_maker.PaddleCloudRoleMaker(is_collective=False)
...@@ -110,12 +104,6 @@ class TestCloudRoleMaker(unittest.TestCase): ...@@ -110,12 +104,6 @@ class TestCloudRoleMaker(unittest.TestCase):
os.environ["POD_IP"] = "127.0.0.1" os.environ["POD_IP"] = "127.0.0.1"
os.environ["PADDLE_PORT"] = "36001" os.environ["PADDLE_PORT"] = "36001"
try:
import netifaces
except:
print("warning: no netifaces, skip test_ps_rolemaker")
return
ro = role_maker.PaddleCloudRoleMaker( ro = role_maker.PaddleCloudRoleMaker(
is_collective=False, init_gloo=False) is_collective=False, init_gloo=False)
self.assertEqual(ro._server_index(), 0) self.assertEqual(ro._server_index(), 0)
...@@ -131,11 +119,6 @@ class TestCloudRoleMaker(unittest.TestCase): ...@@ -131,11 +119,6 @@ class TestCloudRoleMaker(unittest.TestCase):
def test_traing_role(self): def test_traing_role(self):
"""Test training role.""" """Test training role."""
os.environ["TRAINING_ROLE"] = "TEST" os.environ["TRAINING_ROLE"] = "TEST"
try:
import netifaces
except:
print("warning: no netifaces, skip test_training_role")
return
ro = role_maker.PaddleCloudRoleMaker(is_collective=False) ro = role_maker.PaddleCloudRoleMaker(is_collective=False)
self.assertRaises(ValueError, ro._generate_role) self.assertRaises(ValueError, ro._generate_role)
...@@ -150,11 +133,6 @@ class TestUserDefinedRoleMaker(unittest.TestCase): ...@@ -150,11 +133,6 @@ class TestUserDefinedRoleMaker(unittest.TestCase):
pass pass
def test_ps_rolemaker(self): def test_ps_rolemaker(self):
try:
import netifaces
except:
print("warning: no netifaces, skip test_ps_rolemaker")
return
ro = role_maker.UserDefinedRoleMaker( ro = role_maker.UserDefinedRoleMaker(
is_collective=False, is_collective=False,
...@@ -169,12 +147,6 @@ class TestUserDefinedRoleMaker(unittest.TestCase): ...@@ -169,12 +147,6 @@ class TestUserDefinedRoleMaker(unittest.TestCase):
self.assertEqual(ro._role_id(), 0) self.assertEqual(ro._role_id(), 0)
def test_tr_rolemaker(self): def test_tr_rolemaker(self):
try:
import netifaces
except:
print("warning: no netifaces, skip test_tr_rolemaker")
return
ro = role_maker.UserDefinedRoleMaker( ro = role_maker.UserDefinedRoleMaker(
is_collective=False, is_collective=False,
init_gloo=False, init_gloo=False,
......
...@@ -36,11 +36,7 @@ class TestFleet1(unittest.TestCase): ...@@ -36,11 +36,7 @@ class TestFleet1(unittest.TestCase):
from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet from paddle.fluid.incubate.fleet.parameter_server.pslib import fleet
from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib from paddle.fluid.incubate.fleet.parameter_server.pslib import PSLib
from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker from paddle.fluid.incubate.fleet.base.role_maker import GeneralRoleMaker
try:
import netifaces
except:
print("warning: no netifaces, skip test_pslib_1")
return
os.environ["POD_IP"] = "127.0.0.1" os.environ["POD_IP"] = "127.0.0.1"
os.environ["PADDLE_PORT"] = "36001" os.environ["PADDLE_PORT"] = "36001"
os.environ["TRAINING_ROLE"] = "TRAINER" os.environ["TRAINING_ROLE"] = "TRAINER"
......
...@@ -100,11 +100,6 @@ class TestFleetUtil(unittest.TestCase): ...@@ -100,11 +100,6 @@ class TestFleetUtil(unittest.TestCase):
def test_get_file_shard(self): def test_get_file_shard(self):
import paddle.distributed.fleet as fleet import paddle.distributed.fleet as fleet
self.assertRaises(Exception, fleet.util.get_file_shard, "files") self.assertRaises(Exception, fleet.util.get_file_shard, "files")
try:
import netifaces
except:
print("warning: no netifaces, skip test_get_file_shard")
return
role = role_maker.UserDefinedRoleMaker( role = role_maker.UserDefinedRoleMaker(
is_collective=False, is_collective=False,
......
...@@ -17,5 +17,3 @@ decorator ...@@ -17,5 +17,3 @@ decorator
prettytable prettytable
astor astor
pathlib pathlib
netifaces ; platform_system != "Windows"
netifaces ; python_version>="3.5" and platform_system == "Windows"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册