on 2014/10/04 01:29, Aline Manera wrote:
On 09/30/2014 07:00 AM, Zhou Zheng Sheng wrote:
> + "devices_get_list": {
> + "type": "object",
> + "properties": {
> + "_cap": {
> + "description": "List specific type of
device",
> + "type": "string",
> + "pattern":
> "^fc_host|net|pci|scsi|scsi_host|storage|system|usb|usb_device$"
> + },
> + "_passthrough": {
> + "description": "List only devices eligible to be
> assigned to guest",
> + "type": "string",
> + "pattern": "^true|false$"
> + },
> + "_passthrough_affected_by": {
> + "description": "List the affected devices in the
> same group of a certain device to be assigned to guest",
> + "type": "string"
> + }
> + },
> + "additionalProperties": false
> + },
> + "vmhostdevs_create": {
> + "type": "object",
> + "properties": {
> + "name": {
> + "description": "Then name of the device to
assign
> to VM",
> + "type": "string",
> + "pattern": "^[_A-Za-z0-9-]+$",
> + "required": true
> + }
> + }
> }
You need to set "error" to each of those new parameters/structures.
Yes. Thank you for reminding this.
> +class MockNodeDevice(object):
> + dev_xmls = {
> + "computer": """
> +<device>
> + <name>computer</name>
> + <capability type='system'>
> + <product>4180XXX</product>
> + <hardware>
> + <vendor>LENOVO</vendor>
> + <version>ThinkPad T420</version>
> + <serial>PXXXXX</serial>
> + <uuid>9d660370-820f-4241-8731-5a60c97e8aa6</uuid>
> + </hardware>
> + <firmware>
> + <vendor>LENOVO</vendor>
> + <version>XXXXX (X.XX )</version>
> + <release_date>01/01/2012</release_date>
> + </firmware>
> + </capability>
> +</device>""",
> + "pci_0000_03_00_0": """
> +<device>
> + <name>pci_0000_03_00_0</name>
> + <path>/sys/devices/pci0000:00/0000:03:00.0</path>
> + <parent>computer</parent>
> + <driver>
> + <name>iwlwifi</name>
> + </driver>
> + <capability type='pci'>
> + <domain>0</domain>
> + <bus>3</bus>
> + <slot>0</slot>
> + <function>0</function>
> + <product id='0x0085'>Centrino Advanced-N 6205 [Taylor
> Peak]</product>
> + <vendor id='0x8086'>Intel Corporation</vendor>
> + <iommuGroup number='7'>
> + <address domain='0x0000' bus='0x00' slot='0x1c'
function='0x0'/>
> + <address domain='0x0000' bus='0x00' slot='0x1c'
function='0x1'/>
> + <address domain='0x0000' bus='0x00' slot='0x1c'
function='0x3'/>
> + <address domain='0x0000' bus='0x00' slot='0x1c'
function='0x4'/>
> + <address domain='0x0000' bus='0x03' slot='0x00'
function='0x0'/>
> + <address domain='0x0000' bus='0x0d' slot='0x00'
function='0x0'/>
> + </iommuGroup>
> + </capability>
> +</device>""",
> + "pci_0000_0d_00_0": """
> +<device>
> + <name>pci_0000_0d_00_0</name>
> + <path>/sys/devices/pci0000:00/0000:0d:00.0</path>
> + <parent>computer</parent>
> + <driver>
> + <name>sdhci-pci</name>
> + </driver>
> + <capability type='pci'>
> + <domain>0</domain>
> + <bus>13</bus>
> + <slot>0</slot>
> + <function>0</function>
> + <product id='0xe823'>PCIe SDXC/MMC Host
Controller</product>
> + <vendor id='0x1180'>Ricoh Co Ltd</vendor>
> + <iommuGroup number='7'>
> + <address domain='0x0000' bus='0x00' slot='0x1c'
function='0x0'/>
> + <address domain='0x0000' bus='0x00' slot='0x1c'
function='0x1'/>
> + <address domain='0x0000' bus='0x00' slot='0x1c'
function='0x3'/>
> + <address domain='0x0000' bus='0x00' slot='0x1c'
function='0x4'/>
> + <address domain='0x0000' bus='0x03' slot='0x00'
function='0x0'/>
> + <address domain='0x0000' bus='0x0d' slot='0x00'
function='0x0'/>
> + </iommuGroup>
> + </capability>
> +</device>""",
> + }
> + for i in range(3):
> + dev_xmls['scsi_host%s' % i] = """
> +<device>
> + <name>scsi_host%(ind)s</name>
> + <path>/sys/devices/pci0000:00/0000:40:00.0/%(ind)s</path>
> + <parent>computer</parent>
> + <capability type='scsi_host'>
> + <host>0</host>
> + <capability type='fc_host'>
> + <wwnn>%(wwnn)s</wwnn>
> + <wwpn>%(wwpn)s</wwpn>
> + <fabric_wwn>%(fabric_wwn)s</fabric_wwn>
> + </capability>
> + </capability>
> +</device>""" % {"ind": i,
> + "wwnn": uuid.uuid4().hex[:16],
> + "wwpn": uuid.uuid4().hex[:16],
> + "fabric_wwn": uuid.uuid4().hex[:16]}
> +
> + def __init__(self, dev_name):
> + self._dev_name = dev_name
> +
> + def XMLDesc(self, flag=0):
> + return MockNodeDevice.dev_xmls[self._dev_name]
> +
> + def parent(self):
> + return None if self._dev_name == 'computer' else 'computer'
> +
> +
> +class MockDevices(object):
> + def __init__(self):
> + self.devices = {}
> + dev_xmls = MockNodeDevice.dev_xmls
> + for dev_name, dev_xml in dev_xmls.items():
> + self.devices[dev_name] = \
> + hostdev.get_dev_info(MockNodeDevice(dev_name))
> +
Wow! I don't think we need all that for the mockmodel.
I mean, you can get the values and input them on a dict, instead of
having the XML and parse them.
Example:
self.devices['my-dev'] = {...}
self.devices['my-dev2'] = {...}
self.devices['my-dev3'] = {...}
OK. I just thought using XML can also test the XML parsing part and see
if all the parts can glue and work together. I'll use dict directly.
Thank you.