blob: 53d64351fdf68dd9b03f0f583d53fd44326a3aff [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):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090086 self.keypair = self.create_keypair()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090087
88 def nova_boot(self):
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090089 create_kwargs = {'key_name': self.keypair.name}
90 self.server = self.create_server(self.compute_client,
91 image=self.image,
92 create_kwargs=create_kwargs)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090093
94 def nova_list(self):
95 servers = self.compute_client.servers.list()
96 LOG.debug("server_list:%s" % servers)
Attila Fazekase191cb12013-07-29 06:41:52 +020097 self.assertIn(self.server, servers)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090098
99 def nova_show(self):
100 got_server = self.compute_client.servers.get(self.server)
101 LOG.debug("got server:%s" % got_server)
102 self.assertEqual(self.server, got_server)
103
104 def cinder_create(self):
105 name = rand_name('scenario-volume-')
106 LOG.debug("volume display-name:%s" % name)
107 self.volume = self.volume_client.volumes.create(size=1,
108 display_name=name)
109 LOG.debug("volume created:%s" % self.volume.display_name)
110 self._wait_for_volume_status('available')
111
112 self.addCleanup(self.volume_client.volumes.delete, self.volume)
113 self.assertEqual(name, self.volume.display_name)
114
115 def cinder_list(self):
116 volumes = self.volume_client.volumes.list()
Attila Fazekase191cb12013-07-29 06:41:52 +0200117 self.assertIn(self.volume, volumes)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900118
119 def cinder_show(self):
120 volume = self.volume_client.volumes.get(self.volume.id)
121 self.assertEqual(self.volume, volume)
122
123 def nova_volume_attach(self):
124 attach_volume_client = self.compute_client.volumes.create_server_volume
125 volume = attach_volume_client(self.server.id,
126 self.volume.id,
127 '/dev/vdb')
128 self.assertEqual(self.volume.id, volume.id)
129 self._wait_for_volume_status('in-use')
130
131 def nova_reboot(self):
132 self.server.reboot()
133 self._wait_for_server_status('ACTIVE')
134
135 def nova_floating_ip_create(self):
136 self.floating_ip = self.compute_client.floating_ips.create()
137 self.addCleanup(self.floating_ip.delete)
138
139 def nova_floating_ip_add(self):
140 self.server.add_floating_ip(self.floating_ip)
141
142 def nova_security_group_rule_create(self):
143 sgs = self.compute_client.security_groups.list()
144 for sg in sgs:
145 if sg.name == 'default':
146 secgroup = sg
147
148 ruleset = {
149 # ssh
150 'ip_protocol': 'tcp',
151 'from_port': 22,
152 'to_port': 22,
153 'cidr': '0.0.0.0/0',
154 'group_id': None
155 }
156 sg_rule = self.compute_client.security_group_rules.create(secgroup.id,
157 **ruleset)
158 self.addCleanup(self.compute_client.security_group_rules.delete,
159 sg_rule.id)
160
161 def ssh_to_server(self):
162 username = self.config.scenario.ssh_user
163 self.linux_client = RemoteClient(self.floating_ip.ip,
164 username,
165 pkey=self.keypair.private_key)
166
167 def check_partitions(self):
168 partitions = self.linux_client.get_partitions()
169 self.assertEqual(1, partitions.count('vdb'))
170
171 def nova_volume_detach(self):
172 detach_volume_client = self.compute_client.volumes.delete_server_volume
173 detach_volume_client(self.server.id, self.volume.id)
174 self._wait_for_volume_status('available')
175
176 volume = self.volume_client.volumes.get(self.volume.id)
177 self.assertEqual('available', volume.status)
178
179 def test_minimum_basic_scenario(self):
180 self.glance_image_create()
181 self.nova_keypair_add()
182 self.nova_boot()
183 self.nova_list()
184 self.nova_show()
185 self.cinder_create()
186 self.cinder_list()
187 self.cinder_show()
188 self.nova_volume_attach()
189 self.cinder_show()
190 self.nova_reboot()
191
192 self.nova_floating_ip_create()
193 self.nova_floating_ip_add()
194 self.nova_security_group_rule_create()
195 self.ssh_to_server()
196 self.check_partitions()
197
198 self.nova_volume_detach()