1# Copyright (C) 2019 Armin Kuster <akuster808@gmail.com>
2#
3import re
4import os
5
6from oeqa.runtime.case import OERuntimeTestCase
7from oeqa.core.decorator.depends import OETestDepends
8from oeqa.runtime.decorator.package import OEHasPackage
9
10
11class SamhainTest(OERuntimeTestCase):
12
13    @OEHasPackage(['samhain-standalone'])
14    @OETestDepends(['ssh.SSHTest.test_ssh'])
15    def test_samhain_help(self):
16        machine = self.td.get('MACHINE', '')
17        status, output = self.target.run('echo "127.0.0.1 %s.localdomain  %s" >> /etc/hosts' % (machine, machine))
18        msg = ("samhain can't append hosts. "
19               'Status and output:%s and %s' % (status, output))
20        self.assertEqual(status, 0, msg = msg)
21
22        status, output = self.target.run('samhain --help')
23        msg = ('samhain command does not work as expected. '
24               'Status and output:%s and %s' % (status, output))
25        self.assertEqual(status, 0, msg = msg)
26
27    @OETestDepends(['samhain.SamhainTest.test_samhain_help'])
28    def test_samhain_init_db(self):
29        status, output = self.target.run('samhain -t init')
30        match = re.search('FAILED: 0 ', output)
31        if not match:
32            msg = ('samhain database init had an unexpected failure. '
33               'Status and output:%s and %s' % (status, output))
34            self.assertEqual(status, 0, msg = msg)
35
36    @OETestDepends(['samhain.SamhainTest.test_samhain_init_db'])
37    def test_samhain_db_check(self):
38        status, output = self.target.run('samhain -t check')
39        match = re.search('FAILED: 0 ', output)
40        if not match:
41            msg = ('samhain errors found in db. '
42               'Status and output:%s and %s' % (status, output))
43            self.assertEqual(status, 0, msg = msg)
44