Use fake_libvirt_utils for libvirt console tests.
Updates test_libvirt.py so that it users fake_libvirt_utils. This resolves an issue where the previous tests required sudo to properly execute. Fixes LP Bug #992805. Change-Id: I9354b8facf82fb861dc2fe6da5fca102d8a33fbf
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import StringIO
|
||||
|
||||
files = {}
|
||||
@@ -89,7 +90,11 @@ def file_open(path, mode=None):
|
||||
|
||||
|
||||
def load_file(path):
|
||||
return ''
|
||||
if os.path.exists(path):
|
||||
with open(path, 'r+') as fp:
|
||||
return fp.read()
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def file_delete(path):
|
||||
|
@@ -1403,7 +1403,6 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
shutil.rmtree(os.path.join(FLAGS.instances_path,
|
||||
FLAGS.base_dir_name))
|
||||
|
||||
@test.skip_if(missing_libvirt(), "Test requires libvirt")
|
||||
def test_get_console_output_file(self):
|
||||
|
||||
with utils.tempdir() as tmpdir:
|
||||
@@ -1438,13 +1437,12 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
|
||||
self.create_fake_libvirt_mock()
|
||||
connection.LibvirtConnection._conn.lookupByName = fake_lookup
|
||||
connection.libvirt_utils = libvirt_utils
|
||||
connection.libvirt_utils = fake_libvirt_utils
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
output = conn.get_console_output(instance)
|
||||
self.assertEquals("foo", output)
|
||||
|
||||
@test.skip_if(missing_libvirt(), "Test requires libvirt")
|
||||
def test_get_console_output_pty(self):
|
||||
|
||||
with utils.tempdir() as tmpdir:
|
||||
@@ -1477,9 +1475,14 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
def fake_lookup(id):
|
||||
return FakeVirtDomain(fake_dom_xml)
|
||||
|
||||
def _fake_flush(self, fake_pty):
|
||||
with open(fake_pty, 'r+') as fp:
|
||||
return fp.read()
|
||||
|
||||
self.create_fake_libvirt_mock()
|
||||
connection.LibvirtConnection._conn.lookupByName = fake_lookup
|
||||
connection.libvirt_utils = libvirt_utils
|
||||
connection.LibvirtConnection._flush_libvirt_console = _fake_flush
|
||||
connection.libvirt_utils = fake_libvirt_utils
|
||||
|
||||
conn = connection.LibvirtConnection(False)
|
||||
output = conn.get_console_output(instance)
|
||||
|
Reference in New Issue
Block a user