Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 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 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 18 | from tempest.common.utils.data_utils import rand_name |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 19 | from tempest.openstack.common import log as logging |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 20 | from tempest.scenario import manager |
Matthew Treinish | 2153ec0 | 2013-09-09 20:57:30 +0000 | [diff] [blame] | 21 | from tempest.test import services |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 22 | |
| 23 | LOG = logging.getLogger(__name__) |
| 24 | |
| 25 | |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 26 | class TestServerBasicOps(manager.OfficialClientTest): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 27 | |
| 28 | """ |
| 29 | This smoke test case follows this basic set of operations: |
| 30 | |
| 31 | * Create a keypair for use in launching an instance |
| 32 | * Create a security group to control network access in instance |
| 33 | * Add simple permissive rules to the security group |
| 34 | * Launch an instance |
| 35 | * Pause/unpause the instance |
| 36 | * Suspend/resume the instance |
| 37 | * Terminate the instance |
| 38 | """ |
| 39 | |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 40 | def add_keypair(self): |
| 41 | self.keypair = self.create_keypair() |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 42 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 43 | def create_security_group(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 44 | sg_name = rand_name('secgroup-smoke') |
| 45 | sg_desc = sg_name + " description" |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 46 | self.secgroup = self.compute_client.security_groups.create(sg_name, |
| 47 | sg_desc) |
Giulio Fidente | 92f7719 | 2013-08-26 17:13:28 +0200 | [diff] [blame] | 48 | self.assertEqual(self.secgroup.name, sg_name) |
| 49 | self.assertEqual(self.secgroup.description, sg_desc) |
| 50 | self.set_resource('secgroup', self.secgroup) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 51 | |
| 52 | # Add rules to the security group |
Ken'ichi Ohmichi | 3c1f519 | 2013-08-19 19:02:15 +0900 | [diff] [blame] | 53 | self.create_loginable_secgroup_rule(secgroup_id=self.secgroup.id) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 54 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 55 | def boot_instance(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 56 | create_kwargs = { |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 57 | 'key_name': self.keypair.id |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 58 | } |
Giulio Fidente | 61cadca | 2013-09-24 18:33:37 +0200 | [diff] [blame] | 59 | instance = self.create_server(create_kwargs=create_kwargs) |
Ken'ichi Ohmichi | 61f272b | 2013-08-15 15:58:53 +0900 | [diff] [blame] | 60 | self.set_resource('instance', instance) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 61 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 62 | def pause_server(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 63 | instance = self.get_resource('instance') |
| 64 | instance_id = instance.id |
| 65 | LOG.debug("Pausing instance %s. Current status: %s", |
| 66 | instance_id, instance.status) |
| 67 | instance.pause() |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 68 | self.status_timeout( |
| 69 | self.compute_client.servers, instance_id, 'PAUSED') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 70 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 71 | def unpause_server(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 72 | instance = self.get_resource('instance') |
| 73 | instance_id = instance.id |
| 74 | LOG.debug("Unpausing instance %s. Current status: %s", |
| 75 | instance_id, instance.status) |
| 76 | instance.unpause() |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 77 | self.status_timeout( |
| 78 | self.compute_client.servers, instance_id, 'ACTIVE') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 79 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 80 | def suspend_server(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 81 | instance = self.get_resource('instance') |
| 82 | instance_id = instance.id |
| 83 | LOG.debug("Suspending instance %s. Current status: %s", |
| 84 | instance_id, instance.status) |
| 85 | instance.suspend() |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 86 | self.status_timeout(self.compute_client.servers, |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 87 | instance_id, 'SUSPENDED') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 88 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 89 | def resume_server(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 90 | instance = self.get_resource('instance') |
| 91 | instance_id = instance.id |
| 92 | LOG.debug("Resuming instance %s. Current status: %s", |
| 93 | instance_id, instance.status) |
| 94 | instance.resume() |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 95 | self.status_timeout( |
| 96 | self.compute_client.servers, instance_id, 'ACTIVE') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 97 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 98 | def terminate_instance(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 99 | instance = self.get_resource('instance') |
| 100 | instance.delete() |
| 101 | self.remove_resource('instance') |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 102 | |
Matthew Treinish | 2153ec0 | 2013-09-09 20:57:30 +0000 | [diff] [blame] | 103 | @services('compute', 'network') |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 104 | def test_server_basicops(self): |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 105 | self.add_keypair() |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 106 | self.create_security_group() |
| 107 | self.boot_instance() |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 108 | self.pause_server() |
| 109 | self.unpause_server() |
| 110 | self.suspend_server() |
| 111 | self.resume_server() |
| 112 | self.terminate_instance() |