Extend while attached volume

Adding two tests scenarios for extending bootable volumes in Cinder.

Co-Authored-By: Benny Kopilov <bkopilov@redhat.com>
Change-Id: I3b7f2b4a7bfad96e8623d2c895d09815e4069c9c
This commit is contained in:
Sofia Enriquez 2020-07-24 16:43:13 +00:00
parent 6e36e2bd98
commit 0d33745671
1 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,139 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from tempest.common import utils
from tempest.common import waiters
from tempest import config
from tempest.lib import decorators
from tempest.scenario import manager
CONF = config.CONF
LOG = logging.getLogger(__name__)
class TestVolumeExtendWhileAttached(manager.ScenarioTest):
"""This test case attempts to reproduce the following steps:
* Create a Cinder volume
* Create an instance and attach the volume
* Write some data to the volume
* Extend the attached volume
* Check volume's data
* Check volume's size
* Check the extend operation is correct
"""
volume_min_microversion = '3.42'
@classmethod
def skip_checks(cls):
super(TestVolumeExtendWhileAttached, cls).skip_checks()
if not CONF.volume_feature_enabled.extend_attached_volume:
raise cls.skipException('Extend attached volumes is not enabled.')
def _create_volume(self):
return self.create_volume()
def setUp(self):
super(TestVolumeExtendWhileAttached, self).setUp()
self.volume = self._create_volume()
@decorators.idempotent_id('12ba5c30-bb18-4b23-97f4-9a9e97e91c80')
@utils.services('compute', 'volume')
def test_volume_extend_while_attached_to_instance(self):
# keypair and security group allows ssh to instance
keypair1 = self.create_keypair()
security_group1 = self._create_security_group()
# Create an instance with ssh access
kwargs = {'key_name': keypair1['name'],
'security_groups': [{'name': security_group1['name']}]}
server = self.create_server(**kwargs)
ip_server = self.get_server_ip(server)
private_key = keypair1['private_key']
# attach
attach_info = self.nova_volume_attach(server, self.volume)
self.addCleanup(self.nova_volume_detach, server, self.volume)
device = attach_info['attachments'][0]['device']
# write content to volume on instance
timestamp = self.create_timestamp(ip_server,
private_key=keypair1['private_key'],
server=server)
original_size = self.volume['size']
expected_size = original_size * 2
# Check the size manually
ssh_client = self.get_remote_client(ip_server,
private_key=private_key,
server=server)
cmd = "sudo blockdev --getsize64 " + device
device_size = int(ssh_client.exec_command(cmd)) / (1024**3)
self.assertEqual(original_size, device_size)
# extend volume while attahced to instance
self.volumes_client.extend_volume(self.volume['id'],
new_size=expected_size)
waiters.wait_for_volume_resource_status(self.volumes_client,
self.volume['id'], 'in-use')
# verify the data
timestamp2 = self.get_timestamp(ip_server,
private_key=private_key,
server=server)
self.assertEqual(timestamp, timestamp2)
# verify disk size changed in the instance
volume = self.volumes_client.show_volume(self.volume['id'])['volume']
self.assertEqual(volume['size'], expected_size)
class TestEncryptedVolumeExtendWhileAttached(TestVolumeExtendWhileAttached,
manager.EncryptionScenarioTest):
"""This test case attempts to reproduce the following steps:
* Create a server.
* Create in Cinder an encrypted bootable volume and attach it.
* Write some data to the volume
* Extend the attached volume.
* Check volume's data
* Check volume size.
* Check the extend operation is correct.
"""
def create_encrypted_volume(self, encryption_provider='luks',
key_size=256, cipher='aes-xts-plain64',
size=1, control_location='front-end',
volume_type=None, imageRef=None):
if not size:
size = 1
# in case volume_type already created
if not volume_type:
volume_type = self.create_volume_type()
self.create_encryption_type(type_id=volume_type['id'],
provider=encryption_provider,
key_size=key_size,
cipher=cipher,
control_location=control_location)
return self.create_volume(volume_type=volume_type['name'],
imageRef=imageRef, size=size)
def _create_volume(self):
return self.create_encrypted_volume()
def setUp(self):
super(TestEncryptedVolumeExtendWhileAttached, self).setUp()