cannot set multi-line relation data values via juju-run

Bug #1870438 reported by Andrea Ieri
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Fix Released
High
Harry Pidcock

Bug Description

I am trying to override monitors relation data to remove a nrpe check.

The value of this key is multi-line yaml:

$ juju run -u nrpe/2 -- relation-get -r77 - keystone/2
egress-subnets: 10.0.8.36/32
ingress-address: 10.0.8.36
monitors: |
  monitors:
    remote:
      nrpe:
        apache2: {command: check_apache2}
        haproxy: {command: check_haproxy}
        haproxy_queue: {command: check_haproxy_queue}
        haproxy_servers: {command: check_haproxy_servers}
        memcached: {command: check_memcached}
primary: "True"
private-address: 10.0.8.36

I have saved the value of the 'monitors' key in a local file, and removed the check I don't want:

$ cat /tmp/monitors.yaml
monitors:
  remote:
    nrpe:
      apache2: {command: check_apache2}
      haproxy: {command: check_haproxy}
      haproxy_queue: {command: check_haproxy_queue}
      haproxy_servers: {command: check_haproxy_servers}

I now want to inject this updated data via relation set. The odd thing is this:

== Works perfectly:

$ juju run -u keystone/2 -- relation-set -r77 monitors="$(cat /tmp/monitors.yaml)"

== Fails:

$ juju scp /tmp/monitors.yaml keystone/2:/tmp
$ juju ssh keystone/2 -- sudo -i

$ juju-run -r77 keystone/2 relation-set monitors="$(cat /tmp/monitors.yaml)"
ERROR unrecognized args: ["monitors=monitors:\n remote:\n nrpe:\n apache2: {command: check_apache2}\n haproxy: {command: check_haproxy}\n haproxy_queue: {command: check_haproxy_queue}\n haproxy_servers: {command: check_haproxy_servers}"]

$ juju-run -r77 keystone/2 relation-set monitors=$(cat /tmp/monitors.yaml)
ERROR unrecognized args: ["monitors=monitors:" "remote:" "nrpe:" "apache2:" "{command:" "check_apache2}" "haproxy:" "{command:" "check_haproxy}" "haproxy_queue:" "{command:" "check_haproxy_queue}" "haproxy_servers:" "{command:" "check_haproxy_servers}"]

I would expect relation-set to work in the same way both when invoked from within the unit (via juju-run) and from outside of the unit (via juju run). Am I doing something wrong?

In case it matters, this happend on both juju 2.7.3 and 2.7.5.

Andrea Ieri (aieri)
description: updated
Revision history for this message
John A Meinel (jameinel) wrote : Re: [Bug 1870438] Re: cannot set multi-line relation data values via juju-run
Download full text (4.3 KiB)

'juju-run' as currently written takes a single argument to run, so the
entire thing needs to be quoted.eg:

$ juju-run -r77 keystone/2 'relation-set monitors=CONTENT'

From code:
        if len(args) < 1 {
                return fmt.Errorf("missing commands")
        }
        c.commands, args = args[0], args[1:]
        return cmd.CheckEmpty(args)

^ that last is saying 'the command to run is a single argument to
'juju-run' and there must be no further arguments.

In 'juju run' we do:
if len(args) == 1 {
  // If just one argument is specified, we don't pass it through
  // utils.CommandString in case it contains multiple arguments
  // (e.g. juju run --all "sudo whatever"). Passing it through
  // utils.CommandString would quote the string, which the backend
  // does not expect.
  c.commands = args[0]
} else {
  c.commands = utils.CommandString(args...)
}

We should probably do the same for 'juju-run'.

On Fri, Apr 3, 2020 at 6:20 PM Andrea Ieri <email address hidden>
wrote:

> ** Description changed:
>
> I am trying to override monitors relation data to remove a nrpe check.
>
> The value of this key is multi-line yaml:
>
> $ juju run -u nrpe/2 -- relation-get -r77 - keystone/2
> egress-subnets: 10.0.8.36/32
> ingress-address: 10.0.8.36
> monitors: |
> - monitors:
> - remote:
> - nrpe:
> - apache2: {command: check_apache2}
> - haproxy: {command: check_haproxy}
> - haproxy_queue: {command: check_haproxy_queue}
> - haproxy_servers: {command: check_haproxy_servers}
> - memcached: {command: check_memcached}
> + monitors:
> + remote:
> + nrpe:
> + apache2: {command: check_apache2}
> + haproxy: {command: check_haproxy}
> + haproxy_queue: {command: check_haproxy_queue}
> + haproxy_servers: {command: check_haproxy_servers}
> + memcached: {command: check_memcached}
> primary: "True"
> private-address: 10.0.8.36
>
> I have saved the value of the 'monitors' key in a local file, and
> removed the check I don't want:
>
> - $ cat /tmp/monitors.yaml
> + $ cat /tmp/monitors.yaml
> monitors:
> - remote:
> - nrpe:
> - apache2: {command: check_apache2}
> - haproxy: {command: check_haproxy}
> - haproxy_queue: {command: check_haproxy_queue}
> - haproxy_servers: {command: check_haproxy_servers}
> + remote:
> + nrpe:
> + apache2: {command: check_apache2}
> + haproxy: {command: check_haproxy}
> + haproxy_queue: {command: check_haproxy_queue}
> + haproxy_servers: {command: check_haproxy_servers}
>
> I now want to inject this updated data via relation set. The odd thing
> is this:
>
> - # Works perfectly:
> - $ juju run -u keystone/2 -- relation-set -r77 monitors="$(cat
> /tmp/monitors.yaml)"
> + == Works perfectly:
>
> - # Fails:
> + $ juju run -u keystone/2 -- relation-set -r77 monitors="$(cat
> + /tmp/monitors.yaml)"
> +
> + == Fails:
> +
> $ juju scp /tmp/monitors.yaml keystone/2:/tmp
> $ juju ssh keystone/2 -- sudo -i
> - # juju-run -r77 keystone/2 relation-set monitors="$(cat
> /tmp/monitors.yaml)"
> +
> + $ juju-run -r77 keystone/2 relation-set monitors="$(cat
>...

Read more...

Ian Booth (wallyworld)
Changed in juju:
milestone: none → 2.8-rc1
importance: Undecided → High
status: New → Triaged
Harry Pidcock (hpidcock)
Changed in juju:
assignee: nobody → Harry Pidcock (hpidcock)
Revision history for this message
Harry Pidcock (hpidcock) wrote :
Ian Booth (wallyworld)
Changed in juju:
status: Triaged → In Progress
Harry Pidcock (hpidcock)
Changed in juju:
status: In Progress → Fix Committed
Harry Pidcock (hpidcock)
Changed in juju:
status: Fix Committed → Fix Released
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.