Browse Source

Move the guest.get_disk test to test_guest

As a follow up of I86153d31b02e6b74b42d53a6800297cbd0e5cbb4 the two
get_disk test that was mistakenly added to test_driver is now moved to
test_guest where they belong.

Change-Id: I17bd591ffb96b9b296bea04c87e286a83d40570e
Related-Bug: #1882521
(cherry picked from commit 52d6cd941c)
changes/21/788721/2
Balazs Gibizer 4 months ago
parent
commit
5f488d8cd1
2 changed files with 77 additions and 77 deletions
  1. +0
    -77
      nova/tests/unit/virt/libvirt/test_driver.py
  2. +77
    -0
      nova/tests/unit/virt/libvirt/test_guest.py

+ 0
- 77
nova/tests/unit/virt/libvirt/test_driver.py View File

@ -24631,83 +24631,6 @@ class LibvirtDriverTestCase(test.NoDBTestCase, TraitsComparisonMixin):
instance = objects.Instance(uuid=uuids.instance, id=1)
self.assertTrue(drvr.instance_on_disk(instance))
def test_get_disk_xml(self):
dom_xml = """
<domain type="kvm">
<devices>
<disk type="file">
<source file="disk1_file"/>
<target dev="vda" bus="virtio"/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>
<disk type="block">
<source dev="/path/to/dev/1"/>
<target dev="vdb" bus="virtio" serial="1234"/>
</disk>
</devices>
</domain>
"""
diska_xml = """<disk type="file" device="disk">
<source file="disk1_file"/>
<target bus="virtio" dev="vda"/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>"""
diskb_xml = """<disk type="block" device="disk">
<source dev="/path/to/dev/1"/>
<target bus="virtio" dev="vdb"/>
</disk>"""
dom = mock.MagicMock()
dom.XMLDesc.return_value = dom_xml
guest = libvirt_guest.Guest(dom)
# NOTE(gcb): etree.tostring(node) returns an extra line with
# some white spaces, need to strip it.
actual_diska_xml = guest.get_disk('vda').to_xml()
self.assertXmlEqual(diska_xml, actual_diska_xml)
actual_diskb_xml = guest.get_disk('vdb').to_xml()
self.assertXmlEqual(diskb_xml, actual_diskb_xml)
self.assertIsNone(guest.get_disk('vdc'))
dom.XMLDesc.assert_has_calls([mock.call(0)] * 3)
def test_get_disk_xml_from_persistent_config(self):
dom_xml = """
<domain type="kvm">
<devices>
<disk type="file">
<source file="disk1_file"/>
<target dev="vda" bus="virtio"/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>
<disk type="block">
<source dev="/path/to/dev/1"/>
<target dev="vdb" bus="virtio" serial="1234"/>
</disk>
</devices>
</domain>
"""
diska_xml = """<disk type="file" device="disk">
<source file="disk1_file"/>
<target bus="virtio" dev="vda"/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>"""
dom = mock.MagicMock()
dom.XMLDesc.return_value = dom_xml
guest = libvirt_guest.Guest(dom)
actual_diska_xml = guest.get_disk(
'vda', from_persistent_config=True).to_xml()
self.assertXmlEqual(diska_xml, actual_diska_xml)
dom.XMLDesc.assert_called_once_with(
fakelibvirt.VIR_DOMAIN_XML_INACTIVE)
def test_vcpu_model_from_config(self):
drv = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
vcpu_model = drv._cpu_config_to_vcpu_model(None, None)


+ 77
- 0
nova/tests/unit/virt/libvirt/test_guest.py View File

@ -624,6 +624,83 @@ class GuestTestCase(test.NoDBTestCase):
vconfig.NOVA_NS, flags=fakelibvirt.VIR_DOMAIN_AFFECT_LIVE |
fakelibvirt.VIR_DOMAIN_AFFECT_CONFIG)
def test_get_disk_xml(self):
dom_xml = """
<domain type="kvm">
<devices>
<disk type="file">
<source file="disk1_file"/>
<target dev="vda" bus="virtio"/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>
<disk type="block">
<source dev="/path/to/dev/1"/>
<target dev="vdb" bus="virtio" serial="1234"/>
</disk>
</devices>
</domain>
"""
diska_xml = """<disk type="file" device="disk">
<source file="disk1_file"/>
<target bus="virtio" dev="vda"/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>"""
diskb_xml = """<disk type="block" device="disk">
<source dev="/path/to/dev/1"/>
<target bus="virtio" dev="vdb"/>
</disk>"""
dom = mock.MagicMock()
dom.XMLDesc.return_value = dom_xml
guest = libvirt_guest.Guest(dom)
# NOTE(gcb): etree.tostring(node) returns an extra line with
# some white spaces, need to strip it.
actual_diska_xml = guest.get_disk('vda').to_xml()
self.assertXmlEqual(diska_xml, actual_diska_xml)
actual_diskb_xml = guest.get_disk('vdb').to_xml()
self.assertXmlEqual(diskb_xml, actual_diskb_xml)
self.assertIsNone(guest.get_disk('vdc'))
dom.XMLDesc.assert_has_calls([mock.call(0)] * 3)
def test_get_disk_xml_from_persistent_config(self):
dom_xml = """
<domain type="kvm">
<devices>
<disk type="file">
<source file="disk1_file"/>
<target dev="vda" bus="virtio"/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>
<disk type="block">
<source dev="/path/to/dev/1"/>
<target dev="vdb" bus="virtio" serial="1234"/>
</disk>
</devices>
</domain>
"""
diska_xml = """<disk type="file" device="disk">
<source file="disk1_file"/>
<target bus="virtio" dev="vda"/>
<serial>0e38683e-f0af-418f-a3f1-6b67ea0f919d</serial>
</disk>"""
dom = mock.MagicMock()
dom.XMLDesc.return_value = dom_xml
guest = libvirt_guest.Guest(dom)
actual_diska_xml = guest.get_disk(
'vda', from_persistent_config=True).to_xml()
self.assertXmlEqual(diska_xml, actual_diska_xml)
dom.XMLDesc.assert_called_once_with(
fakelibvirt.VIR_DOMAIN_XML_INACTIVE)
class GuestBlockTestCase(test.NoDBTestCase):


Loading…
Cancel
Save