diff options
author | Susan LoVerso <sue@mongodb.com> | 2016-02-08 16:39:20 -0500 |
---|---|---|
committer | Susan LoVerso <sue@mongodb.com> | 2016-02-08 16:39:20 -0500 |
commit | 4f43fb358627a5eb69b9aee48af9681e1f0a27f8 (patch) | |
tree | 6f5568c10d047c114c3f5dfc4bd8a7eb1861d8ce /test/suite/test_readonly01.py | |
parent | 5c9b3f6de26f254063a378775ba9949f442d1607 (diff) | |
download | mongo-4f43fb358627a5eb69b9aee48af9681e1f0a27f8.tar.gz |
WT-2349 Fixes for readonly and new python test.
Diffstat (limited to 'test/suite/test_readonly01.py')
-rw-r--r-- | test/suite/test_readonly01.py | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/test/suite/test_readonly01.py b/test/suite/test_readonly01.py new file mode 100644 index 00000000000..b5314686206 --- /dev/null +++ b/test/suite/test_readonly01.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python +# +# Public Domain 2016-2016 MongoDB, Inc. +# Public Domain 2008-2016 WiredTiger, Inc. +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# test_readonly01.py +# Transactions: Test readonly mode +# + +import fnmatch, os, shutil, time +from suite_subprocess import suite_subprocess +from wtscenario import multiply_scenarios, number_scenarios, prune_scenarios +import wttest + +class test_readonly01(wttest.WiredTigerTestCase, suite_subprocess): + t1 = 'table:test_readonly01_1' + create = True + entries = 10000 + extra_entries = 5 + + # + # We want a list of directory writable or readonly. + # + basecfg_list = [ + ('basecfg', dict(basecfg='config_base=true,')), + ('no_basecfg', dict(basecfg='config_base=false,')), + ] + dir_list = [ + ('write', dict(dirchmod=False)), + ('readonly', dict(dirchmod=True)), + ] + log_list = [ + ('logging', dict(logcfg='log=(archive=false,enabled,file_max=100K),')), + ('no_logging', dict(logcfg='log=(enabled=false),')), + ] + log_list = [ + ('no_logging', dict(logcfg='log=(enabled=false),')), + ] + + types = [ + ('lsm', dict(tabletype='lsm', + create_params = 'key_format=i,value_format=i')), + ('row', dict(tabletype='row', + create_params = 'key_format=i,value_format=i')), + ('var', dict(tabletype='var', + create_params = 'key_format=r,value_format=i')), + ('fix', dict(tabletype='fix', + create_params = 'key_format=r,value_format=8t')), + ] + + scenarios = multiply_scenarios('.', + basecfg_list, dir_list, log_list, types) + + def conn_config(self, dir): + self.home = dir + params = \ + 'error_prefix="%s",' % self.shortid() + \ + '%s' % self.logcfg + \ + '%s' % self.basecfg + if self.create: + conn_params = 'create,' + params + else: + conn_params = 'readonly=true,' + params + return conn_params + + def close_reopen(self): + ''' Close the connection and reopen readonly''' + # + # close the original connection. If needed, chmod the + # database directory to readonly mode. Then reopen the + # connection with readonly. + # + self.close_conn() + if self.dirchmod: + os.chmod(self.home, 0555) + self.conn = self.setUpConnectionOpen(self.home) + self.session = self.setUpSessionOpen(self.conn) + + def test_readonly(self): + # Here's the strategy: + # - Create a table. + # - Insert data into table. + # - Close connection. + # - Possibly chmod to readonly + # - Open connection readonly + # - Confirm we can read the data. + # + self.session.create(self.t1, self.create_params) + c = self.session.open_cursor(self.t1, None, None) + for i in range(self.entries): + c[i+1] = i % 255 + # Close the connection. Reopen readonly + self.create = False + self.close_reopen() + c = self.session.open_cursor(self.t1, None, None) + i = 0 + for key, value in c: + self.assertEqual(i+1, key) + self.assertEqual(i % 255, value) + i += 1 + self.assertEqual(i, self.entries) + self.pr('Read %d entries' % i) + c.close() + self.create = True + + # If we changed the directory to readonly, change it back so that + # the cleanup functions can remove it and set up for the next test. + if self.dirchmod: + os.chmod(self.home, 0777) + +if __name__ == '__main__': + wttest.run() |