39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only checks after installing the RPM in a disposable build container."""
|
|
from pathlib import Path
|
|
import stat
|
|
import subprocess
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PROVIDER = Path('/usr/lib/ocf/resource.d/loxthelion')
|
|
AGENT = PROVIDER / 'managed-container'
|
|
PACKAGE = 'ocf-managed-container'
|
|
|
|
|
|
def output(*args):
|
|
return subprocess.check_output(args, text=True)
|
|
|
|
|
|
assert output('rpm', '-q', '--qf', '%{ARCH}', PACKAGE) == 'noarch'
|
|
assert output('rpm', '-q', '--scripts', PACKAGE) == ''
|
|
subprocess.run(['rpm', '-V', PACKAGE], check=True)
|
|
expected = {AGENT: ROOT / 'refactored/managed-container'}
|
|
for path in (ROOT / 'refactored/managed-container.d').glob('*.sh'):
|
|
expected[PROVIDER / 'managed-container.d' / path.name] = path
|
|
assert len(expected) == 10
|
|
for path, source in expected.items():
|
|
assert path.read_bytes() == source.read_bytes(), path
|
|
info = path.stat()
|
|
assert (info.st_uid, info.st_gid) == (0, 0), path
|
|
assert stat.S_IMODE(info.st_mode) == (0o755 if path == AGENT else 0o644), path
|
|
|
|
owned = set(output('rpm', '-ql', PACKAGE).splitlines())
|
|
allowed = {str(path) for path in expected} | {str(PROVIDER), str(PROVIDER / 'managed-container.d')}
|
|
unexpected = {path for path in owned - allowed if not path.startswith('/usr/share/doc/' + PACKAGE)}
|
|
assert not unexpected, unexpected
|
|
|
|
reference = output(str(ROOT / 'reference/managed-container'), 'meta-data')
|
|
installed = subprocess.check_output([str(AGENT), 'meta-data'], cwd='/tmp', text=True)
|
|
assert installed == reference
|
|
print('PASS installed RPM: noarch, file integrity, root ownership, modes, payload, no scriptlets, metadata/module loading')
|