xref: /unit/test/unit/applications/proto.py (revision 1303)
11019Szelenkov@nginx.comimport re
21019Szelenkov@nginx.comimport time
31019Szelenkov@nginx.comfrom unit.control import TestControl
41019Szelenkov@nginx.com
51019Szelenkov@nginx.com
61019Szelenkov@nginx.comclass TestApplicationProto(TestControl):
71019Szelenkov@nginx.com    def sec_epoch(self):
81019Szelenkov@nginx.com        return time.mktime(time.gmtime())
91019Szelenkov@nginx.com
101019Szelenkov@nginx.com    def date_to_sec_epoch(self, date, template='%a, %d %b %Y %H:%M:%S %Z'):
111019Szelenkov@nginx.com        return time.mktime(time.strptime(date, template))
121019Szelenkov@nginx.com
131027Szelenkov@nginx.com    def search_in_log(self, pattern, name='unit.log'):
141027Szelenkov@nginx.com        with open(self.testdir + '/' + name, 'r', errors='ignore') as f:
151019Szelenkov@nginx.com            return re.search(pattern, f.read())
161028Szelenkov@nginx.com
171028Szelenkov@nginx.com    def wait_for_record(self, pattern, name='unit.log'):
181028Szelenkov@nginx.com        for i in range(50):
191028Szelenkov@nginx.com            found = self.search_in_log(pattern, name)
201028Szelenkov@nginx.com
211028Szelenkov@nginx.com            if found is not None:
221028Szelenkov@nginx.com                break
231028Szelenkov@nginx.com
241028Szelenkov@nginx.com            time.sleep(0.1)
251028Szelenkov@nginx.com
261028Szelenkov@nginx.com        return found
271050Szelenkov@nginx.com
28*1303St.nateldemoura@f5.com    def _load_conf(self, conf, **kwargs):
29*1303St.nateldemoura@f5.com        if 'applications' in conf:
30*1303St.nateldemoura@f5.com            for app in conf['applications'].keys():
31*1303St.nateldemoura@f5.com                app_conf = conf['applications'][app]
32*1303St.nateldemoura@f5.com                if 'user' in kwargs:
33*1303St.nateldemoura@f5.com                    app_conf['user'] = kwargs['user']
34*1303St.nateldemoura@f5.com
35*1303St.nateldemoura@f5.com                if 'group' in kwargs:
36*1303St.nateldemoura@f5.com                    app_conf['group'] = kwargs['group']
37*1303St.nateldemoura@f5.com
38*1303St.nateldemoura@f5.com                if 'isolation' in kwargs:
39*1303St.nateldemoura@f5.com                    app_conf['isolation'] = kwargs['isolation']
40*1303St.nateldemoura@f5.com
411050Szelenkov@nginx.com        self.assertIn(
421050Szelenkov@nginx.com            'success', self.conf(conf), 'load application configuration'
431050Szelenkov@nginx.com        )
44