iLO-manager first main commitgit status
This commit is contained in:
1 parent
e6f4cc04ca
commit
599d8da562
3271 files changed
+550655
No files matched your search
Whitespace-only changes.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
conftest.py is used to set up shared fixtures, plugins, hooks, other config etc.
|
||||
This is the unit test conftest.py
|
||||
http://docs.pytest.org/en/latest/writing_plugins.html#conftest-py-local-per-directory-plugins
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
|
||||
from ..conftest import (
|
||||
ClearPendingConfigCommand,
|
||||
DisplayHelpers,
|
||||
MapperRenderers,
|
||||
RestHelpers,
|
||||
ShowPmemCommand,
|
||||
)
|
||||
@@ -0,0 +1,511 @@
|
||||
"""Module to Test the 'applydcpmmconfig' command"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
|
||||
from rdmc_base_classes import RdmcCommandBase
|
||||
from rdmc_helper import (
|
||||
InvalidCommandLineError,
|
||||
NoChangesFoundOrMadeError,
|
||||
NoContentsFoundForOperationError,
|
||||
)
|
||||
|
||||
from ..conftest import ApplyPmemConfigCommand, RestHelpers
|
||||
|
||||
|
||||
class MockData(object):
|
||||
"""
|
||||
Mock Data for 'applydcpmmconfig' command
|
||||
"""
|
||||
mock_tasks = [{
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 1",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm12/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/"
|
||||
"MemoryChunks/?$expand=."
|
||||
},
|
||||
"TaskState": "New"
|
||||
}, {
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 2",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm10/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/"
|
||||
"MemoryChunks/?$expand=."
|
||||
},
|
||||
"TaskState": "Old"
|
||||
}]
|
||||
|
||||
other_mock_tasks = [{
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 1",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm12/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/?$expand=."
|
||||
},
|
||||
"TaskState": "New"
|
||||
}, {
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 2",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm10/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/?$expand=."
|
||||
},
|
||||
"TaskState": "Old"
|
||||
}]
|
||||
|
||||
mock_chunks = [
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#MemoryChunks.MemoryChunks",
|
||||
"@odata.etag": "W/\"89E7F7C3\"",
|
||||
"@odata.id": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/MemoryChunks/2/",
|
||||
"@odata.type": "#MemoryChunks.v1_2_2.MemoryChunks",
|
||||
"Id": "2",
|
||||
"AddressRangeType": "PMEM",
|
||||
"Description": "Memory Chunk",
|
||||
"InterleaveSets": [
|
||||
{
|
||||
"Memory": {
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc1dimm7/"
|
||||
},
|
||||
"RegionId": "3",
|
||||
"SizeMiB": 131072
|
||||
}
|
||||
],
|
||||
"IsMirrorEnabled": False,
|
||||
"IsSpare": False,
|
||||
"MemoryChunkSizeMiB": 131072,
|
||||
"Name": "MemoryChunk",
|
||||
"Oem": {
|
||||
"Hpe": {
|
||||
"@odata.context": "/redfish/v1/$metadata#HpeMemoryChunksExt.HpeMemoryChunksExt",
|
||||
"@odata.type": "#HpeMemoryChunksExt.v2_1_0.HpeMemoryChunksExt",
|
||||
"MemoryChunkSizePercentage": 50
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#MemoryChunks.MemoryChunks",
|
||||
"@odata.etag": "W/\"89E7F7C3\"",
|
||||
"@odata.id": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/MemoryChunks/1/",
|
||||
"@odata.type": "#MemoryChunks.v1_2_2.MemoryChunks",
|
||||
"Id": "1",
|
||||
"AddressRangeType": "PMEM",
|
||||
"Description": "Memory Chunk",
|
||||
"InterleaveSets": [
|
||||
{
|
||||
"Memory": {
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc1dimm6/"
|
||||
},
|
||||
"RegionId": "1",
|
||||
"SizeMiB": 131072
|
||||
}
|
||||
],
|
||||
"IsMirrorEnabled": False,
|
||||
"IsSpare": False,
|
||||
"MemoryChunkSizeMiB": 131072,
|
||||
"Name": "MemoryChunk",
|
||||
"Oem": {
|
||||
"Hpe": {
|
||||
"@odata.context": "/redfish/v1/$metadata#HpeMemoryChunksExt.HpeMemoryChunksExt",
|
||||
"@odata.type": "#HpeMemoryChunksExt.v2_1_0.HpeMemoryChunksExt",
|
||||
"MemoryChunkSizePercentage": 50
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
mock_interleavable_set = [
|
||||
{
|
||||
"MemorySet": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc2dimm6/"
|
||||
},
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc2dimm7/"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"MemorySet": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc2dimm6/"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"MemorySet": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc2dimm7/"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
expect_post_bodies_app_direct_interleaved = [
|
||||
{
|
||||
'AddressRangeType': 'PMEM',
|
||||
'Oem': {
|
||||
'Hpe': {
|
||||
'MemoryChunkSizePercentage': 100
|
||||
}
|
||||
},
|
||||
'InterleaveSets': [
|
||||
{
|
||||
'Memory': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'
|
||||
}
|
||||
},
|
||||
{
|
||||
'Memory': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
expected_post_bodies_app_direct_not_interleaved = [
|
||||
{
|
||||
'AddressRangeType': 'PMEM',
|
||||
'Oem': {
|
||||
'Hpe': {
|
||||
'MemoryChunkSizePercentage': 100
|
||||
}
|
||||
},
|
||||
'InterleaveSets': [
|
||||
{
|
||||
'Memory': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'AddressRangeType': 'PMEM',
|
||||
'Oem': {
|
||||
'Hpe': {
|
||||
'MemoryChunkSizePercentage': 100
|
||||
}
|
||||
},
|
||||
'InterleaveSets': [
|
||||
{
|
||||
'Memory': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
expected_post_bodies_memory_mode = [
|
||||
{
|
||||
'AddressRangeType': 'PMEM',
|
||||
'Oem': {
|
||||
'Hpe': {
|
||||
'MemoryChunkSizePercentage': 0
|
||||
}
|
||||
},
|
||||
'InterleaveSets': [
|
||||
{
|
||||
'Memory': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'
|
||||
}
|
||||
},
|
||||
{
|
||||
'Memory': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
def retrieve_memory_domains(self):
|
||||
"""
|
||||
Function to retrive memory domains
|
||||
"""
|
||||
memory_domains = [{
|
||||
'Name': 'PROC1 Memory Domain',
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain',
|
||||
'@odata.context': '/redfish/v1/$metadata#MemoryDomain.MemoryDomain',
|
||||
'Id': 'PROC1MemoryDomain',
|
||||
"InterleavableMemorySets":[{
|
||||
"MemorySet":[
|
||||
{
|
||||
"@odata.id":"/redfish/v1/Systems/1/Memory/proc2dimm6/"
|
||||
},
|
||||
{
|
||||
"@odata.id":"/redfish/v1/Systems/1/Memory/proc2dimm7/"
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"MemorySet":[
|
||||
{
|
||||
"@odata.id":"/redfish/v1/Systems/1/Memory/proc2dimm6/"
|
||||
}
|
||||
]
|
||||
}, {
|
||||
"MemorySet":[
|
||||
{
|
||||
"@odata.id":"/redfish/v1/Systems/1/Memory/proc2dimm7/"
|
||||
}
|
||||
]
|
||||
}],
|
||||
"MemoryChunks":{
|
||||
"@odata.id":"/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/MemoryChunks"}
|
||||
}]
|
||||
return [], memory_domains, []
|
||||
|
||||
class TestApplyPmemConfigCommand(object):
|
||||
"""
|
||||
Class for unit tests of 'applydcpmmconfig' command
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('customparser, expected_result', [
|
||||
('', None)
|
||||
])
|
||||
def test_define_arguments(customparser, expected_result):
|
||||
"""
|
||||
Branch Test for 'define_arguments()' when parser is not customparser
|
||||
"""
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(
|
||||
RdmcCommandBase)
|
||||
result = pmem_command.define_arguments(customparser)
|
||||
assert result == expected_result
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('memory_chunk_tasks, memory_chunks', [
|
||||
([MockData.mock_tasks[0]], list()),
|
||||
(list(), MockData.mock_chunks),
|
||||
([MockData.mock_tasks[1]], MockData.mock_chunks),
|
||||
([MockData.other_mock_tasks[0]], MockData.mock_chunks)
|
||||
])
|
||||
def test_warn_existing_chunks_and_tasks_fail(memory_chunk_tasks, memory_chunks):
|
||||
"""
|
||||
Tests for 'delete_existing_chunks_and_tasks' with invalid data
|
||||
"""
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
with pytest.raises(NoChangesFoundOrMadeError):
|
||||
pmem_command.warn_existing_chunks_and_tasks(memory_chunk_tasks, memory_chunks)
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('memory_chunk_tasks, memory_chunks, expected_result', [
|
||||
(list(), list(), None),
|
||||
(None, list(), None)
|
||||
])
|
||||
def test_warn_existing_chunks_and_tasks_pass(memory_chunk_tasks,
|
||||
memory_chunks, expected_result):
|
||||
"""
|
||||
Tests for 'delete_existing_chunks_and_tasks' with valid data
|
||||
"""
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
result = pmem_command.warn_existing_chunks_and_tasks(memory_chunk_tasks, memory_chunks)
|
||||
assert result == expected_result
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('memory_chunk_tasks, memory_chunks, response, expected_result', [
|
||||
([MockData.mock_tasks[0]], list(), 200, None),
|
||||
([MockData.mock_tasks[0]], MockData.mock_chunks, 202, None),
|
||||
(None, None, None, None),
|
||||
(list(), list(), None, None)
|
||||
])
|
||||
def test_delete_existing_chunks_and_tasks_pass(memory_chunk_tasks, memory_chunks,
|
||||
response, expected_result, monkeypatch):
|
||||
"""
|
||||
Tests for 'delete_existing_chunks_and_tasks' with valid data
|
||||
"""
|
||||
def get_response(*argv):
|
||||
"""
|
||||
Returns response codes
|
||||
"""
|
||||
#pylint: disable=unused-argument
|
||||
return response
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "delete_resource", get_response)
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
result = pmem_command.delete_existing_chunks_and_tasks(memory_chunk_tasks, memory_chunks)
|
||||
assert result == expected_result
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('memory_chunk_tasks, memory_chunks', [
|
||||
([MockData.mock_tasks[0]], MockData.mock_chunks),
|
||||
(None, MockData.mock_chunks),
|
||||
])
|
||||
def test_delete_existing_chunks_and_tasks_fail(memory_chunk_tasks, memory_chunks, monkeypatch):
|
||||
"""
|
||||
Tests for 'delete_existing_chunks_and_tasks' with invalid data
|
||||
"""
|
||||
def get_response(*argv):
|
||||
"""
|
||||
Returns none
|
||||
"""
|
||||
#pylint: disable=unused-argument
|
||||
return None
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "delete_resource", get_response)
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
with pytest.raises(NoChangesFoundOrMadeError):
|
||||
pmem_command.delete_existing_chunks_and_tasks(memory_chunk_tasks, memory_chunks)
|
||||
|
||||
|
||||
class MockOptions(object):
|
||||
"""
|
||||
Class containing mock options for validation tests
|
||||
"""
|
||||
list = False
|
||||
config = ""
|
||||
force = False
|
||||
|
||||
@staticmethod
|
||||
def set_options(list, config, force):
|
||||
"""
|
||||
Setter function for options
|
||||
"""
|
||||
MockOptions.list = list
|
||||
MockOptions.config = config
|
||||
MockOptions.force = force
|
||||
|
||||
|
||||
class TestValidation(object):
|
||||
"""
|
||||
Class containing test for validation based on mock options
|
||||
"""
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("list, config, force, expected_result", [
|
||||
(True, False, False, None),
|
||||
(False, "memorymode", False, None),
|
||||
(False, "appdirectnotinterleaved", True, None),
|
||||
(False, "appdirectinterleaved", True, None),
|
||||
(False, "AppdirecTinterLeaveD", False, None),
|
||||
(False, "APPDIRECTNOTINTERLEAVED", False, None),
|
||||
])
|
||||
def test_validate_options_pass(list, config, force, expected_result):
|
||||
"""
|
||||
Tests for 'validate_options' with valid options
|
||||
"""
|
||||
MockOptions.set_options(list, config, force)
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
result = pmem_command.validate_options(MockOptions)
|
||||
assert result == expected_result
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("list_flag, config, force", [
|
||||
(False, "", False),
|
||||
(True, "AppDirectInterleaved", False),
|
||||
(False, "qwerty", True),
|
||||
(True, "MemoryMode", True),
|
||||
(False, None, True),
|
||||
(True, None, True)
|
||||
])
|
||||
def test_validate_options_fail(list_flag, config, force):
|
||||
"""
|
||||
Tests for 'validate_options' with invalid options
|
||||
"""
|
||||
MockOptions.set_options(list_flag, config, force)
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
with pytest.raises(InvalidCommandLineError):
|
||||
pmem_command.validate_options(MockOptions)
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("list_flag, config, force", [
|
||||
(False, "False", False),
|
||||
(False, None, True),
|
||||
(True, "args", True)
|
||||
])
|
||||
def test_validate_args(list_flag, config, force):
|
||||
"""
|
||||
Tests for 'validate_args'
|
||||
"""
|
||||
MockOptions.set_options(list_flag, config, force)
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
with pytest.raises(InvalidCommandLineError):
|
||||
pmem_command.validate_args(MockOptions)
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('mock_config_data, mock_interleavable_set, expected_result', [
|
||||
(ApplyPmemConfigCommand.ApplyPmemConfigCommand.config_ids[0],
|
||||
MockData.mock_interleavable_set,
|
||||
MockData.expected_post_bodies_memory_mode),
|
||||
(ApplyPmemConfigCommand.ApplyPmemConfigCommand.config_ids[1],
|
||||
MockData.mock_interleavable_set,
|
||||
MockData.expect_post_bodies_app_direct_interleaved),
|
||||
(ApplyPmemConfigCommand.ApplyPmemConfigCommand.config_ids[2],
|
||||
MockData.mock_interleavable_set,
|
||||
MockData.expected_post_bodies_app_direct_not_interleaved)
|
||||
])
|
||||
|
||||
def test_get_post_data(mock_config_data, mock_interleavable_set, expected_result):
|
||||
"""
|
||||
Test for get_post_data with MemoryMode, AppDirectInterleaved and AppDirectNotInterleaved
|
||||
"""
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(
|
||||
RdmcCommandBase)
|
||||
result = pmem_command.get_post_data(mock_config_data, mock_interleavable_set)
|
||||
assert result == expected_result
|
||||
|
||||
@staticmethod
|
||||
def test_apply_predefined_err(monkeypatch):
|
||||
"""
|
||||
Test for apply_predefined_config with empty memory domains list
|
||||
"""
|
||||
def retrive_empty_mem_domains(*argv):
|
||||
"""
|
||||
returns empty list
|
||||
"""
|
||||
#pylint: disable=unused-argument
|
||||
return [], [], []
|
||||
|
||||
MockOptions.set_options(False, "memorymode", True)
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "retrieve_task_members_and_mem_domains",
|
||||
retrive_empty_mem_domains)
|
||||
with pytest.raises(NoContentsFoundForOperationError):
|
||||
pmem_command.apply_predefined_config(MockOptions)
|
||||
|
||||
def test_apply_predefined_err3(self, monkeypatch):
|
||||
"""
|
||||
Test for apply_predefined_config with invalid post request
|
||||
"""
|
||||
def get_failure_resp(*argv):
|
||||
"""
|
||||
returns None
|
||||
"""
|
||||
#pylint: disable=unused-argument
|
||||
return None
|
||||
MockOptions.set_options(False, "appdirectinterleaved", True)
|
||||
pmem_command = ApplyPmemConfigCommand.ApplyPmemConfigCommand(RdmcCommandBase)
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "retrieve_task_members_and_mem_domains",
|
||||
MockData().retrieve_memory_domains)
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "post_resource", get_failure_resp)
|
||||
with pytest.raises(NoChangesFoundOrMadeError):
|
||||
pmem_command.apply_predefined_config(MockOptions)
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
"""Module to Test the 'cleardcpmmpendingconfig' command"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
|
||||
from rdmc_base_classes import RdmcCommandBase
|
||||
from rdmc_helper import NoChangesFoundOrMadeError, NoContentsFoundForOperationError
|
||||
|
||||
from .conftest import ClearPendingConfigCommand, RestHelpers
|
||||
|
||||
|
||||
class MockData(object):
|
||||
"""
|
||||
Mock Data for 'cleardcpmmpendingconfig' command
|
||||
"""
|
||||
task = None
|
||||
resp = None
|
||||
|
||||
mock_tasks_1 = [{
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 1",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm12/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/"
|
||||
"MemoryChunks/?$expand=."
|
||||
},
|
||||
"TaskState": "New"
|
||||
}, {
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 2",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm10/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/"
|
||||
"MemoryChunks/?$expand=."
|
||||
},
|
||||
"TaskState": "Old"
|
||||
}]
|
||||
|
||||
mock_tasks_2 = [{
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 1",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm12/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/"
|
||||
"MemoryChunks/?$expand=."
|
||||
},
|
||||
"TaskState": "New"
|
||||
}]
|
||||
|
||||
mock_tasks_3 = [{
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 1",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm12/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/?$expand=."
|
||||
},
|
||||
"TaskState": "New"
|
||||
}, {
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 2",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm10/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/?$expand=."
|
||||
},
|
||||
"TaskState": "Old"
|
||||
}]
|
||||
|
||||
@staticmethod
|
||||
def get_resource_tasks(*argv):
|
||||
"""
|
||||
Returns mock tasks
|
||||
"""
|
||||
return MockData.task
|
||||
|
||||
@staticmethod
|
||||
def get_response_code(*argv):
|
||||
"""
|
||||
Returns mock response codes
|
||||
"""
|
||||
return MockData.resp
|
||||
|
||||
class TestDeleteTasks(object):
|
||||
"""
|
||||
Class for unit tests of 'cleardcpmmpendingconfig' command
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("tasks, expected_result", [
|
||||
(MockData.mock_tasks_1, [MockData.mock_tasks_1[0]]),
|
||||
([MockData.mock_tasks_2[0]], [MockData.mock_tasks_2[0]])
|
||||
])
|
||||
def test_get_memory_chunk_tasks_pass(tasks, expected_result, monkeypatch):
|
||||
"""
|
||||
Tests for 'get_memory_chunk_tasks' with valid data
|
||||
"""
|
||||
MockData.task = tasks
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers,
|
||||
"retrieve_task_members", MockData.get_resource_tasks)
|
||||
pmem_command = ClearPendingConfigCommand.ClearPendingConfigCommand(RdmcCommandBase)
|
||||
result = pmem_command.get_memory_chunk_tasks()
|
||||
assert result == expected_result
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("tasks", [
|
||||
(MockData.mock_tasks_3),
|
||||
([MockData.mock_tasks_3[0]]),
|
||||
([MockData.mock_tasks_3[1]]),
|
||||
([MockData.mock_tasks_1[1]])
|
||||
])
|
||||
def test_get_memory_chunk_tasks_fail(tasks, monkeypatch):
|
||||
"""
|
||||
Tests for 'get_memory_chunk_tasks' with invalid data
|
||||
"""
|
||||
MockData.task = tasks
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "retrieve_task_members",
|
||||
MockData.get_resource_tasks)
|
||||
pmem_command = ClearPendingConfigCommand.ClearPendingConfigCommand(RdmcCommandBase)
|
||||
with pytest.raises(NoContentsFoundForOperationError):
|
||||
pmem_command.get_memory_chunk_tasks()
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("resp, verbose", [
|
||||
(200, False),
|
||||
(200, True)
|
||||
])
|
||||
def test_delete_tasks_pass(resp, verbose, monkeypatch):
|
||||
"""
|
||||
Tests for 'delete_tasks' with valid data
|
||||
"""
|
||||
MockData.resp = resp
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "delete_resource",
|
||||
MockData.get_response_code)
|
||||
pmem_command = ClearPendingConfigCommand.ClearPendingConfigCommand(RdmcCommandBase)
|
||||
result = pmem_command.delete_tasks(MockData.mock_tasks_3, verbose)
|
||||
assert result is None
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("resp, verbose", [
|
||||
(None, False),
|
||||
(None, True)
|
||||
])
|
||||
def test_delete_tasks_fail(resp, verbose, monkeypatch):
|
||||
"""
|
||||
Tests for 'delete_tasks' with invalid data
|
||||
"""
|
||||
MockData.resp = resp
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "delete_resource",
|
||||
MockData.get_response_code)
|
||||
pmem_command = ClearPendingConfigCommand.ClearPendingConfigCommand(RdmcCommandBase)
|
||||
with pytest.raises(NoChangesFoundOrMadeError):
|
||||
pmem_command.delete_tasks(MockData.mock_tasks_3, verbose)
|
||||
@@ -0,0 +1,165 @@
|
||||
"""Module to test the DisplayHelpers Class"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import ast
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
# For cross-compatibility between Python 2 and Python 3
|
||||
from six import StringIO
|
||||
|
||||
from .conftest import DisplayHelpers
|
||||
|
||||
|
||||
class TestDisplayHelpers(object):
|
||||
"""
|
||||
Class to test methods from the DisplayHelpers class
|
||||
"""
|
||||
output_format = DisplayHelpers.OutputFormats
|
||||
|
||||
@staticmethod
|
||||
def capture_stdout(func, data, out_format, prop_id=None):
|
||||
"""
|
||||
Function to capture the standard output stream
|
||||
"""
|
||||
old_stdout = sys.stdout
|
||||
capturer = StringIO()
|
||||
sys.stdout = capturer
|
||||
func(data, out_format, prop_id)
|
||||
sys.stdout = old_stdout
|
||||
output = capturer.getvalue()
|
||||
return output
|
||||
|
||||
@pytest.mark.parametrize('table_data, expected_output', [
|
||||
# Tests with empty input
|
||||
(None, ""),
|
||||
([], ""),
|
||||
# Single object test
|
||||
(["ItemId:ID1\nProperty1:Value1"], "ItemId Property1 ID1 Value1"),
|
||||
# Test to check truncation of string
|
||||
(["ItemId:ID1\nProp2:Value of property2\nProp1:Value1"],
|
||||
"ItemId Prop2 Prop1 ID1 Value of.. Value1"),
|
||||
# Multiple objects test
|
||||
(["ItemId:ID1\nProperty1: ", "ItemId:ID2\nProperty1:LongPropertyValue"],
|
||||
"ItemId Property1 ID1 ID2 LongProp..")
|
||||
])
|
||||
def test_printtable_withwidth(self, table_data, expected_output):
|
||||
"""
|
||||
Test for printtable with a custom specified width
|
||||
"""
|
||||
display_helpers = DisplayHelpers.DisplayHelpers(10)
|
||||
out = TestDisplayHelpers.capture_stdout(
|
||||
display_helpers.display_data, table_data, self.output_format.table, None)
|
||||
assert [str(x) for x in out.split()] == expected_output.split()
|
||||
|
||||
@pytest.mark.parametrize('table_data, expected_output', [
|
||||
# Tests with empty input
|
||||
(None, ""),
|
||||
([], ""),
|
||||
# Single object test
|
||||
(["ItemId:ID1\nProperty1:Value1"], "ItemId Property1 ID1 Value1"),
|
||||
# Test to check truncation of string
|
||||
(["ItemId:ID1\nProp2:Value of property2\nProp1:Value1"],
|
||||
"ItemId Prop2 Prop1 ID1 Value of property2 Value1"),
|
||||
# Converting redfish property to friendly name test
|
||||
(["Property2:Value2\nFWVersion:2.1"], " Property2 FWVersion Value2 2.1"),
|
||||
# Multiple objects test
|
||||
(["ItemId:ID1\nProperty1: ", "ItemId:ID2\nProperty1:LongPropertyValue"],
|
||||
"ItemId Property1 ID1 ID2 LongPropertyValue")
|
||||
])
|
||||
def test_printtable(self, table_data, expected_output):
|
||||
"""
|
||||
Test for printtable with the default width
|
||||
"""
|
||||
display_helpers = DisplayHelpers.DisplayHelpers()
|
||||
out = TestDisplayHelpers.capture_stdout(
|
||||
display_helpers.display_data, table_data, self.output_format.table, None)
|
||||
assert out.split() == expected_output.split()
|
||||
|
||||
@pytest.mark.parametrize('table_data, expected_output', [
|
||||
# Tests with empty input
|
||||
(None, ""),
|
||||
([], ""),
|
||||
# Single object test
|
||||
(["ItemId:ID1\nProperty1:Value1"],
|
||||
"--- 1 ---\nItemId: ID1\nProperty1: Value1"),
|
||||
# Converting redfish property to friendly name test
|
||||
(["FWVersion:2.1\nItemId:ID1"], "--- 1 ---\nFWVersion: 2.1\nItemId: ID1"),
|
||||
# Multiple objects test
|
||||
(["ItemId:ID1\nProperty1:", "ItemId:ID2\nProperty1:Value1"],
|
||||
"--- 1 ---\nItemId: ID1\nProperty1: \n\n--- 2 ---\nItemId: ID2\nProperty1: Value1")
|
||||
])
|
||||
def test_printlist(self, table_data, expected_output):
|
||||
"""
|
||||
Test for the printlist function that produces output in list form
|
||||
"""
|
||||
display_helpers = DisplayHelpers.DisplayHelpers()
|
||||
out = TestDisplayHelpers.capture_stdout(
|
||||
display_helpers.display_data, table_data, self.output_format.list, None)
|
||||
assert out.strip() == expected_output.strip()
|
||||
|
||||
@pytest.mark.parametrize('table_data, expected_output', [
|
||||
# Tests with empty input
|
||||
(None, ""),
|
||||
([], ""),
|
||||
# Single object test
|
||||
(["ItemId:ID1\nProperty1:Value1"],
|
||||
"--- ItemId: ID1 ---\nProperty1: Value1"),
|
||||
# Converting redfish property to friendly name test
|
||||
(["ItemId:ID1\nFWVersion:2.1"], "--- ItemId: ID1 ---\nFWVersion: 2.1"),
|
||||
# Multiple objects test
|
||||
(["ItemId:ID1\nProperty1:", "ItemId:ID2\nProperty1:Value1"],
|
||||
"--- ItemId: ID1 ---\nProperty1: \n\n--- ItemId: ID2 ---\nProperty1: Value1")
|
||||
])
|
||||
def test_printlist_withid(self, table_data, expected_output):
|
||||
"""
|
||||
Test for the printlist function that produces output in list form with custom ID
|
||||
"""
|
||||
display_helpers = DisplayHelpers.DisplayHelpers()
|
||||
out = TestDisplayHelpers.capture_stdout(
|
||||
display_helpers.display_data, table_data, self.output_format.list, "ItemId")
|
||||
assert out.strip() == expected_output.strip()
|
||||
|
||||
@pytest.mark.parametrize('table_data, expected_output', [
|
||||
# Tests with empty input
|
||||
(None, ""),
|
||||
([], ""),
|
||||
# Single object test
|
||||
([{"ItemId": "ID1", "Property1": "Value1"}],
|
||||
[{"ItemId": "ID1", "Property1": "Value1"}]),
|
||||
# Converting redfish property to friendly name test
|
||||
([{"FWVersion": 2.1, "Property2": "Value2"}],
|
||||
[{"Property2": "Value2", "FWVersion": 2.1}]),
|
||||
# Multiple objects test
|
||||
([{"ItemId": "ID1", "Property1": ""}, {"ItemId": "ID2", "Property1": "LongPropertyValue"}],
|
||||
[{"ItemId": "ID1", "Property1": ""}, {"ItemId": "ID2", "Property1": "LongPropertyValue"}])
|
||||
])
|
||||
def test_printjson(self, table_data, expected_output):
|
||||
"""
|
||||
Test for the printjson function that produces output in json form
|
||||
"""
|
||||
display_helpers = DisplayHelpers.DisplayHelpers()
|
||||
out = TestDisplayHelpers.capture_stdout(
|
||||
display_helpers.display_data, table_data, self.output_format.json, None)
|
||||
if expected_output == "":
|
||||
assert out == expected_output
|
||||
else:
|
||||
out = ast.literal_eval("".join(out.split()))
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('string, maxlen, expected_output', [
|
||||
("Banana", 10, "Banana"),
|
||||
("Hot Tamale", 10, "Hot Tamale"),
|
||||
("Antidisestablishmentarianism", 10, "Antidise.."),
|
||||
("hippopotomonstrosesquipedaliophobia", 18, "hippopotomonstro.."),
|
||||
(None, 10, "")
|
||||
])
|
||||
def test_truncate_lengthy(string, maxlen, expected_output):
|
||||
"""
|
||||
Test for the truncate_lengthy method
|
||||
"""
|
||||
display_helpers = DisplayHelpers.DisplayHelpers()
|
||||
out = display_helpers.truncate_lengthy(string, maxlen)
|
||||
assert out == expected_output
|
||||
@@ -0,0 +1,297 @@
|
||||
"""
|
||||
This module contains tests for MapperRenderers
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
|
||||
from .conftest import MapperRenderers
|
||||
|
||||
|
||||
class TestMapperRenderes(object):
|
||||
"""
|
||||
class to test functions in MapperRenderers
|
||||
"""
|
||||
mock_data = [
|
||||
{
|
||||
"DeviceLocator": "PROC 1 DIMM 1",
|
||||
"CapacityMiB": 123456,
|
||||
"PersistentRegionSizeLimitMiB": 24680,
|
||||
"SizeMiB": "xyz",
|
||||
"VolatileRegionSizeLimitMiB": 45678,
|
||||
},
|
||||
{
|
||||
"DeviceLocator": "PROC 2 DIMM 12",
|
||||
"CapacityMiB": 987654,
|
||||
"PersistentRegionSizeLimitMiB": 13579,
|
||||
"SizeMiB": "abc@123",
|
||||
"VolatileRegionSizeLimitMiB": 90123,
|
||||
}]
|
||||
|
||||
tasks = [
|
||||
{
|
||||
"Payload": {
|
||||
"JsonBody": {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Payload": {
|
||||
"JsonBody": {
|
||||
"MemoryChunkSizeMiB": 250
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Payload": {
|
||||
"JsonBody": {
|
||||
"Oem": {
|
||||
"Hpe": {
|
||||
"MemoryChunkSizePercentage": 40
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Payload": {
|
||||
"JsonBody": {
|
||||
"MemoryChunkSizeMiB": 700,
|
||||
"Oem": {
|
||||
"Hpe": {
|
||||
"MemoryChunkSizePercentage": 25
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Payload": {
|
||||
"JsonBody": {
|
||||
"Oem": {
|
||||
"Hpe": {
|
||||
"MemoryChunkSizePercentage": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Payload": {
|
||||
"JsonBody": {
|
||||
"MemoryChunkSizeMiB": 0,
|
||||
"Oem": {
|
||||
"Hpe": {
|
||||
"MemoryChunkSizePercentage": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("num, expected_output", [
|
||||
(0, "0.0 GiB"),
|
||||
(20, "0.02 GiB"),
|
||||
(400, "0.39 GiB"),
|
||||
(1024, "1.0 GiB"),
|
||||
(2000, "1.95 GiB"),
|
||||
(18499, "18.07 GiB")
|
||||
])
|
||||
def test_format_num(num, expected_output):
|
||||
"""
|
||||
Test for format_num()
|
||||
:param num: any number
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.format_num(num)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("num, expected_output", [
|
||||
(0, {"Units": "GiB", "Value": 0.0}),
|
||||
(20, {"Units": "GiB", "Value": 0.02}),
|
||||
(400, {"Units": "GiB", "Value": 0.39}),
|
||||
(1024, {"Units": "GiB", "Value": 1.0}),
|
||||
(2000, {"Units": "GiB", "Value": 1.95}),
|
||||
(18499, {"Units": "GiB", "Value": 18.07})
|
||||
])
|
||||
def test_format_num_json(num, expected_output):
|
||||
"""
|
||||
Test for format_num_json()
|
||||
:param num: any number
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.format_num_json(num)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("members, expected_output", [
|
||||
([], "0.0 GiB"),
|
||||
([mock_data[0]], "120.56 GiB"),
|
||||
([mock_data[1]], "964.51 GiB"),
|
||||
(mock_data, "1085.07 GiB")
|
||||
])
|
||||
def test_calculate_total_capacity(members, expected_output):
|
||||
"""
|
||||
Test for calculate_total_capacity()
|
||||
:param members: members for which total capacity needs to be calculated
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.calculate_total_capacity(members)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("members, expected_output", [
|
||||
([], {"Units": "GiB", "Value": 0.0}),
|
||||
([mock_data[0]], {"Units": "GiB", "Value": 120.56}),
|
||||
([mock_data[1]], {"Units": "GiB", "Value": 964.51}),
|
||||
(mock_data, {"Units": "GiB", "Value": 1085.07})
|
||||
])
|
||||
def test_calculate_total_capacity_json(members, expected_output):
|
||||
"""
|
||||
Test for calculate_total_capacity_json()
|
||||
:param members: members for which total capacity needs to be calculated
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.calculate_total_capacity_json(members)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("members, expected_output", [
|
||||
([], "0.0 GiB"),
|
||||
([mock_data[0]], "44.61 GiB"),
|
||||
([mock_data[1]], "88.01 GiB"),
|
||||
(mock_data, "132.62 GiB")
|
||||
])
|
||||
def test_calculate_total_volatile(members, expected_output):
|
||||
"""
|
||||
Test for calculate_total_volatile()
|
||||
:param members: members for which total volatile size needs to be calculated
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.calculate_total_volatile(members)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("members, expected_output", [
|
||||
([], {"Units": "GiB", "Value": 0.0}),
|
||||
([mock_data[0]], {"Units": "GiB", "Value": 44.61}),
|
||||
([mock_data[1]], {"Units": "GiB", "Value": 88.01}),
|
||||
(mock_data, {"Units": "GiB", "Value": 132.62})
|
||||
])
|
||||
def test_calculate_total_volatile_json(members, expected_output):
|
||||
"""
|
||||
Test for calculate_total_volatile_json()
|
||||
:param members: members for which total volatile size needs to be calculated
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.calculate_total_volatile_json(members)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("members, expected_output", [
|
||||
([], "0.0 GiB"),
|
||||
([mock_data[0]], "24.1 GiB"),
|
||||
([mock_data[1]], "13.26 GiB"),
|
||||
(mock_data, "37.36 GiB")
|
||||
])
|
||||
def test_calculate_total_appdirect(members, expected_output):
|
||||
"""
|
||||
Test for calculate_total_appdirect()
|
||||
:param members: members for which total appdirect size needs to be calculated
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.calculate_total_appdirect(members)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("members, expected_output", [
|
||||
([], {"Units": "GiB", "Value": 0.0}),
|
||||
([mock_data[0]], {"Units": "GiB", "Value": 24.10}),
|
||||
([mock_data[1]], {"Units": "GiB", "Value": 13.26}),
|
||||
(mock_data, {"Units": "GiB", "Value": 37.36})
|
||||
])
|
||||
def test_calculate_total_appdirect_json(members, expected_output):
|
||||
"""
|
||||
Test for calculate_total_appdirect_json()
|
||||
:param members: members for which total appdirect size needs to be calculated
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.calculate_total_appdirect_json(members)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("temp, expected_output", [
|
||||
# neither MemoryChunkSizeMiB nor MemoryChunkSizPercentage is present
|
||||
({"Task": tasks[0], "TotalCapacity": 1000}, "1000.0 GiB"),
|
||||
# Only MemoryChunkSizeMiB is present
|
||||
({"Task": tasks[1], "TotalCapacity": 1000}, "250.0 GiB"),
|
||||
# Only MemoryChunkSizePercentage is present
|
||||
({"Task": tasks[2], "TotalCapacity": 1000}, "400.0 GiB"),
|
||||
# Both MemoryChunkSizeMiB and MemoryChunkSizePercentage are present
|
||||
({"Task": tasks[3], "TotalCapacity": 1000}, "700.0 GiB"),
|
||||
# MemoryChunkSizePercentage is 0
|
||||
({"Task": tasks[4], "TotalCapacity": 1000}, "0.0 GiB"),
|
||||
# MemoryChunkSizeMiB is 0
|
||||
({"Task": tasks[4], "TotalCapacity": 1000}, "0.0 GiB")
|
||||
])
|
||||
def test_calculate_task_pmem_size(temp, expected_output):
|
||||
"""
|
||||
Test for calculate_task_pmem_size()
|
||||
:param temp: dictionary with task and total capacity of the task as keys
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.calculate_task_pmem_size(temp)
|
||||
assert out == expected_output
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("temp, expected_output", [
|
||||
# neither MemoryChunkSizeMiB nor MemoryChunkSizPercentage is present
|
||||
({"Task": tasks[0], "TotalCapacity": 1000}, "1000.0 GiB"),
|
||||
# Only MemoryChunkSizeMiB is present
|
||||
({"Task": tasks[1], "TotalCapacity": 1000}, "750.0 GiB"),
|
||||
# Only MemoryChunkSizePercentage is present
|
||||
({"Task": tasks[2], "TotalCapacity": 1000}, "600.0 GiB"),
|
||||
# Both MemoryChunkSizeMiB and MemoryChunkSizePercentage are present
|
||||
({"Task": tasks[3], "TotalCapacity": 1000}, "300.0 GiB"),
|
||||
# MemoryChunkSizePercentage is 0
|
||||
({"Task": tasks[4], "TotalCapacity": 1000}, "1000.0 GiB"),
|
||||
# MemoryChunkSizeMiB is 0
|
||||
({"Task": tasks[4], "TotalCapacity": 1000}, "1000.0 GiB")
|
||||
])
|
||||
def test_calculate_task_volatile_size(temp, expected_output):
|
||||
"""
|
||||
Test for calculate_task_volatile_size()
|
||||
:param temp: dictionary with task and total capacity of the task as keys
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.calculate_task_volatile_size(temp)
|
||||
assert out == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("operation, expected_output", [
|
||||
("post", "post"),
|
||||
("POST", "CREATE"),
|
||||
("GET", "GET"),
|
||||
("get", "get")
|
||||
])
|
||||
def test_map_operation(operation, expected_output):
|
||||
"""
|
||||
Test for map_operation()
|
||||
:param operation: HTTP operation
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
renderers = MapperRenderers.MapperRenderers()
|
||||
out = renderers.map_operation(operation)
|
||||
assert out == expected_output
|
||||
@@ -0,0 +1,179 @@
|
||||
"""
|
||||
This module contains tests for PmemHelpers
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
|
||||
from ..conftest import PmemHelpers
|
||||
|
||||
|
||||
class TestPmemHelpers(object):
|
||||
"""
|
||||
Class to test functions in PmemHelpers
|
||||
"""
|
||||
mem_members = [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc1dimm1/",
|
||||
"DeviceLocator": "PROC 1 DIMM 1",
|
||||
"MemoryType": "NVDIMM_P",
|
||||
"Oem": {
|
||||
"Hpe": {
|
||||
"@odata.context": "/redfish/v1/$metadata#HpeMemoryExt.HpeMemoryExt",
|
||||
"@odata.type": "#HpeMemoryExt.v2_1_0.HpeMemoryExt",
|
||||
"ProductName": "Intel Optane Memory"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc1dimm2/",
|
||||
"DeviceLocator": "PROC 1 DIMM 2",
|
||||
"MemoryType": "DRAM",
|
||||
"Oem": {
|
||||
"Hpe": {
|
||||
"@odata.context": "/redfish/v1/$metadata#HpeMemoryExt.HpeMemoryExt",
|
||||
"@odata.type": "#HpeMemoryExt.v2_1_0.HpeMemoryExt",
|
||||
"DIMMStatus": "NotPresent"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
chunks = [
|
||||
{
|
||||
"InterleaveSets": [
|
||||
{
|
||||
"Memory": {
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc1dimm1/"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"InterleaveSets": [
|
||||
{
|
||||
"Memory": {
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc1dimm12/"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"InterleaveSets": [
|
||||
{
|
||||
"Memory": {
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc2dimm1/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Memory": {
|
||||
"@odata.id": "/redfish/v1/Systems/1/Memory/proc2dimm12/"
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('dimm_id_list, expected_output', [
|
||||
(['1@2', '2@3', '3@4'], ['PROC 1 DIMM 2', 'PROC 2 DIMM 3', 'PROC 3 DIMM 4']),
|
||||
(['2@12'], ['PROC 2 DIMM 12'])
|
||||
])
|
||||
def test_parse_dimm_id(dimm_id_list, expected_output):
|
||||
"""
|
||||
Test for parse_dimm_id()
|
||||
:param dimm_id_list: DIMM IDs in the 'X@Y' format
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
result = PmemHelpers.PmemHelpers.parse_dimm_id(dimm_id_list)
|
||||
assert result == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("memory_members, expected_output", [
|
||||
(mem_members, ([{'MemoryType': 'NVDIMM_P',
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm1/',
|
||||
'Oem': {
|
||||
'Hpe':
|
||||
{'@odata.type': '#HpeMemoryExt.v2_1_0.HpeMemoryExt',
|
||||
'@odata.context': '/redfish/v1/$metadata#HpeMemoryExt.'
|
||||
'HpeMemoryExt',
|
||||
'ProductName': 'Intel Optane Memory'}
|
||||
},
|
||||
'DeviceLocator': 'PROC 1 DIMM 1'}],
|
||||
set(['PROC 1 DIMM 1']))),
|
||||
([mem_members[0]], ([{'MemoryType': 'NVDIMM_P',
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm1/',
|
||||
'Oem': {
|
||||
'Hpe':
|
||||
{'@odata.type': '#HpeMemoryExt.v2_1_0.HpeMemoryExt',
|
||||
'@odata.context': '/redfish/v1/$metadata#HpeMemoryExt.'
|
||||
'HpeMemoryExt',
|
||||
'ProductName': 'Intel Optane Memory'}
|
||||
},
|
||||
'DeviceLocator': 'PROC 1 DIMM 1'}],
|
||||
set(['PROC 1 DIMM 1']))),
|
||||
([mem_members[1]], ([], set([]))),
|
||||
([], ([], set([])))
|
||||
])
|
||||
def test_get_pmem_members(memory_members, expected_output):
|
||||
"""
|
||||
Test for get_pmem_members()
|
||||
:param memory_members: members of memory collection resource
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
result = PmemHelpers.PmemHelpers.get_pmem_members(memory_members)
|
||||
assert result == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("data_id, chunks, expected_output", [
|
||||
("/redfish/v1/Systems/1/Memory/proc1dimm1/", chunks, False),
|
||||
("/redfish/v1/Systems/1/Memory/proc2dimm1/", chunks, True),
|
||||
("/redfish/v1/Systems/1/Memory/proc2dimm1/", [], None),
|
||||
("/redfish/v1/Systems/1/Memory/proc1dimm4/", chunks, None)])
|
||||
def test_is_interleave_set(data_id, chunks, expected_output):
|
||||
"""
|
||||
Test for is_interleave_set()
|
||||
:param data_id: @odata.id of the memory to be checked
|
||||
:param chunks: list of chunks
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
result = PmemHelpers.PmemHelpers.is_interleave_set(data_id, chunks)
|
||||
assert result == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('location_list, expected_output', [
|
||||
(['PROC X DIMM Y'], ('X@Y', 'PROC X')),
|
||||
(['PROC A DIMM B', 'PROC A DIMM C', 'PROC A DIMM D'], ('A@B, A@C, A@D', 'PROC A'))
|
||||
])
|
||||
def test_location_format_converter(location_list, expected_output):
|
||||
"""
|
||||
Test for location_format_converter()
|
||||
:param location_list: list of locations of the format 'PROC X DIMM Y'
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
result = PmemHelpers.PmemHelpers.location_format_converter(location_list)
|
||||
assert result == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("id1, id2, expected_output", [
|
||||
("/redfish/v1/Systems/1/Memory/proc1dimm1", "/redfish/v1/Systems/1/Memory/proc1dimm1",
|
||||
True),
|
||||
("/redfish/v1/Systems/1/Memory/proc1dimm1/", "/redfish/v1/Systems/1/Memory/proc1dimm1",
|
||||
True),
|
||||
("/redfish/v1/Systems/1/Memory/proc1dimm1", "/redfish/v1/Systems/1/Memory/proc1dimm1/",
|
||||
True),
|
||||
("/redfish/v1/Systems/1/Memory/proc1dimm1/", "/redfish/v1/Systems/1/Memory/proc1dimm1/",
|
||||
True),
|
||||
("/redfish/v1/Systems/1/Memory/proc1dimm2/", "/redfish/v1/Systems/1/Memory/proc1dimm1/",
|
||||
False)
|
||||
])
|
||||
def test_compare_id(id1, id2, expected_output):
|
||||
"""
|
||||
Test for compare_id()
|
||||
:param id1: first id to be compared
|
||||
:param id2: second id to be compared
|
||||
:param expected_output:
|
||||
:return: expected output of the test
|
||||
"""
|
||||
result = PmemHelpers.PmemHelpers.compare_id(id1, id2)
|
||||
assert result == expected_output
|
||||
@@ -0,0 +1,409 @@
|
||||
"""Module to Test the Rest Helpers Class"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
|
||||
from rdmc_base_classes import RdmcCommandBase
|
||||
|
||||
from .conftest import RestHelpers
|
||||
|
||||
|
||||
class MockMemoryDomainResource(object):
|
||||
"""
|
||||
Class to mock Memory Domain Resources
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.status = 200
|
||||
self.dict = {"@odata.context": "/redfish/v1/$metadata#MemoryDomainCollection"
|
||||
".MemoryDomainCollection",
|
||||
"@odata.etag": "W\"92240A75\"",
|
||||
"@odata.id": "/redfish/v1/Systems/1/MemoryDomains/",
|
||||
"@odata.type": "#MemoryDomainCollection.MemoryDomainCollection",
|
||||
"Description": "Memory Domains Collection",
|
||||
"Members": [{"@odata.context": "/redfish/v1/$metadata#MemoryDomain."
|
||||
"MemoryDomain",
|
||||
"@odata.id": "/redfish/v1/Systems/1/MemoryDomains/"
|
||||
"PROC1MemoryDomain/",
|
||||
"@odata.type": "#MemoryDomain.v1_0_0.MemoryDomain",
|
||||
"Id": "PROC1MemoryDomain",
|
||||
"InterleavableMemorySets": [
|
||||
{"MemorySet": [{"@odata.id": "/redfish/v1/Systems/1/Memory/"
|
||||
"proc1dimm6/"},
|
||||
{"@odata.id": "/redfish/v1/Systems/1/Memory/"
|
||||
"proc1dimm7/"}]},
|
||||
{"MemorySet": [{"@odata.id": "/redfish/v1/Systems/1/Memory/"
|
||||
"proc1dimm6/"}]},
|
||||
{"MemorySet": [{"@odata.id": "/redfish/v1/Systems/1/Memory/"
|
||||
"proc1dimm7/"}]}],
|
||||
"MemoryChunks": {
|
||||
"@odata.id": "/redfish/v1/Systems/1/MemoryDomains/"
|
||||
"PROC1MemoryDomain/MemoryChunks/"},
|
||||
"Name": "PROC1 Memory Domain"},
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#MemoryDomain"
|
||||
".MemoryDomain",
|
||||
"@odata.id": "/redfish/v1/Systems/1/MemoryDomains"
|
||||
"/PROC2MemoryDomain/",
|
||||
"@odata.type": "#MemoryDomain.v1_0_0.MemoryDomain",
|
||||
"Id": "PROC2MemoryDomain",
|
||||
"InterleavableMemorySets": [
|
||||
{"MemorySet": [
|
||||
{"@odata.id": "/redfish/v1/Systems/1/Memory/"
|
||||
"proc2dimm6/"},
|
||||
{"@odata.id": "/redfish/v1/Systems/1/Memory/"
|
||||
"proc2dimm7/"}]},
|
||||
{"MemorySet": [
|
||||
{"@odata.id": "/redfish/v1/Systems/1/Memory/"
|
||||
"proc2dimm6/"}]},
|
||||
{"MemorySet": [
|
||||
{"@odata.id": "/redfish/v1/Systems/1/Memory/"
|
||||
"proc2dimm7/"}]}],
|
||||
"MemoryChunks": {
|
||||
"@odata.id": "/redfish/v1/Systems/1/MemoryDomains/"
|
||||
"PROC2MemoryDomain/MemoryChunks/"},
|
||||
"Name": "PROC2 Memory Domain"}],
|
||||
"Members@odata.count": 2,
|
||||
"Name": "Memory Domains Collection"}
|
||||
|
||||
def get_obj(self, *argv):
|
||||
"""
|
||||
Returns dict
|
||||
"""
|
||||
return self.dict
|
||||
|
||||
|
||||
class MockTaskResources(object):
|
||||
"""
|
||||
Class to mock Task Resources
|
||||
"""
|
||||
Tasks = [{
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 1",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm12/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/"
|
||||
"MemoryChunks/?$expand=."
|
||||
},
|
||||
"TaskState": "New"
|
||||
}, {
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 2",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm10/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/"
|
||||
"MemoryChunks/?$expand=."
|
||||
},
|
||||
"TaskState": "Old"
|
||||
}]
|
||||
|
||||
Other_Tasks = [{
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 1",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc1dimm12/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/?$expand=."
|
||||
},
|
||||
"TaskState": "New"
|
||||
}, {
|
||||
"@odata.context": "/redfish/v1/$metadata#Task.Task",
|
||||
"Name": "Task 2",
|
||||
"Payload": {
|
||||
"HttpOperation": "POST",
|
||||
"JsonBody": "{\"AddressRangeType\": \"PMEM\","
|
||||
"\"InterleaveSets\": "
|
||||
"[{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm1/\"}},"
|
||||
"{\"Memory\": "
|
||||
"{\"@odata.id\": \"/redfish/v1/Systems/1/Memory/proc2dimm10/\"}}],"
|
||||
"\"Oem\": {\"Hpe\": {\"MemoryChunkSizePercentage\": 0}}}",
|
||||
"TargetUri": "/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/?$expand=."
|
||||
},
|
||||
"TaskState": "Old"
|
||||
}]
|
||||
|
||||
@staticmethod
|
||||
def get_resource_tasks(*argv):
|
||||
"""
|
||||
Returns valid Task resources
|
||||
"""
|
||||
return {"Members": MockTaskResources.Tasks}
|
||||
|
||||
@staticmethod
|
||||
def get_resource_empty(*argv):
|
||||
"""
|
||||
Returns empty Task Resources
|
||||
"""
|
||||
return {"Members": []}
|
||||
|
||||
@staticmethod
|
||||
def get_resource_none(*argv):
|
||||
"""
|
||||
returns None
|
||||
"""
|
||||
return None
|
||||
|
||||
|
||||
class TestRestHelpers(object):
|
||||
"""
|
||||
Class to test methods from the RestHelpers class
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def test_retrieve_mem_domain_resources(monkeypatch):
|
||||
"""
|
||||
Test for retrieving Memory Domain Resources
|
||||
"""
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers,
|
||||
"get_resource", MockMemoryDomainResource().get_obj)
|
||||
rest_helpers = RestHelpers.RestHelpers(RdmcCommandBase)
|
||||
resp = rest_helpers.retrieve_mem_domain_resources()
|
||||
assert resp == ([{'@odata.context': '/redfish/v1/$metadata#MemoryDomain.MemoryDomain',
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/',
|
||||
'@odata.type': '#MemoryDomain.v1_0_0.MemoryDomain',
|
||||
'Id': 'PROC1MemoryDomain',
|
||||
'InterleavableMemorySets': [
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm6/'},
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm7/'}]},
|
||||
{'MemorySet': [{
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm6/'}]},
|
||||
{'MemorySet': [{
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm7/'}]}],
|
||||
'MemoryChunks': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain'
|
||||
'/MemoryChunks/'},
|
||||
'Name': 'PROC1 Memory Domain'},
|
||||
{'@odata.context': '/redfish/v1/$metadata#MemoryDomain.MemoryDomain',
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/',
|
||||
'@odata.type': '#MemoryDomain.v1_0_0.MemoryDomain',
|
||||
'Id': 'PROC2MemoryDomain',
|
||||
'InterleavableMemorySets': [
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'},
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'}]},
|
||||
{'MemorySet': [{
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'}]},
|
||||
{'MemorySet': [{
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'}]}],
|
||||
'MemoryChunks': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain'
|
||||
'/MemoryChunks/'},
|
||||
'Name': 'PROC2 Memory Domain'}],
|
||||
[{'@odata.context': '/redfish/v1/$metadata#MemoryDomain.MemoryDomain',
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/',
|
||||
'@odata.type': '#MemoryDomain.v1_0_0.MemoryDomain',
|
||||
'Id': 'PROC1MemoryDomain',
|
||||
'InterleavableMemorySets': [
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm6/'},
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm7/'}]},
|
||||
{'MemorySet': [
|
||||
{
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm6/'}]},
|
||||
{'MemorySet': [
|
||||
{
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm7/'}]}],
|
||||
'MemoryChunks': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain'
|
||||
'/MemoryChunks/'},
|
||||
'Name': 'PROC1 Memory Domain'},
|
||||
{'@odata.context': '/redfish/v1/$metadata#MemoryDomain.MemoryDomain',
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/',
|
||||
'@odata.type': '#MemoryDomain.v1_0_0.MemoryDomain',
|
||||
'Id': 'PROC2MemoryDomain',
|
||||
'InterleavableMemorySets': [
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'},
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'}]},
|
||||
{'MemorySet': [
|
||||
{
|
||||
'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'}]},
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'}]}],
|
||||
'MemoryChunks': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain'
|
||||
'/MemoryChunks/'},
|
||||
'Name': 'PROC2 Memory Domain'},
|
||||
{'@odata.context': '/redfish/v1/$metadata#MemoryDomain.MemoryDomain',
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain/',
|
||||
'@odata.type': '#MemoryDomain.v1_0_0.MemoryDomain',
|
||||
'Id': 'PROC1MemoryDomain',
|
||||
'InterleavableMemorySets': [
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm6/'},
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm7/'}]},
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm6/'}]},
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc1dimm7/'}]}],
|
||||
'MemoryChunks': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC1MemoryDomain'
|
||||
'/MemoryChunks/'},
|
||||
'Name': 'PROC1 Memory Domain'},
|
||||
{'@odata.context': '/redfish/v1/$metadata#MemoryDomain.MemoryDomain',
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain/',
|
||||
'@odata.type': '#MemoryDomain.v1_0_0.MemoryDomain',
|
||||
'Id': 'PROC2MemoryDomain',
|
||||
'InterleavableMemorySets': [
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'},
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'}]},
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm6/'}]},
|
||||
{'MemorySet': [
|
||||
{'@odata.id': '/redfish/v1/Systems/1/Memory/proc2dimm7/'}]}],
|
||||
'MemoryChunks': {
|
||||
'@odata.id': '/redfish/v1/Systems/1/MemoryDomains/PROC2MemoryDomain'
|
||||
'/MemoryChunks/'},
|
||||
'Name': 'PROC2 Memory Domain'}])
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('mock_get_resource, expected_output', [
|
||||
(MockTaskResources.get_resource_tasks, MockTaskResources.Tasks),
|
||||
(MockTaskResources.get_resource_empty, []),
|
||||
(MockTaskResources.get_resource_none, [])
|
||||
])
|
||||
def test_retrieve_task_members(mock_get_resource, expected_output, monkeypatch):
|
||||
"""
|
||||
Tests for retrieving task members
|
||||
"""
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers,
|
||||
"get_resource", mock_get_resource)
|
||||
rest_helpers = RestHelpers.RestHelpers(RdmcCommandBase)
|
||||
resp = rest_helpers.retrieve_task_members()
|
||||
assert resp == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("task_members, expected_output", [
|
||||
(MockTaskResources.Tasks, [MockTaskResources.Tasks[0]]),
|
||||
([MockTaskResources.Tasks[1]], []),
|
||||
(MockTaskResources.Other_Tasks, []),
|
||||
([MockTaskResources.Other_Tasks[0]], []),
|
||||
([MockTaskResources.Other_Tasks[1]], []),
|
||||
([], [])
|
||||
])
|
||||
def test_filter_task_members(task_members, expected_output):
|
||||
"""
|
||||
Tests for filtering task members
|
||||
"""
|
||||
rest_helpers = RestHelpers.RestHelpers(RdmcCommandBase)
|
||||
resp = rest_helpers.filter_task_members(task_members)
|
||||
assert resp == expected_output
|
||||
|
||||
|
||||
class MockDeleteResponse(object):
|
||||
"""
|
||||
Class to Mock Delete Response
|
||||
"""
|
||||
@staticmethod
|
||||
def get_success_resp(*argv):
|
||||
"""
|
||||
Returns a success response code (200)
|
||||
"""
|
||||
return 200
|
||||
|
||||
@staticmethod
|
||||
def get_failure_resp(*argv):
|
||||
"""
|
||||
Returns a failure response code (200)
|
||||
"""
|
||||
return 400
|
||||
|
||||
|
||||
class TestDeleteResponse(object):
|
||||
"""
|
||||
Class to Test Delete Response
|
||||
"""
|
||||
@staticmethod
|
||||
def test_delete_success(monkeypatch):
|
||||
"""
|
||||
Test where deletion is successful
|
||||
"""
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "delete_resource",
|
||||
MockDeleteResponse().get_success_resp)
|
||||
rest_helpers = RestHelpers.RestHelpers(RdmcCommandBase)
|
||||
resp = rest_helpers.delete_resource("/redfish/v1/TaskService/Tasks/1")
|
||||
assert resp == 200
|
||||
|
||||
@staticmethod
|
||||
def test_delete_failure(monkeypatch):
|
||||
"""
|
||||
Test where deletion fails
|
||||
"""
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers, "delete_resource",
|
||||
MockDeleteResponse().get_failure_resp)
|
||||
rest_helpers = RestHelpers.RestHelpers(RdmcCommandBase)
|
||||
resp = rest_helpers.delete_resource("/redfish/v1/TaskService/Tasks/1")
|
||||
assert resp == 400
|
||||
|
||||
|
||||
class MockPostResponse(object):
|
||||
"""
|
||||
Class to Mock Post Response
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_success_resp(*argv):
|
||||
"""
|
||||
Returns a success response code (202)
|
||||
"""
|
||||
return 202
|
||||
|
||||
@staticmethod
|
||||
def get_failure_resp(*argv):
|
||||
"""
|
||||
Returns a failure response code (402)
|
||||
"""
|
||||
return 402
|
||||
|
||||
|
||||
class TestPostResponse(object):
|
||||
"""
|
||||
Class to Test Post Response
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def test_post_success(monkeypatch):
|
||||
"""
|
||||
Test where POST succeds
|
||||
"""
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers,
|
||||
"post_resource", MockPostResponse().get_success_resp)
|
||||
rest_helpers = RestHelpers.RestHelpers(RdmcCommandBase)
|
||||
resp = rest_helpers.post_resource(
|
||||
"/redfish/v1/TaskService/Tasks/1", {"default": "testing"})
|
||||
assert resp == 202
|
||||
|
||||
@staticmethod
|
||||
def test_post_failure(monkeypatch):
|
||||
"""
|
||||
Test where POST fails
|
||||
"""
|
||||
monkeypatch.setattr(RestHelpers.RestHelpers,
|
||||
"post_resource", MockPostResponse().get_failure_resp)
|
||||
rest_helpers = RestHelpers.RestHelpers(RdmcCommandBase)
|
||||
resp = rest_helpers.post_resource(
|
||||
"/redfish/v1/TaskService/Tasks/1", {"default": "testing"})
|
||||
assert resp == 402
|
||||
@@ -0,0 +1,332 @@
|
||||
"""
|
||||
This module contains tests for ShowPmemCommand
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import pytest
|
||||
|
||||
from rdmc_base_classes import RdmcCommandBase
|
||||
from rdmc_helper import InvalidCommandLineError
|
||||
|
||||
from ..conftest import ShowPmemCommand
|
||||
|
||||
|
||||
class CustomOptions(object):
|
||||
"""
|
||||
Class to mock different options
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.all = True
|
||||
self.display_attributes = None
|
||||
self.json = False
|
||||
|
||||
def all_flag(self):
|
||||
"""
|
||||
Function to set --all flag to true
|
||||
:return: CustomOptions object
|
||||
"""
|
||||
self.all = True
|
||||
return self
|
||||
|
||||
def no_flag(self):
|
||||
"""
|
||||
Function to reset flags
|
||||
:return: CustomOptions object
|
||||
"""
|
||||
self.all = False
|
||||
self.display_attributes = None
|
||||
return self
|
||||
|
||||
def display_flag(self):
|
||||
"""
|
||||
Function to set --display flag
|
||||
:return: CustomOptions object
|
||||
"""
|
||||
self.all = False
|
||||
self.display_attributes = ["RandomNestedKey1"]
|
||||
return self
|
||||
|
||||
def wrong_display_flag(self):
|
||||
"""
|
||||
Function to set --display flag with wrong attributes
|
||||
:return: CustomOptions object
|
||||
"""
|
||||
self.all = False
|
||||
self.display_attributes = ["aBc", "xYz"]
|
||||
return self
|
||||
|
||||
@staticmethod
|
||||
def get_default(flag):
|
||||
"""
|
||||
Function to return default attributes
|
||||
:return: list of attributes
|
||||
"""
|
||||
if flag == "device":
|
||||
return ["Location", "SizeMiB"]
|
||||
if flag == "config":
|
||||
return ["Location", "Capacity"]
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def get_all(flag):
|
||||
"""
|
||||
Function to return attributes for --all flag
|
||||
:return: list of attributes
|
||||
"""
|
||||
if flag == "device":
|
||||
return ["Location", "SizeMiB", "RandomNestedKey1"]
|
||||
if flag == "config":
|
||||
return ["Location", "Capacity", "RandomNestedKey1"]
|
||||
return []
|
||||
|
||||
|
||||
class MockMappingTable(object):
|
||||
"""
|
||||
class to mock mapping table
|
||||
"""
|
||||
memory = {'Capacity': {'path': '/CapacityMiB', 'redfishName': 'CapacityMiB'},
|
||||
'Location': {'path': '/DeviceLocator', 'redfishName': 'DeviceLocator'},
|
||||
'RandomAttribute': {'path': "/RandomAttribute",
|
||||
'redfishName': 'RandomAttribute'},
|
||||
'RandomNestedKey1': {'path': "/RandomAttribute/RandomNestedKey1",
|
||||
'redfishName': 'RandomNestedKey1'},
|
||||
'SizeMiB': {'path': '/Regions/SizeMiB', 'redfishName': 'SizeMiB'}}
|
||||
memorychunk = {'Capacity': {'path': '/CapacityMiB', 'redfishName': 'CapacityMiB'},
|
||||
'Location': {'path': '/DeviceLocator', 'redfishName': 'DeviceLocator'},
|
||||
'RandomAttribute': {'path': "/RandomAttribute",
|
||||
'redfishName': 'RandomAttribute'},
|
||||
'RandomNestedKey1': {'path': "/RandomAttribute/RandomNestedKey1",
|
||||
'redfishName': 'RandomNestedKey1'},
|
||||
'SizeMiB': {'path': '/Regions/SizeMiB', 'redfishName': 'SizeMiB'}}
|
||||
|
||||
|
||||
class TestShowPmemCommands(object):
|
||||
"""
|
||||
Class to test functions in ShowPmemCommands
|
||||
"""
|
||||
mock_data = [
|
||||
{
|
||||
'DeviceLocator': 'PROC 1 DIMM 1',
|
||||
'CapacityMiB': 123456,
|
||||
'SizeMiB': 'xyz',
|
||||
'RandomAttribute': {
|
||||
'RandomNestedKey1': 'RandomNestedValue1.1',
|
||||
'RandomNestedKey2': [
|
||||
'RandomNestedValue2.1',
|
||||
'RandomNestedValue2.2'
|
||||
],
|
||||
'RandomNestedKey4': [
|
||||
{
|
||||
'RandomNestedKey5': 'RandomNestedValue5.1'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
'DeviceLocator': 'PROC 2 DIMM 12',
|
||||
'CapacityMiB': 987654,
|
||||
'SizeMiB': 'abc@123',
|
||||
'RandomAttribute': {
|
||||
'RandomNestedKey1': 'RandomNestedValue1.2',
|
||||
'RandomNestedKey2': [
|
||||
'RandomNestedValue2.3',
|
||||
'RandomNestedValue2.4'
|
||||
],
|
||||
'RandomNestedKey4': [
|
||||
{
|
||||
'RandomNestedKey5': 'RandomNestedValue5.2'
|
||||
}
|
||||
]
|
||||
}
|
||||
}]
|
||||
|
||||
custom_options_obj = CustomOptions()
|
||||
|
||||
@pytest.mark.parametrize('members, options, flag, expected_output', [
|
||||
# display flag
|
||||
(mock_data, CustomOptions().display_flag(), "device",
|
||||
['\nRandomNestedKey1: RandomNestedValue1.1', '\nRandomNestedKey1: RandomNestedValue1.2']),
|
||||
(mock_data, CustomOptions().display_flag(), "config",
|
||||
['\nRandomNestedKey1: RandomNestedValue1.1', '\nRandomNestedKey1: RandomNestedValue1.2']),
|
||||
# no flag
|
||||
([mock_data[1]], CustomOptions().no_flag(), "device",
|
||||
['\nLocation: PROC 2 DIMM 12\nSizeMiB: None']),
|
||||
([mock_data[0]], CustomOptions().no_flag(), "config",
|
||||
['\nLocation: PROC 1 DIMM 1\nCapacity: 123456'])
|
||||
])
|
||||
@pytest.mark.skip(reason="temporarily remove display flag")
|
||||
def test_generate_display_output_pass(self, members, options, flag, expected_output,
|
||||
monkeypatch):
|
||||
"""
|
||||
Tests for generate_display_output() with valid input
|
||||
:param members: list of members returned as a result of GET request
|
||||
:param options: command options
|
||||
:param flag: name of flag
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
monkeypatch.setattr(ShowPmemCommand, "get_default_attributes",
|
||||
self.custom_options_obj.get_default)
|
||||
pmem_command = ShowPmemCommand.ShowPmemCommand(RdmcCommandBase)
|
||||
result = pmem_command.generate_display_output(members, options, flag,
|
||||
MockMappingTable.memory)
|
||||
assert result == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('members, options, flag, expected_output', [
|
||||
([mock_data[0]], CustomOptions().wrong_display_flag(), "device",
|
||||
["\nNo match found for 'aBc'\nNo match found for 'xYz'"]),
|
||||
([mock_data[1]], CustomOptions().wrong_display_flag(), "config",
|
||||
["\nNo match found for 'aBc'\nNo match found for 'xYz'"]),
|
||||
(mock_data, CustomOptions().wrong_display_flag(), "config",
|
||||
["\nNo match found for 'aBc'\nNo match found for 'xYz'",
|
||||
"\nNo match found for 'aBc'\nNo match found for 'xYz'"]),
|
||||
])
|
||||
@pytest.mark.skip(reason="temporarily remove display flag")
|
||||
def test_generate_display_output_fail(members, options, flag, expected_output):
|
||||
"""
|
||||
Tests for generate_display_output() with invalid input
|
||||
:param members: list of members returned as a result of GET request
|
||||
:param options: command options
|
||||
:param flag: name of flag
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
pmem_command = ShowPmemCommand.ShowPmemCommand(RdmcCommandBase)
|
||||
result = pmem_command.generate_display_output(members, options, flag,
|
||||
MockMappingTable.memory)
|
||||
assert result == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize('customparser, expected_output', [
|
||||
('', None)
|
||||
])
|
||||
def test_define_arguments(customparser, expected_output):
|
||||
"""
|
||||
Branch Test for definearguments() when parser is not customparser
|
||||
:param customparser: command line input
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
pmem_command = ShowPmemCommand.ShowPmemCommand(RdmcCommandBase)
|
||||
result = pmem_command.definearguments(customparser)
|
||||
assert result == expected_output
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("flag, expected_output", [
|
||||
("device", ShowPmemCommand.DefaultAttributes.device.value),
|
||||
("config", ShowPmemCommand.DefaultAttributes.config.value),
|
||||
("summary", None),
|
||||
("abc", None)])
|
||||
def test_get_default_attributes(flag, expected_output):
|
||||
"""
|
||||
Test for get_default_attributes()
|
||||
:param flag: name of flag
|
||||
:param expected_output: expected output of the test
|
||||
"""
|
||||
result = ShowPmemCommand.get_default_attributes(flag)
|
||||
assert result == expected_output
|
||||
|
||||
|
||||
class MockOptions(object):
|
||||
"""
|
||||
Class containing mock options for validation tests
|
||||
"""
|
||||
device = False
|
||||
config = False
|
||||
summary = False
|
||||
logical = False
|
||||
dimm = None
|
||||
|
||||
@staticmethod
|
||||
def set_options(device, config, logical, summary, dimm):
|
||||
"""
|
||||
Setter method for Mock options
|
||||
"""
|
||||
MockOptions.device = device
|
||||
MockOptions.config = config
|
||||
MockOptions.logical = logical
|
||||
MockOptions.summary = summary
|
||||
MockOptions.dimm = dimm
|
||||
|
||||
|
||||
class TestValidation(object):
|
||||
"""
|
||||
Class containing validation tests
|
||||
"""
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("device, config, logical, summary, dimm, expected_result", [
|
||||
(False, False, False, False, None, None),
|
||||
(False, False, False, False, ["1@1", "2@10"], None),
|
||||
(True, False, False, False, None, None),
|
||||
(True, False, False, False, ["3@12", "4@8"], None),
|
||||
(False, True, False, False, None, None),
|
||||
(True, False, False, False, ["4@4", "3@3"], None),
|
||||
(True, False, False, False, ["9@19"], None),
|
||||
(False, False, True, False, None, None),
|
||||
(False, False, False, True, None, None)
|
||||
])
|
||||
def test_validate_show_pmem_options_pass(device, config, logical,
|
||||
summary, dimm, expected_result):
|
||||
"""
|
||||
Tests for 'validate_options' with valid options
|
||||
"""
|
||||
MockOptions.set_options(device, config, logical, summary, dimm)
|
||||
pmem_command = ShowPmemCommand.ShowPmemCommand(RdmcCommandBase)
|
||||
result = pmem_command.validate_show_pmem_options(MockOptions)
|
||||
assert result == expected_result
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("device, config, logical, summary, dimm", [
|
||||
(True, True, True, True, None),
|
||||
(True, True, True, False, None),
|
||||
(True, True, False, True, None),
|
||||
(True, False, True, True, None),
|
||||
(False, True, True, True, None),
|
||||
(True, True, False, False, None),
|
||||
(True, False, True, False, None),
|
||||
(True, False, False, True, None),
|
||||
(False, False, True, True, None),
|
||||
(False, True, False, True, None),
|
||||
(False, True, True, False, None),
|
||||
(True, False, False, False, ["0@0"]),
|
||||
(True, False, False, False, ["0@8"]),
|
||||
(True, False, False, False, ["4@0"]),
|
||||
(True, False, False, False, ["4@20"]),
|
||||
(True, False, False, False, ["10@20"]),
|
||||
(True, False, False, False, ["10@2"]),
|
||||
(True, False, False, False, ["3)12", "438"]),
|
||||
(True, False, False, False, ["4#4", "3!3"]),
|
||||
(True, False, False, False, ["3)12", "438"]),
|
||||
(False, False, False, False, ["1@1", "2@=10"]),
|
||||
(False, False, True, False, ["3@12", "4@8"]),
|
||||
(False, False, False, True, ["4@4", "3@3"])
|
||||
])
|
||||
def test_validate_show_pmem_options_fail(device, config, logical, summary, dimm):
|
||||
"""
|
||||
Tests for 'validate_options' with invalid options
|
||||
"""
|
||||
MockOptions.set_options(device, config, logical, summary, dimm)
|
||||
pmem_command = ShowPmemCommand.ShowPmemCommand(RdmcCommandBase)
|
||||
with pytest.raises(InvalidCommandLineError):
|
||||
pmem_command.validate_show_pmem_options(MockOptions)
|
||||
|
||||
@staticmethod
|
||||
@pytest.mark.parametrize("device, config, logical, summary, dimm", [
|
||||
(False, False, False, False, None),
|
||||
(False, False, False, False, ["1@2"]),
|
||||
(True, False, False, False, None),
|
||||
(True, False, False, False, ["4#4", "3!3"]),
|
||||
(False, True, False, False, None),
|
||||
(False, True, False, False, ["4@4", "3@3"]),
|
||||
(False, False, True, False, None),
|
||||
(False, False, True, False, ["1@1", "2@=10"]),
|
||||
(False, False, False, True, None),
|
||||
(False, False, False, True, ["1@1", "2@10"])
|
||||
])
|
||||
def test_validate_args(device, config, logical, summary, dimm):
|
||||
"""
|
||||
Tests for 'validate_args'
|
||||
"""
|
||||
MockOptions.set_options(device, config, logical, summary, dimm)
|
||||
pmem_command = ShowPmemCommand.ShowPmemCommand(RdmcCommandBase)
|
||||
with pytest.raises(InvalidCommandLineError):
|
||||
pmem_command.validate_args(MockOptions)
|
||||
Reference in new issue
Block a user