blob: 655d19ddd5002e6344785eb96ffb154d9ac25672 [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
Adam Gandelman4a48a602014-03-20 18:23:18 -070018from tempest import config
Adam Gandelman4a48a602014-03-20 18:23:18 -070019from tempest.scenario import manager
20from tempest import test
21
22CONF = config.CONF
23
24LOG = logging.getLogger(__name__)
25
26
David Shrewsbury02719362014-05-20 14:10:03 -040027class BaremetalBasicOps(manager.BaremetalScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000028 """This smoke test tests the pxe_ssh Ironic driver.
29
30 It follows this basic set of operations:
Adam Gandelman4a48a602014-03-20 18:23:18 -070031 * Creates a keypair
32 * Boots an instance using the keypair
33 * Monitors the associated Ironic node for power and
34 expected state transitions
Adam Gandelman4a48a602014-03-20 18:23:18 -070035 * Validates Ironic node's port data has been properly updated
36 * Verifies SSH connectivity using created keypair via fixed IP
37 * Associates a floating ip
38 * Verifies SSH connectivity using created keypair via floating IP
39 * 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 verify_partition(self, client, label, mount, gib_size):
44 """Verify a labeled partition's mount point and size."""
45 LOG.info("Looking for partition %s mounted on %s" % (label, mount))
46
47 # Validate we have a device with the given partition label
48 cmd = "/sbin/blkid | grep '%s' | cut -d':' -f1" % label
49 device = client.exec_command(cmd).rstrip('\n')
50 LOG.debug("Partition device is %s" % device)
51 self.assertNotEqual('', device)
52
53 # Validate the mount point for the device
54 cmd = "mount | grep '%s' | cut -d' ' -f3" % device
55 actual_mount = client.exec_command(cmd).rstrip('\n')
56 LOG.debug("Partition mount point is %s" % actual_mount)
57 self.assertEqual(actual_mount, mount)
58
59 # Validate the partition size matches what we expect
60 numbers = '0123456789'
61 devnum = device.replace('/dev/', '')
62 cmd = "cat /sys/block/%s/%s/size" % (devnum.rstrip(numbers), devnum)
63 num_bytes = client.exec_command(cmd).rstrip('\n')
64 num_bytes = int(num_bytes) * 512
65 actual_gib_size = num_bytes / (1024 * 1024 * 1024)
66 LOG.debug("Partition size is %d GiB" % actual_gib_size)
67 self.assertEqual(actual_gib_size, gib_size)
68
69 def get_flavor_ephemeral_size(self):
70 """Returns size of the ephemeral partition in GiB."""
Adam Gandelmanc78c7572014-08-28 18:38:55 -070071 f_id = self.instance['flavor']['id']
ghanshyam19973be2015-08-18 15:46:42 +090072 flavor = self.flavors_client.show_flavor(f_id)['flavor']
Adam Gandelmanc78c7572014-08-28 18:38:55 -070073 ephemeral = flavor.get('OS-FLV-EXT-DATA:ephemeral')
74 if not ephemeral or ephemeral == 'N/A':
75 return None
76 return int(ephemeral)
David Shrewsbury02719362014-05-20 14:10:03 -040077
Adam Gandelman4a48a602014-03-20 18:23:18 -070078 def validate_ports(self):
Adam Gandelmanc78c7572014-08-28 18:38:55 -070079 for port in self.get_ports(self.node['uuid']):
80 n_port_id = port['extra']['vif_port_id']
John Warren49c0fe52015-10-22 12:35:54 -040081 body = self.ports_client.show_port(n_port_id)
Adam Gandelmanc78c7572014-08-28 18:38:55 -070082 n_port = body['port']
83 self.assertEqual(n_port['device_id'], self.instance['id'])
84 self.assertEqual(n_port['mac_address'], port['address'])
Adam Gandelman4a48a602014-03-20 18:23:18 -070085
Chris Hoge7579c1a2015-02-26 14:12:15 -080086 @test.idempotent_id('549173a5-38ec-42bb-b0e2-c8b9f4a08943')
Adam Gandelman4a48a602014-03-20 18:23:18 -070087 @test.services('baremetal', 'compute', 'image', 'network')
88 def test_baremetal_server_ops(self):
89 self.add_keypair()
90 self.boot_instance()
Adam Gandelman4a48a602014-03-20 18:23:18 -070091 self.validate_ports()
Sean Dague20e98612016-01-06 14:33:28 -050092 ip_address = self.get_server_ip(self.instance)
93 self.get_remote_client(ip_address).validate_authentication()
94 vm_client = self.get_remote_client(ip_address)
David Shrewsbury02719362014-05-20 14:10:03 -040095
96 # We expect the ephemeral partition to be mounted on /mnt and to have
97 # the same size as our flavor definition.
98 eph_size = self.get_flavor_ephemeral_size()
Alexander Gubanov3a7a2bc2015-11-13 21:58:51 +020099 if eph_size:
Jim Rollenhagena170b532014-09-11 08:33:39 -0700100 self.verify_partition(vm_client, 'ephemeral0', '/mnt', eph_size)
101 # Create the test file
Dmitry Tantsur50daa102015-12-21 18:23:16 +0100102 self.create_timestamp(
Sean Dague20e98612016-01-06 14:33:28 -0500103 ip_address, private_key=self.keypair['private_key'])
David Shrewsbury02719362014-05-20 14:10:03 -0400104
Adam Gandelman4a48a602014-03-20 18:23:18 -0700105 self.terminate_instance()