home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.12k stars 29.17k forks source link

ADS integration Exec format error on latest docker #74067

Open jandeschuttere opened 2 years ago

jandeschuttere commented 2 years ago

The problem

When starting the latest docker on a raspberry pi 4 the ADS integration seems to be broken, sounds like a build problem targeting the wrong architecture.

I've had a couple of issues (like MySql 8 suddenly requiring the mysql_native_password plugin instead of the previously already working caching_sha2_password) which I was able to work around but this one is blocking for me as it completely breaks the integration with my Beckhoff which is at the heart of my home control.

Labels provided through this image are:

"io.hass.arch": "armv7",
"io.hass.base.arch": "armv7",
"io.hass.base.image": "homeassistant/armv7-base:3.16",
"io.hass.base.name": "python",
"io.hass.base.version": "2022.06.0",
"io.hass.machine": "raspberrypi4",
"io.hass.type": "core",
"io.hass.version": "2022.7.0.dev20220627",
"org.opencontainers.image.authors": "The Home Assistant Authors",
"org.opencontainers.image.created": "2022-06-27 03:32:54+00:00",
"org.opencontainers.image.description": "Open-source home automation platform running on Python 3",
"org.opencontainers.image.documentation": "https://www.home-assistant.io/docs/",
"org.opencontainers.image.licenses": "Apache License 2.0",
"org.opencontainers.image.source": "https://github.com/home-assistant/core",
"org.opencontainers.image.title": "Home Assistant",
"org.opencontainers.image.url": "https://www.home-assistant.io/",
"org.opencontainers.image.version": "2022.7.0.dev20220627"

Labels of the image that is still working for me:

"io.hass.arch": "armv7",
"io.hass.base.arch": "armv7",
"io.hass.base.image": "homeassistant/armv7-base:3.14",
"io.hass.base.name": "python",
"io.hass.base.version": "2022.02.0",
"io.hass.machine": "raspberrypi4",
"io.hass.type": "core",
"io.hass.version": "2022.6.0.dev20220506",
"org.opencontainers.image.authors": "The Home Assistant Authors",
"org.opencontainers.image.created": "2022-05-06 03:33:40+00:00",
"org.opencontainers.image.description": "Open-source home automation platform running on Python 3",
"org.opencontainers.image.documentation": "https://www.home-assistant.io/docs/",
"org.opencontainers.image.licenses": "Apache License 2.0",
"org.opencontainers.image.source": "https://github.com/home-assistant/core",
"org.opencontainers.image.title": "Home Assistant",
"org.opencontainers.image.url": "https://www.home-assistant.io/",
"org.opencontainers.image.version": "2022.6.0.dev20220506"

What version of Home Assistant Core has the issue?

core-2022.7.0.dev20220627

What was the last working version of Home Assistant Core?

core-2022.6.0.dev20220506

What type of installation are you running?

Home Assistant Container

Integration causing the issue

ADS

Link to integration documentation on our website

https://www.home-assistant.io/integrations/ads/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

These is just one snippet of the many similar issues reported, figured this stacktrace is sufficient:

ERROR (MainThread) [homeassistant.config] Platform error: light
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 618, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 635, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/ads/__init__.py", line 10, in <module>
    import pyads
  File "/usr/local/lib/python3.10/site-packages/pyads/__init__.py", line 12, in <module>
    from .ads import open_port, close_port, get_local_address, read_state, \
  File "/usr/local/lib/python3.10/site-packages/pyads/ads.py", line 18, in <module>
    from .pyads_ex import (
  File "/usr/local/lib/python3.10/site-packages/pyads/pyads_ex.py", line 82, in <module>
    _adsDLL = ctypes.CDLL(adslib)
  File "/usr/local/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: Error loading shared library /usr/local/lib/python3.10/site-packages/pyads/adslib.so: Exec format error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config.py", line 877, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 627, in get_platform
    raise ImportError(
ImportError: Exception importing homeassistant.components.ads.light


### Additional information

_No response_
probot-home-assistant[bot] commented 2 years ago

ads documentation ads source (message by IssueLinks)

jorenreynders commented 2 years ago

Same issue on the raspberry pi 4 running Home Assistant OS. Had to revert back to 2022.6.7

jandeschuttere commented 2 years ago

I have to still look further into the problem - time.. you precious thing - as I'm afraid this plugin has less usage and therefor less priority.

From what I gather it looks like the internals use https://github.com/stlehmann/pyads and the issues could be related to the python 3.10 upgrade

jandeschuttere commented 2 years ago

so looks like /usr/local/lib/python3.10/site-packages/pyads/adslib.so is indeed an x86-64 type, as identified via file

/usr/local/lib/python3.10/site-packages/pyads/adslib.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, with debug_info, not stripped

meaning this is incorrectly packaged with an arm container, can this be looked into?

jandeschuttere commented 2 years ago

For those looking for a (dirty) workaround the package from the working version is compatible it seems with the new release. Assuming you are using docker the following steps might help you out until this gets a fix:

Given: containerA is the name of your working container, containerB is the name of the new container with the faulty adslib.

docker cp containerA:/usr/local/lib/python3.9/site-packages/pyads /tmp
docker stop containerA
docker start containerB
docker cp /tmp/pyads containerB:/usr/local/lib/python3.10/site-packages/
docker restart containerB

If you are not using docker, the digest is basically.. take the pyads lib from the working version, copy it in the location that the new homeassistant build is using.

jandeschuttere commented 2 years ago

@frenck sorry to tag you personally but as you have ads integration tagged in recent PR https://github.com/home-assistant/core/pull/74522 I just wanted to check if above was solved through that PR? (the PR changes were simply too big for sieving through)

reib3n commented 1 year ago

For those looking for a (dirty) workaround the package from the working version is compatible it seems with the new release. Assuming you are using docker the following steps might help you out until this gets a fix:

Given: containerA is the name of your working container, containerB is the name of the new container with the faulty adslib.

docker cp containerA:/usr/local/lib/python3.9/site-packages/pyads /tmp
docker stop containerA
docker start containerB
docker cp /tmp/pyads containerB:/usr/local/lib/python3.10/site-packages/
docker restart containerB

If you are not using docker, the digest is basically.. take the pyads lib from the working version, copy it in the location that the new homeassistant build is using.

I tried to get the workaround working for me without docker, but it seems the directory is not there you described. There is no python3.9 folder. I am using core 2022.06.7 an got access with the Terminal & SSH Addon. May you give me a hint what I am doing wrong?

Thanks a lot.

jandeschuttere commented 1 year ago

I've not tried the core installation but according to the information it is using the python venv method. You could identify the locations python is using by doing python -m site or python -m site --user-site and go through the listed directories to find the pyads site-package. Once you've found this you could copy it (you could use scp or rsync for this if using a terminal and the installation is remote) to your local system and identify the location of the pyads site-package on the new installation and move them there.

reib3n commented 1 year ago

I've not tried the core installation but according to the information it is using the python venv method. You could identify the locations python is using by doing python -m site or python -m site --user-site and go through the listed directories to find the pyads site-package. Once you've found this you could copy it (you could use scp or rsync for this if using a terminal and the installation is remote) to your local system and identify the location of the pyads site-package on the new installation and move them there.

Thanks for the hints, but this doesn't worked for me either.

I got the workaround now working with the Add-on: SSH & Web Terminal.

With this Add-on I could connect to HassOS via SSH and use the "docker" workaround described above.

Thanks a lot guys! hopefully this will be fixed soon!

zimbrich commented 1 year ago

I don't have much experience with Python, but I have a ton of experience with ADS communications and all things TwinCAT-related. Let me know if I can be of any assistance in fixing this issue.

jandeschuttere commented 1 year ago

Thanks for reaching out! From what I gather this is a build issue on this project instead of having an actual issue with the library or the communication itself. Mainly because the library provided is bundled but is simply targeting the wrong cpu architecture and switching to the right one causes no issues.

I have scavanged a bit through the various repositories of this project to see if I can identify the build process itself to see if I can spot an issue there (f.i. a cache layer of some sorts during the build process) but have not yet found it.

Jeroen45 commented 1 year ago

I am not able to find this location : /usr/local/lib/python3.9/site-packages/pyads Can some one help me, Im running HassIO I do have: /usr/local/lib but no python folder

jandeschuttere commented 1 year ago

https://github.com/home-assistant/core/issues/74067#issuecomment-1216265836 might be able to help you locate the packages that your installation is using

it will show the base directory/directories in which python is running, one of them should have a subdirectory pyads

reib3n commented 1 year ago

I am not able to find this location : /usr/local/lib/python3.9/site-packages/pyads Can some one help me, Im running HassIO I do have: /usr/local/lib but no python folder

I got the same issue at first. I needed to use for the ssh connection the SSH & Web Terminal Addon with disabled protection mode. After that I could locate the directory

Bildschirmfoto 2022-09-15 um 13 24 24
Jeroen45 commented 1 year ago

I am not able to find this location : /usr/local/lib/python3.9/site-packages/pyads Can some one help me, Im running HassIO I do have: /usr/local/lib but no python folder

I got the same issue at first. I needed to use for the ssh connection the SSH & Web Terminal Addon with disabled protection mode. After that I could locate the directory Bildschirmfoto 2022-09-15 um 13 24 24

Unfortunately i dont have version 12.0.2. but 9.6.1 and i don't have the protection mode option

reib3n commented 1 year ago

I am not able to find this location : /usr/local/lib/python3.9/site-packages/pyads Can some one help me, Im running HassIO I do have: /usr/local/lib but no python folder

I got the same issue at first. I needed to use for the ssh connection the SSH & Web Terminal Addon with disabled protection mode. After that I could locate the directory Bildschirmfoto 2022-09-15 um 13 24 24

Unfortunately i dont have version 12.0.2. but 9.6.1 and i don't have the protection mode option

Its from the Community Addon Store. I couldnt use the "official" Addon and got the same issue as you with it.

Bildschirmfoto 2022-09-15 um 14 26 21
Jeroen45 commented 1 year ago

i have the addon installed, what next? I still only see the /usr/local/lib and no more. Do i need to login to a higher level, docker?

jandeschuttere commented 1 year ago

What is the output of python -m site and python -m site --user-site when you are logged in through ssh?

maybe a faster way is the next few lines, each line is after an enter. After the first one you will enter the interactive shell of python and each line will be prefixed with >>> so don't be alarmed

python
import pyads
print(pyads.__file__)
exit()

the print action will show you a location, in my current case this prints/usr/local/lib/python3.10/site-packages/pyads/__init__.py .. this could be different in your case. More importantly, this tells you where the package is situated, in this case that means /usr/local/lib/python3.10/site-packages/pyads .. that is the directory you can use to move the working pyads into a home assistance version that has the corrupted pyads

reib3n commented 1 year ago

i have the addon installed, what next? I still only see the /usr/local/lib and no more. Do i need to login to a higher level, docker?

Do you have disabled the protection mode? What core version are you running right now?

Jeroen45 commented 1 year ago

Yes protection is disabled. Home Assistant 2022.9.4 Supervisor 2022.08.6 Operating System 9.0 Frontend-versie: 20220907.2 - latest

reib3n commented 1 year ago

Yes protection is disabled. Home Assistant 2022.9.4 Supervisor 2022.08.6 Operating System 9.0 Frontend-versie: 20220907.2 - latest

are you using the "docker" command to copy the file in the container (container name: homeassistant) like this? docker cp /backup/pylib/pyads homeassistant:/usr/local/lib/python3.10/site-packages/

Jeroen45 commented 1 year ago

When i try: python -m site I get command not found

Jeroen45 commented 1 year ago

What is the output of python -m site and python -m site --user-site when you are logged in through ssh?

I get : command not found I am logged in thru the addon: ssh & WebTerminal

reib3n commented 1 year ago

@Jeroen45: have you tried to copy the files with the docker command within the homeassistant container I mentioned bevor?

Jeroen45 commented 1 year ago

I am almost there to log in with HassOS SSH port 22222 Configurator to get to the root level

alemonta commented 1 year ago

@Jeroen45 I have the same issue, can't log with enough rights, so neither python commands nor python folder is available: anyhow I fixed my setup with the docker commands just like @C0D3-IT was suggesting as originally posted by @jandeschuttere (by the way, thank you very much!)

Jeroen45 commented 1 year ago

@Jeroen45 I have the same issue, can't log with enough rights, so neither python commands nor python folder is available: anyhow I fixed my setup with the docker commands just like @C0D3-IT was suggesting as originally posted by @jandeschuttere (by the way, thank you very much!)

I am not able to go outside the docker to the root, to do the docker commands just like @C0D3-IT and @jandeschuttere. Still looking into this

Jeroen45 commented 1 year ago

Please help, i am not a python programmer. I am not able to go outside the HA docker. I have monitor, keybord connected to my Raspberry pi4. How can i find the path to where the python is installed?

jandeschuttere commented 1 year ago

I'm afraid I'm not acquainted with HassOS myself, to be able to fix the issue it's a requirement to get access to the python runtime executing home assistant so that you can copy the working python code specifically for this functionality to replace the faulty one. I guess the home assistant community forum will have had similar questions (how to get into to the root system hassOS is running in), or is at least a bigger chance for you to be able to find someone who has such experience.

Once you are able to have that (basically see that python is a supported command) you have all information in this thread on how to find the path where you can find that library. If you are at that point and you do not seem to be able to copy it over, give a shout and I'm happy to support you further given the circumstance you are in at that point (please add some explanation of the situation in that case, if no docker is in play in this case I would go for an option like using scp which is a very common way to transfer files between servers)

Jeroen45 commented 1 year ago

Thanks for the help... Lot of learning for me.. will be continued.

KCU1976 commented 1 year ago

@Jeroen45 I'm far from a specialist, but I think you're tying to find / execute the python things in the SSH docker. Try using this post to gain access to the actual home assistant docker where python is installed. Basically: log in with SSH and execute this command: docker exec -it HomeAssistant bash Now you'll be able to find python and pyads.

I'm having the same issue and it took me several hours to come to this point, basically because I was unaware Home Assistant runs in a docker container in the OS. Now all I need is a working version of the pyads folder (preferably without first reverting to the old version of Home assistant OS)

KCU1976 commented 1 year ago

Question: is there a way to get access to the files of the HomeAssistant container through the samba add-on, or would I need to install samba in the container? Would that be OK to do? (It would be much easier to just copy the files from one PI to another using my pc...

jandeschuttere commented 1 year ago

The files in the end need to be in the system running home assistant (the system running python basically). So if you are using a container that would mean it needs to be inside the container.

However, if you are running a container, nothing is stopping you from specifying a volume mount to that directory from your host system, which is how I'm doing it now. That makes managing the samba share much easier in your case.

and ofc, stressing that this is all to alleviate a build issue, once that is been solved all of this is ofc no longer required. I have not yet found where it actually is going wrong though, I'm not so familiar with the home assistant build system, or python build systems in general

KCU1976 commented 1 year ago

However, if you are running a container, nothing is stopping you from specifying a volume mount to that directory from your host system, which is how I'm doing it now. That makes managing the samba share much easier in your case.

Nothing except a general lack of knowledge of Linux-based OS'es and docker containers :-) It's time to expand my knowledge on this. I'll give it a try later this week. Thanks a lot for your kind reply.

Jeroen45 commented 1 year ago

I connected a monitor and keybord, i can find the /usr/local/lib/python3.9/site-packages/pyads folder. But where to store these files to later copy them into the /usr/local/lib/python3.10/site-packages/pyads folder

jandeschuttere commented 1 year ago

you could scp/rsync it to a computer on the network and when upgraded, move it back.. not sure if any other directories will not be touched by this, hence the "be sure" approach

Jeroen45 commented 1 year ago

Yes, i managed to kopie the files to a folder on my laptop, using Winscp. copied them back to the python3.10 folder. ADS is working now. Many many thanks to you guys...

KCU1976 commented 1 year ago
Never mind - solved the issue by restoring an old version and copying the pyads folder form there.
issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

reib3n commented 1 year ago

I updates right now to 2022.12.9 and the bug is still there. Only the mentioned workaround above works, but we will see how long.

Maybe somebody with the knowledge about the pylib generation can fix this finally? That would be great!

alemonta commented 1 year ago

As @C0D3-IT wrote above, neither 2022.12.9 fixes: the workaround does. As evaluated by other users (much more skilled than I am about it, for sure!), the problem resides into the management of pyads with the latest (June 2022?) wheels package management: https://github.com/home-assistant/wheels-custom-integrations/issues/651 could somebody help, please?!?

gibii88 commented 1 year ago

I updates right now to 2022.12.9 and the bug is still there. Only the mentioned workaround above works, but we will see how long.

Maybe somebody with the knowledge about the pylib generation can fix this finally? That would be great!

Could you explain me better which one is it your work arround?

mbed01 commented 1 year ago

Did someone find solution for this issue??

I found that in manifest file there is pyads ==3.2.2 image

Last pyads version is 3.3.9, maybe old version is imported and is not supported python 3.10.

jandeschuttere commented 1 year ago

I'll try to find some time to investigate that breadcrumb this evening or the coming days, that might indeed be an interesting path to explore! 👍 (or if someone is already doing so, by all means let it be known so we're not both spending time ;-))

alemonta commented 1 year ago

I updates right now to 2022.12.9 and the bug is still there. Only the mentioned workaround above works, but we will see how long. Maybe somebody with the knowledge about the pylib generation can fix this finally? That would be great!

Could you explain me better which one is it your work arround?

as soon as you have an older working copy of pyads folder (it was ok till 2022.05, for sure) you can back-up it: after updating to lastest homeassistant version, you can override the new non-working pyads folder with the older one you backed-up.

I took the docker commands to backup/override the pyads folders from here: https://github.com/home-assistant/core/issues/74067#issuecomment-1179256015

more details here: https://github.com/home-assistant/core/issues/74952#issuecomment-1404854509

jandeschuttere commented 1 year ago

While wanting to test this I pulled in the latest docker image provided for home assistant (image tag f0af2244da02) I do not have any issues atm. Although the adslib.so file that is introduced for the pyads module is stil x86_64

Can anyone else verify as well that I'm not having a fluke on my end?

mbed01 commented 1 year ago

Still doesn't work for me.

I have RP4 Home Assistant 2023.2.0b3 Supervisor 2023.01.1 Operating System 9.5

and below log: image

BartDurnez commented 1 year ago

Can anyone else verify as well that I'm not having a fluke on my end?

Updatet my HA core to 2023 version and still not working. Had to copy the old working folder to make everything working again, as described in this post

gibii88 commented 1 year ago

Yes, i managed to kopie the files to a folder on my laptop, using Winscp. copied them back to the python3.10 folder. ADS is working now. Many many thanks to you guys...

@Jeroen45 could you explain how you connect via Winscp? I'm connected but i'm not able to find the python folder

jandeschuttere commented 1 year ago

Still doesn't work for me.

Thank you for checking, will check why mine isn't causing any issues and try to re-iterate on the possible solution that was identified. I'm not able to commit to this in the next few days however, I'll plan something in during next week 👍