virtualbox-python icon indicating copy to clipboard operation
virtualbox-python copied to clipboard

TypeError in launch_vm_process

Open dr0ndv opened this issue 3 years ago • 4 comments

ENVIRONMENT
  • virtualbox-python / pyvbox version: 2.2.1
SUMMARY

Function launch_vm_process in library.py has input parameter 'environment_changes' that is list in the last version.

if not isinstance(environment_changes, list):
            raise TypeError("environment_changes can only be an instance of type list")

But in library_ext/machine.py method launch_vm_process of class IMachine has input parameter 'environment' which is string by default. So call launch_vm_process() for machine with default arguments leads to TypeError exception.

Also need to update comment in library.py (str -> list):

        in environment_changes of type str
            The list of putenv-style changes to the VM process environment.
STEPS TO REPRODUCE
vbox = virtualbox.VirtualBox()
vm = vbox.find_machine(vm_name)
p = vm.launch_vm_process()
EXPECTED RESULTS

No exception

ACTUAL RESULTS
Traceback (most recent call last):
  File "build/bdist.macosx-10.15-x86_64/egg/test_service/vm_utils.py", line 203, in start_vm
    p = vm.launch_vm_process()
  File "/Users/test/Library/Python/2.7/lib/python/site-packages/virtualbox/library_ext/machine.py", line 189, in launch_vm_process
    p = super(IMachine, self).launch_vm_process(local_session, type_p, environment)
  File "/Users/test/Library/Python/2.7/lib/python/site-packages/virtualbox/library.py", line 15345, in launch_vm_process
    raise TypeError("environment_changes can only be an instance of type list")
TypeError: environment_changes can only be an instance of type list

dr0ndv avatar Oct 27 '20 16:10 dr0ndv

Could you submit a PR? Maybe within library_ext/machine.py we can support both string and list.

sethmlarson avatar Oct 27 '20 16:10 sethmlarson

I'll submit PR but right now I'm trying to understand of which data type environment argument should be.

As I see earlier environment supported both string and list:

if not (isinstance(environment, basestring) or isinstance(environment, list)):
            raise TypeError("environment can only be an instance of type basestring or list")

And it was necessary to explicitly provide the value. From README.rst:

    >>> # progress = machine.launch_vm_process(session, "gui", "")
    >>> # For virtualbox API 6_1 and above (VirtualBox 6.1.2+), use the following:
    >>> progress = machine.launch_vm_process(session, "gui", [])

Now argument have to be only list:

if not isinstance(environment_changes, list):
            raise TypeError("environment_changes can only be an instance of type list")

Does this change mean that virtualbox_sdk < 6.1.2 is not supported any more?

dr0ndv avatar Oct 27 '20 17:10 dr0ndv

@dr0ndv I'd like to support v6.1.2 still, however virtualbox/library.py is generated completely from the upstream API spec so we can only do so much. Any changes we want to do should be in library_ext, maybe we can map any input of type str to a list?

sethmlarson avatar Oct 27 '20 17:10 sethmlarson

#154 Let's continue discussion in PR

dr0ndv avatar Oct 27 '20 19:10 dr0ndv