|
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 | 1 | from functools import partial |
18 | | -import getpass |
19 | 2 | import logging |
20 | | -import os |
21 | | -import sys |
22 | 3 | import time |
23 | 4 | import typing |
24 | 5 |
|
25 | 6 | import openstack |
26 | 7 |
|
| 8 | + |
27 | 9 | # prefix to be included in the names of any Keystone resources created |
28 | 10 | # used by the cleanup routine to identify resources that can be safely deleted |
29 | 11 | DEFAULT_PREFIX = "scs-test-" |
@@ -221,75 +203,16 @@ def cleanup(conn: openstack.connection.Connection, prefix=DEFAULT_PREFIX) -> boo |
221 | 203 | return not cleanup_issues |
222 | 204 |
|
223 | 205 |
|
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") |
288 | 209 | 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