Refactor config drive mounting
There are a few places where we mount the config drive which is not done in a consistent manner which results in failures for the cases where the config drive is VFAT, which makes the device label report as CONFIG-2 and not config-2 (uppercase). This refactors the mounting and unmounting codebase to the same block and reuses it to ensure a consistent behaviour across tests, also letting the tags checks pass when using VFAT for config drives. Change-Id: I529cff87c848bc87d63d2ec407ed18cdd631ecef
This commit is contained in:
parent
3fb1d3689e
commit
b6c6d2a128
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- A function has been added to the common library to allow mounting and
|
||||
unmounting of the config drive consistently.
|
@ -264,25 +264,13 @@ class DeviceTaggingTest(base.BaseV2ComputeTest):
|
||||
|
||||
# Verify metadata on config drive
|
||||
if CONF.compute_feature_enabled.config_drive:
|
||||
cmd_blkid = 'blkid -t LABEL=config-2 -o device'
|
||||
LOG.info('Attempting to verify tagged devices in server %s via '
|
||||
'the config drive.', server['id'])
|
||||
dev_name = self.ssh_client.exec_command(cmd_blkid)
|
||||
dev_name = dev_name.rstrip()
|
||||
try:
|
||||
self.ssh_client.exec_command('sudo mount %s /mnt' % dev_name)
|
||||
except exceptions.SSHExecCommandFailed:
|
||||
# So the command failed, let's try to know why and print some
|
||||
# useful information.
|
||||
lsblk = self.ssh_client.exec_command('sudo lsblk --fs --ascii')
|
||||
LOG.error("Mounting %s on /mnt failed. Right after the "
|
||||
"failure 'lsblk' in the guest reported:\n%s",
|
||||
dev_name, lsblk)
|
||||
raise
|
||||
|
||||
self.ssh_client.mount_config_drive()
|
||||
cmd_md = 'sudo cat /mnt/openstack/latest/meta_data.json'
|
||||
md_json = self.ssh_client.exec_command(cmd_md)
|
||||
self.verify_device_metadata(md_json)
|
||||
self.ssh_client.unmount_config_drive()
|
||||
|
||||
|
||||
class DeviceTaggingTestV2_42(DeviceTaggingTest):
|
||||
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import functools
|
||||
import re
|
||||
import sys
|
||||
|
||||
import netaddr
|
||||
@ -126,3 +127,27 @@ class RemoteClient(object):
|
||||
cmd = 'sudo {cmd} -I {nic}'.format(cmd=cmd, nic=nic)
|
||||
cmd += ' -c{0} -w{0} -s{1} {2}'.format(count, size, host)
|
||||
return self.exec_command(cmd)
|
||||
|
||||
def mount_config_drive(self):
|
||||
"""Mount the config drive inside a virtual machine
|
||||
|
||||
This method will not unmount the config drive, so unmount_config_drive
|
||||
must be used for cleanup.
|
||||
"""
|
||||
cmd_blkid = 'blkid | grep -i config-2'
|
||||
result = self.exec_command(cmd_blkid)
|
||||
dev_name = re.match('([^:]+)', result).group()
|
||||
|
||||
try:
|
||||
self.exec_command('sudo mount %s /mnt' % dev_name)
|
||||
except tempest.lib.exceptions.SSHExecCommandFailed:
|
||||
# So the command failed, let's try to know why and print some
|
||||
# useful information.
|
||||
lsblk = self.exec_command('sudo lsblk --fs --ascii')
|
||||
LOG.error("Mounting %s on /mnt failed. Right after the "
|
||||
"failure 'lsblk' in the guest reported:\n%s",
|
||||
dev_name, lsblk)
|
||||
raise
|
||||
|
||||
def unmount_config_drive(self):
|
||||
self.exec_command('sudo umount /mnt')
|
||||
|
@ -14,7 +14,6 @@
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from tempest.common import utils
|
||||
from tempest.common import waiters
|
||||
@ -94,22 +93,13 @@ class TestServerBasicOps(manager.ScenarioTest):
|
||||
result = self.servers_client.show_password(self.instance['id'])
|
||||
self.assertEqual(data, result['password'])
|
||||
|
||||
def _mount_config_drive(self):
|
||||
cmd_blkid = 'blkid | grep -i config-2'
|
||||
result = self.ssh_client.exec_command(cmd_blkid)
|
||||
dev_name = re.match('([^:]+)', result).group()
|
||||
self.ssh_client.exec_command('sudo mount %s /mnt' % dev_name)
|
||||
|
||||
def _unmount_config_drive(self):
|
||||
self.ssh_client.exec_command('sudo umount /mnt')
|
||||
|
||||
def verify_metadata_on_config_drive(self):
|
||||
if self.run_ssh and CONF.compute_feature_enabled.config_drive:
|
||||
# Verify metadata on config_drive
|
||||
self._mount_config_drive()
|
||||
self.ssh_client.mount_config_drive()
|
||||
cmd_md = 'sudo cat /mnt/openstack/latest/meta_data.json'
|
||||
result = self.ssh_client.exec_command(cmd_md)
|
||||
self._unmount_config_drive()
|
||||
self.ssh_client.unmount_config_drive()
|
||||
result = json.loads(result)
|
||||
self.assertIn('meta', result)
|
||||
msg = ('Failed while verifying metadata on config_drive on server.'
|
||||
@ -119,10 +109,10 @@ class TestServerBasicOps(manager.ScenarioTest):
|
||||
def verify_networkdata_on_config_drive(self):
|
||||
if self.run_ssh and CONF.compute_feature_enabled.config_drive:
|
||||
# Verify network data on config_drive
|
||||
self._mount_config_drive()
|
||||
self.ssh_client.mount_config_drive()
|
||||
cmd_md = 'sudo cat /mnt/openstack/latest/network_data.json'
|
||||
result = self.ssh_client.exec_command(cmd_md)
|
||||
self._unmount_config_drive()
|
||||
self.ssh_client.unmount_config_drive()
|
||||
result = json.loads(result)
|
||||
self.assertIn('services', result)
|
||||
self.assertIn('links', result)
|
||||
|
Loading…
x
Reference in New Issue
Block a user