[Kimchi-devel] [PATCH] [Kimchi 5/8] Remove 'run as root' requirement from some tests

Lucio Correia luciojhc at linux.vnet.ibm.com
Fri Mar 10 22:06:08 UTC 2017


Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 tests/test_model.py | 45 ++++++++++++++++++++-------------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/tests/test_model.py b/tests/test_model.py
index 78c291e..8595862 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -381,11 +381,10 @@ class ModelTests(unittest.TestCase):
             info = inst.vm_lookup('kimchi-vm')
             self.assertEquals('running', info['state'])
 
-    @unittest.skipUnless(utils.running_as_root() and
-                         os.uname()[4] != "s390x", 'Must be run as root')
+    @unittest.skipUnless(os.uname()[4] != "s390x", 'Not applicable to s390x')
     def test_vm_graphics(self):
-        inst = model.Model(objstore_loc=self.tmp_store)
-        params = {'name': 'test',
+        inst = model.Model('qemu:///session', self.tmp_store)
+        params = {'name': 'test', 'domain': 'kvm',
                   'source_media': {'type': 'disk', 'path': UBUNTU_ISO}}
         inst.templates_create(params)
         with RollbackContext() as rollback:
@@ -409,10 +408,9 @@ class ModelTests(unittest.TestCase):
 
         inst.template_delete('test')
 
-    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_vm_virtviewerfile_vmnotrunning(self):
-        inst = model.Model(objstore_loc=self.tmp_store)
-        params = {'name': 'test',
+        inst = model.Model('qemu:///session', self.tmp_store)
+        params = {'name': 'test', 'domain': 'kvm',
                   'source_media': {'type': 'disk', 'path': UBUNTU_ISO}}
         inst.templates_create(params)
 
@@ -972,14 +970,14 @@ class ModelTests(unittest.TestCase):
             cur_cdrom_path = re.sub(":80/", '/', cdrom_info['path'])
             self.assertEquals(valid_remote_iso_path, cur_cdrom_path)
 
-    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_vm_storage_provisioning(self):
-        inst = model.Model(objstore_loc=self.tmp_store)
+        inst = model.Model('qemu:///session', self.tmp_store)
 
         with RollbackContext() as rollback:
             params = {'name': 'test', 'disks': [{'size': 1, 'pool': {
                       'name': '/plugins/kimchi/storagepools/default'}}],
-                      'source_media': {'type': 'disk', 'path': UBUNTU_ISO}}
+                      'source_media': {'type': 'disk', 'path': UBUNTU_ISO},
+                      'domain': 'kvm'}
 
             inst.templates_create(params)
             rollback.prependDefer(inst.template_delete, 'test')
@@ -1029,9 +1027,8 @@ class ModelTests(unittest.TestCase):
         xpath = "/domain/devices/disk[@device='disk']/driver/@type"
         return xpath_get_text(xml, xpath)[0]
 
-    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_template_get_default_vol_format_from_conf(self):
-        inst = model.Model(objstore_loc=self.tmp_store)
+        inst = model.Model('qemu:///session', self.tmp_store)
 
         with RollbackContext() as rollback:
             self._create_template_conf_with_disk_format('vmdk')
@@ -1039,7 +1036,8 @@ class ModelTests(unittest.TestCase):
 
             params = {'name': 'test', 'disks': [{'size': 1, 'pool': {
                       'name': '/plugins/kimchi/storagepools/default'}}],
-                      'source_media': {'type': 'disk', 'path': UBUNTU_ISO}}
+                      'source_media': {'type': 'disk', 'path': UBUNTU_ISO},
+                      'domain': 'kvm'}
             inst.templates_create(params)
             rollback.prependDefer(inst.template_delete, 'test')
 
@@ -1054,9 +1052,8 @@ class ModelTests(unittest.TestCase):
             )
             self.assertEqual(created_disk_format, 'vmdk')
 
-    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_template_creates_user_defined_vol_format_instead_default(self):
-        inst = model.Model(objstore_loc=self.tmp_store)
+        inst = model.Model('qemu:///session', self.tmp_store)
 
         default_vol = 'vmdk'
         user_vol = 'raw'
@@ -1064,7 +1061,7 @@ class ModelTests(unittest.TestCase):
             self._create_template_conf_with_disk_format(default_vol)
             rollback.prependDefer(self._restore_template_conf_file)
 
-            params = {'name': 'test', 'disks': [{
+            params = {'name': 'test', 'domain': 'kvm', 'disks': [{
                 'size': 1, 'format': user_vol,
                 'pool': {'name': '/plugins/kimchi/storagepools/default'}}],
                 'source_media': {'type': 'disk', 'path': UBUNTU_ISO}}
@@ -1083,9 +1080,8 @@ class ModelTests(unittest.TestCase):
             )
             self.assertEqual(created_disk_format, user_vol)
 
-    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_template_uses_qcow2_format_if_no_user_or_default_defined(self):
-        inst = model.Model(objstore_loc=self.tmp_store)
+        inst = model.Model('qemu:///session', self.tmp_store)
 
         with RollbackContext() as rollback:
             self._create_template_conf_with_disk_format(None)
@@ -1093,7 +1089,8 @@ class ModelTests(unittest.TestCase):
 
             params = {'name': 'test', 'disks': [{'size': 1, 'pool': {
                       'name': '/plugins/kimchi/storagepools/default'}}],
-                      'source_media': {'type': 'disk', 'path': UBUNTU_ISO}}
+                      'source_media': {'type': 'disk', 'path': UBUNTU_ISO},
+                      'domain': 'kvm'}
             inst.templates_create(params)
             rollback.prependDefer(inst.template_delete, 'test')
 
@@ -1659,12 +1656,11 @@ class ModelTests(unittest.TestCase):
             vms = inst.vms_get_list()
             self.assertFalse(u'kīмсhī-∨м' in vms)
 
-    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_vm_list_sorted(self):
-        inst = model.Model(objstore_loc=self.tmp_store)
+        inst = model.Model('qemu:///session', self.tmp_store)
 
         with RollbackContext() as rollback:
-            params = {'name': 'test', 'disks': [],
+            params = {'name': 'test', 'disks': [], 'domain': 'kvm',
                       'source_media': {'type': 'disk', 'path': UBUNTU_ISO}}
             inst.templates_create(params)
             rollback.prependDefer(inst.template_delete, 'test')
@@ -1765,10 +1761,9 @@ class ModelTests(unittest.TestCase):
             self.assertIn('os_arch', distro)
             self.assertIn('path', distro)
 
-    @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_deep_scan(self):
-        inst = model.Model(None,
-                           objstore_loc=self.tmp_store)
+        inst = model.Model('qemu:///session', self.tmp_store)
+
         with RollbackContext() as rollback:
             deep_path = os.path.join(TMP_DIR, 'deep-scan')
             subdir_path = os.path.join(deep_path, 'isos')
-- 
2.7.4



More information about the Kimchi-devel mailing list