summaryrefslogtreecommitdiffstats
path: root/testsuite/Testsrc/Testlib/TestServer/TestPlugin
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-03-25 13:31:21 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-03-25 13:31:21 -0400
commit9c603d8267c0a511968a8a553d7fa0b2d5bf9b73 (patch)
treec473a7615586dc22d585bda67e118ed2fe535754 /testsuite/Testsrc/Testlib/TestServer/TestPlugin
parent3dc289678812238c2fcc54098b1d8de9bf64f900 (diff)
downloadbcfg2-9c603d8267c0a511968a8a553d7fa0b2d5bf9b73.tar.gz
bcfg2-9c603d8267c0a511968a8a553d7fa0b2d5bf9b73.tar.bz2
bcfg2-9c603d8267c0a511968a8a553d7fa0b2d5bf9b73.zip
Handle FAM monitor failures more gracefully:
* Where possible, create the file or directory that is about to be monitored. This ensures that content can be added later without need to restart Bcfg2. (Otherwise, adding the monitor would fail, and so when you did create the file in question, bcfg2-server would never be notified of it.) * When not possible, give better error messages.
Diffstat (limited to 'testsuite/Testsrc/Testlib/TestServer/TestPlugin')
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py22
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py38
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py11
3 files changed, 52 insertions, 19 deletions
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py
index a1e624824..318f5ceaa 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testbase.py
@@ -72,14 +72,32 @@ class TestPlugin(TestDebuggable):
if core is None:
core = Mock()
core.setup = MagicMock()
- return self.test_obj(core, datastore)
+ @patchIf(not isinstance(os.makedirs, Mock), "os.makedirs", Mock())
+ def inner():
+ return self.test_obj(core, datastore)
+ return inner()
- def test__init(self):
+ @patch("os.makedirs")
+ @patch("os.path.exists")
+ def test__init(self, mock_exists, mock_makedirs):
core = Mock()
core.setup = MagicMock()
+
+ mock_exists.return_value = True
+ p = self.get_obj(core=core)
+ self.assertEqual(p.data, os.path.join(datastore, p.name))
+ self.assertEqual(p.core, core)
+ mock_exists.assert_any_call(p.data)
+ self.assertFalse(mock_makedirs.called)
+
+ mock_exists.reset_mock()
+ mock_makedirs.reset_mock()
+ mock_exists.return_value = False
p = self.get_obj(core=core)
self.assertEqual(p.data, os.path.join(datastore, p.name))
self.assertEqual(p.core, core)
+ mock_exists.assert_any_call(p.data)
+ mock_makedirs.assert_any_call(p.data)
@patch("os.makedirs")
def test_init_repo(self, mock_makedirs):
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
index fb51eb1fe..fceddcc69 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py
@@ -158,6 +158,7 @@ class TestDirectoryBacked(Bcfg2TestCase):
""" ensure that the child object has the correct interface """
self.assertTrue(hasattr(self.test_obj.__child__, "HandleEvent"))
+ @patch("os.makedirs", Mock())
def get_obj(self, fam=None):
if fam is None:
fam = Mock()
@@ -171,12 +172,26 @@ class TestDirectoryBacked(Bcfg2TestCase):
fam)
return inner()
- def test__init(self):
+ @patch("os.makedirs")
+ @patch("os.path.exists")
+ def test__init(self, mock_exists, mock_makedirs):
@patch("%s.%s.add_directory_monitor" % (self.test_obj.__module__,
self.test_obj.__name__))
def inner(mock_add_monitor):
+ mock_exists.return_value = True
+ db = self.test_obj(datastore, Mock())
+ mock_add_monitor.assert_called_with('')
+ mock_exists.assert_called_with(db.data)
+ self.assertFalse(mock_makedirs.called)
+
+ mock_add_monitor.reset_mock()
+ mock_exists.reset_mock()
+ mock_makedirs.reset_mock()
+ mock_exists.return_value = False
db = self.test_obj(datastore, Mock())
mock_add_monitor.assert_called_with('')
+ mock_exists.assert_called_with(db.data)
+ mock_makedirs.assert_called_with(db.data)
inner()
@@ -220,6 +235,7 @@ class TestDirectoryBacked(Bcfg2TestCase):
mock_isdir.return_value = True
for path in self.testpaths.values():
reset()
+ print "testing %s" % path
db.add_directory_monitor(path)
db.fam.AddMonitor.assert_called_with(os.path.join(db.data, path),
db)
@@ -395,10 +411,14 @@ class TestXMLFileBacked(TestFileBacked):
should_monitor = None
path = os.path.join(datastore, "test", "test1.xml")
+ @patch("os.makedirs", Mock())
def get_obj(self, path=None, fam=None, should_monitor=False):
if path is None:
path = self.path
- return self.test_obj(path, fam=fam, should_monitor=should_monitor)
+ @patchIf(not isinstance(os.makedirs, Mock), "os.makedirs", Mock())
+ def inner():
+ return self.test_obj(path, fam=fam, should_monitor=should_monitor)
+ return inner()
def test__init(self):
fam = Mock()
@@ -1186,13 +1206,18 @@ class TestXMLDirectoryBacked(TestDirectoryBacked):
class TestPrioDir(TestPlugin, TestGenerator, TestXMLDirectoryBacked):
test_obj = PrioDir
- @patch("Bcfg2.Server.Plugin.helpers.%s.add_directory_monitor" %
- test_obj.__name__,
- Mock())
def get_obj(self, core=None):
if core is None:
core = Mock()
- return self.test_obj(core, datastore)
+
+ @patch("%s.%s.add_directory_monitor" %
+ (self.test_obj.__module__, self.test_obj.__name__),
+ Mock())
+ @patchIf(not isinstance(os.makedirs, Mock), "os.makedirs", Mock())
+ def inner():
+ return self.test_obj(core, datastore)
+
+ return inner()
def test_HandleEvent(self):
TestXMLDirectoryBacked.test_HandleEvent(self)
@@ -1816,6 +1841,7 @@ class TestGroupSpool(TestPlugin, TestGenerator):
return inner()
def test__init(self):
+ @patchIf(not isinstance(os.makedirs, Mock), "os.makedirs", Mock())
@patch("%s.%s.AddDirectoryMonitor" % (self.test_obj.__module__,
self.test_obj.__name__))
def inner(mock_Add):
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py
index 35f4e0700..1f5c4790b 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testinterfaces.py
@@ -97,11 +97,6 @@ class TestProbing(Bcfg2TestCase):
class TestStatistics(TestPlugin):
test_obj = Statistics
- def get_obj(self, core=None):
- if core is None:
- core = Mock()
- return self.test_obj(core, datastore)
-
def test_process_statistics(self):
s = self.get_obj()
self.assertRaises(NotImplementedError,
@@ -354,12 +349,6 @@ class TestGoalValidator(Bcfg2TestCase):
class TestVersion(TestPlugin):
test_obj = Version
- def get_obj(self, core=None):
- if core is None:
- core = Mock()
- core.setup = MagicMock()
- return self.test_obj(core, datastore)
-
def test_get_revision(self):
d = self.get_obj()
self.assertRaises(NotImplementedError, d.get_revision)