Add function test CLI tests (#2871)
* Add function test CLI tests * Add few more services to tests Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -203,9 +203,18 @@ func (gp *GenericPool) updateCPUUtilizationSvc(ctx context.Context) {
|
||||
}
|
||||
if value, ok := gp.podFSVCMap.Load(val.ObjectMeta.Name); ok {
|
||||
if valArray, ok1 := value.([]interface{}); ok1 {
|
||||
function, address := valArray[0], valArray[1]
|
||||
gp.fsCache.SetCPUUtilizaton(function.(crd.CacheKeyURG), address.(string), p)
|
||||
gp.logger.Info(fmt.Sprintf("updated function %s, address %s, cpuUsage %+v", function.(string), address.(string), p))
|
||||
function, ok2 := valArray[0].(crd.CacheKeyURG)
|
||||
if !ok2 {
|
||||
gp.logger.Error("failed to convert function to type", zap.Any("function", function))
|
||||
return
|
||||
}
|
||||
address, ok2 := valArray[1].(string)
|
||||
if !ok2 {
|
||||
gp.logger.Error("failed to convert address to string", zap.Any("address", address))
|
||||
return
|
||||
}
|
||||
gp.fsCache.SetCPUUtilizaton(function, address, p)
|
||||
gp.logger.Info("updated function cpu usage", zap.Any("function", function), zap.String("address", address), zap.Any("cpuUsage", p))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (opts *LogSubCommand) do(input cli.Input) error {
|
||||
// request the controller to establish a proxy server to the database.
|
||||
logDB, err := logdb.GetLogDB(dbType, input.Context(), logDBOptions)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get log database")
|
||||
return errors.Wrapf(err, "failed to get log from %s", dbType)
|
||||
}
|
||||
|
||||
requestChan := make(chan struct{})
|
||||
|
||||
@@ -164,13 +164,13 @@ func (opts *TestSubCommand) do(input cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
console.Errorf("Error calling function %s: %d; Please try again or fix the error: %s\n", m.Name, resp.StatusCode, string(body))
|
||||
err = printPodLogs(input.Context(), opts.Client(), m)
|
||||
console.Errorf("calling function %s: %d; Please try again or fix the error: %s\n", m.Name, resp.StatusCode, string(body))
|
||||
err = util.FunctionPodLogs(input.Context(), m.Name, m.Namespace, opts.Client())
|
||||
if err != nil {
|
||||
console.Errorf("Error getting function logs from controller: %v. Try to get logs from log database.", err)
|
||||
console.Errorf("getting function logs: %v. Try to get logs from log database.", err)
|
||||
err = Log(input)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error retrieving function log from log database")
|
||||
console.Errorf("getting function logs from log database: %v", err)
|
||||
}
|
||||
}
|
||||
return errors.New("error getting function response")
|
||||
@@ -236,13 +236,3 @@ func doHTTPRequest(ctx context.Context, url string, headers []string, method, bo
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func printPodLogs(ctx context.Context, client cmd.Client, fnMeta *metav1.ObjectMeta) error {
|
||||
err := util.FunctionPodLogs(ctx, fnMeta.Name, fnMeta.Namespace, client)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing get logs request")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -70,7 +69,8 @@ func GetFunctionPodLogs(ctx context.Context, client cmd.Client, logFilter LogFil
|
||||
fv1.ENVIRONMENT_NAMESPACE: f.Spec.Environment.Namespace,
|
||||
}
|
||||
|
||||
podList, err := client.KubernetesClient.CoreV1().Pods(util.ResolveFunctionNS(podNs)).List(ctx, metav1.ListOptions{
|
||||
podNs = util.ResolveFunctionNS(podNs)
|
||||
podList, err := client.KubernetesClient.CoreV1().Pods(podNs).List(ctx, metav1.ListOptions{
|
||||
LabelSelector: labels.Set(selector).AsSelector().String(),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -78,10 +78,7 @@ func GetFunctionPodLogs(ctx context.Context, client cmd.Client, logFilter LogFil
|
||||
}
|
||||
|
||||
if len(podList.Items) <= 0 {
|
||||
if logFilter.WarnUser {
|
||||
console.Warn("version<1.18 used fission-function as pod's default namespace. Specify appropriate namespace with --pod-namespace tag or export an environment variable for function-namespace FUNCTION_NAMESPACE")
|
||||
}
|
||||
return errors.New("no active pods found")
|
||||
return errors.Errorf("no active pods found for function in namespace %s", podNs)
|
||||
}
|
||||
|
||||
pods := podList.Items
|
||||
|
||||
@@ -582,8 +582,7 @@ func FunctionPodLogs(ctx context.Context, fnName, ns string, client cmd.Client)
|
||||
})
|
||||
|
||||
if len(pods) <= 0 {
|
||||
return errors.New("no active pods found")
|
||||
|
||||
return errors.New("no active pods found for function in namespace " + podNs)
|
||||
}
|
||||
|
||||
// get the pod with highest resource version
|
||||
|
||||
@@ -705,6 +705,10 @@ func (fh functionHandler) getServiceEntry(ctx context.Context) (svcURL *url.URL,
|
||||
},
|
||||
)
|
||||
|
||||
if recordObj == nil {
|
||||
return nil, false, fmt.Errorf("empty service entry: %w", err)
|
||||
}
|
||||
|
||||
record, ok := recordObj.(svcEntryRecord)
|
||||
if !ok {
|
||||
return nil, false, fmt.Errorf("unexpected type of recordObj %T: %w", recordObj, err)
|
||||
|
||||
+12
-12
@@ -122,20 +122,20 @@ func TestFissionCLI(t *testing.T) {
|
||||
require.Equal(t, v1.ExecutorTypePoolmgr, testFunc.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType)
|
||||
})
|
||||
|
||||
// t.Run("test/poolmgr", func(t *testing.T) {
|
||||
// _, err := cli.ExecCommand(f, ctx, "function", "test", "--name", testFuncName)
|
||||
// require.NoError(t, err)
|
||||
// })
|
||||
t.Run("test/poolmgr", func(t *testing.T) {
|
||||
_, err := cli.ExecCommand(f, ctx, "function", "test", "--name", testFuncName)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
// t.Run("test/newdeploy", func(t *testing.T) {
|
||||
// _, err := cli.ExecCommand(f, ctx, "function", "test", "--name", testFuncNd)
|
||||
// require.NoError(t, err)
|
||||
// })
|
||||
t.Run("test/newdeploy", func(t *testing.T) {
|
||||
_, err := cli.ExecCommand(f, ctx, "function", "test", "--name", testFuncNd)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
// t.Run("test/container", func(t *testing.T) {
|
||||
// _, err := cli.ExecCommand(f, ctx, "function", "test", "--name", testFuncCn)
|
||||
// require.NoError(t, err)
|
||||
// })
|
||||
t.Run("test/container", func(t *testing.T) {
|
||||
_, err := cli.ExecCommand(f, ctx, "function", "test", "--name", testFuncCn)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("delete/newdeploy", func(t *testing.T) {
|
||||
_, err := cli.ExecCommand(f, ctx, "function", "delete", "--name", testFuncNd)
|
||||
|
||||
@@ -8,8 +8,11 @@ import (
|
||||
"github.com/fission/fission/pkg/buildermgr"
|
||||
"github.com/fission/fission/pkg/executor"
|
||||
eclient "github.com/fission/fission/pkg/executor/client"
|
||||
"github.com/fission/fission/pkg/kubewatcher"
|
||||
"github.com/fission/fission/pkg/mqtrigger"
|
||||
"github.com/fission/fission/pkg/router"
|
||||
"github.com/fission/fission/pkg/storagesvc"
|
||||
"github.com/fission/fission/pkg/timer"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
"github.com/fission/fission/pkg/utils/manager"
|
||||
"github.com/fission/fission/test/e2e/framework"
|
||||
@@ -104,6 +107,25 @@ func StartServices(ctx context.Context, f *framework.Framework, mgr manager.Inte
|
||||
f.ServiceInfo["router"] = framework.ServiceInfo{
|
||||
Port: routerPort,
|
||||
}
|
||||
os.Setenv("FISSION_ROUTER_URL", fmt.Sprintf("http://localhost:%d", routerPort))
|
||||
routerURL := fmt.Sprintf("http://localhost:%d", routerPort)
|
||||
os.Setenv("FISSION_ROUTER_URL", routerURL)
|
||||
|
||||
err = timer.Start(ctx, f.ClientGen(), f.Logger(), mgr, routerURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error starting timer: %v", err)
|
||||
}
|
||||
f.ServiceInfo["timer"] = framework.ServiceInfo{}
|
||||
|
||||
err = mqtrigger.StartScalerManager(ctx, f.ClientGen(), f.Logger(), mgr, routerURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error starting mqt scaler manager: %v", err)
|
||||
}
|
||||
f.ServiceInfo["mqtrigger-keda"] = framework.ServiceInfo{}
|
||||
|
||||
err = kubewatcher.Start(ctx, f.ClientGen(), f.Logger(), mgr, routerURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error starting kubewatcher: %v", err)
|
||||
}
|
||||
f.ServiceInfo["kubewatcher"] = framework.ServiceInfo{}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user