Skip to content

Commit 9981ab3

Browse files
committed
Check environment via .repo files instead of config.json in vm tests
openqa
1 parent 97e7a61 commit 9981ab3

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

tests/test_vms_exist.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import subprocess
33
import unittest
4+
from pathlib import Path
45

56
from qubesadmin import Qubes
67

@@ -16,8 +17,8 @@
1617
SD_VMS,
1718
)
1819

19-
with open("config.json") as f:
20-
CONFIG = json.load(f)
20+
DEV_REPO = Path("/etc/yum.repos.d/securedrop-workstation-dom0-dev.repo")
21+
STAGING_REPO = Path("/etc/yum.repos.d/securedrop-workstation-dom0-staging.repo")
2122

2223

2324
class SD_VM_Tests(unittest.TestCase):
@@ -40,7 +41,7 @@ def test_expected(self):
4041
for vm_name in SD_UNTAGGED_DEPRECATED_VMS:
4142
assert vm_name not in self.app.domains
4243

43-
@unittest.skipIf(CONFIG["environment"] != "prod", "Skipping on non-prod system")
44+
@unittest.skipIf(STAGING_REPO.exists or DEV_REPO.exists, "Skipping on non-prod system")
4445
def test_internal(self):
4546
internal = ["sd-proxy", "sd-proxy-dvm", "sd-viewer"]
4647

tests/test_vms_platform.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import json
21
import os
32
import re
43
import subprocess
54
import unittest
5+
from pathlib import Path
66

77
import pytest
88
from qubesadmin import Qubes
@@ -21,14 +21,22 @@
2121

2222
IS_CI = os.environ.get("CI") == "true"
2323

24+
DEV_REPO = Path("/etc/yum.repos.d/securedrop-workstation-dom0-dev.repo")
25+
STAGING_REPO = Path("/etc/yum.repos.d/securedrop-workstation-dom0-staging.repo")
26+
2427

2528
class SD_VM_Platform_Tests(unittest.TestCase):
2629
def setUp(self):
2730
self.app = Qubes()
28-
with open("config.json") as c:
29-
self.config = json.load(c)
30-
if "environment" not in self.config:
31-
self.config["environment"] = "dev"
31+
32+
# Order matters; if dev .repo file is installed,
33+
# it wins, then staging, due to package versioning
34+
if DEV_REPO.exists:
35+
self.environment = "dev"
36+
elif STAGING_REPO.exists:
37+
self.environment = "staging"
38+
else:
39+
self.environment = "prod"
3240

3341
def tearDown(self):
3442
pass
@@ -63,11 +71,11 @@ def _validate_apt_sources(self, vm):
6371
if vm.name in ["sd-whonix"]:
6472
return
6573

66-
if self.config["environment"] == "prod":
74+
if self.environment == "prod":
6775
component = "main"
6876
url = "https://apt.freedom.press"
6977
filename = "/etc/apt/sources.list.d/apt_freedom_press.sources"
70-
elif self.config["environment"] == "staging":
78+
elif self.environment == "staging":
7179
component = "main"
7280
url = "https://apt-test.freedom.press"
7381
filename = "/etc/apt/sources.list.d/apt-test_freedom_press.sources"
@@ -200,13 +208,13 @@ def test_sd_vm_apt_sources(self):
200208
assert (
201209
"Description: https://apt.freedom.press bookworm/main amd64 Packages\n" in contents
202210
)
203-
if self.config["environment"] == "prod":
211+
if self.environment == "prod":
204212
# prod setups shouldn't have any apt-test sources
205213
assert "apt-test.freedom.press" not in contents
206214
else:
207215
# staging/dev
208216
test_components = ["main"]
209-
if self.config["environment"] == "dev":
217+
if self.environment == "dev":
210218
test_components.append("nightlies")
211219
for component in test_components:
212220
assert (

0 commit comments

Comments
 (0)