Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 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 |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 21 | |
| 22 | LOG = logging.getLogger(__name__) |
| 23 | |
| 24 | |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 25 | class TestServerBasicOps(manager.OfficialClientTest): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 26 | |
| 27 | """ |
| 28 | This smoke test case follows this basic set of operations: |
| 29 | |
| 30 | * Create a keypair for use in launching an instance |
| 31 | * Create a security group to control network access in instance |
| 32 | * Add simple permissive rules to the security group |
| 33 | * Launch an instance |
| 34 | * Pause/unpause the instance |
| 35 | * Suspend/resume the instance |
| 36 | * Terminate the instance |
| 37 | """ |
| 38 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 39 | def create_keypair(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 40 | kp_name = rand_name('keypair-smoke') |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 41 | self.keypair = self.compute_client.keypairs.create(kp_name) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 42 | try: |
| 43 | self.assertEqual(self.keypair.id, kp_name) |
| 44 | self.set_resource('keypair', self.keypair) |
| 45 | except AttributeError: |
| 46 | self.fail("Keypair object not successfully created.") |
| 47 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 48 | def create_security_group(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 49 | sg_name = rand_name('secgroup-smoke') |
| 50 | sg_desc = sg_name + " description" |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 51 | self.secgroup = self.compute_client.security_groups.create(sg_name, |
| 52 | sg_desc) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 53 | try: |
| 54 | self.assertEqual(self.secgroup.name, sg_name) |
| 55 | self.assertEqual(self.secgroup.description, sg_desc) |
| 56 | self.set_resource('secgroup', self.secgroup) |
| 57 | except AttributeError: |
| 58 | self.fail("SecurityGroup object not successfully created.") |
| 59 | |
| 60 | # Add rules to the security group |
| 61 | rulesets = [ |
| 62 | { |
| 63 | 'ip_protocol': 'tcp', |
| 64 | 'from_port': 1, |
| 65 | 'to_port': 65535, |
| 66 | 'cidr': '0.0.0.0/0', |
| 67 | 'group_id': self.secgroup.id |
| 68 | }, |
| 69 | { |
| 70 | 'ip_protocol': 'icmp', |
| 71 | 'from_port': -1, |
| 72 | 'to_port': -1, |
| 73 | 'cidr': '0.0.0.0/0', |
| 74 | 'group_id': self.secgroup.id |
| 75 | } |
| 76 | ] |
| 77 | for ruleset in rulesets: |
| 78 | try: |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 79 | self.compute_client.security_group_rules.create( |
Sean Dague | 14c6818 | 2013-04-14 15:34:30 -0400 | [diff] [blame] | 80 | self.secgroup.id, **ruleset) |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 81 | except Exception: |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 82 | self.fail("Failed to create rule in security group.") |
| 83 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 84 | def boot_instance(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 85 | create_kwargs = { |
| 86 | 'key_name': self.get_resource('keypair').id |
| 87 | } |
Ken'ichi Ohmichi | 61f272b | 2013-08-15 15:58:53 +0900 | [diff] [blame^] | 88 | instance = self.create_server(self.compute_client, |
| 89 | create_kwargs=create_kwargs) |
| 90 | self.set_resource('instance', instance) |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 91 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 92 | def pause_server(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 93 | instance = self.get_resource('instance') |
| 94 | instance_id = instance.id |
| 95 | LOG.debug("Pausing instance %s. Current status: %s", |
| 96 | instance_id, instance.status) |
| 97 | instance.pause() |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 98 | self.status_timeout( |
| 99 | self.compute_client.servers, instance_id, 'PAUSED') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 100 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 101 | def unpause_server(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 102 | instance = self.get_resource('instance') |
| 103 | instance_id = instance.id |
| 104 | LOG.debug("Unpausing instance %s. Current status: %s", |
| 105 | instance_id, instance.status) |
| 106 | instance.unpause() |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 107 | self.status_timeout( |
| 108 | self.compute_client.servers, instance_id, 'ACTIVE') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 109 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 110 | def suspend_server(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 111 | instance = self.get_resource('instance') |
| 112 | instance_id = instance.id |
| 113 | LOG.debug("Suspending instance %s. Current status: %s", |
| 114 | instance_id, instance.status) |
| 115 | instance.suspend() |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 116 | self.status_timeout(self.compute_client.servers, |
Maru Newby | dec13ec | 2012-08-30 11:19:17 -0700 | [diff] [blame] | 117 | instance_id, 'SUSPENDED') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 118 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 119 | def resume_server(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 120 | instance = self.get_resource('instance') |
| 121 | instance_id = instance.id |
| 122 | LOG.debug("Resuming instance %s. Current status: %s", |
| 123 | instance_id, instance.status) |
| 124 | instance.resume() |
Sean Dague | 35a7caf | 2013-05-10 10:38:22 -0400 | [diff] [blame] | 125 | self.status_timeout( |
| 126 | self.compute_client.servers, instance_id, 'ACTIVE') |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 127 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 128 | def terminate_instance(self): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 129 | instance = self.get_resource('instance') |
| 130 | instance.delete() |
| 131 | self.remove_resource('instance') |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 132 | |
| 133 | def test_server_basicops(self): |
| 134 | self.create_keypair() |
| 135 | self.create_security_group() |
| 136 | self.boot_instance() |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 137 | self.pause_server() |
| 138 | self.unpause_server() |
| 139 | self.suspend_server() |
| 140 | self.resume_server() |
| 141 | self.terminate_instance() |