#!/usr/bin/env python3 """Native libostree argument semantics, run in the normal build-tools stage.""" from pathlib import Path import runpy arguments = runpy.run_path(str(Path(__file__).resolve().parents[1] / 'adapters/kernel-arguments.py'))['arguments'] base = b'root=UUID=fixture rw quiet console=tty0 console=ttyS0 ostree=/managed' assert arguments(base, []) == ['root=UUID=fixture', 'rw', 'quiet', 'console=tty0', 'console=ttyS0'] edits = [{'op':'append-if-missing','argument':'quiet'}, {'op':'delete','argument':'quiet'}, {'op':'replace','argument':'console=ttyS0=ttyS1'}, {'op':'append','argument':'archipelago.test=yes'}] result = arguments(base, edits) assert 'quiet' not in result and 'console=ttyS0' not in result assert 'console=tty0' in result and 'console=ttyS1' in result and 'archipelago.test=yes' in result assert arguments(base, [{'op':'delete-if-present','argument':'absent'}]) == arguments(base, []) for change in [{'op':'delete','argument':'absent'}, {'op':'append','argument':'ostree=/bad'}, {'op':'append','argument':'test=yes ostree=/bad'}, {'op':'append','argument':'test="unterminated'}, {'op':'replace','argument':'absent=new'}]: try: arguments(base, [change]) except ValueError: pass else: raise AssertionError(change) print('Native kernel argument edit/duplicate/protected-selector checks passed')