本文整理汇总了Python中utils.grep函数的典型用法代码示例。如果您正苦于以下问题:Python grep函数的具体用法?Python grep怎么用?Python grep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grep函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_del_ip_string
def test_add_del_ip_string(self):
ifname = self.ifname()
ifaddr1 = '%s/24' % (self.ifaddr())
ifaddr2 = '%s/24' % (self.ifaddr())
(self
.ndb
.interfaces
.create(ifname=ifname, kind='dummy', state='down')
.add_ip(ifaddr1)
.add_ip(ifaddr2)
.commit())
assert grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr1))
assert grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr2))
(self
.ndb
.interfaces[ifname]
.del_ip(ifaddr2)
.del_ip(ifaddr1)
.commit())
assert not grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr1))
assert not grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr2))
示例2: test_route_replace_existing
def test_route_replace_existing(self):
# route('replace', ...) should succeed, if route exists
require_user('root')
naddr = str(self.ipnets[1].network)
ifaddr1 = self.ifaddr()
ifaddr2 = self.ifaddr()
ifaddr3 = self.ifaddr()
self.ip.link('set', index=self.ifaces[0], state='up')
self.ip.addr('add', self.ifaces[0], address=ifaddr1, mask=24)
self.ip.route('replace',
dst=naddr,
mask=24,
gateway=ifaddr2,
table=100)
assert grep('ip route show table 100',
pattern='%s/24.*%s' % (naddr, ifaddr2))
self.ip.route('replace',
dst=naddr,
mask=24,
gateway=ifaddr3,
table=100)
assert not grep('ip route show table 100',
pattern='%s/24.*%s' % (naddr, ifaddr2))
assert grep('ip route show table 100',
pattern='%s/24.*%s' % (naddr, ifaddr3))
self.ip.flush_routes(table=100)
assert not grep('ip route show table 100',
pattern='%s/24.*%s' % (naddr, ifaddr3))
示例3: test_add_del_ip_dict
def test_add_del_ip_dict(self):
ifname = self.ifname()
ifaddr1 = self.ifaddr()
ifaddr2 = self.ifaddr()
(self
.ndb
.interfaces
.create(ifname=ifname, kind='dummy', state='down')
.add_ip({'address': ifaddr1, 'prefixlen': 24})
.add_ip({'address': ifaddr2, 'prefixlen': 24})
.commit())
assert grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr1))
assert grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr2))
(self
.ndb
.interfaces[ifname]
.del_ip({'address': ifaddr2, 'prefixlen': 24})
.del_ip({'address': ifaddr1, 'prefixlen': 24})
.commit())
assert not grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr1))
assert not grep('%s ip -o addr show' % self.ssh,
pattern='%s.*%s' % (ifname, ifaddr2))
示例4: test_multipath_ipv4
def test_multipath_ipv4(self):
ifname = self.ifname()
ifaddr = self.ifaddr()
hop1 = self.ifaddr()
hop2 = self.ifaddr()
(self
.ndb
.interfaces
.create(ifname=ifname, kind='dummy', state='up')
.ipaddr
.create(address=ifaddr, prefixlen=24)
.commit())
(self
.ndb
.routes
.create(**{'dst_len': 24,
'dst': str(self.ipnets[1].network),
'multipath': [{'gateway': hop1},
{'gateway': hop2}]})
.commit())
assert grep('%s ip link show' % self.ssh,
pattern=ifname)
assert grep('%s ip addr show dev %s' % (self.ssh, ifname),
pattern=ifaddr)
assert grep('%s ip route show' % self.ssh,
pattern='%s' % str(self.ipnets[1]))
assert grep('%s ip route show' % self.ssh,
pattern='nexthop.*%s.*%s' % (hop1, ifname))
assert grep('%s ip route show' % self.ssh,
pattern='nexthop.*%s.*%s' % (hop2, ifname))
示例5: test_basic
def test_basic(self):
ifaddr = self.ifaddr()
router = self.ifaddr()
ifname = self.ifname()
i = (self
.ndb
.interfaces
.create(ifname=ifname, kind='dummy', state='up'))
i.commit()
a = (self
.ndb
.addresses
.create(index=i['index'],
address=ifaddr,
prefixlen=24))
a.commit()
r = (self
.ndb
.routes
.create(dst_len=24,
dst=str(self.ipnets[1].network),
gateway=router))
r.commit()
assert grep('%s ip link show' % self.ssh,
pattern=ifname)
assert grep('%s ip addr show dev %s' % (self.ssh, ifname),
pattern=ifaddr)
assert grep('%s ip route show' % self.ssh,
pattern='%s.*%s' % (str(self.ipnets[1]), ifname))
示例6: test_veth_simple
def test_veth_simple(self):
ifname = uifname()
peername = uifname()
(self
.ndb
.interfaces
.create(ifname=ifname, peer=peername, kind='veth')
.commit())
iflink = self.ndb.interfaces[ifname]['link']
plink = self.ndb.interfaces[peername]['link']
assert iflink == self.ndb.interfaces[peername]['index']
assert plink == self.ndb.interfaces[ifname]['index']
assert grep('%s ip link show' % self.ssh, pattern=ifname)
assert grep('%s ip link show' % self.ssh, pattern=peername)
(self
.ndb
.interfaces[ifname]
.remove()
.commit())
assert not grep('%s ip link show' % self.ssh, pattern=ifname)
assert not grep('%s ip link show' % self.ssh, pattern=peername)
示例7: test_flush_routes
def test_flush_routes(self):
require_user('root')
self.ip.link('set', index=self.ifaces[0], state='up')
self.ip.addr('add', self.ifaces[0], address='172.16.0.2', mask=24)
self.ip.route('add',
prefix='172.16.1.0',
mask=24,
gateway='172.16.0.1',
table=100)
self.ip.route('add',
prefix='172.16.2.0',
mask=24,
gateway='172.16.0.1',
table=100)
assert grep('ip route show table 100',
pattern='172.16.1.0/24.*172.16.0.1')
assert grep('ip route show table 100',
pattern='172.16.2.0/24.*172.16.0.1')
self.ip.flush_routes(table=100)
assert not grep('ip route show table 100',
pattern='172.16.1.0/24.*172.16.0.1')
assert not grep('ip route show table 100',
pattern='172.16.2.0/24.*172.16.0.1')
示例8: test_route_multipath
def test_route_multipath(self):
require_user('root')
self.ip.route('add',
dst='172.16.243.0/24',
multipath=[{'gateway': '127.0.0.2'},
{'gateway': '127.0.0.3'}])
assert grep('ip route show', pattern='172.16.243.0/24')
assert grep('ip route show', pattern='nexthop.*127.0.0.2')
assert grep('ip route show', pattern='nexthop.*127.0.0.3')
self.ip.route('del', dst='172.16.243.0', mask=24)
示例9: _test_shadow
def _test_shadow(self, kind):
a = self.ip.create(ifname='bala', kind=kind).commit()
if a._mode == 'explicit':
a.begin()
a.shadow().commit()
assert 'bala' in self.ip.interfaces
assert not grep('ip link', pattern='bala')
b = self.ip.create(ifname='bala', kind=kind).commit()
assert a == b
assert grep('ip link', pattern='bala')
示例10: test_vlan_filter_add
def test_vlan_filter_add(self):
require_user('root')
(bn, bx) = self.create('bridge')
(sn, sx) = self.create('dummy')
self.ip.link('set', index=sx, master=bx)
assert not grep('bridge vlan show', pattern=' 568')
self.ip.vlan_filter('add', index=sx, vlan_info={'vid': 568})
assert grep('bridge vlan show', pattern=' 568')
self.ip.vlan_filter('del', index=sx, vlan_info={'vid': 568})
assert not grep('bridge vlan show', pattern=' 568')
示例11: test_route_multipath
def test_route_multipath(self):
require_user('root')
naddr = str(self.ipnets[1].network)
self.ip.route('add',
dst='%s/24' % naddr,
multipath=[{'gateway': '127.0.0.2'},
{'gateway': '127.0.0.3'}])
assert grep('ip route show', pattern='%s/24' % naddr)
assert grep('ip route show', pattern='nexthop.*127.0.0.2')
assert grep('ip route show', pattern='nexthop.*127.0.0.3')
self.ip.route('del', dst=naddr, mask=24)
示例12: test_simple_deps
def test_simple_deps(self):
# register NDB handler to wait for the interface
self.if_simple = uifname()
ifaddr = self.ifaddr()
router = self.ifaddr()
dst = str(self.ipnets[1].network)
#
# simple dummy interface with one address and
# one dependent route
#
(self
.interfaces
.append(self
.ndb
.interfaces
.create(ifname=self.if_simple, kind='dummy')
.set('state', 'up')
.commit()['index']))
(self
.ndb
.addresses
.create(address=ifaddr,
prefixlen=24,
index=self.interfaces[-1])
.commit())
(self
.ndb
.routes
.create(dst=dst, dst_len=24, gateway=router)
.commit())
iface = self.ndb.interfaces[self.if_simple]
# check everything is in place
assert grep('%s ip link show' % self.ssh, pattern=self.if_simple)
assert grep('%s ip route show' % self.ssh, pattern=self.if_simple)
assert grep('%s ip route show' % self.ssh,
pattern='%s.*%s' % (dst, router))
# remove the interface
iface.remove()
iface.commit()
# check there is no interface, no route
assert not grep('%s ip link show' % self.ssh, pattern=self.if_simple)
assert not grep('%s ip route show' % self.ssh, pattern=self.if_simple)
assert not grep('%s ip route show' % self.ssh,
pattern='%s.*%s' % (dst, router))
# revert the changes using the implicit last_save
iface.rollback()
assert grep('%s ip link show' % self.ssh, pattern=self.if_simple)
assert grep('%s ip route show' % self.ssh, pattern=self.if_simple)
assert grep('%s ip route show' % self.ssh,
pattern='%s.*%s' % (dst, router))
示例13: _test_shadow
def _test_shadow(self, kind):
ifA = self.get_ifname()
a = self.ip.create(ifname=ifA, kind=kind).commit()
if a._mode == 'explicit':
a.begin()
a.shadow().commit()
assert ifA in self.ip.interfaces
assert not grep('ip link', pattern=ifA)
b = self.ip.create(ifname=ifA, kind=kind).commit()
assert a == b
assert grep('ip link', pattern=ifA)
示例14: _test_shadow
def _test_shadow(self, kind):
ifA = self.get_ifname()
a = self.ip.create(ifname=ifA, kind=kind).commit()
if a._mode == "explicit":
a.begin()
a.shadow().commit()
assert ifA in self.ip.interfaces
assert not grep("ip link", pattern=ifA)
time.sleep(0.5)
b = self.ip.create(ifname=ifA, kind=kind).commit()
assert a == b
assert grep("ip link", pattern=ifA)
示例15: test_global_create
def test_global_create(self):
require_user('root')
ifA = self.get_ifname()
ifB = self.get_ifname()
self.ip.create(ifname=ifA, kind='dummy')
self.ip.create(ifname=ifB, kind='dummy')
self.ip.commit()
assert ifA in self.ip.interfaces
assert ifB in self.ip.interfaces
assert grep('ip link', pattern=ifA)
assert grep('ip link', pattern=ifB)