55 lines
2.8 KiB
Python
55 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Real CPU Docker transport/failure regression; not engine or GPU qualification."""
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
|
|
spec = importlib.util.spec_from_file_location('package', Path(__file__).with_name('build-linux-package.py'))
|
|
package = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(package)
|
|
|
|
|
|
class LoaderContainerTests(unittest.TestCase):
|
|
def test_actual_nonroot_provision_and_failure_cleanup(self):
|
|
runtime_spec = importlib.util.spec_from_file_location('runtime', Path(__file__).with_name('build-runtime-image.py'))
|
|
runtime = importlib.util.module_from_spec(runtime_spec)
|
|
runtime_spec.loader.exec_module(runtime)
|
|
|
|
def probes():
|
|
containers = set(runtime.docker('ps', '-a', '--filter', 'name=strata-package-probe-',
|
|
'--format', '{{.ID}}').stdout.splitlines())
|
|
volumes = set(runtime.docker('volume', 'ls', '--filter', 'name=strata-package-probe-',
|
|
'--format', '{{.Name}}').stdout.splitlines())
|
|
return containers, volumes
|
|
|
|
before = probes()
|
|
with tempfile.TemporaryDirectory(prefix='strata-loader-contract-') as tmp:
|
|
binary, config = Path(tmp) / 'cli', Path(tmp) / 'config'
|
|
config.write_text('{"engine":{"executable":"@embedded"},"engine_probe":true}')
|
|
binary.write_text('#!/bin/sh\n'
|
|
'test "$(id -u)" = 65532 || exit 21\n'
|
|
'test "$1" = provision && test "$2" = --config || exit 22\n'
|
|
'grep -q @embedded "$3" || exit 23\n'
|
|
'test "$NVIDIA_VISIBLE_DEVICES" = void && test -z "$CUDA_VISIBLE_DEVICES" || exit 24\n'
|
|
'touch /tmp/owned-loader-fixture || exit 25\n'
|
|
'if touch /forbidden-loader-fixture 2>/dev/null; then exit 26; fi\n')
|
|
original = binary.read_bytes()
|
|
audit = {'minimum_glibc': '2.38'}
|
|
result = package.loader_probe(binary, config, audit, container=True)
|
|
self.assertEqual(result['base'], runtime.BASE)
|
|
self.assertFalse(result['gpu_tested'])
|
|
self.assertEqual(binary.read_bytes(), original)
|
|
self.assertEqual(probes(), before)
|
|
binary.write_text('#!/bin/sh\nexit 42\n')
|
|
with self.assertRaisesRegex(ValueError, 'provision failed'):
|
|
package.loader_probe(binary, config, audit, container=True)
|
|
self.assertEqual(probes(), before)
|
|
with self.assertRaisesRegex(ValueError, 'below engine requirement'):
|
|
package.loader_probe(binary, config, {'minimum_glibc': '99.0'}, container=True)
|
|
self.assertEqual(probes(), before)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|