From 10833a848fc0ca825d1dd5349587311a2e7ee33b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 8 Feb 2023 17:21:44 +0100 Subject: [PATCH] network: reset SNAP when calling netplan in dry-run mode --- subiquitycore/controllers/network.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/subiquitycore/controllers/network.py b/subiquitycore/controllers/network.py index dea34b58..7a71803d 100644 --- a/subiquitycore/controllers/network.py +++ b/subiquitycore/controllers/network.py @@ -15,6 +15,7 @@ import abc import asyncio +import contextlib import logging import os import subprocess @@ -294,10 +295,15 @@ class BaseNetworkController(BaseController): if os.path.exists('/lib/netplan/generate'): # If netplan appears to be installed, run generate to # at least test that what we wrote is acceptable to - # netplan. + # netplan but clear the SNAP environment variable to + # avoid that netplan thinks its running in a snap and + # tries to call netplan over the system bus. + env = os.environ.copy() + with contextlib.suppress(KeyError): + del env['SNAP'] await arun_command( ['netplan', 'generate', '--root', self.root], - check=True) + check=True, env=env) else: if devs_to_down or devs_to_delete: try: