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