Skip to content

Commit

Permalink
Interface: handle BSDs
Browse files Browse the repository at this point in the history
  • Loading branch information
philpep committed Apr 5, 2015
1 parent 5dce243 commit 8111c5f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions testinfra/modules/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def __init__(self, name):
def exists(self):
raise NotImplementedError

@property
def speed(self):
raise NotImplementedError

@property
def addresses(self):
raise NotImplementedError

def __repr__(self):
return "<interface %s>" % (self.name,)

Expand All @@ -40,6 +48,8 @@ def as_fixture(cls):
def f(SystemInfo):
if SystemInfo.type == "linux":
return LinuxInterface
elif SystemInfo.type.endswith("bsd"):
return BSDInterface
else:
raise NotImplementedError
f.__doc__ = cls.__doc__
Expand All @@ -66,3 +76,24 @@ def addresses(self):
if splitted and splitted[0] in ("inet", "inet6"):
addrs.append(splitted[1].split("/", 1)[0])
return addrs


class BSDInterface(Interface):

@property
def exists(self):
return self.run_test("ifconfig %s", self.name).rc == 0

@property
def addresses(self):
stdout = self.check_output("ifconfig %s", self.name)
addrs = []
for line in stdout.splitlines():
if line.startswith("\tinet "):
addrs.append(line.split(" ", 2)[1])
elif line.startswith("\tinet6 "):
addr = line.split(" ", 2)[1]
if "%" in addr:
addr = addr.split("%", 1)[0]
addrs.append(addr)
return addrs

0 comments on commit 8111c5f

Please sign in to comment.