set_sysctls.py only works with python < 2.6

25 views
Skip to first unread message

Robert Raszuk

unread,
Aug 6, 2021, 6:34:24 PM8/6/21
to packe...@googlegroups.com
Hi,

Is there a version of set_sysctls.py working with python3  ? 

Thx,
R.

Robert Raszuk

unread,
Aug 6, 2021, 7:09:25 PM8/6/21
to packe...@googlegroups.com
Ok just to respond to myself ;) If anyone cares to review ... 

..../git/packetdrill/gtests/net/tcp/common$ cat set_sysctls.py
#!/usr/bin/python3

import subprocess
import os
import sys

pppid = int(os.popen("ps -p %d -oppid=" % os.getppid()).read().strip())

filename = '/tmp/sysctl_restore_%d.sh' % pppid

restore_file = open(filename, 'w')
restore_file.write("#!/bin/bash \n")

for a in sys.argv[1:]:
  sysctl = a.split('=')

  # save current value
  cur_val = subprocess.getoutput('cat ' + sysctl[0])
  res_string = "echo " + cur_val + " > " + sysctl[0] + "\n"
  restore_file.write(res_string)

  # set new value
  cmd = 'echo %s > %s' % (sysctl[1], sysctl[0])
  os.system(cmd)

restore_file.close()
os.system('chmod u+x %s' % filename)

Neal Cardwell

unread,
Aug 7, 2021, 10:24:22 AM8/7/21
to Robert Raszuk, packe...@googlegroups.com
Thanks for the report!

FWIW the easiest option to resolve this is probably just to install python. On a Linux system based on Debian/Ubuntu/etc you can use something like:

  sudo apt install python

To hopefully avoid these kinds of issues in the future for folks getting started with packetdrill, I have added a note to the README at:

---
First, download the dependencies that you will need in order to build and run packetdrill. If you are on a Linux system based on Debian/Ubuntu then you can use a command like:
  sudo apt install git gcc make bison flex python
---

best regards,
neal


--
You received this message because you are subscribed to the Google Groups "packetdrill" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packetdrill...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packetdrill/CA%2Bb%2BERnvONyjub0UrEU9%2BiJtikr0ciSrniWNOcnuaQMv%3DeYfTQ%40mail.gmail.com.

Robert Raszuk

unread,
Aug 7, 2021, 10:42:43 AM8/7/21
to Neal Cardwell, packe...@googlegroups.com
Hi,

>  sudo apt install python

Very honestly I am not sure if this is best idea. 

As part of this install bunch of links is going to be reverted from python3 to python 2 as part of the installation contains  'python-is-python2' 

So while perhaps good for packetdrill it may mess up life for other python3 scripts immediately if they call python counting on default use of 'python-as-python3'. 

Even if one tries to install python2 it defaults to python2.7 in which "import commands" has been obsoleted post python2.6. 

IMHO the best will be to convert all python code to python3 and avoid this issue for good. 

Cheers,
R.










Reply all
Reply to author
Forward
0 new messages