canonical / python-libmaas

Unofficial python client library for MAAS
https://maas.io
Other
62 stars 70 forks source link

restore_*_configuration() return aiohttp ServerDisconnectedError #251

Closed happycouak closed 3 years ago

happycouak commented 3 years ago

Using restore_*_configuration() return the following error:

Traceback (most recent call last):
  File "/Users/cedric_lemarchand/maas/{value for value in variable}storage_config.py", line 16, in <module>
    m.restore_networking_configuration()
  File "/usr/local/lib/python3.9/site-packages/maas/client/utils/maas_async.py", line 43, in wrapper
    result = eventloop.run_until_complete(result)
  File "/usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/site-packages/maas/client/viscera/machines.py", line 796, in restore_networking_configuration
    await self._handler.restore_networking_configuration(
  File "/usr/local/lib/python3.9/site-packages/maas/client/bones/__init__.py", line 307, in __call__
    response = await self.bind(**params).call(**data)
  File "/usr/local/lib/python3.9/site-packages/maas/client/bones/__init__.py", line 459, in dispatch
    response = await session.request(
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 544, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 890, in start
    message, payload = await self._protocol.read()  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/aiohttp/streams.py", line 604, in read
    await self._waiter
aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

Code snippet:

from maas.client import login
client = login(
    MAAS_URL, username=MAAS_USER, password=MAAS_PWD)

m = client.machines.get(system_id="sqsx8g")
m.restore_networking_configuration()

This code worked some times ago, I have tried some older version of python3, libmaas and aiohttp without success.

Among things that could had potentially changed, the MaaS server is now in 2.9.1 (9153-g.66318f531). Previous successfull runs where against MaaS 2.7 (maybe 2.6).

python-libmaas 0.6.6 aiohttp 3.7.3 async-timeout 3.0.1

LaurentDumont commented 3 years ago

Hiya, I'm seeing the same issue with 2.9.1 and libmaas.

Our call is a bit different, it happens when we use the release method on a machine.

    for machine in machines:
        if machine.status_name != 'Ready':
            print("Releasing machine " + machine.hostname + " from MaaS")
            machine.release(wait=False)
Traceback (most recent call last):
  File "release_machines.py", line 51, in <module>
    main()
  File "release_machines.py", line 44, in main
    machine.release(wait=False)
  File "/usr/local/lib/python3.7/site-packages/maas/client/utils/maas_async.py", line 43, in wrapper
    result = eventloop.run_until_complete(result)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.7/site-packages/maas/client/viscera/machines.py", line 662, in release
    self._reset(await self._handler.release(**params))
  File "/usr/local/lib/python3.7/site-packages/maas/client/bones/__init__.py", line 307, in __call__
    response = await self.bind(**params).call(**data)
  File "/usr/local/lib/python3.7/site-packages/maas/client/bones/__init__.py", line 460, in dispatch
    self.action.method, uri, data=body, headers=_prefer_json(headers)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 504, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 847, in start
    message, payload = await self._protocol.read()  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/site-packages/aiohttp/streams.py", line 591, in read
    await self._waiter
aiohttp.client_exceptions.ServerDisconnectedError
sparkiegeek commented 3 years ago

Thank you for filing this issue, and to those of you who filed issues that are duplicates of this issue. This has additionally been raised in the MAAS discourse, and as bugs on MAAS itself.

I'm glad to share that this issue has now been resolved, and was caused by a bug in Twisted - details on Launchpad and in (upstream's trac)[https://twistedmatrix.com/trac/ticket/10084].

Those of you using MAAS from debian packages should get the fixed version after upgrading your systems (e.g. apt update; apt-full-upgrade), for those using MAAS from a snap - we have pushed a version of MAAS which incorporates the new twisted package to 2.9/candidate.