Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ci
Path: blob/main/scripts/test/extract-test-logs.py
1130 views
1
# Copyright (c) 2014, Craig Rodrigues <[email protected]>
2
# All rights reserved.
3
#
4
# Redistribution and use in source and binary forms, with or without
5
# modification, are permitted provided that the following conditions
6
# are met:
7
# 1. Redistributions of source code must retain the above copyright
8
# notice unmodified, this list of conditions, and the following
9
# disclaimer.
10
# 2. Redistributions in binary form must reproduce the above copyright
11
# notice, this list of conditions and the following disclaimer in the
12
# documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25
# EXTRACT TEST LOGS FROM BHYVE VM
26
#
27
# The following program::
28
# (1) takes a UFS image
29
# (2) mounts it
30
# (3) extracts test logs from /usr/tests directory
31
#
32
33
from __future__ import print_function
34
from optparse import OptionParser
35
import atexit
36
import getopt
37
import json
38
import subprocess
39
import sys
40
import tempfile
41
42
test_config = None
43
test_config_file = None
44
sentinel_file = None
45
temp_dir = None
46
md = ""
47
48
def usage(argv):
49
print("Usage:")
50
print(" %s -f [JSON config file]" % argv[0])
51
52
53
def main(argv):
54
55
try:
56
opts, args = getopt.getopt(sys.argv[1:], "f:")
57
except getopt.GetoptError as err:
58
print(err)
59
sys.exit(2)
60
61
global test_config
62
global test_config_file
63
global sentinel_file
64
global temp_dir
65
global md
66
67
for o, a in opts:
68
if o == "-f":
69
test_config_file = a
70
else:
71
assert False, "unhandled option"
72
73
if test_config_file is None:
74
usage(argv)
75
sys.exit(1)
76
77
config_file = open(test_config_file, "r")
78
test_config = json.load(config_file)
79
config_file.close()
80
81
md = subprocess.check_output(["mdconfig", "-a", "-f", test_config['disks'][0]])
82
md = md.strip()
83
temp_dir = tempfile.mkdtemp()
84
cmd = ["mount", "/dev/%s" % (md), temp_dir]
85
print(" ".join(cmd))
86
ret = subprocess.call(cmd)
87
if ret != 0:
88
sys.exit(ret)
89
90
cmd = "cp %s/usr/tests/*.xml %s/usr/tests/*.txt ." \
91
% (temp_dir, temp_dir)
92
subprocess.call(cmd, shell=True)
93
94
def cleanup():
95
global md
96
subprocess.call("rm -f %s" % (sentinel_file), shell=True)
97
if temp_dir is not None:
98
cmd = ["umount", temp_dir]
99
print(" ".join(cmd))
100
subprocess.call(cmd)
101
102
cmd = ["mdconfig", "-d", "-u", md]
103
print(" ".join(cmd))
104
subprocess.call(cmd)
105
106
if __name__ == "__main__":
107
atexit.register(cleanup)
108
main(sys.argv)
109
110