Note this is only for juju versions with no leadership election. LE versions of juju skip this code entirely.
When relation_get is called in a non-cluster relation hook and we are checking for *cluster* relation data,
the remote unit is not a peer and the remote unit is ignorant of the data set on the *cluster* relation.
So we use the local unit, which for some reason (possibly a bug) gives us the cluster relation data.
However, when we are in a native cluster relation hook using the local unit gives an empty set (AFAIK always).
So we need to use the remote_unit to get the relation data. In this case cookie, without this rabbit never sees a peer cookie and never clusters.
In rabbit's case it is a chicken/egg problem. The non-leader never gets the peer data in order to echo it.
## Using local unit gets no peer data
# relation-get -r cluster:1 - $JUJU_UNIT_NAME
private-address: 10.5.19.154
## Using remote unit gets peer data
# relation-get -r cluster:1 - $JUJU_REMOTE_UNIT
amqp:2_hostname: 10.5.19.152
amqp:2_password: JXyBbWFXsPZqwSjZXhJmkNLxgC5PnnPWpz9SChqGS6X7MsZKCSp4fzbXTSy9mm53
amqp:2_private-address: 10.5.19.152
cinder.passwd: JXyBbWFXsPZqwSjZXhJmkNLxgC5PnnPWpz9SChqGS6X7MsZKCSp4fzbXTSy9mm53
cookie: GYIRHLPVKCKJHNBLSQRE
private-address: 10.5.19.152
## Relation get by itself also works in a cluster relation
# relation-get
amqp:2_hostname: 10.5.19.152
amqp:2_password: JXyBbWFXsPZqwSjZXhJmkNLxgC5PnnPWpz9SChqGS6X7MsZKCSp4fzbXTSy9mm53
amqp:2_private-address: 10.5.19.152
cinder.passwd: JXyBbWFXsPZqwSjZXhJmkNLxgC5PnnPWpz9SChqGS6X7MsZKCSp4fzbXTSy9mm53
cookie: GYIRHLPVKCKJHNBLSQRE
private-address: 10.5.19.152
## Using local unit gets data
# relation-get -r cluster:1 - $JUJU_UNIT_NAME
amqp:2_hostname: 10.5.19.152
amqp:2_password: JXyBbWFXsPZqwSjZXhJmkNLxgC5PnnPWpz9SChqGS6X7MsZKCSp4fzbXTSy9mm53
amqp:2_private-address: 10.5.19.152
cinder.passwd: JXyBbWFXsPZqwSjZXhJmkNLxgC5PnnPWpz9SChqGS6X7MsZKCSp4fzbXTSy9mm53
cookie: GYIRHLPVKCKJHNBLSQRE
private-address: 10.5.19.154
## Using remote unit gets permission denied
# relation-get -r cluster:1 - $JUJU_REMOTE_UNIT
error: permission denied
## Relation get by itself gets the rabbitmq-server <-> cinder data not peer data
# relation-get
private-address: 10.5.19.151
username: cinder
vhost: openstack
Note this is only for juju versions with no leadership election. LE versions of juju skip this code entirely.
When relation_get is called in a non-cluster relation hook and we are checking for *cluster* relation data,
the remote unit is not a peer and the remote unit is ignorant of the data set on the *cluster* relation.
So we use the local unit, which for some reason (possibly a bug) gives us the cluster relation data.
However, when we are in a native cluster relation hook using the local unit gives an empty set (AFAIK always).
So we need to use the remote_unit to get the relation data. In this case cookie, without this rabbit never sees a peer cookie and never clusters.
In rabbit's case it is a chicken/egg problem. The non-leader never gets the peer data in order to echo it.
### Example in a cluster relation
# echo $JUJU_RELATION
cluster
# echo $JUJU_RELATION_ID
cluster:1
# echo $JUJU_UNIT_NAME
rabbitmq-server/2
# echo $JUJU_REMOTE_UNIT
rabbitmq-server/0
## Using local unit gets no peer data
# relation-get -r cluster:1 - $JUJU_UNIT_NAME
private-address: 10.5.19.154
## Using remote unit gets peer data ZXhJmkNLxgC5Pnn PWpz9SChqGS6X7M sZKCSp4fzbXTSy9 mm53 private- address: 10.5.19.152 ZXhJmkNLxgC5Pnn PWpz9SChqGS6X7M sZKCSp4fzbXTSy9 mm53 LSQRE
# relation-get -r cluster:1 - $JUJU_REMOTE_UNIT
amqp:2_hostname: 10.5.19.152
amqp:2_password: JXyBbWFXsPZqwSj
amqp:2_
cinder.passwd: JXyBbWFXsPZqwSj
cookie: GYIRHLPVKCKJHNB
private-address: 10.5.19.152
## Relation get by itself also works in a cluster relation ZXhJmkNLxgC5Pnn PWpz9SChqGS6X7M sZKCSp4fzbXTSy9 mm53 private- address: 10.5.19.152 ZXhJmkNLxgC5Pnn PWpz9SChqGS6X7M sZKCSp4fzbXTSy9 mm53 LSQRE
# relation-get
amqp:2_hostname: 10.5.19.152
amqp:2_password: JXyBbWFXsPZqwSj
amqp:2_
cinder.passwd: JXyBbWFXsPZqwSj
cookie: GYIRHLPVKCKJHNB
private-address: 10.5.19.152
### Example in amqp relation
# echo $JUJU_RELATION
amqp
# echo $JUJU_RELATION_ID
amqp:2
# echo $JUJU_UNIT_NAME
rabbitmq-server/2
# echo $JUJU_REMOTE_UNIT
cinder/0
## Using local unit gets data ZXhJmkNLxgC5Pnn PWpz9SChqGS6X7M sZKCSp4fzbXTSy9 mm53 private- address: 10.5.19.152 ZXhJmkNLxgC5Pnn PWpz9SChqGS6X7M sZKCSp4fzbXTSy9 mm53 LSQRE
# relation-get -r cluster:1 - $JUJU_UNIT_NAME
amqp:2_hostname: 10.5.19.152
amqp:2_password: JXyBbWFXsPZqwSj
amqp:2_
cinder.passwd: JXyBbWFXsPZqwSj
cookie: GYIRHLPVKCKJHNB
private-address: 10.5.19.154
## Using remote unit gets permission denied
# relation-get -r cluster:1 - $JUJU_REMOTE_UNIT
error: permission denied
## Relation get by itself gets the rabbitmq-server <-> cinder data not peer data
# relation-get
private-address: 10.5.19.151
username: cinder
vhost: openstack