Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[patch] Only check mvi usage when over one hour #219

Merged
merged 7 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading