Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

import logging
import os
import socket
from pathlib import Path

Expand Down Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions src/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading