xref: /unit/test/unit/applications/proto.py (revision 1477)
11019Szelenkov@nginx.comimport re
21019Szelenkov@nginx.comimport time
3*1477Szelenkov@nginx.com
41019Szelenkov@nginx.comfrom unit.control import TestControl
51019Szelenkov@nginx.com
61019Szelenkov@nginx.com
71019Szelenkov@nginx.comclass TestApplicationProto(TestControl):
81019Szelenkov@nginx.com    def sec_epoch(self):
91019Szelenkov@nginx.com        return time.mktime(time.gmtime())
101019Szelenkov@nginx.com
111019Szelenkov@nginx.com    def date_to_sec_epoch(self, date, template='%a, %d %b %Y %H:%M:%S %Z'):
121019Szelenkov@nginx.com        return time.mktime(time.strptime(date, template))
131019Szelenkov@nginx.com
141027Szelenkov@nginx.com    def search_in_log(self, pattern, name='unit.log'):
151027Szelenkov@nginx.com        with open(self.testdir + '/' + name, 'r', errors='ignore') as f:
161019Szelenkov@nginx.com            return re.search(pattern, f.read())
171028Szelenkov@nginx.com
181028Szelenkov@nginx.com    def wait_for_record(self, pattern, name='unit.log'):
191028Szelenkov@nginx.com        for i in range(50):
201028Szelenkov@nginx.com            found = self.search_in_log(pattern, name)
211028Szelenkov@nginx.com
221028Szelenkov@nginx.com            if found is not None:
231028Szelenkov@nginx.com                break
241028Szelenkov@nginx.com
251028Szelenkov@nginx.com            time.sleep(0.1)
261028Szelenkov@nginx.com
271028Szelenkov@nginx.com        return found
281050Szelenkov@nginx.com
291303St.nateldemoura@f5.com    def _load_conf(self, conf, **kwargs):
301303St.nateldemoura@f5.com        if 'applications' in conf:
311303St.nateldemoura@f5.com            for app in conf['applications'].keys():
321303St.nateldemoura@f5.com                app_conf = conf['applications'][app]
331303St.nateldemoura@f5.com                if 'user' in kwargs:
341303St.nateldemoura@f5.com                    app_conf['user'] = kwargs['user']
351303St.nateldemoura@f5.com
361303St.nateldemoura@f5.com                if 'group' in kwargs:
371303St.nateldemoura@f5.com                    app_conf['group'] = kwargs['group']
381303St.nateldemoura@f5.com
391303St.nateldemoura@f5.com                if 'isolation' in kwargs:
401303St.nateldemoura@f5.com                    app_conf['isolation'] = kwargs['isolation']
411303St.nateldemoura@f5.com
421050Szelenkov@nginx.com        self.assertIn(
431050Szelenkov@nginx.com            'success', self.conf(conf), 'load application configuration'
441050Szelenkov@nginx.com        )
45