cmdline_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package integration
  2. import (
  3. . "gopkg.in/check.v1"
  4. "fmt"
  5. "strings"
  6. )
  7. func (s *QemuSuite) TestElideCmdLine(c *C) {
  8. extra := "cc.hostname=nope rancher.password=three"
  9. runArgs := []string{
  10. "--fresh",
  11. "--append",
  12. "cc.something=yes rancher.password=two",
  13. "--append-init",
  14. extra,
  15. }
  16. s.RunQemuWith(c, runArgs...)
  17. s.CheckOutput(c, "nope\n", Equals, "hostname")
  18. cmdline := s.CheckOutput(c, "", Not(Equals), "cat /proc/cmdline")
  19. if strings.Contains(cmdline, extra) {
  20. c.Errorf("/proc/cmdline (%s) contains info that should be elided (%s)", cmdline, extra)
  21. }
  22. s.CheckOutput(c,
  23. fmt.Sprintf("/init %s\n", extra),
  24. Equals,
  25. "sudo ros config get rancher.environment.EXTRA_CMDLINE",
  26. )
  27. // TODO: it seems that rancher.password and rancher.autologin are in `ros config export`, but accessible as `ros config get`
  28. s.CheckOutput(c, "\n", Equals, "sudo ros config get rancher.password")
  29. s.CheckOutput(c,
  30. "EXTRA_CMDLINE: /init cc.hostname=nope rancher.password=three\n"+
  31. " EXTRA_CMDLINE: /init cc.hostname=nope rancher.password=three\n"+
  32. " password: three\n",
  33. Equals,
  34. "sudo ros config export | grep password",
  35. )
  36. // And then add a service.yml file example.
  37. s.CheckCall(c,
  38. `echo 'test:
  39. image: alpine
  40. command: echo "tell me a secret ${EXTRA_CMDLINE}"
  41. labels:
  42. io.rancher.os.scope: system
  43. environment:
  44. - EXTRA_CMDLINE
  45. ' > test.yml`)
  46. s.CheckCall(c, "sudo mv test.yml /var/lib/rancher/conf/test.yml")
  47. s.CheckCall(c, "sudo ros service enable /var/lib/rancher/conf/test.yml")
  48. s.CheckCall(c, "sudo ros service up test")
  49. s.CheckOutput(c,
  50. "test_1 | tell me a secret /init cc.hostname=nope rancher.password=three\n",
  51. Equals,
  52. "sudo ros service logs test | grep secret",
  53. )
  54. // TODO: add a test showing we have the right password set
  55. }