Getting permission denied trying to read relation data from a different relation

I’m in a bash hook trying to detect if my unit is related or not to something else (in this case Bind9 dns-entry)…

I only found this in the docs :

I tried

< another-relation >

RELATION_LIST=$(relation-ids dns-entry)    #This returns `dns-entry:7` .. with 7 being the unit #

it is this second line which gives me a permission denied… what is the right way to check my units relations …and then get more details on that relation if it exists?? thank you.

I believe it should actually be relation-get.

sorry I was typing based off my bad memory… but I indeed was using the relation-get command and getting

>dns_relation_ids=$(relation-ids dns-entry)   # this returns 'dns-entry/4`
> dns_relation_data=$(relation-get -r $dns_relation_ids)

unit-APP_NAME-UNIT_NUM: 17:51:48 WARNING unit.APP_NAME/ ERROR permission denied

EDIT: ah hah! I seem to have cracked the problem… but revealed a new problem

if I pass in the unit name and number of the application providing the relation … I get the data expected… but now my question is, how do I get the UNIT_NUMBER for a specific relation if I am running in a hook that is NOT from that relation??

ie I have relation 1 … and relation 2…

in relation 2 hook-changed… I want to get the unit number or blank if nothing related … for relation 1

Is this possible ?

I tried to use goal-state command however because this unit I am relating to is a cross-model relation… i do NOT get the Unit number from this … and what I do get does not work for the relation-get command

I think there’s some confusion. There is no UNIT_NUMBER linked to every relation at any given time. When the unit receives a relation event say, changed, then UNIT_NUMBER is set and the semantics is: UNIT_NUMBER := the remote unit ID that has changed the data of this relation.

However when you are processing a different event (or a relation event for a different relation, there is no such thing as ‘the UNIT_NUMBER for the other relation’, because there’s nothing going on (so far as the charm is concerned) with the other relation.

So you need to ask yourself: what unit ID are you looking for, and why?

1 Like