-
Notifications
You must be signed in to change notification settings - Fork 121
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
fix: expose the mocked Juju environment variables via os.environ again #1573
base: main
Are you sure you want to change the base?
fix: expose the mocked Juju environment variables via os.environ again #1573
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code change looks good to me -- thanks. Two questions:
- Have you tested that this fixes the broken charm tests mentioned in ops-testing should expose the mocked JUJU_ environment variables in os.environ #1572? If not, could we double-check that and note it here.
- Do you think we should do a point release of ops/ops-scenario after this is merged?
Yes, although it also needs: --- a/tests/scenario/test_charm_tracing.py
+++ b/tests/scenario/test_charm_tracing.py
@@ -29,7 +29,7 @@ from charms.tempo_coordinator_k8s.v0.tracing import (
from ops import EventBase, EventSource, Framework
from ops.charm import CharmBase, CharmEvents
from scenario import Context, Relation, State
-from scenario.runtime import UncaughtCharmError
+from scenario.errors import UncaughtCharmError
logger = logging.getLogger(__name__)
The only other charm that I have locally that needs this is
I feel this ties into the general "do we wait for the end of the month" discussion. This doesn't seem as urgent as breaking deferring in some cases - it's only testing, and it's only this one lib as far as we know - but I'm also not opposed to releasing fixes as we get to them. |
for key, value in os.environ.copy().items(): | ||
if key in previous_env: | ||
os.environ[key] = value | ||
else: | ||
del os.environ[key] | ||
for key, value in previous_env.items(): | ||
if key not in os.environ: | ||
os.environ[key] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for key, value in os.environ.copy().items(): | |
if key in previous_env: | |
os.environ[key] = value | |
else: | |
del os.environ[key] | |
for key, value in previous_env.items(): | |
if key not in os.environ: | |
os.environ[key] = value | |
for key, value in previous_env.items(): | |
os.environ[key] = value | |
for key in tuple(os.environ): | |
if key not in previous_env: | |
del os.environ[key] |
The other way round works too
for key, value in os.environ.copy().items(): | |
if key in previous_env: | |
os.environ[key] = value | |
else: | |
del os.environ[key] | |
for key, value in previous_env.items(): | |
if key not in os.environ: | |
os.environ[key] = value | |
for key in tuple(os.environ): | |
if key not in previous_env: | |
del os.environ[key] | |
for key, value in previous_env.items(): | |
os.environ[key] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh hold up, how about this:
for key, value in os.environ.copy().items(): | |
if key in previous_env: | |
os.environ[key] = value | |
else: | |
del os.environ[key] | |
for key, value in previous_env.items(): | |
if key not in os.environ: | |
os.environ[key] = value | |
for key in tuple(os.environ): | |
if key not in previous_env: | |
del os.environ[key] | |
os.environ.update(previous_env) |
Rather than only put
JUJU_VERSION
intoos.environ
, copy the entire contents of the mock Juju environment variables (and after the run, put the environment dictionary back to the same state it was originally).In general, we feel that charms should be using ops to access this information, rather than going directly to the raw environment variable, but this was too large a change to make in a refactoring bugfix release, and should wait for an 8.x release (and also ensuring that there are reasonable ways to get everything from ops - for example, the event name is perhaps too tricky to get globally right now).
Fixes #1572