sethmlarson / virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.
https://pypi.org/project/virtualbox
Apache License 2.0
354 stars 75 forks source link

Can't start guest session (ValueError: Can not find enumeration where value=None). #14

Closed nilp0inter closed 10 years ago

nilp0inter commented 10 years ago

Hi,

I'm trying to start a guest session but it seems that something it's not initialized properly.

My setup:

The traceback:

In [1]: import virtualbox
In [2]: session = virtualbox.Session()
In [4]: vbox = virtualbox.VirtualBox()
In [5]: machine = vbox.find_machine('box20')
In [6]: machine.launch_vm_process(session, 'gui', '').wait_for_completion()  # Here I wait a few until machine boots up.
In [8]: gs=session.console.guest.create_session('Roger', '')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-67037dd6c3ec> in <module>()
----> 1 gs=session.console.guest.create_session('Roger', '')

/home/nil/Envs/bugcuckoo/local/lib/python2.7/site-packages/virtualbox/library_ext/guest.pyc in create_session(self, user, password, domain, session_name, timeout_ms)
     18                                                     session_name)
     19         for i in range(50):
---> 20             if session.status == library.GuestSessionStatus.started:
     21                 break
     22             time.sleep(0.1)

/home/nil/Envs/bugcuckoo/local/lib/python2.7/site-packages/virtualbox/library.pyc in status(self)
  15216         """
  15217         ret = self._get_attr("status")
> 15218         return GuestSessionStatus(ret)
  15219 
  15220     @property

/home/nil/Envs/bugcuckoo/local/lib/python2.7/site-packages/virtualbox/library_base.pyc in __init__(self, value)
     64     def __init__(self, value=None):
     65         if value not in self._lookup_label:
---> 66             raise ValueError("Can not find enumeration where value=%s" % value)
     67         self._value = value
     68         self.__doc__ = self._lookup_doc[self._value]

ValueError: Can not find enumeration where value=None

Thank you for this great package.

mjdorma commented 10 years ago

Thanks for your post.

Problem: This issue looks like it comes from the library pyvbox (COM / XPCOM) interface to VirtualBox. When an attempt to retrieve IGuestSession's getStatus value, pyvbox is returning None (NULL) instead of returning a valid status code.

As a reference, valid GuestSessionStatus status code values are defined here: http://pythonhosted.org//pyvbox/virtualbox/library.html#virtualbox.library.GuestSessionStatus ...

I believe issue #7 suffered from the same problem you're experiencing in this issue. I also documented a few details about this problem in this response: http://stackoverflow.com/a/21820905/2660243.

Ways forward:

A) Try upgrading to the latest VirtualBox (currently 4.3.10) https://www.virtualbox.org/wiki/Downloads

If that fails:

B) Hack https://github.com/mjdorma/pyvbox/blob/master/virtualbox/library_ext/guest.py to capture this error and keep on trying (in the wait for guess sessoin).

In the meantime:

C) Look into raising a special exception when the vboxapi returns None. This way it should be a bit easier to add hack code like in B) to handle the error and try again. In the very least, it will give a more sane error.

I think I'll work on a solution for C) in the next few days. Once you've upgraded to the latest VirtualBox, and if the error still persists, I'd like to know if B) solves your problem.

It would be great if you could have a go at A & B and let me know if it works out? If it doesn't workout, then it means we have a different error (quite possibly something to do with Debian and VirtuaBox).

Cheers

nilp0inter commented 10 years ago

A) Fixes the problem. (Version: 4.3.10-93012~Debian~wheezy) B) raises "SystemError: GuestSession failed to start" due to a timeout. https://github.com/nilp0inter/pyvbox/commit/f8b1c08775219d240e2a6b6a9ac9d7efa4640332

In [10]: gs=session.console.guest.create_session('test', 'test')
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-10-1246d0c194e1> in <module>()
----> 1 gs=session.console.guest.create_session('test', 'test')

/home/vagrant/local/lib/python2.7/site-packages/pyvbox-0.1.4-py2.7.egg/virtualbox/library_ext/guest.pyc in create_session(self, user, password, domain, session_name, timeout_ms)
     26                 time.sleep(0.1)
     27         else:
---> 28             raise SystemError("GuestSession failed to start")
     29         if timeout_ms != 0:
     30             # There is probably a better way to to this?

SystemError: GuestSession failed to start

Regards

mjdorma commented 10 years ago

5d9b891 should make the Enum types clearer as they are never enumerated with a default of None. The attribute handing code was also in a funny state. I think at one point I was raising an error if vboxapi returned None from an attribute getter (but that is a dangerous and probably incorrect generalisation).

If you're trying to get the guest session going and you think there is a bug to be fixed there, please start a new issue so we can discuss.

Thanks for your input!

Cheers

d-xo commented 10 years ago

I can still reproduce this issue with virtualbox 4.3.14 (r95030) I am running OSX 10.9.3 Python 2.7.5

The following code produces ValueError: Can not find enumeration where value=None

vbox = virtualbox.VirtualBox()
vm = vbox.find_machine('10.8')
session = vm.create_session()
gs = session.console.guest.create_session('beta', 'beta')

The traceback is as follows:

Traceback (most recent call last):
  File "installer_automation.py", line 41, in <module>
    gs = session.console.guest.create_session('beta', 'beta')
  File "/Users/davidterry/.virtualenvs/installer_automation/lib/python2.7/site-packages/virtualbox/library_ext/guest.py", line 20, in create_session
    if session.status == library.GuestSessionStatus.started:
  File "/Users/davidterry/.virtualenvs/installer_automation/lib/python2.7/site-packages/virtualbox/library.py", line 15317, in status
    return GuestSessionStatus(ret)
      File "/Users/davidterry/.virtualenvs/installer_automation/lib/python2.7/site- packages/virtualbox/library_base.py", line 63, in __init__
    raise ValueError("Can not find enumeration where value=%s" % value)
ValueError: Can not find enumeration where value=None
spellr commented 9 years ago

Also experiencing on VirtualBox 4.3.18. I am running Ubuntu 14.04.01 LTS x64 python 2.7,6 installed pyvbox today from pip install pyvbox

$python import virtualbox vbox = virtualbox.VirtualBox() m = vbox.machines[0] s = m.create_session() s.console.guest.create_session('beta', 'beta')

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_ext/guest.py", line 20, in create_session if session.status == library.GuestSessionStatus.started: File "/usr/local/lib/python2.7/dist-packages/virtualbox/library.py", line 15821, in status return GuestSessionStatus(ret) File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_base.py", line 63, in init raise ValueError("Can not find enumeration where value=%s" % value) ValueError: Can not find enumeration where value=None