Example #1
0
    def test_uuid_conversion(self):
        uuid = '089ffb20-5d19-4a8c-bb80-13650627d985'
        pvm_uuid = uuid_utils.convert_uuid_to_pvm(uuid)
        self.assertEqual(uuid, pvm_uuid)

        uuid = '989ffb20-5d19-4a8c-bb80-13650627d985'
        pvm_uuid = uuid_utils.convert_uuid_to_pvm(uuid)
        self.assertEqual('1' + uuid[1:], pvm_uuid)

        uuid = 'c89ffb20-5d19-4a8c-bb80-13650627d985'
        pvm_uuid = uuid_utils.convert_uuid_to_pvm(uuid)
        self.assertEqual('4' + uuid[1:], pvm_uuid)
Example #2
0
    def test_uuid_conversion(self):
        uuid = '089ffb20-5d19-4a8c-bb80-13650627d985'
        pvm_uuid = uuid_utils.convert_uuid_to_pvm(uuid)
        self.assertEqual(uuid, pvm_uuid)

        uuid = '989ffb20-5d19-4a8c-bb80-13650627d985'
        pvm_uuid = uuid_utils.convert_uuid_to_pvm(uuid)
        self.assertEqual('1' + uuid[1:], pvm_uuid)

        uuid = 'c89ffb20-5d19-4a8c-bb80-13650627d985'
        pvm_uuid = uuid_utils.convert_uuid_to_pvm(uuid)
        self.assertEqual('4' + uuid[1:], pvm_uuid)
Example #3
0
    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)
Example #4
0
    def _puuid(instance):
        """Derives the PowerVM UUID for an instance.

        :param instance: The OpenStack instance object.
        :return: The PowerVM API's UUID for the instance.
        """
        return pvm_uuid.convert_uuid_to_pvm(instance.id).upper()
    def _puuid(instance):
        """Derives the PowerVM UUID for an instance.

        :param instance: The OpenStack instance object.
        :return: The PowerVM API's UUID for the instance.
        """
        return pvm_uuid.convert_uuid_to_pvm(instance.id).upper()
Example #6
0
    def _format_flavor(self, instance, flavor):
        """Returns the pypowervm format of the flavor.

        :param instance: the VM instance
        :param flavor: The Nova instance flavor.
        :return: a dict that can be used by the LPAR builder
        """
        # The attrs are what is sent to pypowervm to convert the lpar.
        attrs = {}

        attrs[lpar_bldr.NAME] = instance.name
        # The uuid is only actually set on a create of an LPAR
        attrs[lpar_bldr.UUID] = pvm_uuid.convert_uuid_to_pvm(instance.uuid)
        attrs[lpar_bldr.MEM] = flavor.memory_mb
        attrs[lpar_bldr.VCPU] = flavor.vcpus

        # Loop through the extra specs and process powervm keys
        for key in flavor.extra_specs.keys():
            # If it is not a valid key, then can skip.
            if not self._is_pvm_valid_key(key):
                continue

            # Look for the mapping to the lpar builder
            bldr_key = self._ATTRS_MAP.get(key)

            # Check for no direct mapping, if the value is none, need to
            # derive the complex type
            if bldr_key is None:
                self._build_complex_type(key, attrs, flavor)
            else:
                # We found a direct mapping
                attrs[bldr_key] = flavor.extra_specs[key]

        return attrs
Example #7
0
    def _format_flavor(self, instance, flavor):
        """Returns the pypowervm format of the flavor.

        :param instance: the VM instance
        :param flavor: The Nova instance flavor.
        :return: a dict that can be used by the LPAR builder
        """
        # The attrs are what is sent to pypowervm to convert the lpar.
        attrs = {}

        attrs[lpar_bldr.NAME] = instance.name
        # The uuid is only actually set on a create of an LPAR
        attrs[lpar_bldr.UUID] = pvm_uuid.convert_uuid_to_pvm(instance.uuid)
        attrs[lpar_bldr.MEM] = flavor.memory_mb
        attrs[lpar_bldr.VCPU] = flavor.vcpus

        # Loop through the extra specs and process powervm keys
        for key in flavor.extra_specs.keys():
            # If it is not a valid key, then can skip.
            if not self._is_pvm_valid_key(key):
                continue

            # Look for the mapping to the lpar builder
            bldr_key = self._ATTRS_MAP.get(key)

            # Check for no direct mapping, if the value is none, need to
            # derive the complex type
            if bldr_key is None:
                self._build_complex_type(key, attrs, flavor)
            else:
                # We found a direct mapping
                attrs[bldr_key] = flavor.extra_specs[key]

        return attrs
