| ... | ... |
@@ -843,3 +843,43 @@ func TestGetAllChildren(t *testing.T) {
|
| 843 | 843 |
} |
| 844 | 844 |
} |
| 845 | 845 |
} |
| 846 |
+ |
|
| 847 |
+func TestDestroyWithInitLayer(t *testing.T) {
|
|
| 848 |
+ runtime := mkRuntime(t) |
|
| 849 |
+ defer nuke(runtime) |
|
| 850 |
+ |
|
| 851 |
+ container, _, err := runtime.Create(&docker.Config{
|
|
| 852 |
+ Image: GetTestImage(runtime).ID, |
|
| 853 |
+ Cmd: []string{"ls", "-al"},
|
|
| 854 |
+ }, "") |
|
| 855 |
+ |
|
| 856 |
+ if err != nil {
|
|
| 857 |
+ t.Fatal(err) |
|
| 858 |
+ } |
|
| 859 |
+ // Destroy |
|
| 860 |
+ if err := runtime.Destroy(container); err != nil {
|
|
| 861 |
+ t.Fatal(err) |
|
| 862 |
+ } |
|
| 863 |
+ |
|
| 864 |
+ // Make sure runtime.Exists() behaves correctly |
|
| 865 |
+ if runtime.Exists("test_destroy") {
|
|
| 866 |
+ t.Fatalf("Exists() returned true")
|
|
| 867 |
+ } |
|
| 868 |
+ |
|
| 869 |
+ // Make sure runtime.List() doesn't list the destroyed container |
|
| 870 |
+ if len(runtime.List()) != 0 {
|
|
| 871 |
+ t.Fatalf("Expected 0 container, %v found", len(runtime.List()))
|
|
| 872 |
+ } |
|
| 873 |
+ |
|
| 874 |
+ driver := runtime.Graph().Driver() |
|
| 875 |
+ |
|
| 876 |
+ // Make sure that the container does not exist in the driver |
|
| 877 |
+ if _, err := driver.Get(container.ID); err == nil {
|
|
| 878 |
+ t.Fatal("Conttainer should not exist in the driver")
|
|
| 879 |
+ } |
|
| 880 |
+ |
|
| 881 |
+ // Make sure that the init layer is removed from the driver |
|
| 882 |
+ if _, err := driver.Get(fmt.Sprintf("%s-init", container.ID)); err == nil {
|
|
| 883 |
+ t.Fatal("Container's init layer should not exist in the driver")
|
|
| 884 |
+ } |
|
| 885 |
+} |
| ... | ... |
@@ -237,6 +237,11 @@ func (runtime *Runtime) Destroy(container *Container) error {
|
| 237 | 237 |
return fmt.Errorf("Driver %s failed to remove root filesystem %s: %s", runtime.driver, container.ID, err)
|
| 238 | 238 |
} |
| 239 | 239 |
|
| 240 |
+ initID := fmt.Sprintf("%s-init", container.ID)
|
|
| 241 |
+ if err := runtime.driver.Remove(initID); err != nil {
|
|
| 242 |
+ return fmt.Errorf("Driver %s failed to remove init filesystem %s: %s", runtime.driver, initID, err)
|
|
| 243 |
+ } |
|
| 244 |
+ |
|
| 240 | 245 |
if _, err := runtime.containerGraph.Purge(container.ID); err != nil {
|
| 241 | 246 |
utils.Debugf("Unable to remove container from link graph: %s", err)
|
| 242 | 247 |
} |