Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IPU] Make sure revoked is emitted #80

Merged
merged 7 commits into from Aug 19, 2022
Merged

[IPU] Make sure revoked is emitted #80

merged 7 commits into from Aug 19, 2022

Conversation

sed-i
Copy link
Contributor

@sed-i sed-i commented Aug 18, 2022

Issue

Closes #79 .

Solution

  • add utest(s) for IPU event
  • return an empty dict if in relation-broken event instead of looking into relation data, which may be out of date.

Context

  • self.ingress.url was returning old (non-falsey) value even after relation and/or app was removed.
  • Seems like relation data is not emptied out even when looking from within a relation broken event. This may be a juju feature rather than a bug though/

@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events updated to version 0.3.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape updated to version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

@sed-i
Copy link
Contributor Author

sed-i commented Aug 18, 2022

@PietroPasotti I am having trouble with the utest but I'm not sure if it's because of a test bug, lib bug or harness behavior:

The relation is removed with harness, but "removed" is always blank:

INFO     root:ingress_per_unit.py:689 unit: ipu-requirer/0, event: RelationCreatedEvent. removed: set(); changed: set()
INFO     root:ingress_per_unit.py:689 unit: ipu-requirer/0, event: RelationJoinedEvent. removed: set(); changed: set()
INFO     root:ingress_per_unit.py:689 unit: ipu-requirer/0, event: RelationChangedEvent. removed: set(); changed: {'ipu-requirer/0'}
INFO     root:ingress_per_unit.py:689 unit: ipu-requirer/0, event: RelationChangedEvent. removed: set(); changed: set()
INFO     root:ingress_per_unit.py:689 unit: ipu-requirer/0, event: RelationBrokenEvent. removed: set(); changed: set()

and revoke doesn't fire.

@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events updated to version 0.3.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape updated to version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

@sed-i
Copy link
Contributor Author

sed-i commented Aug 18, 2022

{} if isinstance(event, BrokenEvent) per @PietroPasotti's suggestion fixed the utest.

@@ -682,7 +682,7 @@ def _handle_relation(self, event: RelationEvent):
# we calculate the diff between the urls we were aware of
# before and those we know now
previous_urls = self._stored.current_urls or {} # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rbarry82 would you use _type_convert_stored here?

@sed-i sed-i changed the title Add utest for revoked event [IPU] Make sure revoked is emitted Aug 18, 2022
@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events was already up to date in version 0.3.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape was already up to date in version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events was already up to date in version 0.3.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape was already up to date in version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events was already up to date in version 0.3.
Library charms.observability_libs.v0.juju_topology was already up to date in version 0.2.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape was already up to date in version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events was already up to date in version 0.3.
Library charms.observability_libs.v0.juju_topology was already up to date in version 0.2.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape was already up to date in version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

Copy link
Collaborator

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

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

looks good!

@sed-i sed-i marked this pull request as ready for review August 19, 2022 13:59
- Update _stored before events are emitted
- Get urls from stored instead of relation data
@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events was already up to date in version 0.3.
Library charms.observability_libs.v0.juju_topology was already up to date in version 0.2.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape was already up to date in version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

1 similar comment
@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events was already up to date in version 0.3.
Library charms.observability_libs.v0.juju_topology was already up to date in version 0.2.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape was already up to date in version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

@github-actions
Copy link

Libraries are not up to date with their remote counterparts. If this was
not intentional, run charmcraft fetch-libs and commit the updated libs
to your PR branch.

stdout
Library charms.harness_extensions.v0.capture_events was already up to date in version 0.3.
Library charms.observability_libs.v0.juju_topology was already up to date in version 0.2.
Library charms.observability_libs.v0.kubernetes_service_patch was already up to date in version 0.6.
Library charms.prometheus_k8s.v0.prometheus_scrape was already up to date in version 0.21.
Library charms.traefik_k8s.v1.ingress has local changes, cannot be updated.
Library charms.traefik_k8s.v1.ingress_per_unit has local changes, cannot be updated.
Library charms.traefik_route_k8s.v0.traefik_route has local changes, cannot be updated.

stderr

Copy link
Contributor

@rbarry82 rbarry82 left a comment

Choose a reason for hiding this comment

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

Tested manually

@sed-i sed-i merged commit d80dab2 into main Aug 19, 2022
@sed-i sed-i deleted the feature/test_revoked branch August 19, 2022 18:53
@PietroPasotti
Copy link
Collaborator

@sed-i it seems I didn't pay enough attention while reviewing, or actually, that some changes slipped in that I didn't have a chance to review as they came in after I approved: ce32bd3

either way, there's a problem with these changes:

  1. we renamed urls to _get_urls_from_relation_data, which shouldn't really be a property anymore.
  2. we replaced urls with a function that loads in the urls from stored data, which changes some of the semantics of what's going on, enough to break integration tests in traefik-route. So that's a backwards-incompatible change!

@sed-i
Copy link
Contributor Author

sed-i commented Sep 2, 2022

we renamed urls to _get_urls_from_relation_data, which shouldn't really be a property anymore.

Agreed. I noticed that later too. In the IPA PR it is not a property.

we replaced urls with a function that loads in the urls from stored data... break integration tests

Hmm. The change itself still seems correct to me logically. Can you post the link to the failing test? I'm curious.

@PietroPasotti
Copy link
Collaborator

It wasn't a CI failure, it was local, so no links, but essentially what happened was:
I was writing a tester charm to represent an ingress-requiring-charm like:

class MyCharm(CharmBase):
    def __init__...
        self.unit.status=Blocked()
        ingress = IPURequirer()
        if ingress.is_ready(ingress.relation):
            self.unit.status=Active()

This test was passing before this PR got merged.
reason: is_ready() basically checks if bool(urls).
before this PR, urls would fetch the data in real time from the relation.
after this PR, urls is cached and only contains data if we are processing some events.

However, events are processed AFTER the charm is initialized, so at charm-init-time, that branch wouldn't be selected.

Took me a long time to figure that one out :)
Guess I learned to write charms always 'the proper way', even though it's just a tester charm.

@sed-i
Copy link
Contributor Author

sed-i commented Sep 2, 2022

Interesting. I wonder why at charm init time the old url would be non-false-y. And if indeed it was, then was it a mistake?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

possible issue with IPURequirer.on.revoked emission
4 participants