add ubuntu image for testing and port instance_restart test

Change-Id: If19ed3342bdaf6b256a9f5f3a2da6a4bd003e2e3
This commit is contained in:
Andrey Pavlov 2015-05-05 21:07:41 +03:00
parent f3848bfcab
commit 8b13458b19
4 changed files with 112 additions and 1 deletions

View File

@ -30,6 +30,20 @@ if [[ ! -f $TEST_CONFIG_DIR/$TEST_CONFIG ]]; then
exit 1
fi
# prepare flavor
nova flavor-create --is-public True m1.ec2api 16 512 0 1
REGULAR_IMAGE_URL="https://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-i386-disk1.img"
REGULAR_IMAGE_FNAME="precise"
glance image-create --disk-format raw --container-format bare --is-public True --name $REGULAR_IMAGE_FNAME --location $REGULAR_IMAGE_URL
if [[ "$?" -ne "0" ]]; then
echo "Creation precise image failed"
exit 1
fi
sleep 60
# find this image
image_id_ubuntu=$(euca-describe-images --show-empty-fields | grep "precise" | grep "ami-" | head -n 1 | awk '{print $2}')
# create separate user/project
tenant_name="tenant-$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8)"
eval $(openstack project create -f shell -c id $tenant_name)
@ -109,7 +123,10 @@ ec2_url = $EC2_URL
aws_access = $EC2_ACCESS_KEY
aws_secret = $EC2_SECRET_KEY
image_id = $image_id
image_id_ubuntu = $image_id_ubuntu
ebs_image_id = $ebs_image_id
build_timeout = 300
instance_type = m1.ec2api
EOF"
# local workaround for LP#1439819. it doesn't work in gating because glance check isatty property.

View File

@ -35,6 +35,7 @@ logging.getLogger('botocore').setLevel(logging.INFO)
logging.getLogger(
'botocore.vendored.requests.packages.urllib3.connectionpool'
).setLevel(logging.WARNING)
logging.getLogger('paramiko.transport').setLevel(logging.WARNING)
class EC2Waiter(object):

View File

@ -58,13 +58,19 @@ AWSGroup = [
help="Instance type"),
cfg.StrOpt('image_id',
default=None,
help="Image ID for instance running"),
help="Image ID for instance running(can be cirros)"),
cfg.StrOpt('ebs_image_id',
default=None,
help="EBS Image ID for testing snapshots, volumes, instances"),
cfg.StrOpt('image_user',
default='cirros',
help="User for sshing into instance based on configured image"),
cfg.StrOpt('image_id_ubuntu',
default=None,
help="Fully functional image ID for instance running"),
cfg.StrOpt('image_user_ubuntu',
default='ubuntu',
help="User for sshing into instance based on configured image"),
cfg.BoolOpt('run_incompatible_tests',
default=False,
help='Will run all tests plus incompatible with Amazon.'),

View File

@ -0,0 +1,87 @@
# Copyright 2015 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log
from tempest_lib.common import ssh
from tempest_lib.common.utils import data_utils
from ec2api.tests.functional import base
from ec2api.tests.functional import config
from ec2api.tests.functional.scenario import base as scenario_base
CONF = config.CONF
LOG = log.getLogger(__name__)
class InstanceRestartTest(scenario_base.BaseScenarioTest):
@classmethod
@base.safe_setup
def setUpClass(cls):
super(InstanceRestartTest, cls).setUpClass()
if not CONF.aws.image_id_ubuntu:
raise cls.skipException('ubuntu image_id does not provided')
cls.zone = CONF.aws.aws_zone
def test_stop_start_instance(self):
key_name = data_utils.rand_name('testkey')
pkey = self.create_key_pair(key_name)
sec_group_name = self.create_standard_security_group()
instance_id = self.run_instance(KeyName=key_name,
ImageId=CONF.aws.image_id_ubuntu,
SecurityGroups=[sec_group_name])
ip_address = self.get_instance_ip(instance_id)
ssh_client = ssh.Client(ip_address, CONF.aws.image_user_ubuntu,
pkey=pkey)
ssh_client.exec_command('last -x')
self.client.stop_instances(InstanceIds=[instance_id])
self.get_instance_waiter().wait_available(instance_id,
final_set=('stopped'))
self.client.start_instances(InstanceIds=[instance_id])
self.get_instance_waiter().wait_available(instance_id,
final_set=('running'))
data = ssh_client.exec_command('last -x')
self.assertIn("shutdown", data)
def test_reboot_instance(self):
key_name = data_utils.rand_name('testkey')
pkey = self.create_key_pair(key_name)
sec_group_name = self.create_standard_security_group()
instance_id = self.run_instance(KeyName=key_name,
ImageId=CONF.aws.image_id_ubuntu,
SecurityGroups=[sec_group_name])
ip_address = self.get_instance_ip(instance_id)
ssh_client = ssh.Client(ip_address, CONF.aws.image_user_ubuntu,
pkey=pkey)
last_lines = ssh_client.exec_command('last -x').split('\n')
self.client.reboot_instances(InstanceIds=[instance_id])
def _last_state():
current = ssh_client.exec_command('last -x').split('\n')
if len(current) > len(last_lines):
return
raise Exception()
waiter = base.EC2Waiter(_last_state)
waiter.wait_no_exception()
data = ssh_client.exec_command('last -x')
self.assertIn("shutdown", data)