Skip to content

Commit 86a7780

Browse files
committed
Several fixes by Python linters
1 parent ed4bed9 commit 86a7780

File tree

6 files changed

+565
-466
lines changed

6 files changed

+565
-466
lines changed

nets/3routers/ospf3r.py

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
#!/usr/bin/python
22

3+
# pylint: disable=missing-module-docstring
4+
# pylint: disable=missing-function-docstring
5+
# pylint: disable=missing-class-docstring
6+
37
import os
48

59
import shutil
6-
from mininet.topo import Topo
10+
# from mininet.topo import Topo
711
from mininet.node import Host
812
from mininet.net import Mininet
913
from mininet.cli import CLI
1014
from mininet.util import dumpNodeConnections
1115
from mininet.link import Link
1216
from mininet.log import setLogLevel
1317

14-
#BASEDIR = "/home/user/mytests/ospf3routers/nodeconf/"
18+
# BASEDIR = "/home/user/mytests/ospf3routers/nodeconf/"
1519
BASEDIR = os.getcwd()+"/nodeconf/"
1620
OUTPUT_PID_TABLE_FILE = "/tmp/pid_table_file.txt"
1721

1822
PRIVDIR = '/var/priv'
1923

24+
2025
class BaseNode(Host):
2126

2227
def __init__(self, name, *args, **kwargs):
@@ -25,27 +30,29 @@ def __init__(self, name, *args, **kwargs):
2530
self.dir = "/tmp/%s" % name
2631
self.nets = []
2732
if not os.path.exists(self.dir):
28-
os.makedirs(self.dir)
33+
os.makedirs(self.dir)
2934

3035
def config(self, **kwargs):
36+
# pylint: disable=arguments-differ
37+
3138
# Init steps
3239
Host.config(self, **kwargs)
3340
# Iterate over the interfaces
34-
first = True
41+
# first = True
3542
for intf in self.intfs.values():
3643
# Remove any configured address
37-
self.cmd('ifconfig %s 0' %intf.name)
44+
self.cmd('ifconfig %s 0' % intf.name)
3845
# # For the first one, let's configure the mgmt address
3946
# if first:
4047
# first = False
4148
# self.cmd('ip a a %s dev %s' %(kwargs['mgmtip'], intf.name))
42-
#let's write the hostname in /var/mininet/hostname
49+
# let's write the hostname in /var/mininet/hostname
4350
self.cmd("echo '" + self.name + "' > "+PRIVDIR+"/hostname")
44-
if os.path.isfile(BASEDIR+self.name+"/start.sh") :
45-
self.cmd('source %s' %BASEDIR+self.name+"/start.sh")
51+
if os.path.isfile(BASEDIR+self.name+"/start.sh"):
52+
self.cmd('source %s' % BASEDIR+self.name+"/start.sh")
4653

4754
def cleanup(self):
48-
def remove_if_exists (filename):
55+
def remove_if_exists(filename):
4956
if os.path.exists(filename):
5057
os.remove(filename)
5158

@@ -86,78 +93,80 @@ def __init__(self, name, *args, **kwargs):
8693

8794
# the add_link function creates a link and assigns the interface names
8895
# as node1-node2 and node2-node1
89-
def add_link (node1, node2):
96+
97+
98+
def add_link(node1, node2):
9099
Link(node1, node2, intfName1=node1.name+'-'+node2.name,
91-
intfName2=node2.name+'-'+node1.name)
100+
intfName2=node2.name+'-'+node1.name)
101+
92102

93103
def create_topo(my_net):
104+
# pylint: disable=invalid-name
94105
h1 = my_net.addHost(name='h1', cls=BaseNode)
95106
h2 = my_net.addHost(name='h2', cls=BaseNode)
96107
h3 = my_net.addHost(name='h3', cls=BaseNode)
97108
r1 = my_net.addHost(name='r1', cls=Router)
98109
r2 = my_net.addHost(name='r2', cls=Router)
99110
r3 = my_net.addHost(name='r3', cls=Router)
100111

101-
#note that if the interface names are not provided,
102-
#the order of adding link will determine the
103-
#naming of the interfaces (e.g. on r1: r1-eth0, r1-eth1, r1-eth2...)
112+
# note that if the interface names are not provided,
113+
# the order of adding link will determine the
114+
# naming of the interfaces (e.g. on r1: r1-eth0, r1-eth1, r1-eth2...)
104115
# it is possible to provide names as follows
105116
# Link(h1, r1, intfName1='h1-eth0', intfName2='r1-eth0')
106117
# the add_link function creates a link and assigns the interface names
107118
# as node1-node2 and node2-node1
108119

109-
#Link(h1, r1, intfName1='h1-r1', intfName2='r1-h1')
110-
#Link(h2, r2, intfName1='h2-r2', intfName2='r2-h2')
111-
#Link(h3, r3, intfName1='h3-r3', intfName2='r3-h3')
112-
add_link(h1,r1)
113-
add_link(h2,r2)
114-
add_link(h3,r3)
120+
# Link(h1, r1, intfName1='h1-r1', intfName2='r1-h1')
121+
# Link(h2, r2, intfName1='h2-r2', intfName2='r2-h2')
122+
# Link(h3, r3, intfName1='h3-r3', intfName2='r3-h3')
123+
add_link(h1, r1)
124+
add_link(h2, r2)
125+
add_link(h3, r3)
115126

116-
add_link(r1,r2)
117-
add_link(r1,r3)
118-
add_link(r2,r3)
127+
add_link(r1, r2)
128+
add_link(r1, r3)
129+
add_link(r2, r3)
119130

120131

121-
def stopAll():
132+
def stop_all():
122133
# Clean Mininet emulation environment
123134
os.system('sudo mn -c')
124135
# Kill all the started daemons
125136
os.system('sudo killall sshd zebra ospfd')
126137

127-
def extractHostPid (dumpline):
138+
139+
def extract_host_pid(dumpline):
128140
temp = dumpline[dumpline.find('pid=')+4:]
129-
return int(temp [:len(temp)-2])
141+
return int(temp[:len(temp)-2])
130142

131143

132-
133-
def simpleTest():
144+
def simple_test():
134145
"Create and test a simple network"
135146

136-
#topo = RoutersTopo()
137-
#net = Mininet(topo=topo, build=False, controller=None)
147+
# topo = RoutersTopo()
148+
# net = Mininet(topo=topo, build=False, controller=None)
138149
net = Mininet(topo=None, build=False, controller=None)
139150
create_topo(net)
140151

141152
net.build()
142153
net.start()
143154

144-
145155
print("Dumping host connections")
146156
dumpNodeConnections(net.hosts)
147-
#print "Testing network connectivity"
148-
#net.pingAll()
157+
# print "Testing network connectivity"
158+
# net.pingAll()
149159

150-
with open(OUTPUT_PID_TABLE_FILE,"w") as file:
160+
with open(OUTPUT_PID_TABLE_FILE, "w") as file:
151161
for host in net.hosts:
152-
file.write("%s %d\n" % (host, extractHostPid( repr(host) )) )
153-
154-
CLI( net )
155-
net.stop()
156-
stopAll()
162+
file.write("%s %d\n" % (host, extract_host_pid(repr(host))))
157163

164+
CLI(net)
165+
net.stop()
166+
stop_all()
158167

159168

160169
if __name__ == '__main__':
161170
# Tell mininet to print useful information
162171
setLogLevel('info')
163-
simpleTest()
172+
simple_test()

0 commit comments

Comments
 (0)