ait-aecid / logdata-anomaly-miner

This tool parses log data and allows to define analysis pipelines for anomaly detection. It was designed to run the analysis with limited resources and lowest possible permissions to make it suitable for production server use.
GNU General Public License v3.0
80 stars 24 forks source link

Not possible to run unit tests locally without aminer user #604

Closed landauermax closed 3 years ago

landauermax commented 3 years ago

I tried to run the unit test locally and got the following error:

landauerm@N3DSS2112:~/work/git/logdata-anomaly-miner/aecid-testsuite$ python3 -m unittest unit/analysis/EventFrequencyDetectorTest.py
E
======================================================================
ERROR: test1_normal_frequency_detection (unit.analysis.EventFrequencyDetectorTest.EventFrequencyDetectorTest)
This test case checks the normal detection of new frequencies.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/landauerm/work/git/logdata-anomaly-miner/aecid-testsuite/unit/TestBase.py", line 127, in setUp
    initialize_loggers(self.aminer_config, getpwnam('aminer').pw_uid, getgrnam('aminer').gr_gid)
KeyError: "getpwnam(): name not found: 'aminer'"

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)

I uncommented the line that caused the error and then the tests work. I am aware that logging is probably needed to evaluate the tests in the ci pipeline, however, it should also be possible to run the unit tests locally without the need to have a user named aminer.

ernstleierzopf commented 3 years ago

The logging is only needed to prevent everything to be printed in terminal. It has no actual use. What user should be used? The aminer user is created automatically with the proposed way of installing the aminer (with the install script)

Also to run the unittests other requirements like different locales have to be installed.

How should the user be determined in the unittests?

landauermax commented 3 years ago

I would think of this solution, but maybe there is some disadvantage to it that I am not aware of? Like different behavior for normal and root users, etc. - needs to be verified.

>>> import os
>>> os.getuid()
1000
>>> os.getgid()
1000
ernstleierzopf commented 3 years ago

That should be possible. I will implement it that way.