Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [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 | |
Attila Fazekas | c7eb6cc | 2013-07-04 10:25:54 +0200 | [diff] [blame] | 18 | from tempest.common import log as logging |
Masayuki Igawa | 73d9f3a | 2013-05-24 10:30:01 +0900 | [diff] [blame] | 19 | |
| 20 | from tempest.common.utils.data_utils import rand_name |
| 21 | from tempest.common.utils.linux.remote_client import RemoteClient |
| 22 | from tempest.scenario import manager |
| 23 | |
| 24 | |
| 25 | LOG = logging.getLogger(__name__) |
| 26 | |
| 27 | |
| 28 | class TestMinimumBasicScenario(manager.OfficialClientTest): |
| 29 | |
| 30 | """ |
| 31 | This is a basic minimum scenario test. |
| 32 | |
| 33 | This test below: |
| 34 | * across the multiple components |
| 35 | * as a regular user |
| 36 | * with and without optional parameters |
| 37 | * check command outputs |
| 38 | |
| 39 | """ |
| 40 | |
| 41 | def _wait_for_server_status(self, status): |
| 42 | server_id = self.server.id |
| 43 | self.status_timeout( |
| 44 | self.compute_client.servers, server_id, status) |
| 45 | |
| 46 | def _wait_for_volume_status(self, status): |
| 47 | volume_id = self.volume.id |
| 48 | self.status_timeout( |
| 49 | self.volume_client.volumes, volume_id, status) |
| 50 | |
| 51 | def _image_create(self, name, fmt, path, properties={}): |
| 52 | name = rand_name('%s-' % name) |
| 53 | image_file = open(path, 'rb') |
| 54 | self.addCleanup(image_file.close) |
| 55 | params = { |
| 56 | 'name': name, |
| 57 | 'container_format': fmt, |
| 58 | 'disk_format': fmt, |
| 59 | 'is_public': 'True', |
| 60 | } |
| 61 | params.update(properties) |
| 62 | image = self.image_client.images.create(**params) |
| 63 | self.addCleanup(self.image_client.images.delete, image) |
| 64 | self.assertEqual("queued", image.status) |
| 65 | image.update(data=image_file) |
| 66 | return image.id |
| 67 | |
| 68 | def glance_image_create(self): |
| 69 | aki_img_path = self.config.scenario.img_dir + "/" + \ |
| 70 | self.config.scenario.aki_img_file |
| 71 | ari_img_path = self.config.scenario.img_dir + "/" + \ |
| 72 | self.config.scenario.ari_img_file |
| 73 | ami_img_path = self.config.scenario.img_dir + "/" + \ |
| 74 | self.config.scenario.ami_img_file |
| 75 | LOG.debug("paths: ami: %s, ari: %s, aki: %s" |
| 76 | % (ami_img_path, ari_img_path, aki_img_path)) |
| 77 | kernel_id = self._image_create('scenario-aki', 'aki', aki_img_path) |
| 78 | ramdisk_id = self._image_create('scenario-ari', 'ari', ari_img_path) |
| 79 | properties = { |
| 80 | 'properties': {'kernel_id': kernel_id, 'ramdisk_id': ramdisk_id} |
| 81 | } |
| 82 | self.image = self._image_create('scenario-ami', 'ami', |
| 83 | path=ami_img_path, |
| 84 | properties=properties) |
| 85 | |
| 86 | def nova_keypair_add(self): |
| 87 | name = rand_name('scenario-keypair-') |
| 88 | |
| 89 | self.keypair = self.compute_client.keypairs.create(name=name) |
| 90 | self.addCleanup(self.compute_client.keypairs.delete, self.keypair) |
| 91 | self.assertEqual(name, self.keypair.name) |
| 92 | |
| 93 | def nova_boot(self): |
| 94 | name = rand_name('scenario-server-') |
| 95 | client = self.compute_client |
| 96 | flavor_id = self.config.compute.flavor_ref |
| 97 | self.server = client.servers.create(name=name, image=self.image, |
| 98 | flavor=flavor_id, |
| 99 | key_name=self.keypair.name) |
| 100 | self.addCleanup(self.compute_client.servers.delete, self.server) |
| 101 | self.assertEqual(name, self.server.name) |
| 102 | self._wait_for_server_status('ACTIVE') |
| 103 | |
| 104 | def nova_list(self): |
| 105 | servers = self.compute_client.servers.list() |
| 106 | LOG.debug("server_list:%s" % servers) |
| 107 | self.assertTrue(self.server in servers) |
| 108 | |
| 109 | def nova_show(self): |
| 110 | got_server = self.compute_client.servers.get(self.server) |
| 111 | LOG.debug("got server:%s" % got_server) |
| 112 | self.assertEqual(self.server, got_server) |
| 113 | |
| 114 | def cinder_create(self): |
| 115 | name = rand_name('scenario-volume-') |
| 116 | LOG.debug("volume display-name:%s" % name) |
| 117 | self.volume = self.volume_client.volumes.create(size=1, |
| 118 | display_name=name) |
| 119 | LOG.debug("volume created:%s" % self.volume.display_name) |
| 120 | self._wait_for_volume_status('available') |
| 121 | |
| 122 | self.addCleanup(self.volume_client.volumes.delete, self.volume) |
| 123 | self.assertEqual(name, self.volume.display_name) |
| 124 | |
| 125 | def cinder_list(self): |
| 126 | volumes = self.volume_client.volumes.list() |
| 127 | self.assertTrue(self.volume in volumes) |
| 128 | |
| 129 | def cinder_show(self): |
| 130 | volume = self.volume_client.volumes.get(self.volume.id) |
| 131 | self.assertEqual(self.volume, volume) |
| 132 | |
| 133 | def nova_volume_attach(self): |
| 134 | attach_volume_client = self.compute_client.volumes.create_server_volume |
| 135 | volume = attach_volume_client(self.server.id, |
| 136 | self.volume.id, |
| 137 | '/dev/vdb') |
| 138 | self.assertEqual(self.volume.id, volume.id) |
| 139 | self._wait_for_volume_status('in-use') |
| 140 | |
| 141 | def nova_reboot(self): |
| 142 | self.server.reboot() |
| 143 | self._wait_for_server_status('ACTIVE') |
| 144 | |
| 145 | def nova_floating_ip_create(self): |
| 146 | self.floating_ip = self.compute_client.floating_ips.create() |
| 147 | self.addCleanup(self.floating_ip.delete) |
| 148 | |
| 149 | def nova_floating_ip_add(self): |
| 150 | self.server.add_floating_ip(self.floating_ip) |
| 151 | |
| 152 | def nova_security_group_rule_create(self): |
| 153 | sgs = self.compute_client.security_groups.list() |
| 154 | for sg in sgs: |
| 155 | if sg.name == 'default': |
| 156 | secgroup = sg |
| 157 | |
| 158 | ruleset = { |
| 159 | # ssh |
| 160 | 'ip_protocol': 'tcp', |
| 161 | 'from_port': 22, |
| 162 | 'to_port': 22, |
| 163 | 'cidr': '0.0.0.0/0', |
| 164 | 'group_id': None |
| 165 | } |
| 166 | sg_rule = self.compute_client.security_group_rules.create(secgroup.id, |
| 167 | **ruleset) |
| 168 | self.addCleanup(self.compute_client.security_group_rules.delete, |
| 169 | sg_rule.id) |
| 170 | |
| 171 | def ssh_to_server(self): |
| 172 | username = self.config.scenario.ssh_user |
| 173 | self.linux_client = RemoteClient(self.floating_ip.ip, |
| 174 | username, |
| 175 | pkey=self.keypair.private_key) |
| 176 | |
| 177 | def check_partitions(self): |
| 178 | partitions = self.linux_client.get_partitions() |
| 179 | self.assertEqual(1, partitions.count('vdb')) |
| 180 | |
| 181 | def nova_volume_detach(self): |
| 182 | detach_volume_client = self.compute_client.volumes.delete_server_volume |
| 183 | detach_volume_client(self.server.id, self.volume.id) |
| 184 | self._wait_for_volume_status('available') |
| 185 | |
| 186 | volume = self.volume_client.volumes.get(self.volume.id) |
| 187 | self.assertEqual('available', volume.status) |
| 188 | |
| 189 | def test_minimum_basic_scenario(self): |
| 190 | self.glance_image_create() |
| 191 | self.nova_keypair_add() |
| 192 | self.nova_boot() |
| 193 | self.nova_list() |
| 194 | self.nova_show() |
| 195 | self.cinder_create() |
| 196 | self.cinder_list() |
| 197 | self.cinder_show() |
| 198 | self.nova_volume_attach() |
| 199 | self.cinder_show() |
| 200 | self.nova_reboot() |
| 201 | |
| 202 | self.nova_floating_ip_create() |
| 203 | self.nova_floating_ip_add() |
| 204 | self.nova_security_group_rule_create() |
| 205 | self.ssh_to_server() |
| 206 | self.check_partitions() |
| 207 | |
| 208 | self.nova_volume_detach() |