Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.10-cs: client-server rewritten as modules / start in foreground / test coverage for cs #1413

Merged
merged 28 commits into from Jul 13, 2016

Conversation

sebres
Copy link
Contributor

@sebres sebres commented May 12, 2016

closes #1121
closes #1139
Several enhancements, bug fixed and code optimization:

  • starting of the server (and client/server communication behavior during start and daemonize) completely rewritten:
    • client/server functionality moved away from bin and using now the common interface (introduced in fail2bancmdline);
    • start in foreground fixed;
    • server can act as client corresponding command line;
    • command "restart" added: in opposite to "reload" in reality restarts the server (new process);
    • several client/server bugs during starting process fixed.
  • possibility to increase verbosity up to heavy debug (command line parameter -vvv)
  • increase readability and details level by increased verbosity
  • reader bug fix: prevent to silent "load" of not existing jail;
  • coverage of test cases increased;
  • several bug fixed: fork in client-server test cases prohibited, all worker threads daemonized (to prevent hanging on exit).

# Conflicts:
#	fail2ban/server/server.py
…ng start and daemonize) completely rewritten:

  - client/server functionality moved away from bin and using now the common interface (introduced in fail2bancmdline);
  - start in foreground fixed;
  - server can act as client corresponding command line;
  - command "restart" added: in opposite to "reload" in reality restarts the server (new process);
  - several client/server bugs during starting process fixed.
, closes fail2ban#1139

small code review and fixing of some bugs during client-server communication process (in the test cases);
…orker threads daemonized (to prevent hanging on exit).
…eview), wait 4 server ready, test cases fixed (py2/py3)
@codecov-io
Copy link

codecov-io commented May 12, 2016

Current coverage is 92.11%

Merging #1413 into 0.10 will increase coverage by 0.75%

@@               0.10      #1413   diff @@
==========================================
  Files            71         75     +4   
  Lines          9235      10168   +933   
  Methods           0          0          
  Messages          0          0          
  Branches       1399       1548   +149   
==========================================
+ Hits           8437       9366   +929   
+ Misses          567        536    -31   
- Partials        231        266    +35   

Powered by Codecov. Last updated by 7582f13...f0b2cd2

if verbosity > 2:
fmt = ' +%(relativeCreated)5d %(thread)X %(levelname)-5.5s' + fmt
else:
fmt = ' %(asctime)-15s %(thread)X %(levelname)-5.5s' + fmt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems mixed indentation with spaces and tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@yarikoptic
Copy link
Member

Why didn't you listen to a wise man? #1139 (comment)
It would be much easier to review if we first just merged the move files away PR, without any functionality change. Now impossible to see what was moved and what was moved and then changed

@@ -386,6 +412,9 @@ def assertNotLogged(self, *s, **kwargs):
def pruneLog(self):
self._log.truncate(0)

def pruneLog(self):
self._log.truncate(0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@yarikoptic
Copy link
Member

So please do first the move, send it as a PR, we merge it after tests pass, and hopefully this diff becomes manageable

@sebres
Copy link
Contributor Author

sebres commented May 12, 2016

Why didn't you listen to a wise man? #1139 (comment)

Because:

  • it can't be test covered there;
  • in single commit I've moved bin/fail2ban-client -> fail2banclient and bin/fail2ban-server -> fail2banserver
  • I brought together CS in command line (double code -> single code)
  • the wise man can try to do it self, if he says it is lighter :))) With almost 30 years of developing behind back am I already wise enough to determine, that it is not so easy :)))

Now impossible to see what was moved and what was moved and then changed

Wrong, it is possible - just compare:

  • old bin/fail2ban-client with new fail2banclient / fail2bancmdline
  • old bin/fail2ban-server with new fail2banserver / fail2bancmdline

My git does it automatically (it can find the code lines, moved from other files)

So please do first the move, send it as a PR, we merge it after tests pass, and hopefully this diff becomes manageable

Move what and where?

@yarikoptic
Copy link
Member

On Thu, 12 May 2016, Serg G. Brester wrote:

 Why didn't you listen to a wise man? #1139 (comment)

Because:

 * it can't be test covered there;

I am not arguing against moving altogether, and understand that it
couldn't test covered there

 * in single commit I've moved bin/fail2ban-client -> fail2banclient and
   bin/fail2ban-server -> fail2banserver

good!

 * I brought together CS in command line (double code -> single code)

good -- that could be a good point [lets call it POINTX] to send a
PR at without piling up additional fixes/etc. Just code move +
refactoring to reduce duplication

 * the wise man can try to do it self, if he says it is lighter :))) With
   almost 30 years of developing behind back am I already wise enough to
   determine, that it is not so easy :)))

not sure what was the difficulty to have a PR for POINTX

 Now impossible to see what was moved and what was moved and then changed

Wrong, it is possible - just compare:

 * old bin/fail2ban-client with new fail2banclient / fail2bancmdline
 * old bin/fail2ban-server with new fail2banserver / fail2bancmdline

I meant while reviewing PR on github. I often do reviews from the
phone so can't easily checkout /compare files otherwise

My git does it automatically (it can find the code lines, moved from other
files)

 So please do first the move, send it as a PR, we merge it after tests
 pass, and hopefully this diff becomes manageable

Move what and where?

could there be a PR for POINTX mentioned above?

Yaroslav O. Halchenko
Center for Open Neuroscience http://centerforopenneuroscience.org
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419
WWW: http://www.linkedin.com/in/yarik

@sebres
Copy link
Contributor Author

sebres commented May 12, 2016

I don't know all the test cases of this commit pass, I'll make a commit 556ddaa as separated PR.

I can remember a "bug" for 'flushed' vs 'rolled over' in testFlushLogs, was fixed later from me...

@yarikoptic
Copy link
Member

btw -- tests fail for me (only) strangely since seems to (rightfully?) need a sample log file which is not in git... confused (don't have time atm to investigate) how it passed on travis:

$> bin/fail2ban-testcases testCheckStockJailActions
Fail2ban 0.9.4.dev0 test suite. Python 2.7.11+ (default, Apr 17 2016, 14:00:29) [GCC 5.3.1 20160409]. Please wait...
F
======================================================================
FAIL: testCheckStockJailActions (fail2ban.tests.servertestcase.ServerConfigReaderTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./fail2ban/tests/servertestcase.py", line 1046, in testCheckStockJailActions
    self.fail("Command %r has failed. Received %r" % (cmd, e))
AssertionError: Command ['set', 'pass2allow-ftp', 'addlogpath', './fail2ban/tests/files/logs/pass2allow-ftp', 'head'] has failed. Received IOError(2, 'No such file or directory')

----------------------------------------------------------------------
Ran 1 test in 0.397s

FAILED (failures=1)

$> ls -l './fail2ban/tests/files/logs/pass2allow-ftp' 
ls: cannot access './fail2ban/tests/files/logs/pass2allow-ftp': No such file or directory

@sebres
Copy link
Contributor Author

sebres commented May 12, 2016

You have not clean copy - perhabs one custom config pass2allow-ftp local (uncommited) and for it no logs.
testCheckStockJailActions loads all stock filters / action and transmit it to the TestServer...

I can rewrite this test case, that will ignore all configs, that don't have corresponding test log file...

Or just ignore this one...

bin/fail2ban-testcases -i testCheckStockJailActions

@sebres sebres mentioned this pull request May 12, 2016
@sebres sebres force-pushed the f2b-perfom-prepare-716-cs-0.10 branch from dfd9121 to 06dcad7 Compare May 17, 2016 10:27
return True

@staticmethod
def exit(code=0): # pragma: no cover - can't test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope -- pragma is incorrect -- could be tested via mocking at least for the smoke testing and/or logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the global exit handler is overwritten in test cases (to test forked processes exit code), so it can't (we need a return code).

Indeed, we could rewrite it using mock module, but the overhead is unnecessarily (several times larger) for coverage of this 2 lines.

@coveralls
Copy link

coveralls commented Jul 11, 2016

Coverage Status

Coverage increased (+0.9%) to 94.737% when pulling 6a2b70f on sebres:f2b-perfom-prepare-716-cs-0.10 into 7582f13 on fail2ban:0.10.

@sebres
Copy link
Contributor Author

sebres commented Jul 11, 2016

I'm done, ready to merge to 0.10...

Still again: that is a first shot (minimal invasive surgery), better mocking can be made later, because the test cases are almost wholehearted (I mean expected behavior of CS).

@yarikoptic
Copy link
Member

sent you a PR sebres#6

@sebres
Copy link
Contributor Author

sebres commented Jul 12, 2016

sebres#6 merged, but rewritten a little bit (see 2 commits above)
Thanks

@coveralls
Copy link

coveralls commented Jul 13, 2016

Coverage Status

Coverage increased (+0.9%) to 94.716% when pulling 53da35e on sebres:f2b-perfom-prepare-716-cs-0.10 into 7582f13 on fail2ban:0.10.

@yarikoptic
Copy link
Member

I still don't like having tests specific logic within code itself (all the PRODUCTION thing) and persistent mocking of stuff within test module, but I guess we will leave it for the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants