Beispiel #1
0
class TestBonnieFunctional(unittest.TestCase):
    attempts = 12

    def setUp(self):
        self.storage = ElasticSearchStorage()
        self.storage.es.indices.delete(index='logstash-*', ignore=[400, 404])
        self.storage.es.indices.delete(index='objects', ignore=[400, 404])

        call([os.path.join(pwd, 'start.sh'), basedir])
        time.sleep(1)

    def tearDown(self):
        call([os.path.join(pwd, 'stop.sh')])
        time.sleep(2)

    def query_log(self, query):
        attempts = self.attempts
        while attempts > 0:
            attempts -= 1
            res = self.storage.select(query, index='logstash-*', doctype='logs', sortby='@timestamp:desc')
            if res and res['total'] > 0:
                return res['hits']

            time.sleep(1)
            # print "query retry", attempts

        return None

    def storage_get(self, key, index, doctype):
        attempts = self.attempts
        while attempts > 0:
            attempts -= 1
            res = self.storage.get(key, index=index, doctype=doctype)
            if res is not None:
                return res
            time.sleep(1)
            # print "get retry", attempts

        return None