How to use assertXMLEqual method in pytest-django

Best Python code snippet using pytest-django_python

test_config.py

Source:test_config.py Github

copy

Full Screen

1# Copyright (C) 2012 Red Hat, Inc.2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.14from lxml import etree15from oslo_utils import units16from nova.compute import arch17from nova import test18from nova.tests.unit import matchers19from nova.virt.libvirt import config20class LibvirtConfigBaseTest(test.NoDBTestCase):21 def assertXmlEqual(self, expectedXmlstr, actualXmlstr):22 self.assertThat(actualXmlstr, matchers.XMLMatches(expectedXmlstr))23class LibvirtConfigTest(LibvirtConfigBaseTest):24 def test_config_plain(self):25 obj = config.LibvirtConfigObject(root_name="demo")26 xml = obj.to_xml()27 self.assertXmlEqual(xml, "<demo/>")28 def test_config_ns(self):29 obj = config.LibvirtConfigObject(root_name="demo", ns_prefix="foo",30 ns_uri="http://example.com/foo")31 xml = obj.to_xml()32 self.assertXmlEqual(xml, """33 <foo:demo xmlns:foo="http://example.com/foo"/>""")34 def test_config_text(self):35 obj = config.LibvirtConfigObject(root_name="demo")36 root = obj.format_dom()37 root.append(obj._text_node("foo", "bar"))38 xml = etree.tostring(root)39 self.assertXmlEqual(xml, "<demo><foo>bar</foo></demo>")40 def test_config_text_unicode(self):41 obj = config.LibvirtConfigObject(root_name='demo')42 root = obj.format_dom()43 root.append(obj._text_node('foo', u'\xF0\x9F\x92\xA9'))44 self.assertXmlEqual('<demo><foo>&#240;&#159;&#146;&#169;</foo></demo>',45 etree.tostring(root))46 def test_config_parse(self):47 inxml = "<demo><foo/></demo>"48 obj = config.LibvirtConfigObject(root_name="demo")49 obj.parse_str(inxml)50class LibvirtConfigCapsTest(LibvirtConfigBaseTest):51 def test_config_host(self):52 xmlin = """53 <capabilities>54 <host>55 <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>56 <cpu>57 <arch>x86_64</arch>58 <model>Opteron_G3</model>59 <vendor>AMD</vendor>60 <topology sockets='1' cores='4' threads='1'/>61 <feature name='ibs'/>62 <feature name='osvw'/>63 </cpu>64 <topology>65 <cells num='2'>66 <cell id='0'>67 <memory unit='KiB'>4048280</memory>68 <pages unit='KiB' size='4'>1011941</pages>69 <pages unit='KiB' size='2048'>0</pages>70 <cpus num='4'>71 <cpu id='0' socket_id='0' core_id='0' siblings='0'/>72 <cpu id='1' socket_id='0' core_id='1' siblings='1'/>73 <cpu id='2' socket_id='0' core_id='2' siblings='2'/>74 <cpu id='3' socket_id='0' core_id='3' siblings='3'/>75 </cpus>76 </cell>77 <cell id='1'>78 <memory unit='KiB'>4127684</memory>79 <pages unit='KiB' size='4'>1031921</pages>80 <pages unit='KiB' size='2048'>0</pages>81 <cpus num='4'>82 <cpu id='4' socket_id='1' core_id='0' siblings='4'/>83 <cpu id='5' socket_id='1' core_id='1' siblings='5'/>84 <cpu id='6' socket_id='1' core_id='2' siblings='6'/>85 <cpu id='7' socket_id='1' core_id='3' siblings='7'/>86 </cpus>87 </cell>88 </cells>89 </topology>90 </host>91 <guest>92 <os_type>hvm</os_type>93 <arch name='x86_64'/>94 </guest>95 <guest>96 <os_type>hvm</os_type>97 <arch name='i686'/>98 </guest>99 </capabilities>"""100 obj = config.LibvirtConfigCaps()101 obj.parse_str(xmlin)102 self.assertIsInstance(obj.host, config.LibvirtConfigCapsHost)103 self.assertEqual(obj.host.uuid, "c7a5fdbd-edaf-9455-926a-d65c16db1809")104 xmlout = obj.to_xml()105 self.assertXmlEqual(xmlin, xmlout)106 def test_config_host_numa_cell_no_memory_caps(self):107 xmlin = """108 <cell id='0'>109 <cpus num='1'>110 <cpu id='0' socket_id='0' core_id='0' siblings='0'/>111 </cpus>112 </cell>"""113 obj = config.LibvirtConfigCapsNUMACell()114 obj.parse_str(xmlin)115 self.assertEqual(0, obj.memory)116 self.assertEqual(1, len(obj.cpus))117 def test_config_host_numa_cell_no_cpus_caps(self):118 xmlin = """119 <cell id='0'>120 <memory unit='KiB'>128</memory>121 </cell>"""122 obj = config.LibvirtConfigCapsNUMACell()123 obj.parse_str(xmlin)124 self.assertEqual(128, obj.memory)125 self.assertEqual(0, len(obj.cpus))126class LibvirtConfigGuestTimerTest(LibvirtConfigBaseTest):127 def test_config_platform(self):128 obj = config.LibvirtConfigGuestTimer()129 obj.track = "host"130 xml = obj.to_xml()131 self.assertXmlEqual(xml, """132 <timer name="platform" track="host"/>133 """)134 def test_config_pit(self):135 obj = config.LibvirtConfigGuestTimer()136 obj.name = "pit"137 obj.tickpolicy = "discard"138 xml = obj.to_xml()139 self.assertXmlEqual(xml, """140 <timer name="pit" tickpolicy="discard"/>141 """)142 def test_config_hpet(self):143 obj = config.LibvirtConfigGuestTimer()144 obj.name = "hpet"145 obj.present = False146 xml = obj.to_xml()147 self.assertXmlEqual(xml, """148 <timer name="hpet" present="no"/>149 """)150class LibvirtConfigGuestClockTest(LibvirtConfigBaseTest):151 def test_config_utc(self):152 obj = config.LibvirtConfigGuestClock()153 xml = obj.to_xml()154 self.assertXmlEqual(xml, """155 <clock offset="utc"/>156 """)157 def test_config_localtime(self):158 obj = config.LibvirtConfigGuestClock()159 obj.offset = "localtime"160 xml = obj.to_xml()161 self.assertXmlEqual(xml, """162 <clock offset="localtime"/>163 """)164 def test_config_timezone(self):165 obj = config.LibvirtConfigGuestClock()166 obj.offset = "timezone"167 obj.timezone = "EDT"168 xml = obj.to_xml()169 self.assertXmlEqual(xml, """170 <clock offset="timezone" timezone="EDT"/>171 """)172 def test_config_variable(self):173 obj = config.LibvirtConfigGuestClock()174 obj.offset = "variable"175 obj.adjustment = "123456"176 xml = obj.to_xml()177 self.assertXmlEqual(xml, """178 <clock offset="variable" adjustment="123456"/>179 """)180 def test_config_timers(self):181 obj = config.LibvirtConfigGuestClock()182 tmpit = config.LibvirtConfigGuestTimer()183 tmpit.name = "pit"184 tmpit.tickpolicy = "discard"185 tmrtc = config.LibvirtConfigGuestTimer()186 tmrtc.name = "rtc"187 tmrtc.tickpolicy = "merge"188 obj.add_timer(tmpit)189 obj.add_timer(tmrtc)190 xml = obj.to_xml()191 self.assertXmlEqual(xml, """192 <clock offset="utc">193 <timer name="pit" tickpolicy="discard"/>194 <timer name="rtc" tickpolicy="merge"/>195 </clock>196 """)197class LibvirtConfigCPUFeatureTest(LibvirtConfigBaseTest):198 def test_config_simple(self):199 obj = config.LibvirtConfigCPUFeature("mtrr")200 xml = obj.to_xml()201 self.assertXmlEqual(xml, """202 <feature name="mtrr"/>203 """)204class LibvirtConfigGuestCPUFeatureTest(LibvirtConfigBaseTest):205 def test_config_simple(self):206 obj = config.LibvirtConfigGuestCPUFeature("mtrr")207 obj.policy = "force"208 xml = obj.to_xml()209 self.assertXmlEqual(xml, """210 <feature name="mtrr" policy="force"/>211 """)212class LibvirtConfigGuestCPUNUMATest(LibvirtConfigBaseTest):213 def test_parse_dom(self):214 xml = """215 <numa>216 <cell id="0" cpus="0-1" memory="1000000"/>217 <cell id="1" cpus="2-3" memory="1500000"/>218 </numa>219 """220 xmldoc = etree.fromstring(xml)221 obj = config.LibvirtConfigGuestCPUNUMA()222 obj.parse_dom(xmldoc)223 self.assertEqual(2, len(obj.cells))224 def test_config_simple(self):225 obj = config.LibvirtConfigGuestCPUNUMA()226 cell = config.LibvirtConfigGuestCPUNUMACell()227 cell.id = 0228 cell.cpus = set([0, 1])229 cell.memory = 1000000230 cell.memAccess = "shared"231 obj.cells.append(cell)232 cell = config.LibvirtConfigGuestCPUNUMACell()233 cell.id = 1234 cell.cpus = set([2, 3])235 cell.memory = 1500000236 cell.memAccess = "private"237 obj.cells.append(cell)238 xml = obj.to_xml()239 self.assertXmlEqual(xml, """240 <numa>241 <cell id="0" cpus="0-1" memory="1000000" memAccess="shared"/>242 <cell id="1" cpus="2-3" memory="1500000" memAccess="private"/>243 </numa>244 """)245class LibvirtConfigCPUTest(LibvirtConfigBaseTest):246 def test_config_simple(self):247 obj = config.LibvirtConfigCPU()248 obj.model = "Penryn"249 xml = obj.to_xml()250 self.assertXmlEqual(xml, """251 <cpu>252 <model>Penryn</model>253 </cpu>254 """)255 def test_config_complex(self):256 obj = config.LibvirtConfigCPU()257 obj.model = "Penryn"258 obj.vendor = "Intel"259 obj.arch = arch.X86_64260 obj.add_feature(config.LibvirtConfigCPUFeature("mtrr"))261 obj.add_feature(config.LibvirtConfigCPUFeature("apic"))262 xml = obj.to_xml()263 self.assertXmlEqual(xml, """264 <cpu>265 <arch>x86_64</arch>266 <model>Penryn</model>267 <vendor>Intel</vendor>268 <feature name="apic"/>269 <feature name="mtrr"/>270 </cpu>271 """)272 def test_only_uniq_cpu_featues(self):273 obj = config.LibvirtConfigCPU()274 obj.model = "Penryn"275 obj.vendor = "Intel"276 obj.arch = arch.X86_64277 obj.add_feature(config.LibvirtConfigCPUFeature("mtrr"))278 obj.add_feature(config.LibvirtConfigCPUFeature("apic"))279 obj.add_feature(config.LibvirtConfigCPUFeature("apic"))280 obj.add_feature(config.LibvirtConfigCPUFeature("mtrr"))281 xml = obj.to_xml()282 self.assertXmlEqual(xml, """283 <cpu>284 <arch>x86_64</arch>285 <model>Penryn</model>286 <vendor>Intel</vendor>287 <feature name="apic"/>288 <feature name="mtrr"/>289 </cpu>290 """)291 def test_config_topology(self):292 obj = config.LibvirtConfigCPU()293 obj.model = "Penryn"294 obj.sockets = 4295 obj.cores = 4296 obj.threads = 2297 xml = obj.to_xml()298 self.assertXmlEqual(xml, """299 <cpu>300 <model>Penryn</model>301 <topology sockets="4" cores="4" threads="2"/>302 </cpu>303 """)304class LibvirtConfigGuestCPUTest(LibvirtConfigBaseTest):305 def test_config_simple(self):306 obj = config.LibvirtConfigGuestCPU()307 obj.model = "Penryn"308 xml = obj.to_xml()309 self.assertXmlEqual(xml, """310 <cpu match="exact">311 <model>Penryn</model>312 </cpu>313 """)314 def test_config_complex(self):315 obj = config.LibvirtConfigGuestCPU()316 obj.model = "Penryn"317 obj.vendor = "Intel"318 obj.arch = arch.X86_64319 obj.mode = "custom"320 obj.add_feature(config.LibvirtConfigGuestCPUFeature("mtrr"))321 obj.add_feature(config.LibvirtConfigGuestCPUFeature("apic"))322 xml = obj.to_xml()323 self.assertXmlEqual(xml, """324 <cpu mode="custom" match="exact">325 <arch>x86_64</arch>326 <model>Penryn</model>327 <vendor>Intel</vendor>328 <feature name="apic" policy="require"/>329 <feature name="mtrr" policy="require"/>330 </cpu>331 """)332 def test_config_host(self):333 obj = config.LibvirtConfigGuestCPU()334 obj.mode = "host-model"335 obj.match = "exact"336 xml = obj.to_xml()337 self.assertXmlEqual(xml, """338 <cpu mode="host-model" match="exact"/>339 """)340 def test_config_host_with_numa(self):341 obj = config.LibvirtConfigGuestCPU()342 obj.mode = "host-model"343 obj.match = "exact"344 numa = config.LibvirtConfigGuestCPUNUMA()345 cell = config.LibvirtConfigGuestCPUNUMACell()346 cell.id = 0347 cell.cpus = set([0, 1])348 cell.memory = 1000000349 cell.memAccess = "private"350 numa.cells.append(cell)351 cell = config.LibvirtConfigGuestCPUNUMACell()352 cell.id = 1353 cell.cpus = set([2, 3])354 cell.memory = 1500000355 numa.cells.append(cell)356 obj.numa = numa357 xml = obj.to_xml()358 self.assertXmlEqual(xml, """359 <cpu mode="host-model" match="exact">360 <numa>361 <cell id="0" cpus="0-1" memory="1000000" memAccess="private"/>362 <cell id="1" cpus="2-3" memory="1500000"/>363 </numa>364 </cpu>365 """)366class LibvirtConfigGuestSMBIOSTest(LibvirtConfigBaseTest):367 def test_config_simple(self):368 obj = config.LibvirtConfigGuestSMBIOS()369 xml = obj.to_xml()370 self.assertXmlEqual(xml, """371 <smbios mode="sysinfo"/>372 """)373class LibvirtConfigGuestSysinfoTest(LibvirtConfigBaseTest):374 def test_config_simple(self):375 obj = config.LibvirtConfigGuestSysinfo()376 xml = obj.to_xml()377 self.assertXmlEqual(xml, """378 <sysinfo type="smbios"/>379 """)380 def test_config_bios(self):381 obj = config.LibvirtConfigGuestSysinfo()382 obj.bios_vendor = "Acme"383 obj.bios_version = "6.6.6"384 xml = obj.to_xml()385 self.assertXmlEqual(xml, """386 <sysinfo type="smbios">387 <bios>388 <entry name="vendor">Acme</entry>389 <entry name="version">6.6.6</entry>390 </bios>391 </sysinfo>392 """)393 def test_config_system(self):394 obj = config.LibvirtConfigGuestSysinfo()395 obj.system_manufacturer = "Acme"396 obj.system_product = "Wile Coyote"397 obj.system_version = "6.6.6"398 obj.system_serial = "123456"399 obj.system_uuid = "c7a5fdbd-edaf-9455-926a-d65c16db1809"400 obj.system_family = "Anvils"401 xml = obj.to_xml()402 self.assertXmlEqual(xml, """403 <sysinfo type="smbios">404 <system>405 <entry name="manufacturer">Acme</entry>406 <entry name="product">Wile Coyote</entry>407 <entry name="version">6.6.6</entry>408 <entry name="serial">123456</entry>409 <entry name="uuid">c7a5fdbd-edaf-9455-926a-d65c16db1809</entry>410 <entry name="family">Anvils</entry>411 </system>412 </sysinfo>413 """)414 def test_config_mixed(self):415 obj = config.LibvirtConfigGuestSysinfo()416 obj.bios_vendor = "Acme"417 obj.system_manufacturer = "Acme"418 obj.system_product = "Wile Coyote"419 obj.system_uuid = "c7a5fdbd-edaf-9455-926a-d65c16db1809"420 obj.system_family = "Anvils"421 xml = obj.to_xml()422 self.assertXmlEqual(xml, """423 <sysinfo type="smbios">424 <bios>425 <entry name="vendor">Acme</entry>426 </bios>427 <system>428 <entry name="manufacturer">Acme</entry>429 <entry name="product">Wile Coyote</entry>430 <entry name="uuid">c7a5fdbd-edaf-9455-926a-d65c16db1809</entry>431 <entry name="family">Anvils</entry>432 </system>433 </sysinfo>434 """)435class LibvirtConfigGuestDiskTest(LibvirtConfigBaseTest):436 def test_config_file(self):437 obj = config.LibvirtConfigGuestDisk()438 obj.source_type = "file"439 obj.source_path = "/tmp/hello"440 obj.target_dev = "/dev/hda"441 obj.target_bus = "ide"442 xml = obj.to_xml()443 self.assertXmlEqual(xml, """444 <disk type="file" device="disk">445 <source file="/tmp/hello"/>446 <target bus="ide" dev="/dev/hda"/>447 </disk>""")448 def test_config_file_parse(self):449 xml = """<disk type="file" device="disk">450 <source file="/tmp/hello"/>451 <target bus="ide" dev="/dev/hda"/>452 </disk>"""453 xmldoc = etree.fromstring(xml)454 obj = config.LibvirtConfigGuestDisk()455 obj.parse_dom(xmldoc)456 self.assertEqual(obj.source_type, 'file')457 self.assertEqual(obj.source_path, '/tmp/hello')458 self.assertEqual(obj.target_dev, '/dev/hda')459 self.assertEqual(obj.target_bus, 'ide')460 self.assertFalse(obj.readonly)461 self.assertFalse(obj.shareable)462 def test_config_file_readonly(self):463 obj = config.LibvirtConfigGuestDisk()464 obj.source_type = "file"465 obj.source_path = "/tmp/hello"466 obj.target_dev = "/dev/hda"467 obj.target_bus = "ide"468 obj.readonly = True469 xml = obj.to_xml()470 self.assertXmlEqual(xml, """471 <disk type="file" device="disk">472 <source file="/tmp/hello"/>473 <target bus="ide" dev="/dev/hda"/>474 <readonly/>475 </disk>""")476 def test_config_file_parse_readonly(self):477 xml = """<disk type="file" device="disk">478 <source file="/tmp/hello"/>479 <target bus="ide" dev="/dev/hda"/>480 <readonly/>481 </disk>"""482 xmldoc = etree.fromstring(xml)483 obj = config.LibvirtConfigGuestDisk()484 obj.parse_dom(xmldoc)485 self.assertEqual(obj.source_type, 'file')486 self.assertEqual(obj.source_path, '/tmp/hello')487 self.assertEqual(obj.target_dev, '/dev/hda')488 self.assertEqual(obj.target_bus, 'ide')489 self.assertTrue(obj.readonly)490 self.assertFalse(obj.shareable)491 def test_config_file_shareable(self):492 obj = config.LibvirtConfigGuestDisk()493 obj.source_type = "file"494 obj.source_path = "/tmp/hello"495 obj.target_dev = "/dev/hda"496 obj.target_bus = "ide"497 obj.shareable = True498 xml = obj.to_xml()499 self.assertXmlEqual(xml, """500 <disk type="file" device="disk">501 <source file="/tmp/hello"/>502 <target bus="ide" dev="/dev/hda"/>503 <shareable/>504 </disk>""")505 def test_config_file_parse_shareable(self):506 xml = """<disk type="file" device="disk">507 <source file="/tmp/hello"/>508 <target bus="ide" dev="/dev/hda"/>509 <shareable/>510 </disk>"""511 xmldoc = etree.fromstring(xml)512 obj = config.LibvirtConfigGuestDisk()513 obj.parse_dom(xmldoc)514 self.assertEqual(obj.source_type, 'file')515 self.assertEqual(obj.source_path, '/tmp/hello')516 self.assertEqual(obj.target_dev, '/dev/hda')517 self.assertEqual(obj.target_bus, 'ide')518 self.assertFalse(obj.readonly)519 self.assertTrue(obj.shareable)520 def test_config_file_serial(self):521 obj = config.LibvirtConfigGuestDisk()522 obj.source_type = "file"523 obj.source_path = "/tmp/hello"524 obj.target_dev = "/dev/hda"525 obj.target_bus = "ide"526 obj.serial = "7a97c4a3-6f59-41d4-bf47-191d7f97f8e9"527 xml = obj.to_xml()528 self.assertXmlEqual(xml, """529 <disk type="file" device="disk">530 <source file="/tmp/hello"/>531 <target bus="ide" dev="/dev/hda"/>532 <serial>7a97c4a3-6f59-41d4-bf47-191d7f97f8e9</serial>533 </disk>""")534 def test_config_file_serial_parse(self):535 xml = """<disk type="file" device="disk">536 <source file="/tmp/hello"/>537 <target bus="ide" dev="/dev/hda"/>538 <serial>7a97c4a3-6f59-41d4-bf47-191d7f97f8e9</serial>539 </disk>"""540 xmldoc = etree.fromstring(xml)541 obj = config.LibvirtConfigGuestDisk()542 obj.parse_dom(xmldoc)543 self.assertEqual(obj.source_type, 'file')544 self.assertEqual(obj.serial, '7a97c4a3-6f59-41d4-bf47-191d7f97f8e9')545 def test_config_file_discard(self):546 obj = config.LibvirtConfigGuestDisk()547 obj.driver_name = "qemu"548 obj.driver_format = "qcow2"549 obj.driver_cache = "none"550 obj.driver_discard = "unmap"551 obj.source_type = "file"552 obj.source_path = "/tmp/hello.qcow2"553 obj.target_dev = "/dev/hda"554 obj.target_bus = "ide"555 obj.serial = "7a97c4a3-6f59-41d4-bf47-191d7f97f8e9"556 xml = obj.to_xml()557 self.assertXmlEqual("""558 <disk type="file" device="disk">559 <driver name="qemu" type="qcow2" cache="none" discard="unmap"/>560 <source file="/tmp/hello.qcow2"/>561 <target bus="ide" dev="/dev/hda"/>562 <serial>7a97c4a3-6f59-41d4-bf47-191d7f97f8e9</serial>563 </disk>""", xml)564 def test_config_file_discard_parse(self):565 xml = """566 <disk type="file" device="disk">567 <driver name="qemu" type="qcow2" cache="none" discard="unmap"/>568 <source file="/tmp/hello.qcow2"/>569 <target bus="ide" dev="/dev/hda"/>570 <serial>7a97c4a3-6f59-41d4-bf47-191d7f97f8e9</serial>571 </disk>"""572 xmldoc = etree.fromstring(xml)573 obj = config.LibvirtConfigGuestDisk()574 obj.parse_dom(xmldoc)575 self.assertEqual('unmap', obj.driver_discard)576 def test_config_file_io(self):577 obj = config.LibvirtConfigGuestDisk()578 obj.driver_name = "qemu"579 obj.driver_format = "qcow2"580 obj.driver_cache = "none"581 obj.driver_io = "native"582 obj.source_type = "file"583 obj.source_path = "/tmp/hello.qcow2"584 obj.target_dev = "/dev/hda"585 obj.target_bus = "ide"586 obj.serial = "7a97c4a3-6f59-41d4-bf47-191d7f97f8e9"587 xml = obj.to_xml()588 self.assertXmlEqual("""589 <disk type="file" device="disk">590 <driver name="qemu" type="qcow2" cache="none" io="native"/>591 <source file="/tmp/hello.qcow2"/>592 <target bus="ide" dev="/dev/hda"/>593 <serial>7a97c4a3-6f59-41d4-bf47-191d7f97f8e9</serial>594 </disk>""", xml)595 def test_config_file_io_parse(self):596 xml = """597 <disk type="file" device="disk">598 <driver name="qemu" type="qcow2" cache="none" io="native"/>599 <source file="/tmp/hello.qcow2"/>600 <target bus="ide" dev="/dev/hda"/>601 <serial>7a97c4a3-6f59-41d4-bf47-191d7f97f8e9</serial>602 </disk>"""603 xmldoc = etree.fromstring(xml)604 obj = config.LibvirtConfigGuestDisk()605 obj.parse_dom(xmldoc)606 self.assertEqual('native', obj.driver_io)607 def test_config_block(self):608 obj = config.LibvirtConfigGuestDisk()609 obj.source_type = "block"610 obj.source_path = "/tmp/hello"611 obj.source_device = "cdrom"612 obj.driver_name = "qemu"613 obj.target_dev = "/dev/hdc"614 obj.target_bus = "ide"615 xml = obj.to_xml()616 self.assertXmlEqual(xml, """617 <disk type="block" device="cdrom">618 <driver name="qemu"/>619 <source dev="/tmp/hello"/>620 <target bus="ide" dev="/dev/hdc"/>621 </disk>""")622 def test_config_block_parse(self):623 xml = """<disk type="block" device="cdrom">624 <driver name="qemu"/>625 <source dev="/tmp/hello"/>626 <target bus="ide" dev="/dev/hdc"/>627 </disk>"""628 xmldoc = etree.fromstring(xml)629 obj = config.LibvirtConfigGuestDisk()630 obj.parse_dom(xmldoc)631 self.assertEqual(obj.source_type, 'block')632 self.assertEqual(obj.source_path, '/tmp/hello')633 self.assertEqual(obj.target_dev, '/dev/hdc')634 self.assertEqual(obj.target_bus, 'ide')635 def test_config_network(self):636 obj = config.LibvirtConfigGuestDisk()637 obj.source_type = "network"638 obj.source_protocol = "iscsi"639 obj.source_name = "foo.bar.com"640 obj.driver_name = "qemu"641 obj.driver_format = "qcow2"642 obj.target_dev = "/dev/hda"643 obj.target_bus = "ide"644 xml = obj.to_xml()645 self.assertXmlEqual(xml, """646 <disk type="network" device="disk">647 <driver name="qemu" type="qcow2"/>648 <source name="foo.bar.com" protocol="iscsi"/>649 <target bus="ide" dev="/dev/hda"/>650 </disk>""")651 def test_config_network_parse(self):652 xml = """<disk type="network" device="disk">653 <driver name="qemu" type="qcow2"/>654 <source name="foo.bar.com" protocol="iscsi"/>655 <target bus="ide" dev="/dev/hda"/>656 </disk>"""657 xmldoc = etree.fromstring(xml)658 obj = config.LibvirtConfigGuestDisk()659 obj.parse_dom(xmldoc)660 self.assertEqual(obj.source_type, 'network')661 self.assertEqual(obj.source_protocol, 'iscsi')662 self.assertEqual(obj.source_name, 'foo.bar.com')663 self.assertEqual(obj.driver_name, 'qemu')664 self.assertEqual(obj.driver_format, 'qcow2')665 self.assertEqual(obj.target_dev, '/dev/hda')666 self.assertEqual(obj.target_bus, 'ide')667 def test_config_network_no_name(self):668 obj = config.LibvirtConfigGuestDisk()669 obj.source_type = 'network'670 obj.source_protocol = 'nbd'671 obj.source_hosts = ['foo.bar.com']672 obj.source_ports = [None]673 obj.driver_name = 'qemu'674 obj.driver_format = 'raw'675 obj.target_dev = '/dev/vda'676 obj.target_bus = 'virtio'677 xml = obj.to_xml()678 self.assertXmlEqual(xml, """679 <disk type="network" device="disk">680 <driver name="qemu" type="raw"/>681 <source protocol="nbd">682 <host name="foo.bar.com"/>683 </source>684 <target bus="virtio" dev="/dev/vda"/>685 </disk>""")686 def test_config_network_multihost(self):687 obj = config.LibvirtConfigGuestDisk()688 obj.source_type = 'network'689 obj.source_protocol = 'rbd'690 obj.source_name = 'pool/image'691 obj.source_hosts = ['foo.bar.com', '::1', '1.2.3.4']692 obj.source_ports = [None, '123', '456']693 obj.driver_name = 'qemu'694 obj.driver_format = 'raw'695 obj.target_dev = '/dev/vda'696 obj.target_bus = 'virtio'697 xml = obj.to_xml()698 self.assertXmlEqual(xml, """699 <disk type="network" device="disk">700 <driver name="qemu" type="raw"/>701 <source name="pool/image" protocol="rbd">702 <host name="foo.bar.com"/>703 <host name="::1" port="123"/>704 <host name="1.2.3.4" port="456"/>705 </source>706 <target bus="virtio" dev="/dev/vda"/>707 </disk>""")708 def test_config_network_auth(self):709 obj = config.LibvirtConfigGuestDisk()710 obj.source_type = "network"711 obj.source_protocol = "rbd"712 obj.source_name = "pool/image"713 obj.driver_name = "qemu"714 obj.driver_format = "raw"715 obj.target_dev = "/dev/vda"716 obj.target_bus = "virtio"717 obj.auth_username = "foo"718 obj.auth_secret_type = "ceph"719 obj.auth_secret_uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147"720 xml = obj.to_xml()721 self.assertXmlEqual(xml, """722 <disk type="network" device="disk">723 <driver name="qemu" type="raw"/>724 <source name="pool/image" protocol="rbd"/>725 <auth username="foo">726 <secret type="ceph"727 uuid="b38a3f43-4be2-4046-897f-b67c2f5e0147"/>728 </auth>729 <target bus="virtio" dev="/dev/vda"/>730 </disk>""")731 def test_config_iotune(self):732 obj = config.LibvirtConfigGuestDisk()733 obj.source_type = "file"734 obj.source_path = "/tmp/hello"735 obj.target_dev = "/dev/hda"736 obj.target_bus = "ide"737 obj.disk_read_bytes_sec = 1024000738 obj.disk_read_iops_sec = 1000739 obj.disk_total_bytes_sec = 2048000740 obj.disk_write_bytes_sec = 1024000741 obj.disk_write_iops_sec = 1000742 obj.disk_total_iops_sec = 2000743 xml = obj.to_xml()744 self.assertXmlEqual(xml, """745 <disk type="file" device="disk">746 <source file="/tmp/hello"/>747 <target bus="ide" dev="/dev/hda"/>748 <iotune>749 <read_bytes_sec>1024000</read_bytes_sec>750 <read_iops_sec>1000</read_iops_sec>751 <write_bytes_sec>1024000</write_bytes_sec>752 <write_iops_sec>1000</write_iops_sec>753 <total_bytes_sec>2048000</total_bytes_sec>754 <total_iops_sec>2000</total_iops_sec>755 </iotune>756 </disk>""")757 def test_config_blockio(self):758 obj = config.LibvirtConfigGuestDisk()759 obj.source_type = "file"760 obj.source_path = "/tmp/hello"761 obj.target_dev = "/dev/hda"762 obj.target_bus = "ide"763 obj.logical_block_size = "4096"764 obj.physical_block_size = "4096"765 xml = obj.to_xml()766 self.assertXmlEqual("""767 <disk type="file" device="disk">768 <source file="/tmp/hello"/>769 <target bus="ide" dev="/dev/hda"/>770 <blockio logical_block_size="4096" physical_block_size="4096"/>771 </disk>""", xml)772class LibvirtConfigGuestSnapshotDiskTest(LibvirtConfigBaseTest):773 def test_config_file(self):774 obj = config.LibvirtConfigGuestDisk()775 obj.source_type = "file"776 obj.source_path = "/tmp/hello"777 obj.target_dev = "/dev/hda"778 obj.target_bus = "ide"779 xml = obj.to_xml()780 self.assertXmlEqual(xml, """781 <disk type="file" device="disk">782 <source file="/tmp/hello"/>783 <target bus="ide" dev="/dev/hda"/>784 </disk>""")785 def test_config_file_parse(self):786 xml = """<disk type="file" device="disk">787 <source file="/tmp/hello"/>788 <target bus="ide" dev="/dev/hda"/>789 </disk>"""790 xmldoc = etree.fromstring(xml)791 obj = config.LibvirtConfigGuestDisk()792 obj.parse_dom(xmldoc)793 self.assertEqual(obj.source_type, 'file')794 self.assertEqual(obj.source_path, '/tmp/hello')795 self.assertEqual(obj.target_dev, '/dev/hda')796 self.assertEqual(obj.target_bus, 'ide')797class LibvirtConfigGuestDiskBackingStoreTest(LibvirtConfigBaseTest):798 def test_config_file_parse(self):799 xml = """<backingStore type='file'>800 <driver name='qemu' type='qcow2'/>801 <source file='/var/lib/libvirt/images/mid.qcow2'/>802 <backingStore type='file'>803 <driver name='qemu' type='qcow2'/>804 <source file='/var/lib/libvirt/images/base.qcow2'/>805 <backingStore/>806 </backingStore>807 </backingStore>808 """809 xmldoc = etree.fromstring(xml)810 obj = config.LibvirtConfigGuestDiskBackingStore()811 obj.parse_dom(xmldoc)812 self.assertEqual(obj.driver_name, 'qemu')813 self.assertEqual(obj.driver_format, 'qcow2')814 self.assertEqual(obj.source_type, 'file')815 self.assertEqual(obj.source_file, '/var/lib/libvirt/images/mid.qcow2')816 self.assertEqual(obj.backing_store.driver_name, 'qemu')817 self.assertEqual(obj.backing_store.source_type, 'file')818 self.assertEqual(obj.backing_store.source_file,819 '/var/lib/libvirt/images/base.qcow2')820 self.assertIsNone(obj.backing_store.backing_store)821 def test_config_network_parse(self):822 xml = """<backingStore type='network' index='1'>823 <format type='qcow2'/>824 <source protocol='gluster' name='volume1/img1'>825 <host name='host1' port='24007'/>826 </source>827 <backingStore type='network' index='2'>828 <format type='qcow2'/>829 <source protocol='gluster' name='volume1/img2'>830 <host name='host1' port='24007'/>831 </source>832 <backingStore/>833 </backingStore>834 </backingStore>835 """836 xmldoc = etree.fromstring(xml)837 obj = config.LibvirtConfigGuestDiskBackingStore()838 obj.parse_dom(xmldoc)839 self.assertEqual(obj.source_type, 'network')840 self.assertEqual(obj.source_protocol, 'gluster')841 self.assertEqual(obj.source_name, 'volume1/img1')842 self.assertEqual(obj.source_hosts[0], 'host1')843 self.assertEqual(obj.source_ports[0], '24007')844 self.assertEqual(obj.index, '1')845 self.assertEqual(obj.backing_store.source_name, 'volume1/img2')846 self.assertEqual(obj.backing_store.index, '2')847 self.assertEqual(obj.backing_store.source_hosts[0], 'host1')848 self.assertEqual(obj.backing_store.source_ports[0], '24007')849 self.assertIsNone(obj.backing_store.backing_store)850class LibvirtConfigGuestFilesysTest(LibvirtConfigBaseTest):851 def test_config_mount(self):852 obj = config.LibvirtConfigGuestFilesys()853 obj.source_type = "mount"854 obj.source_dir = "/tmp/hello"855 obj.target_dir = "/mnt"856 xml = obj.to_xml()857 self.assertXmlEqual(xml, """858 <filesystem type="mount">859 <source dir="/tmp/hello"/>860 <target dir="/mnt"/>861 </filesystem>""")862 def test_config_block(self):863 obj = config.LibvirtConfigGuestFilesys()864 obj.source_type = "block"865 obj.source_dev = "/dev/sdb"866 obj.target_dir = "/mnt"867 xml = obj.to_xml()868 self.assertXmlEqual(xml, """869 <filesystem type="block">870 <source dev="/dev/sdb"/>871 <target dir="/mnt"/>872 </filesystem>""")873 def test_config_file(self):874 obj = config.LibvirtConfigGuestFilesys()875 obj.source_type = "file"876 obj.source_file = "/data/myimage.qcow2"877 obj.driver_type = "nbd"878 obj.driver_format = "qcow2"879 obj.target_dir = "/mnt"880 xml = obj.to_xml()881 self.assertXmlEqual(xml, """882 <filesystem type="file">883 <driver format="qcow2" type="nbd"/>884 <source file="/data/myimage.qcow2"/>885 <target dir="/mnt"/>886 </filesystem>""")887class LibvirtConfigGuestInputTest(LibvirtConfigBaseTest):888 def test_config_tablet(self):889 obj = config.LibvirtConfigGuestInput()890 xml = obj.to_xml()891 self.assertXmlEqual(xml, """892 <input type="tablet" bus="usb"/>""")893class LibvirtConfigGuestGraphicsTest(LibvirtConfigBaseTest):894 def test_config_graphics(self):895 obj = config.LibvirtConfigGuestGraphics()896 obj.type = "vnc"897 obj.autoport = True898 obj.keymap = "en_US"899 obj.listen = "127.0.0.1"900 xml = obj.to_xml()901 self.assertXmlEqual(xml, """902 <graphics type="vnc" autoport="yes" keymap="en_US" listen="127.0.0.1"/>903 """)904class LibvirtConfigGuestHostdev(LibvirtConfigBaseTest):905 def test_config_pci_guest_host_dev(self):906 obj = config.LibvirtConfigGuestHostdev(mode='subsystem', type='pci')907 xml = obj.to_xml()908 expected = """909 <hostdev mode="subsystem" type="pci" managed="yes"/>910 """911 self.assertXmlEqual(xml, expected)912 def test_parse_GuestHostdev(self):913 xmldoc = """<hostdev mode="subsystem" type="pci" managed="yes"/>"""914 obj = config.LibvirtConfigGuestHostdev()915 obj.parse_str(xmldoc)916 self.assertEqual(obj.mode, 'subsystem')917 self.assertEqual(obj.type, 'pci')918 self.assertEqual(obj.managed, 'yes')919 def test_parse_GuestHostdev_non_pci(self):920 xmldoc = """<hostdev mode="subsystem" type="usb" managed="no"/>"""921 obj = config.LibvirtConfigGuestHostdev()922 obj.parse_str(xmldoc)923 self.assertEqual(obj.mode, 'subsystem')924 self.assertEqual(obj.type, 'usb')925 self.assertEqual(obj.managed, 'no')926class LibvirtConfigGuestHostdevPCI(LibvirtConfigBaseTest):927 expected = """928 <hostdev mode="subsystem" type="pci" managed="yes">929 <source>930 <address bus="0x11" domain="0x1234" function="0x3"931 slot="0x22" />932 </source>933 </hostdev>934 """935 def test_config_guest_hosdev_pci(self):936 hostdev = config.LibvirtConfigGuestHostdevPCI()937 hostdev.domain = "1234"938 hostdev.bus = "11"939 hostdev.slot = "22"940 hostdev.function = "3"941 xml = hostdev.to_xml()942 self.assertXmlEqual(self.expected, xml)943 def test_parse_guest_hosdev_pci(self):944 xmldoc = self.expected945 obj = config.LibvirtConfigGuestHostdevPCI()946 obj.parse_str(xmldoc)947 self.assertEqual(obj.mode, 'subsystem')948 self.assertEqual(obj.type, 'pci')949 self.assertEqual(obj.managed, 'yes')950 self.assertEqual(obj.domain, '0x1234')951 self.assertEqual(obj.bus, '0x11')952 self.assertEqual(obj.slot, '0x22')953 self.assertEqual(obj.function, '0x3')954 def test_parse_guest_hosdev_usb(self):955 xmldoc = """<hostdev mode='subsystem' type='usb'>956 <source startupPolicy='optional'>957 <vendor id='0x1234'/>958 <product id='0xbeef'/>959 </source>960 <boot order='2'/>961 </hostdev>"""962 obj = config.LibvirtConfigGuestHostdevPCI()963 obj.parse_str(xmldoc)964 self.assertEqual(obj.mode, 'subsystem')965 self.assertEqual(obj.type, 'usb')966class LibvirtConfigGuestSerialTest(LibvirtConfigBaseTest):967 def test_config_file(self):968 obj = config.LibvirtConfigGuestSerial()969 obj.type = "file"970 obj.source_path = "/tmp/vm.log"971 xml = obj.to_xml()972 self.assertXmlEqual(xml, """973 <serial type="file">974 <source path="/tmp/vm.log"/>975 </serial>""")976 def test_config_serial_port(self):977 obj = config.LibvirtConfigGuestSerial()978 obj.type = "tcp"979 obj.listen_port = 11111980 obj.listen_host = "0.0.0.0"981 xml = obj.to_xml()982 self.assertXmlEqual(xml, """983 <serial type="tcp">984 <source host="0.0.0.0" service="11111" mode="bind"/>985 </serial>""")986class LibvirtConfigGuestConsoleTest(LibvirtConfigBaseTest):987 def test_config_pty(self):988 obj = config.LibvirtConfigGuestConsole()989 obj.type = "pty"990 xml = obj.to_xml()991 self.assertXmlEqual(xml, """992 <console type="pty"/>""")993 def test_config_target_type(self):994 obj = config.LibvirtConfigGuestConsole()995 obj.type = "pty"996 obj.target_type = "sclp"997 xml = obj.to_xml()998 self.assertXmlEqual(xml, """999 <console type="pty">1000 <target type="sclp"/>1001 </console>1002 """)1003 def test_config_type_file_with_target_type(self):1004 obj = config.LibvirtConfigGuestConsole()1005 obj.type = "file"1006 obj.target_type = "sclplm"1007 obj.source_path = "/var/lib/nova/instances/uuid/console.log"1008 xml = obj.to_xml()1009 self.assertXmlEqual(xml, """1010 <console type="file">1011 <source path="/var/lib/nova/instances/uuid/console.log"/>1012 <target type="sclplm"/>1013 </console>1014 """)1015 def test_config_target_port(self):1016 obj = config.LibvirtConfigGuestConsole()1017 obj.target_port = 01018 xml = obj.to_xml()1019 self.assertXmlEqual(xml, """1020 <console type="pty">1021 <target port="0"/>1022 </console>1023 """)1024class LibvirtConfigGuestChannelTest(LibvirtConfigBaseTest):1025 def test_config_spice_minimal(self):1026 obj = config.LibvirtConfigGuestChannel()1027 obj.type = "spicevmc"1028 xml = obj.to_xml()1029 self.assertXmlEqual(xml, """1030 <channel type="spicevmc">1031 <target type='virtio'/>1032 </channel>""")1033 def test_config_spice_full(self):1034 obj = config.LibvirtConfigGuestChannel()1035 obj.type = "spicevmc"1036 obj.target_name = "com.redhat.spice.0"1037 xml = obj.to_xml()1038 self.assertXmlEqual(xml, """1039 <channel type="spicevmc">1040 <target type='virtio' name='com.redhat.spice.0'/>1041 </channel>""")1042 def test_config_qga_full(self):1043 obj = config.LibvirtConfigGuestChannel()1044 obj.type = "unix"1045 obj.target_name = "org.qemu.guest_agent.0"1046 obj.source_path = "/var/lib/libvirt/qemu/%s.%s.sock" % (1047 obj.target_name, "instance-name")1048 xml = obj.to_xml()1049 self.assertXmlEqual(xml, """1050 <channel type="unix">1051 <source path="%s" mode="bind"/>1052 <target type="virtio" name="org.qemu.guest_agent.0"/>1053 </channel>""" % obj.source_path)1054class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest):1055 def test_config_ethernet(self):1056 obj = config.LibvirtConfigGuestInterface()1057 obj.net_type = "ethernet"1058 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1059 obj.model = "virtio"1060 obj.target_dev = "vnet0"1061 obj.driver_name = "vhost"1062 obj.vif_inbound_average = 163841063 obj.vif_inbound_peak = 327681064 obj.vif_inbound_burst = 32761065 obj.vif_outbound_average = 327681066 obj.vif_outbound_peak = 655361067 obj.vif_outbound_burst = 65531068 xml = obj.to_xml()1069 self.assertXmlEqual(xml, """1070 <interface type="ethernet">1071 <mac address="DE:AD:BE:EF:CA:FE"/>1072 <model type="virtio"/>1073 <driver name="vhost"/>1074 <target dev="vnet0"/>1075 <bandwidth>1076 <inbound average="16384" peak="32768" burst="3276"/>1077 <outbound average="32768" peak="65536" burst="6553"/>1078 </bandwidth>1079 </interface>""")1080 # parse the xml from the first object into a new object and make sure1081 # they are the same1082 obj2 = config.LibvirtConfigGuestInterface()1083 obj2.parse_str(xml)1084 self.assertXmlEqual(xml, obj2.to_xml())1085 def test_config_driver_options(self):1086 obj = config.LibvirtConfigGuestInterface()1087 obj.net_type = "ethernet"1088 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1089 obj.model = "virtio"1090 obj.target_dev = "vnet0"1091 obj.driver_name = "vhost"1092 obj.vhost_queues = 41093 xml = obj.to_xml()1094 self.assertXmlEqual(xml, """1095 <interface type="ethernet">1096 <mac address="DE:AD:BE:EF:CA:FE"/>1097 <model type="virtio"/>1098 <driver name="vhost" queues="4"/>1099 <target dev="vnet0"/>1100 </interface>""")1101 # parse the xml from the first object into a new object and make sure1102 # they are the same1103 obj2 = config.LibvirtConfigGuestInterface()1104 obj2.parse_str(xml)1105 self.assertXmlEqual(xml, obj2.to_xml())1106 def test_config_bridge(self):1107 obj = config.LibvirtConfigGuestInterface()1108 obj.net_type = "bridge"1109 obj.source_dev = "br0"1110 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1111 obj.model = "virtio"1112 obj.target_dev = "tap12345678"1113 obj.filtername = "clean-traffic"1114 obj.filterparams.append({"key": "IP", "value": "192.168.122.1"})1115 obj.vif_inbound_average = 163841116 obj.vif_inbound_peak = 327681117 obj.vif_inbound_burst = 32761118 obj.vif_outbound_average = 327681119 obj.vif_outbound_peak = 655361120 obj.vif_outbound_burst = 65531121 xml = obj.to_xml()1122 self.assertXmlEqual(xml, """1123 <interface type="bridge">1124 <mac address="DE:AD:BE:EF:CA:FE"/>1125 <model type="virtio"/>1126 <source bridge="br0"/>1127 <target dev="tap12345678"/>1128 <filterref filter="clean-traffic">1129 <parameter name="IP" value="192.168.122.1"/>1130 </filterref>1131 <bandwidth>1132 <inbound average="16384" peak="32768" burst="3276"/>1133 <outbound average="32768" peak="65536" burst="6553"/>1134 </bandwidth>1135 </interface>""")1136 # parse the xml from the first object into a new object and make sure1137 # they are the same1138 obj2 = config.LibvirtConfigGuestInterface()1139 obj2.parse_str(xml)1140 self.assertXmlEqual(xml, obj2.to_xml())1141 def test_config_bridge_ovs(self):1142 obj = config.LibvirtConfigGuestInterface()1143 obj.net_type = "bridge"1144 obj.source_dev = "br0"1145 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1146 obj.model = "virtio"1147 obj.target_dev = "tap12345678"1148 obj.vporttype = "openvswitch"1149 obj.vportparams.append({"key": "instanceid", "value": "foobar"})1150 xml = obj.to_xml()1151 self.assertXmlEqual(xml, """1152 <interface type="bridge">1153 <mac address="DE:AD:BE:EF:CA:FE"/>1154 <model type="virtio"/>1155 <source bridge="br0"/>1156 <target dev="tap12345678"/>1157 <virtualport type="openvswitch">1158 <parameters instanceid="foobar"/>1159 </virtualport>1160 </interface>""")1161 # parse the xml from the first object into a new object and make sure1162 # they are the same1163 obj2 = config.LibvirtConfigGuestInterface()1164 obj2.parse_str(xml)1165 self.assertXmlEqual(xml, obj2.to_xml())1166 def test_config_bridge_xen(self):1167 obj = config.LibvirtConfigGuestInterface()1168 obj.net_type = "bridge"1169 obj.source_dev = "br0"1170 obj.mac_addr = "CA:FE:BE:EF:CA:FE"1171 obj.script = "/path/to/test-vif-openstack"1172 xml = obj.to_xml()1173 self.assertXmlEqual(xml, """1174 <interface type="bridge">1175 <mac address="CA:FE:BE:EF:CA:FE"/>1176 <source bridge="br0"/>1177 <script path="/path/to/test-vif-openstack"/>1178 </interface>""")1179 # parse the xml from the first object into a new object and make sure1180 # they are the same1181 obj2 = config.LibvirtConfigGuestInterface()1182 obj2.parse_str(xml)1183 self.assertXmlEqual(xml, obj2.to_xml())1184 def test_config_8021Qbh(self):1185 obj = config.LibvirtConfigGuestInterface()1186 obj.net_type = "direct"1187 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1188 obj.model = "virtio"1189 obj.target_dev = "tap12345678"1190 obj.source_dev = "eth0"1191 obj.vporttype = "802.1Qbh"1192 xml = obj.to_xml()1193 self.assertXmlEqual(xml, """1194 <interface type="direct">1195 <mac address="DE:AD:BE:EF:CA:FE"/>1196 <model type="virtio"/>1197 <source dev="eth0" mode="private"/>1198 <target dev="tap12345678"/>1199 <virtualport type="802.1Qbh"/>1200 </interface>""")1201 # parse the xml from the first object into a new object and make sure1202 # they are the same1203 obj2 = config.LibvirtConfigGuestInterface()1204 obj2.parse_str(xml)1205 self.assertXmlEqual(xml, obj2.to_xml())1206 def test_config_direct(self):1207 obj = config.LibvirtConfigGuestInterface()1208 obj.net_type = "direct"1209 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1210 obj.model = "virtio"1211 obj.source_dev = "eth0"1212 obj.source_mode = "passthrough"1213 xml = obj.to_xml()1214 self.assertXmlEqual(xml, """1215 <interface type="direct">1216 <mac address="DE:AD:BE:EF:CA:FE"/>1217 <model type="virtio"/>1218 <source dev="eth0" mode="passthrough"/>1219 </interface>""")1220 # parse the xml from the first object into a new object and make sure1221 # they are the same1222 obj2 = config.LibvirtConfigGuestInterface()1223 obj2.parse_str(xml)1224 self.assertXmlEqual(xml, obj2.to_xml())1225 def test_config_8021Qbh_hostdev(self):1226 obj = config.LibvirtConfigGuestInterface()1227 obj.net_type = "hostdev"1228 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1229 obj.source_dev = "0000:0a:00.1"1230 obj.vporttype = "802.1Qbh"1231 obj.add_vport_param("profileid", "MyPortProfile")1232 xml = obj.to_xml()1233 self.assertXmlEqual(xml, """1234 <interface type="hostdev" managed="yes">1235 <mac address="DE:AD:BE:EF:CA:FE"/>1236 <source>1237 <address type="pci" domain="0x0000"1238 bus="0x0a" slot="0x00" function="0x1"/>1239 </source>1240 <virtualport type="802.1Qbh">1241 <parameters profileid="MyPortProfile"/>1242 </virtualport>1243 </interface>""")1244 # parse the xml from the first object into a new object and make sure1245 # they are the same1246 obj2 = config.LibvirtConfigGuestInterface()1247 obj2.parse_str(xml)1248 self.assertXmlEqual(xml, obj2.to_xml())1249 def test_config_hw_veb_hostdev(self):1250 obj = config.LibvirtConfigGuestInterface()1251 obj.net_type = "hostdev"1252 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1253 obj.source_dev = "0000:0a:00.1"1254 obj.vlan = "100"1255 xml = obj.to_xml()1256 self.assertXmlEqual(xml, """1257 <interface type="hostdev" managed="yes">1258 <mac address="DE:AD:BE:EF:CA:FE"/>1259 <source>1260 <address type="pci" domain="0x0000"1261 bus="0x0a" slot="0x00" function="0x1"/>1262 </source>1263 <vlan>1264 <tag id="100"/>1265 </vlan>1266 </interface>""")1267 # parse the xml from the first object into a new object and make sure1268 # they are the same1269 obj2 = config.LibvirtConfigGuestInterface()1270 obj2.parse_str(xml)1271 self.assertXmlEqual(xml, obj2.to_xml())1272 def test_config_vhostuser(self):1273 obj = config.LibvirtConfigGuestInterface()1274 obj.net_type = "vhostuser"1275 obj.vhostuser_type = "unix"1276 obj.vhostuser_mode = "server"1277 obj.mac_addr = "DE:AD:BE:EF:CA:FE"1278 obj.vhostuser_path = "/vhost-user/test.sock"1279 obj.model = "virtio"1280 xml = obj.to_xml()1281 self.assertXmlEqual(xml, """1282 <interface type="vhostuser">1283 <mac address="DE:AD:BE:EF:CA:FE"/>1284 <model type="virtio"/>1285 <source type="unix" mode="server" path="/vhost-user/test.sock"/>1286 </interface>""")1287 # parse the xml from the first object into a new object and make sure1288 # they are the same1289 obj2 = config.LibvirtConfigGuestInterface()1290 obj2.parse_str(xml)1291 self.assertXmlEqual(xml, obj2.to_xml())1292class LibvirtConfigGuestFeatureTest(LibvirtConfigBaseTest):1293 def test_feature_hyperv_relaxed(self):1294 obj = config.LibvirtConfigGuestFeatureHyperV()1295 obj.relaxed = True1296 xml = obj.to_xml()1297 self.assertXmlEqual(xml, """1298 <hyperv>1299 <relaxed state="on"/>1300 </hyperv>""")1301 def test_feature_hyperv_all(self):1302 obj = config.LibvirtConfigGuestFeatureHyperV()1303 obj.relaxed = True1304 obj.vapic = True1305 obj.spinlocks = True1306 xml = obj.to_xml()1307 self.assertXmlEqual(xml, """1308 <hyperv>1309 <relaxed state="on"/>1310 <vapic state="on"/>1311 <spinlocks state="on" retries="4095"/>1312 </hyperv>""")1313class LibvirtConfigGuestTest(LibvirtConfigBaseTest):1314 def test_config_lxc(self):1315 obj = config.LibvirtConfigGuest()1316 obj.virt_type = "lxc"1317 obj.memory = 100 * units.Mi1318 obj.vcpus = 21319 obj.cpuset = set([0, 1, 3, 4, 5])1320 obj.name = "demo"1321 obj.uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147"1322 obj.os_type = "exe"1323 obj.os_init_path = "/sbin/init"1324 fs = config.LibvirtConfigGuestFilesys()1325 fs.source_dir = "/root/lxc"1326 fs.target_dir = "/"1327 obj.add_device(fs)1328 xml = obj.to_xml()1329 self.assertXmlEqual(xml, """1330 <domain type="lxc">1331 <uuid>b38a3f43-4be2-4046-897f-b67c2f5e0147</uuid>1332 <name>demo</name>1333 <memory>104857600</memory>1334 <vcpu cpuset="0-1,3-5">2</vcpu>1335 <os>1336 <type>exe</type>1337 <init>/sbin/init</init>1338 </os>1339 <devices>1340 <filesystem type="mount">1341 <source dir="/root/lxc"/>1342 <target dir="/"/>1343 </filesystem>1344 </devices>1345 </domain>""")1346 def test_config_lxc_with_idmap(self):1347 obj = config.LibvirtConfigGuest()1348 obj.virt_type = "lxc"1349 obj.memory = 100 * units.Mi1350 obj.vcpus = 21351 obj.cpuset = set([0, 1, 3, 4, 5])1352 obj.name = "demo"1353 obj.uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147"1354 obj.os_type = "exe"1355 obj.os_init_path = "/sbin/init"1356 uidmap = config.LibvirtConfigGuestUIDMap()1357 uidmap.target = "10000"1358 uidmap.count = "1"1359 obj.idmaps.append(uidmap)1360 gidmap = config.LibvirtConfigGuestGIDMap()1361 gidmap.target = "10000"1362 gidmap.count = "1"1363 obj.idmaps.append(gidmap)1364 fs = config.LibvirtConfigGuestFilesys()1365 fs.source_dir = "/root/lxc"1366 fs.target_dir = "/"1367 obj.add_device(fs)1368 xml = obj.to_xml()1369 self.assertXmlEqual("""1370 <domain type="lxc">1371 <uuid>b38a3f43-4be2-4046-897f-b67c2f5e0147</uuid>1372 <name>demo</name>1373 <memory>104857600</memory>1374 <vcpu cpuset="0-1,3-5">2</vcpu>1375 <os>1376 <type>exe</type>1377 <init>/sbin/init</init>1378 </os>1379 <devices>1380 <filesystem type="mount">1381 <source dir="/root/lxc"/>1382 <target dir="/"/>1383 </filesystem>1384 </devices>1385 <idmap>1386 <uid start="0" target="10000" count="1"/>1387 <gid start="0" target="10000" count="1"/>1388 </idmap>1389 </domain>""", xml)1390 def test_config_xen_pv(self):1391 obj = config.LibvirtConfigGuest()1392 obj.virt_type = "xen"1393 obj.memory = 100 * units.Mi1394 obj.vcpus = 21395 obj.cpuset = set([0, 1, 3, 4, 5])1396 obj.name = "demo"1397 obj.uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147"1398 obj.os_type = "linux"1399 obj.os_kernel = "/tmp/vmlinuz"1400 obj.os_initrd = "/tmp/ramdisk"1401 obj.os_cmdline = "console=xvc0"1402 disk = config.LibvirtConfigGuestDisk()1403 disk.source_type = "file"1404 disk.source_path = "/tmp/img"1405 disk.target_dev = "/dev/xvda"1406 disk.target_bus = "xen"1407 obj.add_device(disk)1408 xml = obj.to_xml()1409 self.assertXmlEqual(xml, """1410 <domain type="xen">1411 <uuid>b38a3f43-4be2-4046-897f-b67c2f5e0147</uuid>1412 <name>demo</name>1413 <memory>104857600</memory>1414 <vcpu cpuset="0-1,3-5">2</vcpu>1415 <os>1416 <type>linux</type>1417 <kernel>/tmp/vmlinuz</kernel>1418 <initrd>/tmp/ramdisk</initrd>1419 <cmdline>console=xvc0</cmdline>1420 </os>1421 <devices>1422 <disk type="file" device="disk">1423 <source file="/tmp/img"/>1424 <target bus="xen" dev="/dev/xvda"/>1425 </disk>1426 </devices>1427 </domain>""")1428 def test_config_xen_hvm(self):1429 obj = config.LibvirtConfigGuest()1430 obj.virt_type = "xen"1431 obj.memory = 100 * units.Mi1432 obj.vcpus = 21433 obj.cpuset = set([0, 1, 3, 4, 5])1434 obj.name = "demo"1435 obj.uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147"1436 obj.os_type = "hvm"1437 obj.os_loader = '/usr/lib/xen/boot/hvmloader'1438 obj.os_root = "root=xvda"1439 obj.os_cmdline = "console=xvc0"1440 obj.features = [1441 config.LibvirtConfigGuestFeatureACPI(),1442 config.LibvirtConfigGuestFeatureAPIC(),1443 config.LibvirtConfigGuestFeaturePAE(),1444 ]1445 disk = config.LibvirtConfigGuestDisk()1446 disk.source_type = "file"1447 disk.source_path = "/tmp/img"1448 disk.target_dev = "/dev/xvda"1449 disk.target_bus = "xen"1450 obj.add_device(disk)1451 xml = obj.to_xml()1452 self.assertXmlEqual(xml, """1453 <domain type="xen">1454 <uuid>b38a3f43-4be2-4046-897f-b67c2f5e0147</uuid>1455 <name>demo</name>1456 <memory>104857600</memory>1457 <vcpu cpuset="0-1,3-5">2</vcpu>1458 <os>1459 <type>hvm</type>1460 <loader>/usr/lib/xen/boot/hvmloader</loader>1461 <cmdline>console=xvc0</cmdline>1462 <root>root=xvda</root>1463 </os>1464 <features>1465 <acpi/>1466 <apic/>1467 <pae/>1468 </features>1469 <devices>1470 <disk type="file" device="disk">1471 <source file="/tmp/img"/>1472 <target bus="xen" dev="/dev/xvda"/>1473 </disk>1474 </devices>1475 </domain>""")1476 def test_config_kvm(self):1477 obj = config.LibvirtConfigGuest()1478 obj.virt_type = "kvm"1479 obj.memory = 100 * units.Mi1480 obj.vcpus = 21481 obj.cpuset = set([0, 1, 3, 4, 5])1482 obj.cputune = config.LibvirtConfigGuestCPUTune()1483 obj.cputune.shares = 1001484 obj.cputune.quota = 500001485 obj.cputune.period = 250001486 obj.membacking = config.LibvirtConfigGuestMemoryBacking()1487 page1 = config.LibvirtConfigGuestMemoryBackingPage()1488 page1.size_kb = 20481489 page1.nodeset = [0, 1, 2, 3, 5]1490 page2 = config.LibvirtConfigGuestMemoryBackingPage()1491 page2.size_kb = 10485761492 page2.nodeset = [4]1493 obj.membacking.hugepages.append(page1)1494 obj.membacking.hugepages.append(page2)1495 obj.memtune = config.LibvirtConfigGuestMemoryTune()1496 obj.memtune.hard_limit = 4961497 obj.memtune.soft_limit = 6721498 obj.memtune.swap_hard_limit = 16381499 obj.memtune.min_guarantee = 29701500 obj.numatune = config.LibvirtConfigGuestNUMATune()1501 numamemory = config.LibvirtConfigGuestNUMATuneMemory()1502 numamemory.mode = "preferred"1503 numamemory.nodeset = [0, 1, 2, 3, 8]1504 obj.numatune.memory = numamemory1505 numamemnode0 = config.LibvirtConfigGuestNUMATuneMemNode()1506 numamemnode0.cellid = 01507 numamemnode0.mode = "preferred"1508 numamemnode0.nodeset = [0, 1]1509 numamemnode1 = config.LibvirtConfigGuestNUMATuneMemNode()1510 numamemnode1.cellid = 11511 numamemnode1.mode = "preferred"1512 numamemnode1.nodeset = [2, 3]1513 numamemnode2 = config.LibvirtConfigGuestNUMATuneMemNode()1514 numamemnode2.cellid = 21515 numamemnode2.mode = "preferred"1516 numamemnode2.nodeset = [8]1517 obj.numatune.memnodes.extend([numamemnode0,1518 numamemnode1,1519 numamemnode2])1520 obj.name = "demo"1521 obj.uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147"1522 obj.os_type = "linux"1523 obj.os_boot_dev = ["hd", "cdrom", "fd"]1524 obj.os_smbios = config.LibvirtConfigGuestSMBIOS()1525 obj.features = [1526 config.LibvirtConfigGuestFeatureACPI(),1527 config.LibvirtConfigGuestFeatureAPIC(),1528 config.LibvirtConfigGuestFeaturePAE(),1529 ]1530 obj.sysinfo = config.LibvirtConfigGuestSysinfo()1531 obj.sysinfo.bios_vendor = "Acme"1532 obj.sysinfo.system_version = "1.0.0"1533 disk = config.LibvirtConfigGuestDisk()1534 disk.source_type = "file"1535 disk.source_path = "/tmp/img"1536 disk.target_dev = "/dev/vda"1537 disk.target_bus = "virtio"1538 obj.add_device(disk)1539 xml = obj.to_xml()1540 self.assertXmlEqual(xml, """1541 <domain type="kvm">1542 <uuid>b38a3f43-4be2-4046-897f-b67c2f5e0147</uuid>1543 <name>demo</name>1544 <memory>104857600</memory>1545 <memoryBacking>1546 <hugepages>1547 <page size="2048" unit="KiB" nodeset="0-3,5"/>1548 <page size="1048576" unit="KiB" nodeset="4"/>1549 </hugepages>1550 </memoryBacking>1551 <memtune>1552 <hard_limit units="K">496</hard_limit>1553 <soft_limit units="K">672</soft_limit>1554 <swap_hard_limit units="K">1638</swap_hard_limit>1555 <min_guarantee units="K">2970</min_guarantee>1556 </memtune>1557 <numatune>1558 <memory mode="preferred" nodeset="0-3,8"/>1559 <memnode cellid="0" mode="preferred" nodeset="0-1"/>1560 <memnode cellid="1" mode="preferred" nodeset="2-3"/>1561 <memnode cellid="2" mode="preferred" nodeset="8"/>1562 </numatune>1563 <vcpu cpuset="0-1,3-5">2</vcpu>1564 <sysinfo type='smbios'>1565 <bios>1566 <entry name="vendor">Acme</entry>1567 </bios>1568 <system>1569 <entry name="version">1.0.0</entry>1570 </system>1571 </sysinfo>1572 <os>1573 <type>linux</type>1574 <boot dev="hd"/>1575 <boot dev="cdrom"/>1576 <boot dev="fd"/>1577 <smbios mode="sysinfo"/>1578 </os>1579 <features>1580 <acpi/>1581 <apic/>1582 <pae/>1583 </features>1584 <cputune>1585 <shares>100</shares>1586 <quota>50000</quota>1587 <period>25000</period>1588 </cputune>1589 <devices>1590 <disk type="file" device="disk">1591 <source file="/tmp/img"/>1592 <target bus="virtio" dev="/dev/vda"/>1593 </disk>1594 </devices>1595 </domain>""")1596 def test_config_uefi(self):1597 obj = config.LibvirtConfigGuest()1598 obj.virt_type = "kvm"1599 obj.memory = 100 * units.Mi1600 obj.vcpus = 11601 obj.name = "uefi"1602 obj.uuid = "f01cf68d-515c-4daf-b85f-ef1424d93bfc"1603 obj.os_type = "x86_64"1604 obj.os_loader = '/tmp/OVMF.fd'1605 obj.os_loader_type = 'pflash'1606 xml = obj.to_xml()1607 self.assertXmlEqual(xml, """1608 <domain type="kvm">1609 <uuid>f01cf68d-515c-4daf-b85f-ef1424d93bfc</uuid>1610 <name>uefi</name>1611 <memory>104857600</memory>1612 <vcpu>1</vcpu>1613 <os>1614 <type>x86_64</type>1615 <loader readonly='yes' type='pflash'>/tmp/OVMF.fd</loader>1616 <nvram template="/tmp/OVMF.fd"></nvram>1617 </os>1618 </domain>""")1619 def test_config_boot_menu(self):1620 obj = config.LibvirtConfigGuest()1621 obj.virt_type = "kvm"1622 obj.memory = 100 * units.Mi1623 obj.vcpus = 21624 obj.name = "bootmenu"1625 obj.uuid = "f01cf68d-515c-4daf-b85f-ef1424d93bfc"1626 obj.os_type = "fake"1627 obj.os_bootmenu = True1628 xml = obj.to_xml()1629 self.assertXmlEqual(xml, """1630 <domain type="kvm">1631 <uuid>f01cf68d-515c-4daf-b85f-ef1424d93bfc</uuid>1632 <name>bootmenu</name>1633 <memory>104857600</memory>1634 <vcpu>2</vcpu>1635 <os>1636 <type>fake</type>1637 <bootmenu enable="yes"/>1638 </os>1639 </domain>""")1640 def test_config_machine_type(self):1641 obj = config.LibvirtConfigGuest()1642 obj.virt_type = "kvm"1643 obj.memory = 100 * units.Mi1644 obj.vcpus = 21645 obj.name = "demo"1646 obj.uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147"1647 obj.os_type = "hvm"1648 obj.os_mach_type = "fake_machine_type"1649 xml = obj.to_xml()1650 self.assertXmlEqual(xml, """1651 <domain type="kvm">1652 <uuid>b38a3f43-4be2-4046-897f-b67c2f5e0147</uuid>1653 <name>demo</name>1654 <memory>104857600</memory>1655 <vcpu>2</vcpu>1656 <os>1657 <type machine="fake_machine_type">hvm</type>1658 </os>1659 </domain>""")1660 def test_ConfigGuest_parse_devices(self):1661 xmldoc = """ <domain type="kvm">1662 <devices>1663 <hostdev mode="subsystem" type="pci" managed="no">1664 </hostdev>1665 </devices>1666 </domain>1667 """1668 obj = config.LibvirtConfigGuest()1669 obj.parse_str(xmldoc)1670 self.assertEqual(len(obj.devices), 1)1671 self.assertIsInstance(obj.devices[0],1672 config.LibvirtConfigGuestHostdevPCI)1673 self.assertEqual(obj.devices[0].mode, 'subsystem')1674 self.assertEqual(obj.devices[0].managed, 'no')1675 def test_ConfigGuest_parse_devices_wrong_type(self):1676 xmldoc = """ <domain type="kvm">1677 <devices>1678 <hostdev mode="subsystem" type="xxxx" managed="no">1679 </hostdev>1680 </devices>1681 </domain>1682 """1683 obj = config.LibvirtConfigGuest()1684 obj.parse_str(xmldoc)1685 self.assertEqual(len(obj.devices), 0)1686 def test_ConfigGuest_parese_cpu(self):1687 xmldoc = """ <domain>1688 <cpu mode='custom' match='exact'>1689 <model>kvm64</model>1690 </cpu>1691 </domain>1692 """1693 obj = config.LibvirtConfigGuest()1694 obj.parse_str(xmldoc)1695 self.assertEqual(obj.cpu.mode, 'custom')1696 self.assertEqual(obj.cpu.match, 'exact')1697 self.assertEqual(obj.cpu.model, 'kvm64')1698class LibvirtConfigGuestSnapshotTest(LibvirtConfigBaseTest):1699 def test_config_snapshot(self):1700 obj = config.LibvirtConfigGuestSnapshot()1701 obj.name = "Demo"1702 xml = obj.to_xml()1703 self.assertXmlEqual(xml, """1704 <domainsnapshot>1705 <name>Demo</name>1706 <disks/>1707 </domainsnapshot>""")1708 def test_config_snapshot_with_disks(self):1709 obj = config.LibvirtConfigGuestSnapshot()1710 obj.name = "Demo"1711 disk = config.LibvirtConfigGuestSnapshotDisk()1712 disk.name = 'vda'1713 disk.source_path = 'source-path'1714 disk.source_type = 'file'1715 disk.snapshot = 'external'1716 disk.driver_name = 'qcow2'1717 obj.add_disk(disk)1718 disk2 = config.LibvirtConfigGuestSnapshotDisk()1719 disk2.name = 'vdb'1720 disk2.snapshot = 'no'1721 obj.add_disk(disk2)1722 xml = obj.to_xml()1723 self.assertXmlEqual(xml, """1724 <domainsnapshot>1725 <name>Demo</name>1726 <disks>1727 <disk name='vda' snapshot='external' type='file'>1728 <source file='source-path'/>1729 </disk>1730 <disk name='vdb' snapshot='no'/>1731 </disks>1732 </domainsnapshot>""")1733 def test_config_snapshot_with_network_disks(self):1734 obj = config.LibvirtConfigGuestSnapshot()1735 obj.name = "Demo"1736 disk = config.LibvirtConfigGuestSnapshotDisk()1737 disk.name = 'vda'1738 disk.source_name = 'source-file'1739 disk.source_type = 'network'1740 disk.source_hosts = ['host1']1741 disk.source_ports = ['12345']1742 disk.source_protocol = 'glusterfs'1743 disk.snapshot = 'external'1744 disk.driver_name = 'qcow2'1745 obj.add_disk(disk)1746 disk2 = config.LibvirtConfigGuestSnapshotDisk()1747 disk2.name = 'vdb'1748 disk2.snapshot = 'no'1749 obj.add_disk(disk2)1750 xml = obj.to_xml()1751 self.assertXmlEqual(xml, """1752 <domainsnapshot>1753 <name>Demo</name>1754 <disks>1755 <disk name='vda' snapshot='external' type='network'>1756 <source protocol='glusterfs' name='source-file'>1757 <host name='host1' port='12345'/>1758 </source>1759 </disk>1760 <disk name='vdb' snapshot='no'/>1761 </disks>1762 </domainsnapshot>""")1763class LibvirtConfigNodeDeviceTest(LibvirtConfigBaseTest):1764 def test_config_virt_usb_device(self):1765 xmlin = """1766 <device>1767 <name>usb_0000_09_00_0</name>1768 <parent>pci_0000_00_1c_0</parent>1769 <driver>1770 <name>vxge</name>1771 </driver>1772 <capability type="usb">1773 <domain>0</domain>1774 <capability type="fake_usb">1775 <address fake_usb="fake"/>1776 </capability>1777 </capability>1778 </device>"""1779 obj = config.LibvirtConfigNodeDevice()1780 obj.parse_str(xmlin)1781 self.assertIsNone(obj.pci_capability)1782 def test_config_virt_device(self):1783 xmlin = """1784 <device>1785 <name>pci_0000_09_00_0</name>1786 <parent>pci_0000_00_1c_0</parent>1787 <driver>1788 <name>vxge</name>1789 </driver>1790 <capability type="pci">1791 <domain>0</domain>1792 <bus>9</bus>1793 <slot>0</slot>1794 <function>0</function>1795 <product id="0x5833">X3100 Series 10 Gigabit Ethernet PCIe</product>1796 <vendor id="0x17d5">Neterion Inc.</vendor>1797 <capability type="virt_functions">1798 <address domain="0x0000" bus="0x0a" slot="0x00" function="0x1"/>1799 <address domain="0x0000" bus="0x0a" slot="0x00" function="0x2"/>1800 <address domain="0x0000" bus="0x0a" slot="0x00" function="0x3"/>1801 </capability>1802 </capability>1803 </device>"""1804 obj = config.LibvirtConfigNodeDevice()1805 obj.parse_str(xmlin)1806 self.assertIsInstance(obj.pci_capability,1807 config.LibvirtConfigNodeDevicePciCap)1808 self.assertIsInstance(obj.pci_capability.fun_capability[0],1809 config.LibvirtConfigNodeDevicePciSubFunctionCap)1810 self.assertEqual(obj.pci_capability.fun_capability[0].type,1811 "virt_functions")1812 self.assertEqual(len(obj.pci_capability.fun_capability[0].1813 device_addrs),1814 3)1815 self.assertEqual(obj.pci_capability.bus, 9)1816 def test_config_phy_device(self):1817 xmlin = """1818 <device>1819 <name>pci_0000_33_00_0</name>1820 <parent>pci_0000_22_1c_0</parent>1821 <driver>1822 <name>vxx</name>1823 </driver>1824 <capability type="pci">1825 <domain>0</domain>1826 <bus>9</bus>1827 <slot>0</slot>1828 <function>0</function>1829 <product id="0x5833">X3100 Series 10 Gigabit Ethernet PCIe</product>1830 <vendor id="0x17d5">Neterion Inc.</vendor>1831 <capability type="phys_function">1832 <address domain='0x0000' bus='0x09' slot='0x00' function='0x0'/>1833 </capability>1834 </capability>1835 </device>"""1836 obj = config.LibvirtConfigNodeDevice()1837 obj.parse_str(xmlin)1838 self.assertIsInstance(obj.pci_capability,1839 config.LibvirtConfigNodeDevicePciCap)1840 self.assertIsInstance(obj.pci_capability.fun_capability[0],1841 config.LibvirtConfigNodeDevicePciSubFunctionCap)1842 self.assertEqual(obj.pci_capability.fun_capability[0].type,1843 "phys_function")1844 self.assertEqual(len(obj.pci_capability.fun_capability[0].1845 device_addrs),1846 1)1847 def test_config_non_device(self):1848 xmlin = """1849 <device>1850 <name>pci_0000_33_00_0</name>1851 <parent>pci_0000_22_1c_0</parent>1852 <driver>1853 <name>vxx</name>1854 </driver>1855 <capability type="pci">1856 <domain>0</domain>1857 <bus>9</bus>1858 <slot>0</slot>1859 <function>0</function>1860 <product id="0x5833">X3100 Series 10 Gigabit Ethernet PCIe</product>1861 <vendor id="0x17d5">Neterion Inc.</vendor>1862 <capability type="virt_functions"/>1863 </capability>1864 </device>"""1865 obj = config.LibvirtConfigNodeDevice()1866 obj.parse_str(xmlin)1867 self.assertIsInstance(obj.pci_capability,1868 config.LibvirtConfigNodeDevicePciCap)1869 self.assertIsInstance(obj.pci_capability.fun_capability[0],1870 config.LibvirtConfigNodeDevicePciSubFunctionCap)1871 self.assertEqual(obj.pci_capability.fun_capability[0].type,1872 "virt_functions")1873 def test_config_fail_device(self):1874 xmlin = """1875 <device>1876 <name>pci_0000_33_00_0</name>1877 <parent>pci_0000_22_1c_0</parent>1878 <driver>1879 <name>vxx</name>1880 </driver>1881 <capability type="pci">1882 <domain>0</domain>1883 <bus>9</bus>1884 <slot>0</slot>1885 <function>0</function>1886 <product id="0x5833">X3100 Series 10 Gigabit Ethernet PCIe</product>1887 <vendor id="0x17d5">Neterion Inc.</vendor>1888 <capability type="virt_functions">1889 </capability>1890 </capability>1891 </device>"""1892 obj = config.LibvirtConfigNodeDevice()1893 obj.parse_str(xmlin)1894 self.assertIsInstance(obj.pci_capability,1895 config.LibvirtConfigNodeDevicePciCap)1896 self.assertIsInstance(obj.pci_capability.fun_capability[0],1897 config.LibvirtConfigNodeDevicePciSubFunctionCap)1898 self.assertEqual(obj.pci_capability.fun_capability[0].type,1899 "virt_functions")1900 def test_config_2cap_device(self):1901 xmlin = """1902 <device>1903 <name>pci_0000_04_10_7</name>1904 <parent>pci_0000_00_01_1</parent>1905 <driver>1906 <name>igbvf</name>1907 </driver>1908 <capability type='pci'>1909 <domain>0</domain>1910 <bus>4</bus>1911 <slot>16</slot>1912 <function>7</function>1913 <product id='0x1520'>I350 Ethernet Controller Virtual</product>1914 <vendor id='0x8086'>Intel Corporation</vendor>1915 <capability type='phys_function'>1916 <address domain='0x0000' bus='0x04' slot='0x00' function='0x3'/>1917 </capability>1918 <capability type='virt_functions'>1919 <address domain='0x0000' bus='0x04' slot='0x00' function='0x3'/>1920 </capability>1921 </capability>1922 </device>"""1923 obj = config.LibvirtConfigNodeDevice()1924 obj.parse_str(xmlin)1925 self.assertIsInstance(obj.pci_capability,1926 config.LibvirtConfigNodeDevicePciCap)1927 self.assertIsInstance(obj.pci_capability.fun_capability[0],1928 config.LibvirtConfigNodeDevicePciSubFunctionCap)1929 self.assertEqual(obj.pci_capability.fun_capability[0].type,1930 "phys_function")1931 self.assertEqual(obj.pci_capability.fun_capability[1].type,1932 "virt_functions")1933class LibvirtConfigNodeDevicePciCapTest(LibvirtConfigBaseTest):1934 def test_config_device_pci_cap(self):1935 xmlin = """1936 <capability type="pci">1937 <domain>0</domain>1938 <bus>10</bus>1939 <slot>1</slot>1940 <function>5</function>1941 <product id="0x10bd">Intel 10 Gigabit Ethernet</product>1942 <vendor id="0x8086">Intel Inc.</vendor>1943 <capability type="virt_functions">1944 <address domain="0000" bus="0x0a" slot="0x1" function="0x1"/>1945 <address domain="0001" bus="0x0a" slot="0x02" function="0x03"/>1946 </capability>1947 </capability>"""1948 obj = config.LibvirtConfigNodeDevicePciCap()1949 obj.parse_str(xmlin)1950 self.assertEqual(obj.domain, 0)1951 self.assertEqual(obj.bus, 10)1952 self.assertEqual(obj.slot, 1)1953 self.assertEqual(obj.function, 5)1954 self.assertEqual(obj.product, "Intel 10 Gigabit Ethernet")1955 self.assertEqual(obj.product_id, 0x10bd)1956 self.assertEqual(obj.vendor, "Intel Inc.")1957 self.assertEqual(obj.vendor_id, 0x8086)1958 self.assertIsNone(obj.numa_node)1959 self.assertIsInstance(obj.fun_capability[0],1960 config.LibvirtConfigNodeDevicePciSubFunctionCap)1961 self.assertEqual(obj.fun_capability[0].type, 'virt_functions')1962 self.assertEqual(obj.fun_capability[0].device_addrs,1963 [(0, 10, 1, 1),1964 (1, 10, 2, 3), ])1965 def test_config_device_pci_2cap(self):1966 xmlin = """1967 <capability type="pci">1968 <domain>0</domain>1969 <bus>10</bus>1970 <slot>1</slot>1971 <function>5</function>1972 <product id="0x10bd">Intel 10 Gigabit Ethernet</product>1973 <vendor id="0x8086">Intel Inc.</vendor>1974 <numa node='0'/>1975 <capability type="virt_functions">1976 <address domain="0000" bus="0x0a" slot="0x1" function="0x1"/>1977 <address domain="0001" bus="0x0a" slot="0x02" function="0x03"/>1978 </capability>1979 <capability type="phys_function">1980 <address domain="0000" bus="0x0a" slot="0x1" function="0x1"/>1981 </capability>1982 </capability>"""1983 obj = config.LibvirtConfigNodeDevicePciCap()1984 obj.parse_str(xmlin)1985 self.assertEqual(obj.domain, 0)1986 self.assertEqual(obj.bus, 10)1987 self.assertEqual(obj.slot, 1)1988 self.assertEqual(obj.function, 5)1989 self.assertEqual(obj.product, "Intel 10 Gigabit Ethernet")1990 self.assertEqual(obj.product_id, 0x10bd)1991 self.assertEqual(obj.vendor, "Intel Inc.")1992 self.assertEqual(obj.vendor_id, 0x8086)1993 self.assertEqual(0, obj.numa_node)1994 self.assertIsInstance(obj.fun_capability[0],1995 config.LibvirtConfigNodeDevicePciSubFunctionCap)1996 self.assertEqual(obj.fun_capability[0].type, 'virt_functions')1997 self.assertEqual(obj.fun_capability[0].device_addrs,1998 [(0, 10, 1, 1),1999 (1, 10, 2, 3), ])2000 self.assertEqual(obj.fun_capability[1].type, 'phys_function')2001 self.assertEqual(obj.fun_capability[1].device_addrs,2002 [(0, 10, 1, 1), ])2003class LibvirtConfigNodeDevicePciSubFunctionCap(LibvirtConfigBaseTest):2004 def test_config_device_pci_subfunction(self):2005 xmlin = """2006 <capability type="virt_functions">2007 <address domain="0000" bus="0x0a" slot="0x1" function="0x1"/>2008 <address domain="0001" bus="0x0a" slot="0x02" function="0x03"/>2009 </capability>"""2010 fun_capability = config.LibvirtConfigNodeDevicePciSubFunctionCap()2011 fun_capability.parse_str(xmlin)2012 self.assertEqual('virt_functions', fun_capability.type)2013 self.assertEqual([(0, 10, 1, 1),2014 (1, 10, 2, 3)],2015 fun_capability.device_addrs)2016class LibvirtConfigGuestVideoTest(LibvirtConfigBaseTest):2017 def test_config_video_driver(self):2018 obj = config.LibvirtConfigGuestVideo()2019 obj.type = 'qxl'2020 xml = obj.to_xml()2021 self.assertXmlEqual(xml, """2022 <video>2023 <model type='qxl'/>2024 </video>""")2025 def test_config_video_driver_vram_heads(self):2026 obj = config.LibvirtConfigGuestVideo()2027 obj.type = 'qxl'2028 obj.vram = '9216'2029 obj.heads = '1'2030 xml = obj.to_xml()2031 self.assertXmlEqual(xml, """2032 <video>2033 <model type='qxl' vram='9216' heads='1'/>2034 </video>""")2035class LibvirtConfigGuestSeclabel(LibvirtConfigBaseTest):2036 def test_config_seclabel_config(self):2037 obj = config.LibvirtConfigSeclabel()2038 xml = obj.to_xml()2039 self.assertXmlEqual(xml, """2040 <seclabel type='dynamic'/>""")2041 def test_config_seclabel_baselabel(self):2042 obj = config.LibvirtConfigSeclabel()2043 obj.type = 'dynamic'2044 obj.baselabel = 'system_u:system_r:my_svirt_t:s0'2045 xml = obj.to_xml()2046 self.assertXmlEqual(xml, """2047 <seclabel type='dynamic'>2048 <baselabel>system_u:system_r:my_svirt_t:s0</baselabel>2049 </seclabel>""")2050class LibvirtConfigGuestRngTest(LibvirtConfigBaseTest):2051 def test_config_rng_driver(self):2052 obj = config.LibvirtConfigGuestRng()2053 xml = obj.to_xml()2054 self.assertXmlEqual(xml, """2055<rng model='virtio'>2056 <backend model='random'/>2057</rng>""")2058 def test_config_rng_driver_with_rate(self):2059 obj = config.LibvirtConfigGuestRng()2060 obj.backend = '/dev/random'2061 obj.rate_period = '12'2062 obj.rate_bytes = '34'2063 xml = obj.to_xml()2064 self.assertXmlEqual(xml, """2065<rng model='virtio'>2066 <rate period='12' bytes='34'/>2067 <backend model='random'>/dev/random</backend>2068</rng>""")2069class LibvirtConfigGuestControllerTest(LibvirtConfigBaseTest):2070 def test_config_guest_contoller(self):2071 obj = config.LibvirtConfigGuestController()2072 obj.type = 'scsi'2073 obj.index = 02074 obj.model = 'virtio-scsi'2075 xml = obj.to_xml()2076 self.assertXmlEqual(xml, """2077 <controller type='scsi' index='0' model='virtio-scsi'/>""")2078class LibvirtConfigGuestWatchdogTest(LibvirtConfigBaseTest):2079 def test_config_watchdog(self):2080 obj = config.LibvirtConfigGuestWatchdog()2081 obj.action = 'none'2082 xml = obj.to_xml()2083 self.assertXmlEqual(xml, "<watchdog model='i6300esb' action='none'/>")2084 def test_config_watchdog_default_action(self):2085 obj = config.LibvirtConfigGuestWatchdog()2086 xml = obj.to_xml()2087 self.assertXmlEqual(xml, "<watchdog model='i6300esb' action='reset'/>")2088class LibvirtConfigGuestCPUTuneTest(LibvirtConfigBaseTest):2089 def test_config_cputune_timeslice(self):2090 cputune = config.LibvirtConfigGuestCPUTune()2091 cputune.shares = 1002092 cputune.quota = 500002093 cputune.period = 250002094 xml = cputune.to_xml()2095 self.assertXmlEqual(xml, """2096 <cputune>2097 <shares>100</shares>2098 <quota>50000</quota>2099 <period>25000</period>2100 </cputune>""")2101 def test_config_cputune_vcpus(self):2102 cputune = config.LibvirtConfigGuestCPUTune()2103 vcpu0 = config.LibvirtConfigGuestCPUTuneVCPUPin()2104 vcpu0.id = 02105 vcpu0.cpuset = set([0, 1])2106 vcpu1 = config.LibvirtConfigGuestCPUTuneVCPUPin()2107 vcpu1.id = 12108 vcpu1.cpuset = set([2, 3])2109 vcpu2 = config.LibvirtConfigGuestCPUTuneVCPUPin()2110 vcpu2.id = 22111 vcpu2.cpuset = set([4, 5])2112 vcpu3 = config.LibvirtConfigGuestCPUTuneVCPUPin()2113 vcpu3.id = 32114 vcpu3.cpuset = set([6, 7])2115 cputune.vcpupin.extend([vcpu0, vcpu1, vcpu2, vcpu3])2116 emu = config.LibvirtConfigGuestCPUTuneEmulatorPin()2117 emu.cpuset = set([0, 1, 2, 3, 4, 5, 6, 7])2118 cputune.emulatorpin = emu2119 sch0 = config.LibvirtConfigGuestCPUTuneVCPUSched()2120 sch0.vcpus = set([0, 1, 2, 3])2121 sch0.scheduler = "fifo"2122 sch0.priority = 12123 sch1 = config.LibvirtConfigGuestCPUTuneVCPUSched()2124 sch1.vcpus = set([4, 5, 6, 7])2125 sch1.scheduler = "fifo"2126 sch1.priority = 992127 cputune.vcpusched.extend([sch0, sch1])2128 xml = cputune.to_xml()2129 self.assertXmlEqual(xml, """2130 <cputune>2131 <emulatorpin cpuset="0-7"/>2132 <vcpupin vcpu="0" cpuset="0-1"/>2133 <vcpupin vcpu="1" cpuset="2-3"/>2134 <vcpupin vcpu="2" cpuset="4-5"/>2135 <vcpupin vcpu="3" cpuset="6-7"/>2136 <vcpusched vcpus="0-3" scheduler="fifo" priority="1"/>2137 <vcpusched vcpus="4-7" scheduler="fifo" priority="99"/>2138 </cputune>""")2139class LibvirtConfigGuestMemoryBackingTest(LibvirtConfigBaseTest):2140 def test_config_memory_backing_none(self):2141 obj = config.LibvirtConfigGuestMemoryBacking()2142 xml = obj.to_xml()2143 self.assertXmlEqual(xml, "<memoryBacking/>")2144 def test_config_memory_backing_all(self):2145 obj = config.LibvirtConfigGuestMemoryBacking()2146 obj.locked = True2147 obj.sharedpages = False2148 page = config.LibvirtConfigGuestMemoryBackingPage()2149 page.size_kb = 20482150 page.nodeset = [2, 3]2151 obj.hugepages.append(page)2152 xml = obj.to_xml()2153 self.assertXmlEqual(xml, """2154 <memoryBacking>2155 <hugepages>2156 <page size="2048" unit="KiB" nodeset="2-3"/>2157 </hugepages>2158 <nosharepages/>2159 <locked/>2160 </memoryBacking>""")2161class LibvirtConfigGuestMemoryTuneTest(LibvirtConfigBaseTest):2162 def test_config_memory_backing_none(self):2163 obj = config.LibvirtConfigGuestMemoryTune()2164 xml = obj.to_xml()2165 self.assertXmlEqual(xml, "<memtune/>")2166 def test_config_memory_backing_all(self):2167 obj = config.LibvirtConfigGuestMemoryTune()2168 obj.soft_limit = 62169 obj.hard_limit = 282170 obj.swap_hard_limit = 1402171 obj.min_guarantee = 2702172 xml = obj.to_xml()2173 self.assertXmlEqual(xml, """2174 <memtune>2175 <hard_limit units="K">28</hard_limit>2176 <soft_limit units="K">6</soft_limit>2177 <swap_hard_limit units="K">140</swap_hard_limit>2178 <min_guarantee units="K">270</min_guarantee>2179 </memtune>""")2180class LibvirtConfigGuestNUMATuneTest(LibvirtConfigBaseTest):2181 def test_config_numa_tune_none(self):2182 obj = config.LibvirtConfigGuestNUMATune()2183 xml = obj.to_xml()2184 self.assertXmlEqual("<numatune/>", xml)2185 def test_config_numa_tune_memory(self):2186 obj = config.LibvirtConfigGuestNUMATune()2187 numamemory = config.LibvirtConfigGuestNUMATuneMemory()2188 numamemory.nodeset = [0, 1, 2, 3, 8]2189 obj.memory = numamemory2190 xml = obj.to_xml()2191 self.assertXmlEqual("""2192 <numatune>2193 <memory mode="strict" nodeset="0-3,8"/>2194 </numatune>""", xml)2195 def test_config_numa_tune_memnodes(self):2196 obj = config.LibvirtConfigGuestNUMATune()2197 numamemnode0 = config.LibvirtConfigGuestNUMATuneMemNode()2198 numamemnode0.cellid = 02199 numamemnode0.nodeset = [0, 1]2200 numamemnode1 = config.LibvirtConfigGuestNUMATuneMemNode()2201 numamemnode1.cellid = 12202 numamemnode1.nodeset = [2, 3]2203 numamemnode2 = config.LibvirtConfigGuestNUMATuneMemNode()2204 numamemnode2.cellid = 22205 numamemnode2.nodeset = [8]2206 obj.memnodes.extend([numamemnode0,2207 numamemnode1,2208 numamemnode2])2209 xml = obj.to_xml()2210 self.assertXmlEqual("""2211 <numatune>2212 <memnode cellid="0" mode="strict" nodeset="0-1"/>2213 <memnode cellid="1" mode="strict" nodeset="2-3"/>2214 <memnode cellid="2" mode="strict" nodeset="8"/>2215 </numatune>""", xml)2216class LibvirtConfigGuestMetadataNovaTest(LibvirtConfigBaseTest):2217 def test_config_metadata(self):2218 meta = config.LibvirtConfigGuestMetaNovaInstance()2219 meta.package = "2014.2.3"2220 meta.name = "moonbuggy"2221 meta.creationTime = 12345678902222 meta.roottype = "image"2223 meta.rootid = "fe55c69a-8b2e-4bbc-811a-9ad2023a0426"2224 owner = config.LibvirtConfigGuestMetaNovaOwner()2225 owner.userid = "3472c2a6-de91-4fb5-b618-42bc781ef670"2226 owner.username = "buzz"2227 owner.projectid = "f241e906-010e-4917-ae81-53f4fb8aa021"2228 owner.projectname = "moonshot"2229 meta.owner = owner2230 flavor = config.LibvirtConfigGuestMetaNovaFlavor()2231 flavor.name = "m1.lowgravity"2232 flavor.vcpus = 82233 flavor.memory = 20482234 flavor.swap = 102235 flavor.disk = 502236 flavor.ephemeral = 102237 meta.flavor = flavor2238 xml = meta.to_xml()2239 self.assertXmlEqual(xml, """2240 <nova:instance xmlns:nova='http://openstack.org/xmlns/libvirt/nova/1.0'>2241 <nova:package version="2014.2.3"/>2242 <nova:name>moonbuggy</nova:name>2243 <nova:creationTime>2009-02-13 23:31:30</nova:creationTime>2244 <nova:flavor name="m1.lowgravity">2245 <nova:memory>2048</nova:memory>2246 <nova:disk>50</nova:disk>2247 <nova:swap>10</nova:swap>2248 <nova:ephemeral>10</nova:ephemeral>2249 <nova:vcpus>8</nova:vcpus>2250 </nova:flavor>2251 <nova:owner>2252 <nova:user2253 uuid="3472c2a6-de91-4fb5-b618-42bc781ef670">buzz</nova:user>2254 <nova:project2255 uuid="f241e906-010e-4917-ae81-53f4fb8aa021">moonshot</nova:project>2256 </nova:owner>2257 <nova:root type="image" uuid="fe55c69a-8b2e-4bbc-811a-9ad2023a0426"/>2258 </nova:instance>2259 """)2260class LibvirtConfigGuestIDMap(LibvirtConfigBaseTest):2261 def test_config_id_map_parse_start_not_int(self):2262 xmlin = "<uid start='a' target='20000' count='5'/>"2263 obj = config.LibvirtConfigGuestIDMap()2264 self.assertRaises(ValueError, obj.parse_str, xmlin)2265 def test_config_id_map_parse_target_not_int(self):2266 xmlin = "<uid start='2' target='a' count='5'/>"2267 obj = config.LibvirtConfigGuestIDMap()2268 self.assertRaises(ValueError, obj.parse_str, xmlin)2269 def test_config_id_map_parse_count_not_int(self):2270 xmlin = "<uid start='2' target='20000' count='a'/>"2271 obj = config.LibvirtConfigGuestIDMap()2272 self.assertRaises(ValueError, obj.parse_str, xmlin)2273 def test_config_uid_map(self):2274 obj = config.LibvirtConfigGuestUIDMap()2275 obj.start = 12276 obj.target = 100002277 obj.count = 22278 xml = obj.to_xml()2279 self.assertXmlEqual("<uid start='1' target='10000' count='2'/>", xml)2280 def test_config_uid_map_parse(self):2281 xmlin = "<uid start='2' target='20000' count='5'/>"2282 obj = config.LibvirtConfigGuestUIDMap()2283 obj.parse_str(xmlin)2284 self.assertEqual(2, obj.start)2285 self.assertEqual(20000, obj.target)2286 self.assertEqual(5, obj.count)2287 def test_config_gid_map(self):2288 obj = config.LibvirtConfigGuestGIDMap()2289 obj.start = 12290 obj.target = 100002291 obj.count = 22292 xml = obj.to_xml()2293 self.assertXmlEqual("<gid start='1' target='10000' count='2'/>", xml)2294 def test_config_gid_map_parse(self):2295 xmlin = "<gid start='2' target='20000' count='5'/>"2296 obj = config.LibvirtConfigGuestGIDMap()2297 obj.parse_str(xmlin)2298 self.assertEqual(2, obj.start)2299 self.assertEqual(20000, obj.target)2300 self.assertEqual(5, obj.count)2301class LibvirtConfigMemoryBalloonTest(LibvirtConfigBaseTest):2302 def test_config_memory_balloon_period(self):2303 balloon = config.LibvirtConfigMemoryBalloon()2304 balloon.model = 'fake_virtio'2305 balloon.period = 112306 xml = balloon.to_xml()2307 expected_xml = """2308 <memballoon model='fake_virtio'>2309 <stats period='11'/>2310 </memballoon>"""2311 self.assertXmlEqual(expected_xml, xml)2312 def test_config_memory_balloon_no_period(self):2313 balloon = config.LibvirtConfigMemoryBalloon()2314 balloon.model = 'fake_virtio'2315 xml = balloon.to_xml()2316 expected_xml = """2317 <memballoon model='fake_virtio' />"""2318 self.assertXmlEqual(expected_xml, xml)2319class LibvirtConfigSecretTest(LibvirtConfigBaseTest):2320 def test_config_secret_volume(self):2321 secret = config.LibvirtConfigSecret()2322 secret.ephemeral = True2323 secret.private = True2324 secret.description = 'sample desc'2325 secret.uuid = 'c7a5fdbd-edaf-9455-926a-d65c16db1809'2326 secret.usage_type = 'volume'2327 secret.usage_id = 'sample_volume'2328 xml = secret.to_xml()2329 expected_xml = """2330 <secret ephemeral="yes" private="yes">2331 <description>sample desc</description>2332 <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>2333 <usage type="volume">2334 <volume>sample_volume</volume>2335 </usage>2336 </secret>"""2337 self.assertXmlEqual(expected_xml, xml)2338 def test_config_secret_ceph(self):2339 secret = config.LibvirtConfigSecret()2340 secret.ephemeral = True2341 secret.private = True2342 secret.description = 'sample desc'2343 secret.usage_type = 'ceph'2344 secret.usage_id = 'sample_name'2345 xml = secret.to_xml()2346 expected_xml = """2347 <secret ephemeral="yes" private="yes">2348 <description>sample desc</description>2349 <usage type="ceph">2350 <name>sample_name</name>2351 </usage>2352 </secret>"""2353 self.assertXmlEqual(expected_xml, xml)2354 def test_config_secret_iscsi(self):2355 secret = config.LibvirtConfigSecret()2356 secret.ephemeral = True2357 secret.private = True2358 secret.description = 'sample desc'2359 secret.usage_type = 'iscsi'2360 secret.usage_id = 'sample_target'2361 xml = secret.to_xml()2362 expected_xml = """2363 <secret ephemeral="yes" private="yes">2364 <description>sample desc</description>2365 <usage type="iscsi">2366 <target>sample_target</target>2367 </usage>2368 </secret>"""...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-django automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful