Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2014 Hewlett-Packard Development Company, L.P. |
| 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 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 16 | from oslo_log import log as logging |
| 17 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 18 | from tempest.scenario import manager |
| 19 | from tempest import test |
| 20 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 21 | LOG = logging.getLogger(__name__) |
| 22 | |
| 23 | |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 24 | class BaremetalBasicOps(manager.BaremetalScenarioTest): |
Ken'ichi Ohmichi | c4e4f1c | 2015-11-17 08:16:12 +0000 | [diff] [blame] | 25 | """This smoke test tests the pxe_ssh Ironic driver. |
| 26 | |
| 27 | It follows this basic set of operations: |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 28 | * Creates a keypair |
| 29 | * Boots an instance using the keypair |
| 30 | * Monitors the associated Ironic node for power and |
| 31 | expected state transitions |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 32 | * Validates Ironic node's port data has been properly updated |
| 33 | * Verifies SSH connectivity using created keypair via fixed IP |
| 34 | * Associates a floating ip |
| 35 | * Verifies SSH connectivity using created keypair via floating IP |
| 36 | * Deletes instance |
| 37 | * Monitors the associated Ironic node for power and |
| 38 | expected state transitions |
| 39 | """ |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 40 | def verify_partition(self, client, label, mount, gib_size): |
| 41 | """Verify a labeled partition's mount point and size.""" |
| 42 | LOG.info("Looking for partition %s mounted on %s" % (label, mount)) |
| 43 | |
| 44 | # Validate we have a device with the given partition label |
| 45 | cmd = "/sbin/blkid | grep '%s' | cut -d':' -f1" % label |
| 46 | device = client.exec_command(cmd).rstrip('\n') |
| 47 | LOG.debug("Partition device is %s" % device) |
| 48 | self.assertNotEqual('', device) |
| 49 | |
| 50 | # Validate the mount point for the device |
| 51 | cmd = "mount | grep '%s' | cut -d' ' -f3" % device |
| 52 | actual_mount = client.exec_command(cmd).rstrip('\n') |
| 53 | LOG.debug("Partition mount point is %s" % actual_mount) |
| 54 | self.assertEqual(actual_mount, mount) |
| 55 | |
| 56 | # Validate the partition size matches what we expect |
| 57 | numbers = '0123456789' |
| 58 | devnum = device.replace('/dev/', '') |
| 59 | cmd = "cat /sys/block/%s/%s/size" % (devnum.rstrip(numbers), devnum) |
| 60 | num_bytes = client.exec_command(cmd).rstrip('\n') |
| 61 | num_bytes = int(num_bytes) * 512 |
| 62 | actual_gib_size = num_bytes / (1024 * 1024 * 1024) |
| 63 | LOG.debug("Partition size is %d GiB" % actual_gib_size) |
| 64 | self.assertEqual(actual_gib_size, gib_size) |
| 65 | |
| 66 | def get_flavor_ephemeral_size(self): |
| 67 | """Returns size of the ephemeral partition in GiB.""" |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 68 | f_id = self.instance['flavor']['id'] |
ghanshyam | 19973be | 2015-08-18 15:46:42 +0900 | [diff] [blame] | 69 | flavor = self.flavors_client.show_flavor(f_id)['flavor'] |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 70 | ephemeral = flavor.get('OS-FLV-EXT-DATA:ephemeral') |
| 71 | if not ephemeral or ephemeral == 'N/A': |
| 72 | return None |
| 73 | return int(ephemeral) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 74 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 75 | def validate_ports(self): |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 76 | for port in self.get_ports(self.node['uuid']): |
| 77 | n_port_id = port['extra']['vif_port_id'] |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 78 | body = self.ports_client.show_port(n_port_id) |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 79 | n_port = body['port'] |
| 80 | self.assertEqual(n_port['device_id'], self.instance['id']) |
| 81 | self.assertEqual(n_port['mac_address'], port['address']) |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 82 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 83 | @test.idempotent_id('549173a5-38ec-42bb-b0e2-c8b9f4a08943') |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 84 | @test.services('baremetal', 'compute', 'image', 'network') |
| 85 | def test_baremetal_server_ops(self): |
| 86 | self.add_keypair() |
| 87 | self.boot_instance() |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 88 | self.validate_ports() |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 89 | ip_address = self.get_server_ip(self.instance) |
| 90 | self.get_remote_client(ip_address).validate_authentication() |
| 91 | vm_client = self.get_remote_client(ip_address) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 92 | |
| 93 | # We expect the ephemeral partition to be mounted on /mnt and to have |
| 94 | # the same size as our flavor definition. |
| 95 | eph_size = self.get_flavor_ephemeral_size() |
Alexander Gubanov | 3a7a2bc | 2015-11-13 21:58:51 +0200 | [diff] [blame] | 96 | if eph_size: |
Jim Rollenhagen | a170b53 | 2014-09-11 08:33:39 -0700 | [diff] [blame] | 97 | self.verify_partition(vm_client, 'ephemeral0', '/mnt', eph_size) |
| 98 | # Create the test file |
Dmitry Tantsur | 50daa10 | 2015-12-21 18:23:16 +0100 | [diff] [blame] | 99 | self.create_timestamp( |
Sean Dague | 20e9861 | 2016-01-06 14:33:28 -0500 | [diff] [blame] | 100 | ip_address, private_key=self.keypair['private_key']) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 101 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 102 | self.terminate_instance() |