Skip to content

Commit

Permalink
check environment before starting cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Jun 25, 2024
1 parent 55f4598 commit d116e12
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ go.work
# the produced binary
report.xml
errors/
vitess-tester
vitess-tester

# Do not ignore anything inside the src/vitess-tester directory
!/src/vitess-tester/
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ func main() {
flag.Parse()
tests := flag.Args()

err := vitess_tester.CheckEnvironment()
if err != nil {
fmt.Println("Fatal error:")
fmt.Println(err.Error())
os.Exit(1)
}

if ll := os.Getenv("LOG_LEVEL"); ll != "" {
logLevel = ll
}
Expand All @@ -227,7 +234,7 @@ func main() {
defer closer()

// remove errors folder if exists
err := os.RemoveAll("errors")
err = os.RemoveAll("errors")
if err != nil {
panic(err.Error())
}
Expand Down
50 changes: 50 additions & 0 deletions src/vitess-tester/environment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vitess_tester

import (
"fmt"
"os"
"os/exec"
)

var environmentVars = []string{
"VTDATAROOT",
"VTROOT",
}
var neededBinaries = []string{
"vtgate",
"mysqlctl",
}

// CheckEnvironment checks if the required environment variables are set
func CheckEnvironment() error {
for _, envVar := range environmentVars {
if os.Getenv(envVar) == "" {
return fmt.Errorf("environment variable %s is not set\nTry sourcing the dev.env file in the vitess directory", envVar)
}
}

for _, binary := range neededBinaries {
_, err := exec.LookPath(binary)
if err != nil {
return fmt.Errorf("binary %s not found in PATH", binary)
}
}

return nil
}

0 comments on commit d116e12

Please sign in to comment.