Merge "allow tcp-based consoles in get_console_output"

This commit is contained in:
Zuul 2018-12-18 16:15:16 +00:00 committed by Gerrit Code Review
commit 2a067e9441
2 changed files with 49 additions and 0 deletions

View File

@ -13334,6 +13334,54 @@ class LibvirtConnTestCase(test.NoDBTestCase,
self.assertEqual(b'67890', output)
# this test resembles test_get_console_output_file() except
# that the instance was created with a tcp-based serial console
# which results in a different XML
@mock.patch('nova.privsep.path.last_bytes',
return_value=(b'67891', 0))
def test_get_console_output_tcp(self, mock_last_bytes):
with utils.tempdir() as tmpdir:
self.flags(instances_path=tmpdir)
# flags to enable the serial console are not necessary
# as we use a fake dom
instance_ref = self.test_instance
instance_ref['image_ref'] = 123456
instance = objects.Instance(**instance_ref)
console_dir = (os.path.join(tmpdir, instance['name']))
console_log = '%s/console.log' % (console_dir)
fake_dom_xml = """
<domain type='kvm'>
<devices>
<disk type='file'>
<source file='filename'/>
</disk>
<console type='tcp'>
<log file='%s'/>
</console>
</devices>
</domain>
""" % console_log
def fake_lookup(id):
return FakeVirtDomain(fake_dom_xml)
self.create_fake_libvirt_mock()
libvirt_driver.LibvirtDriver._conn.lookupByUUIDString = fake_lookup
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
try:
prev_max = libvirt_driver.MAX_CONSOLE_BYTES
libvirt_driver.MAX_CONSOLE_BYTES = 5
with mock.patch('os.path.exists', return_value=True):
output = drvr.get_console_output(self.context, instance)
finally:
libvirt_driver.MAX_CONSOLE_BYTES = prev_max
self.assertEqual(b'67891', output)
def test_get_console_output_file_missing(self):
with utils.tempdir() as tmpdir:
self.flags(instances_path=tmpdir)

View File

@ -3122,6 +3122,7 @@ class LibvirtDriver(driver.ComputeDriver):
# check for different types of consoles
path_sources = [
('file', "./devices/console[@type='file']/source[@path]", 'path'),
('tcp', "./devices/console[@type='tcp']/log[@file]", 'file'),
('pty', "./devices/console[@type='pty']/source[@path]", 'path')]
console_type = ""
console_path = ""