Merge pull request #130 from gostor/ci/add-cli-management-tests
ci: add CLI management tests for target, LU, and TPGT commands
This commit is contained in:
99
.github/workflows/gotgt.yml
vendored
99
.github/workflows/gotgt.yml
vendored
@@ -147,3 +147,102 @@ jobs:
|
||||
sudo mkdir -p /var/tmp/test
|
||||
sudo mount /dev/sdb1 /var/tmp/test
|
||||
sudo ls -lh /var/tmp/test/
|
||||
|
||||
- name: CLI management test
|
||||
run: |
|
||||
API="http://127.0.0.1:23457"
|
||||
|
||||
echo "=== CLI Management API Tests ==="
|
||||
|
||||
# 1. List targets - should show the target from config
|
||||
echo "--- list target ---"
|
||||
curl -sf "$API/target/list" | tee /tmp/list_target.out
|
||||
grep -q "${{env.TARGET}}" /tmp/list_target.out
|
||||
echo "PASS: list target shows configured target"
|
||||
|
||||
# 2. List LUs for the existing target
|
||||
echo "--- list lu ---"
|
||||
curl -sf "$API/lu/list?target=${{env.TARGET}}" | tee /tmp/list_lu.out
|
||||
echo ""
|
||||
# Verify it returns a JSON array (may be empty or have LU 0)
|
||||
python3 -c "import json,sys; data=json.load(sys.stdin); assert isinstance(data,list)" < /tmp/list_lu.out
|
||||
echo "PASS: list lu returns valid JSON array"
|
||||
|
||||
# 3. List TPGTs for the existing target
|
||||
echo "--- list tpgt ---"
|
||||
curl -sf "$API/target/tpgt/list?target=${{env.TARGET}}" | tee /tmp/list_tpgt.out
|
||||
echo ""
|
||||
python3 -c "import json,sys; data=json.load(sys.stdin); assert isinstance(data,list)" < /tmp/list_tpgt.out
|
||||
echo "PASS: list tpgt returns valid JSON array"
|
||||
|
||||
# 4. Create a new target via API
|
||||
echo "--- create target ---"
|
||||
NEW_TARGET="iqn.2016-09.com.gotgt.gostor:ci_test_tgt"
|
||||
curl -sf -X POST "$API/target/create" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"Name\":\"$NEW_TARGET\"}" | tee /tmp/create_target.out
|
||||
echo ""
|
||||
grep -q "$NEW_TARGET" /tmp/create_target.out
|
||||
echo "PASS: create target succeeded"
|
||||
|
||||
# 5. Verify new target appears in list
|
||||
echo "--- verify new target in list ---"
|
||||
curl -sf "$API/target/list" | tee /tmp/list_target2.out
|
||||
echo ""
|
||||
grep -q "$NEW_TARGET" /tmp/list_target2.out
|
||||
echo "PASS: new target visible in list"
|
||||
|
||||
# 6. Create a new LU on the new target
|
||||
echo "--- create lu ---"
|
||||
dd if=/dev/zero of=/var/tmp/ci_disk.img bs=1024 count=10240 2>/dev/null
|
||||
curl -sf -X POST "$API/lu/create" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"targetName\":\"$NEW_TARGET\",\"deviceID\":2000,\"lun\":0,\"path\":\"file:/var/tmp/ci_disk.img\",\"blockShift\":9}" \
|
||||
-o /dev/null -w "%{http_code}" | tee /tmp/create_lu_status.out
|
||||
echo ""
|
||||
grep -q "201" /tmp/create_lu_status.out
|
||||
echo "PASS: create lu returned 201"
|
||||
|
||||
# 7. Verify new LU appears in list
|
||||
echo "--- verify new lu in list ---"
|
||||
curl -sf "$API/lu/list?target=$NEW_TARGET" | tee /tmp/list_lu2.out
|
||||
echo ""
|
||||
python3 -c "import json,sys; data=json.load(sys.stdin); assert len(data)==1, f'expected 1 LU, got {len(data)}'" < /tmp/list_lu2.out
|
||||
echo "PASS: new LU visible in list"
|
||||
|
||||
# 8. Remove the LU
|
||||
echo "--- remove lu ---"
|
||||
curl -sf -X DELETE "$API/lu/delete" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"targetName\":\"$NEW_TARGET\",\"lun\":0}" \
|
||||
-o /dev/null -w "%{http_code}" | tee /tmp/rm_lu_status.out
|
||||
echo ""
|
||||
grep -q "204" /tmp/rm_lu_status.out
|
||||
echo "PASS: remove lu returned 204"
|
||||
|
||||
# 9. Verify LU is gone
|
||||
echo "--- verify lu removed ---"
|
||||
curl -sf "$API/lu/list?target=$NEW_TARGET" | tee /tmp/list_lu3.out
|
||||
echo ""
|
||||
python3 -c "import json,sys; data=json.load(sys.stdin); assert data is None or len(data)==0, f'expected 0 LUs, got {data}'" < /tmp/list_lu3.out
|
||||
echo "PASS: LU no longer in list"
|
||||
|
||||
# 10. Remove the target
|
||||
echo "--- remove target ---"
|
||||
curl -sf -X DELETE "$API/target/$NEW_TARGET?force=1" \
|
||||
-o /dev/null -w "%{http_code}" | tee /tmp/rm_target_status.out
|
||||
echo ""
|
||||
grep -q "204" /tmp/rm_target_status.out
|
||||
echo "PASS: remove target returned 204"
|
||||
|
||||
# 11. Verify target is gone
|
||||
echo "--- verify target removed ---"
|
||||
curl -sf "$API/target/list" | tee /tmp/list_target3.out
|
||||
echo ""
|
||||
if grep -q "$NEW_TARGET" /tmp/list_target3.out; then
|
||||
echo "FAIL: target still present after removal"
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: target no longer in list"
|
||||
|
||||
echo "=== All CLI Management API Tests Passed ==="
|
||||
|
||||
Reference in New Issue
Block a user