Fix caching of model name and remove debug lines

This commit is contained in:
Liam Young
2018-06-12 14:30:09 +01:00
parent 9b26376a19
commit f0d91ae31b
3 changed files with 15 additions and 5 deletions

View File

@@ -10,6 +10,11 @@ import zaza.model as model
class TestModel(ut_utils.BaseTestCase):
def tearDown(self):
super(TestModel, self).tearDown()
# Clear cached model name
model.CURRENT_MODEL = None
def setUp(self):
super(TestModel, self).setUp()
@@ -126,7 +131,6 @@ class TestModel(ut_utils.BaseTestCase):
def test_get_juju_model(self):
self.patch_object(model.os, 'environ')
self.patch_object(model, 'get_current_model')
model.CURRENT_MODEL = None
self.get_current_model.return_value = 'modelsmodel'
def _get_env(key):
@@ -138,6 +142,11 @@ class TestModel(ut_utils.BaseTestCase):
self.assertEqual(model.get_juju_model(), 'envmodel')
self.get_current_model.assert_not_called()
def test_get_juju_model_noenv(self):
self.patch_object(model.os, 'environ')
self.patch_object(model, 'get_current_model')
self.get_current_model.return_value = 'modelsmodel'
# No envirnment variable
self.environ.__getitem__.side_effect = KeyError
self.assertEqual(model.get_juju_model(), 'modelsmodel')

View File

@@ -47,7 +47,6 @@ class BaseTestCase(unittest.TestCase):
def tearDown(self):
for k, v in self._patches.items():
print("Stopping patch {} {}".format(k, v))
v.stop()
setattr(self, k, None)
self._patches = None
@@ -66,7 +65,6 @@ class BaseTestCase(unittest.TestCase):
if new is None:
started.return_value = return_value
self._patches_start[name] = started
print("Starting patch {}".format(name))
setattr(self, name, started)
def patch(self, item, return_value=None, name=None, new=None, **kwargs):

View File

@@ -15,6 +15,7 @@ from zaza import sync_wrapper
CURRENT_MODEL = None
def set_juju_model(model_name):
"""Point environment at the given model
@@ -33,6 +34,7 @@ def get_juju_model():
:returns: In focus model name
:rtype: str
"""
global CURRENT_MODEL
if CURRENT_MODEL:
return CURRENT_MODEL
# LY: I think we should remove the KeyError handling. I don't think we
@@ -41,10 +43,11 @@ def get_juju_model():
# zaza will loose the ability to do concurrent runs.
try:
# Check the environment
return os.environ["JUJU_MODEL"]
CURRENT_MODEL = os.environ["JUJU_MODEL"]
except KeyError:
# If unset connect get the current active model
return get_current_model()
CURRENT_MODEL = get_current_model()
return CURRENT_MODEL
async def deployed(filter=None):