← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~ack/maas:file-backed-value-path-property into maas:master

 

Alberto Donato has proposed merging ~ack/maas:file-backed-value-path-property into maas:master.

Commit message:
make FileBackedValue.path a property.

This is needed to avoid get_maas_data_path calls at import time, before snap
env vars are set up



Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~ack/maas/+git/maas/+merge/437290
-- 
Your team MAAS Committers is subscribed to branch maas:master.
diff --git a/src/conftest.py b/src/conftest.py
index 9769c93..4743647 100644
--- a/src/conftest.py
+++ b/src/conftest.py
@@ -24,7 +24,7 @@ def clean_globals(tmpdir):
     base_path = Path(tmpdir)
     for var in (MAAS_ID, MAAS_UUID, MAAS_SHARED_SECRET):
         var.clear_cached()
-        var.path = base_path / var.name
+        var._path = lambda: base_path / var.name
 
     MAAS_SECRET.set(None)
     yield
diff --git a/src/provisioningserver/__main__.py b/src/provisioningserver/__main__.py
index 5f22393..719976d 100644
--- a/src/provisioningserver/__main__.py
+++ b/src/provisioningserver/__main__.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python3
 # Copyright 2012-2021 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
diff --git a/src/provisioningserver/utils/env.py b/src/provisioningserver/utils/env.py
index 4b29d5f..4ea40f8 100644
--- a/src/provisioningserver/utils/env.py
+++ b/src/provisioningserver/utils/env.py
@@ -42,10 +42,13 @@ class FileBackedValue:
 
     def __init__(self, name):
         self.name = name
-        self.path = Path(get_maas_data_path(self.name))
         self._value = None
         self._lock = threading.Lock()
 
+    @property
+    def path(self) -> Path:
+        return self._path()
+
     def clear_cached(self):
         """Clear cached value so that next get call reads it again from disk."""
         self._value = None
@@ -85,6 +88,10 @@ class FileBackedValue:
             value = value.strip()
         return value if value else None
 
+    def _path(self) -> Path:
+        # separate function so that it can be overridden in tests
+        return Path(get_maas_data_path(self.name))
+
 
 MAAS_ID = FileBackedValue("maas_id")
 MAAS_UUID = FileBackedValue("maas_uuid")

Follow ups