Test whether the test suite is runing in systemd-nspawn with ``--suppress-sync=true``. This can be used to skip tests that rely on ``fsync()`` calls and similar not being intercepted.
()
| 3149 | |
| 3150 | |
| 3151 | def in_systemd_nspawn_sync_suppressed() -> bool: |
| 3152 | """ |
| 3153 | Test whether the test suite is runing in systemd-nspawn |
| 3154 | with ``--suppress-sync=true``. |
| 3155 | |
| 3156 | This can be used to skip tests that rely on ``fsync()`` calls |
| 3157 | and similar not being intercepted. |
| 3158 | """ |
| 3159 | |
| 3160 | if not hasattr(os, "O_SYNC"): |
| 3161 | return False |
| 3162 | |
| 3163 | try: |
| 3164 | with open("/run/systemd/container", "rb") as fp: |
| 3165 | if fp.read().rstrip() != b"systemd-nspawn": |
| 3166 | return False |
| 3167 | except FileNotFoundError: |
| 3168 | return False |
| 3169 | |
| 3170 | # If systemd-nspawn is used, O_SYNC flag will immediately |
| 3171 | # trigger EINVAL. Otherwise, ENOENT will be given instead. |
| 3172 | import errno |
| 3173 | try: |
| 3174 | fd = os.open(__file__, os.O_RDONLY | os.O_SYNC) |
| 3175 | except OSError as err: |
| 3176 | if err.errno == errno.EINVAL: |
| 3177 | return True |
| 3178 | else: |
| 3179 | os.close(fd) |
| 3180 | |
| 3181 | return False |
| 3182 | |
| 3183 | def run_no_yield_async_fn(async_fn, /, *args, **kwargs): |
| 3184 | coro = async_fn(*args, **kwargs) |
searching dependent graphs…