Enable logging mechanism and example of logger usage in one test

This commit is contained in:
Katarzyna Lapinska
2019-10-23 11:03:38 +02:00
parent 06b3e69c0f
commit 35d52caf74
5 changed files with 116 additions and 74 deletions

View File

@@ -4,39 +4,47 @@
#
import logging
import pytest
from api.cas import casadm, casadm_parser
from tests.conftest import base_prepare
from core.test_run import TestRun
from storage_devices.disk import DiskType
from test_utils.size import Unit, Size
LOGGER = logging.getLogger(__name__)
@pytest.mark.parametrize("shortcut", [True, False])
@pytest.mark.parametrize('prepare_and_cleanup',
[{"core_count": 0, "cache_count": 1, "cache_type": "optane"}, ],
indirect=True)
def test_cli_start_stop_default_value(prepare_and_cleanup, shortcut):
prepare()
cache_device = next(
disk for disk in TestRun.dut.disks if disk.disk_type == DiskType.optane)
cache_device.create_partitions([Size(500, Unit.MebiByte)])
cache_device = cache_device.partitions[0]
casadm.start_cache(cache_device, shortcut=shortcut, force=True)
with TestRun.LOGGER.step("Prepare devices"):
cache_device = next(
disk for disk in TestRun.dut.disks if disk.disk_type == DiskType.optane)
cache_device.create_partitions([Size(500, Unit.MebiByte)])
cache_device = cache_device.partitions[0]
caches = casadm_parser.get_caches()
assert len(caches) == 1
assert caches[0].cache_device.system_path == cache_device.system_path
with TestRun.LOGGER.step("Start cache"):
casadm.start_cache(cache_device, shortcut=shortcut, force=True)
casadm.stop_cache(cache_id=caches[0].cache_id, shortcut=shortcut)
with TestRun.LOGGER.step("Check if cache started successfully"):
caches = casadm_parser.get_caches()
if len(caches) != 1:
TestRun.LOGGER.error(f"There is wrong caches count found in OS: {len(caches)}")
if caches[0].cache_device.system_path != cache_device.system_path:
TestRun.LOGGER.error(f"Cache started using wrong device: "
f"{caches[0].cache_device.system_path}. "
f"Should be {cache_device.system_path}")
output = casadm.list_caches(shortcut=shortcut)
caches = casadm_parser.get_caches()
assert len(caches) == 0
assert output.stdout == "No caches running"
with TestRun.LOGGER.step("Stop cache"):
casadm.stop_cache(cache_id=caches[0].cache_id, shortcut=shortcut)
with TestRun.LOGGER.step("Check if cache stopped properly"):
output = casadm.list_caches(shortcut=shortcut)
caches = casadm_parser.get_caches()
if len(caches) != 0:
TestRun.LOGGER.error(f"There is wrong caches count found in OS: {len(caches)}. "
f"Should be 0.")
if output.stdout != "No caches running":
TestRun.LOGGER.error("There is no 'No caches running' info in casadm -L output")
@pytest.mark.parametrize("shortcut", [True, False])
@@ -44,7 +52,6 @@ def test_cli_start_stop_default_value(prepare_and_cleanup, shortcut):
[{"core_count": 1, "cache_count": 1, "cache_type": "optane"}],
indirect=True)
def test_cli_add_remove_default_value(prepare_and_cleanup, shortcut):
prepare()
cache_device = next(
disk for disk in TestRun.dut.disks if disk.disk_type == DiskType.optane)
cache_device.create_partitions([Size(500, Unit.MebiByte)])
@@ -70,7 +77,3 @@ def test_cli_add_remove_default_value(prepare_and_cleanup, shortcut):
caches = casadm_parser.get_caches()
assert len(caches) == 0
assert output.stdout == "No caches running"
def prepare():
base_prepare()