failure_case_external.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package tester
  15. import (
  16. "fmt"
  17. "os/exec"
  18. )
  19. type failureExternal struct {
  20. Failure
  21. description string
  22. scriptPath string
  23. }
  24. func (f *failureExternal) Inject(clus *Cluster) error {
  25. return exec.Command(f.scriptPath, "enable", fmt.Sprintf("%d", clus.rd)).Run()
  26. }
  27. func (f *failureExternal) Recover(clus *Cluster) error {
  28. return exec.Command(f.scriptPath, "disable", fmt.Sprintf("%d", clus.rd)).Run()
  29. }
  30. func (f *failureExternal) Desc() string { return f.description }
  31. func newFailureExternal(scriptPath string) Failure {
  32. return &failureExternal{
  33. description: fmt.Sprintf("external fault injector (script: %q)", scriptPath),
  34. scriptPath: scriptPath,
  35. }
  36. }