Skip to content

Commit

Permalink
Merge pull request #383 from gboutry/fix/os-env
Browse files Browse the repository at this point in the history
Remove OS variable from running process
  • Loading branch information
hemanthnakkina authored Dec 11, 2024
2 parents 358d374 + 200d26c commit b07aaee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sunbeam-python/sunbeam/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from sunbeam.commands import utils as utils_cmds
from sunbeam.core import deployments as deployments_jobs
from sunbeam.provider import commands as provider_cmds
from sunbeam.utils import CatchGroup
from sunbeam.utils import CatchGroup, clean_env

LOG = logging.getLogger()

Expand Down Expand Up @@ -98,6 +98,7 @@ def juju(ctx):


def main():
clean_env()
snap = Snap()
logfile = log.prepare_logfile(snap.paths.user_common / "logs", "sunbeam")
log.setup_root_logging(logfile)
Expand Down
13 changes: 13 additions & 0 deletions sunbeam-python/sunbeam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import ipaddress
import json
import logging
import os
import re
import secrets
import socket
Expand Down Expand Up @@ -440,3 +441,15 @@ def get_metavar(self, param: click.Parameter) -> str:

# Use square braces to indicate an option or optional argument.
return f"[{repr_str}]"


def clean_env():
"""Remove unwanted environment variables from running process.
OpenStack variables defined in the environment can interfere with
the operation of the snap. When these variables are actually needed,
the snap set them itself.
"""
for key in os.environ:
if key.startswith("OS_"):
os.environ.pop(key)

0 comments on commit b07aaee

Please sign in to comment.