Created
February 12, 2025 16:02
-
-
Save akoserwal/f21af3fb4a87ac0efccd99582ecb7a0e to your computer and use it in GitHub Desktop.
smoke test inv api
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": "[email protected]", | |
"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": "[email protected]", | |
"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": "[email protected]", | |
"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": "[email protected]", | |
"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": "[email protected]", | |
"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; } | |
# Create K8S Policies | |
echo "Creating K8S Policies..." | |
make_request POST "/api/inventory/v1beta1/resources/k8s-policies" '{ | |
"k8s_policy": { | |
"metadata": { | |
"resource_type": "k8s_policy", | |
"workspace_id": "01932c7e-e93e-719c-a488-3159877367b0" | |
}, | |
"reporter_data": { | |
"reporter_type": "ACM", | |
"reporter_version": "0.1", | |
"local_resource_id": "1", | |
"api_href": "www.example.com", | |
"console_href": "www.example.com" | |
}, | |
"resource_data": { | |
"disabled": true, | |
"severity": "MEDIUM" | |
} | |
} | |
}' | |
jq -e '{} == {}' response.json >/dev/null || { echo "K8S Policies creation validation failed"; exit 1; } | |
#!/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 K8S Policies | |
echo "Creating K8S Policies..." | |
make_request POST "/api/inventory/v1beta1/resources/k8s-policies" '{ | |
"k8s_policy": { | |
"metadata": { | |
"resource_type": "k8s_policy", | |
"workspace_id": "01932c7e-e93e-719c-a488-3159877367b0" | |
}, | |
"reporter_data": { | |
"reporter_type": "ACM", | |
"reporter_version": "0.1", | |
"local_resource_id": "1", | |
"api_href": "www.example.com", | |
"console_href": "www.example.com" | |
}, | |
"resource_data": { | |
"disabled": true, | |
"severity": "MEDIUM" | |
} | |
} | |
}' | |
jq -e '{} == {}' response.json >/dev/null || { echo "K8S Policies creation validation failed"; exit 1; } | |
# Update K8S Policies | |
echo "Updating K8S Policies..." | |
make_request PUT "/api/inventory/v1beta1/resources/k8s-policies" '{ | |
"k8s_policy": { | |
"metadata": { | |
"resource_type": "k8s_policy", | |
"workspace_id": "01932c7e-e93e-719c-a488-3159877367b0" | |
}, | |
"reporter_data": { | |
"reporter_type": "ACM", | |
"reporter_version": "0.1", | |
"local_resource_id": "1", | |
"api_href": "www.example.com", | |
"console_href": "www.example.com" | |
}, | |
"resource_data": { | |
"disabled": true, | |
"severity": "HIGH" | |
} | |
} | |
}' | |
jq -e '{} == {}' response.json >/dev/null || { echo "K8S Policies update validation failed"; exit 1; } | |
# Create Notification Integrations | |
echo "Creating Notification Integrations..." | |
make_request POST "/api/inventory/v1beta1/resources/notifications-integrations" '{ | |
"integration": { | |
"metadata": { | |
"workspace_id": "1234", | |
"resource_type": "notifications/integration" | |
}, | |
"reporter_data": { | |
"reporter_instance_id": "service-account-1", | |
"reporter_type": "NOTIFICATIONS", | |
"local_resource_id": "1234" | |
} | |
} | |
}' | |
jq -e '{} == {}' response.json >/dev/null || { echo "Notification Integrations creation validation failed"; exit 1; } | |
echo "Updating Notification Integrations..." | |
make_request PUT "/api/inventory/v1beta1/resources/notifications-integrations" '{ | |
"integration": { | |
"metadata": { | |
"workspace_id": "1234", | |
"resource_type": "notifications/integration" | |
}, | |
"reporter_data": { | |
"reporter_instance_id": "service-account-1", | |
"reporter_type": "NOTIFICATIONS", | |
"local_resource_id": "1234" | |
} | |
} | |
}' | |
jq -e '{} == {}' response.json >/dev/null || { echo "Notification Integrations 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