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): |
| 44 | self.rebuild_server(self.instance, |
| 45 | preserve_ephemeral=preserve_ephemeral, |
| 46 | wait=False) |
| 47 | |
| 48 | node = self.get_node(instance_id=self.instance.id) |
| 49 | self.instance = self.compute_client.servers.get(self.instance.id) |
| 50 | |
| 51 | self.addCleanup_with_wait(self.compute_client.servers, |
| 52 | self.instance.id, |
| 53 | cleanup_callable=self.delete_wrapper, |
| 54 | cleanup_args=[self.instance]) |
| 55 | |
| 56 | # We should remain on the same node |
| 57 | self.assertEqual(self.node.uuid, node.uuid) |
| 58 | self.node = node |
| 59 | |
| 60 | self.status_timeout(self.compute_client.servers, self.instance.id, |
| 61 | 'REBUILD') |
| 62 | self.status_timeout(self.compute_client.servers, self.instance.id, |
| 63 | 'ACTIVE') |
| 64 | |
| 65 | def create_remote_file(self, client, filename): |
| 66 | """Create a file on the remote client connection. |
| 67 | |
| 68 | After creating the file, force a filesystem sync. Otherwise, |
| 69 | if we issue a rebuild too quickly, the file may not exist. |
| 70 | """ |
| 71 | client.exec_command('sudo touch ' + filename) |
| 72 | client.exec_command('sync') |
| 73 | |
| 74 | def verify_partition(self, client, label, mount, gib_size): |
| 75 | """Verify a labeled partition's mount point and size.""" |
| 76 | LOG.info("Looking for partition %s mounted on %s" % (label, mount)) |
| 77 | |
| 78 | # Validate we have a device with the given partition label |
| 79 | cmd = "/sbin/blkid | grep '%s' | cut -d':' -f1" % label |
| 80 | device = client.exec_command(cmd).rstrip('\n') |
| 81 | LOG.debug("Partition device is %s" % device) |
| 82 | self.assertNotEqual('', device) |
| 83 | |
| 84 | # Validate the mount point for the device |
| 85 | cmd = "mount | grep '%s' | cut -d' ' -f3" % device |
| 86 | actual_mount = client.exec_command(cmd).rstrip('\n') |
| 87 | LOG.debug("Partition mount point is %s" % actual_mount) |
| 88 | self.assertEqual(actual_mount, mount) |
| 89 | |
| 90 | # Validate the partition size matches what we expect |
| 91 | numbers = '0123456789' |
| 92 | devnum = device.replace('/dev/', '') |
| 93 | cmd = "cat /sys/block/%s/%s/size" % (devnum.rstrip(numbers), devnum) |
| 94 | num_bytes = client.exec_command(cmd).rstrip('\n') |
| 95 | num_bytes = int(num_bytes) * 512 |
| 96 | actual_gib_size = num_bytes / (1024 * 1024 * 1024) |
| 97 | LOG.debug("Partition size is %d GiB" % actual_gib_size) |
| 98 | self.assertEqual(actual_gib_size, gib_size) |
| 99 | |
| 100 | def get_flavor_ephemeral_size(self): |
| 101 | """Returns size of the ephemeral partition in GiB.""" |
| 102 | f_id = self.instance.flavor['id'] |
| 103 | ephemeral = self.compute_client.flavors.get(f_id).ephemeral |
| 104 | if ephemeral != 'N/A': |
| 105 | return int(ephemeral) |
| 106 | return None |
| 107 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 108 | def add_floating_ip(self): |
| 109 | floating_ip = self.compute_client.floating_ips.create() |
| 110 | self.instance.add_floating_ip(floating_ip) |
| 111 | return floating_ip.ip |
| 112 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 113 | def validate_ports(self): |
| 114 | for port in self.get_ports(self.node.uuid): |
| 115 | n_port_id = port.extra['vif_port_id'] |
| 116 | n_port = self.network_client.show_port(n_port_id)['port'] |
| 117 | self.assertEqual(n_port['device_id'], self.instance.id) |
| 118 | self.assertEqual(n_port['mac_address'], port.address) |
| 119 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 120 | @test.services('baremetal', 'compute', 'image', 'network') |
| 121 | def test_baremetal_server_ops(self): |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 122 | test_filename = '/mnt/rebuild_test.txt' |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 123 | self.add_keypair() |
| 124 | self.boot_instance() |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 125 | self.validate_ports() |
| 126 | self.verify_connectivity() |
| 127 | floating_ip = self.add_floating_ip() |
| 128 | self.verify_connectivity(ip=floating_ip) |
David Shrewsbury | 0271936 | 2014-05-20 14:10:03 -0400 | [diff] [blame] | 129 | |
| 130 | vm_client = self.get_remote_client(self.instance) |
| 131 | |
| 132 | # We expect the ephemeral partition to be mounted on /mnt and to have |
| 133 | # the same size as our flavor definition. |
| 134 | eph_size = self.get_flavor_ephemeral_size() |
| 135 | self.assertIsNotNone(eph_size) |
| 136 | self.verify_partition(vm_client, 'ephemeral0', '/mnt', eph_size) |
| 137 | |
| 138 | # Create the test file |
| 139 | self.create_remote_file(vm_client, test_filename) |
| 140 | |
| 141 | # Rebuild and preserve the ephemeral partition |
| 142 | self.rebuild_instance(True) |
| 143 | self.verify_connectivity() |
| 144 | |
| 145 | # Check that we maintained our data |
| 146 | vm_client = self.get_remote_client(self.instance) |
| 147 | self.verify_partition(vm_client, 'ephemeral0', '/mnt', eph_size) |
| 148 | vm_client.exec_command('ls ' + test_filename) |
| 149 | |
Adam Gandelman | 4a48a60 | 2014-03-20 18:23:18 -0700 | [diff] [blame] | 150 | self.terminate_instance() |