|
40 | 40 | from scs_0115_security_groups.security_groups import \ |
41 | 41 | compute_scs_0115_default_rules |
42 | 42 | from scs_0116_key_manager.key_manager import \ |
43 | | - compute_services_lookup, compute_scs_0116_presence, compute_scs_0116_permissions |
| 43 | + ensure_unprivileged, compute_services_lookup, compute_scs_0116_presence, compute_scs_0116_permissions |
44 | 44 | from scs_0117_volume_backup.volume_backup import \ |
45 | 45 | compute_scs_0117_test_backup |
46 | 46 | from scs_0123_mandatory_services.mandatory_services import \ |
@@ -280,6 +280,20 @@ def harness(name, *check_fns): |
280 | 280 | print(f"{name}: {result}") |
281 | 281 |
|
282 | 282 |
|
| 283 | +def run_sanity_checks(container): |
| 284 | + # make sure that we can connect to the cloud and that the user doesn't have elevated privileges |
| 285 | + # the former would lead to each testcase aborting with a marginally useful message; |
| 286 | + # the latter would lead to scs_0116_permissions aborting, which we don't want to single out |
| 287 | + try: |
| 288 | + conn = container.conn |
| 289 | + except openstack.exceptions.ConfigException: |
| 290 | + logger.critical("Please make sure that ~/.config/openstack/clouds.yaml exists and is correct!") |
| 291 | + raise |
| 292 | + if "member" not in ensure_unprivileged(conn, quiet=True): |
| 293 | + logger.critical("Please make sure that your OpenStack user has role member.") |
| 294 | + raise RuntimeError("OpenStack user has elevated privileges.") |
| 295 | + |
| 296 | + |
283 | 297 | def main(argv): |
284 | 298 | # configure logging, disable verbose library logging |
285 | 299 | logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) |
@@ -320,6 +334,7 @@ def main(argv): |
320 | 334 | sys.exit(1) |
321 | 335 |
|
322 | 336 | c = make_container(cloud) |
| 337 | + run_sanity_checks(c) |
323 | 338 | for testcase in testcases: |
324 | 339 | testcase_name = testcase.rsplit('/', 1)[0] # see the note above |
325 | 340 | harness(testcase_name, lambda: getattr(c, testcase.replace('-', '_').replace('/', '_'))) |
|
0 commit comments