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

fsdiff enhancements to diff against a reference dump #260

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,8 @@ def enable_hsts_header(self):
def disable_hsts_header(self):
self.ssh(['rm', '-f', f'{XAPI_CONF_DIR}/00-XCP-ng-tests-enable-hsts-header.conf'])
self.restart_toolstack(verify=True)

def firmware_type(self):
retcode = self.ssh(['test', '-d', '/sys/firmware/efi/'],
check=False, simple_output=False).returncode
return "uefi" if retcode == 0 else "bios"
1 change: 1 addition & 0 deletions scripts/lib
41 changes: 19 additions & 22 deletions scripts/xcpng-fs-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#

import argparse
import logging
import sys
import subprocess
import json
Expand All @@ -48,6 +49,8 @@
from fnmatch import fnmatch
from enum import StrEnum, auto

from lib.commands import ssh

class DataType(StrEnum):
FILE = auto()
FILE_SYMLINK = auto()
Expand All @@ -62,15 +65,6 @@ def ignore_file(filename, ignored_files):

return False

def ssh_cmd(host, cmd):
args = ["ssh", f"root@{host}", cmd]

cmdres = subprocess.run(args, capture_output=True, text=True)
if cmdres.returncode:
raise Exception(cmdres.stderr)

return cmdres.stdout

def ssh_get_files(host, file_type, folders):
md5sum = False
readlink = False
Expand Down Expand Up @@ -101,7 +95,7 @@ def ssh_get_files(host, file_type, folders):
# This is much more efficient than using find '-exec md5sum {}'
find_cmd += " -print0 | xargs -0 md5sum"

rawres = ssh_cmd(host, find_cmd)
rawres = ssh(host, [find_cmd])

res = dict()
for line in rawres.splitlines():
Expand All @@ -113,7 +107,7 @@ def ssh_get_files(host, file_type, folders):
def ssh_get_packages(host):
packages = dict()

res = ssh_cmd(host, "rpm -qa --queryformat '%{NAME} %{VERSION}\n'")
res = ssh(host, ["rpm -qa --queryformat '%{NAME} %{VERSION}\n'"])
for line in res.splitlines():
entries = line.split(' ', 1)
packages[entries[0]] = entries[1]
Expand All @@ -131,7 +125,7 @@ def get_data(host, folders):
ref_data[DataType.PACKAGE] = ssh_get_packages(host)
except Exception as e:
print(e, file=sys.stderr)
exit(-1)
exit(1)

return ref_data

Expand Down Expand Up @@ -160,8 +154,8 @@ def remote_diff(host_ref, host_test, filename):
file_test = None

# check remote files are text files
cmd = f"file -b {shlex.quote(filename)}"
file_type = ssh_cmd(host_ref, cmd)
cmd = ["file", "-b", shlex.quote(filename)]
file_type = ssh(host_ref, cmd)
if not file_type.lower().startswith("ascii"):
print("Binary file. Not showing diff")
return
Expand Down Expand Up @@ -292,7 +286,7 @@ def load_reference_files(filename):
return json.load(fd)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
exit(-1)
exit(1)

# Save files from a reference host in json format
def save_reference_data(files, filename):
Expand All @@ -301,9 +295,11 @@ def save_reference_data(files, filename):
json.dump(files, fd, indent=4)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
exit(-1)
exit(1)

def main():
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)

ref_data = None
folders = ["/boot", "/etc", "/opt", "/usr"]
ignored_file_patterns = [
Expand Down Expand Up @@ -347,6 +343,7 @@ def main():
'/etc/sysconfig/xencommons',
'/etc/sysctl.d/91-net-ipv6.conf',
'/etc/vconsole.conf',
'/etc/xapi.d/plugins/vmssc',
'/etc/xsconsole/state.txt',
'/etc/xensource-inventory',
'/etc/xensource/boot_time_cpus',
Expand Down Expand Up @@ -385,31 +382,31 @@ def main():

if args.ref_host is None and args.show_diff:
print("Missing parameters. -d must be used with -r. Try --help", file=sys.stderr)
return -1
return 1

if args.load_ref:
if not args.json_output:
print(f"Get reference data from {args.load_ref}")
logging.info("Get reference data from %s", args.load_ref)
ref_data = load_reference_files(args.load_ref)
elif args.ref_host:
if not args.json_output:
print(f"Get reference data from {args.ref_host}")
logging.info("Get reference data from %s", args.ref_host)
ref_data = get_data(args.ref_host, args.folders)

if args.save_ref:
if not args.json_output:
print(f"Saving reference data to {args.save_ref}")
logging.info("Saving reference data to %s", args.save_ref)
save_reference_data(ref_data, args.save_ref)

if ref_data is None or args.test_host is None:
if args.save_ref:
return 0

print("\nMissing parameters. Try --help", file=sys.stderr)
return -1
return 1

if not args.json_output:
print(f"Get test host data from {args.test_host}")
logging.info("Get test host data from %s", args.test_host)
test_data = get_data(args.test_host, args.folders)

ref = dict([('data', ref_data), ('host', args.ref_host)])
Expand Down
Loading
Loading