Assertion error on mininet-test experiment - python

My friend and I tried to reproduce this mininet-test experiment: https://github.com/mininet/mininet-tests/tree/master/dctcp
We self created a VM and installed Mininet 2.2 on ubuntu with kernel version 3.18.9, which included dctcp and tcp_probe function.
Since author suggest kernel version 3.0.1 didn't support those function we needed in Mininetnet. We simply changed the some function name in dctcp.py, such as: add_host changed to addHost, add_switch changed to addSwitch ,add_link changed to addLink.
And we also imported some python function we need, such as : python-matplotlib, python-termcolor and bwm-ng.
But we still encounter the following problems when we plotting the graph - cwnd.png.
Are we missing some important lib or any code need to change?
.Traceback (most recent call last):
File "dctcp.py", line 250, in <module>
main()
File "dctcp.py", line 244, in main
net.stop()
File "build/bdist.linux-x86_64/egg/mininet/net.py", line 514, in stop
File "build/bdist.linux-x86_64/egg/mininet/link.py", line 479, in stop
File "build/bdist.linux-x86_64/egg/mininet/link.py", line 472, in delete
File "build/bdist.linux-x86_64/egg/mininet/link.py", line 199, in delete
File "build/bdist.linux-x86_64/egg/mininet/link.py", line 64, in cmd
File "build/bdist.linux-x86_64/egg/mininet/node.py", line 350, in cmd
File "build/bdist.linux-x86_64/egg/mininet/node.py", line 269, in sendCmd
AssertionError
s1
s1-eth1
s1-eth2
s1-eth3
total
['tcp-n3-bw100/qlen_s1-eth1.txt']

I ran into this as well, and found that if you look at: https://github.com/bigswitch/mininet/blob/master/mininet/node.py and in the monitor() function section you will see that this function sets the waiting flag = False.
So the code can be
h1.sendCmd(startbackground_service)
h2.cmd(something_else)
h3.cmd(use_h1_service)
.....
#at some point end h1's background service, naturally or unnaturally
h1.monitor() # will check the service, and set waiting=False

For me h1.monitor() didn't worked in a similar situation on mininet 2.3.0 so I replaced the sendCmd() with popen() and then used the terminate() function.
Using the example above I changed it to:
p1 = h1.popen(startbackground_service)
h2.cmd(something_else)
h3.cmd(use_h1_service)
.....
p1.terminate()

The code seems to set a flag waiting at the end of a sendCmd() call, the flag is check to be False on every run of the method. It seem to be reset when the result of the command is received.
As the result you can't send a second command until the response of the first is received. This might just be a race condition but IMHO the library should handle that case in a more clever and transparent way.

Related

What does it mean when an error shows multiple files in a Python traceback?

I get the following error (edited out some parts, but same structure):
File "./project/calcs.py", line 43, in getVar
var = await olf.getOrg(*args, **kwargs)
File "./project/subView.py", line 177, in getOrg
undo = force.getLength()
File "./project/stack/refine.py", line 89, in getLength
for eTL in getLength():
blablabla.blablabla.issue: Can't redirect user
Am I supposed to look at the very FIRST error line to address the issue? Is it a chronology?
So in this case, I would be obliged to address calcs.py # line 43 to fix that issue? I wouldn't be able to fix it by, let's say, addressing the 2nd error or the last one, correct?
Is that also the way to look at any python error trackback?
You are probably looking at a stack trace which is ordered chronologically (oldest call first). In your case this means var = await olf.getOrg(*args, **kwargs) ran first which then ended up calling undo = force.getLength() and then for eTL in getLength(): which failed.

RuntimeError: At least one choice needs to be made for complete functioning of this sample

I am new to IoT and am using it for the first time for a project. I started with some basics of Microsoft Azure pnp from here:
https://learn.microsoft.com/en-us/azure/iot-pnp/quickstart-connect-device?pivots=programming-language-python
Now, when I try running 'simple_thermostat.py' from this:
https://github.com/Azure/azure-iot-sdk-python/tree/master/azure-iot-device/samples/pnp
I get the following error:
"
Traceback (most recent call last):
File "simple_thermostat.py", line 337, in <module>
asyncio.run(main())
File "C:\ProgramData\Anaconda3\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "simple_thermostat.py", line 253, in main
raise RuntimeError(
RuntimeError: At least one choice needs to be made for complete functioning of this sample.
"
Can someone explain me the problem and the solution as well?
I reviewed through the code sourced # https://github.com/Azure/azure-iot-sdk-python/blob/master/azure-iot-device/samples/pnp/simple_thermostat.py
Highlighting only the important lines of the code which is responsible for the above observed error.
switch = os.getenv("IOTHUB_DEVICE_SECURITY_TYPE")
if switch == "DPS":
provisioning_host = (
.
.
.
.
elif switch == "connectionString":
conn_str = os.getenv("IOTHUB_DEVICE_CONNECTION_STRING")
else:
raise RuntimeError(
"At least one choice needs to be made for complete functioning of this sample."
)
The issue is occurring because the IOTHUB_DEVICE_SECURITY_TYPE is not provided
As per the documentation, before running the sample you will have the environment variable IOTHUB_DEVICE_SECURITY_TYPE
Encountered similar issue. It was because we were using Powershell to set the environment variables.
For powershell:
$Env:IOTHUB_DEVICE_SECURITY_TYPE = "connectionString"
$Env:IOTHUB_DEVICE_CONNECTION_STRING="<your connection string>"

Python:Pycall Validation Error while Calling

I have Asterisk 13.20 set up and running fine on Ubuntu 16.04,calls are going well through a Softphone(Zoiper), I came across a Library in Python "Pycall" which lets you make calls through a Python Script.So I tried testing a snippet from the site Pycall
The code that I used:
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()
Just made changes in the extension,wherein I used one from my server
However I am getting the following error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
c.spool()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 131, in spool
self.writefile()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 119, in writefile
f.write(self.contents)
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 114, in contents
return '\n'.join(self.buildfile())
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
raise ValidationError
pycall.errors.ValidationError
Tried searching online for the solution but coudnt find one,What am I doing wrong?
This question not related to PBX, it is just incorrect use of LIB.
General instruction how to solve ANY issue with availible source code.
You have error
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
Go that file and line, check code, add more debug if needed, fix your app.
Run as asterisk user.
sudo su asterisk -s /bin/bash
python
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()

fexpect breaks fabric scripts

I hot upon an requirement where I needed to automatically answer the prompt on remote machine and then I found fexpect after reading different stackoverflow questions. But the moment I include fexpect in my script it breaks the whole script!
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/fabric/main.py", line 743, in main
*args, **kwargs
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 368, in execute
multiprocessing
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 264, in _execute
return task.run(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 171, in run
return self.wrapped(*args, **kwargs)
File "/etc/puppet/fabfile.py", line 165, in edit_sudoers
run('echo "Current Permission of the file /etc/sudoers - "`stat -c "%a %n" /etc/sudoers`')
File "/usr/local/lib/python2.7/dist-packages/ilogue/fexpect/api.py", line 15, in run
wrappedCmd = wrapExpectations(cmd)
File "/usr/local/lib/python2.7/dist-packages/ilogue/fexpect/internals.py", line 15, in wrapExpectations
script = createScript(cmd)
File "/usr/local/lib/python2.7/dist-packages/ilogue/fexpect/internals.py", line 39, in createScript
for e in fabric.state.env.expectations:
File "/usr/local/lib/python2.7/dist-packages/fabric/utils.py", line 184, in __getattr__
raise AttributeError(key)
AttributeError: expectations
The moment i write
from ilogue.fexpect import expect, expecting, run fabric stops working with the above error message.
I asked in fabric irc as well but I got to know that this might be because of some version related issues. Has anyone else encountered this error before?
fexpect==0.2.post7
Fabric==1.8.0
Just import fexpect's run as erun and its sudo as esudo.
When you use the fexpect run or sudo functions, you must wrap those calls in a with expecting(prompts): context. This is a known issue in fexpect, although there is a pull request, so it might be fixed by the time posterity reads this.
One solution is to import fexpect's run function with a different name, e.g. erun, and use it only when you need the automatic prompt handling functionality:
from fabric.api import run
from ilogue.fexpect import expect, expecting, run as erun
run(a_cmd) # Native Fabric run - should work fine
prompts = [...]
with expecting(prompts):
erun(a_prompting_cmd) # fexpect run - should with fine inside expecting context
Another thing that isn't explicitly stated in the fexpect documentation is that the pexpect package needs to be installed on the target system.
Yet another fexpect gotcha is that the prompt strings are regular expressions -- the fexpect sample code is misleading about this.

multiprocessing.manager issue sys.args

I am running the following python line of code within a small windows service application which is multiprocessed.
multiprocessing.Manager()
The issue is there appears to be no attribute argv within the module sys set when running a windows service. As a result of this I get the following error occur within the python multiprocessing forking library. I was hoping someone might be able to shed some light on this issue.
Stacktrace of issue (when running multiprocessing.Manager within windows service):
File "C:\python27\lib\multiprocessing\__init__.py", line 99, in Manager
m.start()
File "C:\python27\lib\multiprocessing\managers.py", line 524, in start
self._process.start()
File "C:\python27\lib\multiprocessing\process.py", line 130, in start
self._popen = Popen(self)
File "C:\python27\lib\multiprocessing\forking.py", line 252, in __init__
cmd = get_command_line() + [rhandle]
File "C:\python27\lib\multiprocessing\forking.py", line 339, in get_command_line
if process.current_process()._identity==() and is_forking(sys.argv):
AttributeError: 'module' object has no attribute 'argv
Update
One possible solution to my problem is that I manually set the sys.argv value if it is not set at runtime but this seems very unpythonic. But might be the only solution. What do stackoverflow-ers think?
if not hastattr(sys, 'argv'):
sys.argv = []
But, this then leads me to a new issue with the multiprocessing.manager where by an unexpected EOFError occurs within the code.
File "C:\python27\lib\multiprocessing\__init__.py", line 99, in Manager
m.start()
File "C:\python27\lib\multiprocessing\managers.py", line 528, in start
self._address = reader.recv()
EOFError
Since setting sys.argv = [] didn't work, if there is a script name you might be able to use do sys.argv = ['scriptname'] or just sys.argv = ['']. The latter is what you get if you run python, import sys and then look at sys.argv, e.g.,
~$ python
>>> import sys
>>> sys.argv
['']
Call this function after Python initialization:
PySys_SetArgv(argc, argv);
The interpreter can't get access to argc/argv in other way rather then passing them explicitly from main().

Categories