daemon_swarm.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. package daemon
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "strings"
  7. "time"
  8. "github.com/docker/docker/api/types"
  9. "github.com/docker/docker/api/types/filters"
  10. "github.com/docker/docker/api/types/swarm"
  11. "github.com/docker/docker/integration-cli/checker"
  12. "github.com/go-check/check"
  13. "github.com/pkg/errors"
  14. "golang.org/x/net/context"
  15. )
  16. // Swarm is a test daemon with helpers for participating in a swarm.
  17. type Swarm struct {
  18. *Daemon
  19. swarm.Info
  20. Port int
  21. ListenAddr string
  22. }
  23. // Init initializes a new swarm cluster.
  24. func (d *Swarm) Init(req swarm.InitRequest) error {
  25. if req.ListenAddr == "" {
  26. req.ListenAddr = d.ListenAddr
  27. }
  28. cli, err := d.NewClient()
  29. if err != nil {
  30. return fmt.Errorf("initializing swarm: failed to create client %v", err)
  31. }
  32. defer cli.Close()
  33. _, err = cli.SwarmInit(context.Background(), req)
  34. if err != nil {
  35. return fmt.Errorf("initializing swarm: %v", err)
  36. }
  37. info, err := d.SwarmInfo()
  38. if err != nil {
  39. return err
  40. }
  41. d.Info = info
  42. return nil
  43. }
  44. // Join joins a daemon to an existing cluster.
  45. func (d *Swarm) Join(req swarm.JoinRequest) error {
  46. if req.ListenAddr == "" {
  47. req.ListenAddr = d.ListenAddr
  48. }
  49. cli, err := d.NewClient()
  50. if err != nil {
  51. return fmt.Errorf("joining swarm: failed to create client %v", err)
  52. }
  53. defer cli.Close()
  54. err = cli.SwarmJoin(context.Background(), req)
  55. if err != nil {
  56. return fmt.Errorf("joining swarm: %v", err)
  57. }
  58. info, err := d.SwarmInfo()
  59. if err != nil {
  60. return err
  61. }
  62. d.Info = info
  63. return nil
  64. }
  65. // Leave forces daemon to leave current cluster.
  66. func (d *Swarm) Leave(force bool) error {
  67. cli, err := d.NewClient()
  68. if err != nil {
  69. return fmt.Errorf("leaving swarm: failed to create client %v", err)
  70. }
  71. defer cli.Close()
  72. err = cli.SwarmLeave(context.Background(), force)
  73. if err != nil {
  74. err = fmt.Errorf("leaving swarm: %v", err)
  75. }
  76. return err
  77. }
  78. // SwarmInfo returns the swarm information of the daemon
  79. func (d *Swarm) SwarmInfo() (swarm.Info, error) {
  80. cli, err := d.NewClient()
  81. if err != nil {
  82. return swarm.Info{}, fmt.Errorf("get swarm info: %v", err)
  83. }
  84. info, err := cli.Info(context.Background())
  85. if err != nil {
  86. return swarm.Info{}, fmt.Errorf("get swarm info: %v", err)
  87. }
  88. return info.Swarm, nil
  89. }
  90. // Unlock tries to unlock a locked swarm
  91. func (d *Swarm) Unlock(req swarm.UnlockRequest) error {
  92. cli, err := d.NewClient()
  93. if err != nil {
  94. return fmt.Errorf("unlocking swarm: failed to create client %v", err)
  95. }
  96. defer cli.Close()
  97. err = cli.SwarmUnlock(context.Background(), req)
  98. if err != nil {
  99. err = errors.Wrap(err, "unlocking swarm")
  100. }
  101. return err
  102. }
  103. // ServiceConstructor defines a swarm service constructor function
  104. type ServiceConstructor func(*swarm.Service)
  105. // NodeConstructor defines a swarm node constructor
  106. type NodeConstructor func(*swarm.Node)
  107. // SecretConstructor defines a swarm secret constructor
  108. type SecretConstructor func(*swarm.Secret)
  109. // ConfigConstructor defines a swarm config constructor
  110. type ConfigConstructor func(*swarm.Config)
  111. // SpecConstructor defines a swarm spec constructor
  112. type SpecConstructor func(*swarm.Spec)
  113. // CreateServiceWithOptions creates a swarm service given the specified service constructors
  114. // and auth config
  115. func (d *Swarm) CreateServiceWithOptions(c *check.C, opts types.ServiceCreateOptions, f ...ServiceConstructor) string {
  116. var service swarm.Service
  117. for _, fn := range f {
  118. fn(&service)
  119. }
  120. cli, err := d.NewClient()
  121. c.Assert(err, checker.IsNil)
  122. defer cli.Close()
  123. ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
  124. defer cancel()
  125. res, err := cli.ServiceCreate(ctx, service.Spec, opts)
  126. c.Assert(err, checker.IsNil)
  127. return res.ID
  128. }
  129. // CreateService creates a swarm service given the specified service constructor
  130. func (d *Swarm) CreateService(c *check.C, f ...ServiceConstructor) string {
  131. return d.CreateServiceWithOptions(c, types.ServiceCreateOptions{}, f...)
  132. }
  133. // GetService returns the swarm service corresponding to the specified id
  134. func (d *Swarm) GetService(c *check.C, id string) *swarm.Service {
  135. cli, err := d.NewClient()
  136. c.Assert(err, checker.IsNil)
  137. defer cli.Close()
  138. service, _, err := cli.ServiceInspectWithRaw(context.Background(), id, types.ServiceInspectOptions{})
  139. c.Assert(err, checker.IsNil)
  140. return &service
  141. }
  142. // GetServiceTasks returns the swarm tasks for the specified service
  143. func (d *Swarm) GetServiceTasks(c *check.C, service string) []swarm.Task {
  144. cli, err := d.NewClient()
  145. c.Assert(err, checker.IsNil)
  146. defer cli.Close()
  147. filterArgs := filters.NewArgs()
  148. filterArgs.Add("desired-state", "running")
  149. filterArgs.Add("service", service)
  150. options := types.TaskListOptions{
  151. Filters: filterArgs,
  152. }
  153. tasks, err := cli.TaskList(context.Background(), options)
  154. c.Assert(err, checker.IsNil)
  155. return tasks
  156. }
  157. // CheckServiceTasksInState returns the number of tasks with a matching state,
  158. // and optional message substring.
  159. func (d *Swarm) CheckServiceTasksInState(service string, state swarm.TaskState, message string) func(*check.C) (interface{}, check.CommentInterface) {
  160. return func(c *check.C) (interface{}, check.CommentInterface) {
  161. tasks := d.GetServiceTasks(c, service)
  162. var count int
  163. for _, task := range tasks {
  164. if task.Status.State == state {
  165. if message == "" || strings.Contains(task.Status.Message, message) {
  166. count++
  167. }
  168. }
  169. }
  170. return count, nil
  171. }
  172. }
  173. // CheckServiceRunningTasks returns the number of running tasks for the specified service
  174. func (d *Swarm) CheckServiceRunningTasks(service string) func(*check.C) (interface{}, check.CommentInterface) {
  175. return d.CheckServiceTasksInState(service, swarm.TaskStateRunning, "")
  176. }
  177. // CheckServiceUpdateState returns the current update state for the specified service
  178. func (d *Swarm) CheckServiceUpdateState(service string) func(*check.C) (interface{}, check.CommentInterface) {
  179. return func(c *check.C) (interface{}, check.CommentInterface) {
  180. service := d.GetService(c, service)
  181. if service.UpdateStatus == nil {
  182. return "", nil
  183. }
  184. return service.UpdateStatus.State, nil
  185. }
  186. }
  187. // CheckPluginRunning returns the runtime state of the plugin
  188. func (d *Swarm) CheckPluginRunning(plugin string) func(c *check.C) (interface{}, check.CommentInterface) {
  189. return func(c *check.C) (interface{}, check.CommentInterface) {
  190. status, out, err := d.SockRequest("GET", "/plugins/"+plugin+"/json", nil)
  191. c.Assert(err, checker.IsNil, check.Commentf(string(out)))
  192. if status != http.StatusOK {
  193. return false, nil
  194. }
  195. var p types.Plugin
  196. c.Assert(json.Unmarshal(out, &p), checker.IsNil, check.Commentf(string(out)))
  197. return p.Enabled, check.Commentf("%+v", p)
  198. }
  199. }
  200. // CheckPluginImage returns the runtime state of the plugin
  201. func (d *Swarm) CheckPluginImage(plugin string) func(c *check.C) (interface{}, check.CommentInterface) {
  202. return func(c *check.C) (interface{}, check.CommentInterface) {
  203. status, out, err := d.SockRequest("GET", "/plugins/"+plugin+"/json", nil)
  204. c.Assert(err, checker.IsNil, check.Commentf(string(out)))
  205. if status != http.StatusOK {
  206. return false, nil
  207. }
  208. var p types.Plugin
  209. c.Assert(json.Unmarshal(out, &p), checker.IsNil, check.Commentf(string(out)))
  210. return p.PluginReference, check.Commentf("%+v", p)
  211. }
  212. }
  213. // CheckServiceTasks returns the number of tasks for the specified service
  214. func (d *Swarm) CheckServiceTasks(service string) func(*check.C) (interface{}, check.CommentInterface) {
  215. return func(c *check.C) (interface{}, check.CommentInterface) {
  216. tasks := d.GetServiceTasks(c, service)
  217. return len(tasks), nil
  218. }
  219. }
  220. // CheckRunningTaskNetworks returns the number of times each network is referenced from a task.
  221. func (d *Swarm) CheckRunningTaskNetworks(c *check.C) (interface{}, check.CommentInterface) {
  222. cli, err := d.NewClient()
  223. c.Assert(err, checker.IsNil)
  224. defer cli.Close()
  225. filterArgs := filters.NewArgs()
  226. filterArgs.Add("desired-state", "running")
  227. options := types.TaskListOptions{
  228. Filters: filterArgs,
  229. }
  230. tasks, err := cli.TaskList(context.Background(), options)
  231. c.Assert(err, checker.IsNil)
  232. result := make(map[string]int)
  233. for _, task := range tasks {
  234. for _, network := range task.Spec.Networks {
  235. result[network.Target]++
  236. }
  237. }
  238. return result, nil
  239. }
  240. // CheckRunningTaskImages returns the times each image is running as a task.
  241. func (d *Swarm) CheckRunningTaskImages(c *check.C) (interface{}, check.CommentInterface) {
  242. cli, err := d.NewClient()
  243. c.Assert(err, checker.IsNil)
  244. defer cli.Close()
  245. filterArgs := filters.NewArgs()
  246. filterArgs.Add("desired-state", "running")
  247. options := types.TaskListOptions{
  248. Filters: filterArgs,
  249. }
  250. tasks, err := cli.TaskList(context.Background(), options)
  251. c.Assert(err, checker.IsNil)
  252. result := make(map[string]int)
  253. for _, task := range tasks {
  254. if task.Status.State == swarm.TaskStateRunning && task.Spec.ContainerSpec != nil {
  255. result[task.Spec.ContainerSpec.Image]++
  256. }
  257. }
  258. return result, nil
  259. }
  260. // CheckNodeReadyCount returns the number of ready node on the swarm
  261. func (d *Swarm) CheckNodeReadyCount(c *check.C) (interface{}, check.CommentInterface) {
  262. nodes := d.ListNodes(c)
  263. var readyCount int
  264. for _, node := range nodes {
  265. if node.Status.State == swarm.NodeStateReady {
  266. readyCount++
  267. }
  268. }
  269. return readyCount, nil
  270. }
  271. // GetTask returns the swarm task identified by the specified id
  272. func (d *Swarm) GetTask(c *check.C, id string) swarm.Task {
  273. cli, err := d.NewClient()
  274. c.Assert(err, checker.IsNil)
  275. defer cli.Close()
  276. task, _, err := cli.TaskInspectWithRaw(context.Background(), id)
  277. c.Assert(err, checker.IsNil)
  278. return task
  279. }
  280. // UpdateService updates a swarm service with the specified service constructor
  281. func (d *Swarm) UpdateService(c *check.C, service *swarm.Service, f ...ServiceConstructor) {
  282. cli, err := d.NewClient()
  283. c.Assert(err, checker.IsNil)
  284. defer cli.Close()
  285. for _, fn := range f {
  286. fn(service)
  287. }
  288. _, err = cli.ServiceUpdate(context.Background(), service.ID, service.Version, service.Spec, types.ServiceUpdateOptions{})
  289. c.Assert(err, checker.IsNil)
  290. }
  291. // RemoveService removes the specified service
  292. func (d *Swarm) RemoveService(c *check.C, id string) {
  293. cli, err := d.NewClient()
  294. c.Assert(err, checker.IsNil)
  295. defer cli.Close()
  296. err = cli.ServiceRemove(context.Background(), id)
  297. c.Assert(err, checker.IsNil)
  298. }
  299. // GetNode returns a swarm node identified by the specified id
  300. func (d *Swarm) GetNode(c *check.C, id string) *swarm.Node {
  301. cli, err := d.NewClient()
  302. c.Assert(err, checker.IsNil)
  303. defer cli.Close()
  304. node, _, err := cli.NodeInspectWithRaw(context.Background(), id)
  305. c.Assert(err, checker.IsNil)
  306. c.Assert(node.ID, checker.Equals, id)
  307. return &node
  308. }
  309. // RemoveNode removes the specified node
  310. func (d *Swarm) RemoveNode(c *check.C, id string, force bool) {
  311. cli, err := d.NewClient()
  312. c.Assert(err, checker.IsNil)
  313. defer cli.Close()
  314. options := types.NodeRemoveOptions{
  315. Force: force,
  316. }
  317. err = cli.NodeRemove(context.Background(), id, options)
  318. c.Assert(err, checker.IsNil)
  319. }
  320. // UpdateNode updates a swarm node with the specified node constructor
  321. func (d *Swarm) UpdateNode(c *check.C, id string, f ...NodeConstructor) {
  322. cli, err := d.NewClient()
  323. c.Assert(err, checker.IsNil)
  324. defer cli.Close()
  325. for i := 0; ; i++ {
  326. node := d.GetNode(c, id)
  327. for _, fn := range f {
  328. fn(node)
  329. }
  330. err = cli.NodeUpdate(context.Background(), node.ID, node.Version, node.Spec)
  331. if i < 10 && err != nil && strings.Contains(err.Error(), "update out of sequence") {
  332. time.Sleep(100 * time.Millisecond)
  333. continue
  334. }
  335. c.Assert(err, checker.IsNil)
  336. return
  337. }
  338. }
  339. // ListNodes returns the list of the current swarm nodes
  340. func (d *Swarm) ListNodes(c *check.C) []swarm.Node {
  341. cli, err := d.NewClient()
  342. c.Assert(err, checker.IsNil)
  343. defer cli.Close()
  344. nodes, err := cli.NodeList(context.Background(), types.NodeListOptions{})
  345. c.Assert(err, checker.IsNil)
  346. return nodes
  347. }
  348. // ListServices returns the list of the current swarm services
  349. func (d *Swarm) ListServices(c *check.C) []swarm.Service {
  350. cli, err := d.NewClient()
  351. c.Assert(err, checker.IsNil)
  352. defer cli.Close()
  353. services, err := cli.ServiceList(context.Background(), types.ServiceListOptions{})
  354. c.Assert(err, checker.IsNil)
  355. return services
  356. }
  357. // CreateSecret creates a secret given the specified spec
  358. func (d *Swarm) CreateSecret(c *check.C, secretSpec swarm.SecretSpec) string {
  359. cli, err := d.NewClient()
  360. c.Assert(err, checker.IsNil)
  361. defer cli.Close()
  362. scr, err := cli.SecretCreate(context.Background(), secretSpec)
  363. c.Assert(err, checker.IsNil)
  364. return scr.ID
  365. }
  366. // ListSecrets returns the list of the current swarm secrets
  367. func (d *Swarm) ListSecrets(c *check.C) []swarm.Secret {
  368. cli, err := d.NewClient()
  369. c.Assert(err, checker.IsNil)
  370. defer cli.Close()
  371. secrets, err := cli.SecretList(context.Background(), types.SecretListOptions{})
  372. c.Assert(err, checker.IsNil)
  373. return secrets
  374. }
  375. // GetSecret returns a swarm secret identified by the specified id
  376. func (d *Swarm) GetSecret(c *check.C, id string) *swarm.Secret {
  377. cli, err := d.NewClient()
  378. c.Assert(err, checker.IsNil)
  379. defer cli.Close()
  380. secret, _, err := cli.SecretInspectWithRaw(context.Background(), id)
  381. c.Assert(err, checker.IsNil)
  382. return &secret
  383. }
  384. // DeleteSecret removes the swarm secret identified by the specified id
  385. func (d *Swarm) DeleteSecret(c *check.C, id string) {
  386. cli, err := d.NewClient()
  387. c.Assert(err, checker.IsNil)
  388. defer cli.Close()
  389. err = cli.SecretRemove(context.Background(), id)
  390. c.Assert(err, checker.IsNil)
  391. }
  392. // UpdateSecret updates the swarm secret identified by the specified id
  393. // Currently, only label update is supported.
  394. func (d *Swarm) UpdateSecret(c *check.C, id string, f ...SecretConstructor) {
  395. cli, err := d.NewClient()
  396. c.Assert(err, checker.IsNil)
  397. defer cli.Close()
  398. secret := d.GetSecret(c, id)
  399. for _, fn := range f {
  400. fn(secret)
  401. }
  402. err = cli.SecretUpdate(context.Background(), secret.ID, secret.Version, secret.Spec)
  403. c.Assert(err, checker.IsNil)
  404. }
  405. // CreateConfig creates a config given the specified spec
  406. func (d *Swarm) CreateConfig(c *check.C, configSpec swarm.ConfigSpec) string {
  407. cli, err := d.NewClient()
  408. c.Assert(err, checker.IsNil)
  409. defer cli.Close()
  410. scr, err := cli.ConfigCreate(context.Background(), configSpec)
  411. c.Assert(err, checker.IsNil)
  412. return scr.ID
  413. }
  414. // ListConfigs returns the list of the current swarm configs
  415. func (d *Swarm) ListConfigs(c *check.C) []swarm.Config {
  416. cli, err := d.NewClient()
  417. c.Assert(err, checker.IsNil)
  418. defer cli.Close()
  419. configs, err := cli.ConfigList(context.Background(), types.ConfigListOptions{})
  420. c.Assert(err, checker.IsNil)
  421. return configs
  422. }
  423. // GetConfig returns a swarm config identified by the specified id
  424. func (d *Swarm) GetConfig(c *check.C, id string) *swarm.Config {
  425. cli, err := d.NewClient()
  426. c.Assert(err, checker.IsNil)
  427. defer cli.Close()
  428. config, _, err := cli.ConfigInspectWithRaw(context.Background(), id)
  429. c.Assert(err, checker.IsNil)
  430. return &config
  431. }
  432. // DeleteConfig removes the swarm config identified by the specified id
  433. func (d *Swarm) DeleteConfig(c *check.C, id string) {
  434. cli, err := d.NewClient()
  435. c.Assert(err, checker.IsNil)
  436. defer cli.Close()
  437. err = cli.ConfigRemove(context.Background(), id)
  438. c.Assert(err, checker.IsNil)
  439. }
  440. // UpdateConfig updates the swarm config identified by the specified id
  441. // Currently, only label update is supported.
  442. func (d *Swarm) UpdateConfig(c *check.C, id string, f ...ConfigConstructor) {
  443. cli, err := d.NewClient()
  444. c.Assert(err, checker.IsNil)
  445. defer cli.Close()
  446. config := d.GetConfig(c, id)
  447. for _, fn := range f {
  448. fn(config)
  449. }
  450. err = cli.ConfigUpdate(context.Background(), config.ID, config.Version, config.Spec)
  451. c.Assert(err, checker.IsNil)
  452. }
  453. // GetSwarm returns the current swarm object
  454. func (d *Swarm) GetSwarm(c *check.C) swarm.Swarm {
  455. cli, err := d.NewClient()
  456. c.Assert(err, checker.IsNil)
  457. defer cli.Close()
  458. sw, err := cli.SwarmInspect(context.Background())
  459. c.Assert(err, checker.IsNil)
  460. return sw
  461. }
  462. // UpdateSwarm updates the current swarm object with the specified spec constructors
  463. func (d *Swarm) UpdateSwarm(c *check.C, f ...SpecConstructor) {
  464. cli, err := d.NewClient()
  465. c.Assert(err, checker.IsNil)
  466. defer cli.Close()
  467. sw := d.GetSwarm(c)
  468. for _, fn := range f {
  469. fn(&sw.Spec)
  470. }
  471. err = cli.SwarmUpdate(context.Background(), sw.Version, sw.Spec, swarm.UpdateFlags{})
  472. c.Assert(err, checker.IsNil)
  473. }
  474. // RotateTokens update the swarm to rotate tokens
  475. func (d *Swarm) RotateTokens(c *check.C) {
  476. cli, err := d.NewClient()
  477. c.Assert(err, checker.IsNil)
  478. defer cli.Close()
  479. sw, err := cli.SwarmInspect(context.Background())
  480. c.Assert(err, checker.IsNil)
  481. flags := swarm.UpdateFlags{
  482. RotateManagerToken: true,
  483. RotateWorkerToken: true,
  484. }
  485. err = cli.SwarmUpdate(context.Background(), sw.Version, sw.Spec, flags)
  486. c.Assert(err, checker.IsNil)
  487. }
  488. // JoinTokens returns the current swarm join tokens
  489. func (d *Swarm) JoinTokens(c *check.C) swarm.JoinTokens {
  490. cli, err := d.NewClient()
  491. c.Assert(err, checker.IsNil)
  492. defer cli.Close()
  493. sw, err := cli.SwarmInspect(context.Background())
  494. c.Assert(err, checker.IsNil)
  495. return sw.JoinTokens
  496. }
  497. // CheckLocalNodeState returns the current swarm node state
  498. func (d *Swarm) CheckLocalNodeState(c *check.C) (interface{}, check.CommentInterface) {
  499. info, err := d.SwarmInfo()
  500. c.Assert(err, checker.IsNil)
  501. return info.LocalNodeState, nil
  502. }
  503. // CheckControlAvailable returns the current swarm control available
  504. func (d *Swarm) CheckControlAvailable(c *check.C) (interface{}, check.CommentInterface) {
  505. info, err := d.SwarmInfo()
  506. c.Assert(err, checker.IsNil)
  507. c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStateActive)
  508. return info.ControlAvailable, nil
  509. }
  510. // CheckLeader returns whether there is a leader on the swarm or not
  511. func (d *Swarm) CheckLeader(c *check.C) (interface{}, check.CommentInterface) {
  512. cli, err := d.NewClient()
  513. c.Assert(err, checker.IsNil)
  514. defer cli.Close()
  515. errList := check.Commentf("could not get node list")
  516. ls, err := cli.NodeList(context.Background(), types.NodeListOptions{})
  517. if err != nil {
  518. return err, errList
  519. }
  520. for _, node := range ls {
  521. if node.ManagerStatus != nil && node.ManagerStatus.Leader {
  522. return nil, nil
  523. }
  524. }
  525. return fmt.Errorf("no leader"), check.Commentf("could not find leader")
  526. }
  527. // CmdRetryOutOfSequence tries the specified command against the current daemon for 10 times
  528. func (d *Swarm) CmdRetryOutOfSequence(args ...string) (string, error) {
  529. for i := 0; ; i++ {
  530. out, err := d.Cmd(args...)
  531. if err != nil {
  532. if strings.Contains(out, "update out of sequence") {
  533. if i < 10 {
  534. continue
  535. }
  536. }
  537. }
  538. return out, err
  539. }
  540. }