canonical / jhack

Chock-full of Juju hackery.
Apache License 2.0
51 stars 24 forks source link

nuke fails with exception #33

Closed beliaev-maksim closed 1 year ago

beliaev-maksim commented 1 year ago

If you run nuke, you get an exception. However, this is an expected error (OR?)

if yes, then traceback should be truncated and only error message left

ubuntu@charm-dev:~$ jhack nuke
ERROR:jhack./snap/jhack/120/lib/python3.8/site-packages/jhack/utils/tail_charms.py:failed to determine model loglevel: not enough values to unpack (expected 2, got 1). Guessing `WARNING` for now.
ERROR:jhack:It seems like the snap doesn't have access to /home/ubuntu/.local/share/juju;to grant it, run 'sudo snap connect jhack:dot-local-share-juju snapd'.Some Jhack commands will still work, but those that interact with the juju client will not.
Traceback (most recent call last):
  File "/snap/jhack/120/bin/jhack", line 8, in <module>
    sys.exit(main())
  File "/snap/jhack/120/lib/python3.8/site-packages/jhack/main.py", line 134, in main
    app()
  File "/snap/jhack/120/lib/python3.8/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/snap/jhack/120/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/snap/jhack/120/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/snap/jhack/120/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/snap/jhack/120/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/jhack/120/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/snap/jhack/120/lib/python3.8/site-packages/typer/main.py", line 500, in wrapper
    return callback(**use_params)  # type: ignore
  File "/snap/jhack/120/lib/python3.8/site-packages/jhack/utils/nuke.py", line 447, in nuke
    _nuke(None, **kwargs)
  File "/snap/jhack/120/lib/python3.8/site-packages/jhack/utils/nuke.py", line 218, in _nuke
    nukeables = [Nukeable(current_model(), "model")]
  File "/snap/jhack/120/lib/python3.8/site-packages/jhack/helpers.py", line 166, in current_model
    return next(filter(key, all_models)).strip("*")
StopIteration
PietroPasotti commented 1 year ago

Hi Maksim, this is not expected. jhack nuke without further arguments will attempt to nuke the current model. However it seems that jhack can't determine which model is current, because of the output of juju status, no model has a trailing "*". Can you confirm that you are running that from a controller that HAS a current model? If so, and you are running it from a snap and a VM, this is probably a duplicate of #30

beliaev-maksim commented 1 year ago

Yes, it had a model

If I remember it right, once I put a model name it worked fine. However, I don't think we need to print the entire traceback when no model is provided

PietroPasotti commented 1 year ago

That's not the issue. The issue is that juju status SHOULD show the current model. The fact that it doesn't, suggests that the process doesn't have access to local/share/juju as it should

beliaev-maksim commented 1 year ago

I cannot reproduce it any more on my environment

PietroPasotti commented 1 year ago

ok, let me know if it comes up again

beliaev-maksim commented 1 year ago

@PietroPasotti I was able to reproduce it.

First, I had 5 models, then I nuked my current model, all is good. However, you see, there is no active model now

ubuntu@charm-dev:~$ juju models
Controller: tutorial-controller

Model        Cloud/Region        Type        Status     Units  Access  Last connection
charm-model  microk8s/localhost  kubernetes  available  2       admin  3 minutes ago
controller   microk8s/localhost  kubernetes  available  1       admin  just now
test         microk8s/localhost  kubernetes  available  -       admin  2023-01-17

then I try to nuke test model, it fails.


ubuntu@charm-dev:~$ jhack nuke test
Traceback (most recent call last):
  File "/snap/jhack/166/bin/jhack", line 8, in <module>
    sys.exit(main())
  File "/snap/jhack/166/lib/python3.8/site-packages/jhack/main.py", line 152, in main
    app()
  File "/snap/jhack/166/lib/python3.8/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/snap/jhack/166/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/snap/jhack/166/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/snap/jhack/166/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/snap/jhack/166/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/jhack/166/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/snap/jhack/166/lib/python3.8/site-packages/typer/main.py", line 500, in wrapper
    return callback(**use_params)  # type: ignore
  File "/snap/jhack/166/lib/python3.8/site-packages/jhack/utils/nuke.py", line 488, in nuke
    _nuke(obj, **kwargs)
  File "/snap/jhack/166/lib/python3.8/site-packages/jhack/utils/nuke.py", line 263, in _nuke
    nukeables = _gather_nukeables(
  File "/snap/jhack/166/lib/python3.8/site-packages/jhack/utils/nuke.py", line 209, in _gather_nukeables
    model or current_model(),
  File "/snap/jhack/166/lib/python3.8/site-packages/jhack/helpers.py", line 187, in current_model
    return next(filter(key, all_models)).strip("*")
StopIteration

next, you switch to any model and rerun nuke, it works.

I could recommend either fixing the error message or automatically switch to another model

PietroPasotti commented 1 year ago

Yeah, unless you're running nuke without arguments, it shouldn't bork because it can't find any current model. That's a bug. Will work on it.

PietroPasotti commented 1 year ago

Should be fixed on edge