Skip to content

Commit

Permalink
Merge pull request #107 from MOV-AI/dev
Browse files Browse the repository at this point in the history
fix logging of apt update in case of failure
  • Loading branch information
duartecoelhomovai authored Jul 17, 2023
2 parents ef029b3 + 7a6aef3 commit cfacfa1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mobros/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ class Commands(Enum):

MOBROS_CONFIG_PATH = "/etc/mobros/config"
MOBROS_CONFIG_SECTION = "conflict-solving"
MOBROS_CONFIG_BLACKLIST_KEY = "blacklistSource"
MOBROS_CONFIG_BLACKLIST_KEY = "blacklistSource"
7 changes: 6 additions & 1 deletion mobros/types/apt_cache_singleton.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Module defining the apt cache singleton not to be constantly requesting apt for his cache"""
import os
import apt

import mobros.utils.logger as logging
from mobros.exceptions import AptCacheInitializationException
from mobros.utils.utilitary import execute_shell_command


# pylint: disable=R0903,W0107
class AptCache:
"""Apt cache singleton"""
Expand All @@ -31,7 +33,10 @@ def __new__(cls):
message = "Unable to fetch apt cache. Please check your internet connection! Try running 'sudo apt update' for more info."
logging.error(message)

execute_shell_command("sudo apt update", log_output=True)
apt_cmd = ["apt", "update"]
if os.geteuid() != 0:
apt_cmd = ["sudo"] + apt_cmd
execute_shell_command(apt_cmd, log_output=True)
raise AptCacheInitializationException(message) from fetched_failed_exception

cls._installed_cache = []
Expand Down
11 changes: 10 additions & 1 deletion tests/test_utils/test_utilitary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from os import remove
from os import remove, geteuid
from os.path import dirname, exists, realpath

import mock
Expand Down Expand Up @@ -47,6 +47,15 @@ def test_execute_bash_fail_file_not_found(self):
except Exception:
pass

def test_execute_apt_update(self):


apt_cmd = ["apt", "update"]
if geteuid() != 0:
apt_cmd = ["sudo"] + apt_cmd
execute_shell_command(apt_cmd, log_output=True)


def test_is_blacklisted_origin(self):

GlobalData().set_conflict_solving_blacklist(["*.mov.ai/repository/ppa-testing","*.mov.ai/repository/ppa-main"])
Expand Down

0 comments on commit cfacfa1

Please sign in to comment.