Initial commit
This commit is contained in:
commit
1b51716d1b
72 changed files with 8204 additions and 0 deletions
0
tests/cli/__init__.py
Normal file
0
tests/cli/__init__.py
Normal file
79
tests/cli/test_chassis.py
Normal file
79
tests/cli/test_chassis.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
"""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 ..utils import get_test_json, MockResponse, MockRedfishResponse
|
||||
|
||||
from .test_cli import secrets
|
||||
|
||||
|
||||
def test_chassis(capsys, monkeypatch, secrets):
|
||||
"""Test the cli chassis command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("cli_chassis.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",
|
||||
"chassis",
|
||||
"-p",
|
||||
secrets["password"],
|
||||
"-u",
|
||||
secrets["username"],
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.chassis(args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert result["@odata.id"] == "/redfish/v1/Chassis/System.Embedded.1"
|
||||
|
||||
|
||||
def test_get_chassis_details(capsys, monkeypatch):
|
||||
"""Test the cli chassis-details command"""
|
||||
_json = get_test_json("cli_chassis_details.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",
|
||||
"chassis",
|
||||
"--username",
|
||||
"root",
|
||||
"-p",
|
||||
"password",
|
||||
"show",
|
||||
"-c",
|
||||
"System.Embedded.1",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
# captured = capsys.readouterr()
|
||||
result = json.loads(capsys.readouterr().out)
|
||||
assert result["Name"] == "Computer System Chassis"
|
||||
307
tests/cli/test_cli.py
Normal file
307
tests/cli/test_cli.py
Normal file
|
|
@ -0,0 +1,307 @@
|
|||
"""Test for the cli componenets"""
|
||||
import argparse
|
||||
import json
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import redfish_cli.cli
|
||||
import redfish_cli.api
|
||||
from redfish_cli.cli.parsers.utils import EnvDefault
|
||||
|
||||
from ..utils import get_test_json, MockResponse, MockRedfishResponse
|
||||
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
|
||||
################################################################################
|
||||
### Look at moving this into a shared file so we don't also define it in api
|
||||
@pytest.fixture
|
||||
def secrets():
|
||||
"""
|
||||
Secrets for use as a pytest fiixture. There aren't actually any secrets
|
||||
here because everything is mocked now, but we still need some defaults when
|
||||
testing the cli.
|
||||
"""
|
||||
with open(
|
||||
os.path.join(os.path.dirname(__file__), "../test_secrets.json"),
|
||||
encoding="utf-8",
|
||||
) as secrets_file:
|
||||
secrets = json.loads(" ".join(secrets_file.readlines()))
|
||||
return secrets
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
|
||||
def test_base_command(capsys, monkeypatch, secrets):
|
||||
"""Test the base cli command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("cli_base_command.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",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert result["Name"] == "Root Service"
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
["-s", secrets["server"], "-f", "json", "version"]
|
||||
)
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert result == "1.4.0"
|
||||
|
||||
|
||||
def test_get(capsys, monkeypatch, secrets):
|
||||
"""Test the cli get command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("cli_get.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",
|
||||
"--debug",
|
||||
"get",
|
||||
"-p",
|
||||
"password",
|
||||
"-u",
|
||||
"username",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert result["Name"] == "Root Service"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests, "get", lambda *args, **kwargs: MockResponse(status_code=401)
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"json",
|
||||
"get",
|
||||
"-p",
|
||||
"password",
|
||||
"-u",
|
||||
"username",
|
||||
"--expand",
|
||||
]
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
except SystemExit:
|
||||
captured = capsys.readouterr()
|
||||
result = captured.err
|
||||
assert result == "This url requires authentication\n\n"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
ok=False, content='"Invalid url"'
|
||||
),
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
except SystemExit:
|
||||
result = capsys.readouterr().err
|
||||
assert result == '"Invalid url"\n'
|
||||
|
||||
|
||||
def test_error():
|
||||
"""Test the cli error function"""
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
redfish_cli.cli.utils.error("This is an error")
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
redfish_cli.cli.utils.error("This is an error", output_format="json")
|
||||
|
||||
|
||||
def test_parser():
|
||||
"""Test the cli parse_args function"""
|
||||
args = redfish_cli.cli.parse_args(["-s", "xxxx", "version"])
|
||||
assert args.server == "xxxx"
|
||||
assert args.format == "json"
|
||||
assert args.func.__name__ == "version"
|
||||
|
||||
|
||||
def test_add_subparser():
|
||||
"""Test a subparser with no args"""
|
||||
parser = argparse.ArgumentParser(description="Test parser")
|
||||
|
||||
subparsers = parser.add_subparsers()
|
||||
redfish_cli.cli.parsers.utils.add_subparser(
|
||||
subparsers, "Dummy", arguments=None
|
||||
)
|
||||
|
||||
|
||||
def test_product(capsys, monkeypatch):
|
||||
"""Test the product cli command"""
|
||||
_json = {"Product": "Integrated Dell Remote Access Controller"}
|
||||
|
||||
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",
|
||||
"product",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.redfish(args=args)
|
||||
result = json.loads(capsys.readouterr().out)
|
||||
assert result == "Integrated Dell Remote Access Controller"
|
||||
|
||||
|
||||
def test_redfish():
|
||||
"""Test the base redfish command"""
|
||||
with pytest.raises(SystemExit):
|
||||
redfish_cli.cli.redfish()
|
||||
|
||||
|
||||
def test_service_tag(capsys, monkeypatch, secrets):
|
||||
"""Test the service-tag cli command"""
|
||||
_json = get_test_json("cli_service_tag.json")
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = _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"],
|
||||
"service-tag",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.service_tag(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert result == '"JYYZY42"\n'
|
||||
|
||||
_json["Oem"]["NotDell"] = _json["Oem"]["Dell"]
|
||||
del _json["Oem"]["Dell"]
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
content=json.dumps(_json), status_code=200
|
||||
),
|
||||
)
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"service-tag",
|
||||
]
|
||||
)
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
redfish_cli.cli.service_tag(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.err
|
||||
|
||||
assert result == "Service tags are only available for Dell iDRACs\n"
|
||||
|
||||
|
||||
def test_version(capsys, monkeypatch, secrets):
|
||||
"""Test the version command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("cli_version.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"],
|
||||
"version",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.version(args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert result == '"1.4.0"\n'
|
||||
|
||||
|
||||
def test_write():
|
||||
"""Test the cli write function"""
|
||||
redfish_cli.cli.utils.write_output("This is not an error")
|
||||
|
||||
redfish_cli.cli.utils.write_output(
|
||||
"This is not an error", output_format="json"
|
||||
)
|
||||
|
||||
|
||||
def test_env_var():
|
||||
"""Test the envvar action parser action"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Interact with servers via RedFish. Only Dells supported at the moment"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--server",
|
||||
required=True,
|
||||
dest="server",
|
||||
action=EnvDefault,
|
||||
default=os.environ.get("RF_USERNAME"),
|
||||
envvar="USER",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-u",
|
||||
"--user",
|
||||
required=True,
|
||||
dest="server",
|
||||
help="Help",
|
||||
action=EnvDefault,
|
||||
envvar="USER",
|
||||
)
|
||||
204
tests/cli/test_jobs.py
Normal file
204
tests/cli/test_jobs.py
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
"""Test for the cli componenets"""
|
||||
# pylint: disable=redefined-outer-name, no-name-in-module, unused-import
|
||||
|
||||
import json
|
||||
from unittest import mock
|
||||
|
||||
import requests
|
||||
|
||||
from redfish_cli.cli import parse_args
|
||||
from redfish_cli.cli.jobs import jobs_list, job_details, watch_job
|
||||
|
||||
from ..utils import get_test_content, MockResponse, MockWatchedJobResponse
|
||||
|
||||
|
||||
def test_list_jobs(capsys, monkeypatch):
|
||||
"""Test the list jobs command"""
|
||||
# pylint: disable=fixme, unused-argument, unused-variable
|
||||
|
||||
args = parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"jobs",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"list",
|
||||
"--all",
|
||||
]
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content=get_test_content("jobs_list.json")
|
||||
),
|
||||
)
|
||||
|
||||
jobs_list(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert 5 == json.loads(result)["Members@odata.count"]
|
||||
|
||||
args = parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"jobs",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"list",
|
||||
]
|
||||
)
|
||||
jobs_list(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert 0 == json.loads(result)["Members@odata.count"]
|
||||
|
||||
args = parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"text",
|
||||
"jobs",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"list",
|
||||
"--all",
|
||||
]
|
||||
)
|
||||
jobs_list(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert (
|
||||
"JID_878659984891 RAIDConfiguration 100 Config:RAID:RAID.Slot.6-1 Completed\n"
|
||||
"JID_878682850779 RAIDConfiguration 100 Config:RAID:RAID.Slot.6-1 Completed\n"
|
||||
"JID_920326518992 RAIDConfiguration 100 Config:RAID:RAID.Slot.6-1 Completed\n"
|
||||
"JID_923469653542 RAIDConfiguration 100 Config:RAID:RAID.Slot.6-1 Completed\n"
|
||||
"JID_924369311959 RAIDConfiguration 100 Config:RAID:RAID.Slot.6-1 Completed\n"
|
||||
) == result
|
||||
|
||||
args = parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"table",
|
||||
"jobs",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"list",
|
||||
"--all",
|
||||
]
|
||||
)
|
||||
jobs_list(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
expected = get_test_content("job_list_table.txt")
|
||||
assert expected == result
|
||||
|
||||
|
||||
def test_job_details(capsys, monkeypatch):
|
||||
"""Test the list jobs command"""
|
||||
# pylint: disable=fixme, unused-argument, unused-variable
|
||||
|
||||
args = parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"jobs",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"show",
|
||||
"-j",
|
||||
"JID_924369311959",
|
||||
]
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content=get_test_content("api_job_details.json")
|
||||
),
|
||||
)
|
||||
|
||||
job_details(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert "2023-08-20T05:59:24" == json.loads(result)["CompletionTime"]
|
||||
|
||||
|
||||
def test_watch_jobs(capsys, monkeypatch):
|
||||
"""Test the list jobs command"""
|
||||
# pylint: disable=fixme, unused-argument, unused-variable
|
||||
|
||||
response = MockWatchedJobResponse()
|
||||
args = parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"jobs",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"show",
|
||||
"-j",
|
||||
"JID_924369311959",
|
||||
]
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: response,
|
||||
)
|
||||
|
||||
watch_job(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert '"PercentComplete": 100,' in result
|
||||
|
||||
response.accessed = 0
|
||||
args = parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"text",
|
||||
"jobs",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"show",
|
||||
"-j",
|
||||
"JID_924369311959",
|
||||
]
|
||||
)
|
||||
watch_job(args=args)
|
||||
captured = capsys.readouterr()
|
||||
result = captured.out
|
||||
assert "Completed 100\n" in result
|
||||
|
||||
# Test that watch jobs catches a KeyboardInterrup and exits cleanly
|
||||
with mock.patch("requests.get", side_effect=KeyboardInterrupt):
|
||||
watch_job(args=args)
|
||||
255
tests/cli/test_power.py
Normal file
255
tests/cli/test_power.py
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
"""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
|
||||
import redfish_cli.cli.power
|
||||
from redfish_cli import api
|
||||
|
||||
from ..utils import get_test_json, MockResponse, MockRedfishResponse
|
||||
|
||||
|
||||
def test_set_power_state(capsys, monkeypatch):
|
||||
"""Test the set-power-state cli command"""
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda *args, **kwargs: MockResponse(content="{}", status_code=200),
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"power",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"set",
|
||||
"On",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.power.set_power_state(args=args)
|
||||
out = capsys.readouterr().out
|
||||
result = out
|
||||
assert result == '"Powerstate set to On"\n'
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests, "post", lambda *args, **kwargs: MockResponse(ok=False)
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.power.set_power_state(args)
|
||||
except SystemExit:
|
||||
result = capsys.readouterr().err
|
||||
assert result == "Failed to set powerstate to On\n"
|
||||
|
||||
|
||||
def test_power_state(capsys, monkeypatch):
|
||||
"""Test the get power state cli command"""
|
||||
_json = {"PowerState": "Off"}
|
||||
|
||||
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",
|
||||
"power",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"get",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.power.power_state(args=args)
|
||||
out = capsys.readouterr().out
|
||||
result = json.loads(out)
|
||||
assert result == "Off"
|
||||
|
||||
|
||||
def test_list_power_states(capsys, monkeypatch):
|
||||
"""Test the product cli command"""
|
||||
# pylint: disable=duplicate-code
|
||||
|
||||
# This code is similar to the direct api test. Disable the pylint warning.
|
||||
|
||||
_json = get_test_json("power_states_allowed.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",
|
||||
"power",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"list",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.power.power_states(args)
|
||||
result = json.loads(capsys.readouterr().out)
|
||||
assert result == [
|
||||
"On",
|
||||
"ForceOff",
|
||||
"ForceRestart",
|
||||
"GracefulShutdown",
|
||||
"PushPowerButton",
|
||||
"Nmi",
|
||||
]
|
||||
|
||||
|
||||
def test_system_reset(capsys, monkeypatch):
|
||||
"""Test resetting a system"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}"
|
||||
),
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"power",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"reset",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.power.reset_system(args=args)
|
||||
out = capsys.readouterr().out
|
||||
result = json.loads(out)
|
||||
assert result == "System reset"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
ok=False, content="Failed to set power state"
|
||||
),
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.power.reset_system(args)
|
||||
except SystemExit:
|
||||
result = capsys.readouterr().err
|
||||
assert result == "Failed to set power state\n"
|
||||
|
||||
|
||||
def test_power_on(capsys, monkeypatch):
|
||||
"""Test resetting a system"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}"
|
||||
),
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"power",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"on",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.power.power_on(args=args)
|
||||
out = capsys.readouterr().out
|
||||
result = json.loads(out)
|
||||
assert result == "System.Embedded.1 powered on"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
ok=False, content="Failed to power on"
|
||||
),
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.power.power_on(args)
|
||||
except SystemExit:
|
||||
result = capsys.readouterr().err
|
||||
assert result == "Failed to power on\n"
|
||||
|
||||
|
||||
def test_power_off(capsys, monkeypatch):
|
||||
"""Test resetting a system"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}"
|
||||
),
|
||||
)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
"172.1.0.1",
|
||||
"-f",
|
||||
"json",
|
||||
"power",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"password123",
|
||||
"off",
|
||||
]
|
||||
)
|
||||
redfish_cli.cli.power.power_off(args=args)
|
||||
out = capsys.readouterr().out
|
||||
result = json.loads(out)
|
||||
assert result == "System.Embedded.1 powered off"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda *args, **kwargs: MockResponse(
|
||||
ok=False, content="Failed to power off"
|
||||
),
|
||||
)
|
||||
try:
|
||||
redfish_cli.cli.power.power_off(args)
|
||||
except SystemExit:
|
||||
result = capsys.readouterr().err
|
||||
assert result == "Failed to power off\n"
|
||||
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"
|
||||
)
|
||||
43
tests/cli/test_system.py
Normal file
43
tests/cli/test_system.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"""Test for the system cli components"""
|
||||
# pylint: disable=redefined-outer-name, no-name-in-module, unused-import
|
||||
|
||||
import json
|
||||
import requests
|
||||
|
||||
import redfish_cli.cli
|
||||
|
||||
from ..utils import get_test_json, MockResponse, MockRedfishResponse
|
||||
|
||||
from .test_cli import secrets
|
||||
|
||||
|
||||
def test_system_details(capsys, monkeypatch, secrets):
|
||||
"""Test system-details command"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("system_details.json")
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
args = redfish_cli.cli.parse_args(
|
||||
[
|
||||
"-s",
|
||||
secrets["server"],
|
||||
"-f",
|
||||
"json",
|
||||
"system",
|
||||
"-u",
|
||||
"root",
|
||||
"-p",
|
||||
"dummy",
|
||||
"show",
|
||||
]
|
||||
)
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
redfish_cli.cli.system_details(args)
|
||||
captured = capsys.readouterr()
|
||||
result = json.loads(captured.out)
|
||||
assert result["@odata.id"] == "/redfish/v1/Systems/System.Embedded.1"
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
Loading…
Add table
Add a link
Reference in a new issue