| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 1 | # 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 Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 18 | from tempest.common.utils import data_utils | 
| Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 19 | from tempest.openstack.common import log as logging | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 20 | from tempest.scenario import manager | 
| Matthew Treinish | 2153ec0 | 2013-09-09 20:57:30 +0000 | [diff] [blame] | 21 | from tempest.test import services | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 22 |  | 
 | 23 |  | 
 | 24 | LOG = logging.getLogger(__name__) | 
 | 25 |  | 
 | 26 |  | 
| Joe Gordon | 30684ef | 2013-10-08 17:09:09 -0700 | [diff] [blame] | 27 | class TestLargeOpsScenario(manager.NetworkScenarioTest): | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 28 |  | 
 | 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 Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 50 |         name = data_utils.rand_name('%s-' % name) | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 51 |         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 Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 85 |         name = data_utils.rand_name('scenario-server-') | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 86 |         client = self.compute_client | 
 | 87 |         flavor_id = self.config.compute.flavor_ref | 
| Yair Fried | eb69f3f | 2013-10-10 13:18:16 +0300 | [diff] [blame] | 88 |         secgroup = self._create_security_group_nova() | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 89 |         self.servers = client.servers.create( | 
 | 90 |             name=name, image=self.image, | 
 | 91 |             flavor=flavor_id, | 
| Joe Gordon | 30684ef | 2013-10-08 17:09:09 -0700 | [diff] [blame] | 92 |             min_count=self.config.scenario.large_ops_number, | 
 | 93 |             security_groups=[secgroup.name]) | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 94 |         # needed because of bug 1199788 | 
 | 95 |         self.servers = [x for x in client.servers.list() if name in x.name] | 
| Joe Gordon | a321965 | 2013-10-09 15:23:11 -0700 | [diff] [blame] | 96 |         for server in self.servers: | 
 | 97 |             self.set_resource(server.name, server) | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 98 |         self._wait_for_server_status('ACTIVE') | 
 | 99 |  | 
| Matthew Treinish | 2153ec0 | 2013-09-09 20:57:30 +0000 | [diff] [blame] | 100 |     @services('compute', 'image') | 
| Joe Gordon | b5e10cd | 2013-07-10 15:51:12 +0000 | [diff] [blame] | 101 |     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() |