crash_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2021 The Rook Authors. All rights reserved.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package client
  14. import (
  15. "testing"
  16. "github.com/pkg/errors"
  17. "github.com/rook/rook/pkg/clusterd"
  18. exectest "github.com/rook/rook/pkg/util/exec/test"
  19. "github.com/stretchr/testify/assert"
  20. )
  21. var (
  22. fakecrash = `[
  23. {
  24. "crash_id": "2020-11-09_13:58:08.230130Z_ca918f58-c078-444d-a91a-bd972c14c155",
  25. "timestamp": "2020-11-09 13:58:08.230130Z",
  26. "process_name": "ceph-osd",
  27. "entity_name": "osd.0"
  28. }
  29. ]`
  30. )
  31. func TestCephCrash(t *testing.T) {
  32. executor := &exectest.MockExecutor{}
  33. context := &clusterd.Context{Executor: executor}
  34. executor.MockExecuteCommandWithOutput = func(command string, args ...string) (string, error) {
  35. logger.Infof("ExecuteCommandWithOutputFile: %s %v", command, args)
  36. if args[0] == "crash" && args[1] == "ls" {
  37. return fakecrash, nil
  38. }
  39. return "", errors.Errorf("unexpected ceph command %q", args)
  40. }
  41. crash, err := GetCrashList(context, AdminTestClusterInfo("mycluster"))
  42. assert.NoError(t, err)
  43. assert.Equal(t, 1, len(crash))
  44. }