Skip to content

Commit 52eaec1

Browse files
author
Huanxuan Ao
committed
Add functional test for snapshot in volume v1
Add functional test for snapshot commands in volume v1. Tests can always help to find or avoid bugs. Change-Id: Ieb0ab9c763d381a6343b4c4a8a5874f3e682f24f
1 parent 2731fc3 commit 52eaec1

2 files changed

Lines changed: 92 additions & 3 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import time
14+
import uuid
15+
16+
from openstackclient.tests.functional.volume.v1 import common
17+
18+
19+
class SnapshotTests(common.BaseVolumeTests):
20+
"""Functional tests for snapshot. """
21+
22+
VOLLY = uuid.uuid4().hex
23+
NAME = uuid.uuid4().hex
24+
OTHER_NAME = uuid.uuid4().hex
25+
HEADERS = ['"Name"']
26+
27+
@classmethod
28+
def wait_for_status(cls, command, status, tries):
29+
opts = cls.get_opts(['status'])
30+
for attempt in range(tries):
31+
time.sleep(1)
32+
raw_output = cls.openstack(command + opts)
33+
if (raw_output == status):
34+
return
35+
cls.assertOutput(status, raw_output)
36+
37+
@classmethod
38+
def setUpClass(cls):
39+
super(SnapshotTests, cls).setUpClass()
40+
cls.openstack('volume create --size 1 ' + cls.VOLLY)
41+
cls.wait_for_status('volume show ' + cls.VOLLY, 'available\n', 3)
42+
opts = cls.get_opts(['status'])
43+
raw_output = cls.openstack('snapshot create --name ' + cls.NAME +
44+
' ' + cls.VOLLY + opts)
45+
cls.assertOutput('creating\n', raw_output)
46+
cls.wait_for_status('snapshot show ' + cls.NAME, 'available\n', 3)
47+
48+
@classmethod
49+
def tearDownClass(cls):
50+
# Rename test
51+
raw_output = cls.openstack(
52+
'snapshot set --name ' + cls.OTHER_NAME + ' ' + cls.NAME)
53+
cls.assertOutput('', raw_output)
54+
# Delete test
55+
raw_output_snapshot = cls.openstack(
56+
'snapshot delete ' + cls.OTHER_NAME)
57+
cls.wait_for_status('volume show ' + cls.VOLLY, 'available\n', 6)
58+
raw_output_volume = cls.openstack('volume delete --force ' + cls.VOLLY)
59+
cls.assertOutput('', raw_output_snapshot)
60+
cls.assertOutput('', raw_output_volume)
61+
62+
def test_snapshot_list(self):
63+
opts = self.get_opts(self.HEADERS)
64+
raw_output = self.openstack('snapshot list' + opts)
65+
self.assertIn(self.NAME, raw_output)
66+
67+
def test_snapshot_set_unset_properties(self):
68+
raw_output = self.openstack(
69+
'snapshot set --property a=b --property c=d ' + self.NAME)
70+
self.assertEqual("", raw_output)
71+
opts = self.get_opts(["properties"])
72+
raw_output = self.openstack('snapshot show ' + self.NAME + opts)
73+
self.assertEqual("a='b', c='d'\n", raw_output)
74+
75+
raw_output = self.openstack('snapshot unset --property a ' + self.NAME)
76+
self.assertEqual("", raw_output)
77+
raw_output = self.openstack('snapshot show ' + self.NAME + opts)
78+
self.assertEqual("c='d'\n", raw_output)
79+
80+
def test_snapshot_set_description(self):
81+
raw_output = self.openstack(
82+
'snapshot set --description backup ' + self.NAME)
83+
self.assertEqual("", raw_output)
84+
opts = self.get_opts(["display_description", "display_name"])
85+
raw_output = self.openstack('snapshot show ' + self.NAME + opts)
86+
self.assertEqual("backup\n" + self.NAME + "\n", raw_output)

openstackclient/tests/functional/volume/v2/test_snapshot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ def tearDownClass(cls):
5252
'snapshot set --name ' + cls.OTHER_NAME + ' ' + cls.NAME)
5353
cls.assertOutput('', raw_output)
5454
# Delete test
55-
raw_output = cls.openstack('snapshot delete ' + cls.OTHER_NAME)
56-
cls.assertOutput('', raw_output)
57-
cls.openstack('volume delete --force ' + cls.VOLLY, fail_ok=True)
55+
raw_output_snapshot = cls.openstack(
56+
'snapshot delete ' + cls.OTHER_NAME)
57+
cls.wait_for_status('volume show ' + cls.VOLLY, 'available\n', 6)
58+
raw_output_volume = cls.openstack('volume delete --force ' + cls.VOLLY)
59+
cls.assertOutput('', raw_output_snapshot)
60+
cls.assertOutput('', raw_output_volume)
5861

5962
def test_snapshot_list(self):
6063
opts = self.get_opts(self.HEADERS)

0 commit comments

Comments
 (0)