Disk: add new dataStore element to disk.py#4052
Disk: add new dataStore element to disk.py#4052Yingshun merged 1 commit intoavocado-framework:masterfrom
Conversation
|
| def new_datastore(self, **dargs): | ||
| """ | ||
| Return a new disk datastore instance and set properties from dargs | ||
| """ | ||
| new_one = self.dataStore(virsh_instance=self.virsh) | ||
| for key, value in list(dargs.items()): | ||
| setattr(new_one, key, value) | ||
| return new_one | ||
|
|
There was a problem hiding this comment.
This function is actually unnecessary now
| """ | ||
|
|
||
| __slots__ = ("attrs", "dev", "protocol", "name", "host", "file", "auth") | ||
| __slots__ = ("attrs", "protocol", "name", "host", "auth", "datastore") |
There was a problem hiding this comment.
Seems 'dev' was removed from slots , but not it's accessor.
And I'm also worried if it's going to cause error if we delete 'dev' and 'file', are they being used by some test code?
There was a problem hiding this comment.
I didn't consider that other functions would use them. So in case I don't plan to delete them.
| def new_source(self, **dargs): | ||
| """ | ||
| Create new source for dataStore | ||
|
|
||
| """ | ||
| new_one = self.Source(virsh_instance=self.virsh) | ||
| for key, value in list(dargs.items()): | ||
| setattr(new_one, key, value) | ||
| return new_one |
There was a problem hiding this comment.
This function could be removed too, we're using setup_attrs(), this kind of function is no longer necessary.
1efbebe to
35be472
Compare
| accessors.XMLElementNest( | ||
| "datastore", | ||
| self, | ||
| parent_xpath="/", | ||
| tag_name="dataStore", | ||
| subclass=Disk.dataStore, | ||
| subclass_dargs={"virsh_instance": virsh_instance}, | ||
| ) |
There was a problem hiding this comment.
@meinaLi Can you plz provide a test result of this part? I didn't find it in your previous results.
BTW, for new changes in xml part, it's better to have a result of setup_attrs(). can you plz also provide it? Thanks!
There was a problem hiding this comment.
This part is in Disk class which is incorrect. Because dataStore element is mainly placed in the DiskSource or Backingchain. So I've already removed it.
The test result related to setup_attrs():
>>> from virttest.libvirt_xml.devices import disk
>>> disk_dev = disk.Disk()
>>> disk_dict={'device': 'disk', 'source': {'attrs': {'file': '/path/to/datastore.qcow2'}, 'dataStore': {'format': {'type': 'raw'}, 'type': 'file', 'source': {'attrs': {'file': '/path/to/datastore'}}}}, 'target': {'dev': 'vdh', 'bus': 'virtio'}, 'type_name': 'file', 'backingstore': {'type': 'file', 'format': {'type': 'qcow2'}, 'source': {'attrs': {'file': '/var/lib/libvirt/images/base-with-data-file.qcow'}, 'file': '/var/lib/libvirt/images/base-with-data-file.qcow', 'datastore': {'format': {'type': 'raw'}, 'type': 'block', 'source': {'attrs': {'dev': '/dev/mapper/base2'}}}}}, 'driver': {'name': 'qemu', 'type': 'qcow2'}}
>>> disk_dev.setup_attrs(**disk_dict)
>>> disk_dev.xml
'/tmp/xml_utils_temp_yhn4b_bv.xml'
# cat /tmp/xml_utils_temp_yhn4b_bv.xml
<disk type="file" device="disk"><source file="/path/to/datastore.qcow2"><dataStore type="file"><format type="raw" /><source file="/path/to/datastore" /></dataStore></source><target dev="vdh" bus="virtio" /><backingStore type="file"><format type="qcow2" /><source file="/var/lib/libvirt/images/base-with-data-file.qcow"><dataStore type="block"><format type="raw" /><source dev="/dev/mapper/base2" /></dataStore></source></backingStore><driver name="qemu" type="qcow2" /></disk>
There was a problem hiding this comment.
Because the above disk_dict has a bug with XML error: The
Added the test result of attaching disk:
>>> from virttest.libvirt_xml.devices import disk
>>> disk_dev = disk.Disk()
>>> disk_dict={'device': 'disk', 'source': {'attrs': {'file': '/var/lib/libvirt/images/datastore.qcow2'}}, 'target': {'dev': 'vdh', 'bus': 'virtio'}, 'type_name': 'file', 'backingstore': {'type': 'file', 'format': {'type': 'qcow2'}, 'source': {'attrs': {'file': '/var/lib/libvirt/images/base-with-data-file.qcow'}, 'file': '/var/lib/libvirt/images/base-with-data-file.qcow', 'datastore': {'format': {'type': 'raw'}, 'type': 'file', 'source': {'attrs': {'file': '/var/lib/libvirt/images/datastore_1'}}}}}, 'driver': {'name': 'qemu', 'type': 'qcow2'}}
>>> disk_dev.setup_attrs(**disk_dict)
>>> from virttest import virsh
>>> virsh.attach_device("avocado-vt-vm1", disk_dev.xml, debug=True, ignore_status=False)
<avocado.utils.process.CmdResult object at 0x7f260c51da30>
The disk xml is attached to the guest:
# virsh dumpxml avocado-vt-vm1 --xpath //disk
......
<disk type="file" device="disk">
<driver name="qemu" type="qcow2"/>
<source file="/var/lib/libvirt/images/datastore.qcow2" index="2"/>
<backingStore type="file" index="3">
<format type="qcow2"/>
<source file="/var/lib/libvirt/images/base-with-data-file.qcow">
<dataStore type="file">
<format type="raw"/>
<source file="/var/lib/libvirt/images/datastore_1" index="4"/>
</dataStore>
</source>
<backingStore/>
</backingStore>
<target dev="vdh" bus="virtio"/>
<alias name="virtio-disk7"/>
<address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
</disk>
Now a new element dataStore has been implemented. So add it to disk.py. Signed-off-by: meinaLi <meili@redhat.com>
Now a new element dataStore has been implemented. So add it to disk.py.