Example #8
0
def get_pvm_uuid(instance):
    """Get the corresponding PowerVM VM uuid of an instance uuid.

    Maps a OpenStack instance uuid to a PowerVM uuid.  The UUID between the
    Nova instance and PowerVM will be 1 to 1 mapped.  This method runs the
    algorithm against the instance's uuid to convert it to the PowerVM
    UUID.

    :param instance: nova.objects.instance.Instance.
    :return: The PowerVM UUID for the LPAR corresponding to the instance.
    """
    return pvm_uuid.convert_uuid_to_pvm(instance.uuid).upper()
Example #9
0
    def _format_flavor(self, instance):
        """Returns the pypowervm format of the flavor.

        :param instance: the VM instance
        :return: a dict that can be used by the LPAR builder
        """
        # The attrs are what is sent to pypowervm to convert the lpar.
        attrs = {}

        attrs[lpar_bldr.NAME] = pvm_util.sanitize_partition_name_for_api(
            instance.name)
        # The uuid is only actually set on a create of an LPAR
        attrs[lpar_bldr.UUID] = pvm_uuid.convert_uuid_to_pvm(instance.uuid)
        attrs[lpar_bldr.MEM] = instance.flavor.memory_mb
        attrs[lpar_bldr.VCPU] = instance.flavor.vcpus
        # Set the srr capability to True by default
        attrs[lpar_bldr.SRR_CAPABLE] = True

        # Loop through the extra specs and process powervm keys
        for key in instance.flavor.extra_specs.keys():
            # If it is not a valid key, then can skip.
            if not self._is_pvm_valid_key(key):
                continue

            # Look for the mapping to the lpar builder
            bldr_key = self._ATTRS_MAP.get(key)

            # Check for no direct mapping, if the value is none, need to
            # derive the complex type
            if bldr_key is None:
                self._build_complex_type(key, attrs, instance.flavor)
            elif bldr_key == lpar_bldr.ENABLE_LPAR_METRIC:
                lpar_metric = self._flavor_bool(
                    instance.flavor.extra_specs[key], key)
                attrs[bldr_key] = lpar_metric
            elif bldr_key == lpar_bldr.PPT_RATIO:
                if (instance.task_state == task_states.REBUILD_SPAWNING
                        and not self.host_w.get_capability(
                            'physical_page_table_ratio_capable')):
                    # We still want to be able to rebuild from hosts that
                    # support setting the PPT ratio to hosts that don't support
                    # setting the PPT ratio.
                    LOG.info(
                        "Ignoring PPT ratio on rebuild to PPT ratio "
                        "unsupported host.",
                        instance=instance)
                else:
                    attrs[bldr_key] = instance.flavor.extra_specs[key]
            else:
                # We found a direct mapping
                attrs[bldr_key] = instance.flavor.extra_specs[key]

        return attrs
Example #10
0
def get_pvm_uuid(instance):
    """Get the corresponding PowerVM VM uuid of an instance uuid

    Maps a OpenStack instance uuid to a PowerVM uuid.  The UUID between the
    Nova instance and PowerVM will be 1 to 1 mapped.  This method runs the
    algorithm against the instance's uuid to convert it to the PowerVM
    UUID.

    :param instance: nova.objects.instance.Instance OR the OpenStack instance
                     uuid.
    :return: pvm_uuid.
    """
    inst_uuid = instance if uuidutils.is_uuid_like(instance) else instance.uuid
    return pvm_uuid.convert_uuid_to_pvm(inst_uuid).upper()
Example #11
0
def get_pvm_uuid(instance):
    """Get the corresponding PowerVM VM uuid of an instance uuid.

    Maps a OpenStack instance uuid to a PowerVM uuid.  The UUID between the
    Nova instance and PowerVM will be 1 to 1 mapped.  This method runs the
    algorithm against the instance's uuid to convert it to the PowerVM
    UUID.

    :param instance: nova.objects.instance.Instance.
    :return: The PowerVM UUID for the LPAR corresponding to the instance.
    """
    # NOTE(esberglu): To work around bug ##1766692, we explicitly use str()
    # rather than six.text_type here because of this pypowervm check for
    # isinstance(..., str) at L50 of
    # https://github.com/powervm/pypowervm/blob/1.1.10/pypowervm/utils/uuid.py
    return pvm_uuid.convert_uuid_to_pvm(str(instance.uuid)).upper()
Example #12
0
    def build_prov_requests_from_neutron(self):
        """Builds the provisioning requests from the Neutron Server.

        The Neutron Server may have updated ports.  These port requests will
        be sent down to the agent as a ProvisionRequest.

        :return: A list of the ProvisionRequests that have come from Neutron.
        """
        # Convert the ports to devices.
        u_ports = self._list_updated_ports()
        dev_list = [x.get("mac_address") for x in u_ports]
        devices = self.get_devices_details_list(dev_list)

        # Build the network devices
        resp = []
        for port in u_ports:
            port_uuid = port.get("id")

            # Make sure we have a UUID
            if port_uuid is None:
                continue

            # Make sure the binding host matches this agent.  Otherwise it is
            # meant to provision on another agent.
            if port.get("binding:host_id") != cfg.CONF.host:
                continue

            for dev in devices:
                # If the device's id (really the port uuid) doesn't match,
                # ignore it.
                dev_pid = dev.get("port_id")
                if dev_pid is None or port_uuid != dev_pid:
                    continue

                # Valid request.  Add it
                device_id = port.get("device_id")
                lpar_uuid = pvm_uuid.convert_uuid_to_pvm(device_id).upper()
                resp.append(ProvisionRequest(dev, lpar_uuid))
        return resp
Example #13
0
    def build_prov_requests_from_neutron(self):
        """Builds the provisioning requests from the Neutron Server.

        The Neutron Server may have updated ports.  These port requests will
        be sent down to the agent as a ProvisionRequest.

        :return: A list of the ProvisionRequests that have come from Neutron.
        """
        # Convert the ports to devices.
        u_ports = self._list_updated_ports()
        dev_list = [x.get('mac_address') for x in u_ports]
        devices = self.get_devices_details_list(dev_list)

        # Build the network devices
        resp = []
        for port in u_ports:
            port_uuid = port.get('id')

            # Make sure we have a UUID
            if port_uuid is None:
                continue

            # Make sure the binding host matches this agent.  Otherwise it is
            # meant to provision on another agent.
            if port.get('binding:host_id') != cfg.CONF.host:
                continue

            for dev in devices:
                # If the device's id (really the port uuid) doesn't match,
                # ignore it.
                dev_pid = dev.get('port_id')
                if dev_pid is None or port_uuid != dev_pid:
                    continue

                # Valid request.  Add it
                device_id = port.get('device_id')
                lpar_uuid = pvm_uuid.convert_uuid_to_pvm(device_id).upper()
                resp.append(ProvisionRequest(dev, lpar_uuid))
        return resp
Example #14
0
    def test_format_flavor(self):
        """Perform tests against _format_flavor."""
        # convert instance uuid to pypowervm uuid
        # LP 1561128, simplified remote restart is enabled by default
        lpar_attrs = {'memory': 2048,
                      'name': self.san_lpar_name.return_value,
                      'uuid': pvm_uuid.convert_uuid_to_pvm(
                              self.inst.uuid).upper(),
                      'vcpu': 1, 'srr_capability': True}

        # Test dedicated procs
        self.inst.flavor.extra_specs = {'powervm:dedicated_proc': 'true'}
        test_attrs = dict(lpar_attrs, dedicated_proc='true')

        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test dedicated procs, min/max vcpu and sharing mode
        self.inst.flavor.extra_specs = {'powervm:dedicated_proc': 'true',
                                        'powervm:dedicated_sharing_mode':
                                        'share_idle_procs_active',
                                        'powervm:min_vcpu': '1',
                                        'powervm:max_vcpu': '3'}
        test_attrs = dict(lpar_attrs,
                          dedicated_proc='true',
                          sharing_mode='sre idle procs active',
                          min_vcpu='1', max_vcpu='3')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test shared proc sharing mode
        self.inst.flavor.extra_specs = {'powervm:uncapped': 'true'}
        test_attrs = dict(lpar_attrs, sharing_mode='uncapped')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test availability priority
        self.inst.flavor.extra_specs = {'powervm:availability_priority': '150'}
        test_attrs = dict(lpar_attrs, avail_priority='150')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test processor compatibility
        self.inst.flavor.extra_specs = {
            'powervm:processor_compatibility': 'POWER8'}
        test_attrs = dict(lpar_attrs, processor_compatibility='POWER8')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test min, max proc units
        self.inst.flavor.extra_specs = {'powervm:min_proc_units': '0.5',
                                        'powervm:max_proc_units': '2.0'}
        test_attrs = dict(lpar_attrs, min_proc_units='0.5',
                          max_proc_units='2.0')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test min, max mem
        self.inst.flavor.extra_specs = {'powervm:min_mem': '1024',
                                        'powervm:max_mem': '4096'}
        test_attrs = dict(lpar_attrs, min_mem='1024', max_mem='4096')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test remote restart set to false
        self.inst.flavor.extra_specs = {'powervm:srr_capability': 'false'}
        test_attrs = dict(lpar_attrs, srr_capability=False)
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)

        # Unhandled powervm: key is ignored
        self.inst.flavor.extra_specs = {'powervm:srr_capability': 'false',
                                        'powervm:something_new': 'foo'}
        test_attrs = dict(lpar_attrs, srr_capability=False)
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)

        # If we recognize a key, but don't handle it, we raise
        with mock.patch.object(self.lpar_b, '_is_pvm_valid_key',
                               return_value=True):
            self.inst.flavor.extra_specs = {'powervm:srr_capability': 'false',
                                            'powervm:something_new': 'foo'}
            self.assertRaises(KeyError, self.lpar_b._format_flavor, self.inst)
