daemon.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. package daemon // import "github.com/docker/docker/internal/test/daemon"
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "net/http"
  8. "os"
  9. "os/exec"
  10. "path/filepath"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/docker/docker/api/types"
  15. "github.com/docker/docker/api/types/events"
  16. "github.com/docker/docker/client"
  17. "github.com/docker/docker/internal/test"
  18. "github.com/docker/docker/internal/test/request"
  19. "github.com/docker/docker/opts"
  20. "github.com/docker/docker/pkg/ioutils"
  21. "github.com/docker/docker/pkg/stringid"
  22. "github.com/docker/go-connections/sockets"
  23. "github.com/docker/go-connections/tlsconfig"
  24. "github.com/pkg/errors"
  25. "gotest.tools/assert"
  26. )
  27. type testingT interface {
  28. assert.TestingT
  29. logT
  30. Fatalf(string, ...interface{})
  31. }
  32. type logT interface {
  33. Logf(string, ...interface{})
  34. }
  35. const defaultDockerdBinary = "dockerd"
  36. var errDaemonNotStarted = errors.New("daemon not started")
  37. // SockRoot holds the path of the default docker integration daemon socket
  38. var SockRoot = filepath.Join(os.TempDir(), "docker-integration")
  39. type clientConfig struct {
  40. transport *http.Transport
  41. scheme string
  42. addr string
  43. }
  44. // Daemon represents a Docker daemon for the testing framework
  45. type Daemon struct {
  46. GlobalFlags []string
  47. Root string
  48. Folder string
  49. Wait chan error
  50. UseDefaultHost bool
  51. UseDefaultTLSHost bool
  52. id string
  53. logFile *os.File
  54. cmd *exec.Cmd
  55. storageDriver string
  56. userlandProxy bool
  57. execRoot string
  58. experimental bool
  59. init bool
  60. dockerdBinary string
  61. log logT
  62. // swarm related field
  63. swarmListenAddr string
  64. SwarmPort int // FIXME(vdemeester) should probably not be exported
  65. // cached information
  66. CachedInfo types.Info
  67. }
  68. // New returns a Daemon instance to be used for testing.
  69. // This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST.
  70. // The daemon will not automatically start.
  71. func New(t testingT, ops ...func(*Daemon)) *Daemon {
  72. if ht, ok := t.(test.HelperT); ok {
  73. ht.Helper()
  74. }
  75. dest := os.Getenv("DOCKER_INTEGRATION_DAEMON_DEST")
  76. if dest == "" {
  77. dest = os.Getenv("DEST")
  78. }
  79. assert.Check(t, dest != "", "Please set the DOCKER_INTEGRATION_DAEMON_DEST or the DEST environment variable")
  80. storageDriver := os.Getenv("DOCKER_GRAPHDRIVER")
  81. assert.NilError(t, os.MkdirAll(SockRoot, 0700), "could not create daemon socket root")
  82. id := fmt.Sprintf("d%s", stringid.TruncateID(stringid.GenerateRandomID()))
  83. dir := filepath.Join(dest, id)
  84. daemonFolder, err := filepath.Abs(dir)
  85. assert.NilError(t, err, "Could not make %q an absolute path", dir)
  86. daemonRoot := filepath.Join(daemonFolder, "root")
  87. assert.NilError(t, os.MkdirAll(daemonRoot, 0755), "Could not create daemon root %q", dir)
  88. userlandProxy := true
  89. if env := os.Getenv("DOCKER_USERLANDPROXY"); env != "" {
  90. if val, err := strconv.ParseBool(env); err != nil {
  91. userlandProxy = val
  92. }
  93. }
  94. d := &Daemon{
  95. id: id,
  96. Folder: daemonFolder,
  97. Root: daemonRoot,
  98. storageDriver: storageDriver,
  99. userlandProxy: userlandProxy,
  100. execRoot: filepath.Join(os.TempDir(), "docker-execroot", id),
  101. dockerdBinary: defaultDockerdBinary,
  102. swarmListenAddr: defaultSwarmListenAddr,
  103. SwarmPort: DefaultSwarmPort,
  104. log: t,
  105. }
  106. for _, op := range ops {
  107. op(d)
  108. }
  109. return d
  110. }
  111. // RootDir returns the root directory of the daemon.
  112. func (d *Daemon) RootDir() string {
  113. return d.Root
  114. }
  115. // ID returns the generated id of the daemon
  116. func (d *Daemon) ID() string {
  117. return d.id
  118. }
  119. // StorageDriver returns the configured storage driver of the daemon
  120. func (d *Daemon) StorageDriver() string {
  121. return d.storageDriver
  122. }
  123. // Sock returns the socket path of the daemon
  124. func (d *Daemon) Sock() string {
  125. return fmt.Sprintf("unix://" + d.sockPath())
  126. }
  127. func (d *Daemon) sockPath() string {
  128. return filepath.Join(SockRoot, d.id+".sock")
  129. }
  130. // LogFileName returns the path the daemon's log file
  131. func (d *Daemon) LogFileName() string {
  132. return d.logFile.Name()
  133. }
  134. // ReadLogFile returns the content of the daemon log file
  135. func (d *Daemon) ReadLogFile() ([]byte, error) {
  136. return ioutil.ReadFile(d.logFile.Name())
  137. }
  138. // NewClient creates new client based on daemon's socket path
  139. // FIXME(vdemeester): replace NewClient with NewClientT
  140. func (d *Daemon) NewClient() (*client.Client, error) {
  141. return client.NewClientWithOpts(
  142. client.FromEnv,
  143. client.WithHost(d.Sock()))
  144. }
  145. // NewClientT creates new client based on daemon's socket path
  146. // FIXME(vdemeester): replace NewClient with NewClientT
  147. func (d *Daemon) NewClientT(t assert.TestingT) *client.Client {
  148. if ht, ok := t.(test.HelperT); ok {
  149. ht.Helper()
  150. }
  151. c, err := client.NewClientWithOpts(
  152. client.FromEnv,
  153. client.WithHost(d.Sock()))
  154. assert.NilError(t, err, "cannot create daemon client")
  155. return c
  156. }
  157. // Cleanup cleans the daemon files : exec root (network namespaces, ...), swarmkit files
  158. func (d *Daemon) Cleanup(t testingT) {
  159. if ht, ok := t.(test.HelperT); ok {
  160. ht.Helper()
  161. }
  162. // Cleanup swarmkit wal files if present
  163. cleanupRaftDir(t, d.Root)
  164. cleanupNetworkNamespace(t, d.execRoot)
  165. }
  166. // Start starts the daemon and return once it is ready to receive requests.
  167. func (d *Daemon) Start(t testingT, args ...string) {
  168. if ht, ok := t.(test.HelperT); ok {
  169. ht.Helper()
  170. }
  171. if err := d.StartWithError(args...); err != nil {
  172. t.Fatalf("Error starting daemon with arguments: %v", args)
  173. }
  174. }
  175. // StartWithError starts the daemon and return once it is ready to receive requests.
  176. // It returns an error in case it couldn't start.
  177. func (d *Daemon) StartWithError(args ...string) error {
  178. logFile, err := os.OpenFile(filepath.Join(d.Folder, "docker.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
  179. if err != nil {
  180. return errors.Wrapf(err, "[%s] Could not create %s/docker.log", d.id, d.Folder)
  181. }
  182. return d.StartWithLogFile(logFile, args...)
  183. }
  184. // StartWithLogFile will start the daemon and attach its streams to a given file.
  185. func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
  186. d.handleUserns()
  187. dockerdBinary, err := exec.LookPath(d.dockerdBinary)
  188. if err != nil {
  189. return errors.Wrapf(err, "[%s] could not find docker binary in $PATH", d.id)
  190. }
  191. args := append(d.GlobalFlags,
  192. "--containerd", "/var/run/docker/containerd/docker-containerd.sock",
  193. "--data-root", d.Root,
  194. "--exec-root", d.execRoot,
  195. "--pidfile", fmt.Sprintf("%s/docker.pid", d.Folder),
  196. fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
  197. )
  198. if d.experimental {
  199. args = append(args, "--experimental")
  200. }
  201. if d.init {
  202. args = append(args, "--init")
  203. }
  204. if !(d.UseDefaultHost || d.UseDefaultTLSHost) {
  205. args = append(args, []string{"--host", d.Sock()}...)
  206. }
  207. if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" {
  208. args = append(args, []string{"--userns-remap", root}...)
  209. }
  210. // If we don't explicitly set the log-level or debug flag(-D) then
  211. // turn on debug mode
  212. foundLog := false
  213. foundSd := false
  214. for _, a := range providedArgs {
  215. if strings.Contains(a, "--log-level") || strings.Contains(a, "-D") || strings.Contains(a, "--debug") {
  216. foundLog = true
  217. }
  218. if strings.Contains(a, "--storage-driver") {
  219. foundSd = true
  220. }
  221. }
  222. if !foundLog {
  223. args = append(args, "--debug")
  224. }
  225. if d.storageDriver != "" && !foundSd {
  226. args = append(args, "--storage-driver", d.storageDriver)
  227. }
  228. args = append(args, providedArgs...)
  229. d.cmd = exec.Command(dockerdBinary, args...)
  230. d.cmd.Env = append(os.Environ(), "DOCKER_SERVICE_PREFER_OFFLINE_IMAGE=1")
  231. d.cmd.Stdout = out
  232. d.cmd.Stderr = out
  233. d.logFile = out
  234. if err := d.cmd.Start(); err != nil {
  235. return errors.Errorf("[%s] could not start daemon container: %v", d.id, err)
  236. }
  237. wait := make(chan error)
  238. go func() {
  239. wait <- d.cmd.Wait()
  240. d.log.Logf("[%s] exiting daemon", d.id)
  241. close(wait)
  242. }()
  243. d.Wait = wait
  244. tick := time.Tick(500 * time.Millisecond)
  245. // make sure daemon is ready to receive requests
  246. startTime := time.Now().Unix()
  247. for {
  248. d.log.Logf("[%s] waiting for daemon to start", d.id)
  249. if time.Now().Unix()-startTime > 5 {
  250. // After 5 seconds, give up
  251. return errors.Errorf("[%s] Daemon exited and never started", d.id)
  252. }
  253. select {
  254. case <-time.After(2 * time.Second):
  255. return errors.Errorf("[%s] timeout: daemon does not respond", d.id)
  256. case <-tick:
  257. clientConfig, err := d.getClientConfig()
  258. if err != nil {
  259. return err
  260. }
  261. client := &http.Client{
  262. Transport: clientConfig.transport,
  263. }
  264. req, err := http.NewRequest("GET", "/_ping", nil)
  265. if err != nil {
  266. return errors.Wrapf(err, "[%s] could not create new request", d.id)
  267. }
  268. req.URL.Host = clientConfig.addr
  269. req.URL.Scheme = clientConfig.scheme
  270. resp, err := client.Do(req)
  271. if err != nil {
  272. continue
  273. }
  274. resp.Body.Close()
  275. if resp.StatusCode != http.StatusOK {
  276. d.log.Logf("[%s] received status != 200 OK: %s\n", d.id, resp.Status)
  277. }
  278. d.log.Logf("[%s] daemon started\n", d.id)
  279. d.Root, err = d.queryRootDir()
  280. if err != nil {
  281. return errors.Errorf("[%s] error querying daemon for root directory: %v", d.id, err)
  282. }
  283. return nil
  284. case <-d.Wait:
  285. return errors.Errorf("[%s] Daemon exited during startup", d.id)
  286. }
  287. }
  288. }
  289. // StartWithBusybox will first start the daemon with Daemon.Start()
  290. // then save the busybox image from the main daemon and load it into this Daemon instance.
  291. func (d *Daemon) StartWithBusybox(t testingT, arg ...string) {
  292. if ht, ok := t.(test.HelperT); ok {
  293. ht.Helper()
  294. }
  295. d.Start(t, arg...)
  296. d.LoadBusybox(t)
  297. }
  298. // Kill will send a SIGKILL to the daemon
  299. func (d *Daemon) Kill() error {
  300. if d.cmd == nil || d.Wait == nil {
  301. return errDaemonNotStarted
  302. }
  303. defer func() {
  304. d.logFile.Close()
  305. d.cmd = nil
  306. }()
  307. if err := d.cmd.Process.Kill(); err != nil {
  308. return err
  309. }
  310. return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
  311. }
  312. // Pid returns the pid of the daemon
  313. func (d *Daemon) Pid() int {
  314. return d.cmd.Process.Pid
  315. }
  316. // Interrupt stops the daemon by sending it an Interrupt signal
  317. func (d *Daemon) Interrupt() error {
  318. return d.Signal(os.Interrupt)
  319. }
  320. // Signal sends the specified signal to the daemon if running
  321. func (d *Daemon) Signal(signal os.Signal) error {
  322. if d.cmd == nil || d.Wait == nil {
  323. return errDaemonNotStarted
  324. }
  325. return d.cmd.Process.Signal(signal)
  326. }
  327. // DumpStackAndQuit sends SIGQUIT to the daemon, which triggers it to dump its
  328. // stack to its log file and exit
  329. // This is used primarily for gathering debug information on test timeout
  330. func (d *Daemon) DumpStackAndQuit() {
  331. if d.cmd == nil || d.cmd.Process == nil {
  332. return
  333. }
  334. SignalDaemonDump(d.cmd.Process.Pid)
  335. }
  336. // Stop will send a SIGINT every second and wait for the daemon to stop.
  337. // If it times out, a SIGKILL is sent.
  338. // Stop will not delete the daemon directory. If a purged daemon is needed,
  339. // instantiate a new one with NewDaemon.
  340. // If an error occurs while starting the daemon, the test will fail.
  341. func (d *Daemon) Stop(t testingT) {
  342. if ht, ok := t.(test.HelperT); ok {
  343. ht.Helper()
  344. }
  345. err := d.StopWithError()
  346. if err != nil {
  347. if err != errDaemonNotStarted {
  348. t.Fatalf("Error while stopping the daemon %s : %v", d.id, err)
  349. } else {
  350. t.Logf("Daemon %s is not started", d.id)
  351. }
  352. }
  353. }
  354. // StopWithError will send a SIGINT every second and wait for the daemon to stop.
  355. // If it timeouts, a SIGKILL is sent.
  356. // Stop will not delete the daemon directory. If a purged daemon is needed,
  357. // instantiate a new one with NewDaemon.
  358. func (d *Daemon) StopWithError() error {
  359. if d.cmd == nil || d.Wait == nil {
  360. return errDaemonNotStarted
  361. }
  362. defer func() {
  363. d.logFile.Close()
  364. d.cmd = nil
  365. }()
  366. i := 1
  367. tick := time.Tick(time.Second)
  368. if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
  369. if strings.Contains(err.Error(), "os: process already finished") {
  370. return errDaemonNotStarted
  371. }
  372. return errors.Errorf("could not send signal: %v", err)
  373. }
  374. out1:
  375. for {
  376. select {
  377. case err := <-d.Wait:
  378. return err
  379. case <-time.After(20 * time.Second):
  380. // time for stopping jobs and run onShutdown hooks
  381. d.log.Logf("[%s] daemon stop timeout", d.id)
  382. break out1
  383. }
  384. }
  385. out2:
  386. for {
  387. select {
  388. case err := <-d.Wait:
  389. return err
  390. case <-tick:
  391. i++
  392. if i > 5 {
  393. d.log.Logf("tried to interrupt daemon for %d times, now try to kill it", i)
  394. break out2
  395. }
  396. d.log.Logf("Attempt #%d: daemon is still running with pid %d", i, d.cmd.Process.Pid)
  397. if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
  398. return errors.Errorf("could not send signal: %v", err)
  399. }
  400. }
  401. }
  402. if err := d.cmd.Process.Kill(); err != nil {
  403. d.log.Logf("Could not kill daemon: %v", err)
  404. return err
  405. }
  406. d.cmd.Wait()
  407. return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
  408. }
  409. // Restart will restart the daemon by first stopping it and the starting it.
  410. // If an error occurs while starting the daemon, the test will fail.
  411. func (d *Daemon) Restart(t testingT, args ...string) {
  412. if ht, ok := t.(test.HelperT); ok {
  413. ht.Helper()
  414. }
  415. d.Stop(t)
  416. d.Start(t, args...)
  417. }
  418. // RestartWithError will restart the daemon by first stopping it and then starting it.
  419. func (d *Daemon) RestartWithError(arg ...string) error {
  420. if err := d.StopWithError(); err != nil {
  421. return err
  422. }
  423. return d.StartWithError(arg...)
  424. }
  425. func (d *Daemon) handleUserns() {
  426. // in the case of tests running a user namespace-enabled daemon, we have resolved
  427. // d.Root to be the actual final path of the graph dir after the "uid.gid" of
  428. // remapped root is added--we need to subtract it from the path before calling
  429. // start or else we will continue making subdirectories rather than truly restarting
  430. // with the same location/root:
  431. if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" {
  432. d.Root = filepath.Dir(d.Root)
  433. }
  434. }
  435. // ReloadConfig asks the daemon to reload its configuration
  436. func (d *Daemon) ReloadConfig() error {
  437. if d.cmd == nil || d.cmd.Process == nil {
  438. return errors.New("daemon is not running")
  439. }
  440. errCh := make(chan error)
  441. started := make(chan struct{})
  442. go func() {
  443. _, body, err := request.Get("/events", request.Host(d.Sock()))
  444. close(started)
  445. if err != nil {
  446. errCh <- err
  447. }
  448. defer body.Close()
  449. dec := json.NewDecoder(body)
  450. for {
  451. var e events.Message
  452. if err := dec.Decode(&e); err != nil {
  453. errCh <- err
  454. return
  455. }
  456. if e.Type != events.DaemonEventType {
  457. continue
  458. }
  459. if e.Action != "reload" {
  460. continue
  461. }
  462. close(errCh) // notify that we are done
  463. return
  464. }
  465. }()
  466. <-started
  467. if err := signalDaemonReload(d.cmd.Process.Pid); err != nil {
  468. return errors.Errorf("error signaling daemon reload: %v", err)
  469. }
  470. select {
  471. case err := <-errCh:
  472. if err != nil {
  473. return errors.Errorf("error waiting for daemon reload event: %v", err)
  474. }
  475. case <-time.After(30 * time.Second):
  476. return errors.New("timeout waiting for daemon reload event")
  477. }
  478. return nil
  479. }
  480. // LoadBusybox image into the daemon
  481. func (d *Daemon) LoadBusybox(t assert.TestingT) {
  482. if ht, ok := t.(test.HelperT); ok {
  483. ht.Helper()
  484. }
  485. clientHost, err := client.NewEnvClient()
  486. assert.NilError(t, err, "failed to create client")
  487. defer clientHost.Close()
  488. ctx := context.Background()
  489. reader, err := clientHost.ImageSave(ctx, []string{"busybox:latest"})
  490. assert.NilError(t, err, "failed to download busybox")
  491. defer reader.Close()
  492. client, err := d.NewClient()
  493. assert.NilError(t, err, "failed to create client")
  494. defer client.Close()
  495. resp, err := client.ImageLoad(ctx, reader, true)
  496. assert.NilError(t, err, "failed to load busybox")
  497. defer resp.Body.Close()
  498. }
  499. func (d *Daemon) getClientConfig() (*clientConfig, error) {
  500. var (
  501. transport *http.Transport
  502. scheme string
  503. addr string
  504. proto string
  505. )
  506. if d.UseDefaultTLSHost {
  507. option := &tlsconfig.Options{
  508. CAFile: "fixtures/https/ca.pem",
  509. CertFile: "fixtures/https/client-cert.pem",
  510. KeyFile: "fixtures/https/client-key.pem",
  511. }
  512. tlsConfig, err := tlsconfig.Client(*option)
  513. if err != nil {
  514. return nil, err
  515. }
  516. transport = &http.Transport{
  517. TLSClientConfig: tlsConfig,
  518. }
  519. addr = fmt.Sprintf("%s:%d", opts.DefaultHTTPHost, opts.DefaultTLSHTTPPort)
  520. scheme = "https"
  521. proto = "tcp"
  522. } else if d.UseDefaultHost {
  523. addr = opts.DefaultUnixSocket
  524. proto = "unix"
  525. scheme = "http"
  526. transport = &http.Transport{}
  527. } else {
  528. addr = d.sockPath()
  529. proto = "unix"
  530. scheme = "http"
  531. transport = &http.Transport{}
  532. }
  533. if err := sockets.ConfigureTransport(transport, proto, addr); err != nil {
  534. return nil, err
  535. }
  536. transport.DisableKeepAlives = true
  537. return &clientConfig{
  538. transport: transport,
  539. scheme: scheme,
  540. addr: addr,
  541. }, nil
  542. }
  543. func (d *Daemon) queryRootDir() (string, error) {
  544. // update daemon root by asking /info endpoint (to support user
  545. // namespaced daemon with root remapped uid.gid directory)
  546. clientConfig, err := d.getClientConfig()
  547. if err != nil {
  548. return "", err
  549. }
  550. client := &http.Client{
  551. Transport: clientConfig.transport,
  552. }
  553. req, err := http.NewRequest("GET", "/info", nil)
  554. if err != nil {
  555. return "", err
  556. }
  557. req.Header.Set("Content-Type", "application/json")
  558. req.URL.Host = clientConfig.addr
  559. req.URL.Scheme = clientConfig.scheme
  560. resp, err := client.Do(req)
  561. if err != nil {
  562. return "", err
  563. }
  564. body := ioutils.NewReadCloserWrapper(resp.Body, func() error {
  565. return resp.Body.Close()
  566. })
  567. type Info struct {
  568. DockerRootDir string
  569. }
  570. var b []byte
  571. var i Info
  572. b, err = request.ReadBody(body)
  573. if err == nil && resp.StatusCode == http.StatusOK {
  574. // read the docker root dir
  575. if err = json.Unmarshal(b, &i); err == nil {
  576. return i.DockerRootDir, nil
  577. }
  578. }
  579. return "", err
  580. }
  581. // Info returns the info struct for this daemon
  582. func (d *Daemon) Info(t assert.TestingT) types.Info {
  583. if ht, ok := t.(test.HelperT); ok {
  584. ht.Helper()
  585. }
  586. apiclient, err := d.NewClient()
  587. assert.NilError(t, err)
  588. info, err := apiclient.Info(context.Background())
  589. assert.NilError(t, err)
  590. return info
  591. }
  592. func cleanupRaftDir(t testingT, rootPath string) {
  593. if ht, ok := t.(test.HelperT); ok {
  594. ht.Helper()
  595. }
  596. walDir := filepath.Join(rootPath, "swarm/raft/wal")
  597. if err := os.RemoveAll(walDir); err != nil {
  598. t.Logf("error removing %v: %v", walDir, err)
  599. }
  600. }