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 | |
| 16 | from tempest import config |
| 17 | from tempest.openstack.common import log as logging |
| 18 | from tempest.scenario import manager |
| 19 | from tempest import test |
| 20 | |
| 21 | CONF = config.CONF |
| 22 | |
| 23 | LOG = logging.getLogger(__name__) |
| 24 | |
| 25 | |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 26 | class BaremetalBasicOps(manager.BaremetalScenarioTest): |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 27 | """ |
| 28 | This smoke test tests the pxe_ssh Ironic driver. It follows this basic |
| 29 | set of operations: |
| 30 | * Creates a keypair |
| 31 | * Boots an instance using the keypair |
| 32 | * Monitors the associated Ironic node for power and |
| 33 | expected state transitions |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 34 | * Validates Ironic node's port data has been properly updated |
| 35 | * Verifies SSH connectivity using created keypair via fixed IP |
| 36 | * Associates a floating ip |
| 37 | * Verifies SSH connectivity using created keypair via floating IP |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 38 | * Verifies instance rebuild with ephemeral partition preservation |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 39 | * Deletes instance |
| 40 | * Monitors the associated Ironic node for power and |
| 41 | expected state transitions |
| 42 | """ |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 43 | def rebuild_instance(self, preserve_ephemeral=False): |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 44 | self.rebuild_server(server_id=self.instance['id'], |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 45 | preserve_ephemeral=preserve_ephemeral, |
| 46 | wait=False) |
| 47 | |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 48 | node = self.get_node(instance_id=self.instance['id']) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 49 | |
| 50 | # We should remain on the same node |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 51 | self.assertEqual(self.node['uuid'], node['uuid']) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 52 | self.node = node |
| 53 | |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 54 | self.servers_client.wait_for_server_status( |
| 55 | server_id=self.instance['id'], |
| 56 | status='REBUILD', |
| 57 | ready_wait=False) |
| 58 | self.servers_client.wait_for_server_status( |
| 59 | server_id=self.instance['id'], |
| 60 | status='ACTIVE') |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 61 | |
| 62 | def create_remote_file(self, client, filename): |
| 63 | """Create a file on the remote client connection. |
| 64 | |
| 65 | After creating the file, force a filesystem sync. Otherwise, |
| 66 | if we issue a rebuild too quickly, the file may not exist. |
| 67 | """ |
| 68 | client.exec_command('sudo touch ' + filename) |
| 69 | client.exec_command('sync') |
| 70 | |
| 71 | def verify_partition(self, client, label, mount, gib_size): |
| 72 | """Verify a labeled partition's mount point and size.""" |
| 73 | LOG.info("Looking for partition %s mounted on %s" % (label, mount)) |
| 74 | |
| 75 | # Validate we have a device with the given partition label |
| 76 | cmd = "/sbin/blkid | grep '%s' | cut -d':' -f1" % label |
| 77 | device = client.exec_command(cmd).rstrip('\n') |
| 78 | LOG.debug("Partition device is %s" % device) |
| 79 | self.assertNotEqual('', device) |
| 80 | |
| 81 | # Validate the mount point for the device |
| 82 | cmd = "mount | grep '%s' | cut -d' ' -f3" % device |
| 83 | actual_mount = client.exec_command(cmd).rstrip('\n') |
| 84 | LOG.debug("Partition mount point is %s" % actual_mount) |
| 85 | self.assertEqual(actual_mount, mount) |
| 86 | |
| 87 | # Validate the partition size matches what we expect |
| 88 | numbers = '0123456789' |
| 89 | devnum = device.replace('/dev/', '') |
| 90 | cmd = "cat /sys/block/%s/%s/size" % (devnum.rstrip(numbers), devnum) |
| 91 | num_bytes = client.exec_command(cmd).rstrip('\n') |
| 92 | num_bytes = int(num_bytes) * 512 |
| 93 | actual_gib_size = num_bytes / (1024 * 1024 * 1024) |
| 94 | LOG.debug("Partition size is %d GiB" % actual_gib_size) |
| 95 | self.assertEqual(actual_gib_size, gib_size) |
| 96 | |
| 97 | def get_flavor_ephemeral_size(self): |
| 98 | """Returns size of the ephemeral partition in GiB.""" |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 99 | f_id = self.instance['flavor']['id'] |
David Kranz | 2fa77b2 | 2015-02-09 11:39:50 -0500 | [diff] [blame] | 100 | flavor = self.flavors_client.get_flavor_details(f_id) |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 101 | ephemeral = flavor.get('OS-FLV-EXT-DATA:ephemeral') |
| 102 | if not ephemeral or ephemeral == 'N/A': |
| 103 | return None |
| 104 | return int(ephemeral) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 105 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 106 | def add_floating_ip(self): |
David Kranz | e4e3b41 | 2015-02-10 10:50:42 -0500 | [diff] [blame] | 107 | floating_ip = self.floating_ips_client.create_floating_ip() |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 108 | self.floating_ips_client.associate_floating_ip_to_server( |
| 109 | floating_ip['ip'], self.instance['id']) |
| 110 | return floating_ip['ip'] |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 111 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 112 | def validate_ports(self): |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 113 | for port in self.get_ports(self.node['uuid']): |
| 114 | n_port_id = port['extra']['vif_port_id'] |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 115 | body = self.network_client.show_port(n_port_id) |
Adam Gandelman | c78c757 | 2014-08-28 18:38:55 -0700 | [diff] [blame] | 116 | n_port = body['port'] |
| 117 | self.assertEqual(n_port['device_id'], self.instance['id']) |
| 118 | self.assertEqual(n_port['mac_address'], port['address']) |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 119 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame^] | 120 | @test.idempotent_id('549173a5-38ec-42bb-b0e2-c8b9f4a08943') |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 121 | @test.services('baremetal', 'compute', 'image', 'network') |
| 122 | def test_baremetal_server_ops(self): |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 123 | test_filename = '/mnt/rebuild_test.txt' |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 124 | self.add_keypair() |
| 125 | self.boot_instance() |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 126 | self.validate_ports() |
| 127 | self.verify_connectivity() |
| 128 | floating_ip = self.add_floating_ip() |
| 129 | self.verify_connectivity(ip=floating_ip) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 130 | |
| 131 | vm_client = self.get_remote_client(self.instance) |
| 132 | |
| 133 | # We expect the ephemeral partition to be mounted on /mnt and to have |
| 134 | # the same size as our flavor definition. |
| 135 | eph_size = self.get_flavor_ephemeral_size() |
Jim Rollenhagen | a170b53 | 2014-09-11 08:33:39 -0700 | [diff] [blame] | 136 | if eph_size > 0: |
| 137 | preserve_ephemeral = True |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 138 | |
Jim Rollenhagen | a170b53 | 2014-09-11 08:33:39 -0700 | [diff] [blame] | 139 | self.verify_partition(vm_client, 'ephemeral0', '/mnt', eph_size) |
| 140 | # Create the test file |
| 141 | self.create_remote_file(vm_client, test_filename) |
| 142 | else: |
| 143 | preserve_ephemeral = False |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 144 | |
Jim Rollenhagen | a170b53 | 2014-09-11 08:33:39 -0700 | [diff] [blame] | 145 | # Rebuild and preserve the ephemeral partition if it exists |
| 146 | self.rebuild_instance(preserve_ephemeral) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 147 | self.verify_connectivity() |
| 148 | |
| 149 | # Check that we maintained our data |
Jim Rollenhagen | a170b53 | 2014-09-11 08:33:39 -0700 | [diff] [blame] | 150 | if eph_size > 0: |
| 151 | vm_client = self.get_remote_client(self.instance) |
| 152 | self.verify_partition(vm_client, 'ephemeral0', '/mnt', eph_size) |
| 153 | vm_client.exec_command('ls ' + test_filename) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 154 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 155 | self.terminate_instance() |