core: ruckus_unleashed: integration "Failed to set up" on 2023.6.0
The problem
After upgrading my HA instance to v2023.6.0 yesterday my Ruckus Unleashed integration stopped working with the “Failed to set up” error on the integration page; reloading the integration, restarting HA, and rebooting the entire device did not resolve the problem.
If I enable debug logging for the integration, reload the integration, and check the logs I see the following two entries which appear relevant.
The first entry is coming from the Ruckus integration itself:
Logger: homeassistant.config_entries
Source: components/ruckus_unleashed/__init__.py:31
First occurred: June 7, 2023 at 10:13:26 PM (3 occurrences)
Last logged: 10:09:47 AM
Error setting up entry mesh-XXXXXX for ruckus_unleashed
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/ruckus_unleashed/__init__.py", line 31, in async_setup_entry
ruckus = await Ruckus.create(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pyruckus/__init__.py", line 44, in create
await ruckus.connect()
File "/usr/local/lib/python3.11/site-packages/pyruckus/__init__.py", line 50, in connect
result = await ssh.login(
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pyruckus/RuckusSSH.py", line 48, in login
i = await self.expect(login_regex_array, timeout=login_timeout, async_=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pexpect/spawnbase.py", line 340, in expect
return self.expect_list(compiled_pattern_list,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pexpect/spawnbase.py", line 366, in expect_list
from ._async import expect_async
File "/usr/local/lib/python3.11/site-packages/pexpect/_async.py", line 6, in <module>
@asyncio.coroutine
^^^^^^^^^^^^^^^^^
AttributeError: module 'asyncio' has no attribute 'coroutine'
The second entry doesn’t appear to be directly related to the Ruckus integration, but it appears similar to other outstanding GH issues for the integration:
Logger: homeassistant.util.async_
Source: util/async_.py:166
First occurred: 10:00:24 AM (4 occurrences)
Last logged: 10:09:47 AM
Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue for config doing blocking calls at homeassistant/components/config/config_entries.py, line 112: await hass.config_entries.async_reload(entry_id)
What version of Home Assistant Core has the issue?
core-2023.6.0
What was the last working version of Home Assistant Core?
core-2023.5.4
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Ruckus Unleashed
Link to integration documentation on our website
https://www.home-assistant.io/integrations/ruckus_unleashed
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 93 (40 by maintainers)
I can confirm same issue exists also on 2023.6.1
@ms264556 Thanks a ton for working on the tests!
I’ll dig into your branch soon and update the PR!
I’ll second your sentiments @Bubbgump209 : @andornaut - You’re a god 😃
For anybody using HassOS Go to the console ha > login # docker exec -it homeassistant /bin/bash homeassistant:/config# pip install https://github.com/pexpect/pexpect/archive/master.zip homeassistant:/config# exit # shutdown -r now
Thanks for the solutions!
Hi @lanrat, I’ve ported over the existing integration’s tests, apart from one which seems to be testing old HA functionality. Hopefully that’s enough to get this accepted.
Can you have a look at my branch here, and apply the changes to your branch?
I created a library which is completely async, using aiohttp, specifically so it could replace pyruckus here (and I put AP LED, client blocking and WLAN disabling into the API). If you don’t want to reinvent the wheel then you might want to have a look.
https://pypi.org/project/aioruckus/
Hi @Coder84619 - In lieu of a legitmate response I can offer: The rewritten integration has been submitted as a PR and passed 49/51 tests. My head is too far underwater to provide insight into the failed tests, but I believe it may be political rather than technical … possibly regarding the ownership of the code base (?!?) I believe the former owner/writer/creator of the Integration no longer uses Ruckus devices and is keen to hand over ownership. Under a strict “do not hassle the talent” policy, corresopndance is via HA bots. We wait. If, like myself, your HA automations require Device Tracker presense to trigger events, there are a couple of ways to make the old integration work, as per Bubbgump209’s surgical rewrite of the offending _async.py file in the pexpect library, or andornaut’s upgrade of the entire pexpect library to a later version. Preferably though, you can spare 10-15 minutes and follow lanrat’s suggestion of pulling down the new code into your custom_components folder to test the new integration that will (hopefully) soon be released to us all once it passes the final tests. I’m new to much of this, but fortunately have some time to commit to bridging the knowledge gap from those who create, and myself, who consumes. If you’re short on time, but need the Integration up and running, lay out your scenario, and I will try to to help you get things moving until it all becomes a simple click and consume Integration once more.
@faithless01 I’m glad you figured it out.
As you found out the hard way, I forgot to mention you will need a add
"version": "0.0.1"to manifest.json.You’re a beast @lanrat I’ve raw copied the files from your repo into my custom_components folder, and all appears well. Is there any way to tell if I’m running the custom version? Enabling debug only provides the following:
2023-06-25 04:35:41.758 DEBUG (MainThread) [homeassistant.components.ruckus_unleashed] Finished fetching ruckus_unleashed data in 0.666 seconds (success: True)EDIT: I moved the /usr/src/homeassistant/homeassistant/components/ruckus_unleashed folder to my home folder and rebooted. I received the Error: Setup failed for ruckus_unleashed: Integration not found Once I moved the original ruckus_unleashed back and rebooted, all worked as per before. EDIT2: I trashed the device_tracker.py file in the custom_componets file, to brute force test if I’m using your new engine, restarted and everything is working as per before … I think I can safely say, I’m not using your rewritten integration: I’ll go research how to manually add a custom component 😃 EDIT3: So, I replaced the original /usr/src/homeassistant/homeassistant/components/ruckus_unleashed folder with the contents from your repo, and received the following error: Setup failed for ruckus_unleased: No setup or config entry setup function defined.
Time for me do undo my attempts and work with what little I understand at the moment. It feels like I’m trying to repair a pocket watch with a sledgehammer 😃
EDIT4: I promise I’ll internalise my journey going forward and leave the dialogue to those with talent… However, to clarify my failings, the root cause of my problems was mistyping
__init__.pyas_init_.pyUpon correcting the mistake, the logs show the following:Followed shortly after by
2023-06-25 05:34:18.055 DEBUG (MainThread) [homeassistant.components.ruckus_unleashed] Finished fetching ruckus_unleashed data in 0.658 seconds (success: True)EDIT5: Wooo! Apologies, but I persist with my sad rambling in the vain hope some other muppets frustrated google search results in a simple forehead slap and not hours of d*cking around with their slightly blunter sledgehammer So, as per the error thrown above, I appended a version number to the
custom_componets/ruckus_unleasged/manifest.json file…and voila - I was hit with masses of errors for trashing the device_tracker.py file earlier. I recopied the device_tracker.py file, and after a final reboot, a yellow “Custom Integration” icon appeared on my Ruckus Unleashed Integration. I have ADDed a HUB, with the ability to ADD more HUBs! 😃 (The text input boxes inside the ADD HUB popup were not labelled ip/user/pw - but thats probably just me mistyping something) My Device Trackers are all responding perfectly. Thank You!
If anyone wants a simpler solution to get this integration working until we have the correct test coverage to get my PR merged, you can clone my repo/branch and mount the
ruckus_unleashedfrom my repo’s components folder into yourcustom_componentsfolder to have it override the built in broken integration.This is what I have been doing for the past few weeks and its been incredibly stable.
One way to workaround this issue is by installling pexpect from the ‘master’ branch:
Here’s an example from an Ansible role that works around this issue:
I can confirm that downgrading HA core to v2023.5.4 restores the Ruckus Unleashed integration.
Sorry team. I changed the AP unique id in one PR and then fixed this in a second PR.
But they only took my first PR into this month’s release.
So I guess when the 2nd PR goes in next week then you’ll need to delete and re-add the AP again.
On Tue, 26 Sept 2023, 05:15 Coder84619, @.***> wrote:
I’m trying it out and it looks like something’s wrong with the UI at least :
That said, I think it found everything that’s on my wifi very quickly, it even turned some of them into entities when it found matching entities already and it did automagicly set the room these entities are in already… hass magic happening again.
Took me less than 10 mins to do, don’t know why it took me weeks between seeing your comments and trying it out, thanks a lot to @lanrat for the dev and @faithless01 for the quick quide
FYI, just in case, my strings.json in the cusom component has this :
FWIW, the aioruckus integration seems great here. It was a seamless drop in replacement. It survive an update to 2023.7 just fine. For the 5 minutes of effort yeah, I’d very much encourage folks to install it and rest easy until the rejigger is accepted.
I’ll put some time into this tomorrow. I’ll add a note to specifically trace through this situation.
Thanks @andornaut No need to troubleshoot, as monkey patching the _async.py file is currently working. I received the following errors when I clobbered pexpect with the master branch after the last core and OS updates:
Install procedure, as per previous working method:
I’ll try to clobber the pexpect library with the master branch again, after the next core/os release and see how it goes. Thanks again - fantastic community!
Massive thank you to @lanrat and @ms264556 for pushing the aioruckus integration PR. (98% there!) I’m struggling to follow the process, but am learning a lot watching you guys work. Thank You.
For anybody still relying on the current broken integration in the interim, (perhaps having automations based on presence detection of wifi devices), you can still mend the broken implementation, using @Bubbgump209 's monkey patched _async.py file above.
The solution from @andornaut to clobber the pexpect library with the master branch has not worked in the last OS update, providing a different set of error messages. (Maybe just me?)
Unfortunately, for those running HASSOS, there is a challenge gaining access to the ‘broken’ Python libraries. While this can be performed relatively easily from a terminal shell, retyping the monkey patched file without copy/paste can be tedious.
Copy / Paste is straight forward in SSH, and can be accessed easily from your own Host OS, as with a Core, Containered or Supervised installation of Home Assistant.
If however, you are running the HASSOS implementation natively on a Pi, or virtualised in VMware or Proxmox, the native SSH Add-On, drops you into its own docker container, with no access to the Core Container, meaning no access to the ‘broken’ pythin libraries. The following Add-On from @adamoutler provides an SSH session to the host OS, where you can jump up to the Home Assistant Core Docker container, and cut and paste the monkey patch over the broken _async.py file https://community.home-assistant.io/t/add-on-hassos-ssh-port-22222-configurator/264109
Again - thanks to those higher up the tree that are making this work.
For sure if you have a good plan/link for best-practices mocking then I’ll have a go.
But you should definitely be able to mock [sub?]adequately as-is. I whacked the following classes into my test __init__.py:-
then I was able to throw in some quick’n’dirty mocks for a few methods:-
(edited to add login and close methods, since you directly use these)
Honestly, I didn’t 100% understand what HA required to be tested, so I failed miserably at that part of the PR.
@ms264556 I’ve pushed my current WIP changes to my fork here: https://github.com/lanrat/hass_core/tree/ruckus_unleashed_py3.11
Nevermind. I can repro the issue if I try to call
AjaxSession.async_create()directly instead of using it as an async context manager.Let me work up some code which works in that way.
Otherwise I’ll create a new aioruckus release which includes a non-async context, so this usage will work OK.
It was against an older version of aioruckus, which looked quite different (actually, looked quite like your current code 😀), and I killed it when I got feedback that the tests were no good and I should update pyruckus rather than start a new library.
You can see my attempt here:-
https://github.com/home-assistant/core/compare/dev...ms264556:home-assistant-core:ruckus_unleashed_updates
aioruckus looks better than my code and is what I think would be a good path forward.
I can start a draft PR to move this component to it, unless @ms264556 wants to do it.
@ms264556 You did a great job. If use ssh cli, there are some limitation. For example, can not set block clients in system acl-list. Your solution can do. This help me to solve to create a switch by blocking client.
I’ve been working on a python library to parse connected clients from Ruckus Unleashed APs using the web API, instead of scraping the SSH output like
pyruckusdoes. So far I’ve only tested it with my R500 and R600, but if anyone else wants to help me test it, it should be far more stable thanpyruckusand I can submit a PR to use it here.https://github.com/lanrat/ruckus-clients
@faithless01 as I explained above, this is an issue with upstream Python. Python changed how they do things in newer versions. And turn this broke Pexpect which is a library that all these integrations are using to facilitate SSH and pulling back data structures. Pexpect is a generally available Python library and has no relation whatsoever to Home Assistant. Interestingly enough the master branch is ahead of the 4.8 release though still reports as 4.8. Otherwise it would be a very simple fix - bump the version requirement in pyruckus.
So see above as far as what the options are. Wait for pexpect to merge the fix and put out a new release (4.9?), rewrite the integration to use different libraries, or monkey patch while waiting.
I’m running Home Assistant in a Docker container. A similar approach should work for a HassOS installation, but I haven’t used HassOS myself, sorry.
@andornaut You’re a god. I was about to start creating a playbook for this as I have a feeling this won’t be fixed upstream for quite some time.
The issue is 100% in pexpect within _async.py. I monkey patched _async.py to
/usr/local/lib/python3.11/site-packages/pexpect/_async.py
This works perfectly. The bigger issue seems to be upstream. There is some blocker in pexpect where they are waiting for Pypy to get updated so that unit tests will pass. Here’s the Pypy issue https://foss.heptapod.net/pypy/pypy/-/issues/3931 which is blocking the pexpect issue https://github.com/pexpect/pexpect/pull/732.
Essentially this is a bit of dependency hell.
The quick fix is my monkey patch if folks feel comfortable running a shell into the homeassistant container. EDIT: Understand, if you do monkey patch, you’ll need to monkey patch after every HA upgrade until the upstream is fixed as the new container will nuke the change. /EDIT.
The longer fix is wait for the whole dependency deal to work itself out OR rewrite the integration to use an alternative to pexpect (Fabric?) that is better maintained OR fork pyexpect… or 100 other work arounds.
Related issue on pyruckus