Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate extended diagnostics (#1300 with #1295) #1310

Merged
merged 2 commits into from
Oct 3, 2022
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
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