Open PietroPasotti opened 2 years ago
Did you mean to include the jetbrains folder in the PR?
I did not :D
I like this feature, it would be very helpful.
Re: where it fits best in the package: I don't have a great feel for it but @addyess you've been in this package a lot lately do you have an opinion Re: 'raw' Popen: My gut says if there's a non-raw way of doing it, that would be preferred. I think the ideal would be we're not hitting the juju cli. But again, I don't have a good feel for it
sorry i'm late to the party but this doesn't feel like it should be in pytest-operator, but in python libjuju somewhere. Analysis of a model's relation data seems to live in that world.
It could be exposed through ops_test.model
as that represents the juju Model
object. I'd think that's where this ought to belong?
I'm looking to see if that "feature" may already exist there.
yeah, it doesn't seem like python libjuju has this feature, but i'd expect it to be in the Endpoint
class
for _, relation in ops_test.model.relations:
for endpoint in relation.endpoints:
# probe around in here
there are some convenience methods in libjuju, but i haven't spent more than 10min digging around in here.
Just to +1 here.
I tried looking into model.relations
but couldn't grab any data from it.
My solution (which I'd rather not have to do) was:
def get_password(model_full_name):
show_unit = check_output(
f"JUJU_MODEL={model_full_name} juju show-unit {APP_NAME}/0",
stderr=PIPE,
shell=True,
universal_newlines=True,
)
response = yaml.safe_load(show_unit)
password = response[f"{APP_NAME}/0"]["relation-info"][0]["application-data"]["super_password"]
logger.info(f"{password=}")
return password
@PietroPasotti thanks for this contribution. @ca-scribner I'm satisfied with this feature now that it's got some tests on it.
Added a
get_relation_data
method to OpsTest, allowing itest code to easily get a hold of databag contents for both sides of a live relation (where two units and one endpoint per unit are involved).Main idea:
The code is copy-pasted from https://github.com/PietroPasotti/jhack utils show-relation, a utility to visualize relation databags.
Questions for the reviewers:
OpsTest.juju
instead of 'raw' Popen calls?Fixes #81