neoave / mrack

Multicloud use-case based multihost async provisioner for CIs and testing during development
Apache License 2.0
11 stars 14 forks source link

fix: mrack.conf '~' causes no such file or directory #67

Closed Tiboris closed 3 years ago

Tiboris commented 3 years ago

When ~ is used in path for mrack.conf the later operation open('~/.mrack/mrackdb.json', 'w') fails with an exception FileNotFoundError: [Errno 2] No such file or directory: '~/.mrack/mrackdb.json'

Signed-off-by: Tibor Dudlák tdudlak@redhat.com

pvoborni commented 3 years ago

Isn't this a problem of the consumer of the value? I.e. the DB should handle it, not config. Why have this "magic" in a general get method? But if we want to be really expanding the values in config then it should be done only for the values which are paths.

Btw, the use case presented in this issue is something I'd not recommend to use. Atm, the mrack DB don't have concept of sessions so the DB itself is one session and thus it is not something for sharing.

Tiboris commented 3 years ago

I have moved the expanduser to the open() calls

pvoborni commented 3 years ago

Did not test yet, but the approach looks good to me.

Tiboris commented 3 years ago

Before:

(venv) ➜  venv git:(master) cat mrack.conf 
[mrack]
mrackdb = mrackdb.json
provisioning-config = ~/Work/files/provisioning-config.yaml
(venv) ➜  venv git:(master) file ~/Work/files/provisioning-config.yaml
/home/tdudlak/Work/files/provisioning-config.yaml: ASCII text
(venv) ➜  venv git:(master) mrack up -m ./metadata-f33.yaml 
Provisioning config file not found: ~/Work/idm-ci/files/provisioning-config.yaml
(venv) ➜  venv git:(master) echo $?
1

with this patch:

(venv) ➜  venv git:(master) git co user-path 
Switched to branch 'user-path'
Your branch is up to date with 'origin/user-path'.
(venv) ➜  venv git:(user-path) cat mrack.conf 
[mrack]
mrackdb = mrackdb.json
provisioning-config = ~/Work/idm-ci/files/provisioning-config.yaml
(venv) ➜  venv git:(user-path) file ~/Work/files/provisioning-config.yaml
/home/tdudlak/Work/files/provisioning-config.yaml: ASCII text
(venv) ➜  venv git:(user-path) mrack up -m ./metadata-f33.yaml
OpenStack: Initializing provider
OpenStack: Login duration 0:00:03.698010
^C
Aborted!