diff --git a/src/charm.py b/src/charm.py index 9f96a35..e6f12c3 100755 --- a/src/charm.py +++ b/src/charm.py @@ -13,7 +13,6 @@ """ import logging -import os import socket from pathlib import Path @@ -258,13 +257,13 @@ def _refresh_git_ubuntu_source(self) -> bool: if https_proxy != "": logger.info("Using https proxy %s for git-ubuntu source refresh.", https_proxy) - os.environ["https_proxy"] = https_proxy # Run clone or pull of git-ubuntu source. if not usr.refresh_git_ubuntu_source( GIT_UBUNTU_SYSTEM_USER_USERNAME, GIT_UBUNTU_USER_HOME_DIR, GIT_UBUNTU_SOURCE_URL, + https_proxy, ): self.unit.status = ops.BlockedStatus("Failed to refresh git-ubuntu source.") return False diff --git a/src/user_management.py b/src/user_management.py index 89d4acc..4887e84 100644 --- a/src/user_management.py +++ b/src/user_management.py @@ -93,13 +93,16 @@ def setup_git_ubuntu_user_services_dir(user: str, home_dir: str) -> bool: return _mkdir_for_user_with_error_checking(services_dir, user) -def refresh_git_ubuntu_source(user: str, home_dir: str, source_url: str) -> bool: +def refresh_git_ubuntu_source( + user: str, home_dir: str, source_url: str, https_proxy: str = "" +) -> bool: """Clone or update the git-ubuntu git repo in the home directory. Args: user: The user to run git clone as. home_dir: The home directory for the user. source_url: git-ubuntu's git repo url. + https_proxy: The https proxy URL if required. Returns: True if the clone succeeded, False otherwise. @@ -122,15 +125,23 @@ def refresh_git_ubuntu_source(user: str, home_dir: str, source_url: str) -> bool return False # Run git pull to get up to date - if not _run_command_as_user(user, f"git -C {clone_dir.as_posix()} pull"): + pull_command = f"git -C {clone_dir.as_posix()} pull" + if https_proxy != "": + pull_command = f"https_proxy={https_proxy} {pull_command}" + + if not _run_command_as_user(user, pull_command): logger.error("Failed to update existing git-ubuntu source.") return False return True # Clone the repository + clone_command = f"git clone {source_url} {clone_dir.as_posix()}" + if https_proxy != "": + clone_command = f"https_proxy={https_proxy} {clone_command}" + logger.info("Cloning git-ubuntu source to %s", clone_dir.as_posix()) - if not _run_command_as_user(user, f"git clone {source_url} {clone_dir.as_posix()}"): + if not _run_command_as_user(user, clone_command): logger.error("Failed to clone git-ubuntu source.") return False diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index b78fcfc..8689810 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -24,7 +24,7 @@ def test_service_status(app: str, juju: jubilant.Juju): """ # Wait until machine is ready, then wait an extra 60 seconds for services to fully activate. juju.wait(jubilant.all_active) - sleep(60) + sleep(90) def get_services_dict(unit_name: str, juju: jubilant.Juju) -> dict[str, dict[str, bool | str]]: """Get a dictionary of running systemd services on the app's unit.