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