Skip to content

Commit 4ba00c8

Browse files
committed
tests: work around malformed serial XML
The serial elements in fakelibvirt's XMLDesc() are malformed. They are only enough to pass existing unit tests, but are not future-proof, and would not work with something like migration._update_serial_xml(). In addition, two of them (type=file and type=pty) are not actually used by anything. This patch removes the unused types and starts checking the CONF.serial_console.enabled flag before including any serial XML in the fake domain. This allows tests that don't set serial_console_enabled (like the subsequent NUMA LM func test) to not have to deal with the broken serial XML, while tests that relied on it in the past now just set serial_console_enabled = True. Change-Id: Ie74fcd689a627c178f80ec60df2dfef40576f182
1 parent ee05cd8 commit 4ba00c8

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

nova/tests/unit/virt/libvirt/fakelibvirt.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from oslo_log import log as logging
2222
from oslo_utils.fixture import uuidsentinel as uuids
2323

24+
from nova import conf
2425
from nova.objects import fields as obj_fields
2526
from nova.tests.unit.virt.libvirt import fake_libvirt_data
2627
from nova.virt.libvirt import config as vconfig
@@ -40,6 +41,7 @@ def _reset():
4041

4142

4243
LOG = logging.getLogger(__name__)
44+
CONF = conf.CONF
4345

4446
# virDomainState
4547
VIR_DOMAIN_NOSTATE = 0
@@ -1066,6 +1068,12 @@ def XMLDesc(self, flags):
10661068
</memory>
10671069
''' % vpmem
10681070

1071+
serial_console = ''
1072+
if CONF.serial_console.enabled:
1073+
serial_console = """<serial type="tcp">
1074+
<source host="-1" service="-1" mode="bind"/>
1075+
</serial>"""
1076+
10691077
return '''<domain type='kvm'>
10701078
<name>%(name)s</name>
10711079
<uuid>%(uuid)s</uuid>
@@ -1093,17 +1101,7 @@ def XMLDesc(self, flags):
10931101
function='0x1'/>
10941102
</controller>
10951103
%(nics)s
1096-
<serial type='file'>
1097-
<source path='dummy.log'/>
1098-
<target port='0'/>
1099-
</serial>
1100-
<serial type='pty'>
1101-
<source pty='/dev/pts/27'/>
1102-
<target port='1'/>
1103-
</serial>
1104-
<serial type='tcp'>
1105-
<source host="-1" service="-1" mode="bind"/>
1106-
</serial>
1104+
%(serial_console)s
11071105
<console type='file'>
11081106
<source path='dummy.log'/>
11091107
<target port='0'/>
@@ -1132,7 +1130,8 @@ def XMLDesc(self, flags):
11321130
'disks': disks,
11331131
'nics': nics,
11341132
'hostdevs': hostdevs,
1135-
'vpmems': vpmems}
1133+
'vpmems': vpmems,
1134+
'serial_console': serial_console}
11361135

11371136
def managedSave(self, flags):
11381137
self._connection._mark_not_running(self)

nova/tests/unit/virt/test_virt_drivers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ def test_get_rdp_console(self):
572572

573573
@catch_notimplementederror
574574
def test_get_serial_console(self):
575+
self.flags(enabled=True, group='serial_console')
575576
instance_ref, network_info = self._get_running_instance()
576577
serial_console = self.connection.get_serial_console(self.ctxt,
577578
instance_ref)

0 commit comments

Comments
 (0)