blob: 752ff6f97a5ac1302c2709bf52f50c8de93f069f [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
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040019from tempest.openstack.common import log as logging
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090020from tempest.scenario import manager
Matthew Treinish2153ec02013-09-09 20:57:30 +000021from tempest.test import services
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090022
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}
Giulio Fidente61cadca2013-09-24 18:33:37 +020090 self.server = self.create_server(image=self.image,
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090091 create_kwargs=create_kwargs)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090092
93 def nova_list(self):
94 servers = self.compute_client.servers.list()
95 LOG.debug("server_list:%s" % servers)
Attila Fazekase191cb12013-07-29 06:41:52 +020096 self.assertIn(self.server, servers)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090097
98 def nova_show(self):
99 got_server = self.compute_client.servers.get(self.server)
100 LOG.debug("got server:%s" % got_server)
101 self.assertEqual(self.server, got_server)
102
103 def cinder_create(self):
Ken'ichi Ohmichi70672df2013-08-19 18:35:19 +0900104 self.volume = self.create_volume()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900105
106 def cinder_list(self):
107 volumes = self.volume_client.volumes.list()
Attila Fazekase191cb12013-07-29 06:41:52 +0200108 self.assertIn(self.volume, volumes)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900109
110 def cinder_show(self):
111 volume = self.volume_client.volumes.get(self.volume.id)
112 self.assertEqual(self.volume, volume)
113
114 def nova_volume_attach(self):
115 attach_volume_client = self.compute_client.volumes.create_server_volume
116 volume = attach_volume_client(self.server.id,
117 self.volume.id,
118 '/dev/vdb')
119 self.assertEqual(self.volume.id, volume.id)
120 self._wait_for_volume_status('in-use')
121
122 def nova_reboot(self):
123 self.server.reboot()
124 self._wait_for_server_status('ACTIVE')
125
126 def nova_floating_ip_create(self):
127 self.floating_ip = self.compute_client.floating_ips.create()
128 self.addCleanup(self.floating_ip.delete)
129
130 def nova_floating_ip_add(self):
131 self.server.add_floating_ip(self.floating_ip)
132
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900133 def ssh_to_server(self):
Ken'ichi Ohmichib3aa9122013-08-22 23:27:25 +0900134 self.linux_client = self.get_remote_client(self.floating_ip.ip)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900135
136 def check_partitions(self):
137 partitions = self.linux_client.get_partitions()
138 self.assertEqual(1, partitions.count('vdb'))
139
140 def nova_volume_detach(self):
141 detach_volume_client = self.compute_client.volumes.delete_server_volume
142 detach_volume_client(self.server.id, self.volume.id)
143 self._wait_for_volume_status('available')
144
145 volume = self.volume_client.volumes.get(self.volume.id)
146 self.assertEqual('available', volume.status)
147
Matthew Treinish2153ec02013-09-09 20:57:30 +0000148 @services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900149 def test_minimum_basic_scenario(self):
150 self.glance_image_create()
151 self.nova_keypair_add()
152 self.nova_boot()
153 self.nova_list()
154 self.nova_show()
155 self.cinder_create()
156 self.cinder_list()
157 self.cinder_show()
158 self.nova_volume_attach()
159 self.cinder_show()
160 self.nova_reboot()
161
162 self.nova_floating_ip_create()
163 self.nova_floating_ip_add()
Ken'ichi Ohmichi3c1f5192013-08-19 19:02:15 +0900164 self.create_loginable_secgroup_rule()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900165 self.ssh_to_server()
166 self.check_partitions()
167
168 self.nova_volume_detach()