def test_single_change(self): name = "/file/name" old_base = "/OLD" new_base = "/NEW" data = "/etc/group" key = old_base + data file1 = File.create_file(self.db, name, self.user1, key, pynimbusauthz.object_type_s3) self.db.commit() rc = pynimbusauthz.rebase.main([old_base, new_base]) self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc)) f2a = File.find_files_from_data(self.db, key) f2a = list(f2a) self.assertEqual(len(f2a), 0, "should be no values with key %s len is %d" % (old_base, len(f2a))) key = new_base + data f2a = File.find_files_from_data(self.db, key) f2a = list(f2a) self.assertNotEqual(len(f2a), 0, "length should be greater than 0 is %d" % (len(f2a))) found = False for f2 in f2a: tst_key = f2.get_data_key() if tst_key == key: found = True self.assertTrue(found, "key not found")
def test_single_change(self): name = "/file/name" old_base = "/OLD" new_base = "/NEW" data = "/etc/group" key = old_base + data file1 = File.create_file(self.db, name, self.user1, key, pynimbusauthz.object_type_s3) self.db.commit() rc = pynimbusauthz.rebase.main([old_base, new_base]) self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc)) f2a = File.find_files_from_data(self.db, key) f2a = list(f2a) self.assertEqual( len(f2a), 0, "should be no values with key %s len is %d" % (old_base, len(f2a))) key = new_base + data f2a = File.find_files_from_data(self.db, key) f2a = list(f2a) self.assertNotEqual( len(f2a), 0, "length should be greater than 0 is %d" % (len(f2a))) found = False for f2 in f2a: tst_key = f2.get_data_key() if tst_key == key: found = True self.assertTrue(found, "key not found")
def test_many_change_but_not_all(self): name = "/file/name" old_base = "/OLD" new_base = "/NEW" other_base = "/NOTHERE" count = 10 for i in range(0, count): keyname = str(uuid.uuid1()) oldkey = old_base + "/" + keyname File.create_file(self.db, name + oldkey, self.user1, oldkey, pynimbusauthz.object_type_s3) for i in range(0, count * 2): keyname = str(uuid.uuid1()) oldkey = other_base + "/" + keyname File.create_file(self.db, name + oldkey, self.user1, oldkey, pynimbusauthz.object_type_s3) self.db.commit() rc = pynimbusauthz.rebase.main([old_base, new_base]) self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc)) f2a = File.find_files_from_data(self.db, new_base + "%") f2a = list(f2a) self.assertEqual( len(f2a), count, "length of the new items should be %d is %s" % (count, len(f2a)))
def test_find_by_key(self): user1 = User(self.db) name = "/file/name" key = "/old/path/base" f = File.create_file(self.db, name, user1, key, pynimbusauthz.object_type_s3) self.db.commit() f2a = File.find_files_from_data(self.db, key) found = False for f2 in f2a: tst_key = f2.get_data_key() if tst_key == key: found = True self.assertTrue(found, "key not found")
def test_many_change(self): name = "/file/name" old_base = "/OLD" new_base = "/NEW" count = 10 for i in range(0, count): keyname = str(uuid.uuid1()) oldkey = old_base + "/" + keyname File.create_file(self.db, name+oldkey, self.user1, oldkey, pynimbusauthz.object_type_s3) self.db.commit() rc = pynimbusauthz.rebase.main([old_base, new_base]) self.assertEqual(rc, 0, "rc should be 0, is %d" % (rc)) f2a = File.find_files_from_data(self.db, new_base + "%") f2a = list(f2a) self.assertEqual(len(f2a), count, "length of the new items should be %d is %s" % (count, len(f2a)))
def main(argv=sys.argv[1:]): try: con_str = pynimbusauthz.get_db_connection_string() db_obj = DB(con_str=con_str) (opts,args) = setup_options(argv) old_path = args[0] new_path = args[1] pattern = old_path + "%" files = list(File.find_files_from_data(db_obj, pattern)) for f in files: old_key = f.get_data_key() new_key = old_key.replace(old_path, new_path, 1) f.set_data_key(new_key) db_obj.commit() print "done - %d files rebased" % len(files) except AuthzException, ae: print ae return ae.get_rc()