Skip to content

Commit

Permalink
Integrate extended diagnostics (#1300 with #1295) (#1310)
Browse files Browse the repository at this point in the history
* Integrate extended diagnostics (#1300 with #1295)
* Add user-callback path to collect_diagnostics()
* Remove TravisCI test failure workaround (was fixed with #1305).
* Correct some typos in comments
* Diagnostics: Add local and global config file info. Rename "config-version" to "latest-config-version"

by @aryoda and @buhtzz
  • Loading branch information
aryoda authored Oct 3, 2022
1 parent 0622708 commit 4940192
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
18 changes: 2 additions & 16 deletions common/backintime.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import password
import encfstools
import cli
from diagnostics import collect_diagnostics
from exceptions import MountException
from applicationinstance import ApplicationInstance

Expand Down Expand Up @@ -737,23 +738,8 @@ def __init__(self, *args, **kwargs):
super(printDiagnostics, self).__init__(*args, **kwargs)

def __call__(self, *args, **kwargs):
cfg = config.Config()

# TODO Refactor into a separate functions in a new diagnostics.py when more info is added
ref, hashid = tools.gitRevisionAndHash()
git_branch = "Unknown"
git_commit = "Unknown"
if ref:
git_branch = ref
git_commit = hashid

diagnostics = dict(
app_name=config.Config.APP_NAME,
app_version=config.Config.VERSION,
app_git_branch=git_branch,
app_git_commit=git_commit,
user_callback=cfg.takeSnapshotUserCallback()
)
diagnostics = collect_diagnostics()

print(json.dumps(diagnostics, indent=4))

Expand Down
19 changes: 15 additions & 4 deletions common/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,41 @@


def collect_diagnostics():
"""Collect information's about environment and versions of tools and
"""Collect information about environment and versions of tools and
packages used by Back In Time.
The informatinos can be used e.g. for debugging and but reports.
The information can be used e.g. for debugging and bug reports.
Returns:
dict: A nested dictionary.
"""
result = {}

# Replace home folder user names with this dummy name
# for privacy reasons
USER_REPLACED = 'UsernameReplaced'

pwd_struct = pwd.getpwuid(os.getuid())

# === BACK IN TIME ===
distro_path = _determine_distro_package_folder()

# work-around: Instantiate to get the user-callback folder
# (should be singleton)
cfg = config.Config()

result['backintime'] = {
'name': config.Config.APP_NAME,
'version': config.Config.VERSION,
'config-version': config.Config.CONFIG_VERSION,
'latest-config-version': config.Config.CONFIG_VERSION,
'local-config-file': cfg._LOCAL_CONFIG_PATH,
'local-config-file-found': os.path.exists(cfg._LOCAL_CONFIG_PATH),
'global-config-file': cfg._GLOBAL_CONFIG_PATH,
'global-config-file-found': os.path.exists(cfg._GLOBAL_CONFIG_PATH),
'distribution-package': str(distro_path),
'started-from': str(pathlib.Path(config.__file__).parent),
'running_as_root': pwd_struct.pw_name == 'root',
'running-as-root': pwd_struct.pw_name == 'root',
'user-callback': cfg.takeSnapshotUserCallback()
}

# Git repo
Expand Down
7 changes: 2 additions & 5 deletions common/test/test_backintime.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,8 @@ def test_local_snapshot_is_successful(self):

def test_diagnostics_arg(self):

# Workaround: Without this line the next "subprocess.getoutput()" call fails on TravisCI for unknown reasons!
subprocess.check_output(["./backintime", "--diagnostics"])

output = subprocess.getoutput("./backintime --diagnostics")

diagnostics = json.loads(output)
self.assertEqual(diagnostics["app_name"], config.Config.APP_NAME)
self.assertEqual(diagnostics["app_version"], config.Config.VERSION)
self.assertEqual(diagnostics["backintime"]["name"], config.Config.APP_NAME)
self.assertEqual(diagnostics["backintime"]["version"], config.Config.VERSION)
4 changes: 2 additions & 2 deletions common/test/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_minimal(self):
)

# 2nd level "backintime"
minimal_keys = ['name', 'version', 'config-version',
'started-from', 'running_as_root']
minimal_keys = ['name', 'version', 'latest-config-version',
'started-from', 'running-as-root']
for key in minimal_keys:
self.assertIn(key, result['backintime'], key)

Expand Down

0 comments on commit 4940192

Please sign in to comment.