~openstack-charmers-archive/charms/trusty/keystone/next

« back to all changes in this revision

Viewing changes to tests/charmhelpers/contrib/openstack/amulet/utils.py

  • Committer: james.page at ubuntu
  • Date: 2014-07-31 08:11:46 UTC
  • mfrom: (72.1.1 keystone)
  • Revision ID: james.page@ubuntu.com-20140731081146-j08aadm8vc3xxz8a
[coreycb,r=james-page] Resync helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
class OpenStackAmuletUtils(AmuletUtils):
19
 
    """This class inherits from AmuletUtils and has additional support
20
 
       that is specifically for use by OpenStack charms."""
 
19
    """OpenStack amulet utilities.
 
20
 
 
21
       This class inherits from AmuletUtils and has additional support
 
22
       that is specifically for use by OpenStack charms.
 
23
       """
21
24
 
22
25
    def __init__(self, log_level=ERROR):
23
26
        """Initialize the deployment environment."""
25
28
 
26
29
    def validate_endpoint_data(self, endpoints, admin_port, internal_port,
27
30
                               public_port, expected):
28
 
        """Validate actual endpoint data vs expected endpoint data. The ports
29
 
           are used to find the matching endpoint."""
 
31
        """Validate endpoint data.
 
32
 
 
33
           Validate actual endpoint data vs expected endpoint data. The ports
 
34
           are used to find the matching endpoint.
 
35
           """
30
36
        found = False
31
37
        for ep in endpoints:
32
38
            self.log.debug('endpoint: {}'.format(repr(ep)))
33
 
            if admin_port in ep.adminurl and internal_port in ep.internalurl \
34
 
               and public_port in ep.publicurl:
 
39
            if (admin_port in ep.adminurl and
 
40
                    internal_port in ep.internalurl and
 
41
                    public_port in ep.publicurl):
35
42
                found = True
36
43
                actual = {'id': ep.id,
37
44
                          'region': ep.region,
47
54
            return 'endpoint not found'
48
55
 
49
56
    def validate_svc_catalog_endpoint_data(self, expected, actual):
50
 
        """Validate a list of actual service catalog endpoints vs a list of
51
 
           expected service catalog endpoints."""
 
57
        """Validate service catalog endpoint data.
 
58
 
 
59
           Validate a list of actual service catalog endpoints vs a list of
 
60
           expected service catalog endpoints.
 
61
           """
52
62
        self.log.debug('actual: {}'.format(repr(actual)))
53
63
        for k, v in expected.iteritems():
54
64
            if k in actual:
60
70
        return ret
61
71
 
62
72
    def validate_tenant_data(self, expected, actual):
63
 
        """Validate a list of actual tenant data vs list of expected tenant
64
 
           data."""
 
73
        """Validate tenant data.
 
74
 
 
75
           Validate a list of actual tenant data vs list of expected tenant
 
76
           data.
 
77
           """
65
78
        self.log.debug('actual: {}'.format(repr(actual)))
66
79
        for e in expected:
67
80
            found = False
78
91
        return ret
79
92
 
80
93
    def validate_role_data(self, expected, actual):
81
 
        """Validate a list of actual role data vs a list of expected role
82
 
           data."""
 
94
        """Validate role data.
 
95
 
 
96
           Validate a list of actual role data vs a list of expected role
 
97
           data.
 
98
           """
83
99
        self.log.debug('actual: {}'.format(repr(actual)))
84
100
        for e in expected:
85
101
            found = False
95
111
        return ret
96
112
 
97
113
    def validate_user_data(self, expected, actual):
98
 
        """Validate a list of actual user data vs a list of expected user
99
 
           data."""
 
114
        """Validate user data.
 
115
 
 
116
           Validate a list of actual user data vs a list of expected user
 
117
           data.
 
118
           """
100
119
        self.log.debug('actual: {}'.format(repr(actual)))
101
120
        for e in expected:
102
121
            found = False
114
133
        return ret
115
134
 
116
135
    def validate_flavor_data(self, expected, actual):
117
 
        """Validate a list of actual flavors vs a list of expected flavors."""
 
136
        """Validate flavor data.
 
137
 
 
138
           Validate a list of actual flavors vs a list of expected flavors.
 
139
           """
118
140
        self.log.debug('actual: {}'.format(repr(actual)))
119
141
        act = [a.name for a in actual]
120
142
        return self._validate_list_data(expected, act)
121
143
 
122
144
    def tenant_exists(self, keystone, tenant):
123
 
        """Return True if tenant exists"""
 
145
        """Return True if tenant exists."""
124
146
        return tenant in [t.name for t in keystone.tenants.list()]
125
147
 
126
148
    def authenticate_keystone_admin(self, keystone_sentry, user, password,
127
149
                                    tenant):
128
150
        """Authenticates admin user with the keystone admin endpoint."""
129
 
        service_ip = \
130
 
            keystone_sentry.relation('shared-db',
131
 
                                     'mysql:shared-db')['private-address']
 
151
        unit = keystone_sentry
 
152
        service_ip = unit.relation('shared-db',
 
153
                                   'mysql:shared-db')['private-address']
132
154
        ep = "http://{}:35357/v2.0".format(service_ip.strip().decode('utf-8'))
133
155
        return keystone_client.Client(username=user, password=password,
134
156
                                      tenant_name=tenant, auth_url=ep)
177
199
            image = glance.images.create(name=image_name, is_public=True,
178
200
                                         disk_format='qcow2',
179
201
                                         container_format='bare', data=f)
 
202
        count = 1
 
203
        status = image.status
 
204
        while status != 'active' and count < 10:
 
205
            time.sleep(3)
 
206
            image = glance.images.get(image.id)
 
207
            status = image.status
 
208
            self.log.debug('image status: {}'.format(status))
 
209
            count += 1
 
210
 
 
211
        if status != 'active':
 
212
            self.log.error('image creation timed out')
 
213
            return None
 
214
 
180
215
        return image
181
216
 
182
217
    def delete_image(self, glance, image):
183
218
        """Delete the specified image."""
 
219
        num_before = len(list(glance.images.list()))
184
220
        glance.images.delete(image)
185
221
 
 
222
        count = 1
 
223
        num_after = len(list(glance.images.list()))
 
224
        while num_after != (num_before - 1) and count < 10:
 
225
            time.sleep(3)
 
226
            num_after = len(list(glance.images.list()))
 
227
            self.log.debug('number of images: {}'.format(num_after))
 
228
            count += 1
 
229
 
 
230
        if num_after != (num_before - 1):
 
231
            self.log.error('image deletion timed out')
 
232
            return False
 
233
 
 
234
        return True
 
235
 
186
236
    def create_instance(self, nova, image_name, instance_name, flavor):
187
237
        """Create the specified instance."""
188
238
        image = nova.images.find(name=image_name)
199
249
            self.log.debug('instance status: {}'.format(status))
200
250
            count += 1
201
251
 
202
 
        if status == 'BUILD':
 
252
        if status != 'ACTIVE':
 
253
            self.log.error('instance creation timed out')
203
254
            return None
204
255
 
205
256
        return instance
206
257
 
207
258
    def delete_instance(self, nova, instance):
208
259
        """Delete the specified instance."""
 
260
        num_before = len(list(nova.servers.list()))
209
261
        nova.servers.delete(instance)
 
262
 
 
263
        count = 1
 
264
        num_after = len(list(nova.servers.list()))
 
265
        while num_after != (num_before - 1) and count < 10:
 
266
            time.sleep(3)
 
267
            num_after = len(list(nova.servers.list()))
 
268
            self.log.debug('number of instances: {}'.format(num_after))
 
269
            count += 1
 
270
 
 
271
        if num_after != (num_before - 1):
 
272
            self.log.error('instance deletion timed out')
 
273
            return False
 
274
 
 
275
        return True