forked from ceph/ceph
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ceph#61392 from Hezko/nvmeof-gw-info-cli
Dashboard: Introduce nvmeof cli commands
- Loading branch information
Showing
5 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import errno | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from mgr_module import CLICommand, HandleCommandResult | ||
|
||
from ..services.nvmeof_cli import NvmeofCLICommand | ||
|
||
|
||
@pytest.fixture(scope="class", name="sample_command") | ||
def fixture_sample_command(): | ||
test_cmd = "test command" | ||
|
||
@NvmeofCLICommand(test_cmd) | ||
def func(_): # noqa # pylint: disable=unused-variable | ||
return {'a': '1', 'b': 2} | ||
yield test_cmd | ||
del NvmeofCLICommand.COMMANDS[test_cmd] | ||
assert test_cmd not in NvmeofCLICommand.COMMANDS | ||
|
||
|
||
@pytest.fixture(name='base_call_mock') | ||
def fixture_base_call_mock(monkeypatch): | ||
mock_result = {'a': 'b'} | ||
super_mock = MagicMock() | ||
super_mock.return_value = mock_result | ||
monkeypatch.setattr(CLICommand, 'call', super_mock) | ||
return super_mock | ||
|
||
|
||
@pytest.fixture(name='base_call_return_none_mock') | ||
def fixture_base_call_return_none_mock(monkeypatch): | ||
mock_result = None | ||
super_mock = MagicMock() | ||
super_mock.return_value = mock_result | ||
monkeypatch.setattr(CLICommand, 'call', super_mock) | ||
return super_mock | ||
|
||
|
||
class TestNvmeofCLICommand: | ||
def test_command_being_added(self, sample_command): | ||
assert sample_command in NvmeofCLICommand.COMMANDS | ||
assert isinstance(NvmeofCLICommand.COMMANDS[sample_command], NvmeofCLICommand) | ||
|
||
def test_command_return_cmd_result_default_format(self, base_call_mock, sample_command): | ||
result = NvmeofCLICommand.COMMANDS[sample_command].call(MagicMock(), {}) | ||
assert isinstance(result, HandleCommandResult) | ||
assert result.retval == 0 | ||
assert result.stdout == '{"a": "b"}' | ||
assert result.stderr == '' | ||
base_call_mock.assert_called_once() | ||
|
||
def test_command_return_cmd_result_json_format(self, base_call_mock, sample_command): | ||
result = NvmeofCLICommand.COMMANDS[sample_command].call(MagicMock(), {'format': 'json'}) | ||
assert isinstance(result, HandleCommandResult) | ||
assert result.retval == 0 | ||
assert result.stdout == '{"a": "b"}' | ||
assert result.stderr == '' | ||
base_call_mock.assert_called_once() | ||
|
||
def test_command_return_cmd_result_yaml_format(self, base_call_mock, sample_command): | ||
result = NvmeofCLICommand.COMMANDS[sample_command].call(MagicMock(), {'format': 'yaml'}) | ||
assert isinstance(result, HandleCommandResult) | ||
assert result.retval == 0 | ||
assert result.stdout == 'a: b\n' | ||
assert result.stderr == '' | ||
base_call_mock.assert_called_once() | ||
|
||
def test_command_return_cmd_result_invalid_format(self, base_call_mock, sample_command): | ||
mock_result = {'a': 'b'} | ||
super_mock = MagicMock() | ||
super_mock.call.return_value = mock_result | ||
|
||
result = NvmeofCLICommand.COMMANDS[sample_command].call(MagicMock(), {'format': 'invalid'}) | ||
assert isinstance(result, HandleCommandResult) | ||
assert result.retval == -errno.EINVAL | ||
assert result.stdout == '' | ||
assert result.stderr | ||
base_call_mock.assert_called_once() | ||
|
||
def test_command_return_empty_cmd_result(self, base_call_return_none_mock, sample_command): | ||
result = NvmeofCLICommand.COMMANDS[sample_command].call(MagicMock(), {}) | ||
assert isinstance(result, HandleCommandResult) | ||
assert result.retval == 0 | ||
assert result.stdout == '' | ||
assert result.stderr == '' | ||
base_call_return_none_mock.assert_called_once() |