Skip to content

Commit dc785bd

Browse files
committed
Adapt check pertaining to scs-0117-volume-backup
Signed-off-by: Matthias Büchse <[email protected]>
1 parent 18f5901 commit dc785bd

File tree

4 files changed

+111
-91
lines changed

4 files changed

+111
-91
lines changed

Tests/iaas/openstack_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
compute_scs_0115_default_rules
4141
from scs_0116_key_manager.key_manager import \
4242
compute_services_lookup, compute_scs_0116_presence, compute_scs_0116_permissions
43+
from scs_0117_volume_backup.volume_backup import \
44+
compute_scs_0117_test_backup
4345

4446

4547
logger = logging.getLogger(__name__)
@@ -168,14 +170,19 @@ def make_container(cloud):
168170
# scs_0115_security_groups
169171
c.add_function('scs_0115_default_rules', lambda c: compute_scs_0115_default_rules(c.conn))
170172
c.add_function('security_groups_default_rules_check', lambda c: c.scs_0115_default_rules)
171-
# scs_0115_key_manager
173+
# scs_0116_key_manager
172174
c.add_function('services_lookup', lambda c: compute_services_lookup(c.conn))
173175
c.add_function('scs_0116_presence', lambda c: compute_scs_0116_presence(c.services_lookup))
174176
c.add_function('scs_0116_permissions', lambda c: compute_scs_0116_permissions(c.conn, c.services_lookup))
175177
c.add_function('key_manager_check', lambda c: all((
176178
# recommended only: c.scs_0116_presence,
177179
c.scs_0116_permissions,
178180
)))
181+
# scs_0117_volume_backup
182+
c.add_function('scs_0117_test_backup', lambda c: compute_scs_0117_test_backup(c.conn))
183+
c.add_function('volume_backup_check', lambda c: all((
184+
c.scs_0117_test_backup,
185+
)))
179186
return c
180187

181188

File renamed without changes.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
"""Volume Backup API tester for Block Storage API
3+
4+
This test script executes basic operations on the Block Storage API centered
5+
around volume backups. Its purpose is to verify that the Volume Backup API is
6+
available and working as expected using simple operations such as creating and
7+
restoring volume backups.
8+
9+
It verifies that a properly configured backup driver is present to the extent
10+
that aforementioned operations succeed on the API level. It does not by any
11+
means verify that the backup and restore procedures actual handle the data
12+
correctly (it only uses empty volumes and does not look at data for the sake
13+
of simplicity).
14+
"""
15+
16+
import argparse
17+
import getpass
18+
import logging
19+
import os
20+
import sys
21+
22+
import openstack
23+
24+
25+
from volume_backup import DEFAULT_PREFIX, cleanup, compute_scs_0117_test_backup
26+
27+
28+
def main():
29+
parser = argparse.ArgumentParser(
30+
description="SCS Volume Backup API Conformance Checker")
31+
parser.add_argument(
32+
"--os-cloud", type=str,
33+
help="Name of the cloud from clouds.yaml, alternative "
34+
"to the OS_CLOUD environment variable"
35+
)
36+
parser.add_argument(
37+
"--ask",
38+
help="Ask for password interactively instead of reading it from the "
39+
"clouds.yaml",
40+
action="store_true"
41+
)
42+
parser.add_argument(
43+
"--debug", action="store_true",
44+
help="Enable OpenStack SDK debug logging"
45+
)
46+
parser.add_argument(
47+
"--prefix", type=str,
48+
default=DEFAULT_PREFIX,
49+
help=f"OpenStack resource name prefix for all resources to be created "
50+
f"and/or cleaned up by this script within the configured domains "
51+
f"(default: '{DEFAULT_PREFIX}')"
52+
)
53+
parser.add_argument(
54+
"--cleanup-only", action="store_true",
55+
help="Instead of executing tests, cleanup all resources "
56+
"with the prefix specified via '--prefix' (or its default)"
57+
)
58+
args = parser.parse_args()
59+
openstack.enable_logging(debug=False)
60+
logging.basicConfig(
61+
format="%(levelname)s: %(message)s",
62+
level=logging.DEBUG if args.debug else logging.INFO,
63+
)
64+
65+
# parse cloud name for lookup in clouds.yaml
66+
cloud = args.os_cloud or os.environ.get("OS_CLOUD", None)
67+
if not cloud:
68+
raise Exception(
69+
"You need to have the OS_CLOUD environment variable set to your "
70+
"cloud name or pass it via --os-cloud"
71+
)
72+
password = getpass.getpass("Enter password: ") if args.ask else None
73+
74+
with openstack.connect(cloud, password=password) as conn:
75+
if args.cleanup_only:
76+
if not cleanup(conn, prefix=args.prefix):
77+
raise RuntimeError("cleanup failed")
78+
else:
79+
compute_scs_0117_test_backup(conn, prefix=args.prefix)
80+
81+
82+
if __name__ == "__main__":
83+
try:
84+
sys.exit(main())
85+
except SystemExit:
86+
raise
87+
except BaseException as exc:
88+
logging.debug("traceback", exc_info=True)
89+
logging.critical(str(exc))
90+
sys.exit(1)

