functional tests: rework image register test
Change-Id: Ic2e948467fdbf20e5f5c5d784ab11e508c3e4ad7
This commit is contained in:
parent
344a77b96f
commit
08ad73786d
|
@ -13,9 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from tempest_lib.common.utils import data_utils
|
||||
import testtools
|
||||
|
||||
|
@ -308,50 +305,24 @@ class ImageTest(base.EC2TestCase):
|
|||
|
||||
class ImageRegisterTest(base.EC2TestCase):
|
||||
|
||||
valid_image_state = set(('available', 'pending', 'failed'))
|
||||
|
||||
@classmethod
|
||||
@base.safe_setup
|
||||
def setUpClass(cls):
|
||||
super(ImageRegisterTest, cls).setUpClass()
|
||||
cls.materials_path = CONF.aws.s3_materials_path
|
||||
if not cls.materials_path:
|
||||
raise cls.skipException('Image materials are not ready')
|
||||
cls.image_location = CONF.aws.ami_image_location
|
||||
if not cls.image_location:
|
||||
raise cls.skipException('Image materials are not ready in S3')
|
||||
|
||||
cls.bucket_name = data_utils.rand_name("bucket")
|
||||
cls.ami_manifest = CONF.aws.ami_manifest
|
||||
cls.aki_manifest = CONF.aws.aki_manifest
|
||||
cls.ari_manifest = CONF.aws.ari_manifest
|
||||
|
||||
cls.ami_path = cls.materials_path + os.sep + cls.ami_manifest
|
||||
cls.aki_path = cls.materials_path + os.sep + cls.aki_manifest
|
||||
cls.ari_path = cls.materials_path + os.sep + cls.ari_manifest
|
||||
cls.s3_client.create_bucket(Bucket=cls.bucket_name, ACL='public-read')
|
||||
cls.addResourceCleanUpStatic(cls.s3_client.delete_bucket,
|
||||
Bucket=cls.bucket_name)
|
||||
cls._s3_upload_dir(cls.bucket_name, cls.materials_path)
|
||||
|
||||
@classmethod
|
||||
def _s3_upload_dir(cls, bucket_name, path, prefix=""):
|
||||
for root, _, files in os.walk(path):
|
||||
for file in files:
|
||||
source = root + os.sep + file
|
||||
target = re.sub("^" + re.escape(path) + "?/", prefix, source)
|
||||
if os.sep != '/':
|
||||
target = re.sub(re.escape(os.sep), '/', target)
|
||||
hfile = open(source, 'r')
|
||||
cls.s3_client.put_object(Bucket=bucket_name, Key=target,
|
||||
Body=hfile, ACL='public-read')
|
||||
|
||||
valid_image_state = set(('available', 'pending', 'failed'))
|
||||
|
||||
def _register_get_deregister_image(self, image_type, manifest):
|
||||
image_name = data_utils.rand_name(image_type + "-name")
|
||||
image_location = self.bucket_name + "/" + manifest
|
||||
def test_register_get_deregister_ami_image(self):
|
||||
image_name = data_utils.rand_name("ami-name")
|
||||
data = self.client.register_image(
|
||||
Name=image_name, ImageLocation=image_location)
|
||||
Name=image_name, ImageLocation=self.image_location)
|
||||
image_id = data['ImageId']
|
||||
image_clean = self.addResourceCleanUp(self.client.deregister_image,
|
||||
ImageId=image_id)
|
||||
self.assertEqual(image_id[0:3], image_type)
|
||||
self.assertEqual(image_id[0:3], "ami")
|
||||
|
||||
data = self.client.describe_images(ImageIds=[image_id])
|
||||
self.assertEqual(1, len(data['Images']))
|
||||
|
@ -367,12 +338,3 @@ class ImageRegisterTest(base.EC2TestCase):
|
|||
self.client.describe_images,
|
||||
ImageIds=[image_id])
|
||||
self.cancelResourceCleanUp(image_clean)
|
||||
|
||||
def test_register_get_deregister_ami_image(self):
|
||||
self._register_get_deregister_image('ami', self.ami_manifest)
|
||||
|
||||
def test_register_get_deregister_aki_image(self):
|
||||
self._register_get_deregister_image('aki', self.aki_manifest)
|
||||
|
||||
def test_register_get_deregister_ari_image(self):
|
||||
self._register_get_deregister_image('ari', self.ari_manifest)
|
||||
|
|
15
config.py
15
config.py
|
@ -13,8 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import logging as std_logging
|
||||
import os
|
||||
|
||||
|
@ -86,18 +84,9 @@ AWSGroup = [
|
|||
cfg.BoolOpt('run_long_tests',
|
||||
default=False,
|
||||
help='Will run all long tests also.'),
|
||||
cfg.StrOpt('s3_materials_path',
|
||||
cfg.StrOpt('ami_image_location',
|
||||
default=None,
|
||||
help="S3 Materials Path"),
|
||||
cfg.StrOpt('ari_manifest',
|
||||
default=None,
|
||||
help="ARI Ramdisk Image manifest"),
|
||||
cfg.StrOpt('ami_manifest',
|
||||
default=None,
|
||||
help="AMI Machine Image manifest"),
|
||||
cfg.StrOpt('aki_manifest',
|
||||
default=None,
|
||||
help="AKI Kernel Image manifest"),
|
||||
help="S3 URL with manifest of AMI Machine Image."),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
import base64
|
||||
import os
|
||||
|
||||
from oslo_log import log
|
||||
import six
|
||||
|
@ -132,3 +133,26 @@ class InstancesTest(scenario_base.BaseScenarioTest):
|
|||
|
||||
waiter = base.EC2Waiter(_compare_console_output)
|
||||
waiter.wait_no_exception()
|
||||
|
||||
@testtools.skipUnless(CONF.aws.ami_image_location, "Image is absent in S3")
|
||||
def test_run_and_ping_registered_image(self):
|
||||
image_name = data_utils.rand_name("ami-name")
|
||||
data = self.client.register_image(
|
||||
Name=image_name, ImageLocation=CONF.aws.ami_image_location)
|
||||
image_id = data['ImageId']
|
||||
self.addResourceCleanUp(self.client.deregister_image, ImageId=image_id)
|
||||
self.get_image_waiter().wait_available(image_id)
|
||||
|
||||
# launch this image
|
||||
sec_group_name = self.create_standard_security_group()
|
||||
instance_id = self.run_instance(ImageId=image_id,
|
||||
SecurityGroups=[sec_group_name])
|
||||
|
||||
ip_address = self.get_instance_ip(instance_id)
|
||||
|
||||
def _ping():
|
||||
response = os.system("ping -c 1 " + ip_address + " > /dev/null")
|
||||
self.assertEqual(0, response)
|
||||
|
||||
waiter = base.EC2Waiter(_ping)
|
||||
waiter.wait_no_exception()
|
||||
|
|
Loading…
Reference in New Issue