~corey.bryant/charms/trusty/keystone/python-six

« back to all changes in this revision

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

  • Committer: Liam Young
  • Date: 2014-07-21 09:49:40 UTC
  • mfrom: (68.1.6 keystone)
  • Revision ID: liam.young@canonical.com-20140721094940-ffsywsa04ocxqhfa
[corey.bryant,r=gnuoy] Sleep for 10 seconds before checking if keystone-all has restarted. Sync with charm-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
            image = glance.images.create(name=image_name, is_public=True,
178
178
                                         disk_format='qcow2',
179
179
                                         container_format='bare', data=f)
 
180
        count = 1
 
181
        status = image.status
 
182
        while status != 'active' and count < 10:
 
183
            time.sleep(3)
 
184
            image = glance.images.get(image.id)
 
185
            status = image.status
 
186
            self.log.debug('image status: {}'.format(status))
 
187
            count += 1
 
188
 
 
189
        if status != 'active':
 
190
            self.log.error('image creation timed out')
 
191
            return None
 
192
 
180
193
        return image
181
194
 
182
195
    def delete_image(self, glance, image):
183
196
        """Delete the specified image."""
 
197
        num_before = len(list(glance.images.list()))
184
198
        glance.images.delete(image)
185
199
 
 
200
        count = 1
 
201
        num_after = len(list(glance.images.list()))
 
202
        while num_after != (num_before - 1) and count < 10:
 
203
            time.sleep(3)
 
204
            num_after = len(list(glance.images.list()))
 
205
            self.log.debug('number of images: {}'.format(num_after))
 
206
            count += 1
 
207
 
 
208
        if num_after != (num_before - 1):
 
209
            self.log.error('image deletion timed out')
 
210
            return False
 
211
 
 
212
        return True
 
213
 
186
214
    def create_instance(self, nova, image_name, instance_name, flavor):
187
215
        """Create the specified instance."""
188
216
        image = nova.images.find(name=image_name)
199
227
            self.log.debug('instance status: {}'.format(status))
200
228
            count += 1
201
229
 
202
 
        if status == 'BUILD':
 
230
        if status != 'ACTIVE':
 
231
            self.log.error('instance creation timed out')
203
232
            return None
204
233
 
205
234
        return instance
206
235
 
207
236
    def delete_instance(self, nova, instance):
208
237
        """Delete the specified instance."""
 
238
        num_before = len(list(nova.servers.list()))
209
239
        nova.servers.delete(instance)
 
240
 
 
241
        count = 1
 
242
        num_after = len(list(nova.servers.list()))
 
243
        while num_after != (num_before - 1) and count < 10:
 
244
            time.sleep(3)
 
245
            num_after = len(list(nova.servers.list()))
 
246
            self.log.debug('number of instances: {}'.format(num_after))
 
247
            count += 1
 
248
 
 
249
        if num_after != (num_before - 1):
 
250
            self.log.error('instance deletion timed out')
 
251
            return False
 
252
 
 
253
        return True