functional test for volume
Rework functional tests to remove resource create/delete from setupClass() and teardownClass() methods. Add test for more command options Change-Id: I2b6ad1fce26f04c11ed43f8d73515fde4a7d09af
This commit is contained in:
parent
4d3cfb9142
commit
07ade2266c
@ -10,6 +10,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -19,118 +20,220 @@ from openstackclient.tests.functional.volume.v2 import common
|
|||||||
class VolumeTests(common.BaseVolumeTests):
|
class VolumeTests(common.BaseVolumeTests):
|
||||||
"""Functional tests for volume. """
|
"""Functional tests for volume. """
|
||||||
|
|
||||||
NAME = uuid.uuid4().hex
|
def test_volume_delete(self):
|
||||||
SNAPSHOT_NAME = uuid.uuid4().hex
|
"""Test create, delete multiple"""
|
||||||
VOLUME_FROM_SNAPSHOT_NAME = uuid.uuid4().hex
|
name1 = uuid.uuid4().hex
|
||||||
OTHER_NAME = uuid.uuid4().hex
|
cmd_output = json.loads(self.openstack(
|
||||||
HEADERS = ['"Display Name"']
|
'volume create -f json ' +
|
||||||
FIELDS = ['name']
|
'--size 1 ' +
|
||||||
|
name1
|
||||||
|
))
|
||||||
|
self.assertEqual(
|
||||||
|
1,
|
||||||
|
cmd_output["size"],
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
name2 = uuid.uuid4().hex
|
||||||
def setUpClass(cls):
|
cmd_output = json.loads(self.openstack(
|
||||||
super(VolumeTests, cls).setUpClass()
|
'volume create -f json ' +
|
||||||
opts = cls.get_opts(cls.FIELDS)
|
'--size 2 ' +
|
||||||
|
name2
|
||||||
|
))
|
||||||
|
self.assertEqual(
|
||||||
|
2,
|
||||||
|
cmd_output["size"],
|
||||||
|
)
|
||||||
|
|
||||||
# Create test volume
|
self.wait_for("volume", name1, "available")
|
||||||
raw_output = cls.openstack('volume create --size 1 ' + cls.NAME + opts)
|
self.wait_for("volume", name2, "available")
|
||||||
expected = cls.NAME + '\n'
|
del_output = self.openstack('volume delete ' + name1 + ' ' + name2)
|
||||||
cls.assertOutput(expected, raw_output)
|
self.assertOutput('', del_output)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
# Rename test volume
|
|
||||||
raw_output = cls.openstack(
|
|
||||||
'volume set --name ' + cls.OTHER_NAME + ' ' + cls.NAME)
|
|
||||||
cls.assertOutput('', raw_output)
|
|
||||||
|
|
||||||
# Set volume state
|
|
||||||
cls.openstack('volume set --state error ' + cls.OTHER_NAME)
|
|
||||||
opts = cls.get_opts(["status"])
|
|
||||||
raw_output_status = cls.openstack(
|
|
||||||
'volume show ' + cls.OTHER_NAME + opts)
|
|
||||||
|
|
||||||
# Delete test volume
|
|
||||||
raw_output = cls.openstack('volume delete ' + cls.OTHER_NAME)
|
|
||||||
cls.assertOutput('', raw_output)
|
|
||||||
cls.assertOutput('error\n', raw_output_status)
|
|
||||||
|
|
||||||
def test_volume_list(self):
|
def test_volume_list(self):
|
||||||
opts = self.get_opts(self.HEADERS)
|
"""Test create, list filter"""
|
||||||
raw_output = self.openstack('volume list' + opts)
|
name1 = uuid.uuid4().hex
|
||||||
self.assertIn(self.NAME, raw_output)
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'volume create -f json ' +
|
||||||
|
'--size 1 ' +
|
||||||
|
name1
|
||||||
|
))
|
||||||
|
self.addCleanup(self.openstack, 'volume delete ' + name1)
|
||||||
|
self.assertEqual(
|
||||||
|
1,
|
||||||
|
cmd_output["size"],
|
||||||
|
)
|
||||||
|
self.wait_for("volume", name1, "available")
|
||||||
|
|
||||||
def test_volume_show(self):
|
name2 = uuid.uuid4().hex
|
||||||
opts = self.get_opts(self.FIELDS)
|
cmd_output = json.loads(self.openstack(
|
||||||
raw_output = self.openstack('volume show ' + self.NAME + opts)
|
'volume create -f json ' +
|
||||||
self.assertEqual(self.NAME + "\n", raw_output)
|
'--size 2 ' +
|
||||||
|
name2
|
||||||
def test_volume_properties(self):
|
))
|
||||||
|
self.addCleanup(self.openstack, 'volume delete ' + name2)
|
||||||
|
self.assertEqual(
|
||||||
|
2,
|
||||||
|
cmd_output["size"],
|
||||||
|
)
|
||||||
|
self.wait_for("volume", name2, "available")
|
||||||
raw_output = self.openstack(
|
raw_output = self.openstack(
|
||||||
'volume set --property a=b --property c=d ' + self.NAME)
|
'volume set ' +
|
||||||
self.assertEqual("", raw_output)
|
'--state error ' +
|
||||||
opts = self.get_opts(["properties"])
|
name2
|
||||||
raw_output = self.openstack('volume show ' + self.NAME + opts)
|
)
|
||||||
self.assertEqual("a='b', c='d'\n", raw_output)
|
self.assertOutput('', raw_output)
|
||||||
|
|
||||||
raw_output = self.openstack('volume unset --property a ' + self.NAME)
|
# Test list --long
|
||||||
self.assertEqual("", raw_output)
|
cmd_output = json.loads(self.openstack(
|
||||||
raw_output = self.openstack('volume show ' + self.NAME + opts)
|
'volume list -f json ' +
|
||||||
self.assertEqual("c='d'\n", raw_output)
|
'--long'
|
||||||
|
))
|
||||||
|
names = [x["Display Name"] for x in cmd_output]
|
||||||
|
self.assertIn(name1, names)
|
||||||
|
self.assertIn(name2, names)
|
||||||
|
|
||||||
|
# Test list --status
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'volume list -f json ' +
|
||||||
|
'--status error'
|
||||||
|
))
|
||||||
|
names = [x["Display Name"] for x in cmd_output]
|
||||||
|
self.assertNotIn(name1, names)
|
||||||
|
self.assertIn(name2, names)
|
||||||
|
|
||||||
|
# TODO(qiangjiahui): Add project option to filter tests when we can
|
||||||
|
# specify volume with project
|
||||||
|
|
||||||
def test_volume_set(self):
|
def test_volume_set(self):
|
||||||
discription = uuid.uuid4().hex
|
"""Tests create volume, set, unset, show, delete"""
|
||||||
self.openstack('volume set --description ' + discription + ' ' +
|
name = uuid.uuid4().hex
|
||||||
self.NAME)
|
new_name = name + "_"
|
||||||
opts = self.get_opts(["description", "name"])
|
cmd_output = json.loads(self.openstack(
|
||||||
raw_output = self.openstack('volume show ' + self.NAME + opts)
|
'volume create -f json ' +
|
||||||
self.assertEqual(discription + "\n" + self.NAME + "\n", raw_output)
|
'--size 1 ' +
|
||||||
|
'--description aaaa ' +
|
||||||
|
'--property Alpha=a ' +
|
||||||
|
name
|
||||||
|
))
|
||||||
|
self.addCleanup(self.openstack, 'volume delete ' + new_name)
|
||||||
|
self.assertEqual(
|
||||||
|
name,
|
||||||
|
cmd_output["name"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
1,
|
||||||
|
cmd_output["size"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'aaaa',
|
||||||
|
cmd_output["description"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
"Alpha='a'",
|
||||||
|
cmd_output["properties"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'false',
|
||||||
|
cmd_output["bootable"],
|
||||||
|
)
|
||||||
|
self.wait_for("volume", name, "available")
|
||||||
|
|
||||||
def test_volume_set_size(self):
|
# Test volume set
|
||||||
self.openstack('volume set --size 2 ' + self.NAME)
|
raw_output = self.openstack(
|
||||||
opts = self.get_opts(["name", "size"])
|
'volume set ' +
|
||||||
raw_output = self.openstack('volume show ' + self.NAME + opts)
|
'--name ' + new_name +
|
||||||
self.assertEqual(self.NAME + "\n2\n", raw_output)
|
' --size 2 ' +
|
||||||
|
'--description bbbb ' +
|
||||||
|
'--property Alpha=c ' +
|
||||||
|
'--property Beta=b ' +
|
||||||
|
'--bootable ' +
|
||||||
|
name,
|
||||||
|
)
|
||||||
|
self.assertOutput('', raw_output)
|
||||||
|
|
||||||
def test_volume_set_bootable(self):
|
cmd_output = json.loads(self.openstack(
|
||||||
self.openstack('volume set --bootable ' + self.NAME)
|
'volume show -f json ' +
|
||||||
opts = self.get_opts(["bootable"])
|
new_name
|
||||||
raw_output = self.openstack('volume show ' + self.NAME + opts)
|
))
|
||||||
self.assertEqual("true\n", raw_output)
|
self.assertEqual(
|
||||||
|
new_name,
|
||||||
|
cmd_output["name"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
2,
|
||||||
|
cmd_output["size"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'bbbb',
|
||||||
|
cmd_output["description"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
"Alpha='c', Beta='b'",
|
||||||
|
cmd_output["properties"],
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
'true',
|
||||||
|
cmd_output["bootable"],
|
||||||
|
)
|
||||||
|
|
||||||
self.openstack('volume set --non-bootable ' + self.NAME)
|
# Test volume unset
|
||||||
opts = self.get_opts(["bootable"])
|
raw_output = self.openstack(
|
||||||
raw_output = self.openstack('volume show ' + self.NAME + opts)
|
'volume unset ' +
|
||||||
self.assertEqual("false\n", raw_output)
|
'--property Alpha ' +
|
||||||
|
new_name,
|
||||||
|
)
|
||||||
|
self.assertOutput('', raw_output)
|
||||||
|
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'volume show -f json ' +
|
||||||
|
new_name
|
||||||
|
))
|
||||||
|
self.assertEqual(
|
||||||
|
"Beta='b'",
|
||||||
|
cmd_output["properties"],
|
||||||
|
)
|
||||||
|
|
||||||
def test_volume_snapshot(self):
|
def test_volume_snapshot(self):
|
||||||
opts = self.get_opts(self.FIELDS)
|
"""Tests volume create from snapshot"""
|
||||||
|
|
||||||
# Create snapshot from test volume
|
volume_name = uuid.uuid4().hex
|
||||||
raw_output = self.openstack('volume snapshot create ' +
|
snapshot_name = uuid.uuid4().hex
|
||||||
self.SNAPSHOT_NAME +
|
# Make a snapshot
|
||||||
' --volume ' + self.NAME + opts)
|
cmd_output = json.loads(self.openstack(
|
||||||
expected = self.SNAPSHOT_NAME + '\n'
|
'volume create -f json ' +
|
||||||
self.assertOutput(expected, raw_output)
|
'--size 1 ' +
|
||||||
self.wait_for("volume snapshot", self.SNAPSHOT_NAME, "available")
|
volume_name
|
||||||
|
))
|
||||||
|
self.wait_for("volume", volume_name, "available")
|
||||||
|
self.assertEqual(
|
||||||
|
volume_name,
|
||||||
|
cmd_output["name"],
|
||||||
|
)
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'volume snapshot create -f json ' +
|
||||||
|
snapshot_name +
|
||||||
|
' --volume ' + volume_name
|
||||||
|
))
|
||||||
|
self.wait_for("volume snapshot", snapshot_name, "available")
|
||||||
|
|
||||||
# Create volume from snapshot
|
name = uuid.uuid4().hex
|
||||||
raw_output = self.openstack('volume create --size 2 --snapshot ' +
|
cmd_output = json.loads(self.openstack(
|
||||||
self.SNAPSHOT_NAME + ' ' +
|
'volume create -f json ' +
|
||||||
self.VOLUME_FROM_SNAPSHOT_NAME + opts)
|
'--snapshot ' + snapshot_name +
|
||||||
expected = self.VOLUME_FROM_SNAPSHOT_NAME + '\n'
|
' ' + name
|
||||||
self.assertOutput(expected, raw_output)
|
))
|
||||||
self.wait_for("volume", self.VOLUME_FROM_SNAPSHOT_NAME, "available")
|
self.addCleanup(self.openstack, 'volume delete ' + name)
|
||||||
|
self.addCleanup(self.openstack, 'volume delete ' + volume_name)
|
||||||
|
self.assertEqual(
|
||||||
|
name,
|
||||||
|
cmd_output["name"],
|
||||||
|
)
|
||||||
|
self.wait_for("volume", name, "available")
|
||||||
|
|
||||||
# Delete volume that create from snapshot
|
# Delete snapshot
|
||||||
raw_output = self.openstack('volume delete ' +
|
|
||||||
self.VOLUME_FROM_SNAPSHOT_NAME)
|
|
||||||
self.assertOutput('', raw_output)
|
|
||||||
|
|
||||||
# Delete test snapshot
|
|
||||||
raw_output = self.openstack(
|
raw_output = self.openstack(
|
||||||
'volume snapshot delete ' + self.SNAPSHOT_NAME)
|
'volume snapshot delete ' + snapshot_name)
|
||||||
self.assertOutput('', raw_output)
|
self.assertOutput('', raw_output)
|
||||||
self.wait_for("volume", self.NAME, "available")
|
|
||||||
|
|
||||||
def wait_for(self, check_type, check_name, desired_status, wait=120,
|
def wait_for(self, check_type, check_name, desired_status, wait=120,
|
||||||
interval=5, failures=['ERROR']):
|
interval=5, failures=['ERROR']):
|
||||||
|
Loading…
Reference in New Issue
Block a user