1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
|
# Copyright 2014, 2015 IBM Corp.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
import uuid
import mock
import testtools
import pypowervm.tests.test_fixtures as fx
from pypowervm.tests.test_utils import pvmhttp
import pypowervm.tests.test_utils.test_wrapper_abc as twrap
import pypowervm.utils.uuid as pvm_uuid
import pypowervm.wrappers.base_partition as bp
import pypowervm.wrappers.logical_partition as lpar
LPAR_HTTPRESP_FILE = "lpar.txt"
IBMI_HTTPRESP_FILE = "lpar_ibmi.txt"
MC_HTTPRESP_FILE = "managementconsole.txt"
DEDICATED_LPAR_NAME = 'z3-9-5-126-168-00000002'
SHARED_LPAR_NAME = 'z3-9-5-126-127-00000001'
EXPECTED_OPERATING_SYSTEM_VER = 'Linux/Red Hat 2.6.32-358.el6.ppc64 6.4'
EXPECTED_ASSOC_SYSTEM_UUID = 'a168a3ec-bb3e-3ead-86c1-7d98b9d50239'
class TestLogicalPartition(testtools.TestCase):
_skip_setup = False
_shared_wrapper = None
_dedicated_wrapper = None
_bad_wrapper = None
_shared_entry = None
_dedicated_entry = None
def setUp(self):
super(TestLogicalPartition, self).setUp()
self.adptfx = self.useFixture(fx.AdapterFx(traits=fx.LocalPVMTraits))
self.adpt = self.adptfx.adpt
self.TC = TestLogicalPartition
lpar_http = pvmhttp.load_pvm_resp(LPAR_HTTPRESP_FILE,
adapter=self.adpt)
self.assertIsNotNone(lpar_http,
"Could not load %s " %
LPAR_HTTPRESP_FILE)
entries = lpar_http.response.feed.findentries(
bp._BP_NAME, SHARED_LPAR_NAME)
self.assertIsNotNone(entries,
"Could not find %s in %s" %
(SHARED_LPAR_NAME, LPAR_HTTPRESP_FILE))
self.TC._shared_entry = entries[0]
entries = lpar_http.response.feed.findentries(
bp._BP_NAME, DEDICATED_LPAR_NAME)
self.assertIsNotNone(entries,
"Could not find %s in %s" %
(DEDICATED_LPAR_NAME, LPAR_HTTPRESP_FILE))
self.TC._dedicated_entry = entries[0]
TestLogicalPartition._shared_wrapper = lpar.LPAR.wrap(
self.TC._shared_entry)
TestLogicalPartition._dedicated_wrapper = lpar.LPAR.wrap(
self.TC._dedicated_entry)
mc_http = pvmhttp.load_pvm_resp(MC_HTTPRESP_FILE, adapter=self.adpt)
self.assertIsNotNone(mc_http,
"Could not load %s" %
MC_HTTPRESP_FILE)
# Create a bad wrapper to use when retrieving properties which don't
# exist
TestLogicalPartition._bad_wrapper = lpar.LPAR.wrap(
mc_http.response.feed.entries[0])
TestLogicalPartition._skip_setup = True
def verify_equal(self, method_name, returned_value, expected_value):
if returned_value is not None and expected_value is not None:
returned_type = type(returned_value)
expected_type = type(expected_value)
self.assertEqual(returned_type, expected_type,
"%s: type mismatch. "
"Returned %s(%s). Expected %s(%s)" %
(method_name,
returned_value, returned_type,
expected_value, expected_type))
self.assertEqual(returned_value, expected_value,
"%s returned %s instead of %s"
% (method_name, returned_value, expected_value))
@staticmethod
def _get_nested_prop(wrapper, prop_path):
value = None
for partial in prop_path.split('.'):
value = wrapper.__getattribute__(partial)
if callable(value):
value = value()
wrapper = value
return value
def call_simple_getter(self,
method_name,
expected_value,
expected_bad_value,
use_dedicated=False):
# Use __getattribute__ to dynamically call the method
if use_dedicated:
wrapper = TestLogicalPartition._dedicated_wrapper
else:
wrapper = TestLogicalPartition._shared_wrapper
value = self._get_nested_prop(wrapper, method_name)
self.verify_equal(method_name, value, expected_value)
bad_value = self._get_nested_prop(TestLogicalPartition._bad_wrapper,
method_name)
self.verify_equal(method_name, bad_value, expected_bad_value)
def test_get_val_str(self):
expected_value = SHARED_LPAR_NAME
value = TestLogicalPartition._shared_wrapper._get_val_str(
bp._BP_NAME)
self.verify_equal("_get_val_str", value, expected_value)
expected_value = None
value = TestLogicalPartition._shared_wrapper._get_val_str(
'BogusName')
self.verify_equal(
"_get_val_str for BogusName ", value, expected_value)
def test_get_state(self):
self.call_simple_getter("state", bp.LPARState.NOT_ACTIVATED, None)
self._shared_wrapper.set_parm_value(bp._BP_STATE, bp.LPARState.RUNNING)
self.call_simple_getter("state", bp.LPARState.RUNNING, None)
def test_get_name(self):
self.call_simple_getter("name", SHARED_LPAR_NAME, None)
def test_get_id(self):
self.call_simple_getter("id", 9, None)
def test_get_ref_code(self):
self.call_simple_getter("ref_code", "00000000", None)
def test_get_ref_code_full(self):
self.call_simple_getter(
"ref_code_full", ("time_stamp=08/13/2016 23:52:08,refcode=00000000"
",word2=03D00000,fru_call_out_loc_codes=#47-"
"Ubuntu SMP Fri Jun 24 10:09:20 UTC 2016"), None)
def test_uuid(self):
wrapper = self._dedicated_wrapper
self.assertEqual('42DF39A2-3A4A-4748-998F-25B15352E8A7', wrapper.uuid)
# Test set and retrieve
uuid1 = pvm_uuid.convert_uuid_to_pvm(str(uuid.uuid4()))
up_uuid1 = uuid1.upper()
wrapper.set_uuid(uuid1)
self.assertEqual(up_uuid1, wrapper.uuid)
self.assertEqual(up_uuid1, wrapper.partition_uuid)
uuid2 = pvm_uuid.convert_uuid_to_pvm(str(uuid.uuid4()))
wrapper.uuid = uuid2
self.assertEqual(uuid2.upper(), wrapper.uuid)
def test_rmc_state(self):
self.call_simple_getter("rmc_state", bp.RMCState.INACTIVE, None)
self._shared_wrapper.set_parm_value(bp._BP_RMC_STATE,
bp.RMCState.ACTIVE)
self.call_simple_getter("rmc_state", bp.RMCState.ACTIVE, None)
def test_avail_priority(self):
self.call_simple_getter("avail_priority", 127, 0)
self._shared_wrapper.avail_priority = 63
self.call_simple_getter("avail_priority", 63, 0)
def test_profile_sync(self):
self.call_simple_getter("profile_sync", True, False)
self.assertEqual(
self._shared_wrapper._get_val_str(bp._BP_PROFILE_SYNC), "On")
self._shared_wrapper.profile_sync = False
self.call_simple_getter("profile_sync", False, False)
self.assertEqual(
self._shared_wrapper._get_val_str(bp._BP_PROFILE_SYNC), "Off")
self._shared_wrapper.profile_sync = "Off"
self.call_simple_getter("profile_sync", False, False)
def test_get_operating_system(self):
self.call_simple_getter(
"operating_system", EXPECTED_OPERATING_SYSTEM_VER, "Unknown")
@mock.patch('warnings.warn')
def test_rr_off(self, mock_warn):
"""Remote Restart fields when not RR capable."""
self.call_simple_getter("rr_enabled", None, None)
mock_warn.assert_called_with(mock.ANY, DeprecationWarning)
mock_warn.reset_mock()
self._shared_wrapper.rr_enabled = True
mock_warn.assert_called_with(mock.ANY, DeprecationWarning)
mock_warn.reset_mock()
self.call_simple_getter("rr_enabled", None, None)
mock_warn.assert_called_with(mock.ANY, DeprecationWarning)
def test_srr(self):
self.call_simple_getter("srr_enabled", True, False)
self._shared_wrapper.srr_enabled = False
self.call_simple_getter("srr_enabled", False, False)
def test_get_proc_compat_modes(self):
self.call_simple_getter("proc_compat_mode", "POWER6_Plus", None)
self.call_simple_getter("pending_proc_compat_mode", "default", None)
def test_get_type(self):
self.call_simple_getter("env", "AIX/Linux", None)
def test_associated_managed_system_uuid(self):
self.call_simple_getter("assoc_sys_uuid", EXPECTED_ASSOC_SYSTEM_UUID,
None)
def test_is_mgmt_partition(self):
self.call_simple_getter("is_mgmt_partition", True, False)
def test_is_svc_partition(self):
self.call_simple_getter("is_service_partition", False, False)
self._shared_wrapper.is_service_partition = True
self.call_simple_getter("is_service_partition", True, False)
def test_keylock_pos(self):
self.call_simple_getter("keylock_pos", "normal", None)
self._shared_wrapper.keylock_pos = bp.KeylockPos.MANUAL
self.call_simple_getter("keylock_pos", "manual", None)
with testtools.ExpectedException(ValueError):
self._shared_wrapper.keylock_pos = 'frobnicated'
def test_bootmode(self):
self.call_simple_getter("bootmode", "Normal", None)
self._shared_wrapper.bootmode = bp.BootMode.SMS
self.call_simple_getter("bootmode", "System_Management_Services", None)
with testtools.ExpectedException(ValueError):
self._shared_wrapper.bootmode = 'frobnicated'
def test_disable_secure_boot(self):
self.call_simple_getter("disable_secure_boot", False, False)
self._shared_wrapper.disable_secure_boot = True
self.call_simple_getter("disable_secure_boot", True, False)
def test_allow_perf_data_collection(self):
self.call_simple_getter("allow_perf_data_collection", False, False)
self._shared_wrapper.allow_perf_data_collection = True
self.call_simple_getter("allow_perf_data_collection", True, False)
def test_subwrapper_getters(self):
wrap = self._shared_wrapper
self.assertIsInstance(wrap.capabilities, bp.PartitionCapabilities)
self.assertIsInstance(wrap.io_config, bp.PartitionIOConfiguration)
self.assertIsInstance(wrap.mem_config, bp.PartitionMemoryConfiguration)
proc = wrap.proc_config
self.assertIsInstance(proc, bp.PartitionProcessorConfiguration)
self.assertIsInstance(proc.shared_proc_cfg,
bp.SharedProcessorConfiguration)
self.assertIsInstance(proc.dedicated_proc_cfg,
bp.DedicatedProcessorConfiguration)
def test_can_modifies(self):
"""Simple check on the 'can_modify_xxx' methods."""
wrap = TestLogicalPartition._shared_wrapper
wrap.set_parm_value(bp._BP_STATE, bp.LPARState.RUNNING)
wrap.set_parm_value(bp._BP_RMC_STATE, bp.RMCState.ACTIVE)
self.assertTrue(wrap.can_modify_io()[0])
self.assertFalse(wrap.can_modify_mem()[0])
self.assertTrue(wrap.can_modify_proc()[0])
def test_can_modify(self):
"""Detailed testing on the _can_modify method."""
wrap = TestLogicalPartition._shared_wrapper
# By default, it will return True because it is a non-activated LPAR
self.assertTrue(wrap._can_modify(mock.Mock(), '')[0])
# Turn on the LPAR. Should fail due to RMC
wrap.set_parm_value(bp._BP_MGT_PARTITION, False)
wrap.set_parm_value(bp._BP_STATE, bp.LPARState.RUNNING)
val, reason = wrap._can_modify(mock.Mock(), '')
self.assertFalse(val)
self.assertTrue('RMC' in reason)
# Turn on Management Partition
wrap.set_parm_value(bp._BP_MGT_PARTITION, True)
val, reason = wrap._can_modify(mock.Mock(), '')
self.assertTrue(val)
self.assertIsNone(reason)
# Turn on RMC, but have the DLPAR return false.
wrap.set_parm_value(bp._BP_RMC_STATE, bp.RMCState.ACTIVE)
val, reason = wrap._can_modify(None, 'Testing')
self.assertFalse(val)
self.assertTrue('DLPAR' in reason)
self.assertTrue('Testing' in reason)
# Turn on DLPAR
val, reason = wrap._can_modify(mock.Mock(), '')
self.assertTrue(val)
self.assertIsNone(reason)
# Now turn off RMC but change the LPAR type to OS400. Should be OK.
wrap.set_parm_value(bp._BP_RMC_STATE, bp.RMCState.INACTIVE)
wrap.set_parm_value(bp._BP_TYPE, bp.LPARType.OS400)
val, reason = wrap._can_modify(mock.Mock(), '')
self.assertTrue(val)
self.assertIsNone(reason)
def test_can_lpm(self):
"""Tests for the can_lpm method."""
wrap = TestLogicalPartition._shared_wrapper
# By default, it will return True because it is a non-activated LPAR
val, reason = wrap.can_lpm(mock.ANY)
self.assertFalse(val)
self.assertTrue('active' in reason)
# Turn on the LPAR, but make it RMC inactive
wrap.set_parm_value(bp._BP_MGT_PARTITION, False)
wrap.set_parm_value(bp._BP_STATE, bp.LPARState.RUNNING)
wrap.set_parm_value(bp._BP_RMC_STATE, bp.RMCState.INACTIVE)
val, reason = wrap.can_lpm(mock.ANY)
self.assertFalse(val)
self.assertTrue('RMC' in reason)
# Turn on RMC, but by default some of the capabilities are off.
wrap.set_parm_value(bp._BP_RMC_STATE, bp.RMCState.ACTIVE)
val, reason = wrap.can_lpm(mock.ANY)
self.assertFalse(val)
self.assertTrue('DLPAR' in reason)
# Turn on the DLPAR bits. Mem is the only one required as the others
# are on in the root XML.
wrap.capabilities.set_parm_value(bp._CAP_DLPAR_MEM_CAPABLE, True)
val, reason = wrap.can_lpm(mock.ANY)
self.assertTrue(val)
self.assertIsNone(reason)
# Turn on Management Partition
wrap.set_parm_value(bp._BP_MGT_PARTITION, True)
val, reason = wrap.can_lpm(mock.ANY)
self.assertFalse(val)
self.assertTrue('management' in reason)
def test_can_lpm_ibmi(self):
"""Tests for the can_lpm method for IBM i branches."""
wrap = TestLogicalPartition._shared_wrapper
# Set that it is IBM i
wrap.set_parm_value(bp._BP_MGT_PARTITION, False)
wrap.set_parm_value(bp._BP_TYPE, bp.LPARType.OS400)
wrap.set_parm_value(bp._BP_STATE, bp.LPARState.RUNNING)
host_w = mock.MagicMock()
# Destination host is not capable for IBMi LPM
migr_data = {'ibmi_lpar_mobility_capable': False}
val, reason = wrap.can_lpm(host_w, migr_data=migr_data)
self.assertFalse(val)
self.assertEqual(reason, 'Target system does not have the IBM i '
'LPAR Mobility Capability.')
# Check if restricted I/O is off.
migr_data = {'ibmi_lpar_mobility_capable': True}
wrap.set_parm_value(lpar._LPAR_RESTRICTED_IO, 'False')
val, reason = wrap.can_lpm(host_w, migr_data=migr_data)
self.assertFalse(val)
self.assertIn('restricted I/O', reason)
# Turn restricted I/O on, but get a host without the mobility cap
wrap.set_parm_value(lpar._LPAR_RESTRICTED_IO, 'True')
host_w = mock.MagicMock()
host_w.get_capability.return_value = False
val, reason = wrap.can_lpm(host_w, migr_data=migr_data)
self.assertFalse(val)
self.assertEqual('Source system does not have the IBM i LPAR '
'Mobility Capability.', reason)
# Turn all required capabilities on
host_w.get_capability.return_value = True
wrap.capabilities.set_parm_value(bp._CAP_DLPAR_MEM_CAPABLE, True)
val, reason = wrap.can_lpm(host_w, migr_data=migr_data)
self.assertTrue(val)
self.assertIsNone(reason)
# Turn all required capabilities on but migration data is empty
val, reason = wrap.can_lpm(host_w)
self.assertTrue(val)
self.assertIsNone(reason)
# Turn all required capabilities on but migration data doesn't contain
# the key 'ibmi_lpar_mobility_capable'
migr_data = {}
val, reason = wrap.can_lpm(host_w, migr_data=migr_data)
self.assertTrue(val)
self.assertIsNone(reason)
def test_capabilities(self):
# PartitionCapabilities
self.call_simple_getter("capabilities.io_dlpar", True, False)
self.call_simple_getter("capabilities.mem_dlpar", False, False)
self.call_simple_getter("capabilities.proc_dlpar", True, False)
def test_get_proc_mode(self):
# PartitionProcessorConfiguration
self.call_simple_getter(
"proc_config.has_dedicated", False, False)
self.call_simple_getter(
"proc_config.has_dedicated", True, False, use_dedicated=True)
self._dedicated_wrapper.proc_config._has_dedicated(False)
self.call_simple_getter(
"proc_config.has_dedicated", False, False, use_dedicated=True)
def test_get_current_sharing_mode(self):
# SharedProcessorConfiguration
self.call_simple_getter("proc_config.sharing_mode", "uncapped", None)
self._shared_wrapper.proc_config.sharing_mode = "keep idle procs"
self.call_simple_getter("proc_config.sharing_mode", "keep idle procs",
None)
def test_desired_units(self):
self.call_simple_getter("proc_config.shared_proc_cfg.desired_units",
1.5, None)
self._shared_wrapper.proc_config.shared_proc_cfg.desired_units = 1.75
self.call_simple_getter("proc_config.shared_proc_cfg.desired_units",
1.75, None)
def test_max_units(self):
self.call_simple_getter("proc_config.shared_proc_cfg.max_units",
2.5, None)
self._shared_wrapper.proc_config.shared_proc_cfg.max_units = 1.75
self.call_simple_getter("proc_config.shared_proc_cfg.max_units",
1.75, None)
def test_min_units(self):
self.call_simple_getter("proc_config.shared_proc_cfg.min_units",
0.5, None)
self._shared_wrapper.proc_config.shared_proc_cfg.min_units = 1.75
self.call_simple_getter("proc_config.shared_proc_cfg.min_units",
1.75, None)
def test_desired_virtual(self):
self.call_simple_getter("proc_config.shared_proc_cfg.desired_virtual",
2, None)
self._shared_wrapper.proc_config.shared_proc_cfg.desired_virtual = 5
self.call_simple_getter("proc_config.shared_proc_cfg.desired_virtual",
5, None)
def test_max_virtual(self):
self.call_simple_getter("proc_config.shared_proc_cfg.max_virtual",
3, None)
self._shared_wrapper.proc_config.shared_proc_cfg.max_virtual = 2
self.call_simple_getter("proc_config.shared_proc_cfg.max_virtual",
2, None)
def test_min_virtual(self):
self.call_simple_getter("proc_config.shared_proc_cfg.min_virtual",
1, None)
self._shared_wrapper.proc_config.shared_proc_cfg.min_virtual = 2
self.call_simple_getter("proc_config.shared_proc_cfg.min_virtual",
2, None)
def test_get_shared_proc_pool_id(self):
self.call_simple_getter("proc_config.shared_proc_cfg.pool_id", 9, 0)
self._shared_wrapper.proc_config.shared_proc_cfg.pool_id = 2
self.call_simple_getter("proc_config.shared_proc_cfg.pool_id", 2, 0)
def test_uncapped_weight(self):
self.call_simple_getter("proc_config.shared_proc_cfg.uncapped_weight",
128, 0)
self._shared_wrapper.proc_config.shared_proc_cfg.uncapped_weight = 100
self.call_simple_getter("proc_config.shared_proc_cfg.uncapped_weight",
100, 0)
# DedicatedProcessorConfiguration
def test_desired(self):
self.call_simple_getter("proc_config.dedicated_proc_cfg.desired",
2, 0, use_dedicated=True)
self._dedicated_wrapper.proc_config.dedicated_proc_cfg.desired = 3
self.call_simple_getter("proc_config.dedicated_proc_cfg.desired",
3, 0, use_dedicated=True)
def test_max(self):
self.call_simple_getter("proc_config.dedicated_proc_cfg.max",
3, 0, use_dedicated=True)
self._dedicated_wrapper.proc_config.dedicated_proc_cfg.max = 4
self.call_simple_getter("proc_config.dedicated_proc_cfg.max",
4, 0, use_dedicated=True)
def test_min(self):
self.call_simple_getter("proc_config.dedicated_proc_cfg.min",
1, 0, use_dedicated=True)
self._dedicated_wrapper.proc_config.dedicated_proc_cfg.min = 3
self.call_simple_getter("proc_config.dedicated_proc_cfg.min",
3, 0, use_dedicated=True)
def test_nvram(self):
self.assertEqual("TheNVRAMis20KofBASE64encodedDATA",
self._dedicated_wrapper.nvram)
self._dedicated_wrapper.nvram = "RRNVRAMis20KofBASE64encodedDATA"
self.assertEqual("RRNVRAMis20KofBASE64encodedDATA",
self._dedicated_wrapper.nvram)
# Test setting one that's absent
self.assertIsNone(self._shared_wrapper.nvram)
self._shared_wrapper.nvram = 'SomeOtherValue'
self.assertEqual('SomeOtherValue', self._shared_wrapper.nvram)
def test_uptime(self):
self.assertEqual(1185681, self._dedicated_wrapper.uptime)
class TestIBMiSpecific(twrap.TestWrapper):
"""IBMi-specific tests, requiring a test file from an IBMi partition."""
file = IBMI_HTTPRESP_FILE
wrapper_class_to_test = lpar.LPAR
def test_restricted_io(self):
self.dwrap.restrictedio = True
self.assertTrue(self.dwrap.restrictedio)
def test_desig_ipl_src(self):
self.assertEqual('b', self.dwrap.desig_ipl_src)
self.dwrap.desig_ipl_src = 'c'
self.assertEqual('c', self.dwrap.desig_ipl_src)
# Argh, testtools.TestCase overrides assertRaises - can't use 'with'
try:
self.dwrap.desig_ipl_src = 'q'
self.fail()
except ValueError:
pass
def test_tagged_io(self):
# Getter
tio = self.dwrap.io_config.tagged_io
self.assertIsInstance(tio, bp.TaggedIO)
# Field getters & setters
self.assertEqual('NONE', tio.alt_load_src)
tio.alt_load_src = 34
self.assertEqual('34', tio.alt_load_src)
self.assertEqual('0', tio.console)
tio.console = 'NONE'
self.assertEqual('NONE', tio.console)
self.assertEqual('NONE', tio.load_src)
tio.load_src = '56'
self.assertEqual('56', tio.load_src)
# _bld honors child ordering
new_tio = bp.TaggedIO.bld(self.adpt)
new_tio.load_src = 1
new_tio.alt_load_src = 2
new_tio.console = 3
self.assertEqual(
'<uom:TaggedIO xmlns:uom="http://www.ibm.com/xmlns/systems/power/f'
'irmware/uom/mc/2012_10/" schemaVersion="V1_0"><uom:Metadata><uom:'
'Atom/></uom:Metadata><uom:AlternateLoadSource>2</uom:AlternateLoa'
'dSource><uom:Console>3</uom:Console><uom:LoadSource>1</uom:LoadSo'
'urce></uom:TaggedIO>'.encode('utf-8'), new_tio.toxmlstring())
# Setter
self.dwrap.io_config.tagged_io = new_tio
self.assertEqual('3', self.dwrap.io_config.tagged_io.console)
new_tio = bp.TaggedIO.bld(self.adpt)
self.assertEqual(
'<uom:TaggedIO xmlns:uom="http://www.ibm.com/xmlns/systems/power/f'
'irmware/uom/mc/2012_10/" schemaVersion="V1_0"><uom:Metadata><uom:'
'Atom/></uom:Metadata><uom:AlternateLoadSource>NONE</uom:Alternate'
'LoadSource><uom:Console>HMC</uom:Console><uom:LoadSource>0</uom:L'
'oadSource></uom:TaggedIO>'.encode('utf-8'), new_tio.toxmlstring())
@mock.patch('warnings.warn')
def test_rr_real_values(self, mock_warn):
"""Test Remote Restart fields when RR capable."""
# Testing this under IBMi because the IBMi payload file happens to have
# real data to use.
self.assertIsNone(self.dwrap.rr_enabled)
mock_warn.assert_called_with(mock.ANY, DeprecationWarning)
mock_warn.reset_mock()
self.assertIsNone(self.dwrap.rr_state)
mock_warn.assert_called_with(mock.ANY, DeprecationWarning)
class TestPartitionIOConfiguration(twrap.TestWrapper):
file = LPAR_HTTPRESP_FILE
wrapper_class_to_test = lpar.LPAR
def setUp(self):
super(TestPartitionIOConfiguration, self).setUp()
self.io_config = self.entries[0].io_config
def test_max_slots(self):
self.assertEqual(64, self.io_config.max_virtual_slots)
def test_io_slots(self):
# IO Slots are typically associated with the VIOS. Further testing
# driven there.
self.assertIsNotNone(self.io_config.io_slots)
self.assertEqual(0, len(self.io_config.io_slots))
class TestMemCfg(twrap.TestWrapper):
"""Test cases to test the lpar mem operations."""
file = LPAR_HTTPRESP_FILE
wrapper_class_to_test = lpar.LPAR
def setUp(self):
super(TestMemCfg, self).setUp()
self.mem_config = self.entries[0].mem_config
def test_mem(self):
mem_wrap = bp.PartitionMemoryConfiguration.bld(
None, 1024, min_mem=512, max_mem=2048)
self.assertIsNotNone(mem_wrap)
self.assertEqual(512, mem_wrap.min)
self.assertEqual(1024, mem_wrap.desired)
self.assertEqual(2048, mem_wrap.max)
self.assertEqual(0, mem_wrap.exp_factor)
self.assertFalse(mem_wrap.ame_enabled)
def test_current_mem(self):
self.assertEqual(512, self.mem_config.current)
class TestIOCfg(twrap.TestWrapper):
"""Test the lpar I/O configuration."""
file = LPAR_HTTPRESP_FILE
wrapper_class_to_test = lpar.LPAR
def setUp(self):
super(TestIOCfg, self).setUp()
self.io_config = self.entries[0].io_config
def test_bld(self):
# No slots
io_wrap = bp.PartitionIOConfiguration.bld(None, 10)
self.assertEqual(10, io_wrap.max_virtual_slots)
self.assertEqual([], io_wrap.io_slots)
# With slots
slot_wraps = [bp.IOSlot.bld(None, True, 1234),
bp.IOSlot.bld(None, False, 4321)]
io_wrap = bp.PartitionIOConfiguration.bld(None, 12, slot_wraps)
self.assertEqual(len(slot_wraps), len(io_wrap.io_slots))
for exp, act in zip(slot_wraps, io_wrap.io_slots):
self.assertEqual(exp.drc_index, act.drc_index)
self.assertEqual(exp.bus_grp_required, act.bus_grp_required)
def test_data(self):
self.assertEqual(64, self.io_config.max_virtual_slots)
self.assertEqual([], self.io_config.io_slots)
class TestPhysFCPort(unittest.TestCase):
def test_bld(self):
port = bp.PhysFCPort.bld_ref(None, 'fcs0')
self.assertIsNotNone(port)
self.assertEqual('fcs0', port.name)
if __name__ == "__main__":
unittest.main()
|