blob: 846e0cce2e01168fb0de4d7ad62c40752e9dc1b2 [file] [log] [blame]
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +09001# Copyright 2013 NEC Corporation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Masayuki Igawa259c1132013-10-31 17:48:44 +090016from tempest.common.utils import data_utils
Matthew Treinish6c072292014-01-29 19:15:52 +000017from tempest import config
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040018from tempest.openstack.common import log as logging
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090019from tempest.scenario import manager
Matthew Treinish2153ec02013-09-09 20:57:30 +000020from tempest.test import services
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090021
Matthew Treinish6c072292014-01-29 19:15:52 +000022CONF = config.CONF
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090023
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={}):
Masayuki Igawa259c1132013-10-31 17:48:44 +090051 name = data_utils.rand_name('%s-' % name)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090052 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):
Matthew Treinish6c072292014-01-29 19:15:52 +000068 aki_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.aki_img_file
69 ari_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.ari_img_file
70 ami_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.ami_img_file
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090071 LOG.debug("paths: ami: %s, ari: %s, aki: %s"
72 % (ami_img_path, ari_img_path, aki_img_path))
73 kernel_id = self._image_create('scenario-aki', 'aki', aki_img_path)
74 ramdisk_id = self._image_create('scenario-ari', 'ari', ari_img_path)
75 properties = {
76 'properties': {'kernel_id': kernel_id, 'ramdisk_id': ramdisk_id}
77 }
78 self.image = self._image_create('scenario-ami', 'ami',
79 path=ami_img_path,
80 properties=properties)
81
82 def nova_keypair_add(self):
Ken'ichi Ohmichi599d1b82013-08-19 18:48:37 +090083 self.keypair = self.create_keypair()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090084
85 def nova_boot(self):
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090086 create_kwargs = {'key_name': self.keypair.name}
Giulio Fidente61cadca2013-09-24 18:33:37 +020087 self.server = self.create_server(image=self.image,
Ken'ichi Ohmichi61f272b2013-08-15 15:58:53 +090088 create_kwargs=create_kwargs)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090089
90 def nova_list(self):
91 servers = self.compute_client.servers.list()
92 LOG.debug("server_list:%s" % servers)
Attila Fazekase191cb12013-07-29 06:41:52 +020093 self.assertIn(self.server, servers)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +090094
95 def nova_show(self):
96 got_server = self.compute_client.servers.get(self.server)
97 LOG.debug("got server:%s" % got_server)
98 self.assertEqual(self.server, got_server)
99
100 def cinder_create(self):
Ken'ichi Ohmichi70672df2013-08-19 18:35:19 +0900101 self.volume = self.create_volume()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900102
103 def cinder_list(self):
104 volumes = self.volume_client.volumes.list()
Attila Fazekase191cb12013-07-29 06:41:52 +0200105 self.assertIn(self.volume, volumes)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900106
107 def cinder_show(self):
108 volume = self.volume_client.volumes.get(self.volume.id)
109 self.assertEqual(self.volume, volume)
110
111 def nova_volume_attach(self):
112 attach_volume_client = self.compute_client.volumes.create_server_volume
113 volume = attach_volume_client(self.server.id,
114 self.volume.id,
115 '/dev/vdb')
116 self.assertEqual(self.volume.id, volume.id)
117 self._wait_for_volume_status('in-use')
118
119 def nova_reboot(self):
120 self.server.reboot()
121 self._wait_for_server_status('ACTIVE')
122
123 def nova_floating_ip_create(self):
124 self.floating_ip = self.compute_client.floating_ips.create()
125 self.addCleanup(self.floating_ip.delete)
126
127 def nova_floating_ip_add(self):
128 self.server.add_floating_ip(self.floating_ip)
129
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900130 def ssh_to_server(self):
Nachi Ueno95b41282014-01-15 06:54:21 -0800131 try:
132 self.linux_client = self.get_remote_client(self.floating_ip.ip)
133 except Exception:
134 LOG.exception('ssh to server failed')
135 self._log_console_output()
136 raise
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900137
138 def check_partitions(self):
139 partitions = self.linux_client.get_partitions()
140 self.assertEqual(1, partitions.count('vdb'))
141
142 def nova_volume_detach(self):
143 detach_volume_client = self.compute_client.volumes.delete_server_volume
144 detach_volume_client(self.server.id, self.volume.id)
145 self._wait_for_volume_status('available')
146
147 volume = self.volume_client.volumes.get(self.volume.id)
148 self.assertEqual('available', volume.status)
149
Matthew Treinish2153ec02013-09-09 20:57:30 +0000150 @services('compute', 'volume', 'image', 'network')
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900151 def test_minimum_basic_scenario(self):
152 self.glance_image_create()
153 self.nova_keypair_add()
154 self.nova_boot()
155 self.nova_list()
156 self.nova_show()
157 self.cinder_create()
158 self.cinder_list()
159 self.cinder_show()
160 self.nova_volume_attach()
john-griffith5462b332013-12-13 10:04:43 -0500161 self.addCleanup(self.nova_volume_detach)
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900162 self.cinder_show()
163 self.nova_reboot()
164
165 self.nova_floating_ip_create()
166 self.nova_floating_ip_add()
Yair Friedeb69f3f2013-10-10 13:18:16 +0300167 self._create_loginable_secgroup_rule_nova()
Masayuki Igawa73d9f3a2013-05-24 10:30:01 +0900168 self.ssh_to_server()
169 self.check_partitions()