blob: 7f8d3e4feb527f6017186798e65fca0ab0170c9c [file] [log] [blame]
Joe Gordonb5e10cd2013-07-10 15:51:12 +00001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 NEC Corporation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Masayuki Igawa259c1132013-10-31 17:48:44 +090018from tempest.common.utils import data_utils
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
Matthew Treinish2153ec02013-09-09 20:57:30 +000021from tempest.test import services
Joe Gordonb5e10cd2013-07-10 15:51:12 +000022
23
24LOG = logging.getLogger(__name__)
25
26
Joe Gordon30684ef2013-10-08 17:09:09 -070027class TestLargeOpsScenario(manager.NetworkScenarioTest):
Joe Gordonb5e10cd2013-07-10 15:51:12 +000028
29 """
30 Test large operations.
31
32 This test below:
33 * Spin up multiple instances in one nova call
34 * as a regular user
35 * TODO: same thing for cinder
36
37 """
38
39 def _wait_for_server_status(self, status):
40 for server in self.servers:
41 self.status_timeout(
42 self.compute_client.servers, server.id, status)
43
44 def _wait_for_volume_status(self, status):
45 volume_id = self.volume.id
46 self.status_timeout(
47 self.volume_client.volumes, volume_id, status)
48
49 def _image_create(self, name, fmt, path, properties={}):
Masayuki Igawa259c1132013-10-31 17:48:44 +090050 name = data_utils.rand_name('%s-' % name)
Joe Gordonb5e10cd2013-07-10 15:51:12 +000051 image_file = open(path, 'rb')
52 self.addCleanup(image_file.close)
53 params = {
54 'name': name,
55 'container_format': fmt,
56 'disk_format': fmt,
57 'is_public': 'True',
58 }
59 params.update(properties)
60 image = self.image_client.images.create(**params)
61 self.addCleanup(self.image_client.images.delete, image)
62 self.assertEqual("queued", image.status)
63 image.update(data=image_file)
64 return image.id
65
66 def glance_image_create(self):
67 aki_img_path = self.config.scenario.img_dir + "/" + \
68 self.config.scenario.aki_img_file
69 ari_img_path = self.config.scenario.img_dir + "/" + \
70 self.config.scenario.ari_img_file
71 ami_img_path = self.config.scenario.img_dir + "/" + \
72 self.config.scenario.ami_img_file
73 LOG.debug("paths: ami: %s, ari: %s, aki: %s"
74 % (ami_img_path, ari_img_path, aki_img_path))
75 kernel_id = self._image_create('scenario-aki', 'aki', aki_img_path)
76 ramdisk_id = self._image_create('scenario-ari', 'ari', ari_img_path)
77 properties = {
78 'properties': {'kernel_id': kernel_id, 'ramdisk_id': ramdisk_id}
79 }
80 self.image = self._image_create('scenario-ami', 'ami',
81 path=ami_img_path,
82 properties=properties)
83
84 def nova_boot(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +090085 name = data_utils.rand_name('scenario-server-')
Joe Gordonb5e10cd2013-07-10 15:51:12 +000086 client = self.compute_client
87 flavor_id = self.config.compute.flavor_ref
Yair Friedeb69f3f2013-10-10 13:18:16 +030088 secgroup = self._create_security_group_nova()
Joe Gordonb5e10cd2013-07-10 15:51:12 +000089 self.servers = client.servers.create(
90 name=name, image=self.image,
91 flavor=flavor_id,
Joe Gordon30684ef2013-10-08 17:09:09 -070092 min_count=self.config.scenario.large_ops_number,
93 security_groups=[secgroup.name])
Joe Gordonb5e10cd2013-07-10 15:51:12 +000094 # needed because of bug 1199788
95 self.servers = [x for x in client.servers.list() if name in x.name]
Joe Gordona3219652013-10-09 15:23:11 -070096 for server in self.servers:
97 self.set_resource(server.name, server)
Joe Gordonb5e10cd2013-07-10 15:51:12 +000098 self._wait_for_server_status('ACTIVE')
99
Matthew Treinish2153ec02013-09-09 20:57:30 +0000100 @services('compute', 'image')
Joe Gordonb5e10cd2013-07-10 15:51:12 +0000101 def test_large_ops_scenario(self):
102 if self.config.scenario.large_ops_number < 1:
103 return
104 self.glance_image_create()
105 self.nova_boot()