summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJirayut Nimsaeng <wingth@gmail.com>2016-04-11 15:54:23 +0700
committerJirayut Nimsaeng <wingth@gmail.com>2016-04-15 16:13:02 +0000
commite12837067698062ce3fea89dd543f1cab39866c1 (patch)
tree1bcdae7aa3cd8005fcad89a049e597a747a63996
parent52a12e743ea1047b6c34cd66dcb60cd61638ce1f (diff)
downloadpython-openstackclient-e12837067698062ce3fea89dd543f1cab39866c1.tar.gz
Fix wrong attribute name and add functional test for --snapshot
Change-Id: I91f2091ef06a55bcf5373d1beeea2dd81e9f1334 Closes-Bug: #1567895
-rw-r--r--functional/tests/volume/v2/test_volume.py54
-rw-r--r--openstackclient/tests/volume/v2/test_volume.py43
2 files changed, 95 insertions, 2 deletions
diff --git a/functional/tests/volume/v2/test_volume.py b/functional/tests/volume/v2/test_volume.py
index b0775183..9c7f11a1 100644
--- a/functional/tests/volume/v2/test_volume.py
+++ b/functional/tests/volume/v2/test_volume.py
@@ -11,6 +11,7 @@
# under the License.
import os
+import time
import uuid
from functional.common import test
@@ -20,6 +21,8 @@ class VolumeTests(test.TestCase):
"""Functional tests for volume. """
NAME = uuid.uuid4().hex
+ SNAPSHOT_NAME = uuid.uuid4().hex
+ VOLUME_FROM_SNAPSHOT_NAME = uuid.uuid4().hex
OTHER_NAME = uuid.uuid4().hex
HEADERS = ['"Display Name"']
FIELDS = ['name']
@@ -28,17 +31,20 @@ class VolumeTests(test.TestCase):
def setUpClass(cls):
os.environ['OS_VOLUME_API_VERSION'] = '2'
opts = cls.get_show_opts(cls.FIELDS)
+
+ # Create test volume
raw_output = cls.openstack('volume create --size 1 ' + cls.NAME + opts)
expected = cls.NAME + '\n'
cls.assertOutput(expected, raw_output)
@classmethod
def tearDownClass(cls):
- # Rename test
+ # Rename test volume
raw_output = cls.openstack(
'volume set --name ' + cls.OTHER_NAME + ' ' + cls.NAME)
cls.assertOutput('', raw_output)
- # Delete test
+
+ # Delete test volume
raw_output = cls.openstack('volume delete ' + cls.OTHER_NAME)
cls.assertOutput('', raw_output)
@@ -78,3 +84,47 @@ class VolumeTests(test.TestCase):
opts = self.get_show_opts(["name", "size"])
raw_output = self.openstack('volume show ' + self.NAME + opts)
self.assertEqual(self.NAME + "\n2\n", raw_output)
+
+ def test_volume_snapshot(self):
+ opts = self.get_show_opts(self.FIELDS)
+
+ # Create snapshot from test volume
+ raw_output = self.openstack('snapshot create ' + self.NAME +
+ ' --name ' + self.SNAPSHOT_NAME + opts)
+ expected = self.SNAPSHOT_NAME + '\n'
+ self.assertOutput(expected, raw_output)
+ self.wait_for("snapshot", self.SNAPSHOT_NAME, "available")
+
+ # Create volume from snapshot
+ raw_output = self.openstack('volume create --size 2 --snapshot ' +
+ self.SNAPSHOT_NAME + ' ' +
+ self.VOLUME_FROM_SNAPSHOT_NAME + opts)
+ expected = self.VOLUME_FROM_SNAPSHOT_NAME + '\n'
+ self.assertOutput(expected, raw_output)
+ self.wait_for("volume", self.VOLUME_FROM_SNAPSHOT_NAME, "available")
+
+ # Delete volume that create from snapshot
+ raw_output = self.openstack('volume delete ' +
+ self.VOLUME_FROM_SNAPSHOT_NAME)
+ self.assertOutput('', raw_output)
+
+ # Delete test snapshot
+ raw_output = self.openstack('snapshot delete ' + self.SNAPSHOT_NAME)
+ self.assertOutput('', 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_show_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)
diff --git a/openstackclient/tests/volume/v2/test_volume.py b/openstackclient/tests/volume/v2/test_volume.py
index 12253806..e4ac7c10 100644
--- a/openstackclient/tests/volume/v2/test_volume.py
+++ b/openstackclient/tests/volume/v2/test_volume.py
@@ -14,6 +14,7 @@
import copy
+import mock
from mock import call
from openstackclient.common import utils
@@ -40,6 +41,9 @@ class TestVolume(volume_fakes.TestVolume):
self.images_mock = self.app.client_manager.image.images
self.images_mock.reset_mock()
+ self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
+ self.snapshots_mock.reset_mock()
+
def setup_volumes_mock(self, count):
volumes = volume_fakes.FakeVolume.create_volumes(count=count)
@@ -376,6 +380,45 @@ class TestVolumeCreate(TestVolume):
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, data)
+ def test_volume_create_with_snapshot(self):
+ arglist = [
+ '--size', str(self.new_volume.size),
+ '--snapshot', volume_fakes.snapshot_id,
+ self.new_volume.name,
+ ]
+ verifylist = [
+ ('size', self.new_volume.size),
+ ('snapshot', volume_fakes.snapshot_id),
+ ('name', self.new_volume.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ fake_snapshot = mock.Mock()
+ fake_snapshot.id = volume_fakes.snapshot_id
+ self.snapshots_mock.get.return_value = fake_snapshot
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.volumes_mock.create.assert_called_once_with(
+ size=self.new_volume.size,
+ snapshot_id=fake_snapshot.id,
+ name=self.new_volume.name,
+ description=None,
+ volume_type=None,
+ user_id=None,
+ project_id=None,
+ availability_zone=None,
+ metadata=None,
+ imageRef=None,
+ source_volid=None
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.datalist, data)
+
class TestVolumeDelete(TestVolume):