Commit 27a27263 authored by zhifan huang's avatar zhifan huang Committed by Xiaowu Zhang

test: fix nemu device name too long

nemu use "%.4x%.3x" % (os.getpid(), n) to generate device name, but it
define the min length not the max length, when pid is high, this will
exceed 16 bytes IFNAMSIZ
parent 6d4a6671
...@@ -20,6 +20,8 @@ import re ...@@ -20,6 +20,8 @@ import re
from new import function from new import function
from nemu.iproute import backticks, get_if_data, route, \ from nemu.iproute import backticks, get_if_data, route, \
get_addr_data, get_all_route_data, interface get_addr_data, get_all_route_data, interface
from nemu.interface import Switch, Interface
import os
def _get_all_route_data(): def _get_all_route_data():
ipdata = backticks([IP_PATH, "-o", "route", "list"]) # "table", "all" ipdata = backticks([IP_PATH, "-o", "route", "list"]) # "table", "all"
...@@ -69,3 +71,18 @@ def _get_addr_data(): ...@@ -69,3 +71,18 @@ def _get_addr_data():
byidx, bynam = get_addr_data.orig() byidx, bynam = get_addr_data.orig()
return byidx, {name.split('@',1)[0]: a for name, a in bynam.iteritems()} return byidx, {name.split('@',1)[0]: a for name, a in bynam.iteritems()}
get_addr_data.func_code = _get_addr_data.func_code get_addr_data.func_code = _get_addr_data.func_code
@staticmethod
def _gen_if_name():
n = Interface._gen_next_id()
# Max 15 chars
return "NETNSif-" + ("%.4x%.3x" % (os.getpid(), n))[-7:]
Interface._gen_if_name = _gen_if_name
@staticmethod
def _gen_br_name():
n = Switch._gen_next_id()
# Max 15 chars
return "NETNSbr-" + ("%.4x%.3x" % (os.getpid(), n))[-7:]
Switch._gen_br_name = _gen_br_name
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment