summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-11-07 16:17:13 +0300
committerMaxim Devaev <[email protected]>2022-11-07 16:17:13 +0300
commit29bd1e2f6f026464ff6e9151631f326cf3486981 (patch)
treea6e484d08daa7fde58a9c4ef425906baf8974d4f
parent68b3dd4fd0801858328c16d3ae56215c76f25873 (diff)
static env
-rw-r--r--Makefile3
-rw-r--r--kvmd/env.py11
-rw-r--r--kvmd/fstab.py4
-rw-r--r--testenv/Dockerfile1
-rw-r--r--testenv/env.py26
-rw-r--r--testenv/fakes/etc/fstab2
6 files changed, 36 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 37813041..8d012a97 100644
--- a/Makefile
+++ b/Makefile
@@ -104,14 +104,13 @@ run: testenv $(TESTENV_GPIO)
--volume `pwd`/testenv/run:/run/kvmd:rw \
--volume `pwd`/testenv:/testenv:ro \
--volume `pwd`/kvmd:/kvmd:ro \
+ --volume `pwd`/testenv/env.py:/kvmd/env.py:ro \
--volume `pwd`/web:/usr/share/kvmd/web:ro \
--volume `pwd`/extras:/usr/share/kvmd/extras:ro \
--volume `pwd`/configs:/usr/share/kvmd/configs.default:ro \
--volume `pwd`/contrib/keymaps:/usr/share/kvmd/keymaps:ro \
--device $(TESTENV_VIDEO):$(TESTENV_VIDEO) \
--device $(TESTENV_GPIO):$(TESTENV_GPIO) \
- --env KVMD_SYSFS_PREFIX=/fake_sysfs \
- --env KVMD_PROCFS_PREFIX=/fake_procfs \
$(if $(TESTENV_RELAY),--device $(TESTENV_RELAY):$(TESTENV_RELAY),) \
--publish 8080:80/tcp \
--publish 4430:443/tcp \
diff --git a/kvmd/env.py b/kvmd/env.py
index e1aaeff7..82149951 100644
--- a/kvmd/env.py
+++ b/kvmd/env.py
@@ -20,12 +20,7 @@
# ========================================================================== #
-import os
-
-
# =====
-# XXX: Don't use these variables for any purpose other than testing.
-# It can be removed at any time.
-
-SYSFS_PREFIX = str(os.getenv("KVMD_SYSFS_PREFIX", "")).strip()
-PROCFS_PREFIX = str(os.getenv("KVMD_PROCFS_PREFIX", "")).strip()
+ETC_PREFIX = ""
+SYSFS_PREFIX = ""
+PROCFS_PREFIX = ""
diff --git a/kvmd/fstab.py b/kvmd/fstab.py
index 0dfb8d52..bd3a593c 100644
--- a/kvmd/fstab.py
+++ b/kvmd/fstab.py
@@ -23,6 +23,8 @@
import re
import dataclasses
+from . import env
+
# =====
class PartitionType:
@@ -43,7 +45,7 @@ class Partition:
def find_partition(part_type: str) -> Partition:
assert part_type in PartitionType.ALL
- fstab_path = "/etc/fstab"
+ fstab_path = f"{env.ETC_PREFIX}/etc/fstab"
with open(fstab_path) as file:
for line in file.read().split("\n"):
line = line.strip()
diff --git a/testenv/Dockerfile b/testenv/Dockerfile
index fb9a19f4..12a93a8e 100644
--- a/testenv/Dockerfile
+++ b/testenv/Dockerfile
@@ -107,5 +107,6 @@ RUN mkdir -p \
COPY testenv/fakes/vcgencmd /opt/vc/bin/
COPY testenv/fakes/sys /fake_sysfs/sys
COPY testenv/fakes/proc /fake_procfs/proc
+COPY testenv/fakes/etc /fake_etc/etc
CMD /bin/bash
diff --git a/testenv/env.py b/testenv/env.py
new file mode 100644
index 00000000..a65ba3d0
--- /dev/null
+++ b/testenv/env.py
@@ -0,0 +1,26 @@
+# ========================================================================== #
+# #
+# KVMD - The main PiKVM daemon. #
+# #
+# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <https://www.gnu.org/licenses/>. #
+# #
+# ========================================================================== #
+
+
+# =====
+ETC_PREFIX = "/fake_etc"
+SYSFS_PREFIX = "/fake_sysfs"
+PROCFS_PREFIX = "/fake_procfs"
diff --git a/testenv/fakes/etc/fstab b/testenv/fakes/etc/fstab
new file mode 100644
index 00000000..27a0f9f4
--- /dev/null
+++ b/testenv/fakes/etc/fstab
@@ -0,0 +1,2 @@
+LABEL=PIPST /var/lib/kvmd/pst ext4 nodev,nosuid,noexec,ro,errors=remount-ro,data=journal,X-kvmd.pst-user=kvmd-pst 0 0
+LABEL=PIMSD /var/lib/kvmd/msd ext4 nodev,nosuid,noexec,ro,errors=remount-ro,data=journal,X-kvmd.otgmsd-user=kvmd 0 0