From 9733d0e1520cae67e084ee63da98aa3de4be840e Mon Sep 17 00:00:00 2001 From: Jerry Cai Date: Wed, 19 Mar 2014 15:50:49 +0800 Subject: [PATCH] Volume size could be specified to create volume 1. Provide a "volume_size" config at VolumeGroup 2. Make size as optional prameter, modify all volumes_client to read the size from CONf if size is None. 3. Modify the testcase: test_volume_create_get_update _delete_from_image to call create_volume with no size parameter specified. Change-Id: I2897f6d6bd970f73867f56d9d23a768cafcbfd80 Closes-Bug: #1293885 --- etc/tempest.conf.sample | 6 +++++- tempest/api/volume/test_volumes_get.py | 3 +-- tempest/config.py | 5 ++++- tempest/services/volume/json/volumes_client.py | 8 ++++++-- tempest/services/volume/v2/json/volumes_client.py | 8 ++++++-- tempest/services/volume/v2/xml/volumes_client.py | 8 ++++++-- tempest/services/volume/xml/volumes_client.py | 8 ++++++-- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample index 761a07748c..fe383bcd9c 100644 --- a/etc/tempest.conf.sample +++ b/etc/tempest.conf.sample @@ -193,7 +193,7 @@ # admin credentials are known. (boolean value) #allow_tenant_isolation=false -# Valid secondary image reference to be used in tests. (string +# Valid primary image reference to be used in tests. (string # value) #image_ref={$IMAGE_ID} @@ -940,6 +940,10 @@ # value) #disk_format=raw +# Default size in GB for volumes created by volumes tests +# (integer value) +#volume_size=1 + [volume-feature-enabled] diff --git a/tempest/api/volume/test_volumes_get.py b/tempest/api/volume/test_volumes_get.py index be5d76bbbe..58da440ea6 100644 --- a/tempest/api/volume/test_volumes_get.py +++ b/tempest/api/volume/test_volumes_get.py @@ -51,8 +51,7 @@ class VolumesGetTest(base.BaseVolumeV1Test): v_name = data_utils.rand_name('Volume') metadata = {'Type': 'Test'} # Create a volume - resp, volume = self.client.create_volume(size=1, - display_name=v_name, + resp, volume = self.client.create_volume(display_name=v_name, metadata=metadata, **kwargs) self.assertEqual(200, resp.status) diff --git a/tempest/config.py b/tempest/config.py index b0945bb417..7de2b44c4e 100644 --- a/tempest/config.py +++ b/tempest/config.py @@ -126,7 +126,7 @@ ComputeGroup = [ "OpenStack Identity API admin credentials are known."), cfg.StrOpt('image_ref', default="{$IMAGE_ID}", - help="Valid secondary image reference to be used in tests."), + help="Valid primary image reference to be used in tests."), cfg.StrOpt('image_ref_alt', default="{$IMAGE_ID_ALT}", help="Valid secondary image reference to be used in tests."), @@ -441,6 +441,9 @@ VolumeGroup = [ cfg.StrOpt('disk_format', default='raw', help='Disk format to use when copying a volume to image'), + cfg.IntOpt('volume_size', + default=1, + help='Default size in GB for volumes created by volumes tests'), ] volume_feature_group = cfg.OptGroup(name='volume-feature-enabled', diff --git a/tempest/services/volume/json/volumes_client.py b/tempest/services/volume/json/volumes_client.py index e4d2e8dbb9..b55a0373e4 100644 --- a/tempest/services/volume/json/volumes_client.py +++ b/tempest/services/volume/json/volumes_client.py @@ -67,10 +67,10 @@ class VolumesClientJSON(rest_client.RestClient): body = json.loads(body) return resp, body['volume'] - def create_volume(self, size, **kwargs): + def create_volume(self, size=None, **kwargs): """ Creates a new Volume. - size(Required): Size of volume in GB. + size: Size of volume in GB. Following optional keyword arguments are accepted: display_name: Optional Volume Name. metadata: A dictionary of values to be used as metadata. @@ -78,6 +78,10 @@ class VolumesClientJSON(rest_client.RestClient): snapshot_id: When specified the volume is created from this snapshot imageRef: When specified the volume is created from this image """ + # for bug #1293885: + # If no size specified, read volume size from CONF + if size is None: + size = CONF.volume.volume_size post_body = {'size': size} post_body.update(kwargs) post_body = json.dumps({'volume': post_body}) diff --git a/tempest/services/volume/v2/json/volumes_client.py b/tempest/services/volume/v2/json/volumes_client.py index 5bfa75fc1d..df20a2ac8a 100644 --- a/tempest/services/volume/v2/json/volumes_client.py +++ b/tempest/services/volume/v2/json/volumes_client.py @@ -68,10 +68,10 @@ class VolumesV2ClientJSON(rest_client.RestClient): body = json.loads(body) return resp, body['volume'] - def create_volume(self, size, **kwargs): + def create_volume(self, size=None, **kwargs): """ Creates a new Volume. - size(Required): Size of volume in GB. + size: Size of volume in GB. Following optional keyword arguments are accepted: name: Optional Volume Name. metadata: A dictionary of values to be used as metadata. @@ -79,6 +79,10 @@ class VolumesV2ClientJSON(rest_client.RestClient): snapshot_id: When specified the volume is created from this snapshot imageRef: When specified the volume is created from this image """ + # for bug #1293885: + # If no size specified, read volume size from CONF + if size is None: + size = CONF.volume.volume_size post_body = {'size': size} post_body.update(kwargs) post_body = json.dumps({'volume': post_body}) diff --git a/tempest/services/volume/v2/xml/volumes_client.py b/tempest/services/volume/v2/xml/volumes_client.py index e735a657e4..1fdaf19b0f 100644 --- a/tempest/services/volume/v2/xml/volumes_client.py +++ b/tempest/services/volume/v2/xml/volumes_client.py @@ -117,10 +117,10 @@ class VolumesV2ClientXML(rest_client.RestClient): body = self._check_if_bootable(body) return resp, body - def create_volume(self, size, **kwargs): + def create_volume(self, size=None, **kwargs): """Creates a new Volume. - :param size: Size of volume in GB. (Required) + :param size: Size of volume in GB. :param name: Optional Volume Name. :param metadata: An optional dictionary of values for metadata. :param volume_type: Optional Name of volume_type for the volume @@ -129,6 +129,10 @@ class VolumesV2ClientXML(rest_client.RestClient): :param imageRef: When specified the volume is created from this image """ + # for bug #1293885: + # If no size specified, read volume size from CONF + if size is None: + size = CONF.volume.volume_size # NOTE(afazekas): it should use a volume namespace volume = common.Element("volume", xmlns=common.XMLNS_11, size=size) diff --git a/tempest/services/volume/xml/volumes_client.py b/tempest/services/volume/xml/volumes_client.py index 6866dad9e8..65bc321be8 100644 --- a/tempest/services/volume/xml/volumes_client.py +++ b/tempest/services/volume/xml/volumes_client.py @@ -118,10 +118,10 @@ class VolumesClientXML(rest_client.RestClient): body = self._check_if_bootable(body) return resp, body - def create_volume(self, size, **kwargs): + def create_volume(self, size=None, **kwargs): """Creates a new Volume. - :param size: Size of volume in GB. (Required) + :param size: Size of volume in GB. :param display_name: Optional Volume Name. :param metadata: An optional dictionary of values for metadata. :param volume_type: Optional Name of volume_type for the volume @@ -130,6 +130,10 @@ class VolumesClientXML(rest_client.RestClient): :param imageRef: When specified the volume is created from this image """ + # for bug #1293885: + # If no size specified, read volume size from CONF + if size is None: + size = CONF.volume.volume_size # NOTE(afazekas): it should use a volume namespace volume = common.Element("volume", xmlns=common.XMLNS_11, size=size)