libvirt: remove explicit /dev/random rng default

libvirt (or rather qemu) will default to /dev/random if no rng device
path is specified i.e.

  <rng model='virtio'>
    <backend model='random'/>
  </rng>

It's preferable for us to not duplicate this default to allow for a
future where libvirt or the hypervisor needs to make more intelligent
decisions about the default device to use.

Also, improve the unit tests to catch this issue.

Change-Id: Ia0f922f7de575496972b4dfa9d56aa22205f1758
This commit is contained in:
Mark McLoughlin
2014-02-19 07:24:17 +00:00
parent 3dcf8347da
commit 605677ca57
3 changed files with 12 additions and 2 deletions

View File

@@ -1387,6 +1387,10 @@ class LibvirtConnTestCase(test.TestCase):
vconfig.LibvirtConfigGuestVideo)
self.assertIsInstance(cfg.devices[6],
vconfig.LibvirtConfigGuestRng)
self.assertEqual(cfg.devices[6].model, 'random')
self.assertIsNone(cfg.devices[6].backend)
self.assertIsNone(cfg.devices[6].rate_bytes)
self.assertIsNone(cfg.devices[6].rate_period)
def test_get_guest_config_with_rng_not_allowed(self):
self.flags(virt_type='kvm',
@@ -1453,6 +1457,8 @@ class LibvirtConnTestCase(test.TestCase):
vconfig.LibvirtConfigGuestVideo)
self.assertIsInstance(cfg.devices[6],
vconfig.LibvirtConfigGuestRng)
self.assertEqual(cfg.devices[6].model, 'random')
self.assertIsNone(cfg.devices[6].backend)
self.assertEqual(cfg.devices[6].rate_bytes, 1024)
self.assertEqual(cfg.devices[6].rate_period, 2)
@@ -1495,7 +1501,10 @@ class LibvirtConnTestCase(test.TestCase):
vconfig.LibvirtConfigGuestVideo)
self.assertIsInstance(cfg.devices[6],
vconfig.LibvirtConfigGuestRng)
self.assertEqual(cfg.devices[6].model, 'random')
self.assertEqual(cfg.devices[6].backend, '/dev/hw_rng')
self.assertIsNone(cfg.devices[6].rate_bytes)
self.assertIsNone(cfg.devices[6].rate_period)
def test_get_guest_config_with_rng_dev_not_present(self):
self.flags(virt_type='kvm',

View File

@@ -1616,11 +1616,12 @@ class LibvirtConfigGuestRngTest(LibvirtConfigBaseTest):
xml = obj.to_xml()
self.assertXmlEqual(xml, """
<rng model='virtio'>
<backend model='random'>/dev/random</backend>
<backend model='random'/>
</rng>""")
def test_config_rng_driver_with_rate(self):
obj = config.LibvirtConfigGuestRng()
obj.backend = '/dev/random'
obj.rate_period = '12'
obj.rate_bytes = '34'

View File

@@ -1371,7 +1371,7 @@ class LibvirtConfigGuestRng(LibvirtConfigGuestDevice):
**kwargs)
self.model = 'random'
self.backend = '/dev/random'
self.backend = None
self.rate_period = None
self.rate_bytes = None