Example #15
0
    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_format_flavor(self):
        """Perform tests against _format_flavor."""
        # convert instance uuid to pypowervm uuid
        # LP 1561128, simplified remote restart is enabled by default
        lpar_attrs = {
            'memory': 2048,
            'name': self.san_lpar_name.return_value,
            'uuid': pvm_uuid.convert_uuid_to_pvm(self.inst.uuid).upper(),
            'vcpu': 1,
            'srr_capability': True
        }

        # Test dedicated procs
        self.inst.flavor.extra_specs = {'powervm:dedicated_proc': 'true'}
        test_attrs = dict(lpar_attrs, dedicated_proc='true')

        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test dedicated procs, min/max vcpu and sharing mode
        self.inst.flavor.extra_specs = {
            'powervm:dedicated_proc': 'true',
            'powervm:dedicated_sharing_mode': 'share_idle_procs_active',
            'powervm:min_vcpu': '1',
            'powervm:max_vcpu': '3'
        }
        test_attrs = dict(lpar_attrs,
                          dedicated_proc='true',
                          sharing_mode='sre idle procs active',
                          min_vcpu='1',
                          max_vcpu='3')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test shared proc sharing mode
        self.inst.flavor.extra_specs = {'powervm:uncapped': 'true'}
        test_attrs = dict(lpar_attrs, sharing_mode='uncapped')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test availability priority
        self.inst.flavor.extra_specs = {'powervm:availability_priority': '150'}
        test_attrs = dict(lpar_attrs, avail_priority='150')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test processor compatibility
        self.inst.flavor.extra_specs = {
            'powervm:processor_compatibility': 'POWER8'
        }
        test_attrs = dict(lpar_attrs, processor_compatibility='POWER8')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test min, max proc units
        self.inst.flavor.extra_specs = {
            'powervm:min_proc_units': '0.5',
            'powervm:max_proc_units': '2.0'
        }
        test_attrs = dict(lpar_attrs,
                          min_proc_units='0.5',
                          max_proc_units='2.0')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test min, max mem
        self.inst.flavor.extra_specs = {
            'powervm:min_mem': '1024',
            'powervm:max_mem': '4096'
        }
        test_attrs = dict(lpar_attrs, min_mem='1024', max_mem='4096')
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)
        self.san_lpar_name.assert_called_with(self.inst.name)
        self.san_lpar_name.reset_mock()

        # Test remote restart set to false
        self.inst.flavor.extra_specs = {'powervm:srr_capability': 'false'}
        test_attrs = dict(lpar_attrs, srr_capability=False)
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)

        # Unhandled powervm: key is ignored
        self.inst.flavor.extra_specs = {
            'powervm:srr_capability': 'false',
            'powervm:something_new': 'foo'
        }
        test_attrs = dict(lpar_attrs, srr_capability=False)
        self.assertEqual(self.lpar_b._format_flavor(self.inst), test_attrs)

        # If we recognize a key, but don't handle it, we raise
        with mock.patch.object(self.lpar_b,
                               '_is_pvm_valid_key',
                               return_value=True):
            self.inst.flavor.extra_specs = {
                'powervm:srr_capability': 'false',
                'powervm:something_new': 'foo'
            }
            self.assertRaises(KeyError, self.lpar_b._format_flavor, self.inst)
Example #17
0
    def test_builder(self):
        # Build the minimum attributes, Shared Procs
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1)
        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)
        bldr = lpar_bldr.LPARBuilder(self.adpt, attr, self.stdz_sys1)
        new_lpar = bldr.build()
        self.assert_xml(new_lpar, self.sections['shared_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-defaulted IO Slots and SRR
        attr = dict(name='TheName', memory=1024, max_io_slots=64,
                    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
        attr = dict(name='TheName', env=bp.LPARType.AIXLINUX, memory=1024,
                    vcpu=1, sharing_mode=bp.SharingMode.CAPPED,
                    srr_capability='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)

        # 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_sys1)
        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)

        # 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
        attr = dict(name='TheName', env=bp.LPARType.VIOS, 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['vios'])