~ajkavanagh/+junk/useful-things

« back to all changes in this revision

Viewing changes to charm-manual-testing/manila/v2_keystone/post-deploy-config.py

  • Committer: Alex Kavanagh
  • Date: 2016-12-01 17:01:49 UTC
  • Revision ID: alex.kavanagh@canonical.com-20161201170149-ytewr1hw7z2xre8o
Added serverstack.yaml for juju & manila testing scripts

Note that the manila testing scripts are for serverstack ONLY.
There's a different github repo for manual testing of
manila.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import subprocess
 
4
import yaml
 
5
import os
 
6
import sys
 
7
 
 
8
from neutronclient.v2_0 import client as ne_client
 
9
from novaclient import client as no_client
 
10
from keystoneclient.v2_0 import client as ks_client
 
11
from keystoneclient.auth import identity
 
12
from keystoneclient import session
 
13
 
 
14
if __name__ == '__main__':
 
15
    # use session based authentication
 
16
    ep = os.environ['OS_AUTH_URL']
 
17
    if not ep.endswith('v2.0'):
 
18
        ep = "{}/v2.0".format(ep)
 
19
    auth = identity.v2.Password(username=os.environ['OS_USERNAME'],
 
20
                                password=os.environ['OS_PASSWORD'],
 
21
                                tenant_name=os.environ['OS_TENANT_NAME'],
 
22
                                auth_url=ep)
 
23
    sess = session.Session(auth=auth)
 
24
    keystone = ks_client.Client(session=sess)
 
25
    keystone.auth_ref = auth.get_access(sess)
 
26
 
 
27
    neutron_ep = keystone.service_catalog.url_for(
 
28
            service_type='network', endpoint_type='publicURL')
 
29
    neutron = ne_client.Client(session=sess)
 
30
    # neutron = ne_client.Client(username=os.environ['OS_USERNAME'],
 
31
                               # password=os.environ['OS_PASSWORD'],
 
32
                               # tenant_name=os.environ['OS_TENANT_NAME'],
 
33
                               # auth_url=os.environ['OS_AUTH_URL'],
 
34
                               # region_name=os.environ['OS_REGION_NAME'])
 
35
    nova_ep = keystone.service_catalog.url_for(
 
36
        service_type='compute', endpoint_type='publicURL')
 
37
    nova = no_client.Client('2', session=sess)
 
38
    # nova = no_client.Client('2',
 
39
                            # os.environ['OS_USERNAME'],
 
40
                            # os.environ['OS_PASSWORD'],
 
41
                            # os.environ['OS_TENANT_NAME'],
 
42
                            # os.environ['OS_AUTH_URL'],
 
43
                            # os.environ['OS_REGION_NAME'])
 
44
 
 
45
    net_id = os.environ.get('NET_ID')
 
46
    if net_id:
 
47
        # Use OSCI / Jenkins environment variable if defined.
 
48
        print('Using NET_ID environment variable: {}'.format(net_id))
 
49
    else:
 
50
        # Preserve existing default behavior (eg. manual testing)
 
51
        net_name = os.environ['OS_USERNAME'] + '_admin_net'
 
52
        print('Using default network name: {}'.format(net_name))
 
53
        try:
 
54
            network = neutron.list_networks(name=net_name)['networks'][0]
 
55
            net_id = network['id']
 
56
        except IndexError:
 
57
            print('Unable to find local network {}'.format(net_name))
 
58
            raise ValueError('Unable to find local network {}'.format(net_name))
 
59
 
 
60
    service = sys.argv[1]
 
61
 
 
62
    service_config = yaml.load(
 
63
        subprocess.check_output(['juju', 'status', '--format=yaml', service])
 
64
    )
 
65
 
 
66
    uuids = []
 
67
    for machine in service_config['machines']:
 
68
        uuids.append(service_config['machines'][machine]['instance-id'])
 
69
 
 
70
    ext_port = []
 
71
    if len(sys.argv) >= 3:
 
72
        ext_port = [sys.argv[2]]
 
73
 
 
74
    if len(uuids) > 0:
 
75
        for uuid in uuids:
 
76
            print("Attaching interface to instance {}".format(uuid))
 
77
            server = nova.servers.get(uuid)
 
78
            result = server.interface_attach(port_id=None,
 
79
                                             net_id=net_id,
 
80
                                             fixed_ip=None).to_dict()
 
81
            ext_port.append("br-ex:{}".format(result['mac_addr']))
 
82
 
 
83
    ports = " ".join(ext_port)
 
84
    if ports:
 
85
        juju_version = subprocess.check_output(['juju', '--version'])[0]
 
86
        print("juju_version: '{}'".format(juju_version))
 
87
        command = ['set', 'config'][int(juju_version) - 1]
 
88
        print("Setting data-port configuration on {} to {}".format(service, ports))
 
89
        subprocess.check_call(['juju', command, service, 'data-port={}'.format(ports)])
 
90
    else:
 
91
        print("Nothing to do with ext-port configuration")
 
92