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

« back to all changes in this revision

Viewing changes to tests/ppa_assigner/test.py

  • Committer: Vincent Ladeuil
  • Date: 2013-12-18 17:27:45 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: v.ladeuil+lp@free.fr-20131218172745-wf9vw92a8pl1kh40
A first rough integration test using juju-deployer and amulet. It currently fails because the list of ppas returned is empty (but the server properly returns a 200 ok response \o/).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import json
 
4
import httplib2
 
5
import yaml
 
6
import os
 
7
import sys
 
8
 
 
9
opd = os.path.dirname
 
10
 
 
11
root_dir = opd(opd(opd((os.path.abspath(__file__)))))
 
12
 
 
13
import amulet
 
14
 
 
15
def main():
 
16
    # FIXME: Running amulet with sentries is vurrently bogus in multiple ways
 
17
    # and we can get juju status ourselves -- vila 2013-12-18
 
18
    depl = amulet.Deployment(sentries=False)
 
19
    jd_path = os.path.join(root_dir, 'juju-deployer', 'ppa-assigner.yaml')
 
20
    with open(jd_path) as f:
 
21
        jd_script = yaml.safe_load(f.read())
 
22
    # Override the juju env provided by ppa-assigner or amulet gets confused
 
23
    script = {depl.juju_env: jd_script.values()[0]}
 
24
    depl.load(script)
 
25
    # This is a no-op if (as expected) the ppa-assigner has already been
 
26
    # deployed, but it *will* be deployed if needed anyway.
 
27
    depl.setup()
 
28
 
 
29
    status = amulet.waiter.status(depl.juju_env)
 
30
    units = status['services']['django']['units']
 
31
    ip = units['django/0']['public-address']
 
32
    port, _ = units['django/0']['open-ports'][0].split('/')
 
33
    # Issue a simple command against the ppa assigner API
 
34
    url = 'http://{}:{}/api/v1/ppa'.format(ip, port)
 
35
    client = httplib2.Http()
 
36
    resp, content = client.request(url, 'GET')
 
37
    jcontent = json.loads(content)
 
38
    # Target
 
39
    # self.assertEqual('200', resp['status'])
 
40
    # self.assertNotEqual([], jcontent['objects'])
 
41
    if '200' != resp['status']:
 
42
        sys.exit(1)
 
43
    if [] == jcontent['objects']:
 
44
        sys.exit(2)
 
45
 
 
46
 
 
47
if __name__ == "__main__":
 
48
    main()