juju-run gives a poor error when the unit is ambiguous

Bug #1946809 reported by James Troup
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Triaged
High
Unassigned

Bug Description

juju-run --help claims that you can pass an empty string to -u, but this doesn't appear to be true.

| root@grafana-1:~# juju-run --help

[...]

| If the there's one and only one unit on this host, <unit-name>
| is automatically inferred and the positional argument is not needed.
| If -u is passed an empty string, this behaviour is also observed.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| Examples:
| juju-run app/0 hostname -f
| juju-run --no-context -- hostname -f
| juju-run "hostname -f"
| juju-run -u "" -- hostname -f
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| juju-run -u app/0 "hostname -f"
| juju-run -u app/0 -- hostname -f
|
| The commands are executed with '/bin/bash -s', and the output returned.
| root@grafana-1:~# juju-run -u "" -- hostname -f
| ERROR no unit
| root@grafana-1:~#

tags: added: ju-10
tags: added: ju-19
tags: removed: ju-10 ju-19
Revision history for this message
Joseph Phillips (manadart) wrote :

This appears to be the help for a plugin. I've marked it invalid for the Juju project.

Changed in juju:
status: New → Invalid
Revision history for this message
John A Meinel (jameinel) wrote :

This isn't a plugin, this is /usr/bin/juju-run which we create for things like Cron to be able to create a unit hook context and run a script as that unit.
eg:
```
$ juju ssh 0
ubuntu@juju-883c05-0:~$ juju-run --help
Usage: juju-run [options] [-u] [<unit-name>] <commands>

Summary:
run commands in a unit's hook context

Options:
--force-remote-unit (= false)
    run the commands for a specific relation context, bypassing the remote unit check
```

Which has both:
```
-u (= "-")
    explicit unit-name, all other arguments are commands. if -u is passed an empty string, unit-name is inferred from state
```
and
```
If the there's one and only one unit on this host, <unit-name>
is automatically inferred and the positional argument is not needed.
If -u is passed an empty string, this behaviour is also observed.
```

Note, though, that on my test instance it does work:
root@juju-883c05-0:~# juju-run -u "" -- echo hello
hello

But note the caveat: *If there is one and only one unit*.

If you are on a machine with subordinates, etc, then it cannot detect which unit you want, because it is ambiguous.

Changed in juju:
importance: Undecided → High
milestone: none → 2.9-next
status: Invalid → Triaged
Revision history for this message
John A Meinel (jameinel) wrote :

I think the actual fix is that: "ERROR no unit" is a bad error message, and should instead be something like: "ERROR unit is ambiguous, could be one of 'a', 'b', 'c'

summary: - juju-run --help output contains invalid example
+ juju-run gives a poor error when the unit is ambiguous
Ian Booth (wallyworld)
Changed in juju:
milestone: 2.9-next → none
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.