SeattleTestbed / repy_v2

Seattle Testbed's Repy ("Restricted Python") sandbox, version 2
MIT License
12 stars 50 forks source link

resourcemanipulation.py parses all resources as float #59

Closed choksi81 closed 7 years ago

choksi81 commented 10 years ago

resourcemanipulation.py is responsible for reading in and parsing restrictions files, and making the contents available to nanny. It will however treat all resource values as floats, see here. This makes sense for things like consumption rates (cpu, net, loop, disk, random), but it also converts port numbers, Bytes used on disk and in memory, and socket, file, and thread counts.

This weird behavior is visible e.g. through getresources:

({'loopsend': 1000000.0, 'netrecv': 10000.0, 'random': 10000.0, 'insockets': 5.0, 'fileread': 10000.0, 'netsend': 10000.0, 'connport': set(['messport': set([34612.0](]),)), 'diskused': 100000000.0, 'filewrite': 10000.0, 'lograte': 30000.0, 'filesopened': 5.0, 'looprecv': 1000000.0, 'events': 10.0, 'memory': 20000000.0, 'outsockets': 5.0, 'cpu': 0.5}, {'diskused': 0L, 'fileread': 0.0, 'loopsend': 0.0, 'filesopened': 0, 'lograte': 0.0, 'netrecv': 0.0, 'random': 0.0, 'insockets': 0, 'filewrite': 0.0, 'looprecv': 0.0, 'events': 1, 'messport': set(['memory': 5365760L, 'netsend': 0.0, 'connport': set([](]),)), 'outsockets': 0, 'cpu': 0.007458812, 'threadcpu': 0.007168}, [not fixed, using ```getresources``` for things like determining which ports are currently available to a program become unnecessarily cluttered with casting to ```int``` of set items.
----
Proposed fix: On parsing, check the category for resource (per [source:seattle/branches/repy_v2/repy&resource_constants.py resourceconstants.py](])

If)), and use the correct numeric type accordingly.

choksi81 commented 10 years ago

Author: albert Fixed in r7174. All of the unit tests that use getresources and succeeded before still work; no additional ones fail.

choksi81 commented 10 years ago

Author: leonwlaw This fix broke vessel joining, as when the resourcedicts are added together, they are checked if they are floats. Of course, ints break that :)

https://seattle.poly.edu/browser/seattle/branches/repy_v2/repy/resourcemanipulation.py?rev=7147#L339

Proposed fix is to change the condition to be:

if type(retdict[not in [float, int](resource]))
choksi81 commented 10 years ago

Author: monzum Additional fix for this in r7166. resourcemanipulation.py was still reaching this error: https://seattle.poly.edu/browser/seattle/branches/repy_v2/repy/resourcemanipulation.py?rev=7147#L404

aaaaalbert commented 7 years ago

Closing this issue, it was fixed via ca83de7de7f2a71c97f692d7c4c14e5fe253b9d2 a while ago.