| 1 |
# Copyright (c) 2022, Masayoshi Mizuma <[email protected]> |
| 2 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 3 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
import json |
| 8 |
from unittest.mock import patch |
| 9 |
|
| 10 |
import pytest |
| 11 |
|
| 12 |
pytest.importorskip("xmltodict") |
| 13 |
|
| 14 |
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ( |
| 15 |
AnsibleExitJson, |
| 16 |
AnsibleFailJson, |
| 17 |
ModuleTestCase, |
| 18 |
set_module_args, |
| 19 |
) |
| 20 |
|
| 21 |
from ansible_collections.community.general.plugins.modules import pmem as pmem_module |
| 22 |
|
| 23 |
# goal_plain: the mock return value of pmem_run_command with: |
| 24 |
# impctl create -goal MemoryMode=70 Reserved=20 PersistentMemoryType=AppDirect |
| 25 |
goal_plain = """The following configuration will be applied: |
| 26 |
SocketID | DimmID | MemorySize | AppDirect1Size | AppDirect2Size |
| 27 |
================================================================== |
| 28 |
0x0000 | 0x0001 | 88.000 GiB | 12.000 GiB | 0.000 GiB |
| 29 |
0x0000 | 0x0011 | 88.000 GiB | 12.000 GiB | 0.000 GiB |
| 30 |
0x0001 | 0x1001 | 88.000 GiB | 12.000 GiB | 0.000 GiB |
| 31 |
0x0001 | 0x1011 | 88.000 GiB | 12.000 GiB | 0.000 GiB |
| 32 |
Do you want to continue? [y/n] Error: Invalid data input.""" |
| 33 |
|
| 34 |
# goal_plain_sk0: the mock return value of pmem_run_command with: |
| 35 |
# ipmctl create -goal -socket 0 MemoryMode=70 Reserved=20 PersistentMemoryType=AppDirect |
| 36 |
goal_plain_sk0 = """The following configuration will be applied: |
| 37 |
SocketID | DimmID | MemorySize | AppDirect1Size | AppDirect2Size |
| 38 |
================================================================== |
| 39 |
0x0000 | 0x0001 | 88.000 GiB | 12.000 GiB | 0.000 GiB |
| 40 |
0x0000 | 0x0011 | 88.000 GiB | 12.000 GiB | 0.000 GiB |
| 41 |
Do you want to continue? [y/n] Error: Invalid data input.""" |
| 42 |
|
| 43 |
# goal_plain_sk1: the mock return value of pmem_run_command with: |
| 44 |
# ipmctl create -goal -socket 1 MemoryMode=70 Reserved=20 PersistentMemoryType=AppDirect |
| 45 |
goal_plain_sk1 = """The following configuration will be applied: |
| 46 |
SocketID | DimmID | MemorySize | AppDirect1Size | AppDirect2Size |
| 47 |
================================================================== |
| 48 |
0x0001 | 0x1001 | 88.000 GiB | 12.000 GiB | 0.000 GiB |
| 49 |
0x0001 | 0x1011 | 88.000 GiB | 12.000 GiB | 0.000 GiB |
| 50 |
Do you want to continue? [y/n] Error: Invalid data input.""" |
| 51 |
|
| 52 |
# goal: the mock return value of pmem_run_command with: |
| 53 |
# ipmctl create -u B -o nvmxml -force -goal -socket 0 MemoryMode=70 Reserved=20 PersistentMemoryType=AppDirect |
| 54 |
goal = """<?xml version="1.0"?> |
| 55 |
<ConfigGoalList> |
| 56 |
<ConfigGoal> |
| 57 |
<SocketID>0x0000</SocketID> |
| 58 |
<DimmID>0x0001</DimmID> |
| 59 |
<MemorySize>94489280512 B</MemorySize> |
| 60 |
<AppDirect1Size>12884901888 B</AppDirect1Size> |
| 61 |
<AppDirect2Size>0 B</AppDirect2Size> |
| 62 |
</ConfigGoal> |
| 63 |
<ConfigGoal> |
| 64 |
<SocketID>0x0000</SocketID> |
| 65 |
<DimmID>0x0011</DimmID> |
| 66 |
<MemorySize>94489280512 B</MemorySize> |
| 67 |
<AppDirect1Size>12884901888 B</AppDirect1Size> |
| 68 |
<AppDirect2Size>0 B</AppDirect2Size> |
| 69 |
</ConfigGoal> |
| 70 |
</ConfigGoalList>""" |
| 71 |
|
| 72 |
# goal_sk0: the mock return value of pmem_run_command with: |
| 73 |
# ipmctl create -u B -o nvmxml -force -goal -socket 0 MemoryMode=70 Reserved=20 PersistentMemoryType=AppDirect |
| 74 |
goal_sk0 = """<?xml version="1.0"?> |
| 75 |
<ConfigGoalList> |
| 76 |
<ConfigGoal> |
| 77 |
<SocketID>0x0000</SocketID> |
| 78 |
<DimmID>0x0001</DimmID> |
| 79 |
<MemorySize>94489280512 B</MemorySize> |
| 80 |
<AppDirect1Size>12884901888 B</AppDirect1Size> |
| 81 |
<AppDirect2Size>0 B</AppDirect2Size> |
| 82 |
</ConfigGoal> |
| 83 |
<ConfigGoal> |
| 84 |
<SocketID>0x0001</SocketID> |
| 85 |
<DimmID>0x0011</DimmID> |
| 86 |
<MemorySize>94489280512 B</MemorySize> |
| 87 |
<AppDirect1Size>12884901888 B</AppDirect1Size> |
| 88 |
<AppDirect2Size>0 B</AppDirect2Size> |
| 89 |
</ConfigGoal> |
| 90 |
</ConfigGoalList>""" |
| 91 |
|
| 92 |
# goal_sk1: the mock return value of pmem_run_command with: |
| 93 |
# ipmctl create -u B -o nvmxml -force -goal -socket 1 MemoryMode=70 Reserved=20 PersistentMemoryType=AppDirect |
| 94 |
goal_sk1 = """<?xml version="1.0"?> |
| 95 |
<ConfigGoalList> |
| 96 |
<ConfigGoal> |
| 97 |
<SocketID>0x0001</SocketID> |
| 98 |
<DimmID>0x1001</DimmID> |
| 99 |
<MemorySize>94489280512 B</MemorySize> |
| 100 |
<AppDirect1Size>12884901888 B</AppDirect1Size> |
| 101 |
<AppDirect2Size>0 B</AppDirect2Size> |
| 102 |
</ConfigGoal> |
| 103 |
<ConfigGoal> |
| 104 |
<SocketID>0x0001</SocketID> |
| 105 |
<DimmID>0x1011</DimmID> |
| 106 |
<MemorySize>94489280512 B</MemorySize> |
| 107 |
<AppDirect1Size>12884901888 B</AppDirect1Size> |
| 108 |
<AppDirect2Size>0 B</AppDirect2Size> |
| 109 |
</ConfigGoal> |
| 110 |
</ConfigGoalList>""" |
| 111 |
|
| 112 |
# dimmlist: the mock return value of pmem_run_command with: |
| 113 |
# ipmctl show -d Capacity -u B -o nvmxml -dimm |
| 114 |
dimmlist = """<?xml version="1.0"?> |
| 115 |
<DimmList> |
| 116 |
<Dimm> |
| 117 |
<DimmID>0x0001</DimmID> |
| 118 |
<Capacity>135744782336 B</Capacity> |
| 119 |
</Dimm> |
| 120 |
<Dimm> <DimmID>0x0011</DimmID> |
| 121 |
<Capacity>135744782336 B</Capacity> |
| 122 |
</Dimm> |
| 123 |
<Dimm> |
| 124 |
<DimmID>0x1001</DimmID> |
| 125 |
<Capacity>135744782336 B</Capacity> |
| 126 |
</Dimm> |
| 127 |
<Dimm> <DimmID>0x1011</DimmID> |
| 128 |
<Capacity>135744782336 B</Capacity> |
| 129 |
</Dimm> |
| 130 |
</DimmList>""" |
| 131 |
|
| 132 |
# dimmlist_sk0: the mock return value of pmem_run_command with: |
| 133 |
# ipmctl show -d Capacity -u B -o nvmxml -dimm -socket 0 |
| 134 |
dimmlist_sk0 = """<?xml version="1.0"?> |
| 135 |
<DimmList> |
| 136 |
<Dimm> |
| 137 |
<DimmID>0x0001</DimmID> |
| 138 |
<Capacity>135744782336 B</Capacity> |
| 139 |
</Dimm> |
| 140 |
<Dimm> <DimmID>0x0011</DimmID> |
| 141 |
<Capacity>135744782336 B</Capacity> |
| 142 |
</Dimm> |
| 143 |
</DimmList>""" |
| 144 |
|
| 145 |
# dimmlist_sk1: the mock return value of pmem_run_command with: |
| 146 |
# ipmctl show -d Capacity -u B -o nvmxml -dimm -socket 1 |
| 147 |
dimmlist_sk1 = """<?xml version="1.0"?> |
| 148 |
<DimmList> |
| 149 |
<Dimm> |
| 150 |
<DimmID>0x1001</DimmID> |
| 151 |
<Capacity>135744782336 B</Capacity> |
| 152 |
</Dimm> |
| 153 |
<Dimm> <DimmID>0x1011</DimmID> |
| 154 |
<Capacity>135744782336 B</Capacity> |
| 155 |
</Dimm> |
| 156 |
</DimmList>""" |
| 157 |
|
| 158 |
# show_skt: the mock return value of pmem_run_command with: |
| 159 |
# ipmctl show -o nvmxml -socket |
| 160 |
show_skt = """<?xml version="1.0"?> |
| 161 |
<SocketList> |
| 162 |
<Socket> |
| 163 |
<SocketID>0x0000</SocketID> |
| 164 |
<MappedMemoryLimit>1024.000 GiB</MappedMemoryLimit> |
| 165 |
<TotalMappedMemory>400.000 GiB</TotalMappedMemory> |
| 166 |
</Socket> |
| 167 |
<Socket> |
| 168 |
<SocketID>0x0001</SocketID> |
| 169 |
<MappedMemoryLimit>1024.000 GiB</MappedMemoryLimit> |
| 170 |
<TotalMappedMemory>400.000 GiB</TotalMappedMemory> |
| 171 |
</Socket> |
| 172 |
</SocketList>""" |
| 173 |
|
| 174 |
# ndctl_region: the mock return value of pmem_run_command with: |
| 175 |
# ndctl list -R |
| 176 |
ndctl_region = """[ |
| 177 |
{ |
| 178 |
"dev":"region1", |
| 179 |
"size":51539607552, |
| 180 |
"align":16777216, |
| 181 |
"available_size":50465865728, |
| 182 |
"max_available_extent":50465865728, |
| 183 |
"type":"pmem", |
| 184 |
"iset_id":4694373484956518536, |
| 185 |
"persistence_domain":"memory_controller" |
| 186 |
}, |
| 187 |
{ |
| 188 |
"dev":"region0", |
| 189 |
"size":51539607552, |
| 190 |
"align":16777216, |
| 191 |
"available_size":51539607552, |
| 192 |
"max_available_extent":51539607552, |
| 193 |
"type":"pmem", |
| 194 |
"iset_id":4588538894081362056, |
| 195 |
"persistence_domain":"memory_controller" |
| 196 |
} |
| 197 |
]""" |
| 198 |
|
| 199 |
# ndctl_region_empty: the mock return value of pmem_run_command with: |
| 200 |
# ndctl list -R |
| 201 |
ndctl_region_empty = "" |
| 202 |
|
| 203 |
# ndctl_without_size: the mock return value of pmem_run_command with: |
| 204 |
# ndctl create-namespace -t pmem -m sector |
| 205 |
ndctl_create_without_size = """{ |
| 206 |
"dev":"namespace1.0", |
| 207 |
"mode":"sector", |
| 208 |
"size":"47.95 GiB (51.49 GB)", |
| 209 |
"uuid":"1aca23a5-941c-4f4a-9d88-e531f0b5a27e", |
| 210 |
"sector_size":4096, |
| 211 |
"blockdev":"pmem1s" |
| 212 |
}""" |
| 213 |
|
| 214 |
# ndctl_list_N: the mock return value of pmem_run_command with: |
| 215 |
# ndctl list -N |
| 216 |
ndctl_list_N = """[ |
| 217 |
{ |
| 218 |
"dev":"namespace1.0", |
| 219 |
"mode":"sector", |
| 220 |
"size":51488243712, |
| 221 |
"uuid":"1aca23a5-941c-4f4a-9d88-e531f0b5a27e", |
| 222 |
"sector_size":4096, |
| 223 |
"blockdev":"pmem1s" |
| 224 |
} |
| 225 |
]""" |
| 226 |
|
| 227 |
# ndctl_result_1G: the mock return value of pmem_run_command with: |
| 228 |
# ndctl create-namespace -t pmem -m sector -s 1073741824 |
| 229 |
ndctl_create_1G = """{ |
| 230 |
"dev":"namespace0.0", |
| 231 |
"mode":"sector", |
| 232 |
"size":"1021.97 MiB (1071.62 MB)", |
| 233 |
"uuid":"5ba4e51b-3028-4b06-8495-b6834867a9af", |
| 234 |
"sector_size":4096, |
| 235 |
"blockdev":"pmem0s" |
| 236 |
}""" |
| 237 |
|
| 238 |
# ndctl_result_640M: the mock return value of pmem_run_command with: |
| 239 |
# ndctl create-namespace -t pmem -m raw -s 671088640 |
| 240 |
ndctl_create_640M = """{ |
| 241 |
"dev":"namespace1.0", |
| 242 |
"mode":"raw", |
| 243 |
"size":"640.00 MiB (671.09 MB)", |
| 244 |
"uuid":"5ac1f81d-86e6-4f07-9460-8c4d37027f7a", |
| 245 |
"sector_size":512, |
| 246 |
"blockdev":"pmem1" |
| 247 |
}""" |
| 248 |
|
| 249 |
# ndctl_list_N_tow_namespaces: the mock return value of pmem_run_command with: |
| 250 |
# ndctl list -N |
| 251 |
ndctl_list_N_two_namespaces = """[ |
| 252 |
{ |
| 253 |
"dev":"namespace1.0", |
| 254 |
"mode":"sector", |
| 255 |
"size":1071616000, |
| 256 |
"uuid":"afcf050d-3a8b-4f48-88a5-16d7c40ab2d8", |
| 257 |
"sector_size":4096, |
| 258 |
"blockdev":"pmem1s" |
| 259 |
}, |
| 260 |
{ |
| 261 |
"dev":"namespace1.1", |
| 262 |
"mode":"raw", |
| 263 |
"size":671088640, |
| 264 |
"uuid":"fb704339-729b-4cc7-b260-079f2633d84f", |
| 265 |
"sector_size":512, |
| 266 |
"blockdev":"pmem1.1" |
| 267 |
} |
| 268 |
]""" |
| 269 |
|
| 270 |
|
| 271 |
class TestPmem(ModuleTestCase): |
| 272 |
def setUp(self): |
| 273 |
super().setUp() |
| 274 |
self.module = pmem_module |
| 275 |
|
| 276 |
self.mock_run_command = patch("ansible.module_utils.basic.AnsibleModule.run_command") |
| 277 |
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path") |
| 278 |
|
| 279 |
self.run_command = self.mock_run_command.start() |
| 280 |
self.get_bin_path = self.mock_get_bin_path.start() |
| 281 |
|
| 282 |
self.mock_pmem_is_dcpmm_installed = patch( |
| 283 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_is_dcpmm_installed", |
| 284 |
return_value="", |
| 285 |
) |
| 286 |
self.mock_pmem_init_env = patch( |
| 287 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_init_env", return_value="" |
| 288 |
) |
| 289 |
|
| 290 |
self.pmem_is_dcpmm_installed = self.mock_pmem_is_dcpmm_installed.start() |
| 291 |
self.pmem_init_env = self.mock_pmem_init_env.start() |
| 292 |
|
| 293 |
def tearDown(self): |
| 294 |
super().tearDown() |
| 295 |
self.mock_get_bin_path.stop() |
| 296 |
self.mock_run_command.stop() |
| 297 |
self.mock_pmem_is_dcpmm_installed.stop() |
| 298 |
self.mock_pmem_init_env.stop() |
| 299 |
|
| 300 |
def result_check(self, result, socket, appdirect, memmode, reserved): |
| 301 |
self.assertTrue(result.exception.args[0]["changed"]) |
| 302 |
self.assertTrue(result.exception.args[0]["reboot_required"]) |
| 303 |
|
| 304 |
test_result = result.exception.args[0]["result"] |
| 305 |
|
| 306 |
if socket: |
| 307 |
maxIndex = 1 |
| 308 |
else: |
| 309 |
maxIndex = 0 |
| 310 |
|
| 311 |
for i in range(0, maxIndex): |
| 312 |
self.assertAlmostEqual(test_result[i]["appdirect"], appdirect[i]) |
| 313 |
self.assertAlmostEqual(test_result[i]["memorymode"], memmode[i]) |
| 314 |
self.assertAlmostEqual(test_result[i]["reserved"], reserved[i]) |
| 315 |
if socket: |
| 316 |
self.assertAlmostEqual(test_result[i]["socket"], i) |
| 317 |
|
| 318 |
def result_check_ns(self, result, namespace): |
| 319 |
self.assertTrue(result.exception.args[0]["changed"]) |
| 320 |
self.assertFalse(result.exception.args[0]["reboot_required"]) |
| 321 |
|
| 322 |
test_result = result.exception.args[0]["result"] |
| 323 |
expected = json.loads(namespace) |
| 324 |
|
| 325 |
for i, result in enumerate(test_result): |
| 326 |
self.assertEqual(result["dev"], expected[i]["dev"]) |
| 327 |
self.assertEqual(result["size"], expected[i]["size"]) |
| 328 |
|
| 329 |
def test_fail_when_required_args_missing(self): |
| 330 |
with self.assertRaises(AnsibleFailJson): |
| 331 |
with set_module_args({}): |
| 332 |
pmem_module.main() |
| 333 |
|
| 334 |
def test_fail_when_appdirect_only(self): |
| 335 |
with self.assertRaises(AnsibleFailJson): |
| 336 |
with set_module_args( |
| 337 |
{ |
| 338 |
"appdirect": 10, |
| 339 |
} |
| 340 |
): |
| 341 |
pmem_module.main() |
| 342 |
|
| 343 |
def test_fail_when_MemosyMode_only(self): |
| 344 |
with self.assertRaises(AnsibleFailJson): |
| 345 |
with set_module_args( |
| 346 |
{ |
| 347 |
"memorymode": 70, |
| 348 |
} |
| 349 |
): |
| 350 |
pmem_module.main() |
| 351 |
|
| 352 |
def test_fail_when_reserved_only(self): |
| 353 |
with self.assertRaises(AnsibleFailJson): |
| 354 |
with set_module_args( |
| 355 |
{ |
| 356 |
"reserved": 10, |
| 357 |
} |
| 358 |
): |
| 359 |
pmem_module.main() |
| 360 |
|
| 361 |
def test_fail_when_appdirect_memorymode_reserved_total_not_100(self): |
| 362 |
with self.assertRaises(AnsibleFailJson): |
| 363 |
with set_module_args( |
| 364 |
{ |
| 365 |
"appdirect": 10, |
| 366 |
"memorymode": 70, |
| 367 |
"reserved": 10, |
| 368 |
} |
| 369 |
): |
| 370 |
pmem_module.main() |
| 371 |
|
| 372 |
def test_when_appdirect_memorymode(self): |
| 373 |
with set_module_args( |
| 374 |
{ |
| 375 |
"appdirect": 10, |
| 376 |
"memorymode": 70, |
| 377 |
} |
| 378 |
): |
| 379 |
with patch( |
| 380 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 381 |
side_effect=[goal_plain, goal, dimmlist], |
| 382 |
): |
| 383 |
with self.assertRaises(AnsibleExitJson) as result: |
| 384 |
pmem_module.main() |
| 385 |
self.result_check(result, False, [25769803776], [188978561024], [328230764544]) |
| 386 |
|
| 387 |
def test_when_appdirect_memorymode_reserved(self): |
| 388 |
with set_module_args( |
| 389 |
{ |
| 390 |
"appdirect": 10, |
| 391 |
"memorymode": 70, |
| 392 |
"reserved": 20, |
| 393 |
} |
| 394 |
): |
| 395 |
with patch( |
| 396 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 397 |
side_effect=[goal_plain, goal, dimmlist], |
| 398 |
): |
| 399 |
with self.assertRaises(AnsibleExitJson) as result: |
| 400 |
pmem_module.main() |
| 401 |
self.result_check(result, False, [25769803776], [188978561024], [328230764544]) |
| 402 |
|
| 403 |
def test_when_appdirect_notinterleaved_memorymode_reserved(self): |
| 404 |
with set_module_args( |
| 405 |
{ |
| 406 |
"appdirect": 10, |
| 407 |
"appdirect_interleaved": False, |
| 408 |
"memorymode": 70, |
| 409 |
"reserved": 20, |
| 410 |
} |
| 411 |
): |
| 412 |
with patch( |
| 413 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 414 |
side_effect=[goal_plain, goal, dimmlist], |
| 415 |
): |
| 416 |
with self.assertRaises(AnsibleExitJson) as result: |
| 417 |
pmem_module.main() |
| 418 |
self.result_check(result, False, [25769803776], [188978561024], [328230764544]) |
| 419 |
|
| 420 |
def test_fail_when_socket_id_appdirect(self): |
| 421 |
with self.assertRaises(AnsibleFailJson): |
| 422 |
with set_module_args( |
| 423 |
{ |
| 424 |
"socket": [ |
| 425 |
{ |
| 426 |
"id": 0, |
| 427 |
"appdirect": 10, |
| 428 |
}, |
| 429 |
{ |
| 430 |
"id": 1, |
| 431 |
"appdirect": 10, |
| 432 |
}, |
| 433 |
], |
| 434 |
} |
| 435 |
): |
| 436 |
pmem_module.main() |
| 437 |
|
| 438 |
def test_fail_when_socket0_id_memorymode_socket1_id_appdirect(self): |
| 439 |
with self.assertRaises(AnsibleFailJson): |
| 440 |
with set_module_args( |
| 441 |
{ |
| 442 |
"socket": [ |
| 443 |
{ |
| 444 |
"id": 0, |
| 445 |
" memorymode": 70, |
| 446 |
}, |
| 447 |
{ |
| 448 |
"id": 1, |
| 449 |
"appdirect": 10, |
| 450 |
}, |
| 451 |
], |
| 452 |
} |
| 453 |
): |
| 454 |
pmem_module.main() |
| 455 |
|
| 456 |
def test_fail_when_socket0_without_id(self): |
| 457 |
with self.assertRaises(AnsibleFailJson): |
| 458 |
with set_module_args( |
| 459 |
{ |
| 460 |
"socket": [ |
| 461 |
{ |
| 462 |
"appdirect": 10, |
| 463 |
"memorymode": 70, |
| 464 |
}, |
| 465 |
{ |
| 466 |
"id": 1, |
| 467 |
"appdirect": 10, |
| 468 |
"memorymode": 70, |
| 469 |
}, |
| 470 |
], |
| 471 |
} |
| 472 |
): |
| 473 |
pmem_module.main() |
| 474 |
|
| 475 |
def test_when_socket0_and_1_appdirect_memorymode(self): |
| 476 |
with set_module_args( |
| 477 |
{ |
| 478 |
"socket": [ |
| 479 |
{ |
| 480 |
"id": 0, |
| 481 |
"appdirect": 10, |
| 482 |
"memorymode": 70, |
| 483 |
}, |
| 484 |
{ |
| 485 |
"id": 1, |
| 486 |
"appdirect": 10, |
| 487 |
"memorymode": 70, |
| 488 |
}, |
| 489 |
], |
| 490 |
} |
| 491 |
): |
| 492 |
with patch( |
| 493 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 494 |
side_effect=[show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1], |
| 495 |
): |
| 496 |
with self.assertRaises(AnsibleExitJson) as result: |
| 497 |
pmem_module.main() |
| 498 |
self.result_check( |
| 499 |
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272] |
| 500 |
) |
| 501 |
|
| 502 |
def test_when_socket0_and_1_appdirect_memorymode_reserved(self): |
| 503 |
with set_module_args( |
| 504 |
{ |
| 505 |
"socket": [ |
| 506 |
{ |
| 507 |
"id": 0, |
| 508 |
"appdirect": 10, |
| 509 |
"memorymode": 70, |
| 510 |
"reserved": 20, |
| 511 |
}, |
| 512 |
{ |
| 513 |
"id": 1, |
| 514 |
"appdirect": 10, |
| 515 |
"memorymode": 70, |
| 516 |
"reserved": 20, |
| 517 |
}, |
| 518 |
], |
| 519 |
} |
| 520 |
): |
| 521 |
with patch( |
| 522 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 523 |
side_effect=[show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1], |
| 524 |
): |
| 525 |
with self.assertRaises(AnsibleExitJson) as result: |
| 526 |
pmem_module.main() |
| 527 |
self.result_check( |
| 528 |
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272] |
| 529 |
) |
| 530 |
|
| 531 |
def test_when_socket0_appdirect_notinterleaved_memorymode_reserved_socket1_appdirect_memorymode_reserved(self): |
| 532 |
with set_module_args( |
| 533 |
{ |
| 534 |
"socket": [ |
| 535 |
{ |
| 536 |
"id": 0, |
| 537 |
"appdirect": 10, |
| 538 |
"appdirect_interleaved": False, |
| 539 |
"memorymode": 70, |
| 540 |
"reserved": 20, |
| 541 |
}, |
| 542 |
{ |
| 543 |
"id": 1, |
| 544 |
"appdirect": 10, |
| 545 |
"memorymode": 70, |
| 546 |
"reserved": 20, |
| 547 |
}, |
| 548 |
], |
| 549 |
} |
| 550 |
): |
| 551 |
with patch( |
| 552 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 553 |
side_effect=[show_skt, goal_plain_sk0, goal_sk0, dimmlist_sk0, goal_plain_sk1, goal_sk1, dimmlist_sk1], |
| 554 |
): |
| 555 |
with self.assertRaises(AnsibleExitJson) as result: |
| 556 |
pmem_module.main() |
| 557 |
self.result_check( |
| 558 |
result, True, [12884901888, 12884901888], [94489280512, 94489280512], [164115382272, 164115382272] |
| 559 |
) |
| 560 |
|
| 561 |
def test_fail_when_namespace_without_mode(self): |
| 562 |
with self.assertRaises(AnsibleFailJson): |
| 563 |
with set_module_args( |
| 564 |
{ |
| 565 |
"namespace": [ |
| 566 |
{ |
| 567 |
"size": "1GB", |
| 568 |
"type": "pmem", |
| 569 |
}, |
| 570 |
{ |
| 571 |
"size": "2GB", |
| 572 |
"type": "blk", |
| 573 |
}, |
| 574 |
], |
| 575 |
} |
| 576 |
): |
| 577 |
pmem_module.main() |
| 578 |
|
| 579 |
def test_fail_when_region_is_empty(self): |
| 580 |
with self.assertRaises(AnsibleFailJson): |
| 581 |
with set_module_args( |
| 582 |
{ |
| 583 |
"namespace": [ |
| 584 |
{ |
| 585 |
"size": "1GB", |
| 586 |
"type": "pmem", |
| 587 |
"mode": "sector", |
| 588 |
}, |
| 589 |
], |
| 590 |
} |
| 591 |
): |
| 592 |
with patch( |
| 593 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 594 |
side_effect=[ndctl_region_empty], |
| 595 |
): |
| 596 |
pmem_module.main() |
| 597 |
|
| 598 |
def test_fail_when_namespace_invalid_size(self): |
| 599 |
with self.assertRaises(AnsibleFailJson): |
| 600 |
with set_module_args( |
| 601 |
{ |
| 602 |
"namespace": [ |
| 603 |
{ |
| 604 |
"size": "1XXX", |
| 605 |
"type": "pmem", |
| 606 |
"mode": "sector", |
| 607 |
}, |
| 608 |
], |
| 609 |
} |
| 610 |
): |
| 611 |
with patch( |
| 612 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 613 |
side_effect=[ndctl_region], |
| 614 |
): |
| 615 |
pmem_module.main() |
| 616 |
|
| 617 |
def test_fail_when_size_is_invalid_alignment(self): |
| 618 |
with self.assertRaises(AnsibleFailJson): |
| 619 |
with set_module_args( |
| 620 |
{ |
| 621 |
"namespace": [ |
| 622 |
{"size": "400MB", "type": "pmem", "mode": "sector"}, |
| 623 |
{"size": "500MB", "type": "pmem", "mode": "sector"}, |
| 624 |
], |
| 625 |
} |
| 626 |
): |
| 627 |
with patch( |
| 628 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 629 |
side_effect=[ndctl_region], |
| 630 |
): |
| 631 |
pmem_module.main() |
| 632 |
|
| 633 |
def test_fail_when_blk_is_unsupported_type(self): |
| 634 |
with self.assertRaises(AnsibleFailJson): |
| 635 |
with set_module_args( |
| 636 |
{ |
| 637 |
"namespace": [ |
| 638 |
{"size": "4GB", "type": "pmem", "mode": "sector"}, |
| 639 |
{"size": "5GB", "type": "blk", "mode": "sector"}, |
| 640 |
], |
| 641 |
} |
| 642 |
): |
| 643 |
with patch( |
| 644 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 645 |
side_effect=[ndctl_region], |
| 646 |
): |
| 647 |
pmem_module.main() |
| 648 |
|
| 649 |
def test_fail_when_size_isnot_set_to_multiple_namespaces(self): |
| 650 |
with self.assertRaises(AnsibleFailJson): |
| 651 |
with set_module_args( |
| 652 |
{ |
| 653 |
"namespace": [ |
| 654 |
{"type": "pmem", "mode": "sector"}, |
| 655 |
{"size": "500GB", "type": "blk", "mode": "sector"}, |
| 656 |
], |
| 657 |
} |
| 658 |
): |
| 659 |
with patch( |
| 660 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 661 |
side_effect=[ndctl_region], |
| 662 |
): |
| 663 |
pmem_module.main() |
| 664 |
|
| 665 |
def test_fail_when_size_of_namespace_over_available(self): |
| 666 |
with self.assertRaises(AnsibleFailJson): |
| 667 |
with set_module_args( |
| 668 |
{ |
| 669 |
"namespace": [ |
| 670 |
{"size": "400GB", "type": "pmem", "mode": "sector"}, |
| 671 |
{"size": "500GB", "type": "pmem", "mode": "sector"}, |
| 672 |
], |
| 673 |
} |
| 674 |
): |
| 675 |
with patch( |
| 676 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 677 |
side_effect=[ndctl_region], |
| 678 |
): |
| 679 |
pmem_module.main() |
| 680 |
|
| 681 |
def test_when_namespace0_without_size(self): |
| 682 |
with set_module_args( |
| 683 |
{ |
| 684 |
"namespace": [ |
| 685 |
{"type": "pmem", "mode": "sector"}, |
| 686 |
], |
| 687 |
} |
| 688 |
): |
| 689 |
with patch( |
| 690 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 691 |
side_effect=[ndctl_region, ndctl_create_without_size, ndctl_list_N], |
| 692 |
): |
| 693 |
with self.assertRaises(AnsibleExitJson) as result: |
| 694 |
pmem_module.main() |
| 695 |
self.result_check_ns(result, ndctl_list_N) |
| 696 |
|
| 697 |
def test_when_namespace0_with_namespace_append(self): |
| 698 |
with set_module_args( |
| 699 |
{ |
| 700 |
"namespace": [ |
| 701 |
{"size": "640MB", "type": "pmem", "mode": "raw"}, |
| 702 |
], |
| 703 |
"namespace_append": True, |
| 704 |
} |
| 705 |
): |
| 706 |
with patch( |
| 707 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 708 |
side_effect=[ndctl_region, ndctl_create_640M, ndctl_list_N_two_namespaces], |
| 709 |
): |
| 710 |
with self.assertRaises(AnsibleExitJson) as result: |
| 711 |
pmem_module.main() |
| 712 |
self.result_check_ns(result, ndctl_list_N_two_namespaces) |
| 713 |
|
| 714 |
def test_when_namespace0_1GiB_pmem_sector_namespace1_640MiB_pmem_raw(self): |
| 715 |
with set_module_args( |
| 716 |
{ |
| 717 |
"namespace": [ |
| 718 |
{"size": "1GB", "type": "pmem", "mode": "sector"}, |
| 719 |
{ |
| 720 |
"size": "640MB", |
| 721 |
"type": "pmem", |
| 722 |
"mode": "raw", |
| 723 |
}, |
| 724 |
], |
| 725 |
} |
| 726 |
): |
| 727 |
with patch( |
| 728 |
"ansible_collections.community.general.plugins.modules.pmem.PersistentMemory.pmem_run_command", |
| 729 |
side_effect=[ndctl_region, ndctl_create_1G, ndctl_create_640M, ndctl_list_N_two_namespaces], |
| 730 |
): |
| 731 |
with self.assertRaises(AnsibleExitJson) as result: |
| 732 |
pmem_module.main() |
| 733 |
self.result_check_ns(result, ndctl_list_N_two_namespaces) |