Tests/iaas/volume-backup/volume-backup-tester.py renamed to Tests/iaas/scs_0117_volume_backup/volume_backup.py

Lines changed: 13 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
#!/usr/bin/env python3
2-
"""Volume Backup API tester for Block Storage API
3-
4-
This test script executes basic operations on the Block Storage API centered
5-
around volume backups. Its purpose is to verify that the Volume Backup API is
6-
available and working as expected using simple operations such as creating and
7-
restoring volume backups.
8-
9-
It verifies that a properly configured backup driver is present to the extent
10-
that aforementioned operations succeed on the API level. It does not by any
11-
means verify that the backup and restore procedures actual handle the data
12-
correctly (it only uses empty volumes and does not look at data for the sake
13-
of simplicity).
14-
"""
15-
16-
import argparse
171
from functools import partial
18-
import getpass
192
import logging
20-
import os
21-
import sys
223
import time
234
import typing
245

256
import openstack
267

8+
279
# prefix to be included in the names of any Keystone resources created
2810
# used by the cleanup routine to identify resources that can be safely deleted
2911
DEFAULT_PREFIX = "scs-test-"
@@ -221,75 +203,16 @@ def cleanup(conn: openstack.connection.Connection, prefix=DEFAULT_PREFIX) -> boo
221203
return not cleanup_issues
222204

223205

224-
def main():
225-
parser = argparse.ArgumentParser(
226-
description="SCS Volume Backup API Conformance Checker")
227-
parser.add_argument(
228-
"--os-cloud", type=str,
229-
help="Name of the cloud from clouds.yaml, alternative "
230-
"to the OS_CLOUD environment variable"
231-
)
232-
parser.add_argument(
233-
"--ask",
234-
help="Ask for password interactively instead of reading it from the "
235-
"clouds.yaml",
236-
action="store_true"
237-
)
238-
parser.add_argument(
239-
"--debug", action="store_true",
240-
help="Enable OpenStack SDK debug logging"
241-
)
242-
parser.add_argument(
243-
"--prefix", type=str,
244-
default=DEFAULT_PREFIX,
245-
help=f"OpenStack resource name prefix for all resources to be created "
246-
f"and/or cleaned up by this script within the configured domains "
247-
f"(default: '{DEFAULT_PREFIX}')"
248-
)
249-
parser.add_argument(
250-
"--cleanup-only", action="store_true",
251-
help="Instead of executing tests, cleanup all resources "
252-
"with the prefix specified via '--prefix' (or its default)"
253-
)
254-
args = parser.parse_args()
255-
openstack.enable_logging(debug=False)
256-
logging.basicConfig(
257-
format="%(levelname)s: %(message)s",
258-
level=logging.DEBUG if args.debug else logging.INFO,
259-
)
260-
261-
# parse cloud name for lookup in clouds.yaml
262-
cloud = args.os_cloud or os.environ.get("OS_CLOUD", None)
263-
if not cloud:
264-
raise Exception(
265-
"You need to have the OS_CLOUD environment variable set to your "
266-
"cloud name or pass it via --os-cloud"
267-
)
268-
password = getpass.getpass("Enter password: ") if args.ask else None
269-
270-
with openstack.connect(cloud, password=password) as conn:
271-
if not cleanup(conn, prefix=args.prefix):
272-
raise RuntimeError("Initial cleanup failed")
273-
if args.cleanup_only:
274-
logging.info("Cleanup-only run finished.")
275-
return
276-
try:
277-
test_backup(conn, prefix=args.prefix)
278-
except BaseException:
279-
print('volume-backup-check: FAIL')
280-
raise
281-
else:
282-
print('volume-backup-check: PASS')
283-
finally:
284-
cleanup(conn, prefix=args.prefix)
285-
286-
287-
if __name__ == "__main__":
206+
def compute_scs_0117_test_backup(conn, prefix=DEFAULT_PREFIX):
207+
if not cleanup(conn, prefix=prefix):
208+
raise RuntimeError("Initial cleanup failed")
288209
try:
289-
sys.exit(main())
290-
except SystemExit:
291-
raise
292-
except BaseException as exc:
293-
logging.debug("traceback", exc_info=True)
294-
logging.critical(str(exc))
295-
sys.exit(1)
210+
test_backup(conn, prefix=prefix)
211+
except BaseException:
212+
logging.error('Backup test failed.')
213+
logging.debug('exception details', exc_info=True)
214+
return False
215+
else:
216+
return True
217+
finally:
218+
cleanup(conn, prefix=prefix)

0 commit comments

Comments
 (0)