blob: fd4449a30383b2be3d701d994d3193cd42281ea5 [file] [log] [blame]
Adam Gandelman4a48a602014-03-20 18:23:18 -07001#
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
16from tempest import config
17from tempest.openstack.common import log as logging
18from tempest.scenario import manager
19from tempest import test
20
21CONF = config.CONF
22
23LOG = logging.getLogger(__name__)
24
25
David Shrewsbury02719362014-05-20 14:10:03 -040026class BaremetalBasicOps(manager.BaremetalScenarioTest):
Adam Gandelman4a48a602014-03-20 18:23:18 -070027 """
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 Gandelman4a48a602014-03-20 18:23:18 -070034 * 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 Shrewsbury02719362014-05-20 14:10:03 -040038 * Verifies instance rebuild with ephemeral partition preservation
Adam Gandelman4a48a602014-03-20 18:23:18 -070039 * Deletes instance
40 * Monitors the associated Ironic node for power and
41 expected state transitions
42 """
David Shrewsbury02719362014-05-20 14:10:03 -040043 def rebuild_instance(self, preserve_ephemeral=False):
Adam Gandelmanc78c7572014-08-28 18:38:55 -070044 self.rebuild_server(server_id=self.instance['id'],
David Shrewsbury02719362014-05-20 14:10:03 -040045 preserve_ephemeral=preserve_ephemeral,
46 wait=False)
47
Adam Gandelmanc78c7572014-08-28 18:38:55 -070048 node = self.get_node(instance_id=self.instance['id'])
David Shrewsbury02719362014-05-20 14:10:03 -040049
50 # We should remain on the same node
Adam Gandelmanc78c7572014-08-28 18:38:55 -070051 self.assertEqual(self.node['uuid'], node['uuid'])
David Shrewsbury02719362014-05-20 14:10:03 -040052 self.node = node
53
Adam Gandelmanc78c7572014-08-28 18:38:55 -070054 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 Shrewsbury02719362014-05-20 14:10:03 -040061
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 Gandelmanc78c7572014-08-28 18:38:55 -070099 f_id = self.instance['flavor']['id']
David Kranz2fa77b22015-02-09 11:39:50 -0500100 flavor = self.flavors_client.get_flavor_details(f_id)
Adam Gandelmanc78c7572014-08-28 18:38:55 -0700101 ephemeral = flavor.get('OS-FLV-EXT-DATA:ephemeral')
102 if not ephemeral or ephemeral == 'N/A':
103 return None
104 return int(ephemeral)
David Shrewsbury02719362014-05-20 14:10:03 -0400105
Adam Gandelman4a48a602014-03-20 18:23:18 -0700106 def add_floating_ip(self):
Adam Gandelmanc78c7572014-08-28 18:38:55 -0700107 _, floating_ip = self.floating_ips_client.create_floating_ip()
108 self.floating_ips_client.associate_floating_ip_to_server(
109 floating_ip['ip'], self.instance['id'])
110 return floating_ip['ip']
Adam Gandelman4a48a602014-03-20 18:23:18 -0700111
Adam Gandelman4a48a602014-03-20 18:23:18 -0700112 def validate_ports(self):
Adam Gandelmanc78c7572014-08-28 18:38:55 -0700113 for port in self.get_ports(self.node['uuid']):
114 n_port_id = port['extra']['vif_port_id']
David Kranz34e88122014-12-11 15:24:05 -0500115 body = self.network_client.show_port(n_port_id)
Adam Gandelmanc78c7572014-08-28 18:38:55 -0700116 n_port = body['port']
117 self.assertEqual(n_port['device_id'], self.instance['id'])
118 self.assertEqual(n_port['mac_address'], port['address'])
Adam Gandelman4a48a602014-03-20 18:23:18 -0700119
Adam Gandelman4a48a602014-03-20 18:23:18 -0700120 @test.services('baremetal', 'compute', 'image', 'network')
121 def test_baremetal_server_ops(self):
David Shrewsbury02719362014-05-20 14:10:03 -0400122 test_filename = '/mnt/rebuild_test.txt'
Adam Gandelman4a48a602014-03-20 18:23:18 -0700123 self.add_keypair()
124 self.boot_instance()
Adam Gandelman4a48a602014-03-20 18:23:18 -0700125 self.validate_ports()
126 self.verify_connectivity()
127 floating_ip = self.add_floating_ip()
128 self.verify_connectivity(ip=floating_ip)
David Shrewsbury02719362014-05-20 14:10:03 -0400129
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()
Jim Rollenhagena170b532014-09-11 08:33:39 -0700135 if eph_size > 0:
136 preserve_ephemeral = True
David Shrewsbury02719362014-05-20 14:10:03 -0400137
Jim Rollenhagena170b532014-09-11 08:33:39 -0700138 self.verify_partition(vm_client, 'ephemeral0', '/mnt', eph_size)
139 # Create the test file
140 self.create_remote_file(vm_client, test_filename)
141 else:
142 preserve_ephemeral = False
David Shrewsbury02719362014-05-20 14:10:03 -0400143
Jim Rollenhagena170b532014-09-11 08:33:39 -0700144 # Rebuild and preserve the ephemeral partition if it exists
145 self.rebuild_instance(preserve_ephemeral)
David Shrewsbury02719362014-05-20 14:10:03 -0400146 self.verify_connectivity()
147
148 # Check that we maintained our data
Jim Rollenhagena170b532014-09-11 08:33:39 -0700149 if eph_size > 0:
150 vm_client = self.get_remote_client(self.instance)
151 self.verify_partition(vm_client, 'ephemeral0', '/mnt', eph_size)
152 vm_client.exec_command('ls ' + test_filename)
David Shrewsbury02719362014-05-20 14:10:03 -0400153
Adam Gandelman4a48a602014-03-20 18:23:18 -0700154 self.terminate_instance()