info.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright 2020 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 test
  14. import (
  15. "context"
  16. "fmt"
  17. "os"
  18. "path"
  19. "github.com/pkg/errors"
  20. "github.com/rook/rook/pkg/daemon/ceph/client"
  21. )
  22. func CreateConfigDir(configDir string) error {
  23. if err := os.MkdirAll(configDir, 0700); err != nil {
  24. return errors.Wrap(err, "error while creating directory")
  25. }
  26. if err := os.WriteFile(path.Join(configDir, "client.admin.keyring"), []byte("key = adminsecret"), 0600); err != nil {
  27. return errors.Wrap(err, "admin writefile error")
  28. }
  29. if err := os.WriteFile(path.Join(configDir, "mon.keyring"), []byte("key = monsecret"), 0600); err != nil {
  30. return errors.Wrap(err, "mon writefile error")
  31. }
  32. return nil
  33. }
  34. // CreateTestClusterInfo creates a test cluster info
  35. // This would be best in a test package, but is included here to avoid cyclic dependencies
  36. func CreateTestClusterInfo(monCount int) *client.ClusterInfo {
  37. ownerInfo := client.NewMinimumOwnerInfoWithOwnerRef()
  38. c := &client.ClusterInfo{
  39. FSID: "12345",
  40. Namespace: "default",
  41. MonitorSecret: "monsecret",
  42. CephCred: client.CephCred{
  43. Username: client.AdminUsername,
  44. Secret: "adminkey",
  45. },
  46. Monitors: map[string]*client.MonInfo{},
  47. OwnerInfo: ownerInfo,
  48. Context: context.TODO(),
  49. }
  50. mons := []string{"a", "b", "c", "d", "e"}
  51. for i := 0; i < monCount; i++ {
  52. id := mons[i]
  53. c.Monitors[id] = &client.MonInfo{
  54. Name: id,
  55. Endpoint: fmt.Sprintf("1.2.3.%d:3300", (i + 1)),
  56. }
  57. }
  58. c.SetName(c.Namespace)
  59. return c
  60. }