Skip to content

Conversation

lucasgameiroborges
Copy link

No description provided.

harness.get_relation_data(rel_id, harness.charm.unit.name)["password"]
== "test-password"
)
assert harness.charm.get_secret("unit", "password") == "test-password"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't re-write the old test.

We should keep Juju2 compatibilty.

Please add a separate test for secrets, that's only executed when secrets are available

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the old test, running on juju2 only, as it checks the relation databag for the secret. I kept the changed test running on both versions as it is compatible either way. Left some comments for future perspective. LMK what you think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, I see, sorry it was my confusion.

Now I understand what you mean, renaming was a good idea here :-)

All good on this one, thank you :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... My bad sorry, I overlooked this test.

This one is not using secrtes.

IT's only using secrets when secrets are configured but otherwise it's falling back to the databag.

We should have a test that is specifically checking if a Juju secret comes to existence when we create one with charm.set_secret().

I think we had it already somewhere lower down in this file.

We don't need to duplicate that.

I mean: it's good to have a single generic test on set-get secret functionality. It will work both on databag and with Juju Secrets, with no knowledge of the underlying storage.

However we also MUST have specific tests for both databag usage (@only_without_juju_secrets -- should fail otherwise) and vica versa.

I think I have some of those in all PG apps main right now. That concept has to be kept and followed if we want a single pipeline.

harness.get_relation_data(rel_id, harness.charm.unit.name)["password"]
== "test-password"
)
assert harness.charm.get_secret("unit", "password") == "test-password"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, I see, sorry it was my confusion.

Now I understand what you mean, renaming was a good idea here :-)

All good on this one, thank you :-)


def test_on_get_password(harness):
# Create a mock event and set passwords in peer relation data.
harness.set_leader(True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All units should be able to get the password. If now we reduce it to the leader, we're changing the expected behavior instead of the previously expected behavior of the application.

I mean: earlier this test was ensuring that all units get the password (in a way as described by the test).
Setting the unit to leader, from now on this test only ensures (expect) that we can get the password this way for the leader.

Tests generally mustn't change -- except when being aligned to a new behavior (i.e. fix or feature) we are implemneting. However, the changes we did in the charm should have been fully identical to the previous behavior.

There was supposed to be no behavior change in this PR -- thus the tests have to stay intact, too.

Was there a reason for switching to leader? I may be overlooking something, perhaps we did a change that stopped the test from passing as before (and we may want to investigate that).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this specific test was failing after the library bump.

My reason to add it was: I realized that this exact same test on the postgreSQL VM repo had set_leader(True) in it (this commit, we can see it being added in the diff). At first I saw no reason for this test to be different on k8s and vm, so I added set_leader(True) here in order to make them coherent with each other, and this change made it pass again.

I thought this was a fair addition to the test, since the same exact test over on VM had it in the first place (not sure why we didn't have it here). If there was a reason for it to not be here, then I might need some more context and suggestions on what to do about it (if not having this).

I think its a good idea to have @marceloneppel and @dragomirp input here, as they might have context that I lack.

Copy link
Contributor

@dragomirp dragomirp May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juditnovak I think the issue is that fetch_my_relation_field is marked as leader only:
https://github.com/canonical/postgresql-k8s-operator/blob/lucas/update-lib/lib/charms/data_platform_libs/v0/data_interfaces.py#L1543

Looked into it more and translation from peer data in get_secret is happening only if there is a difference in keys. I'd guess it works on leader due to some hook firing and translating to secrets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose merging this as is, until we establish the correct behaviour of the translation logic, since we already have it everywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @dragomirp if U prefer, go head.

Copy link
Contributor

@juditnovak juditnovak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasgameiroborges
Copy link
Author

Following our discussion about why test_on_get_password is passing only if the unit is leader, I created the following ticket to address it: https://warthogs.atlassian.net/browse/DPE-4259
If everyone agrees I think this PR can get merged in the meantime. Then I can create follow-ups once we investigate the issue.

@marceloneppel
Copy link
Member

I think that's fine to merge it as is and investigate later.

@lucasgameiroborges lucasgameiroborges merged commit e2bae44 into main May 2, 2024
@lucasgameiroborges lucasgameiroborges deleted the lucas/update-lib branch May 2, 2024 12:35
BON4 pushed a commit to BON4/postgresql-k8s-operator that referenced this pull request May 20, 2024
…o 16 (canonical#454)

* update libs

* fix unit tests

* add peer check

* adapt src code and unit tests

* separate tests in 2 versions

* review suggestions

* add new review suggestions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants