[PATCH] [Gingerbase 0/2] Fixes test cases based on latest Wok changes

2 views
Skip to first unread message

Aline Manera

unread,
Feb 7, 2017, 1:36:15 PM2/7/17
to Ginger Devel
Aline Manera (2):
Specify objectstore location when running on test mode
Update run_server() calls to do not pass model instance

gingerbase.py | 16 +++++++++++-----
mockmodel.py | 1 -
tests/test_authorization.py | 15 +++------------
tests/test_host.py | 15 +++++----------
tests/test_rest.py | 14 +++-----------
5 files changed, 22 insertions(+), 39 deletions(-)

--
2.9.3

Aline Manera

unread,
Feb 7, 2017, 1:36:17 PM2/7/17
to Ginger Devel
That way, the objectstore file can be deleted on server shutting down
and the system keeps clean of any changes while running on test mode.

Signed-off-by: Aline Manera <ali...@linux.vnet.ibm.com>
---
gingerbase.py | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/gingerbase.py b/gingerbase.py
index eef1b61..a6ca61d 100644
--- a/gingerbase.py
+++ b/gingerbase.py
@@ -1,7 +1,7 @@
#
# Project Ginger Base
#
-# 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
@@ -17,8 +17,10 @@
# 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 tempfile

from wok.plugins.gingerbase import config, mockmodel
from wok.plugins.gingerbase.i18n import messages
@@ -37,10 +39,14 @@ class Gingerbase(WokRoot):
if not os.path.isdir(directory):
os.makedirs(directory)

- if hasattr(wok_options, "model"):
- self.model = wok_options.model
- elif wok_options.test:
- self.model = mockmodel.MockModel()
+ 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)
+ cherrypy.engine.subscribe('exit', remove_objectstore)
else:
self.model = gingerBaseModel.Model()

--
2.9.3

Aline Manera

unread,
Feb 7, 2017, 1:36:19 PM2/7/17
to Ginger Devel
The model instance will be gotten from cherrypy when needed.

Signed-off-by: Aline Manera <ali...@linux.vnet.ibm.com>
---
mockmodel.py | 1 -
tests/test_authorization.py | 15 +++------------
tests/test_host.py | 15 +++++----------
tests/test_rest.py | 14 +++-----------
4 files changed, 11 insertions(+), 34 deletions(-)

diff --git a/mockmodel.py b/mockmodel.py
index 92d1531..4ed5261 100644
--- a/mockmodel.py
+++ b/mockmodel.py
@@ -35,7 +35,6 @@ from wok.plugins.gingerbase.model.debugreports import DebugReportsModel
from wok.plugins.gingerbase.model.model import Model

fake_user = {'root': 'letmein!'}
-mockmodel_defaults = {'domain': 'test', 'arch': 'i686'}


class MockModel(Model):
diff --git a/tests/test_authorization.py b/tests/test_authorization.py
index de4f259..eb2ca58 100644
--- a/tests/test_authorization.py
+++ b/tests/test_authorization.py
@@ -1,7 +1,7 @@
#
# Project Ginger Base
#
-# Copyright IBM Corp, 2014-2016
+# Copyright IBM Corp, 2014-2017
#
# Code derived from Project Kimchi
#
@@ -19,37 +19,28 @@
# 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 os
import unittest
from functools import partial

from tests.utils import patch_auth, request, run_server

-from wok.plugins.gingerbase import mockmodel
-
-
test_server = None
-model = None
-fake_iso = '/tmp/fake.iso'


def setUpModule():
- global test_server, model
+ global test_server

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)


def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')


class AuthorizationTests(unittest.TestCase):
def setUp(self):
self.request = partial(request)
- model.reset()

def test_nonroot_access(self):
# Non-root users can access static host information
diff --git a/tests/test_host.py b/tests/test_host.py
index 8cabb58..267b917 100644
--- a/tests/test_host.py
+++ b/tests/test_host.py
@@ -2,7 +2,7 @@
#
# Project Ginger Base
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# Code derived from Project Kimchi
#
@@ -19,12 +19,12 @@
# You should have received a copy of the GNU Lesser General Public
# 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 platform
import psutil
-import tempfile
import time
import unittest

@@ -34,27 +34,22 @@ from mock import patch
from tests.utils import patch_auth, request
from tests.utils import run_server, wait_task

-from wok.plugins.gingerbase.mockmodel import MockModel
from wok.plugins.gingerbase.model.host import HostModel

-
test_server = None
model = None
-tmpfile = None


def setUpModule():
global test_server, model, tmpfile

patch_auth()
- tmpfile = tempfile.mktemp()
- model = MockModel(tmpfile)
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/gingerbase'].root.model


def tearDownModule():
test_server.stop()
- os.unlink(tmpfile)


class HostTests(unittest.TestCase):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 861a3e6..908c636 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -2,7 +2,7 @@
#
# Project Ginger Base
#
-# Copyright IBM Corp, 2013-2016
+# Copyright IBM Corp, 2013-2017
#
# Code derived from Project Kimchi
#
@@ -21,7 +21,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import json
-import os
import time
import unittest
from functools import partial
@@ -31,24 +30,18 @@ from tests.utils import run_server, wait_task

