combox

split and encrypted files between online file storage providers
git clone git://git.ricketyspace.net/combox.git
Log | Files | Refs

commit a6a2c35dbdcae1a1a69e348d8fc2ffe07eee4be3
parent f15ce63ba11ad101349ee51a0baa4109400d7329
Author: Siddharth Ravikumar <sravik@bgsu.edu>
Date:   Wed,  8 Apr 2015 20:49:09 -0400

rewrote combox.events.NodeDirMonitor.on_modified method.

     - Now the the node monitor waits for all shards of the file,
	   which was modified on a remote computer, to arrive on this
	   computer, before it re-constructs the file into the respective
	   location in the combox directory.

    - Tests for it is at
	  tests.events_test.TestEvents.test_NDM_onmodified method.

	modified:   combox/events.py
	modified:   tests/events_test.py

Part of this was done while listening to Avril's "Complicated" ; I
think this is the only modern Pop song which I like.

Diffstat:
combox/events.py | 11++++++++---
tests/events_test.py | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/combox/events.py b/combox/events.py @@ -373,6 +373,11 @@ class NodeDirMonitor(LoggingEventHandler): # means, file was modified on another computer (also # running combox). so, reconstruct the file and put it # in the combox directory. - decrypt_and_glue(file_cb_path, self.config) - # update db. - self.silo.update(file_cb_path) + with self.lock: + self.silo.node_set('file_modified', file_cb_path) + num = self.silo.node_get('file_modified', file_cb_path) + if num == self.num_nodes: + decrypt_and_glue(file_cb_path, self.config) + # update db. + self.silo.update(file_cb_path) + self.silo.node_rem('file_modified', file_cb_path) diff --git a/tests/events_test.py b/tests/events_test.py @@ -303,6 +303,64 @@ class TestEvents(object): observers[i].join() + def test_NDM_onmodified(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) + + # Test - shard modification + self.lorem_file = path.join(self.FILES_DIR, 'lorem.txt') + lorem_content = read_file(self.lorem_file) + self.lorem_file_copy = "%s.copy" % self.lorem_file + + copyfile(self.lorem_file, self.lorem_file_copy) + split_and_encrypt(self.lorem_file_copy, self.config, + lorem_content) + + self.silo.update(self.lorem_file_copy) + shardedp(self.lorem_file_copy) + + self.silo.reload() + lorem_file_copy_hash = self.silo.db.get(self.lorem_file_copy) + + self.ipsum_file = path.join(self.FILES_DIR, 'ipsum.txt') + ipsum_content = read_file(self.ipsum_file) + lorem_copy_content = "%s\n%s" % (lorem_content, ipsum_content) + + split_and_encrypt(self.lorem_file_copy, self.config, + lorem_copy_content) + time.sleep(1) + assert lorem_copy_content == read_file(self.lorem_file_copy) + + ## check if the lorem_file_copy's info is updated in silo + self.silo.reload() + assert lorem_file_copy_hash != self.silo.db.get(self.lorem_file_copy) + assert_equal(None, self.silo.node_get('file_modified', + self.lorem_file_copy)) + + self.purge_list.append(self.lorem_file_copy) + + # stop the zarking observers. + for i in range(num_nodes): + observers[i].stop() + observers[i].join() + + def untest_NDM(self): """ Tests the NodeDirMonitor class.