This repository was archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathfixtures.py
More file actions
48 lines (40 loc) · 1.65 KB
/
fixtures.py
File metadata and controls
48 lines (40 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import requests
import json
import urllib
import os
from retrying import retry
from pytest import fixture, config
from subprocess import run, PIPE
from .retry import retry_settings
@fixture
def kibana(host):
class Kibana(object):
def __init__(self):
self.version = run('./bin/elastic-version', stdout=PIPE).stdout.decode().strip()
self.flavor = config.getoption('--image-flavor')
self.url = 'http://localhost:5601'
self.process = host.process.get(comm='node')
self.image_flavor = config.getoption('--image-flavor')
self.environment = dict(
[line.split('=', 1) for line in self.stdout_of('env').split('\n')]
)
if 'STAGING_BUILD_NUM' in os.environ:
self.tag = '%s-%s' % (self.version, os.environ['STAGING_BUILD_NUM'])
else:
self.tag = self.version
if self.flavor != 'full':
self.image = 'docker.elastic.co/kibana/kibana-%s:%s' % (self.flavor, self.tag)
else:
self.image = 'docker.elastic.co/kibana/kibana:%s' % (self.tag)
self.docker_metadata = json.loads(
run(['docker', 'inspect', self.image], stdout=PIPE).stdout.decode())[0]
@retry(**retry_settings)
def get(self, location='/', allow_redirects=True):
"""GET a page from Kibana."""
url = urllib.parse.urljoin(self.url, location)
return requests.get(url)
def stdout_of(self, command):
result = host.run(command)
assert result.rc is 0
return result.stdout.strip()
return Kibana()