Skip to content

Commit a31925e

Browse files
authored
Merge pull request #29 from canonical/fix-git-ubuntu-source-proxy-download
Fix git ubuntu source proxy download
2 parents 2ba6d03 + 8c1e0ac commit a31925e

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/charm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""
1414

1515
import logging
16-
import os
1716
import socket
1817
from pathlib import Path
1918

@@ -258,13 +257,13 @@ def _refresh_git_ubuntu_source(self) -> bool:
258257

259258
if https_proxy != "":
260259
logger.info("Using https proxy %s for git-ubuntu source refresh.", https_proxy)
261-
os.environ["https_proxy"] = https_proxy
262260

263261
# Run clone or pull of git-ubuntu source.
264262
if not usr.refresh_git_ubuntu_source(
265263
GIT_UBUNTU_SYSTEM_USER_USERNAME,
266264
GIT_UBUNTU_USER_HOME_DIR,
267265
GIT_UBUNTU_SOURCE_URL,
266+
https_proxy,
268267
):
269268
self.unit.status = ops.BlockedStatus("Failed to refresh git-ubuntu source.")
270269
return False

src/user_management.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ def setup_git_ubuntu_user_services_dir(user: str, home_dir: str) -> bool:
9393
return _mkdir_for_user_with_error_checking(services_dir, user)
9494

9595

96-
def refresh_git_ubuntu_source(user: str, home_dir: str, source_url: str) -> bool:
96+
def refresh_git_ubuntu_source(
97+
user: str, home_dir: str, source_url: str, https_proxy: str = ""
98+
) -> bool:
9799
"""Clone or update the git-ubuntu git repo in the home directory.
98100
99101
Args:
100102
user: The user to run git clone as.
101103
home_dir: The home directory for the user.
102104
source_url: git-ubuntu's git repo url.
105+
https_proxy: The https proxy URL if required.
103106
104107
Returns:
105108
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
122125
return False
123126

124127
# Run git pull to get up to date
125-
if not _run_command_as_user(user, f"git -C {clone_dir.as_posix()} pull"):
128+
pull_command = f"git -C {clone_dir.as_posix()} pull"
129+
if https_proxy != "":
130+
pull_command = f"https_proxy={https_proxy} {pull_command}"
131+
132+
if not _run_command_as_user(user, pull_command):
126133
logger.error("Failed to update existing git-ubuntu source.")
127134
return False
128135

129136
return True
130137

131138
# Clone the repository
139+
clone_command = f"git clone {source_url} {clone_dir.as_posix()}"
140+
if https_proxy != "":
141+
clone_command = f"https_proxy={https_proxy} {clone_command}"
142+
132143
logger.info("Cloning git-ubuntu source to %s", clone_dir.as_posix())
133-
if not _run_command_as_user(user, f"git clone {source_url} {clone_dir.as_posix()}"):
144+
if not _run_command_as_user(user, clone_command):
134145
logger.error("Failed to clone git-ubuntu source.")
135146
return False
136147

tests/integration/test_charm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_service_status(app: str, juju: jubilant.Juju):
2424
"""
2525
# Wait until machine is ready, then wait an extra 60 seconds for services to fully activate.
2626
juju.wait(jubilant.all_active)
27-
sleep(60)
27+
sleep(90)
2828

2929
def get_services_dict(unit_name: str, juju: jubilant.Juju) -> dict[str, dict[str, bool | str]]:
3030
"""Get a dictionary of running systemd services on the app's unit.

0 commit comments

Comments
 (0)