from wok.rollbackcontext import RollbackContext

-from wok.plugins.gingerbase import mockmodel
-
-
test_server = None
-model = None


def setUpModule():
- global test_server, model
+ global test_server

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)


def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')


class RestTests(unittest.TestCase):
@@ -68,7 +61,6 @@ class RestTests(unittest.TestCase):

def setUp(self):
self.request = partial(request)
- model.reset()

def _task_lookup(self, taskid):
return json.loads(
--
2.9.3

Aline Manera

unread,
Feb 7, 2017, 1:37:26 PM2/7/17
to Ginger Devel
The model instance will be gotten from cherrypy when needed.

Also Ginger has no MockModel, so test_mode should be always set to False
to run running the real model.

Signed-off-by: Aline Manera <ali...@linux.vnet.ibm.com>
---
tests/test_authorization.py | 12 +++---------
tests/test_tasks.py | 12 +++---------
2 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/tests/test_authorization.py b/tests/test_authorization.py
index 4abb208..6c5372b 100644
--- a/tests/test_authorization.py
+++ b/tests/test_authorization.py
@@ -1,7 +1,7 @@
#
# Project Ginger
#
-# Copyright IBM Corp, 2016
+# Copyright IBM Corp, 2016-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -22,18 +22,12 @@ from functools import partial

from tests.utils import request, run_server

-from wok.plugins.ginger.model import GingerModel
-
-
test_server = None
-model = None


def setUpModule():
- global test_server, model
-
- model = GingerModel()
- test_server = run_server(test_mode=True, model=model)
+ global test_server
+ test_server = run_server(test_mode=False)


def tearDownModule():
diff --git a/tests/test_tasks.py b/tests/test_tasks.py
index 39931fd..43e88c7 100644
--- a/tests/test_tasks.py
+++ b/tests/test_tasks.py
@@ -2,7 +2,7 @@
#
# Project Ginger
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# Code derived from Project Kimchi
#
@@ -27,23 +27,17 @@ import urllib2
from functools import partial

from wok.asynctask import AsyncTask
-from wok.plugins.ginger.model import GingerModel

from tests.utils import patch_auth, request
from tests.utils import run_server, wait_task

-
test_server = None
-model = None


def setUpModule():
- global test_server, model
-
+ global test_server
patch_auth()
- model = GingerModel()
-
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=False)


def tearDownModule():
--
2.9.3

Daniel Henrique Barboza

unread,
Feb 7, 2017, 2:38:28 PM2/7/17
to ginger-...@googlegroups.com
Applied. Thanks!

Lucio Correia

unread,
Feb 8, 2017, 7:54:00 AM2/8/17
to ginger-...@googlegroups.com
Reviewed-By: Lucio Correia <luci...@linux.vnet.ibm.com>
Lucio Correia

Lucio Correia

unread,
Feb 8, 2017, 1:01:24 PM2/8/17
to ginger-...@googlegroups.com
On 07/02/2017 16:36, Aline Manera wrote:
Further testitng it, when running from source, plugin loading is failing
here:

Failed to import plugin plugins.gingerbase.Gingerbase, error: 'NoneType'
object has no attribute 'lower'



> + 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)
> + cherrypy.engine.subscribe('exit', remove_objectstore)
> else:
> self.model = gingerBaseModel.Model()
>


--
Lucio Correia

Aline Manera

unread,
Feb 8, 2017, 8:46:04 PM2/8/17
to luci...@linux.vnet.ibm.com, ginger-...@googlegroups.com
Hi Lucio,

Thanks for reporting it.
I will fix and send a V2.

Regards,
Aline Manera

Aline Manera

unread,
Feb 8, 2017, 9:00:57 PM2/8/17
to Ginger Devel
That way, the objectstore file can be deleted on server shutting down
and the system keeps clean of any changes while running on test mode.

Signed-off-by: Aline Manera <ali...@linux.vnet.ibm.com>
---
gingerbase.py | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/gingerbase.py b/gingerbase.py
index eef1b61..d471b51 100644
--- a/gingerbase.py
+++ b/gingerbase.py
@@ -1,7 +1,7 @@
#
# Project Ginger Base
#
-# 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
@@ -17,8 +17,10 @@
# 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 tempfile

from wok.plugins.gingerbase import config, mockmodel
from wok.plugins.gingerbase.i18n import messages
@@ -37,10 +39,15 @@ class Gingerbase(WokRoot):
if not os.path.isdir(directory):
os.makedirs(directory)

- if hasattr(wok_options, "model"):
- self.model = wok_options.model
- elif wok_options.test:
- self.model = mockmodel.MockModel()
+ if wok_options.test and (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)
+ cherrypy.engine.subscribe('exit', remove_objectstore)
else:
self.model = gingerBaseModel.Model()

--
2.9.3

Aline Manera

unread,
Feb 8, 2017, 9:00:58 PM2/8/17
to Ginger Devel
Only patch 1/2 has changed from V1.
Now it is checking if wok_options.test is not None before using its value.

Aline Manera (2):
Specify objectstore location when running on test mode
Update run_server() calls to do not pass model instance

gingerbase.py | 17 ++++++++++++-----
mockmodel.py | 3 +--
tests/test_authorization.py | 15 +++------------
tests/test_host.py | 15 +++++----------
tests/test_rest.py | 14 +++-----------
5 files changed, 24 insertions(+), 40 deletions(-)

--
2.9.3

Aline Manera

unread,
Feb 8, 2017, 9:00:59 PM2/8/17
to Ginger Devel
The model instance will be gotten from cherrypy when needed.

Signed-off-by: Aline Manera <ali...@linux.vnet.ibm.com>
---
mockmodel.py | 3 +--
tests/test_authorization.py | 15 +++------------
tests/test_host.py | 15 +++++----------
tests/test_rest.py | 14 +++-----------
4 files changed, 12 insertions(+), 35 deletions(-)

diff --git a/mockmodel.py b/mockmodel.py
index 92d1531..d00a93a 100644
--- a/mockmodel.py
+++ b/mockmodel.py
@@ -1,7 +1,7 @@
#
# Project Ginger Base
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# Code derived from Project Kimchi
#
@@ -35,7 +35,6 @@ from wok.plugins.gingerbase.model.debugreports import DebugReportsModel
from wok.plugins.gingerbase.model.model import Model

fake_user = {'root': 'letmein!'}
-mockmodel_defaults = {'domain': 'test', 'arch': 'i686'}


class MockModel(Model):
diff --git a/tests/test_authorization.py b/tests/test_authorization.py
index de4f259..eb2ca58 100644
--- a/tests/test_authorization.py
+++ b/tests/test_authorization.py
@@ -1,7 +1,7 @@
#
# Project Ginger Base
#
-# Copyright IBM Corp, 2014-2016
+# Copyright IBM Corp, 2014-2017
#
# Code derived from Project Kimchi
#
@@ -19,37 +19,28 @@
# 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 os
import unittest
from functools import partial

from tests.utils import patch_auth, request, run_server

-from wok.plugins.gingerbase import mockmodel
-
-
test_server = None
-model = None
-fake_iso = '/tmp/fake.iso'


def setUpModule():
- global test_server, model
+ global test_server

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)


def tearDownModule():
test_server.stop()
- os.unlink('/tmp/obj-store-test')


class AuthorizationTests(unittest.TestCase):
def setUp(self):
self.request = partial(request)
- model.reset()

def test_nonroot_access(self):
# Non-root users can access static host information
diff --git a/tests/test_host.py b/tests/test_host.py
index 8cabb58..267b917 100644
--- a/tests/test_host.py
+++ b/tests/test_host.py
@@ -2,7 +2,7 @@
#
# Project Ginger Base
#
-# Copyright IBM Corp, 2015-2016
+# Copyright IBM Corp, 2015-2017
#
# Code derived from Project Kimchi
#
@@ -19,12 +19,12 @@
# You should have received a copy of the GNU Lesser General Public
# 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 platform
import psutil
-import tempfile
import time
import unittest

@@ -34,27 +34,22 @@ from mock import patch
from tests.utils import patch_auth, request
from tests.utils import run_server, wait_task

-from wok.plugins.gingerbase.mockmodel import MockModel
from wok.plugins.gingerbase.model.host import HostModel

-
test_server = None
model = None
-tmpfile = None


def setUpModule():
global test_server, model, tmpfile

patch_auth()
- tmpfile = tempfile.mktemp()
- model = MockModel(tmpfile)
- test_server = run_server(test_mode=True, model=model)
+ test_server = run_server(test_mode=True)
+ model = cherrypy.tree.apps['/plugins/gingerbase'].root.model


def tearDownModule():
test_server.stop()
- os.unlink(tmpfile)


class HostTests(unittest.TestCase):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 861a3e6..908c636 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -2,7 +2,7 @@
#
# Project Ginger Base
#
-# Copyright IBM Corp, 2013-2016
+# Copyright IBM Corp, 2013-2017
#
# Code derived from Project Kimchi
#
@@ -21,7 +21,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import json
-import os
import time
import unittest
from functools import partial
@@ -31,24 +30,18 @@ from tests.utils import run_server, wait_task

from wok.rollbackcontext import RollbackContext

-from wok.plugins.gingerbase import mockmodel
-
-
test_server = None
-model = None


def setUpModule():
- global test_server, model
+ global test_server

patch_auth()
- model = mockmodel.MockModel('/tmp/obj-store-test')
- test_server = run_server(test_mode=True, model=model)

Lucio Correia

unread,
Feb 9, 2017, 7:31:37 AM2/9/17
to ginger-...@googlegroups.com
Reviewed-By: Lucio Correia <luci...@linux.vnet.ibm.com>
Lucio Correia

Daniel Henrique Barboza

unread,
Feb 9, 2017, 7:54:00 AM2/9/17
to ginger-...@googlegroups.com
Applied. Thanks!
Reply all
Reply to author
Forward
0 new messages