Signed-off-by: Shishir Mahajan <shishir.mahajan@redhat.com>
| ... | ... |
@@ -20,6 +20,7 @@ import ( |
| 20 | 20 |
"time" |
| 21 | 21 |
|
| 22 | 22 |
"github.com/docker/docker/pkg/integration/checker" |
| 23 |
+ "github.com/docker/go-units" |
|
| 23 | 24 |
"github.com/docker/libnetwork/iptables" |
| 24 | 25 |
"github.com/docker/libtrust" |
| 25 | 26 |
"github.com/go-check/check" |
| ... | ... |
@@ -154,6 +155,44 @@ func (s *DockerDaemonSuite) TestDaemonStartIptablesFalse(c *check.C) {
|
| 154 | 154 |
} |
| 155 | 155 |
} |
| 156 | 156 |
|
| 157 |
+// Make sure we cannot shrink base device at daemon restart. |
|
| 158 |
+func (s *DockerDaemonSuite) TestDaemonRestartWithInvalidBasesize(c *check.C) {
|
|
| 159 |
+ testRequires(c, Devicemapper) |
|
| 160 |
+ c.Assert(s.d.Start(), check.IsNil) |
|
| 161 |
+ |
|
| 162 |
+ oldBasesizeBytes := s.d.getBaseDeviceSize(c) |
|
| 163 |
+ var newBasesizeBytes int64 = 1073741824 //1GB in bytes |
|
| 164 |
+ |
|
| 165 |
+ if newBasesizeBytes < oldBasesizeBytes {
|
|
| 166 |
+ err := s.d.Restart("--storage-opt", fmt.Sprintf("dm.basesize=%d", newBasesizeBytes))
|
|
| 167 |
+ c.Assert(err, check.IsNil, check.Commentf("daemon should not have started as new base device size is less than existing base device size: %v", err))
|
|
| 168 |
+ } |
|
| 169 |
+ c.Assert(s.d.Stop(), check.IsNil) |
|
| 170 |
+} |
|
| 171 |
+ |
|
| 172 |
+// Make sure we can grow base device at daemon restart. |
|
| 173 |
+func (s *DockerDaemonSuite) TestDaemonRestartWithIncreasedBasesize(c *check.C) {
|
|
| 174 |
+ testRequires(c, Devicemapper) |
|
| 175 |
+ c.Assert(s.d.Start(), check.IsNil) |
|
| 176 |
+ |
|
| 177 |
+ oldBasesizeBytes := s.d.getBaseDeviceSize(c) |
|
| 178 |
+ |
|
| 179 |
+ var newBasesizeBytes int64 = 53687091200 //50GB in bytes |
|
| 180 |
+ |
|
| 181 |
+ if newBasesizeBytes < oldBasesizeBytes {
|
|
| 182 |
+ c.Skip(fmt.Sprintf("New base device size (%v) must be greater than (%s)", units.HumanSize(float64(newBasesizeBytes)), units.HumanSize(float64(oldBasesizeBytes))))
|
|
| 183 |
+ } |
|
| 184 |
+ |
|
| 185 |
+ err := s.d.Restart("--storage-opt", fmt.Sprintf("dm.basesize=%d", newBasesizeBytes))
|
|
| 186 |
+ c.Assert(err, check.IsNil, check.Commentf("we should have been able to start the daemon with increased base device size: %v", err))
|
|
| 187 |
+ |
|
| 188 |
+ basesizeAfterRestart := s.d.getBaseDeviceSize(c) |
|
| 189 |
+ newBasesize, err := convertBasesize(newBasesizeBytes) |
|
| 190 |
+ c.Assert(err, check.IsNil, check.Commentf("Error in converting base device size: %v", err))
|
|
| 191 |
+ c.Assert(newBasesize, check.Equals, basesizeAfterRestart, check.Commentf("Basesize passed is not equal to Basesize set"))
|
|
| 192 |
+ c.Assert(s.d.Stop(), check.IsNil) |
|
| 193 |
+} |
|
| 194 |
+ |
|
| 157 | 195 |
// Issue #8444: If docker0 bridge is modified (intentionally or unintentionally) and |
| 158 | 196 |
// no longer has an IP associated, we should gracefully handle that case and associate |
| 159 | 197 |
// an IP with it rather than fail daemon start |
| ... | ... |
@@ -25,11 +25,13 @@ import ( |
| 25 | 25 |
"github.com/docker/docker/opts" |
| 26 | 26 |
"github.com/docker/docker/pkg/httputils" |
| 27 | 27 |
"github.com/docker/docker/pkg/integration" |
| 28 |
+ "github.com/docker/docker/pkg/integration/checker" |
|
| 28 | 29 |
"github.com/docker/docker/pkg/ioutils" |
| 29 | 30 |
"github.com/docker/docker/pkg/stringutils" |
| 30 | 31 |
"github.com/docker/engine-api/types" |
| 31 | 32 |
"github.com/docker/go-connections/sockets" |
| 32 | 33 |
"github.com/docker/go-connections/tlsconfig" |
| 34 |
+ "github.com/docker/go-units" |
|
| 33 | 35 |
"github.com/go-check/check" |
| 34 | 36 |
) |
| 35 | 37 |
|
| ... | ... |
@@ -463,6 +465,32 @@ func (d *Daemon) waitRun(contID string) error {
|
| 463 | 463 |
return waitInspectWithArgs(contID, "{{.State.Running}}", "true", 10*time.Second, args...)
|
| 464 | 464 |
} |
| 465 | 465 |
|
| 466 |
+func (d *Daemon) getBaseDeviceSize(c *check.C) int64 {
|
|
| 467 |
+ |
|
| 468 |
+ infoCmdOutput, _, err := runCommandPipelineWithOutput( |
|
| 469 |
+ exec.Command(dockerBinary, "-H", d.sock(), "info"), |
|
| 470 |
+ exec.Command("grep", "Base Device Size"),
|
|
| 471 |
+ ) |
|
| 472 |
+ c.Assert(err, checker.IsNil) |
|
| 473 |
+ basesizeSlice := strings.Split(infoCmdOutput, ":") |
|
| 474 |
+ basesize := strings.Trim(basesizeSlice[1], " ") |
|
| 475 |
+ basesize = strings.Trim(basesize, "\n")[:len(basesize)-3] |
|
| 476 |
+ basesizeFloat, err := strconv.ParseFloat(strings.Trim(basesize, " "), 64) |
|
| 477 |
+ c.Assert(err, checker.IsNil) |
|
| 478 |
+ basesizeBytes := int64(basesizeFloat) * (1024 * 1024 * 1024) |
|
| 479 |
+ return basesizeBytes |
|
| 480 |
+} |
|
| 481 |
+ |
|
| 482 |
+func convertBasesize(basesizeBytes int64) (int64, error) {
|
|
| 483 |
+ basesize := units.HumanSize(float64(basesizeBytes)) |
|
| 484 |
+ basesize = strings.Trim(basesize, " ")[:len(basesize)-3] |
|
| 485 |
+ basesizeFloat, err := strconv.ParseFloat(strings.Trim(basesize, " "), 64) |
|
| 486 |
+ if err != nil {
|
|
| 487 |
+ return 0, err |
|
| 488 |
+ } |
|
| 489 |
+ return int64(basesizeFloat) * 1024 * 1024 * 1024, nil |
|
| 490 |
+} |
|
| 491 |
+ |
|
| 466 | 492 |
// Cmd will execute a docker CLI command against this Daemon. |
| 467 | 493 |
// Example: d.Cmd("version") will run docker -H unix://path/to/unix.sock version
|
| 468 | 494 |
func (d *Daemon) Cmd(name string, arg ...string) (string, error) {
|
| ... | ... |
@@ -103,6 +103,18 @@ var ( |
| 103 | 103 |
}, |
| 104 | 104 |
"Test requires underlying root filesystem not be backed by overlay.", |
| 105 | 105 |
} |
| 106 |
+ |
|
| 107 |
+ Devicemapper = testRequirement{
|
|
| 108 |
+ func() bool {
|
|
| 109 |
+ cmd := exec.Command("grep", "^devicemapper / devicemapper", "/proc/mounts")
|
|
| 110 |
+ if err := cmd.Run(); err != nil {
|
|
| 111 |
+ return false |
|
| 112 |
+ } |
|
| 113 |
+ return true |
|
| 114 |
+ }, |
|
| 115 |
+ "Test requires underlying root filesystem to be backed by devicemapper.", |
|
| 116 |
+ } |
|
| 117 |
+ |
|
| 106 | 118 |
IPv6 = testRequirement{
|
| 107 | 119 |
func() bool {
|
| 108 | 120 |
cmd := exec.Command("test", "-f", "/proc/net/if_inet6")
|