Merge "Refactor volume functional test in volume v1"

This commit is contained in:
Jenkins 2017-02-14 08:01:03 +00:00 committed by Gerrit Code Review
commit f106b4f022

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import time
import uuid
from openstackclient.tests.functional.volume.v1 import common
@ -18,71 +20,189 @@ from openstackclient.tests.functional.volume.v1 import common
class VolumeTests(common.BaseVolumeTests):
"""Functional tests for volume. """
NAME = uuid.uuid4().hex
OTHER_NAME = uuid.uuid4().hex
HEADERS = ['"Display Name"']
FIELDS = ['display_name']
def test_volume_create_and_delete(self):
"""Test create, delete multiple"""
name1 = uuid.uuid4().hex
cmd_output = json.loads(self.openstack(
'volume create -f json ' +
'--size 1 ' +
name1
))
self.assertEqual(
1,
cmd_output["size"],
)
@classmethod
def setUpClass(cls):
super(VolumeTests, cls).setUpClass()
opts = cls.get_opts(cls.FIELDS)
raw_output = cls.openstack('volume create --size 1 ' + cls.NAME + opts)
expected = cls.NAME + '\n'
cls.assertOutput(expected, raw_output)
name2 = uuid.uuid4().hex
cmd_output = json.loads(self.openstack(
'volume create -f json ' +
'--size 2 ' +
name2
))
self.assertEqual(
2,
cmd_output["size"],
)
@classmethod
def tearDownClass(cls):
# Rename test
raw_output = cls.openstack(
'volume set --name ' + cls.OTHER_NAME + ' ' + cls.NAME)
cls.assertOutput('', raw_output)
# Delete test
raw_output = cls.openstack('volume delete ' + cls.OTHER_NAME)
cls.assertOutput('', raw_output)
self.wait_for("volume", name1, "available")
self.wait_for("volume", name2, "available")
del_output = self.openstack('volume delete ' + name1 + ' ' + name2)
self.assertOutput('', del_output)
def test_volume_list(self):
opts = self.get_opts(self.HEADERS)
raw_output = self.openstack('volume list' + opts)
self.assertIn(self.NAME, raw_output)
"""Test create, list filter"""
name1 = uuid.uuid4().hex
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):
opts = self.get_opts(self.FIELDS)
raw_output = self.openstack('volume show ' + self.NAME + opts)
self.assertEqual(self.NAME + "\n", raw_output)
name2 = uuid.uuid4().hex
cmd_output = json.loads(self.openstack(
'volume create -f json ' +
'--size 2 ' +
name2
))
self.addCleanup(self.openstack, 'volume delete ' + name2)
self.assertEqual(
2,
cmd_output["size"],
)
self.wait_for("volume", name2, "available")
def test_volume_properties(self):
# Test list
cmd_output = json.loads(self.openstack(
'volume list -f json '
))
names = [x["Display Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertIn(name2, names)
# Test list --long
cmd_output = json.loads(self.openstack(
'volume list -f json --long'
))
bootable = [x["Bootable"] for x in cmd_output]
self.assertIn('false', bootable)
# Test list --name
cmd_output = json.loads(self.openstack(
'volume list -f json ' +
'--name ' + name1
))
names = [x["Display Name"] for x in cmd_output]
self.assertIn(name1, names)
self.assertNotIn(name2, names)
def test_volume_set_and_unset(self):
"""Tests create volume, set, unset, show, delete"""
name = uuid.uuid4().hex
cmd_output = json.loads(self.openstack(
'volume create -f json ' +
'--size 1 ' +
'--description aaaa ' +
'--property Alpha=a ' +
name
))
self.assertEqual(
name,
cmd_output["display_name"],
)
self.assertEqual(
1,
cmd_output["size"],
)
self.assertEqual(
'aaaa',
cmd_output["display_description"],
)
self.assertEqual(
"Alpha='a'",
cmd_output["properties"],
)
self.assertEqual(
'false',
cmd_output["bootable"],
)
self.wait_for("volume", name, "available")
# Test volume set
new_name = uuid.uuid4().hex
self.addCleanup(self.openstack, 'volume delete ' + new_name)
raw_output = self.openstack(
'volume set --property a=b --property c=d ' + self.NAME)
self.assertEqual("", raw_output)
opts = self.get_opts(["properties"])
raw_output = self.openstack('volume show ' + self.NAME + opts)
self.assertEqual("a='b', c='d'\n", raw_output)
'volume set ' +
'--name ' + new_name +
' --size 2 ' +
'--description bbbb ' +
'--property Alpha=c ' +
'--property Beta=b ' +
'--bootable ' +
name,
)
self.assertOutput('', raw_output)
raw_output = self.openstack('volume unset --property a ' + self.NAME)
self.assertEqual("", raw_output)
raw_output = self.openstack('volume show ' + self.NAME + opts)
self.assertEqual("c='d'\n", raw_output)
cmd_output = json.loads(self.openstack(
'volume show -f json ' +
new_name
))
self.assertEqual(
new_name,
cmd_output["display_name"],
)
self.assertEqual(
2,
cmd_output["size"],
)
self.assertEqual(
'bbbb',
cmd_output["display_description"],
)
self.assertEqual(
"Alpha='c', Beta='b'",
cmd_output["properties"],
)
self.assertEqual(
'true',
cmd_output["bootable"],
)
def test_volume_set(self):
self.openstack('volume set --description RAMAC ' + self.NAME)
opts = self.get_opts(["display_description", "display_name"])
raw_output = self.openstack('volume show ' + self.NAME + opts)
self.assertEqual("RAMAC\n" + self.NAME + "\n", raw_output)
# Test volume unset
raw_output = self.openstack(
'volume unset ' +
'--property Alpha ' +
new_name,
)
self.assertOutput('', raw_output)
def test_volume_set_size(self):
self.openstack('volume set --size 2 ' + self.NAME)
opts = self.get_opts(["display_name", "size"])
raw_output = self.openstack('volume show ' + self.NAME + opts)
self.assertEqual(self.NAME + "\n2\n", raw_output)
cmd_output = json.loads(self.openstack(
'volume show -f json ' +
new_name
))
self.assertEqual(
"Beta='b'",
cmd_output["properties"],
)
def test_volume_set_bootable(self):
self.openstack('volume set --bootable ' + self.NAME)
opts = self.get_opts(["bootable"])
raw_output = self.openstack('volume show ' + self.NAME + opts)
self.assertEqual("true\n", raw_output)
self.openstack('volume set --non-bootable ' + self.NAME)
opts = self.get_opts(["bootable"])
raw_output = self.openstack('volume show ' + self.NAME + opts)
self.assertEqual("false\n", raw_output)
def wait_for(self, check_type, check_name, desired_status, wait=120,
interval=5, failures=['ERROR']):
status = "notset"
total_sleep = 0
opts = self.get_opts(['status'])
while total_sleep < wait:
status = self.openstack(check_type + ' show ' + check_name + opts)
status = status.rstrip()
print('Checking {} {} Waiting for {} current status: {}'
.format(check_type, check_name, desired_status, status))
if status == desired_status:
break
self.assertNotIn(status, failures)
time.sleep(interval)
total_sleep += interval
self.assertEqual(desired_status, status)