File: test_lpar_bldr.py

package info (click to toggle)
python-pypowervm 1.1.24%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,400 kB
  • sloc: python: 29,780; xml: 174; makefile: 14
file content (553 lines) | stat: -rw-r--r-- 26,201 bytes parent folder | download
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
# Copyright 2015, 2018 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 uuid

import mock
import six
import testtools

from pypowervm.tests import test_fixtures as fx
from pypowervm.tests.test_utils import xml_sections
from pypowervm.utils import lpar_builder as lpar_bldr
import pypowervm.utils.uuid as pvm_uuid
from pypowervm.wrappers import base_partition as bp
from pypowervm.wrappers import logical_partition as lpar

LPAR_BLDR_DATA = 'lpar_builder.txt'


class TestLPARBuilder(testtools.TestCase):
    """Unit tests for the lpar builder."""

    def setUp(self):
        super(TestLPARBuilder, self).setUp()
        self.sections = xml_sections.load_xml_sections(LPAR_BLDR_DATA)
        self.adpt = self.useFixture(fx.AdapterFx()).adpt

        def _bld_mgd_sys(proc_units, mem_reg, srr, pcm, ame,
                         ppt, affinity=False, psbc=False):
            # Build a fake managed system wrapper
            mngd_sys = mock.Mock()
            type(mngd_sys).proc_units_avail = (
                mock.PropertyMock(return_value=proc_units))
            type(mngd_sys).memory_region_size = (
                mock.PropertyMock(return_value=mem_reg))

            def get_cap(cap):
                capabilities = {
                    'simplified_remote_restart_capable': srr,
                    'ibmi_restrictedio_capable': True,
                    'active_memory_expansion_capable': ame,
                    'physical_page_table_ratio_capable': ppt,
                    'affinity_check_capable': affinity,
                    'partition_secure_boot_capable': psbc
                }
                return capabilities[cap]
            mngd_sys.get_capability.side_effect = get_cap

            type(mngd_sys).proc_compat_modes = (
                mock.PropertyMock(return_value=pcm))
            return mngd_sys

        self.mngd_sys = _bld_mgd_sys(20.0, 128, True,
                                     bp.LPARCompat.ALL_VALUES, False, False)
        self.mngd_sys_no_srr = _bld_mgd_sys(20.0, 128, False, ['POWER6'],
                                            False, False)
        self.mngd_sys_ame = _bld_mgd_sys(20.0, 128, True,
                                         bp.LPARCompat.ALL_VALUES, True, False)
        self.mngd_sys_ppt = _bld_mgd_sys(20.0, 128, True,
                                         bp.LPARCompat.ALL_VALUES, False, True)
        self.mngd_sys_affinity = _bld_mgd_sys(20.0, 128, True,
                                              bp.LPARCompat.ALL_VALUES, False,
                                              True, affinity=True)
        self.mngd_sys_secure_boot = _bld_mgd_sys(20.0, 128, True,
                                                 bp.LPARCompat.ALL_VALUES,
                                                 False, True, psbc=True)
        self.stdz_sys1 = lpar_bldr.DefaultStandardize(self.mngd_sys)
        self.stdz_sys2 = lpar_bldr.DefaultStandardize(self.mngd_sys_no_srr)
        self.stdz_sys3 = lpar_bldr.DefaultStandardize(self.mngd_sys_ame)
        self.stdz_sys4 = lpar_bldr.DefaultStandardize(self.mngd_sys_ppt)
        self.stdz_sys5 = lpar_bldr.DefaultStandardize(self.mngd_sys_affinity)
        self.stdz_sys6 = lpar_bldr.DefaultStandardize(
            self.mngd_sys_secure_boot)

    def assert_xml(self, entry, string):
        self.assertEqual(six.b(string.rstrip('\n')),
                         entry.element.toxmlstring())

    def test_proc_modes(self):
        # Base minimum attrs
        attr = dict(name='TheName', memory=1024, vcpu=1)
        # No proc keys specified
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertFalse(bldr._shared_proc_keys_specified())
        self.assertFalse(bldr._dedicated_proc_keys_specified())
        # Default is shared
        self.assertTrue(bldr._shared_procs_specified())
        # Shared proc keys specified
        for key in ('proc_units', 'max_proc_units', 'min_proc_units',
                    'uncapped_weight'):
            bldr = lpar_bldr.LPARBuilder(self.adpt, dict(attr, **{key: 1}),
                                         self.stdz_sys1)
            self.assertTrue(bldr._shared_proc_keys_specified())
            self.assertFalse(bldr._dedicated_proc_keys_specified())
            self.assertTrue(bldr._shared_procs_specified())
        # Shared modes specified
        for mode in ('capped', 'uncapped'):
            bldr = lpar_bldr.LPARBuilder(
                self.adpt, dict(attr, sharing_mode=mode), self.stdz_sys1)
            self.assertTrue(bldr._shared_proc_keys_specified())
            self.assertFalse(bldr._dedicated_proc_keys_specified())
            self.assertTrue(bldr._shared_procs_specified())
        # Dedicated modes specified
        for mode in ('sre idle proces', 'sre idle procs active',
                     'sre idle procs always', 'keep idle procs'):
            bldr = lpar_bldr.LPARBuilder(
                self.adpt, dict(attr, sharing_mode=mode), self.stdz_sys1)
            self.assertFalse(bldr._shared_proc_keys_specified())
            self.assertTrue(bldr._dedicated_proc_keys_specified())
            self.assertFalse(bldr._shared_procs_specified())
        # Dedicated proc explicitly true
        bldr = lpar_bldr.LPARBuilder(
            self.adpt, dict(attr, dedicated_proc='TRUE'), self.stdz_sys1)
        self.assertFalse(bldr._shared_proc_keys_specified())
        self.assertFalse(bldr._dedicated_proc_keys_specified())
        self.assertFalse(bldr._shared_procs_specified())
        # Dedicated proc explicitly false
        bldr = lpar_bldr.LPARBuilder(
            self.adpt, dict(attr, dedicated_proc='NO'), self.stdz_sys1)
        self.assertFalse(bldr._shared_proc_keys_specified())
        self.assertFalse(bldr._dedicated_proc_keys_specified())
        self.assertTrue(bldr._shared_procs_specified())

    def test_builder(self):
        # Build the minimum attributes, Shared Procs
        # shared_lpar test file uses non-default max I/O slots
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, max_io_slots=2000)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertIsNotNone(bldr)

        new_lpar = bldr.build()
        self.assertIsNotNone(new_lpar)
        self.assert_xml(new_lpar, self.sections['shared_lpar'])
        self.assertEqual('TheName', new_lpar.name)

        # Rebuild the same lpar with a different name
        attr['name'] = 'NewName'
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        rbld_lpar = bldr.rebuild(new_lpar)
        self.assertEqual('NewName', rbld_lpar.name)

        # Build the minimum attributes, Dedicated Procs
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, dedicated_proc=True)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertIsNotNone(bldr)

        new_lpar = bldr.build()
        self.assertIsNotNone(new_lpar)
        self.assert_xml(new_lpar.entry, self.sections['dedicated_lpar'])

        # Build the minimum attributes, Dedicated Procs = 'true'
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, dedicated_proc='true')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar.entry, self.sections['dedicated_lpar'])

        # Leave out memory
        attr = dict(name=lpar, env=bp.LPARType.AIXLINUX, vcpu=1)
        self.assertRaises(
            lpar_bldr.LPARBuilderException, lpar_bldr.LPARBuilder, self.adpt,
            attr, self.stdz_sys1)

        # Bad memory lmb multiple
        attr = dict(name='lpar', memory=3333, env=bp.LPARType.AIXLINUX, vcpu=1)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Check the validation of the LPAR type when not specified
        attr = dict(name='TheName', memory=1024, vcpu=1, max_io_slots=2000)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['shared_lpar'])

        # Check the PPT ratio element builds correctly
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, ppt_ratio='1:512')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys4)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['ppt_lpar'])

        # Ensure secure boot is set properly
        attr = dict(name='SecureBoot', memory=1024, env=bp.LPARType.AIXLINUX,
                    vcpu=1, secure_boot=2)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys6)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['secure_boot_lpar'])

        # Ensure secure boot disabled works for IBMi
        attr = dict(name='SecureBoot', memory=1024, env=bp.LPARType.OS400,
                    vcpu=1, secure_boot=0)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys6)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['secure_boot_ibmi_lpar'])

        # LPAR name too long
        attr = dict(name='lparlparlparlparlparlparlparlparlparlparlparlpar'
                    'lparlparlparlparlparlparlparlparlparlparlparlparlparlpar',
                    memory=1024, env=bp.LPARType.AIXLINUX, vcpu=1)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(lpar_bldr.LPARBuilderException, bldr.build)

        # Test setting uuid
        uuid1 = pvm_uuid.convert_uuid_to_pvm(str(uuid.uuid4()))
        attr = dict(name='lpar', memory=1024, uuid=uuid1, vcpu=1)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        lpar_w = bldr.build()
        self.assertEqual(uuid1.upper(), lpar_w.uuid)

        # Test setting id
        id1 = 1234
        attr = dict(name='lpar', memory=1024, uuid=uuid1, vcpu=1, id=id1)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        lpar_w = bldr.build()
        self.assertEqual(id1, lpar_w.id)

        # Bad LPAR type
        attr = dict(name='lpar', memory=1024, env='BADLPARType', vcpu=1)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Bad IO Slots
        attr = dict(name='lpar', memory=1024, max_io_slots=0,
                    env=bp.LPARType.AIXLINUX, vcpu=1)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        attr = dict(name='lpar', memory=1024, max_io_slots=(65534+1),
                    env=bp.LPARType.AIXLINUX, vcpu=1)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Good non-default IO Slots and SRR
        attr = dict(name='TheName', memory=1024, max_io_slots=2000,
                    env=bp.LPARType.AIXLINUX, vcpu=1, srr_capability=False)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['shared_lpar'])

        # Bad SRR value.
        attr = dict(name='lpar', memory=1024, max_io_slots=64,
                    env=bp.LPARType.AIXLINUX, vcpu=1, srr_capability='Frog')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Uncapped / capped shared procs and enabled lpar metrics
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, sharing_mode=bp.SharingMode.CAPPED,
                    srr_capability='true', enable_lpar_metric=True)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['capped_lpar'])

        # Uncapped and no SRR capability
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, sharing_mode=bp.SharingMode.UNCAPPED,
                    uncapped_weight=100, processor_compatibility='POWER6')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys2)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['uncapped_lpar'])

        # Build dedicated but only via dedicated attributes
        m = bp.DedicatedSharingMode.SHARE_IDLE_PROCS_ALWAYS
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, sharing_mode=m, processor_compatibility='PoWeR7')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar.entry,
                        self.sections['ded_lpar_sre_idle_procs_always'])

        # Desired mem outside min
        attr = dict(name='lpar', memory=1024, env=bp.LPARType.AIXLINUX, vcpu=1,
                    min_mem=2048)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Desired mem outside max
        attr = dict(name='lpar', memory=5000, env=bp.LPARType.AIXLINUX, vcpu=1,
                    max_mem=2048)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # AME not supported on host
        attr = dict(name='lpar', memory=1024, env=bp.LPARType.AIXLINUX, vcpu=1,
                    ame_factor='1.5')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # AME outside valid range
        attr = dict(name='lpar', memory=1024, env=bp.LPARType.AIXLINUX, vcpu=1,
                    ame_factor='0.5')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys3)
        self.assertRaises(ValueError, bldr.build)

        # PPT not supported on host
        attr = dict(name='lpar', memory=1024, env=bp.LPARType.AIXLINUX, vcpu=1,
                    ppt_ratio='1:64')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys3)
        self.assertRaises(ValueError, bldr.build)

        # PPT ratio not a valid choice
        attr = dict(name='lpar', memory=1024, env=bp.LPARType.AIXLINUX, vcpu=1,
                    ppt_ratio='1:76')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys3)
        self.assertRaises(ValueError, bldr.build)

        # Affinity unsupported host
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    enforce_affinity_check='true')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys4)
        self.assertRaises(ValueError, bldr.build)

        # Enforce affinity score check for Lpar with incorrect value
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    enforce_affinity_check='BADVALUE')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys5)
        self.assertRaises(ValueError, bldr.build)

        # Secure boot on unsupported host
        attr = dict(name='SecureBoot', memory=1024, env=bp.LPARType.AIXLINUX,
                    vcpu=1, secure_boot=2)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys5)
        self.assertRaises(ValueError, bldr.build)

        # Secure boot of IBMi LPAR
        attr = dict(name='SecureBoot', memory=1024, env=bp.LPARType.OS400,
                    vcpu=1, secure_boot=2)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys6)
        self.assertRaises(ValueError, bldr.build)

        # Secure boot bad value
        attr = dict(name='SecureBoot', memory=1024, env=bp.LPARType.AIXLINUX,
                    vcpu=1, secure_boot=10)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys6)
        self.assertRaises(ValueError, bldr.build)

        # Secure boot as 0 on unsupported host
        # This dictionary should equate to the 'dedicated_lpar' XML on an
        # unsupported host.
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, dedicated_proc=True, secure_boot=0)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['dedicated_lpar'])

        # Desired vcpu outside min
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=1,
                    min_vcpu=2)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys5)
        self.assertRaises(ValueError, bldr.build)

        # Desired vcpu outside max
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    max_vcpu=2)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Ensure the calculated procs are not below the min
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    min_proc_units=3)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        procs = new_lpar.proc_config.shared_proc_cfg
        self.assertEqual(3.0, procs.min_units)

        # Ensure the calculated procs are all 0.5
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=1,
                    proc_units=0.5)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        procs = new_lpar.proc_config.shared_proc_cfg
        self.assertEqual(0.5, procs.min_units)
        self.assertEqual(0.5, procs.max_units)
        self.assertEqual(0.5, procs.desired_units)

        # Create a temp standardizer with a smaller proc units factor
        stdz = lpar_bldr.DefaultStandardize(self.mngd_sys,
                                            proc_units_factor=0.1)
        # Ensure the min, max, and desired proc units works as VCPU is scaled.
        for x in [1, 5, 10, 17, 20]:
            attr = dict(name='lpar', memory=2048, vcpu=x)
            bldr = lpar_bldr.LPARBuilder(self.adpt, attr, stdz)
            new_lpar = bldr.build()
            procs = new_lpar.proc_config.shared_proc_cfg
            self.assertEqual(round(0.1 * x, 2), procs.min_units)
            self.assertEqual(round(0.1 * x, 2), procs.max_units)
            self.assertEqual(round(0.1 * x, 2), procs.desired_units)

        # Ensure the calculated procs are below the max
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    max_proc_units=2.1)
        stdz = lpar_bldr.DefaultStandardize(
            self.mngd_sys, proc_units_factor=0.9)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, stdz)
        new_lpar = bldr.build()
        procs = new_lpar.proc_config.shared_proc_cfg
        self.assertEqual(2.1, procs.max_units)

        # Ensure proc units factor is between 0.1 and 1.0
        self.assertRaises(
            lpar_bldr.LPARBuilderException,
            lpar_bldr.DefaultStandardize,
            self.mngd_sys, proc_units_factor=1.01)
        self.assertRaises(
            lpar_bldr.LPARBuilderException,
            lpar_bldr.DefaultStandardize,
            self.mngd_sys, proc_units_factor=0.01)

        # Avail priority outside max
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    avail_priority=332)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Avail priority bad parm
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    avail_priority='BADVALUE')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Avail priority at min value
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    avail_priority=0)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assertEqual(new_lpar.avail_priority, 0)

        # Avail priority at max value
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    avail_priority=255)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assertEqual(new_lpar.avail_priority, 255)

        # Enable Lpar metric with correct value as true
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    enable_lpar_metric='true')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assertEqual(new_lpar.allow_perf_data_collection, True)

        # Enable Lpar metric with correct value as false
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    enable_lpar_metric='false')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assertEqual(new_lpar.allow_perf_data_collection, False)

        # Enable Lpar Metric with bad parm other than true or false
        attr = dict(name='lpar', memory=2048, env=bp.LPARType.AIXLINUX, vcpu=3,
                    enable_lpar_metric='BADVALUE')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertRaises(ValueError, bldr.build)

        # Proc compat
        for pc in bp.LPARCompat.ALL_VALUES:
            attr = dict(name='name', memory=1024, vcpu=1,
                        processor_compatibility=pc)
            bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
            new_lpar = bldr.build()
            self.assertEqual(new_lpar.pending_proc_compat_mode, pc)

        attr = dict(name='name', memory=1024, vcpu=1,
                    processor_compatibility='POWER6')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys2)
        new_lpar = bldr.build()
        self.assertEqual(new_lpar.pending_proc_compat_mode, 'POWER6')

        # Ensure failure occurs on validation after the host supported
        # proc modes are loaded and not on convert_value which converts
        # across all acceptable proc modes.
        # This works because 'POWER8' is in LPARCompat.ALL_VALUES
        attr = dict(name='name', memory=1024, vcpu=1,
                    processor_compatibility='POWER8')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys2)
        exp_msg = ("Value 'POWER8' is not valid for field 'Processor "
                   "Compatability Mode' with acceptable choices: ['POWER6']")
        try:
            bldr.build()
        except Exception as e:
            self.assertEqual(six.text_type(e), exp_msg)

        # Build a VIOS with I/O slots
        slots = [bp.IOSlot.bld(self.adpt, True, 12345),
                 bp.IOSlot.bld(self.adpt, False, 54321)]
        attr = dict(name='TheName', env=bp.LPARType.VIOS, memory=1024,
                    vcpu=1, dedicated_proc=True, phys_io_slots=slots)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertIsNotNone(bldr)

        new_lpar = bldr.build()
        self.assertIsNotNone(new_lpar)
        self.assert_xml(new_lpar.entry, self.sections['vios'])

    def test_IBMi(self):
        attr = dict(name='TheName', env=bp.LPARType.OS400, memory=1024,
                    vcpu=1, ame_factor=False)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertIsNotNone(bldr)

        new_lpar = bldr.build()
        self.assertIsNotNone(new_lpar)
        self.assertTrue(new_lpar.restrictedio)
        tag_io = new_lpar.io_config.tagged_io
        self.assertEqual('HMC', tag_io.console)
        self.assertEqual('0', tag_io.load_src)
        self.assertEqual('NONE', tag_io.alt_load_src)

        attr = dict(name='OS400LPAR', env=bp.LPARType.OS400, memory=1024,
                    vcpu=1, console='CONSOLE', load_src='9', alt_load_src='9')
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        self.assertIsNotNone(bldr)

        new_lpar = bldr.build()
        self.assertIsNotNone(new_lpar)
        self.assertTrue(new_lpar.restrictedio)
        tag_io = new_lpar.io_config.tagged_io
        self.assertEqual('CONSOLE', tag_io.console)
        self.assertEqual('9', tag_io.load_src)
        self.assertEqual('9', tag_io.alt_load_src)

    def test_io_slots(self):
        attr = dict(name='TheName', memory=1024, vcpu=1)
        nlpar = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1).build()
        self.assertEqual([], nlpar.io_config.io_slots)

        attr = dict(name='TheName', memory=1024, vcpu=1, phys_io_slots=[])
        nlpar = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1).build()
        self.assertEqual([], nlpar.io_config.io_slots)

        slots = [bp.IOSlot.bld(self.adpt, True, 12345),
                 bp.IOSlot.bld(self.adpt, False, 54321)]
        attr = dict(name='TheName', memory=1024, vcpu=1, phys_io_slots=slots)
        nlpar = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1).build()
        self.assertEqual(len(slots), len(nlpar.io_config.io_slots))
        for exp, act in zip(slots, nlpar.io_config.io_slots):
            self.assertEqual(exp.drc_index, act.drc_index)
            self.assertEqual(exp.bus_grp_required, act.bus_grp_required)