diff --git a/cmd_mirror.go b/cmd_mirror.go index 0af83462..580e5e13 100644 --- a/cmd_mirror.go +++ b/cmd_mirror.go @@ -159,6 +159,46 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error { return err } +func aptlyMirrorDrop(cmd *commander.Command, args []string) error { + var err error + if len(args) != 1 { + cmd.Usage() + return err + } + + name := args[0] + + repoCollection := debian.NewRemoteRepoCollection(context.database) + repo, err := repoCollection.ByName(name) + if err != nil { + return fmt.Errorf("unable to drop: %s", err) + } + + force := cmd.Flag.Lookup("force").Value.Get().(bool) + if !force { + snapshotCollection := debian.NewSnapshotCollection(context.database) + snapshots := snapshotCollection.ByRemoteRepoSource(repo) + + if len(snapshots) > 0 { + fmt.Printf("Mirror `%s` was used to create following snapshots:\n", repo.Name) + for _, snapshot := range snapshots { + fmt.Printf(" * %s\n", snapshot) + } + + return fmt.Errorf("won't delete mirror with snapshots, use --force to override") + } + } + + err = repoCollection.Drop(repo) + if err != nil { + return fmt.Errorf("unable to drop: %s", err) + } + + fmt.Printf("Mirror `%s` has been removed.\n", repo.Name) + + return err +} + func makeCmdMirrorCreate() *commander.Command { cmd := &commander.Command{ Run: aptlyMirrorCreate, @@ -230,6 +270,26 @@ ex: return cmd } +func makeCmdMirrorDrop() *commander.Command { + cmd := &commander.Command{ + Run: aptlyMirrorDrop, + UsageLine: "drop ", + Short: "delete remote repository mirror", + Long: ` +Drop deletes information about remote repository mirror. Package data is not deleted +if it is still used by other mirrors or snapshots. + +ex: + $ aptly mirror drop wheezy-main +`, + Flag: *flag.NewFlagSet("aptly-mirror-drop", flag.ExitOnError), + } + + cmd.Flag.Bool("force", false, "force mirror deletion even if used by snapshots") + + return cmd +} + func makeCmdMirror() *commander.Command { return &commander.Command{ UsageLine: "mirror", @@ -238,7 +298,7 @@ func makeCmdMirror() *commander.Command { makeCmdMirrorCreate(), makeCmdMirrorList(), makeCmdMirrorShow(), - //makeCmdMirrorDestroy(), + makeCmdMirrorDrop(), makeCmdMirrorUpdate(), }, Flag: *flag.NewFlagSet("aptly-mirror", flag.ExitOnError), diff --git a/cmd_snapshot.go b/cmd_snapshot.go index 5173cfdf..528e186d 100644 --- a/cmd_snapshot.go +++ b/cmd_snapshot.go @@ -489,6 +489,35 @@ func aptlySnapshotMerge(cmd *commander.Command, args []string) error { return err } +func aptlySnapshotDrop(cmd *commander.Command, args []string) error { + var err error + if len(args) != 1 { + cmd.Usage() + return err + } + + name := args[0] + + snapshotCollection := debian.NewSnapshotCollection(context.database) + snapshot, err := snapshotCollection.ByName(name) + if err != nil { + return fmt.Errorf("unable to drop: %s", err) + } + + force := cmd.Flag.Lookup("force").Value.Get().(bool) + if !force { + // check for snapshots using this + } + + // check for published repos + + // drop + + _ = snapshot + + return err +} + func makeCmdSnapshotCreate() *commander.Command { cmd := &commander.Command{ Run: aptlySnapshotCreate, @@ -623,6 +652,26 @@ ex. return cmd } +func makeCmdSnapshotDrop() *commander.Command { + cmd := &commander.Command{ + Run: aptlySnapshotDrop, + UsageLine: "drop ", + Short: "delete snapshot", + Long: ` +Drop removes information about snapshot. If snapshot is published, +it can't be dropped. + +ex. + $ aptly snapshot drop wheezy-main +`, + Flag: *flag.NewFlagSet("aptly-snapshot-drop", flag.ExitOnError), + } + + cmd.Flag.Bool("force", false, "remove snapshot even if it was used as source for other snapshots") + + return cmd +} + func makeCmdSnapshot() *commander.Command { return &commander.Command{ UsageLine: "snapshot", @@ -635,7 +684,7 @@ func makeCmdSnapshot() *commander.Command { makeCmdSnapshotPull(), makeCmdSnapshotDiff(), makeCmdSnapshotMerge(), - //makeCmdSnapshotDestroy(), + makeCmdSnapshotDrop(), }, Flag: *flag.NewFlagSet("aptly-snapshot", flag.ExitOnError), } diff --git a/system/lib.py b/system/lib.py index bfe5cfa7..ce39b8e9 100644 --- a/system/lib.py +++ b/system/lib.py @@ -104,8 +104,8 @@ class BaseTest(object): def check_output(self): self.verify_match(self.get_gold(), self.output, match_prepare=self.outputMatchPrepare) - def check_cmd_output(self, command, gold_name, match_prepare=None): - self.verify_match(self.get_gold(gold_name), self.run_cmd(command), match_prepare) + def check_cmd_output(self, command, gold_name, match_prepare=None, expected_code=0): + self.verify_match(self.get_gold(gold_name), self.run_cmd(command, expected_code=expected_code), match_prepare) def verify_match(self, a, b, match_prepare=None): if match_prepare is not None: diff --git a/system/t03_help/MirrorHelpTest_gold b/system/t03_help/MirrorHelpTest_gold index 651082c9..a7dced76 100644 --- a/system/t03_help/MirrorHelpTest_gold +++ b/system/t03_help/MirrorHelpTest_gold @@ -3,6 +3,7 @@ aptly mirror - manage mirrors of remote repositories Commands: create create new mirror of Debian repository + drop delete remote repository mirror list list mirrors of remote repositories show show details about remote repository mirror update update packages from remote mirror diff --git a/system/t03_help/MirrorTest_gold b/system/t03_help/MirrorTest_gold index 651082c9..a7dced76 100644 --- a/system/t03_help/MirrorTest_gold +++ b/system/t03_help/MirrorTest_gold @@ -3,6 +3,7 @@ aptly mirror - manage mirrors of remote repositories Commands: create create new mirror of Debian repository + drop delete remote repository mirror list list mirrors of remote repositories show show details about remote repository mirror update update packages from remote mirror diff --git a/system/t04_mirror/DropMirror1Test_gold b/system/t04_mirror/DropMirror1Test_gold new file mode 100644 index 00000000..4faf1410 --- /dev/null +++ b/system/t04_mirror/DropMirror1Test_gold @@ -0,0 +1 @@ +Mirror `mirror1` has been removed. diff --git a/system/t04_mirror/DropMirror1Test_mirror_show b/system/t04_mirror/DropMirror1Test_mirror_show new file mode 100644 index 00000000..5e0b449b --- /dev/null +++ b/system/t04_mirror/DropMirror1Test_mirror_show @@ -0,0 +1 @@ +ERROR: unable to show: mirror with name mirror1 not found diff --git a/system/t04_mirror/DropMirror2Test_gold b/system/t04_mirror/DropMirror2Test_gold new file mode 100644 index 00000000..cd461b8a --- /dev/null +++ b/system/t04_mirror/DropMirror2Test_gold @@ -0,0 +1,3 @@ +Mirror `wheezy-main` was used to create following snapshots: + * [wheez]: Snapshot from mirror [wheezy-main]: http://mirror.yandex.ru/debian/ wheezy +ERROR: won't delete mirror with snapshots, use --force to override diff --git a/system/t04_mirror/DropMirror3Test_gold b/system/t04_mirror/DropMirror3Test_gold new file mode 100644 index 00000000..15ad42d4 --- /dev/null +++ b/system/t04_mirror/DropMirror3Test_gold @@ -0,0 +1 @@ +Mirror `wheezy-main` has been removed. diff --git a/system/t04_mirror/DropMirror4Test_gold b/system/t04_mirror/DropMirror4Test_gold new file mode 100644 index 00000000..f93d4ebd --- /dev/null +++ b/system/t04_mirror/DropMirror4Test_gold @@ -0,0 +1 @@ +ERROR: unable to drop: mirror with name mirror1 not found diff --git a/system/t04_mirror/__init__.py b/system/t04_mirror/__init__.py index c28d4fa6..12cb9cb0 100644 --- a/system/t04_mirror/__init__.py +++ b/system/t04_mirror/__init__.py @@ -6,3 +6,4 @@ from .create import * from .show import * from .list import * from .update import * +from .drop import * diff --git a/system/t04_mirror/drop.py b/system/t04_mirror/drop.py new file mode 100644 index 00000000..8680ff69 --- /dev/null +++ b/system/t04_mirror/drop.py @@ -0,0 +1,46 @@ +from lib import BaseTest + + +class DropMirror1Test(BaseTest): + """ + drop mirror: regular list + """ + fixtureCmds = [ + "aptly mirror create mirror1 http://mirror.yandex.ru/debian/ wheezy", + ] + runCmd = "aptly mirror drop mirror1" + + def check(self): + self.check_output() + self.check_cmd_output("aptly mirror show mirror1", "mirror_show", expected_code=1) + + +class DropMirror2Test(BaseTest): + """ + drop mirror: in use by snapshots + """ + fixtureDB = True + fixtureCmds = [ + "aptly snapshot create wheez from mirror wheezy-main" + ] + runCmd = "aptly mirror drop wheezy-main" + expectedCode = 1 + + +class DropMirror3Test(BaseTest): + """ + drop mirror: force + """ + fixtureDB = True + fixtureCmds = [ + "aptly snapshot create wheez from mirror wheezy-main" + ] + runCmd = "aptly mirror drop --force wheezy-main" + + +class DropMirror4Test(BaseTest): + """ + drop mirror: no such mirror + """ + runCmd = "aptly mirror drop mirror1" + expectedCode = 1