blob: 99a202373573a434df48fc83020a1e7713b4e456 [file] [log] [blame]
Joe Gordonb5e10cd2013-07-10 15:51:12 +00001# Copyright 2013 NEC Corporation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
Yair Fried6cad1362014-11-24 17:56:56 +020015from tempest_lib import exceptions
Joe Gordonb5e10cd2013-07-10 15:51:12 +000016
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
Matthew Treinish6c072292014-01-29 19:15:52 +000018from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040019from tempest.openstack.common import log as logging
Joe Gordonb5e10cd2013-07-10 15:51:12 +000020from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090021from tempest import test
Joe Gordonb5e10cd2013-07-10 15:51:12 +000022
Matthew Treinish6c072292014-01-29 19:15:52 +000023CONF = config.CONF
24
Joe Gordonb5e10cd2013-07-10 15:51:12 +000025
26LOG = logging.getLogger(__name__)
27
28
Ghanshyamaa4511e2014-09-08 10:37:50 +090029class TestLargeOpsScenario(manager.ScenarioTest):
Joe Gordonb5e10cd2013-07-10 15:51:12 +000030
31 """
32 Test large operations.
33
34 This test below:
Joe Gordonfa29a622014-04-17 13:21:44 -070035 * Spin up multiple instances in one nova call, and repeat three times
Joe Gordonb5e10cd2013-07-10 15:51:12 +000036 * as a regular user
37 * TODO: same thing for cinder
38
39 """
40
Sylvain Afchain92064772014-01-16 02:45:57 +010041 @classmethod
Andrea Frittoliac20b5e2014-09-15 13:31:14 +010042 def resource_setup(cls):
Yair Friedc1f1e832014-09-21 12:57:32 +030043 if CONF.scenario.large_ops_number < 1:
44 raise cls.skipException("large_ops_number not set to multiple "
45 "instances")
Sylvain Afchain92064772014-01-16 02:45:57 +010046 cls.set_network_resources()
Andrea Frittoliac20b5e2014-09-15 13:31:14 +010047 super(TestLargeOpsScenario, cls).resource_setup()
Yair Fried6cad1362014-11-24 17:56:56 +020048 # list of cleanup calls to be executed in reverse order
49 cls._cleanup_resources = []
50
51 @classmethod
52 def resource_cleanup(cls):
53 while cls._cleanup_resources:
54 function, args, kwargs = cls._cleanup_resources.pop(-1)
55 try:
56 function(*args, **kwargs)
57 except exceptions.NotFound:
58 pass
59 super(TestLargeOpsScenario, cls).resource_cleanup()
60
61 @classmethod
62 def addCleanupClass(cls, function, *arguments, **keywordArguments):
63 cls._cleanup_resources.append((function, arguments, keywordArguments))
Sylvain Afchain92064772014-01-16 02:45:57 +010064
Joe Gordonb5e10cd2013-07-10 15:51:12 +000065 def _wait_for_server_status(self, status):
66 for server in self.servers:
Joe Gordon6286a6a2014-03-05 16:35:03 -080067 # Make sure nova list keeps working throughout the build process
68 self.servers_client.list_servers()
Ghanshyamaa4511e2014-09-08 10:37:50 +090069 self.servers_client.wait_for_server_status(server['id'], status)
Joe Gordonb5e10cd2013-07-10 15:51:12 +000070
Joe Gordonb5e10cd2013-07-10 15:51:12 +000071 def nova_boot(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090072 name = data_utils.rand_name('scenario-server-')
Matthew Treinish6c072292014-01-29 19:15:52 +000073 flavor_id = CONF.compute.flavor_ref
Yair Fried6cad1362014-11-24 17:56:56 +020074 # Explicitly create secgroup to avoid cleanup at the end of testcases.
75 # Since no traffic is tested, we don't need to actually add rules to
76 # secgroup
David Kranz9964b4e2015-02-06 15:45:29 -050077 secgroup = self.security_groups_client.create_security_group(
Yair Fried6cad1362014-11-24 17:56:56 +020078 'secgroup-%s' % name, 'secgroup-desc-%s' % name)
79 self.addCleanupClass(self.security_groups_client.delete_security_group,
80 secgroup['id'])
81
Ghanshyamaa4511e2014-09-08 10:37:50 +090082 self.servers_client.create_server(
83 name,
84 self.image,
85 flavor_id,
Matthew Treinish6c072292014-01-29 19:15:52 +000086 min_count=CONF.scenario.large_ops_number,
Ken'ichi Ohmichi1b3461e2014-12-02 03:41:07 +000087 security_groups=[{'name': secgroup['name']}])
Joe Gordonb5e10cd2013-07-10 15:51:12 +000088 # needed because of bug 1199788
Ghanshyamaa4511e2014-09-08 10:37:50 +090089 params = {'name': name}
90 _, server_list = self.servers_client.list_servers(params)
91 self.servers = server_list['servers']
Joe Gordona3219652013-10-09 15:23:11 -070092 for server in self.servers:
Matthew Treinishb7144eb2013-12-13 22:57:35 +000093 # after deleting all servers - wait for all servers to clear
94 # before cleanup continues
Yair Fried6cad1362014-11-24 17:56:56 +020095 self.addCleanupClass(self.servers_client.
96 wait_for_server_termination,
97 server['id'])
Matthew Treinishb7144eb2013-12-13 22:57:35 +000098 for server in self.servers:
Yair Fried6cad1362014-11-24 17:56:56 +020099 self.addCleanupClass(self.servers_client.delete_server,
100 server['id'])
Joe Gordonb5e10cd2013-07-10 15:51:12 +0000101 self._wait_for_server_status('ACTIVE')
102
Joe Gordonb7f37cc2014-05-09 13:30:40 -0700103 def _large_ops_scenario(self):
Joe Gordonb5e10cd2013-07-10 15:51:12 +0000104 self.glance_image_create()
105 self.nova_boot()
Joe Gordonb7f37cc2014-05-09 13:30:40 -0700106
107 @test.services('compute', 'image')
108 def test_large_ops_scenario_1(self):
109 self._large_ops_scenario()
110
111 @test.services('compute', 'image')
112 def test_large_ops_scenario_2(self):
113 self._large_ops_scenario()
114
115 @test.services('compute', 'image')
116 def test_large_ops_scenario_3(self):
117 self._large_ops_scenario()