crossdistro / network-testing

BSD 2-Clause "Simplified" License
6 stars 9 forks source link

Check if the testing driver is run as root #2

Closed thozza closed 8 years ago

thozza commented 8 years ago

The testing driver does not check if the user running it has root privileges and fails with backtrace in case the user does not have the permissions:

[vagrant@localhost ~]$ test-client-server 
Debugger trace forks (options=7)
Cannot remove namespace file "/var/run/netns/test-loopback": No such file or directory
mkdir /var/run/netns failed: Permission denied
Traceback (most recent call last):
  File "/usr/bin/test-client-server", line 5, in <module>
    main()
  File "/usr/lib/python2.7/site-packages/network_testing/client_server.py", line 380, in main
    suite.run()
  File "/usr/lib/python2.7/site-packages/network_testing/client_server.py", line 342, in run
    testcase.run()
  File "/usr/lib/python2.7/site-packages/network_testing/client_server.py", line 315, in run
    scenario.run()
  File "/usr/lib/python2.7/site-packages/network_testing/client_server.py", line 100, in run
    self.prepare()
  File "/usr/lib/python2.7/site-packages/network_testing/client_server.py", line 231, in prepare
    self._add_netns('test-loopback')
  File "/usr/lib/python2.7/site-packages/network_testing/client_server.py", line 197, in _add_netns
    subprocess.check_call(['ip', 'netns', 'add', ns])
  File "/usr/lib64/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ip', 'netns', 'add', 'test-loopback']' returned non-zero exit status 1

The driver should either check the UID of the user running the process OR catch the exceptions and provide meaningful error message