Skip to content

Commit 794c2a1

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add functional tests for snapshots"
2 parents fb4240a + e108719 commit 794c2a1

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 functional.common import test
17+
18+
19+
class SnapshotTests(test.TestCase):
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_show_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+
cls.openstack('volume create --size 1 ' + cls.VOLLY)
40+
cls.wait_for_status('volume show ' + cls.VOLLY, 'available\n', 3)
41+
opts = cls.get_show_opts(['status'])
42+
raw_output = cls.openstack('snapshot create --name ' + cls.NAME +
43+
' ' + cls.VOLLY + opts)
44+
cls.assertOutput('creating\n', raw_output)
45+
cls.wait_for_status('snapshot show ' + cls.NAME, 'available\n', 3)
46+
47+
@classmethod
48+
def tearDownClass(cls):
49+
# Rename test
50+
raw_output = cls.openstack(
51+
'snapshot set --name ' + cls.OTHER_NAME + ' ' + cls.NAME)
52+
cls.assertOutput('', raw_output)
53+
# Delete test
54+
raw_output = cls.openstack('snapshot delete ' + cls.OTHER_NAME)
55+
cls.assertOutput('', raw_output)
56+
cls.openstack('volume delete --force ' + cls.VOLLY, fail_ok=True)
57+
58+
def test_snapshot_list(self):
59+
opts = self.get_list_opts(self.HEADERS)
60+
raw_output = self.openstack('snapshot list' + opts)
61+
self.assertIn(self.NAME, raw_output)
62+
63+
def test_snapshot_properties(self):
64+
raw_output = self.openstack(
65+
'snapshot set --property a=b --property c=d ' + self.NAME)
66+
self.assertEqual("", raw_output)
67+
opts = self.get_show_opts(["properties"])
68+
raw_output = self.openstack('snapshot show ' + self.NAME + opts)
69+
self.assertEqual("a='b', c='d'\n", raw_output)
70+
71+
raw_output = self.openstack('snapshot unset --property a ' + self.NAME)
72+
self.assertEqual("", raw_output)
73+
raw_output = self.openstack('snapshot show ' + self.NAME + opts)
74+
self.assertEqual("c='d'\n", raw_output)
75+
76+
def test_snapshot_set(self):
77+
raw_output = self.openstack(
78+
'snapshot set --description backup ' + self.NAME)
79+
self.assertEqual("", raw_output)
80+
opts = self.get_show_opts(["description", "name"])
81+
raw_output = self.openstack('snapshot show ' + self.NAME + opts)
82+
self.assertEqual("backup\n" + self.NAME + "\n", raw_output)

0 commit comments

Comments
 (0)