jo-jstrm / SmartHomeBuddy

GNU General Public License v3.0
4 stars 0 forks source link

Initial shbdeviceidentifier setup does not create table entries for influx user #72

Open TB-DevAcc opened 2 years ago

TB-DevAcc commented 2 years ago

Describe the bug When cloning the repo and setting up the project for development, shbdeviceidentifier start does create the sqlite tables users and influxdb but does not populate them with the necessary entries.

To Reproduce Steps to reproduce the behavior:

  1. Remove all installed files from the SHB project
  2. Clone Repo and setup the dev environment (python, influxdb)
  3. start the identifier, no error is displayed
  4. Check the SQLite db file, which should be empty now

Expected behavior SQLite db should contain at least one user

Desktop (please complete the following information):

TB-DevAcc commented 2 years ago

This should probably already fix the issue: Changing this line

https://github.com/jo-jstrm/SmartHomeBuddy/blob/ac2a7cbe82cee8581b9284479b65db33257afc64/device-identifier/shbdeviceidentifier/db.py#L186

to

elif influxdb_admin.token != None:
TB-DevAcc commented 2 years ago

This should probably already fix the issue: Changing this line

https://github.com/jo-jstrm/SmartHomeBuddy/blob/ac2a7cbe82cee8581b9284479b65db33257afc64/device-identifier/shbdeviceidentifier/db.py#L186

to

elif influxdb_admin.token != None:

Doesn't really fix it, the token stays empty. The question is how to set the token when the setup was run but the database does not contain the token?

jo-jstrm commented 2 years ago

The problem exists, because you already have InfluxDB set up. SHB cannot run the InfluxDB setup on an set up instance. To the best of my knowledge, there is no way to programmatically acquire the admin token from an already set-up InfluxDB instance. This means that you can a) reset InfluxDB (delete ~/.influxdbv2 and rerun SHB, which will then set InfluxDB up and add the admin token to influxdb) or b) look up the admin token in the InfluxDB GUI and add it to the DB manually.

Regarding a): InfluxDB's Setup API allows passing a custom admin token. If not given, it returns an auto-generated token after successful setup. Currently, we do not set a token, so we use the auto-generated one.

When performing a fresh install (no DBs present), the problem should not come up. Also, it should not happen after reinstalling SHB, e.g., after an update, because then both DBs with all relevant data will be present. However, in the future we should probably implement a way to update the token (maybe also username/password) via SHBs GUI...

TB-DevAcc commented 2 years ago

Yes it should not, but it did. I have not setup Influxdb myself, meaning that shbdeviceidentifier must have set up the database but failed somehow. If this happens for a user, requiring him to delete the influxdb directory manually does not seem to be the best solution.

Finding the influxdb data directory and remembering it might be important for the uninstaller anyway, so deleting it programmatically would then be a viable option.

jo-jstrm commented 2 years ago

Oh, ok. Would be interesting to find out why it fails.

Fixing the setup in case of failure would require something like (pseudo code)

def _fix_influxdb_setup():
    if is_influxdb_set_up and is_token_in_sqlite_empty:
        reset_influxdb()
        reset_user_in_sqlite()
        _run_influxdb_setup() # Already exists in db.py:132