forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e test to presubmit (kubeflow#652)
* Adding grid e2e test to presubmit * Adding extra checks
- Loading branch information
1 parent
ae10864
commit c81692c
Showing
3 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
k8syaml "k8s.io/apimachinery/pkg/util/yaml" | ||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2" | ||
"github.com/kubeflow/katib/pkg/util/v1alpha2/katibclient" | ||
) | ||
|
||
const ( | ||
timeout = 20 * time.Minute | ||
) | ||
|
||
func verifyResult(exp *experimentsv1alpha2.Experiment) error { | ||
if len(exp.Status.CurrentOptimalTrial.ParameterAssignments) == 0 { | ||
return fmt.Errorf("Best parameter assignments not updated in status") | ||
} | ||
|
||
if len(exp.Status.CurrentOptimalTrial.Observation.Metrics) == 0 { | ||
return fmt.Errorf("Bst metrics not updated in status") | ||
} | ||
|
||
metric := exp.Status.CurrentOptimalTrial.Observation.Metrics[0] | ||
if metric.Name != exp.Spec.Objective.ObjectiveMetricName { | ||
return fmt.Errorf("Best objective metric not updated in status") | ||
} | ||
return nil | ||
} | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
log.Fatal("Experiment name is missing") | ||
} | ||
expName := os.Args[1] | ||
b, err := ioutil.ReadFile(expName) | ||
if err != nil { | ||
log.Fatal("Error in reading file ", err) | ||
} | ||
exp := &experimentsv1alpha2.Experiment{} | ||
buf := bytes.NewBufferString(string(b)) | ||
if err = k8syaml.NewYAMLOrJSONDecoder(buf, 1024).Decode(exp); err != nil { | ||
log.Fatal("Yaml decode error ", err) | ||
} | ||
kclient, err := katibclient.NewClient(client.Options{}) | ||
if err != nil { | ||
log.Fatal("NewClient for Katib failed: ", err) | ||
} | ||
var maxtrials int32 = 3 | ||
var paralleltrials int32 = 2 | ||
exp.Spec.MaxTrialCount = &maxtrials | ||
exp.Spec.ParallelTrialCount = ¶lleltrials | ||
err = kclient.CreateExperiment(exp) | ||
if err != nil { | ||
log.Fatal("CreateExperiment from YAML failed: ", err) | ||
} | ||
|
||
for endTime := time.Now().Add(timeout); time.Now().Before(endTime); { | ||
exp, err = kclient.GetExperiment(exp.Name, exp.Namespace) | ||
if err != nil { | ||
log.Fatal("Get Experiment error ", err) | ||
} | ||
if exp.IsCompleted() { | ||
log.Printf("Job %v finished", exp.Name) | ||
break | ||
} | ||
log.Printf("Waiting for job %v to finish. [ %v trials running %v succeeded ]", exp.Name, exp.Status.TrialsRunning, exp.Status.TrialsSucceeded) | ||
time.Sleep(20 * time.Second) | ||
} | ||
|
||
if !exp.IsCompleted() { | ||
log.Fatal("Experiment run timed out") | ||
} | ||
|
||
if exp.Status.Trials != *exp.Spec.MaxTrialCount { | ||
log.Fatal("All trials are not run in the experiment ", exp.Status.Trials, exp.Spec.MaxTrialCount) | ||
} | ||
|
||
if exp.Status.TrialsSucceeded != *exp.Spec.MaxTrialCount { | ||
log.Fatal("All trials are not successful ", exp.Status.TrialsSucceeded, *exp.Spec.MaxTrialCount) | ||
} | ||
err = verifyResult(exp) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("Experiment has recorded best current Optimal Trial %v", exp.Status.CurrentOptimalTrial) | ||
err = kclient.DeleteExperiment(exp) | ||
if err != nil { | ||
log.Printf("CreateExperiment from YAML failed: %v", err) | ||
return | ||
} | ||
log.Printf("Experiment %v deleted", exp.Name) | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,7 +261,7 @@ | |
], | ||
[ | ||
{ | ||
name: "run-tests", | ||
name: "run-e2e-tests", | ||
template: "run-tests", | ||
}, | ||
], | ||
|