Skip to content

Commit

Permalink
[patch] Only check mvi usage when over one hour (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfiea authored Nov 11, 2024
1 parent 62ef5ee commit adcdd2b
Showing 1 changed file with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ rules:
- ""
resources:
- configmaps

- verbs:
- get
- list
apiGroups:
- "apps.mas.ibm.com"
resources:
- visualinspectionappworkspaces
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down Expand Up @@ -151,6 +157,7 @@ data:
import semver
import tempfile
import base64
from datetime import datetime
# e.g. "dclain-1a"
mas_instance_id = os.getenv("MAS_INSTANCE_ID")
Expand All @@ -177,15 +184,16 @@ data:
yield dyn_client
@pytest.fixture(scope="session")
def v1_pods(dyn_client):
yield dyn_client.resources.get(api_version='v1', kind='Pod')
def v1_mviworkspace(dyn_client):
yield dyn_client.resources.get(api_version='apps.mas.ibm.com/v1', kind='VisualInspectionAppWorkspace')
@pytest.fixture(scope="session")
def get_usage_pod(v1_pods):
usage_pod = v1_pods.get(label_selector="app.kubernetes.io/name=usage-hourly-job", namespace=mvi_namespace)
if not usage_pod.items:
assert False, f"Could not find any usage-hourly-job in {mvi_namespace}"
yield usage_pod
def mvi_workspace_cr(v1_mviworkspace):
yield v1_mviworkspace.get(namespace=mvi_namespace, label_selector=f"mas.ibm.com/instanceId={mas_instance_id}, mas.ibm.com/workspaceId={mas_workspace_id}").items[0]
@pytest.fixture(scope="session")
def v1_pods(dyn_client):
yield dyn_client.resources.get(api_version='v1', kind='Pod')
@pytest.fixture(scope="session")
def v1_secrets(dyn_client):
Expand Down Expand Up @@ -284,9 +292,20 @@ data:
assert False, "Expected data.dnn-apikey field not present in secret {mvi_apikey_secret_name} in {mvi_namespace}"
yield base64.b64decode(dnn_apikey_b64)
def test_usage_reporter(get_usage_pod):
def get_usage_pod(v1_pods):
usage_pod = v1_pods.get(label_selector="app.kubernetes.io/name=usage-hourly-job", namespace=mvi_namespace)
if not usage_pod.items:
assert False, f"Could not find any usage-hourly-job in {mvi_namespace}"
return usage_pod
def test_usage_reporter(mvi_workspace_cr, v1_pods):
print("Test usage reporter")
assert get_usage_pod.items[0].status['phase'] == 'Succeeded'
mvi_create_time = datetime.strptime(mvi_workspace_cr['metadata']['creationTimestamp'], '%Y-%m-%dT%H:%M:%SZ')
current_time = datetime.now()
if (current_time - mvi_create_time).total_seconds() > 3600:
assert get_usage_pod(v1_pods).items[0].status['phase'] == 'Succeeded'
else:
print("MVI CR created only recently")
def test_bgtasks_api(mvi_host, mvi_host_ca_filepath, mvi_apikey):
resp = requests.get(
Expand Down

0 comments on commit adcdd2b

Please sign in to comment.