Skip to content

ArgoCD Blueapi pod login fails #1448

@oliwenmandiamond

Description

@oliwenmandiamond

When using blueapi from the ArgoCD pod terminal connected to k8 and trying to login, it fails:

ubuntu@i09-k8s-serv-01:/app/.venv/lib$ blueapi login
Traceback (most recent call last):
  File "/app/.venv/lib/python3.11/site-packages/blueapi/cli/cli.py", line 491, in login
    auth: SessionManager = SessionManager.from_cache(config.auth_token_path)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/blueapi/service/authentication.py", line 92, in from_cache
    cache = cache_manager.load_cache()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/blueapi/service/authentication.py", line 55, in load_cache
    with open(self._file_path, "rb") as cache_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/.cache/blueapi_cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.venv/bin/blueapi", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/click/core.py", line 1485, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/click/core.py", line 1406, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/click/core.py", line 1873, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/click/core.py", line 1269, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/click/core.py", line 824, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/click/decorators.py", line 46, in new_func
    return f(get_current_context().obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/blueapi/cli/cli.py", line 215, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/blueapi/cli/cli.py", line 501, in login
    auth.start_device_flow()
  File "/app/.venv/lib/python3.11/site-packages/blueapi/service/authentication.py", line 199, in start_device_flow
    assert self._cache_manager.can_access_cache()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.11/site-packages/blueapi/service/authentication.py", line 74, in can_access_cache
    self._token_path.write_text("")
  File "/python/cpython-3.11.14-linux-x86_64-gnu/lib/python3.11/pathlib.py", line 1078, in write_text
    with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/python/cpython-3.11.14-linux-x86_64-gnu/lib/python3.11/pathlib.py", line 1044, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/.cache/blueapi_cache'
ubuntu@i09-k8s-serv-01:/app/.venv/lib$ 

It fails because the path .cache folder doesn't exist.

ubuntu@i09-k8s-serv-01:~$ ll -a
total 12
drwxr-x---. 2 ubuntu ubuntu   57 Feb 10 14:12 ./
drwxr-xr-x. 3 root   root     20 Feb 10 14:12 ../
-rw-r--r--. 1 ubuntu ubuntu  220 Mar 31  2024 .bash_logout
-rw-r--r--. 1 ubuntu ubuntu 3771 Mar 31  2024 .bashrc
-rw-r--r--. 1 ubuntu ubuntu  807 Mar 31  2024 .profile
ubuntu@i09-k8s-serv-01:~$ 

If I create the .cache folder, it now works!

ubuntu@i09-k8s-serv-01:~$ mkdir .cache
ubuntu@i09-k8s-serv-01:~$ ll -a
total 12
drwxr-x---. 1 ubuntu ubuntu   20 Mar 20 13:53 ./
drwxr-xr-x. 1 root   root     20 Feb 10 14:12 ../
-rw-r--r--. 1 ubuntu ubuntu  220 Mar 31  2024 .bash_logout
-rw-r--r--. 1 ubuntu ubuntu 3771 Mar 31  2024 .bashrc
drwxr-xr-x. 2 ubuntu ubuntu   27 Mar 20 13:53 .cache/
-rw-r--r--. 1 ubuntu ubuntu  807 Mar 31  2024 .profile
ubuntu@i09-k8s-serv-01:~$ blueapi login
Logging in
Please login from this URL:- https://identity.diamond.ac.uk/realms/dls/device?user_code=LNVI-MPUB
Logged in and cached new token

The authentication code in BlueAPI should create the .cache folder if it doesn't already exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions