2020-10-14 21:36:47 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
|
|
|
|
# is made available to anyone wishing to use, modify, copy, or
|
|
|
|
# redistribute it subject to the terms and conditions of the GNU General
|
|
|
|
# Public License v.2.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; If not, see http://www.gnu.org/licenses/.
|
|
|
|
#
|
|
|
|
# Author: Bruno Goncalves <bgoncalv@redhat.com>
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
|
2021-07-23 09:23:40 +00:00
|
|
|
|
2020-10-14 21:36:47 +00:00
|
|
|
def run(cmd):
|
2021-06-10 13:56:30 +00:00
|
|
|
print("INFO: Running '%s'..." % cmd)
|
2021-07-23 09:23:40 +00:00
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
|
|
|
|
stderr = b""
|
|
|
|
stdout = b""
|
|
|
|
while p.poll() is None:
|
|
|
|
new_data = p.stdout.readline()
|
|
|
|
stdout += new_data
|
|
|
|
sys.stdout.write(new_data.decode('ascii', 'ignore'))
|
|
|
|
sys.stdout.flush()
|
2020-10-14 21:36:47 +00:00
|
|
|
|
|
|
|
retcode = p.returncode
|
2021-07-23 09:23:40 +00:00
|
|
|
output = stdout.decode('ascii', 'ignore') + stderr.decode('ascii', 'ignore')
|
|
|
|
|
|
|
|
# remove new line from last line
|
|
|
|
output = output.rstrip()
|
2021-06-10 13:56:30 +00:00
|
|
|
print(output)
|
2020-10-14 21:36:47 +00:00
|
|
|
return retcode, output
|
|
|
|
|
|
|
|
|
2021-07-23 09:23:40 +00:00
|
|
|
def start_test():
|
|
|
|
# if uses any library linked to /usr this my affect the tools during boot
|
|
|
|
print("INFO: Making sure tools provided by device-mapper-persistent-data are not linked to /usr")
|
2020-10-14 21:36:47 +00:00
|
|
|
|
2021-07-23 09:23:40 +00:00
|
|
|
# Paths where we should have no libraries linked from
|
2020-10-14 21:36:47 +00:00
|
|
|
lib_paths = ["/usr/"]
|
|
|
|
|
|
|
|
package = "device-mapper-persistent-data"
|
|
|
|
run("yum install -y %s" % package)
|
2021-07-23 09:23:40 +00:00
|
|
|
# Get all tools that we need to check
|
2020-10-14 21:36:47 +00:00
|
|
|
ret, output = run("rpm -ql %s | grep \"sbin/\"" % package)
|
|
|
|
if ret != 0:
|
|
|
|
print("FAIL: Could not get the tools shipped from %s" % package)
|
|
|
|
return False
|
|
|
|
tools = output.split("\n")
|
|
|
|
|
|
|
|
error = False
|
|
|
|
for tool in tools:
|
|
|
|
if not tool:
|
2021-07-23 09:23:40 +00:00
|
|
|
# skip any blank line
|
2020-10-14 21:36:47 +00:00
|
|
|
continue
|
|
|
|
tool_error = 0
|
|
|
|
for lib_path in lib_paths:
|
2021-06-10 13:56:30 +00:00
|
|
|
print("INFO: Checking if %s is not linked to libraries at %s" % (tool, lib_path))
|
2020-10-14 21:36:47 +00:00
|
|
|
ret, linked_lib = run("ldd %s" % tool)
|
|
|
|
if ret != 0:
|
|
|
|
print("FAIL: Could not list dynamically libraries for %s" % (tool))
|
|
|
|
tool_error += 1
|
|
|
|
else:
|
2021-07-23 09:23:40 +00:00
|
|
|
# The command executed sucessfuly
|
|
|
|
# check if any library linked is from lib_path
|
2020-10-14 21:36:47 +00:00
|
|
|
links = linked_lib.split("\n")
|
|
|
|
for link in links:
|
|
|
|
if re.match(".*%s.*" % lib_path, link):
|
|
|
|
print("FAIL: %s is linked to %s" % (tool, link))
|
|
|
|
tool_error += 1
|
|
|
|
|
|
|
|
if tool_error == 0:
|
|
|
|
print("%s is not linked to %s" % (tool, lib_path))
|
|
|
|
else:
|
2021-07-23 09:23:40 +00:00
|
|
|
# found some error in at least 1 tool
|
2020-10-14 21:36:47 +00:00
|
|
|
error = True
|
|
|
|
|
|
|
|
if error:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if not start_test():
|
2021-06-10 13:56:30 +00:00
|
|
|
print("FAIL: test failed")
|
2020-10-14 21:36:47 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2021-06-10 13:56:30 +00:00
|
|
|
print("PASS: Test pass")
|
2020-10-14 21:36:47 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
2021-07-23 09:23:40 +00:00
|
|
|
main()
|