daemon.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. const containerdSocket = "/var/run/docker/containerd/containerd.sock"
  37. var errDaemonNotStarted = errors.New("daemon not started")
  38. // SockRoot holds the path of the default docker integration daemon socket
  39. var SockRoot = filepath.Join(os.TempDir(), "docker-integration")
  40. type clientConfig struct {
  41. transport *http.Transport
  42. scheme string
  43. addr string
  44. }
  45. // Daemon represents a Docker daemon for the testing framework
  46. type Daemon struct {
  47. GlobalFlags []string
  48. Root string
  49. Folder string
  50. Wait chan error
  51. UseDefaultHost bool
  52. UseDefaultTLSHost bool
  53. id string
  54. logFile *os.File
  55. cmd *exec.Cmd
  56. storageDriver string
  57. userlandProxy bool
  58. execRoot string
  59. experimental bool
  60. init bool
  61. dockerdBinary string
  62. log logT
  63. // swarm related field
  64. swarmListenAddr string
  65. SwarmPort int // FIXME(vdemeester) should probably not be exported
  66. DefaultAddrPool []string
  67. SubnetSize uint32
  68. DataPathPort uint32
  69. // cached information
  70. CachedInfo types.Info
  71. }
  72. // New returns a Daemon instance to be used for testing.
  73. // This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST.
  74. // The daemon will not automatically start.
  75. func New(t testingT, ops ...func(*Daemon)) *Daemon {
  76. if ht, ok := t.(test.HelperT); ok {
  77. ht.Helper()
  78. }
  79. t.Log("Creating a new daemon")
  80. dest := os.Getenv("DOCKER_INTEGRATION_DAEMON_DEST")
  81. if dest == "" {
  82. dest = os.Getenv("DEST")
  83. }
  84. assert.Check(t, dest != "", "Please set the DOCKER_INTEGRATION_DAEMON_DEST or the DEST environment variable")
  85. storageDriver := os.Getenv("DOCKER_GRAPHDRIVER")
  86. assert.NilError(t, os.MkdirAll(SockRoot, 0700), "could not create daemon socket root")
  87. id := fmt.Sprintf("d%s", stringid.TruncateID(stringid.GenerateRandomID()))
  88. dir := filepath.Join(dest, id)
  89. daemonFolder, err := filepath.Abs(dir)
  90. assert.NilError(t, err, "Could not make %q an absolute path", dir)
  91. daemonRoot := filepath.Join(daemonFolder, "root")
  92. assert.NilError(t, os.MkdirAll(daemonRoot, 0755), "Could not create daemon root %q", dir)
  93. userlandProxy := true
  94. if env := os.Getenv("DOCKER_USERLANDPROXY"); env != "" {
  95. if val, err := strconv.ParseBool(env); err != nil {
  96. userlandProxy = val
  97. }
  98. }
  99. d := &Daemon{
  100. id: id,
  101. Folder: daemonFolder,
  102. Root: daemonRoot,
  103. storageDriver: storageDriver,
  104. userlandProxy: userlandProxy,
  105. // dxr stands for docker-execroot (shortened for avoiding unix(7) path length limitation)
  106. execRoot: filepath.Join(os.TempDir(), "dxr", id),
  107. dockerdBinary: defaultDockerdBinary,
  108. swarmListenAddr: defaultSwarmListenAddr,
  109. SwarmPort: DefaultSwarmPort,
  110. log: t,
  111. }
  112. for _, op := range ops {
  113. op(d)
  114. }
  115. return d
  116. }
  117. // RootDir returns the root directory of the daemon.
  118. func (d *Daemon) RootDir() string {
  119. return d.Root
  120. }
  121. // ID returns the generated id of the daemon
  122. func (d *Daemon) ID() string {
  123. return d.id
  124. }
  125. // StorageDriver returns the configured storage driver of the daemon
  126. func (d *Daemon) StorageDriver() string {
  127. return d.storageDriver
  128. }
  129. // Sock returns the socket path of the daemon
  130. func (d *Daemon) Sock() string {
  131. return fmt.Sprintf("unix://" + d.sockPath())
  132. }
  133. func (d *Daemon) sockPath() string {
  134. return filepath.Join(SockRoot, d.id+".sock")
  135. }
  136. // LogFileName returns the path the daemon's log file
  137. func (d *Daemon) LogFileName() string {
  138. return d.logFile.Name()
  139. }
  140. // ReadLogFile returns the content of the daemon log file
  141. func (d *Daemon) ReadLogFile() ([]byte, error) {
  142. return ioutil.ReadFile(d.logFile.Name())
  143. }
  144. // NewClientT creates new client based on daemon's socket path
  145. func (d *Daemon) NewClientT(t assert.TestingT) *client.Client {
  146. if ht, ok := t.(test.HelperT); ok {
  147. ht.Helper()
  148. }
  149. c, err := client.NewClientWithOpts(
  150. client.FromEnv,
  151. client.WithHost(d.Sock()))
  152. assert.NilError(t, err, "cannot create daemon client")
  153. return c
  154. }
  155. // Cleanup cleans the daemon files : exec root (network namespaces, ...), swarmkit files
  156. func (d *Daemon) Cleanup(t testingT) {
  157. if ht, ok := t.(test.HelperT); ok {
  158. ht.Helper()
  159. }
  160. // Cleanup swarmkit wal files if present
  161. cleanupRaftDir(t, d.Root)
  162. cleanupNetworkNamespace(t, d.execRoot)
  163. }
  164. // Start starts the daemon and return once it is ready to receive requests.
  165. func (d *Daemon) Start(t testingT, args ...string) {
  166. if ht, ok := t.(test.HelperT); ok {
  167. ht.Helper()
  168. }
  169. if err := d.StartWithError(args...); err != nil {
  170. t.Fatalf("failed to start daemon with arguments %v : %v", args, err)
  171. }
  172. }
  173. // StartWithError starts the daemon and return once it is ready to receive requests.
  174. // It returns an error in case it couldn't start.
  175. func (d *Daemon) StartWithError(args ...string) error {
  176. logFile, err := os.OpenFile(filepath.Join(d.Folder, "docker.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
  177. if err != nil {
  178. return errors.Wrapf(err, "[%s] Could not create %s/docker.log", d.id, d.Folder)
  179. }
  180. return d.StartWithLogFile(logFile, args...)
  181. }
  182. // StartWithLogFile will start the daemon and attach its streams to a given file.
  183. func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
  184. d.handleUserns()
  185. dockerdBinary, err := exec.LookPath(d.dockerdBinary)
  186. if err != nil {
  187. return errors.Wrapf(err, "[%s] could not find docker binary in $PATH", d.id)
  188. }
  189. args := append(d.GlobalFlags,
  190. "--containerd", containerdSocket,
  191. "--data-root", d.Root,
  192. "--exec-root", d.execRoot,
  193. "--pidfile", fmt.Sprintf("%s/docker.pid", d.Folder),
  194. fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
  195. )
  196. if d.experimental {
  197. args = append(args, "--experimental")
  198. }
  199. if d.init {
  200. args = append(args, "--init")
  201. }
  202. if !(d.UseDefaultHost || d.UseDefaultTLSHost) {
  203. args = append(args, []string{"--host", d.Sock()}...)
  204. }
  205. if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" {
  206. args = append(args, []string{"--userns-remap", root}...)
  207. }
  208. // If we don't explicitly set the log-level or debug flag(-D) then
  209. // turn on debug mode
  210. foundLog := false
  211. foundSd := false
  212. for _, a := range providedArgs {
  213. if strings.Contains(a, "--log-level") || strings.Contains(a, "-D") || strings.Contains(a, "--debug") {
  214. foundLog = true
  215. }
  216. if strings.Contains(a, "--storage-driver") {
  217. foundSd = true
  218. }
  219. }
  220. if !foundLog {
  221. args = append(args, "--debug")
  222. }
  223. if d.storageDriver != "" && !foundSd {
  224. args = append(args, "--storage-driver", d.storageDriver)
  225. }
  226. args = append(args, providedArgs...)
  227. d.cmd = exec.Command(dockerdBinary, args...)
  228. d.cmd.Env = append(os.Environ(), "DOCKER_SERVICE_PREFER_OFFLINE_IMAGE=1")
  229. d.cmd.Stdout = out
  230. d.cmd.Stderr = out
  231. d.logFile = out
  232. if err := d.cmd.Start(); err != nil {
  233. return errors.Errorf("[%s] could not start daemon container: %v", d.id, err)
  234. }
  235. wait := make(chan error)
  236. go func() {
  237. wait <- d.cmd.Wait()
  238. d.log.Logf("[%s] exiting daemon", d.id)
  239. close(wait)
  240. }()
  241. d.Wait = wait
  242. ticker := time.NewTicker(500 * time.Millisecond)
  243. defer ticker.Stop()
  244. tick := ticker.C
  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 err := <-d.Wait:
  285. return errors.Errorf("[%s] Daemon exited during startup: %v", d.id, err)
  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. ticker := time.NewTicker(time.Second)
  368. defer ticker.Stop()
  369. tick := ticker.C
  370. if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
  371. if strings.Contains(err.Error(), "os: process already finished") {
  372. return errDaemonNotStarted
  373. }
  374. return errors.Errorf("could not send signal: %v", err)
  375. }
  376. out1:
  377. for {
  378. select {
  379. case err := <-d.Wait:
  380. return err
  381. case <-time.After(20 * time.Second):
  382. // time for stopping jobs and run onShutdown hooks
  383. d.log.Logf("[%s] daemon stop timeout", d.id)
  384. break out1
  385. }
  386. }
  387. out2:
  388. for {
  389. select {
  390. case err := <-d.Wait:
  391. return err
  392. case <-tick:
  393. i++
  394. if i > 5 {
  395. d.log.Logf("tried to interrupt daemon for %d times, now try to kill it", i)
  396. break out2
  397. }
  398. d.log.Logf("Attempt #%d: daemon is still running with pid %d", i, d.cmd.Process.Pid)
  399. if err := d.cmd.Process.Signal(os.Interrupt); err != nil {
  400. return errors.Errorf("could not send signal: %v", err)
  401. }
  402. }
  403. }
  404. if err := d.cmd.Process.Kill(); err != nil {
  405. d.log.Logf("Could not kill daemon: %v", err)
  406. return err
  407. }
  408. d.cmd.Wait()
  409. return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
  410. }
  411. // Restart will restart the daemon by first stopping it and the starting it.
  412. // If an error occurs while starting the daemon, the test will fail.
  413. func (d *Daemon) Restart(t testingT, args ...string) {
  414. if ht, ok := t.(test.HelperT); ok {
  415. ht.Helper()
  416. }
  417. d.Stop(t)
  418. d.Start(t, args...)
  419. }
  420. // RestartWithError will restart the daemon by first stopping it and then starting it.
  421. func (d *Daemon) RestartWithError(arg ...string) error {
  422. if err := d.StopWithError(); err != nil {
  423. return err
  424. }
  425. return d.StartWithError(arg...)
  426. }
  427. func (d *Daemon) handleUserns() {
  428. // in the case of tests running a user namespace-enabled daemon, we have resolved
  429. // d.Root to be the actual final path of the graph dir after the "uid.gid" of
  430. // remapped root is added--we need to subtract it from the path before calling
  431. // start or else we will continue making subdirectories rather than truly restarting
  432. // with the same location/root:
  433. if root := os.Getenv("DOCKER_REMAP_ROOT"); root != "" {
  434. d.Root = filepath.Dir(d.Root)
  435. }
  436. }
  437. // ReloadConfig asks the daemon to reload its configuration
  438. func (d *Daemon) ReloadConfig() error {
  439. if d.cmd == nil || d.cmd.Process == nil {
  440. return errors.New("daemon is not running")
  441. }
  442. errCh := make(chan error)
  443. started := make(chan struct{})
  444. go func() {
  445. _, body, err := request.Get("/events", request.Host(d.Sock()))
  446. close(started)
  447. if err != nil {
  448. errCh <- err
  449. }
  450. defer body.Close()
  451. dec := json.NewDecoder(body)
  452. for {
  453. var e events.Message
  454. if err := dec.Decode(&e); err != nil {
  455. errCh <- err
  456. return
  457. }
  458. if e.Type != events.DaemonEventType {
  459. continue
  460. }
  461. if e.Action != "reload" {
  462. continue
  463. }
  464. close(errCh) // notify that we are done
  465. return
  466. }
  467. }()
  468. <-started
  469. if err := signalDaemonReload(d.cmd.Process.Pid); err != nil {
  470. return errors.Errorf("error signaling daemon reload: %v", err)
  471. }
  472. select {
  473. case err := <-errCh:
  474. if err != nil {
  475. return errors.Errorf("error waiting for daemon reload event: %v", err)
  476. }
  477. case <-time.After(30 * time.Second):
  478. return errors.New("timeout waiting for daemon reload event")
  479. }
  480. return nil
  481. }
  482. // LoadBusybox image into the daemon
  483. func (d *Daemon) LoadBusybox(t assert.TestingT) {
  484. if ht, ok := t.(test.HelperT); ok {
  485. ht.Helper()
  486. }
  487. clientHost, err := client.NewClientWithOpts(client.FromEnv)
  488. assert.NilError(t, err, "failed to create client")
  489. defer clientHost.Close()
  490. ctx := context.Background()
  491. reader, err := clientHost.ImageSave(ctx, []string{"busybox:latest"})
  492. assert.NilError(t, err, "failed to download busybox")
  493. defer reader.Close()
  494. c := d.NewClientT(t)
  495. defer c.Close()
  496. resp, err := c.ImageLoad(ctx, reader, true)
  497. assert.NilError(t, err, "failed to load busybox")
  498. defer resp.Body.Close()
  499. }
  500. func (d *Daemon) getClientConfig() (*clientConfig, error) {
  501. var (
  502. transport *http.Transport
  503. scheme string
  504. addr string
  505. proto string
  506. )
  507. if d.UseDefaultTLSHost {
  508. option := &tlsconfig.Options{
  509. CAFile: "fixtures/https/ca.pem",
  510. CertFile: "fixtures/https/client-cert.pem",
  511. KeyFile: "fixtures/https/client-key.pem",
  512. }
  513. tlsConfig, err := tlsconfig.Client(*option)
  514. if err != nil {
  515. return nil, err
  516. }
  517. transport = &http.Transport{
  518. TLSClientConfig: tlsConfig,
  519. }
  520. addr = fmt.Sprintf("%s:%d", opts.DefaultHTTPHost, opts.DefaultTLSHTTPPort)
  521. scheme = "https"
  522. proto = "tcp"
  523. } else if d.UseDefaultHost {
  524. addr = opts.DefaultUnixSocket
  525. proto = "unix"
  526. scheme = "http"
  527. transport = &http.Transport{}
  528. } else {
  529. addr = d.sockPath()
  530. proto = "unix"
  531. scheme = "http"
  532. transport = &http.Transport{}
  533. }
  534. if err := sockets.ConfigureTransport(transport, proto, addr); err != nil {
  535. return nil, err
  536. }
  537. transport.DisableKeepAlives = true
  538. return &clientConfig{
  539. transport: transport,
  540. scheme: scheme,
  541. addr: addr,
  542. }, nil
  543. }
  544. func (d *Daemon) queryRootDir() (string, error) {
  545. // update daemon root by asking /info endpoint (to support user
  546. // namespaced daemon with root remapped uid.gid directory)
  547. clientConfig, err := d.getClientConfig()
  548. if err != nil {
  549. return "", err
  550. }
  551. c := &http.Client{
  552. Transport: clientConfig.transport,
  553. }
  554. req, err := http.NewRequest("GET", "/info", nil)
  555. if err != nil {
  556. return "", err
  557. }
  558. req.Header.Set("Content-Type", "application/json")
  559. req.URL.Host = clientConfig.addr
  560. req.URL.Scheme = clientConfig.scheme
  561. resp, err := c.Do(req)
  562. if err != nil {
  563. return "", err
  564. }
  565. body := ioutils.NewReadCloserWrapper(resp.Body, func() error {
  566. return resp.Body.Close()
  567. })
  568. type Info struct {
  569. DockerRootDir string
  570. }
  571. var b []byte
  572. var i Info
  573. b, err = request.ReadBody(body)
  574. if err == nil && resp.StatusCode == http.StatusOK {
  575. // read the docker root dir
  576. if err = json.Unmarshal(b, &i); err == nil {
  577. return i.DockerRootDir, nil
  578. }
  579. }
  580. return "", err
  581. }
  582. // Info returns the info struct for this daemon
  583. func (d *Daemon) Info(t assert.TestingT) types.Info {
  584. if ht, ok := t.(test.HelperT); ok {
  585. ht.Helper()
  586. }
  587. c := d.NewClientT(t)
  588. info, err := c.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. }