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