~psivaa/uci-engine/lander-jenkins-plugin

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
#!/usr/bin/env python

import json
import httplib2
import yaml
import os
import sys

opd = os.path.dirname

root_dir = opd(opd(opd((os.path.abspath(__file__)))))

import amulet

def main():
    # FIXME: Running amulet with sentries is vurrently bogus in multiple ways
    # and we can get juju status ourselves -- vila 2013-12-18
    depl = amulet.Deployment(sentries=False)
    jd_path = os.path.join(root_dir, 'juju-deployer', 'ppa-assigner.yaml')
    with open(jd_path) as f:
        jd_script = yaml.safe_load(f.read())
    # Override the juju env provided by ppa-assigner or amulet gets confused
    script = {depl.juju_env: jd_script.values()[0]}
    depl.load(script)
    # This is a no-op if (as expected) the ppa-assigner has already been
    # deployed, but it *will* be deployed if needed anyway.
    depl.setup()

    status = amulet.waiter.status(depl.juju_env)
    units = status['services']['django']['units']
    ip = units['django/0']['public-address']
    port, _ = units['django/0']['open-ports'][0].split('/')
    # Issue a simple command against the ppa assigner API
    url = 'http://{}:{}/api/v1/ppa'.format(ip, port)
    client = httplib2.Http()
    resp, content = client.request(url, 'GET')
    jcontent = json.loads(content)
    # Target
    # self.assertEqual('200', resp['status'])
    # self.assertNotEqual([], jcontent['objects'])
    if '200' != resp['status']:
        sys.exit(1)
    if [] == jcontent['objects']:
        sys.exit(2)


if __name__ == "__main__":
    main()