[Kimchi-devel] [PATCH] [Kimchi 2/6] Update run_server() calls to do not pass model instance
Aline Manera
alinefm at linux.vnet.ibm.com
Tue Feb 7 18:35:12 UTC 2017
The model instance will be gotten from cherrypy when needed.
Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
root.py | 3 ++-
tests/test_authorization.py | 10 ++++------
tests/test_host.py | 15 +++------------
tests/test_livemigration.py | 6 +-----
tests/test_mock_network.py | 10 ++++------
tests/test_mock_storagepool.py | 12 ++++--------
tests/test_mock_storagevolume.py | 11 ++++-------
tests/test_mockmodel.py | 8 +++-----
tests/test_model_network.py | 18 +++++++++++-------
tests/test_model_storagepool.py | 18 ++++++++++--------
tests/test_model_storagevolume.py | 18 +++++++++++-------
tests/test_rest.py | 7 +++----
tests/test_template.py | 9 ++++-----
13 files changed, 64 insertions(+), 81 deletions(-)
diff --git a/root.py b/root.py
index 3b39c05..68c4a78 100644
--- a/root.py
+++ b/root.py
@@ -48,9 +48,10 @@ class Kimchi(WokRoot):
# When running on test mode, specify the objectstore location to
# remove the file on server shutting down. That way, the system will
# not suffer any change while running on test mode
- if wok_options.test:
+ if wok_options.test is True or wok_options.test.lower() == 'true':
self.objectstore_loc = tempfile.mktemp()
self.model = mockmodel.MockModel(self.objectstore_loc)
+
def remove_objectstore():
if os.path.exists(self.objectstore_loc):
os.unlink(self.objectstore_loc)
diff --git a/tests/test_authorization.py b/tests/test_authorization.py
index 565f446..b67d8d6 100644
--- a/tests/test_authorization.py
+++ b/tests/test_authorization.py
@@ -1,7 +1,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2014-2016
+# Copyright IBM Corp, 2014-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -17,6 +17,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import json
import os
import unittest
@@ -25,8 +26,6 @@ from functools import partial
from tests.utils import get_fake_user, patch_auth
from tests.utils import request, run_server, wait_task
-from wok.plugins.kimchi import mockmodel
-
from iso_gen import construct_fake_iso
@@ -39,8 +38,8 @@ def setUpModule():
global test_server, model
patch_auth(sudo=False)
- model = mockmodel.MockModel('/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
# Create fake ISO to do the tests
construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
@@ -48,7 +47,6 @@ def setUpModule():
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
os.unlink(fake_iso)
diff --git a/tests/test_host.py b/tests/test_host.py
index 1ee3368..6db6839 100644
--- a/tests/test_host.py
+++ b/tests/test_host.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -19,33 +19,24 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import json
-import os
-import tempfile
import unittest
from functools import partial
from tests.utils import patch_auth, request, run_server
-from wok.plugins.kimchi.mockmodel import MockModel
-
test_server = None
-model = None
-tmpfile = None
def setUpModule():
- global test_server, model, tmpfile
+ global test_server
patch_auth()
- tmpfile = tempfile.mktemp()
- model = MockModel(tmpfile)
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
def tearDownModule():
test_server.stop()
- os.unlink(tmpfile)
class HostTests(unittest.TestCase):
diff --git a/tests/test_livemigration.py b/tests/test_livemigration.py
index 7d49dc1..90fdaa1 100644
--- a/tests/test_livemigration.py
+++ b/tests/test_livemigration.py
@@ -407,12 +407,8 @@ class LiveMigrationTests(unittest.TestCase):
'not possible to test a live migration')
def test_vm_livemigrate_persistent_API(self):
patch_auth()
-
- inst = model.Model(libvirt_uri='qemu:///system',
- objstore_loc=self.tmp_store)
-
with RollbackContext() as rollback:
- test_server = run_server(test_mode=True, model=inst)
+ test_server = run_server()
rollback.prependDefer(test_server.stop)
self.request = partial(request)
diff --git a/tests/test_mock_network.py b/tests/test_mock_network.py
index 48e5557..c1e875d 100644
--- a/tests/test_mock_network.py
+++ b/tests/test_mock_network.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,14 +18,13 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import json
-import os
import unittest
from functools import partial
from tests.utils import patch_auth, request, run_server
-from wok.plugins.kimchi.mockmodel import MockModel
from wok.plugins.kimchi.model.featuretests import FeatureTests
from test_model_network import _do_network_test
@@ -39,13 +38,12 @@ def setUpModule():
global test_server, model
patch_auth()
- model = MockModel('/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
class MockNetworkTests(unittest.TestCase):
diff --git a/tests/test_mock_storagepool.py b/tests/test_mock_storagepool.py
index 5c152e4..f584382 100644
--- a/tests/test_mock_storagepool.py
+++ b/tests/test_mock_storagepool.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,16 +18,13 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import json
-import os
import unittest
from functools import partial
from tests.utils import patch_auth, request, run_server
-from wok.plugins.kimchi.mockmodel import MockModel
-
-
model = None
test_server = None
@@ -36,13 +33,12 @@ def setUpModule():
global test_server, model
patch_auth()
- model = MockModel('/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
class MockStoragepoolTests(unittest.TestCase):
diff --git a/tests/test_mock_storagevolume.py b/tests/test_mock_storagevolume.py
index 3380bd5..4b3306b 100644
--- a/tests/test_mock_storagevolume.py
+++ b/tests/test_mock_storagevolume.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,15 +18,13 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import json
-import os
import unittest
from functools import partial
from tests.utils import patch_auth, request, run_server
-from wok.plugins.kimchi.mockmodel import MockModel
-
from test_model_storagevolume import _do_volume_test
@@ -38,13 +36,12 @@ def setUpModule():
global test_server, model
patch_auth()
- model = MockModel('/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
class MockStorageVolumeTests(unittest.TestCase):
diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
index 826af12..19994ab 100644
--- a/tests/test_mockmodel.py
+++ b/tests/test_mockmodel.py
@@ -1,7 +1,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2013-2016
+# Copyright IBM Corp, 2013-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -27,7 +27,6 @@ from tests.utils import patch_auth, request, run_server
from tests.utils import wait_task
from wok.exception import InvalidOperation
-from wok.plugins.kimchi import mockmodel
from wok.plugins.kimchi.osinfo import get_template_default
import iso_gen
@@ -40,16 +39,15 @@ fake_iso = None
def setUpModule():
global model, test_server, fake_iso
cherrypy.request.headers = {'Accept': 'application/json'}
- model = mockmodel.MockModel('/tmp/obj-store-test')
patch_auth()
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
fake_iso = '/tmp/fake.iso'
iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
def tearDown():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
os.unlink(fake_iso)
diff --git a/tests/test_model_network.py b/tests/test_model_network.py
index 79fda88..e83c515 100644
--- a/tests/test_model_network.py
+++ b/tests/test_model_network.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,8 +18,11 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import json
+import mock
import os
+import tempfile
import unittest
from functools import partial
@@ -28,25 +31,26 @@ from tests.utils import run_server
from wok.rollbackcontext import RollbackContext
-from wok.plugins.kimchi.model.model import Model
from wok.plugins.kimchi.model.featuretests import FeatureTests
-
model = None
+objectstore_loc = tempfile.mktemp()
test_server = None
-def setUpModule():
+ at mock.patch('wok.plugins.kimchi.config.get_object_store')
+def setUpModule(func):
+ func.return_value = objectstore_loc
global test_server, model
patch_auth()
- model = Model(None, '/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=False)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
+ os.unlink(objectstore_loc)
def _do_network_test(self, model, params):
diff --git a/tests/test_model_storagepool.py b/tests/test_model_storagepool.py
index 2210a37..a1a5d95 100644
--- a/tests/test_model_storagepool.py
+++ b/tests/test_model_storagepool.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import json
+import mock
import os
import shutil
import tempfile
@@ -27,27 +29,27 @@ from functools import partial
from wok.rollbackcontext import RollbackContext
-from wok.plugins.kimchi.model.model import Model
-
from tests.utils import patch_auth, request
from tests.utils import run_server
-
model = None
+objectstore_loc = tempfile.mktemp()
test_server = None
-def setUpModule():
+ at mock.patch('wok.plugins.kimchi.config.get_object_store')
+def setUpModule(func):
+ func.return_value = objectstore_loc
global test_server, model
patch_auth()
- model = Model(None, '/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=False)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
+ os.unlink(objectstore_loc)
class StoragepoolTests(unittest.TestCase):
diff --git a/tests/test_model_storagevolume.py b/tests/test_model_storagevolume.py
index cacfbb5..a1f1db9 100644
--- a/tests/test_model_storagevolume.py
+++ b/tests/test_model_storagevolume.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,9 +18,12 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import json
+import mock
import os
import requests
+import tempfile
import unittest
from functools import partial
@@ -32,24 +35,25 @@ from wok.config import paths
from wok.rollbackcontext import RollbackContext
from wok.plugins.kimchi.config import READONLY_POOL_TYPE
-from wok.plugins.kimchi.model.model import Model
-
model = None
+objectstore_loc = tempfile.mktemp()
test_server = None
-def setUpModule():
+ at mock.patch('wok.plugins.kimchi.config.get_object_store')
+def setUpModule(func):
+ func.return_value = objectstore_loc
global test_server, model
patch_auth()
- model = Model(None, '/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=False)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
+ os.unlink(objectstore_loc)
def _do_volume_test(self, model, pool_name):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index a06cfe5..09fd8a5 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -18,6 +18,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import json
import os
import re
@@ -32,7 +33,6 @@ from tests.utils import patch_auth, request, run_server, wait_task
from wok.asynctask import AsyncTask
from wok.rollbackcontext import RollbackContext
-from wok.plugins.kimchi import mockmodel
from wok.plugins.kimchi.osinfo import get_template_default
import iso_gen
@@ -50,8 +50,8 @@ def setUpModule():
global test_server, model
patch_auth()
- model = mockmodel.MockModel('/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
# Create fake ISO to do the tests
iso_gen.construct_fake_iso(fake_iso, True, '12.04', 'ubuntu')
@@ -61,7 +61,6 @@ def setUpModule():
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
os.unlink(fake_iso)
os.unlink("/var/lib/libvirt/images/fedora.iso")
diff --git a/tests/test_template.py b/tests/test_template.py
index 8127a82..bf63acf 100644
--- a/tests/test_template.py
+++ b/tests/test_template.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,6 +18,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import iso_gen
import json
import os
@@ -28,7 +29,6 @@ from functools import partial
from tests.utils import patch_auth, request, run_server
from wok.plugins.kimchi.config import READONLY_POOL_TYPE
-from wok.plugins.kimchi.mockmodel import MockModel
from wok.plugins.kimchi.model.featuretests import FeatureTests
from wok.plugins.kimchi.model.templates import MAX_MEM_LIM
@@ -43,14 +43,13 @@ def setUpModule():
global test_server, model
patch_auth()
- model = MockModel('/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/kimchi'].root.model
iso_gen.construct_fake_iso(MOCK_ISO, True, '14.04', 'ubuntu')
def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')
class TemplateTests(unittest.TestCase):
--
2.9.3
More information about the Kimchi-devel
mailing list