Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Bug fixes

- dbaas: send `--pg-migration-ignore-dbs` value to API #839

## 1.95.0

Expand Down
39 changes: 12 additions & 27 deletions cmd/aiservices/deployment/deployment_actions_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package deployment

import (
"context"
"encoding/json"
"io"
"net/http"
Expand All @@ -12,10 +11,9 @@ import (
"time"

exocmd "github.com/exoscale/cli/cmd"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
"github.com/exoscale/cli/pkg/testutils"
v3 "github.com/exoscale/egoscale/v3"
"github.com/exoscale/egoscale/v3/credentials"
)

type depActionsServer struct {
Expand All @@ -30,9 +28,9 @@ func newDepActionsServer(t *testing.T) *depActionsServer {
mux.HandleFunc("/ai/deployment", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
writeJSON(t, w, http.StatusOK, v3.ListDeploymentsResponse{Deployments: ts.deployments})
testutils.WriteJSON(t, w, http.StatusOK, v3.ListDeploymentsResponse{Deployments: ts.deployments})
case http.MethodPost:
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
default:
w.WriteHeader(http.StatusMethodNotAllowed)
}
Expand All @@ -49,30 +47,30 @@ func newDepActionsServer(t *testing.T) *depActionsServer {
for _, d := range ts.deployments {
if string(d.ID) == id {
resp := v3.GetDeploymentResponse{ID: d.ID, Name: d.Name, State: v3.GetDeploymentResponseState(d.State), GpuType: d.GpuType, GpuCount: d.GpuCount, Replicas: d.Replicas, ServiceLevel: d.ServiceLevel, DeploymentURL: d.DeploymentURL, Model: d.Model, CreatedAT: d.CreatedAT, UpdatedAT: d.UpdatedAT}
writeJSON(t, w, http.StatusOK, resp)
testutils.WriteJSON(t, w, http.StatusOK, resp)
return
}
}
w.WriteHeader(http.StatusNotFound)
return
}
if len(parts) == 1 && r.Method == http.MethodDelete {
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-delete"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-delete"), State: v3.OperationStateSuccess})
return
}
if len(parts) == 2 && parts[1] == "scale" && r.Method == http.MethodPost {
b, _ := io.ReadAll(r.Body)
r.Body.Close()
ts.lastScaleBody = string(b)
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-scale"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-scale"), State: v3.OperationStateSuccess})
return
}
if len(parts) == 2 && parts[1] == "api-key" && r.Method == http.MethodGet {
writeJSON(t, w, http.StatusOK, v3.RevealDeploymentAPIKeyResponse{APIKey: "secret"})
testutils.WriteJSON(t, w, http.StatusOK, v3.RevealDeploymentAPIKeyResponse{APIKey: "secret"})
return
}
if len(parts) == 2 && parts[1] == "logs" && r.Method == http.MethodGet {
writeJSON(t, w, http.StatusOK, v3.GetDeploymentLogsResponse{
testutils.WriteJSON(t, w, http.StatusOK, v3.GetDeploymentLogsResponse{
Logs: []v3.GetDeploymentLogsEntry{
{Message: "l1"},
{Message: "l2"},
Expand All @@ -87,7 +85,7 @@ func newDepActionsServer(t *testing.T) *depActionsServer {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID(path.Base(r.URL.Path)), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID(path.Base(r.URL.Path)), State: v3.OperationStateSuccess})
})
ts.server = httptest.NewServer(mux)
return ts
Expand All @@ -96,14 +94,7 @@ func newDepActionsServer(t *testing.T) *depActionsServer {
func TestDeploymentDeleteScaleRevealLogs(t *testing.T) {
ts := newDepActionsServer(t)
defer ts.server.Close()
exocmd.GContext = context.Background()
globalstate.Quiet = true
creds := credentials.NewStaticCredentials("key", "secret")
client, err := v3.NewClient(creds)
if err != nil {
t.Fatalf("new client: %v", err)
}
globalstate.EgoscaleV3Client = client.WithEndpoint(v3.Endpoint(ts.server.URL))
testutils.SetupV3Client(t, ts.server.URL)

now := time.Now()
ts.deployments = []v3.ListDeploymentsResponseEntry{{ID: v3.UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), Name: "alpha", CreatedAT: now, UpdatedAT: now}}
Expand Down Expand Up @@ -150,14 +141,8 @@ func TestDeploymentDeleteScaleRevealLogs(t *testing.T) {
func TestDeploymentScaleZeroIncludesReplicas(t *testing.T) {
ts := newDepActionsServer(t)
defer ts.server.Close()
exocmd.GContext = context.Background()
globalstate.Quiet = true
creds := credentials.NewStaticCredentials("key", "secret")
client, err := v3.NewClient(creds)
if err != nil {
t.Fatalf("new client: %v", err)
}
globalstate.EgoscaleV3Client = client.WithEndpoint(v3.Endpoint(ts.server.URL))
testutils.SetupV3Client(t, ts.server.URL)

now := time.Now()
ts.deployments = []v3.ListDeploymentsResponseEntry{{ID: v3.UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), Name: "alpha", CreatedAT: now, UpdatedAT: now}}
sc := &DeploymentScaleCmd{CliCommandSettings: exocmd.DefaultCLICmdSettings(), Deployment: "alpha", Size: 0}
Expand Down
58 changes: 12 additions & 46 deletions cmd/aiservices/deployment/deployment_create_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package deployment

import (
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"

exocmd "github.com/exoscale/cli/cmd"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/testutils"
v3 "github.com/exoscale/egoscale/v3"
"github.com/exoscale/egoscale/v3/credentials"
)

func TestDeploymentCreateValidationAndSuccess(t *testing.T) {
Expand All @@ -21,26 +19,18 @@ func TestDeploymentCreateValidationAndSuccess(t *testing.T) {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
})
mux.HandleFunc("/operation/", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
})
srv := httptest.NewServer(mux)
defer srv.Close()

exocmd.GContext = context.Background()
globalstate.Quiet = true
creds := credentials.NewStaticCredentials("key", "secret")
client, err := v3.NewClient(creds)
if err != nil {
t.Fatalf("new client: %v", err)
}
globalstate.EgoscaleV3Client = client.WithEndpoint(v3.Endpoint(srv.URL))
testutils.SetupV3Client(t, srv.URL)

// missing gpu flags
c := &DeploymentCreateCmd{CliCommandSettings: exocmd.DefaultCLICmdSettings()}
Expand Down Expand Up @@ -77,26 +67,18 @@ func TestDeploymentCreateWithInferenceEngineParameters(t *testing.T) {
if err := json.Unmarshal(body, &capturedRequest); err != nil {
t.Fatalf("failed to unmarshal request: %v", err)
}
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
})
mux.HandleFunc("/operation/", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
})
srv := httptest.NewServer(mux)
defer srv.Close()

exocmd.GContext = context.Background()
globalstate.Quiet = true
creds := credentials.NewStaticCredentials("key", "secret")
client, err := v3.NewClient(creds)
if err != nil {
t.Fatalf("new client: %v", err)
}
globalstate.EgoscaleV3Client = client.WithEndpoint(v3.Endpoint(srv.URL))
testutils.SetupV3Client(t, srv.URL)

// Test with space-separated inference engine parameters
c := &DeploymentCreateCmd{
Expand Down Expand Up @@ -137,26 +119,18 @@ func TestDeploymentCreateWithInferenceEngineVersion(t *testing.T) {
if err := json.Unmarshal(body, &capturedRequest); err != nil {
t.Fatalf("failed to unmarshal request: %v", err)
}
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
})
mux.HandleFunc("/operation/", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op-deploy-create"), State: v3.OperationStateSuccess})
})
srv := httptest.NewServer(mux)
defer srv.Close()

exocmd.GContext = context.Background()
globalstate.Quiet = true
creds := credentials.NewStaticCredentials("key", "secret")
client, err := v3.NewClient(creds)
if err != nil {
t.Fatalf("new client: %v", err)
}
globalstate.EgoscaleV3Client = client.WithEndpoint(v3.Endpoint(srv.URL))
testutils.SetupV3Client(t, srv.URL)

c := &DeploymentCreateCmd{
CliCommandSettings: exocmd.DefaultCLICmdSettings(),
Expand Down Expand Up @@ -205,19 +179,11 @@ func TestDeploymentCreateInferenceEngineHelp(t *testing.T) {
},
},
}
writeJSON(t, w, http.StatusOK, resp)
testutils.WriteJSON(t, w, http.StatusOK, resp)
})
srv := httptest.NewServer(mux)
defer srv.Close()

exocmd.GContext = context.Background()
globalstate.Quiet = true
creds := credentials.NewStaticCredentials("key", "secret")
client, err := v3.NewClient(creds)
if err != nil {
t.Fatalf("new client: %v", err)
}
globalstate.EgoscaleV3Client = client.WithEndpoint(v3.Endpoint(srv.URL))
testutils.SetupV3Client(t, srv.URL)

c := &DeploymentCreateCmd{
CliCommandSettings: exocmd.DefaultCLICmdSettings(),
Expand Down
17 changes: 6 additions & 11 deletions cmd/aiservices/deployment/deployment_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"testing"
"time"

"github.com/exoscale/cli/pkg/testutils"
v3 "github.com/exoscale/egoscale/v3"
"github.com/exoscale/egoscale/v3/credentials"
)

type depHelperServer struct {
Expand All @@ -24,7 +24,7 @@ func newDepHelperServer(t *testing.T) *depHelperServer {
mux := http.NewServeMux()
mux.HandleFunc("/ai/deployment", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
writeJSON(t, w, http.StatusOK, v3.ListDeploymentsResponse{Deployments: ts.deployments})
testutils.WriteJSON(t, w, http.StatusOK, v3.ListDeploymentsResponse{Deployments: ts.deployments})
return
}
w.WriteHeader(http.StatusMethodNotAllowed)
Expand All @@ -35,13 +35,13 @@ func newDepHelperServer(t *testing.T) *depHelperServer {
case http.MethodGet:
for _, d := range ts.deployments {
if string(d.ID) == id {
writeJSON(t, w, http.StatusOK, v3.GetDeploymentResponse{ID: d.ID, Name: d.Name, State: v3.GetDeploymentResponseState(d.State), GpuType: d.GpuType, GpuCount: d.GpuCount, Replicas: d.Replicas, ServiceLevel: d.ServiceLevel, DeploymentURL: d.DeploymentURL, Model: d.Model, CreatedAT: d.CreatedAT, UpdatedAT: d.UpdatedAT})
testutils.WriteJSON(t, w, http.StatusOK, v3.GetDeploymentResponse{ID: d.ID, Name: d.Name, State: v3.GetDeploymentResponseState(d.State), GpuType: d.GpuType, GpuCount: d.GpuCount, Replicas: d.Replicas, ServiceLevel: d.ServiceLevel, DeploymentURL: d.DeploymentURL, Model: d.Model, CreatedAT: d.CreatedAT, UpdatedAT: d.UpdatedAT})
return
}
}
w.WriteHeader(http.StatusNotFound)
case http.MethodDelete:
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op"), State: v3.OperationStateSuccess})
case http.MethodPost:
if strings.HasSuffix(r.URL.Path, "/scale") {
_, err := io.Copy(io.Discard, r.Body)
Expand All @@ -52,7 +52,7 @@ func newDepHelperServer(t *testing.T) *depHelperServer {
if err != nil {
t.Fail()
}
writeJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op"), State: v3.OperationStateSuccess})
testutils.WriteJSON(t, w, http.StatusOK, v3.Operation{ID: v3.UUID("op"), State: v3.OperationStateSuccess})
return
}
w.WriteHeader(http.StatusNotFound)
Expand All @@ -69,12 +69,7 @@ func TestFindListDeploymentsResponseEntryByIDAndName(t *testing.T) {
defer ts.server.Close()
now := time.Now()
ts.deployments = []v3.ListDeploymentsResponseEntry{{ID: v3.UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), Name: "alpha", CreatedAT: now, UpdatedAT: now}}
creds := credentials.NewStaticCredentials("key", "secret")
client, err := v3.NewClient(creds)
if err != nil {
t.Fatalf("new client: %v", err)
}
client = client.WithEndpoint(v3.Endpoint(ts.server.URL))
client := testutils.NewV3Client(t, ts.server.URL)
ctx := context.Background()

// by ID
Expand Down
Loading
Loading