]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Fix HTTP 500 raised for getConsoleLog for stopped instance
authorKevin_Zheng <zhengzhenyu@huawei.com>
Mon, 10 Apr 2017 09:28:33 +0000 (17:28 +0800)
committerMatt Riedemann <mriedem.os@gmail.com>
Thu, 13 Apr 2017 16:04:43 +0000 (12:04 -0400)
Stopped instances with pty console will not contain
`source_node` information, and in the current
implementation the pty variable used later will
result in an UnboundLocalError, which results in a
500 error out of the API.

Closes-bug: #1680363

Change-Id: I4dffba959e2292254dc757f22c3f7893d2da72f9
(cherry picked from commit 0c2b73e80141c6bef309097d1cbd0129d6ca094d)

nova/tests/unit/virt/libvirt/test_driver.py
nova/virt/libvirt/driver.py

index 1608b1ffb85df141a45cdda4df4889631b4cdeb0..3be22f6eb642ab668612923320f27d791f4aa2da 100644 (file)
@@ -11078,6 +11078,30 @@ class LibvirtConnTestCase(test.NoDBTestCase):
 
             self.assertEqual(b'67890', output)
 
+    def test_get_console_output_pty_not_available(self):
+        instance = objects.Instance(**self.test_instance)
+        fake_dom_xml = """
+            <domain type='kvm'>
+                <devices>
+                    <disk type='file'>
+                        <source file='filename'/>
+                    </disk>
+                    <console type='pty'>
+                        <target port='0'/>
+                    </console>
+                </devices>
+            </domain>
+        """
+
+        def fake_lookup(id):
+            return FakeVirtDomain(fake_dom_xml)
+
+        self.create_fake_libvirt_mock()
+        libvirt_driver.LibvirtDriver._conn.lookupByName = fake_lookup
+        drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
+        self.assertRaises(exception.ConsoleNotAvailable,
+                          drvr.get_console_output, self.context, instance)
+
     @mock.patch('nova.virt.libvirt.host.Host.get_domain')
     @mock.patch.object(libvirt_guest.Guest, "get_xml_desc")
     def test_get_console_output_not_available(self, mock_get_xml, get_domain):
index db2f6ba93dce1489ee09ad066109f53c753bb843..0e8fe0702c149e7a11c4f9a37beea89407e483e3 100644 (file)
@@ -2783,6 +2783,8 @@ class LibvirtDriver(driver.ComputeDriver):
                 if not pty:
                     continue
                 break
+            else:
+                raise exception.ConsoleNotAvailable()
         else:
             raise exception.ConsoleNotAvailable()