drakkar-lig / walt-python-packages

Home of walt-node, walt-server, walt-client and walt-common python packages.
https://walt-project.liglab.fr
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

Rebooting the server while an image is downloaded may cause a problem #57

Closed eduble closed 1 year ago

eduble commented 3 years ago

The download is interrupted but the image is registered in database. From this time, walt service fails to start. See error trace and workaround below.

root@localhost:~# walt-server-daemon

dhcpd conf updated.

iptables v1.8.2 (nf_tables): Chain already exists

** Waiting for companion services to be ready...

** Waiting for companion services to be ready... done

** Ready.

** Scanning walt images...

WARNING: Removing image waltplatform/rpi-3-b-default:latest from db because walt does not have it in its own repo.

server-blocking stopped because of propagated exception.

Exception in thread server-main:

Traceback (most recent call last):

  File "/usr/local/lib/python3.7/dist-packages/walt/common/thread.py", line 27, in run

    self.prepare()

  File "/usr/local/lib/python3.7/dist-packages/walt/server/threads/main/thread.py", line 23, in prepare

    self.server.update()

  File "/usr/local/lib/python3.7/dist-packages/walt/server/threads/main/server.py", line 73, in update

    self.images.update(startup = True)

  File "/usr/local/lib/python3.7/dist-packages/walt/server/threads/main/images/manager.py", line 33, in update

    self.store.refresh(startup)

  File "/usr/local/lib/python3.7/dist-packages/walt/server/threads/main/images/store.py", line 76, in refresh

    self.db.delete('images', fullname = db_fullname)

  File "/usr/local/lib/python3.7/dist-packages/walt/server/postgres.py", line 129, in delete

    self.c.execute(sql, values)

  File "/usr/local/lib/python3.7/dist-packages/psycopg2/extras.py", line 327, in execute

    return super(NamedTupleCursor, self).execute(query, vars)

psycopg2.errors.ForeignKeyViolation: update or delete on table "images" violates foreign key constraint "nodes_image_fkey" on table "nodes"

DETAIL:  Key (fullname)=(waltplatform/rpi-3-b-default:latest) is still referenced from table "nodes".

Workaround: download the image manually and set its ready flag in database:

[root@walt-server]$ podman pull docker.io/waltplatform/rpi-3-b-default:latest
[root@walt-server]$ psql walt
walt=> update images set ready = true where fullname = 'waltplatform/rpi-3-b-default:latest';
walt=> exit
[root@walt-server]$