Skip to content

Commit

Permalink
Merge pull request #1253 from pdebski21/test_standby_init_with_preexi…
Browse files Browse the repository at this point in the history
…sting_metadata

Test standby init with preexisting metadata or preexisting filesystem
  • Loading branch information
Robert Baldyga authored Jun 29, 2022
2 parents 8d8971d + b7792bb commit 36e1139
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 2 deletions.
5 changes: 5 additions & 0 deletions test/functional/api/cas/cli_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
r" discard on-disk metadata and start fresh cache instance\."
]

standby_init_with_existing_filesystem = [
r"A filesystem exists on \S+. Specify the --force option if you wish to add the cache anyway.",
r"Note: this may result in loss of data"
]

error_inserting_cache = [
r"Error inserting cache \d+"
]
Expand Down
114 changes: 112 additions & 2 deletions test/functional/tests/cli/test_cli_standby.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

from api.cas import casadm, casadm_parser, dmesg
from api.cas.casadm import standby_init
from api.cas.cli import casadm_bin
from api.cas.cli import casadm_bin, standby_init_cmd
from core.test_run import TestRun
from storage_devices.device import Device
from storage_devices.disk import DiskType, DiskTypeSet
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
from test_tools.dd import Dd
from test_tools.disk_utils import Filesystem
from test_utils.filesystem.file import File
from test_utils.os_utils import sync
from test_utils.output import CmdException
Expand All @@ -25,6 +26,8 @@
mutually_exclusive_params_load,
activate_without_detach,
cache_line_size_mismatch,
start_cache_with_existing_metadata,
standby_init_with_existing_filesystem,
)
from api.cas.cache_config import CacheLineSize, CacheStatus
from api.cas import cli
Expand Down Expand Up @@ -459,3 +462,110 @@ def test_activate_neg_cache_line_size():
f'Expected Cache state: "{CacheStatus.standby.value}" '
f'Got "{cache_status.value}" instead.'
)


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
def test_standby_init_with_preexisting_metadata():
"""
title: Initialize standby cache instance with preexisting metadata
description: |
Initialize standby cache instance with preexisting metadata with and without force flag
pass_criteria:
- initialize cache without force flag fails and informative error message is printed
- initialize cache with force flag succeeds and passive instance is present in system
"""
with TestRun.step("Prepare device for cache"):
cache_device = TestRun.disks["cache"]
cache_device.create_partitions([Size(200, Unit.MebiByte)])
cache_device = cache_device.partitions[0]
cls = CacheLineSize.LINE_32KiB
cache_id = 1

with TestRun.step("Start standby cache instance"):
cache = casadm.standby_init(
cache_dev=cache_device,
cache_line_size=int(cls.value.value / Unit.KibiByte.value),
cache_id=cache_id,
force=True,
)

with TestRun.step("Stop standby cache instance"):
cache.stop()

with TestRun.step("Try initialize cache without force flag"):
output = TestRun.executor.run(
standby_init_cmd(
cache_dev=cache_device.path,
cache_id=str(cache_id),
cache_line_size=str(int(cls.value.value / Unit.KibiByte.value)),
)
)
if not check_stderr_msg(output, start_cache_with_existing_metadata):
TestRun.LOGGER.error(
f"Invalid error message. Expected {start_cache_with_existing_metadata}."
f"Got {output.stderr}"
)

with TestRun.step("Try initialize cache with force flag"):
casadm.standby_init(
cache_dev=cache_device,
cache_line_size=int(cls.value.value / Unit.KibiByte.value),
cache_id=cache_id,
force=True,
)

with TestRun.step("Verify whether passive instance is running"):
caches = casadm_parser.get_caches()
if len(caches) != 1:
TestRun.LOGGER.error("Standby cache instance is not running!")


@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.nand, DiskType.optane]))
@pytest.mark.require_disk("core", DiskTypeLowerThan("cache"))
@pytest.mark.parametrizex("filesystem", Filesystem)
def test_standby_init_with_preexisting_filesystem(filesystem):
"""
title: Initialize standby cache instance with preexisting filesystem
description: |
Initialize standby cache instance with preexisting filesystem with and without force flag
pass_criteria:
- initialize cache without force flag fails and informative error message is printed
- initialize cache with force flag succeeds and passive instance is present in system
"""
with TestRun.step("Prepare device for cache"):
cache_device = TestRun.disks["cache"]
cache_device.create_partitions([Size(200, Unit.MebiByte)])
cache_device = cache_device.partitions[0]
cls = CacheLineSize.LINE_32KiB
cache_id = 1

with TestRun.step("Create filesystem on cache device partition"):
cache_device.create_filesystem(filesystem)

with TestRun.step("Try initialize cache without force flag"):
output = TestRun.executor.run(
standby_init_cmd(
cache_dev=cache_device.path,
cache_id=str(cache_id),
cache_line_size=str(int(cls.value.value / Unit.KibiByte.value)),
)
)
if not check_stderr_msg(output, standby_init_with_existing_filesystem):
TestRun.LOGGER.error(
f"Invalid error message. Expected {standby_init_with_existing_filesystem}."
f"Got {output.stderr}"
)

with TestRun.step("Try initialize cache with force flag"):
casadm.standby_init(
cache_dev=cache_device,
cache_line_size=int(cls.value.value / Unit.KibiByte.value),
cache_id=cache_id,
force=True,
)

with TestRun.step("Verify whether passive instance is running"):
caches = casadm_parser.get_caches()
if len(caches) != 1:
TestRun.LOGGER.error("Standby cache instance is not running!")

0 comments on commit 36e1139

Please sign in to comment.