Skip to content

Commit d8bfaa7

Browse files
committed
Merge branch 'ydi/fsdiff'
2 parents caa39be + 58fdc13 commit d8bfaa7

File tree

8 files changed

+99673
-23
lines changed

8 files changed

+99673
-23
lines changed

lib/host.py

+5
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,8 @@ def enable_hsts_header(self):
639639
def disable_hsts_header(self):
640640
self.ssh(['rm', '-f', f'{XAPI_CONF_DIR}/00-XCP-ng-tests-enable-hsts-header.conf'])
641641
self.restart_toolstack(verify=True)
642+
643+
def firmware_type(self):
644+
retcode = self.ssh(['test', '-d', '/sys/firmware/efi/'],
645+
check=False, simple_output=False).returncode
646+
return "uefi" if retcode == 0 else "bios"

scripts/lib

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../lib

scripts/xcpng-fs-diff.py

+19-22
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#
4040

4141
import argparse
42+
import logging
4243
import sys
4344
import subprocess
4445
import json
@@ -48,6 +49,8 @@
4849
from fnmatch import fnmatch
4950
from enum import StrEnum, auto
5051

52+
from lib.commands import ssh
53+
5154
class DataType(StrEnum):
5255
FILE = auto()
5356
FILE_SYMLINK = auto()
@@ -62,15 +65,6 @@ def ignore_file(filename, ignored_files):
6265

6366
return False
6467

65-
def ssh_cmd(host, cmd):
66-
args = ["ssh", f"root@{host}", cmd]
67-
68-
cmdres = subprocess.run(args, capture_output=True, text=True)
69-
if cmdres.returncode:
70-
raise Exception(cmdres.stderr)
71-
72-
return cmdres.stdout
73-
7468
def ssh_get_files(host, file_type, folders):
7569
md5sum = False
7670
readlink = False
@@ -101,7 +95,7 @@ def ssh_get_files(host, file_type, folders):
10195
# This is much more efficient than using find '-exec md5sum {}'
10296
find_cmd += " -print0 | xargs -0 md5sum"
10397

104-
rawres = ssh_cmd(host, find_cmd)
98+
rawres = ssh(host, [find_cmd])
10599

106100
res = dict()
107101
for line in rawres.splitlines():
@@ -113,7 +107,7 @@ def ssh_get_files(host, file_type, folders):
113107
def ssh_get_packages(host):
114108
packages = dict()
115109

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

136130
return ref_data
137131

@@ -160,8 +154,8 @@ def remote_diff(host_ref, host_test, filename):
160154
file_test = None
161155

162156
# check remote files are text files
163-
cmd = f"file -b {shlex.quote(filename)}"
164-
file_type = ssh_cmd(host_ref, cmd)
157+
cmd = ["file", "-b", shlex.quote(filename)]
158+
file_type = ssh(host_ref, cmd)
165159
if not file_type.lower().startswith("ascii"):
166160
print("Binary file. Not showing diff")
167161
return
@@ -292,7 +286,7 @@ def load_reference_files(filename):
292286
return json.load(fd)
293287
except Exception as e:
294288
print(f"Error: {e}", file=sys.stderr)
295-
exit(-1)
289+
exit(1)
296290

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

306300
def main():
301+
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
302+
307303
ref_data = None
308304
folders = ["/boot", "/etc", "/opt", "/usr"]
309305
ignored_file_patterns = [
@@ -347,6 +343,7 @@ def main():
347343
'/etc/sysconfig/xencommons',
348344
'/etc/sysctl.d/91-net-ipv6.conf',
349345
'/etc/vconsole.conf',
346+
'/etc/xapi.d/plugins/vmssc',
350347
'/etc/xsconsole/state.txt',
351348
'/etc/xensource-inventory',
352349
'/etc/xensource/boot_time_cpus',
@@ -385,31 +382,31 @@ def main():
385382

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

390387
if args.load_ref:
391388
if not args.json_output:
392-
print(f"Get reference data from {args.load_ref}")
389+
logging.info("Get reference data from %s", args.load_ref)
393390
ref_data = load_reference_files(args.load_ref)
394391
elif args.ref_host:
395392
if not args.json_output:
396-
print(f"Get reference data from {args.ref_host}")
393+
logging.info("Get reference data from %s", args.ref_host)
397394
ref_data = get_data(args.ref_host, args.folders)
398395

399396
if args.save_ref:
400397
if not args.json_output:
401-
print(f"Saving reference data to {args.save_ref}")
398+
logging.info("Saving reference data to %s", args.save_ref)
402399
save_reference_data(ref_data, args.save_ref)
403400

404401
if ref_data is None or args.test_host is None:
405402
if args.save_ref:
406403
return 0
407404

408405
print("\nMissing parameters. Try --help", file=sys.stderr)
409-
return -1
406+
return 1
410407

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

415412
ref = dict([('data', ref_data), ('host', args.ref_host)])

0 commit comments

Comments
 (0)