Reland of PyLint fixes for tools-webrtc and webrtc/tools (patchset #1 id:1 of https://codereview.webrtc.org/2737233003/ )

Reason for revert:
Fixing errors for reland. I have tested that this does not make Chromium video quality tests fail.

Original issue's description:
> Revert of PyLint fixes for tools-webrtc and webrtc/tools (patchset #3 id:40001 of https://codereview.webrtc.org/2736233003/ )
>
> Reason for revert:
> Fails video quality tests in Chrome:  http://build.chromium.org/p/chromium.webrtc.fyi/builders/Win10%20Tester/builds/6568
> I should have looked more closer at those :(
>
> Original issue's description:
> > PyLint fixes for tools-webrtc and webrtc/tools
> >
> > Fix a lot of errors before bringing in the new config in
> > https://codereview.webrtc.org/2737963003/
> >
> > BUG=webrtc:7303
> > NOTRY=True
> >
> > Review-Url: https://codereview.webrtc.org/2736233003
> > Cr-Commit-Position: refs/heads/master@{#17137}
> > Committed: f5318e1f39
>
> TBR=oprypin@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:7303
>
> Review-Url: https://codereview.webrtc.org/2737233003
> Cr-Commit-Position: refs/heads/master@{#17142}
> Committed: 94f4d9effc

NOTRY=true
BUG=webrtc:7312

Review-Url: https://codereview.webrtc.org/2741733003
Cr-Commit-Position: refs/heads/master@{#17541}
This commit is contained in:
kjellander
2017-04-05 06:42:43 -07:00
committed by Commit bot
parent adf0635ed5
commit c88b5d56ad
15 changed files with 154 additions and 157 deletions

View File

@ -55,14 +55,14 @@ class NonStrippingEpilogOptionParser(optparse.OptionParser):
return self.epilog
def _get_external_ip():
def _GetExternalIp():
"""Finds out the machine's external IP by connecting to google.com."""
external_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
external_socket.connect(('google.com', 80))
return external_socket.getsockname()[0]
def _parse_args():
def _ParseArgs():
"""Define and parse the command-line arguments."""
presets_string = '\n'.join(str(p) for p in _PRESETS)
parser = NonStrippingEpilogOptionParser(epilog=(
@ -123,11 +123,11 @@ def _parse_args():
except ValueError:
parser.error('Invalid port range specified.')
_set_logger(options.verbose)
_InitLogging(options.verbose)
return options
def _set_logger(verbose):
def _InitLogging(verbose):
"""Setup logging."""
log_level = _DEFAULT_LOG_LEVEL
if verbose:
@ -135,8 +135,8 @@ def _set_logger(verbose):
logging.basicConfig(level=log_level, format='%(message)s')
def _main():
options = _parse_args()
def main():
options = _ParseArgs()
# Build a configuration object. Override any preset configuration settings if
# a value of a setting was also given as a flag.
@ -154,19 +154,19 @@ def _main():
emulator = network_emulator.NetworkEmulator(connection_config,
options.port_range)
try:
emulator.check_permissions()
emulator.CheckPermissions()
except network_emulator.NetworkEmulatorError as e:
logging.error('Error: %s\n\nCause: %s', e.fail_msg, e.error)
return -1
if not options.target_ip:
external_ip = _get_external_ip()
external_ip = _GetExternalIp()
else:
external_ip = options.target_ip
logging.info('Constraining traffic to/from IP: %s', external_ip)
try:
emulator.emulate(external_ip)
emulator.Emulate(external_ip)
logging.info('Started network emulation with the following configuration:\n'
' Receive bandwidth: %s kbps (%s kB/s)\n'
' Send bandwidth : %s kbps (%s kB/s)\n'
@ -184,7 +184,7 @@ def _main():
options.port_range[0], options.port_range[1])
raw_input('Press Enter to abort Network Emulation...')
logging.info('Flushing all Dummynet rules...')
network_emulator.cleanup()
network_emulator.Cleanup()
logging.info('Completed Network Emulation.')
return 0
except network_emulator.NetworkEmulatorError as e:
@ -192,4 +192,4 @@ def _main():
return -2
if __name__ == '__main__':
sys.exit(_main())
sys.exit(main())

View File

@ -53,20 +53,20 @@ class NetworkEmulator(object):
self._port_range = port_range
self._connection_config = connection_config
def emulate(self, target_ip):
def Emulate(self, target_ip):
"""Starts a network emulation by setting up Dummynet rules.
Args:
target_ip: The IP address of the interface that shall be that have the
network constraints applied to it.
"""
receive_pipe_id = self._create_dummynet_pipe(
receive_pipe_id = self._CreateDummynetPipe(
self._connection_config.receive_bw_kbps,
self._connection_config.delay_ms,
self._connection_config.packet_loss_percent,
self._connection_config.queue_slots)
logging.debug('Created receive pipe: %s', receive_pipe_id)
send_pipe_id = self._create_dummynet_pipe(
send_pipe_id = self._CreateDummynetPipe(
self._connection_config.send_bw_kbps,
self._connection_config.delay_ms,
self._connection_config.packet_loss_percent,
@ -74,15 +74,15 @@ class NetworkEmulator(object):
logging.debug('Created send pipe: %s', send_pipe_id)
# Adding the rules will start the emulation.
incoming_rule_id = self._create_dummynet_rule(receive_pipe_id, 'any',
target_ip, self._port_range)
incoming_rule_id = self._CreateDummynetRule(receive_pipe_id, 'any',
target_ip, self._port_range)
logging.debug('Created incoming rule: %s', incoming_rule_id)
outgoing_rule_id = self._create_dummynet_rule(send_pipe_id, target_ip,
'any', self._port_range)
outgoing_rule_id = self._CreateDummynetRule(send_pipe_id, target_ip,
'any', self._port_range)
logging.debug('Created outgoing rule: %s', outgoing_rule_id)
@staticmethod
def check_permissions():
def CheckPermissions():
"""Checks if permissions are available to run Dummynet commands.
Raises:
@ -99,8 +99,8 @@ class NetworkEmulator(object):
raise NetworkEmulatorError('You must run this script with administrator'
' privileges.')
def _create_dummynet_rule(self, pipe_id, from_address, to_address,
port_range):
def _CreateDummynetRule(self, pipe_id, from_address, to_address,
port_range):
"""Creates a network emulation rule and returns its ID.
Args:
@ -118,14 +118,14 @@ class NetworkEmulator(object):
self._rule_counter += 100
add_part = ['add', self._rule_counter, 'pipe', pipe_id,
'ip', 'from', from_address, 'to', to_address]
_run_ipfw_command(add_part + ['src-port', '%s-%s' % port_range],
_RunIpfwCommand(add_part + ['src-port', '%s-%s' % port_range],
'Failed to add Dummynet src-port rule.')
_run_ipfw_command(add_part + ['dst-port', '%s-%s' % port_range],
_RunIpfwCommand(add_part + ['dst-port', '%s-%s' % port_range],
'Failed to add Dummynet dst-port rule.')
return self._rule_counter
def _create_dummynet_pipe(self, bandwidth_kbps, delay_ms, packet_loss_percent,
queue_slots):
def _CreateDummynetPipe(self, bandwidth_kbps, delay_ms, packet_loss_percent,
queue_slots):
"""Creates a Dummynet pipe and return its ID.
Args:
@ -146,21 +146,21 @@ class NetworkEmulator(object):
if sys.platform.startswith('linux'):
error_message += ('Make sure you have loaded the ipfw_mod.ko module to '
'your kernel (sudo insmod /path/to/ipfw_mod.ko).')
_run_ipfw_command(cmd, error_message)
_RunIpfwCommand(cmd, error_message)
return self._pipe_counter
def cleanup():
def Cleanup():
"""Stops the network emulation by flushing all Dummynet rules.
Notice that this will flush any rules that may have been created previously
before starting the emulation.
"""
_run_ipfw_command(['-f', 'flush'],
_RunIpfwCommand(['-f', 'flush'],
'Failed to flush Dummynet rules!')
_run_ipfw_command(['-f', 'pipe', 'flush'],
_RunIpfwCommand(['-f', 'pipe', 'flush'],
'Failed to flush Dummynet pipes!')
def _run_ipfw_command(command, fail_msg=None):
def _RunIpfwCommand(command, fail_msg=None):
"""Executes a command and prefixes the appropriate command for
Windows or Linux/UNIX.