Skip to content

Commit

Permalink
Ensure functional tests clean up their images
Browse files Browse the repository at this point in the history
Fixes bug 903887

Change-Id: I8772cf39a7de42b31c65f0b5dfb093693d38751a
  • Loading branch information
Brian Waldon committed Dec 13, 2011
1 parent 5fc3d42 commit 105f1fc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
51 changes: 49 additions & 2 deletions glance/tests/functional/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ def test_get_head_simple_post(self):
self.assertEqual(data['properties']['arch'], "x86_64")
self.assertEqual(data['properties']['distro'], "Ubuntu")

# DELETE image
path = "http://%s:%d/v1/images/%s" % ("0.0.0.0", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(response.status, 200)

self.stop_servers()

@skip_if_disabled
Expand Down Expand Up @@ -392,6 +399,13 @@ def test_queued_process_flow(self):
self.assertEqual(data['images'][0]['disk_format'], None)
self.assertEqual(data['images'][0]['name'], "Image1")

# DELETE image
path = "http://%s:%d/v1/images/%s" % ("0.0.0.0", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(response.status, 200)

self.stop_servers()

@skip_if_disabled
Expand Down Expand Up @@ -642,6 +656,8 @@ def test_filtered_images(self):
self.assertEqual(response.status, 200)
self.assertEqual(content, '{"images": []}')

image_ids = []

# 1. POST /images with three public images, and one private image
# with various attributes
headers = {'Content-Type': 'application/octet-stream',
Expand All @@ -659,6 +675,7 @@ def test_filtered_images(self):
data = json.loads(content)
self.assertEqual(data['image']['properties']['pants'], "are on")
self.assertEqual(data['image']['is_public'], True)
image_ids.append(data['image']['id'])

headers = {'Content-Type': 'application/octet-stream',
'X-Image-Meta-Name': 'My Image!',
Expand All @@ -675,6 +692,7 @@ def test_filtered_images(self):
data = json.loads(content)
self.assertEqual(data['image']['properties']['pants'], "are on")
self.assertEqual(data['image']['is_public'], True)
image_ids.append(data['image']['id'])

headers = {'Content-Type': 'application/octet-stream',
'X-Image-Meta-Name': 'My Image!',
Expand All @@ -691,6 +709,7 @@ def test_filtered_images(self):
data = json.loads(content)
self.assertEqual(data['image']['properties']['pants'], "are off")
self.assertEqual(data['image']['is_public'], True)
image_ids.append(data['image']['id'])

headers = {'Content-Type': 'application/octet-stream',
'X-Image-Meta-Name': 'My Private Image',
Expand All @@ -705,6 +724,7 @@ def test_filtered_images(self):
self.assertEqual(response.status, 201)
data = json.loads(content)
self.assertEqual(data['image']['is_public'], False)
image_ids.append(data['image']['id'])

# 2. GET /images
# Verify three public images
Expand Down Expand Up @@ -877,6 +897,14 @@ def test_filtered_images(self):
data = json.loads(content)
self.assertEqual(len(data['images']), 0)

# DELETE images
for image_id in image_ids:
path = "http://%s:%d/v1/images/%s" % ("0.0.0.0", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(response.status, 200)

self.stop_servers()

@skip_if_disabled
Expand All @@ -895,6 +923,8 @@ def test_limited_images(self):
self.assertEqual(response.status, 200)
self.assertEqual(content, '{"images": []}')

image_ids = []

# 1. POST /images with three public images with various attributes
headers = {'Content-Type': 'application/octet-stream',
'X-Image-Meta-Name': 'Image1',
Expand All @@ -903,6 +933,7 @@ def test_limited_images(self):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 201)
image_ids.append(json.loads(content)['image']['id'])

headers = {'Content-Type': 'application/octet-stream',
'X-Image-Meta-Name': 'Image2',
Expand All @@ -911,6 +942,7 @@ def test_limited_images(self):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 201)
image_ids.append(json.loads(content)['image']['id'])

headers = {'Content-Type': 'application/octet-stream',
'X-Image-Meta-Name': 'Image3',
Expand All @@ -919,6 +951,7 @@ def test_limited_images(self):
http = httplib2.Http()
response, content = http.request(path, 'POST', headers=headers)
self.assertEqual(response.status, 201)
image_ids.append(json.loads(content)['image']['id'])

# 2. GET /images with all images
path = "http://%s:%d/v1/images" % ("0.0.0.0", self.api_port)
Expand Down Expand Up @@ -961,8 +994,6 @@ def test_limited_images(self):
self.assertEqual(response.status, 200)
data = json.loads(content)['images']
self.assertEqual(len(data), 1)
print images
print data[0]
self.assertEqual(data[0]['id'], images[2]['id'])

# 6. GET /images/detail with marker and limit
Expand All @@ -976,6 +1007,14 @@ def test_limited_images(self):
self.assertEqual(len(data), 1)
self.assertEqual(data[0]['id'], images[2]['id'])

# DELETE images
for image_id in image_ids:
path = "http://%s:%d/v1/images/%s" % ("0.0.0.0", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(response.status, 200)

self.stop_servers()

@skip_if_disabled
Expand Down Expand Up @@ -1091,6 +1130,14 @@ def test_ordered_images(self):
data = json.loads(content)
self.assertEqual(len(data['images']), 0)

# DELETE images
for image_id in image_ids:
path = "http://%s:%d/v1/images/%s" % ("0.0.0.0", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(response.status, 200)

self.stop_servers()

@skip_if_disabled
Expand Down
11 changes: 8 additions & 3 deletions glance/tests/functional/test_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@
import httplib2
import json
import os
import tempfile
import unittest

from glance.common import crypt
import glance.store.swift # Needed to register driver for location
from glance.store.location import get_location_from_uri
from glance.tests.functional import test_api
from glance.tests.utils import execute, skip_if_disabled
from glance.tests.utils import skip_if_disabled

FIVE_KB = 5 * 1024
FIVE_MB = 5 * 1024 * 1024
Expand Down Expand Up @@ -402,6 +400,13 @@ def test_add_large_object_manifest_uneven_size(self):
self.assertEqual(hashlib.md5(content).hexdigest(),
hashlib.md5("*" * FIVE_MB).hexdigest())

# DELETE image
path = "http://%s:%d/v1/images/%s" % ("0.0.0.0", self.api_port,
image_id)
http = httplib2.Http()
response, content = http.request(path, 'DELETE')
self.assertEqual(response.status, 200)

self.stop_servers()

@skip_if_disabled
Expand Down

0 comments on commit 105f1fc

Please sign in to comment.