blob: 811e47bfac63677e5930d47a1b5dd4b2b4d65b50 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
17
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000018from tempest.common import waiters
Adam Gandelman4a48a602014-03-20 18:23:18 -070019from tempest import config
Adam Gandelman4a48a602014-03-20 18:23:18 -070020from tempest.scenario import manager
21from tempest import test
22
23CONF = config.CONF
24
25LOG = logging.getLogger(__name__)
26
27
David Shrewsbury02719362014-05-20 14:10:03 -040028class BaremetalBasicOps(manager.BaremetalScenarioTest):
Adam Gandelman4a48a602014-03-20 18:23:18 -070029 """
30 This smoke test tests the pxe_ssh Ironic driver. It follows this basic
31 set of operations:
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 Gandelman4a48a602014-03-20 18:23:18 -070036 * 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 Shrewsbury02719362014-05-20 14:10:03 -040040 * Verifies instance rebuild with ephemeral partition preservation
Adam Gandelman4a48a602014-03-20 18:23:18 -070041 * Deletes instance
42 * Monitors the associated Ironic node for power and
43 expected state transitions
44 """
David Shrewsbury02719362014-05-20 14:10:03 -040045 def rebuild_instance(self, preserve_ephemeral=False):
Adam Gandelmanc78c7572014-08-28 18:38:55 -070046 self.rebuild_server(server_id=self.instance['id'],
David Shrewsbury02719362014-05-20 14:10:03 -040047 preserve_ephemeral=preserve_ephemeral,
48 wait=False)
49
Adam Gandelmanc78c7572014-08-28 18:38:55 -070050 node = self.get_node(instance_id=self.instance['id'])
David Shrewsbury02719362014-05-20 14:10:03 -040051
52 # We should remain on the same node
Adam Gandelmanc78c7572014-08-28 18:38:55 -070053 self.assertEqual(self.node['uuid'], node['uuid'])
David Shrewsbury02719362014-05-20 14:10:03 -040054 self.node = node
55
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000056 waiters.wait_for_server_status(
57 self.servers_client,
Adam Gandelmanc78c7572014-08-28 18:38:55 -070058 server_id=self.instance['id'],
59 status='REBUILD',
60 ready_wait=False)
Ken'ichi Ohmichi0eb153c2015-07-13 02:18:25 +000061 waiters.wait_for_server_status(
62 self.servers_client,
Adam Gandelmanc78c7572014-08-28 18:38:55 -070063 server_id=self.instance['id'],
64 status='ACTIVE')
David Shrewsbury02719362014-05-20 14:10:03 -040065
66 def create_remote_file(self, client, filename):
67 """Create a file on the remote client connection.
68
69 After creating the file, force a filesystem sync. Otherwise,
70 if we issue a rebuild too quickly, the file may not exist.
71 """
72 client.exec_command('sudo touch ' + filename)
73 client.exec_command('sync')
74
75 def verify_partition(self, client, label, mount, gib_size):
76 """Verify a labeled partition's mount point and size."""
77 LOG.info("Looking for partition %s mounted on %s" % (label, mount))
78
79 # Validate we have a device with the given partition label
80 cmd = "/sbin/blkid | grep '%s' | cut -d':' -f1" % label
81 device = client.exec_command(cmd).rstrip('\n')
82 LOG.debug("Partition device is %s" % device)
83 self.assertNotEqual('', device)
84
85 # Validate the mount point for the device
86 cmd = "mount | grep '%s' | cut -d' ' -f3" % device
87 actual_mount = client.exec_command(cmd).rstrip('\n')
88 LOG.debug("Partition mount point is %s" % actual_mount)
89 self.assertEqual(actual_mount, mount)
90
91 # Validate the partition size matches what we expect
92 numbers = '0123456789'
93 devnum = device.replace('/dev/', '')
94 cmd = "cat /sys/block/%s/%s/size" % (devnum.rstrip(numbers), devnum)
95 num_bytes = client.exec_command(cmd).rstrip('\n')
96 num_bytes = int(num_bytes) * 512
97 actual_gib_size = num_bytes / (1024 * 1024 * 1024)
98 LOG.debug("Partition size is %d GiB" % actual_gib_size)
99 self.assertEqual(actual_gib_size, gib_size)
100
101 def get_flavor_ephemeral_size(self):
102 """Returns size of the ephemeral partition in GiB."""
Adam Gandelmanc78c7572014-08-28 18:38:55 -0700103 f_id = self.instance['flavor']['id']
ghanshyam19973be2015-08-18 15:46:42 +0900104 flavor = self.flavors_client.show_flavor(f_id)['flavor']
Adam Gandelmanc78c7572014-08-28 18:38:55 -0700105 ephemeral = flavor.get('OS-FLV-EXT-DATA:ephemeral')
106 if not ephemeral or ephemeral == 'N/A':
107 return None
108 return int(ephemeral)
David Shrewsbury02719362014-05-20 14:10:03 -0400109
Adam Gandelman4a48a602014-03-20 18:23:18 -0700110 def validate_ports(self):
Adam Gandelmanc78c7572014-08-28 18:38:55 -0700111 for port in self.get_ports(self.node['uuid']):
112 n_port_id = port['extra']['vif_port_id']
David Kranz34e88122014-12-11 15:24:05 -0500113 body = self.network_client.show_port(n_port_id)
Adam Gandelmanc78c7572014-08-28 18:38:55 -0700114 n_port = body['port']
115 self.assertEqual(n_port['device_id'], self.instance['id'])
116 self.assertEqual(n_port['mac_address'], port['address'])
Adam Gandelman4a48a602014-03-20 18:23:18 -0700117
Chris Hoge7579c1a2015-02-26 14:12:15 -0800118 @test.idempotent_id('549173a5-38ec-42bb-b0e2-c8b9f4a08943')
Adam Gandelman4a48a602014-03-20 18:23:18 -0700119 @test.services('baremetal', 'compute', 'image', 'network')
120 def test_baremetal_server_ops(self):
David Shrewsbury02719362014-05-20 14:10:03 -0400121 test_filename = '/mnt/rebuild_test.txt'
Adam Gandelman4a48a602014-03-20 18:23:18 -0700122 self.add_keypair()
123 self.boot_instance()
Adam Gandelman4a48a602014-03-20 18:23:18 -0700124 self.validate_ports()
125 self.verify_connectivity()
Ramakrishnan G1ddfb052015-04-17 16:56:25 +0000126 if CONF.compute.ssh_connect_method == 'floating':
Alexander Gubanov2388e2a2015-11-07 11:16:28 +0200127 floating_ip = self.create_floating_ip(self.instance)['ip']
Ramakrishnan G1ddfb052015-04-17 16:56:25 +0000128 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()