Created
February 11, 2025 17:35
-
-
Save akoserwal/0fd37c807c8bab4e07fffa128ec96bf2 to your computer and use it in GitHub Desktop.
inventory smoke test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| set -o pipefail | |
| # Set API URL | |
| INV_HTTP_URL=${INV_HTTP_URL:-"http://localhost:8000"} | |
| # Function to make requests and validate responses | |
| make_request() { | |
| local method=$1 | |
| local endpoint=$2 | |
| local data=$3 | |
| echo "Calling: $method $INV_HTTP_URL$endpoint" | |
| response=$(curl -s -o response.json -w "%{http_code}" -X "$method" "$INV_HTTP_URL$endpoint" \ | |
| -H "Content-Type: application/json" \ | |
| ${data:+-d "$data"}) | |
| cat response.json | |
| } | |
| # Livez Endpoint | |
| echo "Checking Livez..." | |
| make_request GET "/api/inventory/v1/livez" | |
| jq -e '.status == "OK"' response.json >/dev/null || { echo "Livez check failed"; exit 1; } | |
| # Readyz Endpoint | |
| echo "Checking Readyz..." | |
| make_request GET "/api/inventory/v1/readyz" | |
| jq -e '.code == 200' response.json >/dev/null || { echo "Readyz check failed"; exit 1; } | |
| # Create RHEL Host | |
| echo "Creating RHEL Host..." | |
| make_request POST "/api/inventory/v1beta1/resources/rhel-hosts" '{ | |
| "rhel_host": { | |
| "metadata": { | |
| "resource_type": "rhel_host", | |
| "workspace_id": "workspace", | |
| "org_id": "" | |
| }, | |
| "reporter_data": { | |
| "reporter_instance_id": "user@example.com", | |
| "reporter_type": "HBI", | |
| "console_href": "www.example.com", | |
| "api_href": "www.example.com", | |
| "local_resource_id": "0123", | |
| "reporter_version": "0.1" | |
| } | |
| } | |
| }' | |
| jq -e '{} == {}' response.json >/dev/null || { echo "RHEL host creation validation failed"; exit 1; } | |
| # Update RHEL Host | |
| echo "Updating RHEL Host..." | |
| make_request PUT "/api/inventory/v1beta1/resources/rhel-hosts" '{ | |
| "rhel_host": { | |
| "metadata": { | |
| "resource_type": "rhel_host", | |
| "workspace_id": "workspace6", | |
| "org_id": "" | |
| }, | |
| "reporter_data": { | |
| "reporter_instance_id": "user@example.com", | |
| "reporter_type": "HBI", | |
| "console_href": "www.exampleConsole.com", | |
| "api_href": "www.exampleAPI.com", | |
| "local_resource_id": "0123", | |
| "reporter_version": "0.1" | |
| } | |
| } | |
| }' | |
| jq -e '{} == {}' response.json >/dev/null || { echo "RHEL host update validation failed"; exit 1; } | |
| # Delete RHEL Host | |
| echo "Deleting RHEL Host..." | |
| make_request DELETE "/api/inventory/v1beta1/resources/rhel-hosts" '{ | |
| "reporter_data": { | |
| "reporter_instance_id": "user@example.com", | |
| "reporter_type": "HBI", | |
| "console_href": "www.exampleConsole.com", | |
| "api_href": "www.exampleAPI.com", | |
| "local_resource_id": "0123", | |
| "reporter_version": "0.1" | |
| } | |
| }' | |
| jq -e '{} == {}' response.json >/dev/null || { echo "RHEL host deletion validation failed"; exit 1; } | |
| # Create K8S Cluster | |
| echo "Creating K8S Cluster..." | |
| make_request POST "/api/inventory/v1beta1/resources/k8s-clusters" '{ | |
| "k8s_cluster": { | |
| "metadata": { | |
| "resource_type": "k8s_cluster", | |
| "workspace_id": "workspace1", | |
| "org_id": "" | |
| }, | |
| "resource_data": { | |
| "external_cluster_id": "01234", | |
| "cluster_status": "READY", | |
| "kube_version": "1.31", | |
| "kube_vendor": "OPENSHIFT", | |
| "vendor_version": "4.16", | |
| "cloud_platform": "AWS_UPI", | |
| "nodes": [ | |
| { | |
| "name": "www.web.com", | |
| "cpu": "7500m", | |
| "memory": "30973224Ki", | |
| "labels": [ | |
| { "key": "has_monster_gpu", "value": "no" } | |
| ] | |
| } | |
| ] | |
| }, | |
| "reporter_data": { | |
| "reporter_instance_id": "user@example.com", | |
| "reporter_type": "ACM", | |
| "console_href": "www.example.com", | |
| "api_href": "www.example.com", | |
| "local_resource_id": "01234", | |
| "reporter_version": "0.1" | |
| } | |
| } | |
| }' | |
| jq -e '{} == {}' response.json >/dev/null || { echo "K8S cluster creation validation failed"; exit 1; } | |
| # Update K8S Cluster | |
| echo "Updating K8S Cluster..." | |
| make_request PUT "/api/inventory/v1beta1/resources/k8s-clusters" '{ | |
| "k8s_cluster": { | |
| "metadata": { | |
| "resource_type": "k8s_cluster", | |
| "workspace_id": "workspace7", | |
| "org_id": "" | |
| }, | |
| "resource_data": { | |
| "external_cluster_id": "01234", | |
| "cluster_status": "OFFLINE", | |
| "kube_version": "1.31", | |
| "kube_vendor": "OPENSHIFT", | |
| "vendor_version": "4.16", | |
| "cloud_platform": "AWS_UPI", | |
| "nodes": [ | |
| { | |
| "name": "www.website.com", | |
| "cpu": "7500m", | |
| "memory": "30973224Ki" | |
| } | |
| ] | |
| }, | |
| "reporter_data": { | |
| "reporter_instance_id": "user@example.com", | |
| "reporter_type": "ACM", | |
| "console_href": "www.example.com", | |
| "api_href": "www.example.com", | |
| "local_resource_id": "01234", | |
| "reporter_version": "0.1" | |
| } | |
| } | |
| }' | |
| jq -e '{} == {}' response.json >/dev/null || { echo "K8S cluster update validation failed"; exit 1; } | |
| echo "All requests completed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment