Skip to content
Snippets Groups Projects
Verified Commit 41c3953a authored by Martin Matějek's avatar Martin Matějek
Browse files

Add NVMe drives to the allowed storage drive types

This will effectively also detect devices `/dev/nvme*`.
parent 79ad0d3a
1 merge request!28Add NVMe drives to the allowed storage drive types
Pipeline #114074 failed with stage
in 30 seconds
......@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
# [Unreleased]
### Added
- Add NVMe drives to the allowed storage device types.
## [0.10.2] - 2023-03-23
### Fixed
- init: Fix the notification on error
......
......@@ -2,15 +2,24 @@ import logging
import os
import shlex
from foris_controller_backends.uci import UciBackend, get_option_named, parse_bool, store_bool
from foris_controller_backends.cmdline import BaseCmdLine
from foris_controller_backends.files import BaseFile, inject_file_root, path_exists
from foris_controller.exceptions import (
FailedToParseFileContent,
FailedToParseCommandOutput,
BackendCommandFailed,
FailedToParseCommandOutput,
FailedToParseFileContent,
UciException,
)
from foris_controller_backends.cmdline import BaseCmdLine
from foris_controller_backends.files import (
BaseFile,
inject_file_root,
path_exists,
)
from foris_controller_backends.uci import (
UciBackend,
get_option_named,
parse_bool,
store_bool,
)
logger = logging.getLogger(__name__)
......@@ -138,8 +147,8 @@ class DriveManager(BaseCmdLine, BaseFile):
drive_dir = "/sys/class/block"
for dev in os.listdir(inject_file_root(drive_dir)):
# skip some device
if not dev.startswith("sd"):
# we are interested only in /dev/sd* and /dev/nvme* devices
if not dev.startswith(("sd", "nvme")):
continue
# is device mounted somewhere
......
0
250069680
#
# foris-controller-storage-module
# Copyright (C) 2018-2021 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
# Copyright (C) 2018-2023 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -17,20 +17,19 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
import pytest
import textwrap
from .conftest import file_root, CMDLINE_SCRIPT_ROOT
import pytest
from foris_controller_testtools.fixtures import (
FILE_ROOT_PATH,
file_root_init,
infrastructure,
uci_configs_init,
file_root_init,
FILE_ROOT_PATH,
)
from foris_controller_testtools.utils import FileFaker
from .conftest import CMDLINE_SCRIPT_ROOT, file_root
@pytest.fixture(params=["/", "/srv"], ids=["srv_not_mounted", "srv_mounted"], scope="function")
def stat_cmd(request):
......@@ -101,6 +100,22 @@ def blkid_sda_ok_cmd(request):
yield f
@pytest.fixture(scope="function")
def blkid_nvme_ok_cmd(request):
content = """\
#!/bin/sh
if [ "$1" != "/dev/nvme0n1p1" ] ; then
exit 1
elif [ "$2" = "-s" ] && [ "$3" = UUID ] && [ "$4" = "-o" ] && [ "$5" = "value" ]; then
echo "e2d635fb-e88c-4189-b928-b23c7e608297"
else
echo '/dev/nvme0n1p1: LABEL="srv" UUID="e2d635fb-e88c-4189-b928-b23c7e608297" UUID_SUB="74dbc859-1fce-4d38-a624-a546dd28945b" BLOCK_SIZE="4096" TYPE="btrfs" PARTUUID="51ce0b15-01"'
fi
"""
with FileFaker(CMDLINE_SCRIPT_ROOT, "/usr/sbin/blkid", True, textwrap.dedent(content)) as f:
yield f
@pytest.fixture(params=MOUNTS.keys(), scope="function")
def mounts_file(request):
with FileFaker(FILE_ROOT_PATH, "/proc/mounts", False, MOUNTS[request.param]) as f:
......@@ -180,6 +195,23 @@ def test_get_drives(
assert "drives" in res["data"]
def test_get_drives_nvme(
file_root_init, uci_configs_init, infrastructure, blkid_nvme_ok_cmd, mounts_file
):
"""Check whether we can detect NVMe drives."""
res = infrastructure.process_message(
{"module": "storage", "action": "get_drives", "kind": "request"}
)
assert "errors" not in res
assert "data" in res
assert "drives" in res["data"]
# there should be flash drive (sda) and nvme drive (nvme0n1)
assert len(res["data"]["drives"]) == 2
nvme_drive = res["data"]["drives"][1]
assert nvme_drive["dev"] == "nvme0n1"
def test_prepare_srv_drive(
file_root_init, uci_configs_init, infrastructure, prepare_srv_drive_sh_cmd
):
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment