Initial commit
This commit is contained in:
commit
1b51716d1b
72 changed files with 8204 additions and 0 deletions
631
tests/cli/test_storage.py
Normal file
631
tests/cli/test_storage.py
Normal file
|
|
@ -0,0 +1,631 @@
|
|||
"""Test for the cli componenets"""
|
||||
# pylint: disable=redefined-outer-name, no-name-in-module, unused-import
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import redfish_cli.cli
|
||||
from redfish_cli import api
|
||||
from redfish_cli.api import storage
|
||||
from redfish_cli.api.exceptions import LogicalVolumeCreationFailure
|
||||
|
||||
from ..utils import get_test_json, MockResponse, MockRedfishResponse
|
||||
|
||||
from .test_cli import secrets
|
||||
|
||||
|
||||
def test_create_logical_volume(capsys, monkeypatch):
|
||||
"""Test the create-logical-volume command"""
|
||||
# pylint: disable=fixme, unused-argument, unused-variable
|
||||
# TODO: Write actual tests when the create-logical-volume code is fixed
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"logical",
|
||||
"create",
|
||||
"-c",
|
||||
"controller",
|
||||
"-d",
|
||||
"disk",
|
||||
"-r",
|
||||
"0",
|
||||
]
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}", headers={"Location": "/JOB12345"}
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(redfish_cli.api, "firmware_version", lambda args: 2)
|
||||
|
||||
redfish_cli.cli.create_logical_volume(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert "JOB12345" in result
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
# pylint: disable=line-too-long
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
ok=False, content='{"msg":"and error occurred"}'
|
||||
),
|
||||
)
|
||||
redfish_cli.cli.create_logical_volume(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.err
|
||||
assert "JOB12345" in result
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
args.raid_level = "zz"
|
||||
redfish_cli.cli.create_logical_volume(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.err
|
||||
assert (
|
||||
"zz is not a valid raid level. Valid choices are 0,1,5,10,50"
|
||||
in result
|
||||
)
|
||||
|
||||
|
||||
def test_delete_logical_volume(capsys, monkeypatch):
|
||||
"""Test the create-logical-volume command"""
|
||||
# pylint: disable=fixme, unused-argument, unused-variable
|
||||
# TODO: Write actual tests when the create-logical-volume code is fixed
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"logical",
|
||||
"create",
|
||||
"-c",
|
||||
"controller",
|
||||
"-d",
|
||||
"disk",
|
||||
"-r",
|
||||
"0",
|
||||
]
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"delete",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}", headers={"Location": "/JOB12345"}
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(redfish_cli.api, "firmware_version", lambda args: 2)
|
||||
|
||||
redfish_cli.cli.delete_logical_volume(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert "JOB12345" in result
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
# pylint: disable=line-too-long
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"delete",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
ok=False, content='{"msg":"and error occurred"}'
|
||||
),
|
||||
)
|
||||
redfish_cli.cli.delete_logical_volume(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.err
|
||||
assert "JOB12345" in result
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
args.raid_level = "zz"
|
||||
redfish_cli.cli.create_logical_volume(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.err
|
||||
assert (
|
||||
"zz is not a valid raid level. Valid choices are 0,1,5,10,50"
|
||||
in result
|
||||
)
|
||||
|
||||
|
||||
def test_show_logical_volume(capsys, monkeypatch):
|
||||
"""Test the cli logical-volume command"""
|
||||
_json = get_test_json("cli_logical_volume.json")
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
content=json.dumps(_json), status_code=200
|
||||
),
|
||||
)
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"logical",
|
||||
"show",
|
||||
"-d",
|
||||
"Disk.Virtual.0:RAID.Slot.6-1",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
result = json.loads(capsys.readouterr().out)
|
||||
assert result["Id"] == "Disk.Virtual.0:RAID.Slot.6-1"
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"logical",
|
||||
"show",
|
||||
]
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
redfish_cli.api.storage,
|
||||
"list_storage_controllers",
|
||||
lambda *args, **kwargs: {
|
||||
"Members": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/System.Embedded.1/Storage/RAID.Slot.6-1"
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
redfish_cli.api.storage,
|
||||
"list_logical_volumes",
|
||||
lambda *args, **kwargs: {
|
||||
"Members": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/System.Embedded.1/"
|
||||
"Storage/Volumes/Disk.Virtual.0:RAID.Slot.6-1"
|
||||
},
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/System.Embedded.1"
|
||||
"/Storage/Volumes/Disk.Virtual.1:RAID.Slot.6-1"
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
result = json.loads(capsys.readouterr().out)
|
||||
assert result["Id"] == "Disk.Virtual.0:RAID.Slot.6-1"
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"logical",
|
||||
"show",
|
||||
"-c",
|
||||
"RAID.Slot.6-1",
|
||||
]
|
||||
)
|
||||
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
result = json.loads(capsys.readouterr().out)
|
||||
assert result["Id"] == "Disk.Virtual.0:RAID.Slot.6-1"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
ok=False, content='"Invalid logical volume"'
|
||||
),
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
except SystemExit:
|
||||
result = capsys.readouterr().err
|
||||
assert result == '"Invalid logical volume"\n'
|
||||
|
||||
|
||||
def test_list_logical_volumes(capsys, monkeypatch):
|
||||
"""Test the cli logical-volumes command"""
|
||||
_json = get_test_json("cli_logical_volumes.json")
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
content=json.dumps(_json), status_code=200
|
||||
),
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"logical",
|
||||
"list",
|
||||
"-c",
|
||||
"RAID.Slot.6-1",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
# err_out = capsys.readouterr().out
|
||||
result = json.loads(capsys.readouterr().out)
|
||||
assert result["Name"] == "Volume Collection"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda *args, **kwargs: MockResponse(ok=False, content='"Invalid"'),
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
except SystemExit:
|
||||
result = capsys.readouterr().err
|
||||
assert result == '"Invalid"\n'
|
||||
|
||||
|
||||
def test_show_phsyical_volume(capsys, monkeypatch, secrets):
|
||||
"""Test the physical_voume cli command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("physical_volume.json")
|
||||
return MockResponse(status_code=200, content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
monkeypatch.setattr(
|
||||
storage,
|
||||
"list_storage_controllers",
|
||||
lambda *args, **kwargs: {"Members": [{"@odata.id": ""}]},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
storage,
|
||||
"list_physical_volumes",
|
||||
lambda *args, **kwargs: [{"drive": "Dummy"}],
|
||||
)
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"physical",
|
||||
"show",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.physical_volume(args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert result["CapacityBytes"] == 299439751168
|
||||
|
||||
|
||||
def test_list_phsyical_volumes(capsys, monkeypatch, secrets):
|
||||
"""Test the physical_voume cli command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("physical_volumes.json")
|
||||
return MockResponse(status_code=200, content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
monkeypatch.setattr(
|
||||
storage,
|
||||
"list_storage_controllers",
|
||||
lambda *args, **kwargs: {"Members": [{"@odata.id": ""}]},
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"physical",
|
||||
"list",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.physical_volumes(args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert (
|
||||
result[0]["drive"] == "Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.6-1"
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"text",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"physical",
|
||||
"list",
|
||||
"-c",
|
||||
"Storage.Controller.1",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.physical_volumes(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert (
|
||||
"System.Embedded.1 Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.6-1\n"
|
||||
in result
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"table",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"physical",
|
||||
"list",
|
||||
"-c",
|
||||
"Storage.Controller.1",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.physical_volumes(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert result.startswith("+-------------------+-------------------------")
|
||||
assert "| Disk.Bay.0:Enclosure.Internal.0-1:RAID.Slot.6-1 |" in result
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-v",
|
||||
"-f",
|
||||
"table",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"physical",
|
||||
"list",
|
||||
"-c",
|
||||
"Storage.Controller.1",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.physical_volumes(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert result.startswith("+-------------------+-------------------------")
|
||||
assert "| System.Embedded.1 | Disk.Bay.0:Enclosure.Internal.0-" in result
|
||||
|
||||
|
||||
def test_storage_controller(capsys, monkeypatch, secrets):
|
||||
"""Test the storage-controller cli command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("storage_controller.json")
|
||||
return MockResponse(status_code=200, content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
monkeypatch.setattr(
|
||||
api.storage,
|
||||
"list_storage_controllers",
|
||||
lambda *args, **kwargs: {"Members": [{"@odata.id": "/"}]},
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"controllers",
|
||||
"show",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.storage_controller(args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert result["Id"] == "RAID.Slot.6-1"
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"text",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"controllers",
|
||||
"show",
|
||||
"-c",
|
||||
"RAID.Slot.6-1",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.storage_controller(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
# Currently returns JSON(ish) will need to update test later
|
||||
assert "'Id': 'RAID.Slot.6-1'" in result
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"table",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"controllers",
|
||||
"show",
|
||||
"-c",
|
||||
"RAID.Slot.6-1",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.storage_controller(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
# Currently returns JSON(ish) will need to update test later
|
||||
assert "'Id': 'RAID.Slot.6-1'" in result
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
ok=False, content='"Invalid storage controller"'
|
||||
),
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
except SystemExit:
|
||||
result = capsys.readouterr().err
|
||||
assert result == '"Invalid storage controller"\n'
|
||||
|
||||
|
||||
def test_list_storage_controllers(capsys, monkeypatch, secrets):
|
||||
"""Test the storage-controllers cli command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("cli_storage_controllers.json")
|
||||
return MockResponse(status_code=200, content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"json",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"controllers",
|
||||
"list",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.storage_controllers(args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert result == ["RAID.Slot.6-1"]
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"text",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"controllers",
|
||||
"list",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.storage_controllers(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert result == "RAID.Slot.6-1\n"
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"table",
|
||||
"storage",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"controllers",
|
||||
"list",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.storage_controllers(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert result == (
|
||||
"+---------------+\n| Controller |\n+===============+\n| "
|
||||
"RAID.Slot.6-1 |\n+---------------+\n"
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue