Merge "Add initial scenario test for Manila"

This commit is contained in:
Jenkins 2015-04-02 13:01:06 +00:00 committed by Gerrit Code Review
commit 02083bd11e
3 changed files with 282 additions and 0 deletions

View File

@ -85,5 +85,10 @@ cd $BASE/new/tempest
export MANILA_TEMPEST_CONCURRENCY=${MANILA_TEMPEST_CONCURRENCY:-12}
export MANILA_TESTS='tempest.api.share*'
if [[ "$JOB_NAME" =~ "scenario" ]]; then
echo "Set test set to scenario only"
MANILA_TESTS='tempest.scenario.*share*'
fi
echo "Running tempest manila test suites"
sudo -H -u jenkins tox -eall $MANILA_TESTS -- --concurrency=$MANILA_TEMPEST_CONCURRENCY

View File

@ -0,0 +1,157 @@
# Copyright 2015 Deutsche Telekom AG
# 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 # noqa
from tempest_lib.common.utils import data_utils # noqa
from tempest import clients_share
from tempest import config
from tempest.scenario import manager
CONF = config.CONF
LOG = log.getLogger(__name__)
class ShareScenarioTest(manager.NetworkScenarioTest):
"""Provide harness to do Manila scenario tests."""
@classmethod
def resource_setup(cls):
cls.set_network_resources()
super(ShareScenarioTest, cls).resource_setup()
os = clients_share.Manager(
credentials=cls.credentials()
)
# Manila clients
cls.shares_client = os.shares_client
cls.shares_admin_client = clients_share.AdminManager().shares_client
def _create_share(self, share_protocol=None, size=1, name=None,
snapshot_id=None, description=None, metadata=None,
share_network_id=None, share_type_id=None,
client=None, cleanup_in_class=True):
"""Create a share
:param share_protocol: NFS or CIFS
:param size: size in GB
:param name: name of the share (otherwise random)
:param snapshot_id: snapshot as basis for the share
:param description: description of the share
:param metadata: adds additional metadata
:param share_network_id: id of network to be used
:param share_type_id: type of the share to be created
:param client: client object
:param cleanup_in_class: default: True
:returns: a created share
"""
client = client or self.shares_client
description = description or "Tempest's share"
if not name:
name = data_utils.rand_name("manila-scenario")
share_network_id = share_network_id or client.share_network_id or None
metadata = metadata or {}
kwargs = {
'share_protocol': share_protocol,
'size': size,
'name': name,
'snapshot_id': snapshot_id,
'description': description,
'metadata': metadata,
'share_network_id': share_network_id,
'share_type_id': share_type_id,
}
resp, share = self.shares_client.create_share(**kwargs)
self.addCleanup(client.wait_for_resource_deletion,
share_id=share['id'])
self.addCleanup(client.delete_share,
share['id'])
self.assertEqual(resp['status'], '200')
client.wait_for_share_status(share['id'], 'available')
return share
def _wait_for_share_server_deletion(self, sn_id, client=None):
"""Wait for a share server to be deleted
:param sn_id: shared network id
:param client: client object
"""
client = client or self.shares_admin_client
resp, servers = client.list_share_servers(search_opts={
"share_network": sn_id})
if resp['status'] == '200':
for server in servers:
client.delete_share_server(server['id'])
client.wait_for_resource_deletion(server_id=server['id'])
def _create_share_network(self, client=None, **kwargs):
"""Create a share network
:param client: client object
:returns: a created share network
"""
client = client or self.shares_client
resp, sn = client.create_share_network(**kwargs)
self.addCleanup(client.wait_for_resource_deletion,
sn_id=sn['id'])
self.addCleanup(client.delete_share_network,
sn['id'])
self.addCleanup(self._wait_for_share_server_deletion,
sn['id'])
self.assertEqual(resp['status'], '200')
return sn
def _allow_access(self, share_id, client=None,
access_type="ip", access_to="0.0.0.0"):
"""Allow share access
:param share_id: id of the share
:param client: client object
:param access_type: "ip", "user" or "cert"
:param access_to
:returns: access object
"""
client = client or self.shares_client
resp, access = client.create_access_rule(share_id, access_type,
access_to)
self.assertEqual(resp['status'], '200')
client.wait_for_access_rule_status(share_id, access['id'], "active")
self.addCleanup(client.delete_access_rule,
share_id, access['id'])
return access
def _create_router_interface(self, subnet_id, client=None,
tenant_id=None, router_id=None):
"""Create a router interface
:param subnet_id: id of the subnet
:param client: client object
:param tenant_id
"""
if not client:
client = self.network_client
if not tenant_id:
tenant_id = client.tenant_id
if not router_id:
router_id = self._get_router()['id']
client.add_router_interface_with_subnet_id(router_id,
subnet_id)
self.addCleanup(client.remove_router_interface_with_subnet_id,
router_id, subnet_id)

View File

@ -0,0 +1,120 @@
# Copyright 2015 Deutsche Telekom AG
# 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 as logging # noqa
from tempest_lib.common.utils import data_utils # noqa
from tempest import config
from tempest.scenario import manager_share as manager
from tempest.scenario import utils as test_utils
from tempest import test
CONF = config.CONF
LOG = logging.getLogger(__name__)
load_tests = test_utils.load_tests_input_scenario_utils
class TestShareBasicOps(manager.ShareScenarioTest):
"""This smoke test case follows this basic set of operations:
* Create share network
* Create share
* Launch an instance
* Allow access
* Perform ssh to instance
* Terminate the instance
"""
protocol = "NFS"
def setUp(self):
super(TestShareBasicOps, self).setUp()
# Setup image and flavor the test instance
# Support both configured and injected values
if not hasattr(self, 'image_ref'):
self.image_ref = CONF.compute.image_ref
if not hasattr(self, 'flavor_ref'):
self.flavor_ref = CONF.compute.flavor_ref
self.image_utils = test_utils.ImageUtils()
if not self.image_utils.is_flavor_enough(self.flavor_ref,
self.image_ref):
raise self.skipException(
'{image} does not fit in {flavor}'.format(
image=self.image_ref, flavor=self.flavor_ref
)
)
self.ssh_user = CONF.compute.image_ssh_user
LOG.debug('Starting test for i:{image}, f:{flavor}. '
'user: {ssh_user}'.format(
image=self.image_ref, flavor=self.flavor_ref,
ssh_user=self.ssh_user))
def boot_instance(self, network):
self.keypair = self.create_keypair()
security_groups = [{'name': self.security_group['name']}]
create_kwargs = {
'networks': [
{'uuid': network['id']},
],
'key_name': self.keypair['name'],
'security_groups': security_groups,
}
self.instance = self.create_server(create_kwargs=create_kwargs)
def verify_ssh(self):
# Obtain a floating IP
floating_ip = self.floating_ips_client.create_floating_ip()
self.addCleanup(self.delete_wrapper,
self.floating_ips_client.delete_floating_ip,
floating_ip['id'])
# Attach a floating IP
self.floating_ips_client.associate_floating_ip_to_server(
floating_ip['ip'], self.instance['id'])
# Check ssh
ssh_client = self.get_remote_client(
server_or_ip=floating_ip['ip'],
username=self.ssh_user,
private_key=self.keypair['private_key'])
_, share = self.shares_client.get_share(self.share['id'])
server_ip = share['export_location'].split(":")[0]
ssh_client.exec_command("ping -c 1 %s" % server_ip)
def create_share_network(self):
self.net = self._create_network(namestart="manila-share")
self.subnet = self._create_subnet(network=self.net,
namestart="manila-share-sub")
router = self._get_router()
self._create_router_interface(subnet_id=self.subnet['id'],
router_id=router['id'])
self.share_net = self._create_share_network(
neutron_net_id=self.net['id'],
neutron_subnet_id=self.subnet['id'],
name=data_utils.rand_name("sn-name"))
def create_share(self, share_net_id):
self.share = self._create_share(share_protocol=self.protocol,
share_network_id=share_net_id)
@test.services('compute', 'network')
def test_server_basicops(self):
self.security_group = self._create_security_group()
self.create_share_network()
self.create_share(self.share_net['id'])
self.boot_instance(self.net)
self._allow_access(self.share['id'])
self.verify_ssh()
self.servers_client.delete_server(self.instance['id'])