~openstack-charmers/charms/trusty/tempest/next

« back to all changes in this revision

Viewing changes to lib/charm/openstack/tempest.py

  • Committer: Liam Young
  • Date: 2016-05-06 19:19:59 UTC
  • Revision ID: liam.young@canonical.com-20160506191959-86z9jgx3sn41w34y
Docstrings and trusty deploy fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
 
14
14
def get_charm():
 
15
    """ Return a new instance of TempestCharm or existing global instance
 
16
    @returns TempestCharm
 
17
    """
15
18
    global tempest_charm
16
19
    if tempest_charm is None:
17
20
        tempest_charm = TempestCharmFactory.charm()
20
23
 
21
24
class TempestAdminAdapter(adapters.OpenStackRelationAdapter):
22
25
 
 
26
    """Inspect relations and provide properties that can be used when
 
27
       rendering templates"""
 
28
 
23
29
    interface_type = "identity-admin"
24
30
 
25
31
    def __init__(self, relation):
 
32
        """Initialise a keystone client and collect user defined config"""
26
33
        self.kc = None
27
34
        super(TempestAdminAdapter, self).__init__(relation)
28
35
        self.init_keystone_client()
29
36
        self.uconfig = hookenv.config()
30
37
 
 
38
    @property
 
39
    def keystone_info(self):
 
40
        """Collection keystone information from keystone relation"""
 
41
        return self.relation.credentials()
 
42
 
31
43
    def init_keystone_client(self):
 
44
        """Initialise keystone client"""
32
45
        if self.kc:
33
46
            return
34
47
        self.keystone_auth_url = '{}://{}:{}/v2.0'.format(
35
48
            'http',
36
 
            self.creds['service_hostname'],
37
 
            self.creds['service_port']
 
49
            self.keystone_info['service_hostname'],
 
50
            self.keystone_info['service_port']
38
51
        )
39
52
        auth = {
40
 
            'username': self.creds['service_username'],
41
 
            'password': self.creds['service_password'],
 
53
            'username': self.keystone_info['service_username'],
 
54
            'password': self.keystone_info['service_password'],
42
55
            'auth_url': self.keystone_auth_url,
43
 
            'tenant_name': self.creds['service_tenant_name'],
44
 
            'region_name': self.creds['service_region'],
 
56
            'tenant_name': self.keystone_info['service_tenant_name'],
 
57
            'region_name': self.keystone_info['service_region'],
45
58
        }
46
59
        try:
47
60
            self.kc = keystoneclient.client.Client(**auth)
50
63
 
51
64
    @property
52
65
    def ec2_creds(self):
 
66
        """Generate EC2 style tokens or return existing EC2 tokens
 
67
 
 
68
        @returns {'access_token' token1, 'secret_token': token2}
 
69
        """
53
70
        self.init_keystone_client()
54
71
        if not self.kc:
55
72
            return {}
62
79
 
63
80
    @property
64
81
    def image_info(self):
 
82
        """Return image ids for the user-defined image names
 
83
 
 
84
        @returns {'image_id' id1, 'image_alt_id': id2}
 
85
        """
65
86
        self.init_keystone_client()
66
87
        glance_endpoint = self.kc.service_catalog.url_for(
67
88
            service_type='image',
81
102
 
82
103
    @property
83
104
    def network_info(self):
 
105
        """Return public network and router ids for user-defined router and
 
106
           network names
 
107
 
 
108
        @returns {'image_id' id1, 'image_alt_id': id2}
 
109
        """
84
110
        self.init_keystone_client()
85
111
        neutron_ep = self.kc.service_catalog.url_for(
86
112
            service_type='network',
110
136
 
111
137
    @property
112
138
    def compute_info(self):
 
139
        """Return flavor ids for user-defined flavors
 
140
 
 
141
        @returns {'flavor_id' id1, 'flavor_alt_id': id2}
 
142
        """
113
143
        self.init_keystone_client()
114
144
        nova_ep = self.kc.service_catalog.url_for(
115
145
            service_type='compute',
122
152
                                                     url.netloc.split(':')[0])
123
153
        try:
124
154
            nova_client = novaclient.client.Client(
125
 
                self.creds['service_username'],
126
 
                self.creds['service_password'],
127
 
                self.creds['service_tenant_name'],
 
155
                self.keystone_info['service_username'],
 
156
                self.keystone_info['service_password'],
 
157
                self.keystone_info['service_tenant_name'],
128
158
                self.keystone_auth_url,
129
159
            )
130
160
            for flavor in nova_client.flavors.list():
136
166
            hookenv.log("Nova is not ready, deferring nova query")
137
167
        return compute_info
138
168
 
139
 
    @property
140
 
    def creds(self):
141
 
        return self.relation.credentials()
142
 
 
143
 
    @property
144
 
    def auth_url(self):
145
 
        bob = self.get_keystone_client() or 'bugger'
146
 
        return bob
147
169
 
148
170
    def get_present_services(self):
 
171
        """Query keystone catalogue for a list for registered services
 
172
 
 
173
        @returns [svc1, svc2, ...]: List of registered services
 
174
        """
149
175
        self.init_keystone_client()
150
176
        services = [svc.name for svc in self.kc.services.list() if svc.enabled]
151
 
#        if DashboardRelation().get('dashboard_url'):
152
 
#            services.append('horizon')
153
177
        return services
154
178
 
155
179
    @property
156
180
    def service_info(self):
 
181
        """Assemble a list of services tempest should tests
 
182
 
 
183
        Compare the list of keystone registered services with the services the
 
184
        user has requested be tested. If in 'auto' mode test all services
 
185
        registered in keystone.
 
186
        
 
187
        @returns [svc1, svc2, ...]: List of services to test
 
188
        """
157
189
        service_info = {}
158
190
        tempest_candidates = ['ceilometer', 'cinder', 'glance', 'heat',
159
191
                              'horizon', 'ironic', 'neutron', 'nova',
181
213
 
182
214
class TempestAdapters(adapters.OpenStackRelationAdapters):
183
215
    """
184
 
    Adapters class for the Designate charm.
 
216
    Adapters class for the Tempest charm.
185
217
    """
186
218
    relation_adapters = {
187
219
        'identity_admin': TempestAdminAdapter,
194
226
 
195
227
 
196
228
class TempestConfigurationAdapter(adapters.ConfigurationAdapter):
197
 
 
 
229
    """
 
230
    Manipulate user supplied config as needed
 
231
    """
198
232
    def __init__(self):
199
233
        super(TempestConfigurationAdapter, self).__init__()
200
234
 
201
235
 
202
236
class TempestCharm(charm.OpenStackCharm):
203
237
 
 
238
    """Directories and files used for running tempest"""
204
239
    TEMPEST_ROOT = '/var/lib/tempest/'
205
240
    TEMPEST_LOGDIR = TEMPEST_ROOT + '/logs'
206
241
    TEMPEST_CONF = TEMPEST_ROOT + '/tempest.conf'
 
242
    """pip.conf for proxy settings etc"""
207
243
    PIP_CONF = '/root/.pip/pip.conf'
208
244
 
 
245
    """List of packages charm should install
 
246
       XXX The install hook is currently installing most packages ahead of
 
247
           this because modules like keystoneclient are needed at load time
 
248
    """
209
249
    packages = [
210
250
        'git', 'testrepository', 'subunit', 'python-nose', 'python-lxml',
211
251
        'python-boto', 'python-junitxml', 'python-subunit',
217
257
        'python3-keystoneclient', 'python3-neutronclient',
218
258
        'python3-novaclient', 'python3-swiftclient',
219
259
        'python3-ceilometerclient', 'openvswitch-common', 'libffi-dev',
220
 
        'libssl-dev', 'python-dev', 'python-cffi', 'tox'
 
260
        'libssl-dev', 'python-dev', 'python-cffi'
221
261
    ]
222
262
 
 
263
    """Use the Tempest specific adapters"""
223
264
    adapters_class = TempestAdapters
 
265
    """Tempest has no running services so no services need restarting on
 
266
       config file change
 
267
    """
224
268
    restart_map = {
225
269
        TEMPEST_CONF: [],
226
270
        PIP_CONF: [],