1
1
#!/usr/bin/env python
16
root_dir = opd(opd(opd((os.path.abspath(__file__)))))
19
class AmuletDeployment(object):
20
"""Fixture for a deployed set of juju services from a deployer config"""
22
def __init__(self, deployer_cfg, juju_env=None, sentries=False):
23
self.deployment = amulet.Deployment(juju_env, sentries=sentries)
24
with open(deployer_cfg) as f:
25
jd_script = yaml.safe_load(f.read())
26
self.fixup_includes(os.path.dirname(deployer_cfg), jd_script)
27
# Use juju_env given or defaulted above rather than taking the name
28
# from the deployer config and assuming an env of that name exists
29
script = {self.deployment.juju_env: jd_script.values()[0]}
30
self.deployment.load(script)
32
def fixup_includes(self, path, jd_script):
33
# amulet doesn't deal with "include-base64" options, we we have to
34
# patch the config ourselves
35
for deployment in jd_script:
36
for service in jd_script[deployment]['services'].values():
37
for key, val in service.get('options', {}).iteritems():
38
include_token = 'include-base64://'
39
if type(val) is str and val.startswith(include_token):
40
val = val.replace(include_token, '')
41
path = os.path.join(path, val)
43
val = base64.b64encode(f.read())
44
service['options'][key] = val
47
self.deployment.setup()
50
class TicketSystemTest(unittest.TestCase):
9
from tests.deployers import DEPLOYER_DIR, DeployerTest
12
class TicketSystemTest(DeployerTest):
51
13
"""Integration tests for ticket-system service run on a juju deployment"""
54
super(TicketSystemTest, self).setUp()
55
self.deployer = AmuletDeployment(os.path.join(root_dir,
57
'ticket-system.yaml'))
60
def get_ip_and_port(self):
61
self.status = amulet.waiter.status(self.deployer.deployment.juju_env)
62
units = self.status['services']['ts-django']['units']
63
ip = units['ts-django/0']['public-address']
64
port, _ = units['ts-django/0']['open-ports'][0].split('/')
15
deployer_cfg = os.path.join(DEPLOYER_DIR, 'ticket-system.yaml')
67
17
def get_server_status_and_content(self, url):
68
final_url = url.format(*self.get_ip_and_port())
18
final_url = url.format(*self.get_ip_and_port('ts-django'))
70
20
# Issue a simple command against the ticket API
71
21
client = httplib2.Http()