command line for db selection added
@@ -25,12 +25,19 @@ __version__ = "${VERSION}"
@pytest.fixture
-def reset_and_start_foglamp():
- """Fixture that kills foglamp, reset database and starts foglamp again"""
+def reset_and_start_foglamp(storage_plugin):
+ """Fixture that kills foglamp, reset database and starts foglamp again
+ storage_plugin: Fixture that defines the storage plugin to be used for tests
+ """
- # TODO: allow to sed storage.json and use postgres database plugin
assert os.environ.get('FOGLAMP_ROOT') is not None
+
subprocess.run(["$FOGLAMP_ROOT/scripts/foglamp kill"], shell=True, check=True)
+ if storage_plugin == 'postgres':
+ subprocess.run(["sed -i 's/sqlite/postgres/g' $FOGLAMP_ROOT/data/etc/storage.json"], shell=True, check=True)
+ else:
+ subprocess.run(["sed -i 's/postgres/sqlite/g' $FOGLAMP_ROOT/data/etc/storage.json"], shell=True, check=True)
+
subprocess.run(["echo YES | $FOGLAMP_ROOT/scripts/foglamp reset"], shell=True, check=True)
subprocess.run(["$FOGLAMP_ROOT/scripts/foglamp start"], shell=True)
stat = subprocess.run(["$FOGLAMP_ROOT/scripts/foglamp status"], shell=True, stdout=subprocess.PIPE)
@@ -274,6 +281,8 @@ def disable_schedule():
def pytest_addoption(parser):
+ parser.addoption("--storage-plugin", action="store", default="sqlite",
+ help="Database plugin to use for tests")
parser.addoption("--foglamp-url", action="store", default="localhost:8081",
help="FogLAMP client api url")
parser.addoption("--use-pip-cache", action="store", default=False,
@@ -338,6 +347,11 @@ def pytest_addoption(parser):
parser.addoption("--kafka-rest-port", action="store", default="8082", help="Kafka Rest Proxy Port")
+@pytest.fixture
+def storage_plugin(request):
+ return request.config.getoption("--storage-plugin")
+
+
@pytest.fixture
def south_branch(request):
return request.config.getoption("--south-branch")
