ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 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 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 16 | from tempest import config |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 17 | from tempest.openstack.common import log as logging |
Sean Dague | 6dbc6da | 2013-05-08 17:49:46 -0400 | [diff] [blame] | 18 | from tempest.scenario import manager |
Matthew Treinish | d75edef | 2014-04-11 15:57:16 -0400 | [diff] [blame] | 19 | from tempest.scenario import utils as test_utils |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 20 | from tempest import test |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 21 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 22 | CONF = config.CONF |
| 23 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 24 | LOG = logging.getLogger(__name__) |
| 25 | |
Matthew Treinish | a0048cb | 2014-04-08 17:44:42 -0400 | [diff] [blame] | 26 | load_tests = test_utils.load_tests_input_scenario_utils |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 27 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 28 | |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 29 | class TestServerBasicOps(manager.ScenarioTest): |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 30 | |
| 31 | """ |
| 32 | This smoke test case follows this basic set of operations: |
| 33 | |
| 34 | * Create a keypair for use in launching an instance |
| 35 | * Create a security group to control network access in instance |
| 36 | * Add simple permissive rules to the security group |
| 37 | * Launch an instance |
ghanshyam | 416c94c | 2014-10-02 13:47:25 +0900 | [diff] [blame] | 38 | * Perform ssh to instance |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 39 | * Terminate the instance |
| 40 | """ |
| 41 | |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 42 | def setUp(self): |
| 43 | super(TestServerBasicOps, self).setUp() |
| 44 | # Setup image and flavor the test instance |
| 45 | # Support both configured and injected values |
| 46 | if not hasattr(self, 'image_ref'): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 47 | self.image_ref = CONF.compute.image_ref |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 48 | if not hasattr(self, 'flavor_ref'): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 49 | self.flavor_ref = CONF.compute.flavor_ref |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 50 | self.image_utils = test_utils.ImageUtils() |
| 51 | if not self.image_utils.is_flavor_enough(self.flavor_ref, |
| 52 | self.image_ref): |
| 53 | raise self.skipException( |
| 54 | '{image} does not fit in {flavor}'.format( |
| 55 | image=self.image_ref, flavor=self.flavor_ref |
| 56 | ) |
| 57 | ) |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 58 | self.run_ssh = CONF.compute.run_ssh and \ |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 59 | self.image_utils.is_sshable_image(self.image_ref) |
| 60 | self.ssh_user = self.image_utils.ssh_user(self.image_ref) |
| 61 | LOG.debug('Starting test for i:{image}, f:{flavor}. ' |
| 62 | 'Run ssh: {ssh}, user: {ssh_user}'.format( |
| 63 | image=self.image_ref, flavor=self.flavor_ref, |
| 64 | ssh=self.run_ssh, ssh_user=self.ssh_user)) |
| 65 | |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 66 | def add_keypair(self): |
| 67 | self.keypair = self.create_keypair() |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 68 | |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 69 | def boot_instance(self): |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 70 | # Create server with image and flavor from input scenario |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 71 | security_groups = [self.security_group] |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 72 | create_kwargs = { |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 73 | 'key_name': self.keypair['name'], |
Grishkin | 0f1e11c | 2014-05-04 20:44:52 +0400 | [diff] [blame] | 74 | 'security_groups': security_groups |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 75 | } |
Matthew Treinish | b7144eb | 2013-12-13 22:57:35 +0000 | [diff] [blame] | 76 | self.instance = self.create_server(image=self.image_ref, |
| 77 | flavor=self.flavor_ref, |
| 78 | create_kwargs=create_kwargs) |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 79 | |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 80 | def verify_ssh(self): |
| 81 | if self.run_ssh: |
| 82 | # Obtain a floating IP |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 83 | _, floating_ip = self.floating_ips_client.create_floating_ip() |
| 84 | self.addCleanup(self.delete_wrapper, |
| 85 | self.floating_ips_client.delete_floating_ip, |
| 86 | floating_ip['id']) |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 87 | # Attach a floating IP |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 88 | self.floating_ips_client.associate_floating_ip_to_server( |
| 89 | floating_ip['ip'], self.instance['id']) |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 90 | # Check ssh |
Nachi Ueno | 95b4128 | 2014-01-15 06:54:21 -0800 | [diff] [blame] | 91 | try: |
Yair Fried | 3960c4d | 2014-05-07 15:20:30 +0300 | [diff] [blame] | 92 | self.get_remote_client( |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 93 | server_or_ip=floating_ip['ip'], |
Nachi Ueno | 95b4128 | 2014-01-15 06:54:21 -0800 | [diff] [blame] | 94 | username=self.image_utils.ssh_user(self.image_ref), |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 95 | private_key=self.keypair['private_key']) |
Nachi Ueno | 95b4128 | 2014-01-15 06:54:21 -0800 | [diff] [blame] | 96 | except Exception: |
| 97 | LOG.exception('ssh to server failed') |
| 98 | self._log_console_output() |
| 99 | raise |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 100 | |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 101 | @test.services('compute', 'network') |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 102 | def test_server_basicops(self): |
Ken'ichi Ohmichi | 599d1b8 | 2013-08-19 18:48:37 +0900 | [diff] [blame] | 103 | self.add_keypair() |
Yair Fried | 1fc32a1 | 2014-08-04 09:11:30 +0300 | [diff] [blame] | 104 | self.security_group = self._create_security_group() |
ivan-zhu | 1997739 | 2013-01-12 21:57:55 +0800 | [diff] [blame] | 105 | self.boot_instance() |
Andrea Frittoli | f5da28b | 2013-12-06 07:08:07 +0000 | [diff] [blame] | 106 | self.verify_ssh() |
Ghanshyam | 5a305c4 | 2014-08-27 14:24:58 +0900 | [diff] [blame] | 107 | self.servers_client.delete_server(self.instance['id']) |