Skip to content

Commit 0bf8ee2

Browse files
committed
Add general sanity check to OpenStack tests
closes #991 Signed-off-by: Matthias Büchse <[email protected]>
1 parent e27a38b commit 0bf8ee2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Tests/iaas/openstack_test.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from scs_0115_security_groups.security_groups import \
4141
compute_scs_0115_default_rules
4242
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
4444
from scs_0117_volume_backup.volume_backup import \
4545
compute_scs_0117_test_backup
4646
from scs_0123_mandatory_services.mandatory_services import \
@@ -280,6 +280,20 @@ def harness(name, *check_fns):
280280
print(f"{name}: {result}")
281281

282282

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+
283297
def main(argv):
284298
# configure logging, disable verbose library logging
285299
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
@@ -320,6 +334,7 @@ def main(argv):
320334
sys.exit(1)
321335

322336
c = make_container(cloud)
337+
run_sanity_checks(c)
323338
for testcase in testcases:
324339
testcase_name = testcase.rsplit('/', 1)[0] # see the note above
325340
harness(testcase_name, lambda: getattr(c, testcase.replace('-', '_').replace('/', '_')))

Tests/iaas/scs_0116_key_manager/key_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
logger = logging.getLogger(__name__)
88

99

10-
def ensure_unprivileged(conn: openstack.connection.Connection) -> list:
10+
def ensure_unprivileged(conn: openstack.connection.Connection, quiet=False) -> list:
1111
"""
1212
Retrieves role names.
1313
Raises exception if elevated privileges (admin, manager) are present.
@@ -19,6 +19,8 @@ def ensure_unprivileged(conn: openstack.connection.Connection) -> list:
1919
role_names = set(conn.session.auth.get_access(conn.session).role_names)
2020
if role_names & {"admin", "manager"}:
2121
raise RuntimeError("user privileges too high: admin/manager roles detected")
22+
if quiet:
23+
return role_names
2224
if "reader" in role_names:
2325
logger.info("User has reader role.")
2426
custom_roles = sorted(role_names - {"reader", "member"})

0 commit comments

Comments
 (0)