Skip to content
Snippets Groups Projects
Commit cf15a46a authored by bigbes's avatar bigbes
Browse files

Add greplog. Fixes gh-516

1) server.get_log(); server.seek_once(msg) -- since we get log object
2) server.logfile_pos.seek_once(msg) -- since the start of server
parent c27af84f
No related branches found
No related tags found
No related merge requests found
...@@ -4,17 +4,22 @@ print("Hello, world") ...@@ -4,17 +4,22 @@ print("Hello, world")
io = require('io') io = require('io')
--- ---
... ...
local f = require('fiber').create(function() print('Ehllo, world') io.flush() end) local f = require('fiber').create(
function()
print('Ehllo, world')
io.flush()
end
)
--- ---
... ...
require('fiber').sleep(0.1) require('fiber').sleep(0.1)
--- ---
... ...
Check log line Check log line (Hello):
--- ---
- "line contains 'Hello'" - "logfile contains "Hello""
... ...
Check log line Check log line (Ehllo):
--- ---
- "line contains 'Ehllo'" - "logfile contains "Ehllo""
... ...
...@@ -4,32 +4,31 @@ import sys ...@@ -4,32 +4,31 @@ import sys
import os import os
import re import re
log = server.get_log()
admin('print("Hello, world")') admin('print("Hello, world")')
admin("io = require('io')") admin("io = require('io')")
log = server.logfile admin("""local f = require('fiber').create(
f = open(log, "r") function()
f.seek(0, 2) print('Ehllo, world')
io.flush()
admin("local f = require('fiber').create(function() print('Ehllo, world') io.flush() end)") end
)""")
admin("require('fiber').sleep(0.1)") admin("require('fiber').sleep(0.1)")
line = f.readline()
print("Check log line")
print("---")
found = re.search(r'(Hello)', line)
if found and re.search(r'(Hello)', line).start(1) >= 0:
print("""- "line contains 'Hello'" """)
print("...")
else:
print('String "%s" does not contain "Hello"' % line)
line = f.readline() print("Check log line (Hello):")
print("Check log line") print('---')
print("---") if log.seek_once('Hello') >= 0:
if re.search('(Ehllo)', line): print('- "logfile contains "Hello""')
print("""- "line contains 'Ehllo'" """)
else: else:
print("""- "line doesn't contain 'Ehllo'" """) print('- "logfile does not contain "Hello""')
print("...") print('...')
print("Check log line (Ehllo):")
print('---')
if log.seek_once('Ehllo') >= 0:
print('- "logfile contains "Ehllo""')
else:
print('- "logfile does not contain "Ehllo""')
print('...')
...@@ -89,7 +89,7 @@ lsn += 1 ...@@ -89,7 +89,7 @@ lsn += 1
# #
# wal_inprogress = os.path.join(server.vardir, "00000000000000000006.xlog.inprogress") # wal_inprogress = os.path.join(server.vardir, "00000000000000000006.xlog.inprogress")
# wal = os.path.join(server.vardir, "00000000000000000006.xlog") # wal = os.path.join(server.vardir, "00000000000000000006.xlog")
# #
# os.symlink(abspath("box/empty.xlog"), wal_inprogress) # os.symlink(abspath("box/empty.xlog"), wal_inprogress)
# server.start() # server.start()
# #
...@@ -101,16 +101,16 @@ lsn += 1 ...@@ -101,16 +101,16 @@ lsn += 1
# # Empty (header only, no records) inprogress xlog must be deleted # # Empty (header only, no records) inprogress xlog must be deleted
# # during recovery. # # during recovery.
# """ # """
# #
# # If the previous test has failed, there is a dangling link # # If the previous test has failed, there is a dangling link
# # and symlink fails. # # and symlink fails.
# try: # try:
# os.symlink(abspath("box/just_header.xlog"), wal_inprogress) # os.symlink(abspath("box/just_header.xlog"), wal_inprogress)
# except OSError as e: # except OSError as e:
# print e # print e
# #
# server.start() # server.start()
# #
# if not os.access(wal_inprogress, os.F_OK) and not os.access(wal, os.F_OK): # if not os.access(wal_inprogress, os.F_OK) and not os.access(wal, os.F_OK):
# print "00000000000000000006.xlog.inprogress has been successfully deleted" # print "00000000000000000006.xlog.inprogress has been successfully deleted"
# server.stop() # server.stop()
...@@ -118,16 +118,16 @@ lsn += 1 ...@@ -118,16 +118,16 @@ lsn += 1
# print """ # print """
# # Inprogress xlog with bad record must be deleted during recovery. # # Inprogress xlog with bad record must be deleted during recovery.
# """ # """
# #
# # If the previous test has failed, there is a dangling link # # If the previous test has failed, there is a dangling link
# # and symlink fails. # # and symlink fails.
# try: # try:
# os.symlink(abspath("box/bad_record.xlog"), wal_inprogress) # os.symlink(abspath("box/bad_record.xlog"), wal_inprogress)
# except OSError as e: # except OSError as e:
# print e # print e
# #
# server.start() # server.start()
# #
# if not os.access(wal_inprogress, os.F_OK) and not os.access(wal, os.F_OK): # if not os.access(wal_inprogress, os.F_OK) and not os.access(wal, os.F_OK):
# print "00000000000000000006.xlog.inprogress has been successfully deleted" # print "00000000000000000006.xlog.inprogress has been successfully deleted"
...@@ -177,20 +177,13 @@ if os.access(wal, os.F_OK): ...@@ -177,20 +177,13 @@ if os.access(wal, os.F_OK):
os.unlink(wal) os.unlink(wal)
os.rename(wal_old, wal) os.rename(wal_old, wal)
f = open(server.logfile, "r")
f.seek(0, 2)
server.start() server.start()
line = 'Duplicate key'
check="Duplicate key" print "check log line for '%s'" % line
print "check log line for '%s'" % check
print print
line = f.readline() if server.logfile_pos.seek_once(line) >= 0:
while line: print "'%s' exists in server log" % line
if re.search(r'(%s)' % check, line):
print "'%s' exists in server log" % check
break
line = f.readline()
print print
server.admin("box.space['test']:get{1}") server.admin("box.space['test']:get{1}")
...@@ -222,16 +215,13 @@ server.stop() ...@@ -222,16 +215,13 @@ server.stop()
# Remove xlog with {3, 'third tuple'} # Remove xlog with {3, 'third tuple'}
os.unlink(wal) os.unlink(wal)
server.start() server.start()
check="ignoring missing WAL" line="ignoring missing WAL"
print "check log line for '%s'" % check print "check log line for '%s'" % line
print print
line = f.readline() if server.logfile_pos.seek_once(line) >= 0:
while line: print "'%s' exists in server log" % line
if re.search(r'(%s)' % check, line):
print "'%s' exists in server log" % check
break
line = f.readline()
print print
# missing tuple from removed xlog # missing tuple from removed xlog
......
...@@ -18,7 +18,6 @@ import subprocess ...@@ -18,7 +18,6 @@ import subprocess
import collections import collections
import os.path import os.path
try: try:
from cStringIO import StringIO from cStringIO import StringIO
except ImportError: except ImportError:
...@@ -122,6 +121,21 @@ class TarantoolLog(object): ...@@ -122,6 +121,21 @@ class TarantoolLog(object):
with open(self.path, 'r') as f: with open(self.path, 'r') as f:
f.seek(0, os.SEEK_END) f.seek(0, os.SEEK_END)
self.log_begin = f.tell() self.log_begin = f.tell()
return self
def seek_once(self, msg):
if not os.path.exists(self.path):
return -1
with open(self.path, 'r') as f:
f.seek(self.log_begin, os.SEEK_SET)
while True:
log_str = f.readline()
if not log_str:
return -1
pos = log_str.find(msg)
if pos != -1:
return pos
def seek_from(self, msg, proc=None): def seek_from(self, msg, proc=None):
while True: while True:
...@@ -275,8 +289,7 @@ class TarantoolServer(Server): ...@@ -275,8 +289,7 @@ class TarantoolServer(Server):
return self._logfile_pos return self._logfile_pos
@logfile_pos.setter @logfile_pos.setter
def logfile_pos(self, val): def logfile_pos(self, val):
self._logfile_pos = TarantoolLog(val) self._logfile_pos = TarantoolLog(val).positioning()
self._logfile_pos.positioning()
@property @property
def script(self): def script(self):
...@@ -613,3 +626,6 @@ class TarantoolServer(Server): ...@@ -613,3 +626,6 @@ class TarantoolServer(Server):
version = p.stdout.read().rstrip() version = p.stdout.read().rstrip()
p.wait() p.wait()
return version return version
def get_log(self):
return TarantoolLog(self.logfile).positioning()
...@@ -16,21 +16,14 @@ server.admin("box.info.server.uuid") ...@@ -16,21 +16,14 @@ server.admin("box.info.server.uuid")
# Check log message # Check log message
server.stop() server.stop()
f = open(server.logfile, "r")
f.seek(0, 2)
server.start() server.start()
check="server uuid changed to " + new_uuid line = "server uuid changed to " + new_uuid
print "check log line for '%s'" % check print "check log line for '%s'" % line
print print
line = f.readline() if server.logfile_pos.seek_once(line) >= 0:
while line: print "'%s' exists in server log" % line
if re.search(r'(%s)' % check, line):
print "'%s' exists in server log" % check
break
line = f.readline()
print print
f.close()
server.admin("box.info.server.uuid") server.admin("box.info.server.uuid")
# Check that new UUID has been saved in snapshot # Check that new UUID has been saved in snapshot
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment