summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--combox/events.py26
-rw-r--r--tests/events_test.py55
2 files changed, 75 insertions, 6 deletions
diff --git a/combox/events.py b/combox/events.py
index bc6fe8b..3cb8ebd 100644
--- a/combox/events.py
+++ b/combox/events.py
@@ -339,13 +339,27 @@ class NodeDirMonitor(LoggingEventHandler):
file_cb_path = cb_path(event.src_path, self.config)
if event.is_directory:
- # Delete corresponding directory under the combox directory.
- rm_path(file_cb_path)
+ with self.lock:
+ self.silo.node_set('file_deleted', file_cb_path)
+ num = self.silo.node_get('file_deleted', file_cb_path)
+
+ if num == self.num_nodes:
+ # Delete corresponding directory under the combox
+ # directory.
+ rm_path(file_cb_path)
+ self.silo.node_rem('file_deleted', file_cb_path)
elif not event.is_directory and path.exists(file_cb_path):
- # remove the corresponding file under the combox directory.
- rm_path(file_cb_path)
- # remove file info from silo.
- self.silo.remove(file_cb_path)
+ with self.lock:
+ self.silo.node_set('file_deleted', file_cb_path)
+ num = self.silo.node_get('file_deleted', file_cb_path)
+
+ if num == self.num_nodes:
+ # remove the corresponding file under the combox
+ # directory.
+ rm_path(file_cb_path)
+ # remove file info from silo.
+ self.silo.remove(file_cb_path)
+ self.silo.node_rem('file_deleted', file_cb_path)
def on_modified(self, event):
diff --git a/tests/events_test.py b/tests/events_test.py
index ae626b8..9d90f0e 100644
--- a/tests/events_test.py
+++ b/tests/events_test.py
@@ -361,6 +361,61 @@ class TestEvents(object):
observers[i].join()
+ def test_NDM_ondeleted(self):
+ """Testing on_modified method in NodeDirMonitor"""
+ nodes = get_nodedirs(self.config)
+ num_nodes = len(get_nodedirs(self.config))
+
+ nmonitors = []
+ observers = []
+
+ # create an observer for each node directory and make it
+ # monitor them.
+ for node in nodes:
+ nmonitor = NodeDirMonitor(self.config, self.silo_lock,
+ self.nodem_lock)
+ observer = Observer()
+ observer.schedule(nmonitor, node, recursive=True)
+ observer.start()
+
+ nmonitors.append(nmonitor)
+ observers.append(observer)
+
+ BAR_DIR = path.join(self.FILES_DIR, 'bar')
+ mk_nodedir(BAR_DIR, self.config)
+ # wait for the `bar' directory to be created inside combox
+ # directory.
+ time.sleep(1)
+
+ # Test - directory deletion inside node directory.
+ rm_nodedir(BAR_DIR, self.config)
+ time.sleep(1)
+ assert not path.exists(BAR_DIR)
+
+ the_guide = path.join(self.FILES_DIR, 'the.guide')
+ split_and_encrypt(the_guide, self.config,
+ read_file(self.TEST_FILE))
+ time.sleep(1)
+ assert path.exists(the_guide)
+
+ # Test - Shard deletion.
+ rm_shards(the_guide, self.config)
+ time.sleep(1)
+ assert not path.exists(the_guide)
+
+ ## check if the new file's info is removed from silo
+ silo = ComboxSilo(self.config, self.silo_lock)
+ assert not silo.exists(the_guide)
+
+ self.purge_list.append(BAR_DIR)
+ self.purge_list.append(the_guide)
+
+ # stop the zarking observers.
+ for i in range(num_nodes):
+ observers[i].stop()
+ observers[i].join()
+
+
def untest_NDM(self):
"""
Tests the NodeDirMonitor class.