From 4a10ed1ae09a13708d395215aa741ac1345adbd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Thu, 3 Jan 2013 02:59:34 +0000 Subject: [PATCH] ensure failure to inject user files results in startup error This was the case in Essex but was inadvertantly changed in: folsom-2-95-g0d166ca. * nova/virt/disk/api.py: Refactor to allow specifying mandatory injection items, that result in an exception on failure to inject. * nova/virt/libvirt/driver.py: Specify that user 'files' are mandatory items and thus result in VM startup failure unless injected successfully. * nova/tests/test_virt_disk.py: A new test for the separate warning and error cases. Fixes bug: 1095744 Change-Id: Idab5c4294c1cb52098ce44a7aae957a44fb2674f --- nova/tests/test_virt_disk.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nova/tests/test_virt_disk.py b/nova/tests/test_virt_disk.py index 902d4970..e6a57e08 100644 --- a/nova/tests/test_virt_disk.py +++ b/nova/tests/test_virt_disk.py @@ -14,8 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. +import os import sys +from nova import exception from nova import test from nova.tests import fakeguestfs from nova.virt.disk import api as diskapi @@ -29,6 +31,25 @@ class VirtDiskTest(test.TestCase): sys.modules['guestfs'] = fakeguestfs vfsguestfs.guestfs = fakeguestfs + def test_inject_data(self): + + self.assertTrue(diskapi.inject_data("/some/file", use_cow=True)) + + self.assertTrue(diskapi.inject_data("/some/file", + mandatory=('files',))) + + self.assertTrue(diskapi.inject_data("/some/file", key="mysshkey", + mandatory=('key',))) + + os_name = os.name + os.name = 'nt' # Cause password injection to fail + self.assertRaises(exception.NovaException, + diskapi.inject_data, + "/some/file", admin_password="p", + mandatory=('admin_password',)) + self.assertFalse(diskapi.inject_data("/some/file", admin_password="p")) + os.name = os_name + def test_inject_data_key(self): vfs = vfsguestfs.VFSGuestFS("/some/file", "qcow2")