Ejemplo n.º 1
0
 def test_tag_namespace(self):
     el = ent.Element('tag', self.adpt)
     self.assertEqual(
         el.element.tag, '{http://www.ibm.com/xmlns/systems/po'
         'wer/firmware/uom/mc/2012_10/}tag')
     # entities.Element.tag strips the namespace
     self.assertEqual(el.tag, 'tag')
     self.assertEqual(
         el.namespace, 'http://www.ibm.com/xmlns/systems/powe'
         'r/firmware/uom/mc/2012_10/')
     # Test setter
     el.tag = 'gat'
     self.assertEqual(
         el.element.tag, '{http://www.ibm.com/xmlns/systems/po'
         'wer/firmware/uom/mc/2012_10/}gat')
     self.assertEqual(el.tag, 'gat')
     el.namespace = 'foo'
     self.assertEqual(el.namespace, 'foo')
     # Now with no namespace
     el = ent.Element('tag', self.adpt, ns='')
     self.assertEqual(el.element.tag, 'tag')
     self.assertEqual(el.tag, 'tag')
     self.assertEqual(el.namespace, '')
     el.tag = 'gat'
     self.assertEqual(el.element.tag, 'gat')
     self.assertEqual(el.tag, 'gat')
     el.namespace = 'foo'
     self.assertEqual(el.namespace, 'foo')
Ejemplo n.º 2
0
 def test_cdata(self):
     no_cdata = ent.Element('tag', self.adpt, text='text', cdata=False)
     with_cdata = ent.Element('tag', self.adpt, text='text', cdata=True)
     self.assertEqual(
         no_cdata.toxmlstring(),
         '<uom:tag xmlns:uom="http://www.ibm.com/xmlns/systems/power/'
         'firmware/uom/mc/2012_10/">text</uom:tag>'.encode('utf-8'))
     self.assertEqual(
         with_cdata.toxmlstring(),
         '<uom:tag xmlns:uom="http://www.ibm.com/xmlns/systems/power/firmwa'
         're/uom/mc/2012_10/"><![CDATA[text]]></uom:tag>'.encode('utf-8'))
Ejemplo n.º 3
0
 def test_subelement_not_in_ordering_list(self):
     """Subelement not in ordering list - should append."""
     el = self._mk_el(self.all_children)
     ch = ent.Element('SomeNewElement', self.adpt, text='foo')
     el.inject(ch, ordering_list=self.ordering_list)
     self.assert_expected_children(el, self.child_at, self.child_unasi,
                                   self.child_rlpi1, self.child_rsn, ch)
Ejemplo n.º 4
0
    def create_job_parameter(name, value, cdata=False):
        """Creates a JobParameter Element.

           :param name: ParameterName text value
           :param value: ParameterValue text value
           :param cdata: If True, the value text will be wrapped in CDATA tags
           :returns: JobParameter Element
        """
        # JobParameter doesn't need adapter today
        adapter = None

        job_parm = ent.Element('JobParameter', adapter,
                               attrib={'schemaVersion': 'V1_0'},
                               ns=pc.WEB_NS)
        job_parm.append(ent.Element('ParameterName', adapter,
                                    text=name, ns=pc.WEB_NS))
        job_parm.append(ent.Element('ParameterValue', adapter,
                                    text=value, ns=pc.WEB_NS, cdata=cdata))
        return job_parm
Ejemplo n.º 5
0
    def _target_dev(self, vtd):
        """Sets the target device of this mapping.

        :param vtd: A {storage_type}TargetDev ElementWrapper representing the
                    virtual target device to assign.
        """
        vtd_elem = ent.Element(_MAP_TARGET_DEV, self.adapter, attrib={},
                               children=[])
        vtd_elem.inject(vtd.element)
        self.inject(vtd_elem)
Ejemplo n.º 6
0
 def setUp(self):
     super(TestMigration, self).setUp()
     self.adpt = self.useFixture(fx.AdapterFx()).adpt
     mock_resp = mock.MagicMock()
     mock_resp.entry = ent.Entry({}, ent.Element('Dummy', self.adpt),
                                 self.adpt)
     self.adpt.read.return_value = mock_resp
     self.lpar_w = mock.MagicMock()
     self.lpar_w.adapter = self.adpt
     self.lpar_w.uuid = '1234'
Ejemplo n.º 7
0
 def test_repos_pv(self):
     repos = self.dwrap.repos_pv
     # PV is tested elsewhere.  Minimal verification here.
     self.assertEqual(repos.name, 'hdisk2')
     # Test setter
     newrepos = stor.PV.wrap(
         ent.Element(
             "PhysicalVolume", None,
             attrib={'schemaVersion': 'V1_2_0'},
             children=[
                 ent.Element('Metadata', None,
                             children=[ent.Element('Atom', None)]),
                 ent.Element('VolumeName', None, text='hdisk99')]))
     self.dwrap.repos_pv = newrepos
     self.assertEqual(self.dwrap.repos_pv.name, 'hdisk99')
     # Now try the same thing, but using factory constructor to build PV
     newrepos = stor.PV.bld(None, name='hdisk123')
     self.dwrap.repos_pv = newrepos
     self.assertAlmostEqual(self.dwrap.repos_pv.name, 'hdisk123')
Ejemplo n.º 8
0
    def _backing_device(self, eth_back_dev):
        """The BackingDeviceChoice for this SEA.

        :param eth_back_dev: The EthernetBackingDevice for this
                             BackingDeviceChoice.
        """
        stor_elem = ent.Element(_SEA_BACKING_DEV,
                                self.adapter,
                                attrib={},
                                children=[])
        stor_elem.inject(eth_back_dev.element)
        self.inject(stor_elem)
Ejemplo n.º 9
0
    def backing_storage(self, stg):
        """Sets the backing storage of this mapping to a VDisk, VOpt, LU or PV.

        :param stg: Either a VDisk, VOpt, LU or PV wrapper representing the
                    backing storage to assign.
        """
        # Always replace.  Because while the storage has one element, it can't
        # inject properly if the backing type changes (ex. cloning from vOpt to
        # vDisk).
        stor_elem = ent.Element(_MAP_STORAGE, self.adapter, attrib={},
                                children=[])
        stor_elem.inject(stg.element)
        self.inject(stor_elem)
Ejemplo n.º 10
0
    def test_clone_uuid(self, mock_run_job):

        mock_resp = mock.MagicMock()
        mock_resp.entry = ent.Entry(
            {}, ent.Element('Dummy', self.adpt), self.adpt)
        self.adpt.read.side_effect = [mock_resp]
        mock_run_job.side_effect = tju.get_parm_checker(
            self, '1234', [('targetLparName', 'abc')])
        tpar.clone_uuid(self.adpt, '1234', 'abc')
        self.adpt.read.assert_called_once_with('LogicalPartition',
                                               root_id='1234',
                                               suffix_type='do',
                                               suffix_parm='CloneUUID')
Ejemplo n.º 11
0
 def test_close_vterm_non_local(self, mock_run_job):
     """Performs a close LPAR vterm test."""
     mock_resp = mock.MagicMock()
     mock_resp.entry = ent.Entry({}, ent.Element('Dummy', self.adpt),
                                 self.adpt)
     self.adpt.read.return_value = mock_resp
     vterm._close_vterm_non_local(self.adpt, '12345')
     self.assertEqual(1, mock_run_job.call_count)
     self.assertEqual(1, self.adpt.read.call_count)
     # test exception path
     mock_run_job.side_effect = pexc.LPARNotFound(lpar_name='12345')
     self.assertRaises(pexc.LPARNotFound, vterm._close_vterm_non_local,
                       self.adpt, '12345')
     mock_run_job.reset_mock()
Ejemplo n.º 12
0
    def _rebuild_vnet_list(self):
        """A callback from the Load Group to rebuild the virtual network list.

        Needed due to the API using both the LoadGroup and Network Bridge
        as a source.  But usage at an API level should be through Load
        Groups.
        """
        # Find all the children Virtual Networks.
        search = u.xpath(_NB_LGS, _NB_LG, _NB_VNETS, c.LINK)
        new_vnets = copy.deepcopy(self.element.findall(search))
        # Find and replace the current element.
        cur_vnets = self.element.find(_NB_VNETS)
        self.element.replace(
            cur_vnets, ent.Element(_NB_VNETS, self.adapter,
                                   children=new_vnets))
Ejemplo n.º 13
0
    def test_element_iter(self):
        """Test the ETElement iter() method found in the Adapter class."""

        # Init test data
        children = [
            ent.Element('Type1', None, text='T1_0'),
            ent.Element('Type12', None, text='T12_0'),
            ent.Element('Type1', None, text='T1_1'),
            ent.Element('Type12', None, text='T12_1'),
            ent.Element('Type1', None, text='T1_2')
        ]
        top_element = ent.Element('Top',
                                  None,
                                  attrib={'schemaVersion': 'V1_0'},
                                  children=children)

        def _count_elem(top, tag, it=None, assert_tag=True):
            elem_count = 0
            it = it if it else top.iter(tag=tag)
            for elem in it:
                if assert_tag:
                    self.assertEqual(elem.tag, tag)
                elem_count += 1
            return elem_count

        # Run the actual tests

        # Ensure all elements are traversed if we don't specify a tag
        self.assertEqual(
            _count_elem(top_element,
                        'Type1',
                        it=top_element.iter(),
                        assert_tag=False), 6)

        # Ensure all elements are traversed for tag=*
        self.assertEqual(
            _count_elem(top_element,
                        'Type1',
                        it=top_element.iter(tag='*'),
                        assert_tag=False), 6)

        # Ensure all elements are traversed for tag=None
        self.assertEqual(
            _count_elem(top_element,
                        'Type1',
                        it=top_element.iter(tag=None),
                        assert_tag=False), 6)

        # Get only the Type1 elements
        self.assertEqual(_count_elem(top_element, 'Type1'), 3)

        # Get only the top
        self.assertEqual(_count_elem(top_element, 'Top'), 1)
Ejemplo n.º 14
0
 def setUp(self):
     super(TestElementInject, self).setUp()
     self.adpt = self.useFixture(fx.AdapterFx()).adpt
     self.ordering_list = ('AdapterType', 'UseNextAvailableSlotID',
                           'RemoteLogicalPartitionID', 'RemoteSlotNumber')
     self.child_at = ent.Element('AdapterType', self.adpt, text='Client')
     self.child_unasi = ent.Element('UseNextAvailableSlotID',
                                    self.adpt,
                                    text='true')
     self.child_rlpi1 = ent.Element('RemoteLogicalPartitionID',
                                    self.adpt,
                                    text='1')
     self.child_rlpi2 = ent.Element('RemoteLogicalPartitionID',
                                    self.adpt,
                                    text='2')
     self.child_rlpi3 = ent.Element('RemoteLogicalPartitionID',
                                    self.adpt,
                                    text='3')
     self.child_rsn = ent.Element('RemoteSlotNumber', self.adpt, text='12')
     self.all_children = [
         self.child_at, self.child_unasi, self.child_rlpi1, self.child_rsn
     ]
Ejemplo n.º 15
0
 def setUp(self):
     super(TestMemory, self).setUp()
     entry = ent.Entry({}, ent.Element('Dummy', None), None)
     self.mock_job = job.Job(entry)
     self.adpt = self.useFixture(fx.AdapterFx()).adpt
Ejemplo n.º 16
0
 def _mk_el(self, children):
     return ent.Element('VirtualSCSIClientAdapter',
                        self.adpt,
                        attrib={'schemaVersion': 'V1_0'},
                        children=children)
Ejemplo n.º 17
0
 def setUp(self):
     super(TestPower, self).setUp()
     mock_resp = mock.MagicMock()
     mock_resp.entry = ent.Entry({}, ent.Element('Dummy', None), None)
     self.adpt = self.useFixture(fx.AdapterFx()).adpt
     self.adpt.read.return_value = mock_resp
Ejemplo n.º 18
0
def _lua_recovery_xml(itls, adapter, vendor=LUAType.OTHER):
    """Builds the XML that is used as input for the lua_recovery job.

    The lua_recovery provides a very quick way for the system to discover
    an hdisk on the system.  This method builds the input into the lua_recovery
    job.
    :param itls: The list of ITL objects that define the various connections
                 between the server port (initiator), disk port (target) and
                 disk itself.
    :param vendor: The LUA vendor.  See the LUAType.* Constants.
    :return: The CDATA XML that is used for the lua_recovery job.
    """
    # Used for building the internal XML.

    root = ent.Element("XML_LIST", adapter, ns='')

    # The general attributes
    # TODO(IBM) Need to determine value of making these constants modifiable
    general = ent.Element("general", adapter, ns='')
    general.append(ent.Element("cmd_version", adapter, text=_LUA_CMD_VERSION,
                               ns=''))
    general.append(ent.Element("version", adapter, text=_LUA_VERSION, ns=''))
    root.append(general)

    # TODO(IBM) This can be re-evaluated.  Set to true if you know for sure
    # the ITLs are alive.  If there are any bad ITLs, this should be false.
    root.append(ent.Element("reliableITL", adapter, text="false", ns=''))

    # There is only one device in the device list.
    device_list = ent.Element("deviceList", adapter, ns='')
    device = ent.Element("device", adapter, ns='')
    device.append(ent.Element("vendor", adapter, text=vendor, ns=''))
    device.append(ent.Element("deviceTag", adapter, text="1", ns=''))

    itl_list = ent.Element("itlList", adapter, ns='')
    itl_list.append(ent.Element("number", adapter, text="%d" % (len(itls)),
                                ns=''))

    for itl in itls:
        itl_elem = ent.Element("itl", adapter, ns='')

        itl_elem.append(ent.Element("Iwwpn", adapter, text=itl.initiator,
                                    ns=''))
        itl_elem.append(ent.Element("Twwpn", adapter, text=itl.target, ns=''))
        itl_elem.append(ent.Element("lua", adapter, text=itl.lun, ns=''))

        itl_list.append(itl_elem)

    device.append(itl_list)
    device_list.append(device)
    root.append(device_list)

    return root.toxmlstring().decode('utf-8')