Merge pull request #535 from Ostrokrzew/by-id
Disallow to use other than by-id path to core or cache device
This commit is contained in:
@@ -19,12 +19,12 @@ class Cache:
|
||||
self.__metadata_size = None
|
||||
|
||||
def __get_cache_id(self):
|
||||
cmd = f"{list_cmd()} | grep {self.cache_device.system_path}"
|
||||
cmd = f"{list_cmd(by_id_path=False)} | grep {self.cache_device.short_path}"
|
||||
output = TestRun.executor.run(cmd)
|
||||
if output.exit_code == 0 and output.stdout.strip():
|
||||
return output.stdout.split()[1]
|
||||
else:
|
||||
raise Exception(f"There is no cache started on {self.cache_device.system_path}.")
|
||||
raise Exception(f"There is no cache started on {self.cache_device.path}.")
|
||||
|
||||
def get_core_devices(self):
|
||||
return get_cores(self.cache_id)
|
||||
|
@@ -35,7 +35,7 @@ def start_cache(cache_dev: Device, cache_mode: CacheMode = None,
|
||||
_cache_id = None if cache_id is None else str(cache_id)
|
||||
_cache_mode = None if cache_mode is None else cache_mode.name.lower()
|
||||
output = TestRun.executor.run(start_cmd(
|
||||
cache_dev=cache_dev.system_path, cache_mode=_cache_mode, cache_line_size=_cache_line_size,
|
||||
cache_dev=cache_dev.path, cache_mode=_cache_mode, cache_line_size=_cache_line_size,
|
||||
cache_id=_cache_id, force=force, load=load, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to start cache.", output)
|
||||
@@ -53,11 +53,11 @@ def stop_cache(cache_id: int, no_data_flush: bool = False, shortcut: bool = Fals
|
||||
def add_core(cache: Cache, core_dev: Device, core_id: int = None, shortcut: bool = False):
|
||||
_core_id = None if core_id is None else str(core_id)
|
||||
output = TestRun.executor.run(
|
||||
add_core_cmd(cache_id=str(cache.cache_id), core_dev=core_dev.system_path,
|
||||
add_core_cmd(cache_id=str(cache.cache_id), core_dev=core_dev.path,
|
||||
core_id=_core_id, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to add core.", output)
|
||||
core = Core(core_dev.system_path, cache.cache_id)
|
||||
core = Core(core_dev.path, cache.cache_id)
|
||||
return core
|
||||
|
||||
|
||||
@@ -71,18 +71,18 @@ def remove_core(cache_id: int, core_id: int, force: bool = False, shortcut: bool
|
||||
|
||||
def remove_detached(core_device: Device, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
remove_detached_cmd(core_device=core_device.system_path, shortcut=shortcut))
|
||||
remove_detached_cmd(core_device=core_device.path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to remove detached core.", output)
|
||||
return output
|
||||
|
||||
|
||||
def try_add(core_device: Device, cache_id: int, core_id: int = None):
|
||||
output = TestRun.executor.run(script_try_add_cmd(str(cache_id), core_device.system_path,
|
||||
output = TestRun.executor.run(script_try_add_cmd(str(cache_id), core_device.path,
|
||||
str(core_id) if core_id is not None else None))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to execute try add script command.", output)
|
||||
return Core(core_device.system_path, cache_id)
|
||||
return Core(core_device.path, cache_id)
|
||||
|
||||
|
||||
def purge_cache(cache_id: int):
|
||||
@@ -128,16 +128,17 @@ def flush(cache_id: int, core_id: int = None, shortcut: bool = False):
|
||||
|
||||
def load_cache(device: Device, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
load_cmd(cache_dev=device.system_path, shortcut=shortcut))
|
||||
load_cmd(cache_dev=device.path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to load cache.", output)
|
||||
return Cache(device)
|
||||
|
||||
|
||||
def list_caches(output_format: OutputFormat = None, shortcut: bool = False):
|
||||
def list_caches(output_format: OutputFormat = None, by_id_path: bool = True,
|
||||
shortcut: bool = False):
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
output = TestRun.executor.run(
|
||||
list_cmd(output_format=_output_format, shortcut=shortcut))
|
||||
list_cmd(output_format=_output_format, by_id_path=by_id_path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to list caches.", output)
|
||||
return output
|
||||
@@ -154,7 +155,7 @@ def print_version(output_format: OutputFormat = None, shortcut: bool = False):
|
||||
|
||||
def zero_metadata(cache_dev: Device, shortcut: bool = False):
|
||||
output = TestRun.executor.run(
|
||||
zero_metadata_cmd(cache_dev=cache_dev.system_path, shortcut=shortcut))
|
||||
zero_metadata_cmd(cache_dev=cache_dev.path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Failed to wipe metadata.", output)
|
||||
return output
|
||||
@@ -179,7 +180,8 @@ def remove_all_detached_cores():
|
||||
|
||||
def print_statistics(cache_id: int, core_id: int = None, per_io_class: bool = False,
|
||||
io_class_id: int = None, filter: List[StatsFilter] = None,
|
||||
output_format: OutputFormat = None, shortcut: bool = False):
|
||||
output_format: OutputFormat = None, by_id_path: bool = True,
|
||||
shortcut: bool = False):
|
||||
_output_format = None if output_format is None else output_format.name
|
||||
_core_id = None if core_id is None else str(core_id)
|
||||
_io_class_id = None if io_class_id is None else str(io_class_id)
|
||||
@@ -192,7 +194,8 @@ def print_statistics(cache_id: int, core_id: int = None, per_io_class: bool = Fa
|
||||
print_statistics_cmd(
|
||||
cache_id=str(cache_id), core_id=_core_id,
|
||||
per_io_class=per_io_class, io_class_id=_io_class_id,
|
||||
filter=_filter, output_format=_output_format, shortcut=shortcut))
|
||||
filter=_filter, output_format=_output_format,
|
||||
by_id_path=by_id_path, shortcut=shortcut))
|
||||
if output.exit_code != 0:
|
||||
raise CmdException("Printing statistics failed.", output)
|
||||
return output
|
||||
|
@@ -2,24 +2,20 @@
|
||||
# Copyright(c) 2019-2020 Intel Corporation
|
||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
#
|
||||
import csv
|
||||
|
||||
import csv
|
||||
import json
|
||||
import re
|
||||
from api.cas import casadm
|
||||
from test_utils.output import CmdException
|
||||
from test_utils.size import parse_unit
|
||||
from storage_devices.device import Device
|
||||
from api.cas.cache_config import *
|
||||
from api.cas.casadm_params import *
|
||||
from api.cas.version import CasVersion
|
||||
from datetime import timedelta
|
||||
from typing import List
|
||||
|
||||
from api.cas import casadm
|
||||
from api.cas.cache_config import *
|
||||
from api.cas.casadm_params import *
|
||||
from api.cas.version import CasVersion
|
||||
from storage_devices.device import Device
|
||||
from test_utils.size import parse_unit
|
||||
from test_utils.output import CmdException
|
||||
|
||||
|
||||
class Stats(dict):
|
||||
|
@@ -95,7 +95,8 @@ def start_cmd(cache_dev: str, cache_mode: str = None, cache_line_size: str = Non
|
||||
|
||||
def print_statistics_cmd(cache_id: str, core_id: str = None, per_io_class: bool = False,
|
||||
io_class_id: str = None, filter: str = None,
|
||||
output_format: str = None, shortcut: bool = False):
|
||||
output_format: str = None, by_id_path: bool = True,
|
||||
shortcut: bool = False):
|
||||
command = (" -P -i " if shortcut else " --stats --cache-id ") + cache_id
|
||||
if core_id is not None:
|
||||
command += (" -j " if shortcut else " --core-id ") + core_id
|
||||
@@ -109,6 +110,8 @@ def print_statistics_cmd(cache_id: str, core_id: str = None, per_io_class: bool
|
||||
command += (" -f " if shortcut else " --filter ") + filter
|
||||
if output_format is not None:
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
if by_id_path:
|
||||
command += (" -b " if shortcut else " --by-id-path ")
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
@@ -126,10 +129,12 @@ def stop_cmd(cache_id: str, no_data_flush: bool = False, shortcut: bool = False)
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
def list_cmd(output_format: str = None, shortcut: bool = False):
|
||||
def list_cmd(output_format: str = None, by_id_path: bool = True, shortcut: bool = False):
|
||||
command = " -L" if shortcut else " --list-caches"
|
||||
if output_format == "table" or output_format == "csv":
|
||||
command += (" -o " if shortcut else " --output-format ") + output_format
|
||||
if by_id_path:
|
||||
command += (" -b " if shortcut else " --by-id-path ")
|
||||
return casadm_bin + command
|
||||
|
||||
|
||||
|
@@ -26,7 +26,7 @@ SEQ_CUT_OFF_THRESHOLD_DEFAULT = Size(1, Unit.MebiByte)
|
||||
class Core(Device):
|
||||
def __init__(self, core_device: str, cache_id: int):
|
||||
self.core_device = Device(core_device)
|
||||
self.system_path = None
|
||||
self.path = None
|
||||
core_info = self.__get_core_info()
|
||||
if core_info["core_id"] != "-":
|
||||
self.core_id = int(core_info["core_id"])
|
||||
@@ -38,14 +38,14 @@ class Core(Device):
|
||||
|
||||
def __get_core_info(self):
|
||||
output = TestRun.executor.run(
|
||||
list_cmd(OutputFormat.csv.name))
|
||||
list_cmd(OutputFormat.csv.name, by_id_path=False))
|
||||
if output.exit_code != 0:
|
||||
raise Exception("Failed to execute list caches command.")
|
||||
output_lines = output.stdout.splitlines()
|
||||
for line in output_lines:
|
||||
split_line = line.split(',')
|
||||
if split_line[0] == "core" and (split_line[2] == self.core_device.system_path
|
||||
or split_line[5] == self.system_path):
|
||||
if split_line[0] == "core" and (split_line[2] == self.core_device.short_path
|
||||
or split_line[5] == self.path):
|
||||
return {"core_id": split_line[1],
|
||||
"core_device": split_line[2],
|
||||
"status": split_line[3],
|
||||
@@ -132,7 +132,7 @@ class Core(Device):
|
||||
def check_if_is_present_in_os(self, should_be_visible=True):
|
||||
device_in_system_message = "CAS device exists in OS."
|
||||
device_not_in_system_message = "CAS device does not exist in OS."
|
||||
item = fs_utils.ls_item(f"{self.system_path}")
|
||||
item = fs_utils.ls_item(f"{self.path}")
|
||||
if item is not None:
|
||||
if should_be_visible:
|
||||
TestRun.LOGGER.info(device_in_system_message)
|
||||
|
@@ -70,11 +70,8 @@ class CacheConfigLine:
|
||||
self.extra_flags = extra_flags
|
||||
|
||||
def __str__(self):
|
||||
cache_symlink = self.cache_device.get_device_link("/dev/disk/by-id")
|
||||
cache_device_path = (
|
||||
cache_symlink.full_path if cache_symlink is not None else self.cache_device.system_path
|
||||
)
|
||||
params = [str(self.cache_id), cache_device_path, self.cache_mode.name, self.extra_flags]
|
||||
params = [str(self.cache_id), self.cache_device.path,
|
||||
self.cache_mode.name, self.extra_flags]
|
||||
return '\t'.join(params)
|
||||
|
||||
|
||||
@@ -88,9 +85,6 @@ class CoreConfigLine:
|
||||
self.extra_flags = extra_flags
|
||||
|
||||
def __str__(self):
|
||||
core_symlink = self.core_device.get_device_link("/dev/disk/by-id")
|
||||
core_device_path = (
|
||||
core_symlink.full_path if core_symlink is not None else self.core_device.system_path
|
||||
)
|
||||
params = [str(self.cache_id), str(self.core_id), core_device_path, self.extra_flags]
|
||||
params = [str(self.cache_id), str(self.core_id),
|
||||
self.core_device.path, self.extra_flags]
|
||||
return '\t'.join(params)
|
||||
|
Reference in New Issue
Block a user