Skip to content

Commit

Permalink
Rhcloud 19820 add pool type column (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
maknop authored Jun 23, 2022
1 parent 7bb6eae commit 0036d13
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 51 deletions.
2 changes: 2 additions & 0 deletions bonfire/bonfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ def _list_namespaces(available, mine, output):
"status": ns.status,
"requester": ns.requester,
"expires_in": ns.expires_in,
"pool_type": ns.pool_type
}
click.echo(json.dumps(data, indent=2))
else:
Expand All @@ -654,6 +655,7 @@ def _list_namespaces(available, mine, output):
"ENV STATUS": [str(ns.status).lower() for ns in namespaces],
"APPS READY": [ns.clowdapps for ns in namespaces],
"REQUESTER": [ns.requester for ns in namespaces],
"POOL TYPE": [ns.pool_type for ns in namespaces],
"EXPIRES IN": [ns.expires_in for ns in namespaces],
}
tabulated = tabulate(data, headers="keys")
Expand Down
4 changes: 4 additions & 0 deletions bonfire/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def is_reservable(self):
"""
return self.operator_ns

@property
def pool_type(self):
return self.labels.get("pool", "false")

@property
def expires_in(self):
if not self.expires:
Expand Down
37 changes: 21 additions & 16 deletions tests/data/namespace_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,87 @@
"items": [
{
"metadata": {
"name": "namespace-1",
"name": "ns-1",
"namespace": "namspace-1",
"annotations": {
"env-status": "false",
"reserved": "true"
},
"labels": {
"operator-ns": "true"
"operator-ns": "true",
"pool": "minimal"
}
},
"status": {
"namespace": "namespace-1"
"namespace": "ns-1"
}
},
{
"metadata": {
"name": "namespace-2",
"name": "ns-2",
"namespace": "namspace-2",
"annotations": {
"env-status": "false",
"reserved": "true"
},
"labels": {
"operator-ns": "true"
"operator-ns": "true",
"pool": "default"
}
},
"status": {
"namespace": "namespace-2"
"namespace": "ns-2"
}
},
{
"metadata": {
"name": "namespace-3",
"name": "ns-3",
"namespace": "namspace-3",
"annotations": {
"env-status": "ready",
"reserved": "false,"
},
"labels": {
"operator-ns": "true"
"operator-ns": "true",
"pool": "default"
}
},
"status": {
"namespace": "namespace-3"
"namespace": "ns-3"
}
},
{
"metadata": {
"name": "namespace-4",
"name": "ns-4",
"namespace": "namspace-4",
"annotations": {
"env-status": "ready",
"reserved": "false,"
},
"labels": {
"operator-ns": "true"
"operator-ns": "true",
"pool": "default"
}
},
"status": {
"namespace": "namespace-4"
"namespace": "ns-4"
}
},
{
"metadata": {
"name": "namespace-5",
"namespace": "namespace-5",
"name": "ns-5",
"namespace": "ns-5",
"annotations": {
"env-status": "false",
"reserved": "true"
},
"labels": {
"operator-ns": "true"
"operator-ns": "true",
"pool": "default"
}
},
"status": {
"namespace": "namespace-5"
"namespace": "ns-5"
}
}
]
Expand Down
12 changes: 6 additions & 6 deletions tests/data/reservation_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"items": [
{
"metadata": {
"name": "namespace-1"
"name": "ns-1"
},
"status": {
"namespace": "namespace-1",
"namespace": "ns-1",
"state": "active",
"expiration": "2024-04-13T22:00:00Z"
},
Expand All @@ -15,10 +15,10 @@
},
{
"metadata": {
"name": "namespace-2"
"name": "ns-2"
},
"status": {
"namespace": "namespace-2",
"namespace": "ns-2",
"state": "active",
"expiration": "2024-04-29T22:00:00Z"
},
Expand All @@ -28,10 +28,10 @@
},
{
"metadata": {
"name": "namespace-5"
"name": "ns-5"
},
"status": {
"namespace": "namespace-5",
"namespace": "ns-5",
"state": "active",
"expiration": "2024-04-19T16:30:00Z"
},
Expand Down
83 changes: 54 additions & 29 deletions tests/test_bonfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def reservation_list():
@pytest.mark.parametrize(
"name",
[
("namespace-6"),
("namespace-7"),
("ns-6"),
("ns-7"),
],
)
def test_ns_reserve_flag_name(mocker, caplog, name: str):
Expand Down Expand Up @@ -118,11 +118,11 @@ def test_ns_list_option(mocker, caplog, namespace_list: list, reservation_list:

actual = " ".join(result.output.split())

assert " ".join(["namespace-1", "true", "false", "none", "user-1"]) in actual
assert " ".join(["namespace-2", "true", "false", "none", "user-2"]) in actual
assert " ".join(["namespace-3", "false", "ready", "none"]) in actual
assert " ".join(["namespace-4", "false", "ready", "none"]) in actual
assert " ".join(["namespace-5", "true", "false", "none", "user-5"]) in actual
assert " ".join(["ns-1", "true", "false", "none", "user-1", "minimal"]) in actual
assert " ".join(["ns-2", "true", "false", "none", "user-2", "default"]) in actual
assert " ".join(["ns-3", "false", "ready", "none", "default"]) in actual
assert " ".join(["ns-4", "false", "ready", "none", "default"]) in actual
assert " ".join(["ns-5", "true", "false", "none", "user-5", "default"]) in actual


def test_ns_list_options_available(mocker, caplog, namespace_list: list, reservation_list: list):
Expand All @@ -141,11 +141,11 @@ def test_ns_list_options_available(mocker, caplog, namespace_list: list, reserva

actual = " ".join(result.output.split())

assert " ".join(["namespace-1", "true", "false", "none", "user-1"]) not in actual
assert " ".join(["namespace-2", "true", "false", "none", "user-2"]) not in actual
assert " ".join(["namespace-3", "false", "ready", "none"]) in actual
assert " ".join(["namespace-4", "false", "ready", "none"]) in actual
assert " ".join(["namespace-5", "true", "false", "none", "user-5"]) not in actual
assert " ".join(["ns-1", "true", "false", "none", "user-1"]) not in actual
assert " ".join(["ns-2", "true", "false", "none", "user-2"]) not in actual
assert " ".join(["ns-3", "false", "ready", "none"]) in actual
assert " ".join(["ns-4", "false", "ready", "none"]) in actual
assert " ".join(["ns-5", "true", "false", "none", "user-5"]) not in actual


def test_ns_list_option_mine(mocker, caplog, namespace_list: list, reservation_list: list):
Expand All @@ -164,11 +164,11 @@ def test_ns_list_option_mine(mocker, caplog, namespace_list: list, reservation_l

actual = " ".join(result.output.split())

assert " ".join(["namespace-1", "true", "false", "none", "user-1"]) in actual
assert " ".join(["namespace-2", "true", "false", "none", "user-2"]) not in actual
assert " ".join(["namespace-3", "false", "ready", "none"]) not in actual
assert " ".join(["namespace-4", "false", "ready", "none"]) not in actual
assert " ".join(["namespace-5", "true", "false", "none", "user-5"]) not in actual
assert " ".join(["ns-1", "true", "false", "none", "user-1"]) in actual
assert " ".join(["ns-2", "true", "false", "none", "user-2"]) not in actual
assert " ".join(["ns-3", "false", "ready", "none"]) not in actual
assert " ".join(["ns-4", "false", "ready", "none"]) not in actual
assert " ".join(["ns-5", "true", "false", "none", "user-5"]) not in actual


def test_ns_list_flag_output(
Expand All @@ -190,23 +190,48 @@ def test_ns_list_flag_output(
runner = CliRunner()
result = runner.invoke(bonfire.namespace, ["list", "--output", "json"])

actual_ns_1 = json.loads(result.output).get("namespace-1")
actual_ns_2 = json.loads(result.output).get("namespace-2")
actual_ns_3 = json.loads(result.output).get("namespace-3")
actual_ns_4 = json.loads(result.output).get("namespace-4")
actual_ns_5 = json.loads(result.output).get("namespace-5")
actual_ns_1 = json.loads(result.output).get("ns-1")
actual_ns_2 = json.loads(result.output).get("ns-2")
actual_ns_3 = json.loads(result.output).get("ns-3")
actual_ns_4 = json.loads(result.output).get("ns-4")
actual_ns_5 = json.loads(result.output).get("ns-5")

del actual_ns_1["expires_in"]
del actual_ns_2["expires_in"]
del actual_ns_3["expires_in"]
del actual_ns_4["expires_in"]
del actual_ns_5["expires_in"]

test_items_1 = {"reserved": True, "status": "false", "requester": "user-1"}
test_items_2 = {"reserved": True, "status": "false", "requester": "user-2"}
test_items_3 = {"reserved": False, "status": "ready", "requester": None}
test_items_4 = {"reserved": False, "status": "ready", "requester": None}
test_items_5 = {"reserved": True, "status": "false", "requester": "user-5"}
test_items_1 = {
"reserved": True,
"status": "false",
"requester": "user-1",
"pool_type": "minimal"
}
test_items_2 = {
"reserved": True,
"status": "false",
"requester": "user-2",
"pool_type": "default"
}
test_items_3 = {
"reserved": False,
"status": "ready",
"requester": None,
"pool_type": "default"
}
test_items_4 = {
"reserved": False,
"status": "ready",
"requester": None,
"pool_type": "default"
}
test_items_5 = {
"reserved": True,
"status": "false",
"requester": "user-5",
"pool_type": "default"
}

assert all([item in test_items_1.items() for item in actual_ns_1.items()])
assert all([item in test_items_2.items() for item in actual_ns_2.items()])
Expand All @@ -218,8 +243,8 @@ def test_ns_list_flag_output(
@pytest.mark.parametrize(
"user, namespace, timeout",
[
("user-6", "namespace-6", 600),
("user-7", "namespace-7", 700),
("user-6", "ns-6", 600),
("user-7", "ns-7", 700),
],
)
def test_ns_reserve_flag_timeout(mocker, caplog, user: str, namespace: str, timeout: int):
Expand Down

0 comments on commit 0036d13

Please sign in to comment.