Command aptly mirror drop with system tests.

This commit is contained in:
Andrey Smirnov
2014-01-29 16:57:10 +04:00
parent 555256c1fe
commit 1803252f33
12 changed files with 169 additions and 4 deletions

View File

@@ -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 <name>",
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),

View File

@@ -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 <name>",
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),
}

View File

@@ -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:

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1 @@
Mirror `mirror1` has been removed.

View File

@@ -0,0 +1 @@
ERROR: unable to show: mirror with name mirror1 not found

View File

@@ -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

View File

@@ -0,0 +1 @@
Mirror `wheezy-main` has been removed.

View File

@@ -0,0 +1 @@
ERROR: unable to drop: mirror with name mirror1 not found

View File

@@ -6,3 +6,4 @@ from .create import *
from .show import *
from .list import *
from .update import *
from .drop import *

46
system/t04_mirror/drop.py Normal file
View File

@@ -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