mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-05 22:08:27 +00:00
Command aptly mirror drop with system tests.
This commit is contained in:
@@ -159,6 +159,46 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
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 {
|
func makeCmdMirrorCreate() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlyMirrorCreate,
|
Run: aptlyMirrorCreate,
|
||||||
@@ -230,6 +270,26 @@ ex:
|
|||||||
return cmd
|
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 {
|
func makeCmdMirror() *commander.Command {
|
||||||
return &commander.Command{
|
return &commander.Command{
|
||||||
UsageLine: "mirror",
|
UsageLine: "mirror",
|
||||||
@@ -238,7 +298,7 @@ func makeCmdMirror() *commander.Command {
|
|||||||
makeCmdMirrorCreate(),
|
makeCmdMirrorCreate(),
|
||||||
makeCmdMirrorList(),
|
makeCmdMirrorList(),
|
||||||
makeCmdMirrorShow(),
|
makeCmdMirrorShow(),
|
||||||
//makeCmdMirrorDestroy(),
|
makeCmdMirrorDrop(),
|
||||||
makeCmdMirrorUpdate(),
|
makeCmdMirrorUpdate(),
|
||||||
},
|
},
|
||||||
Flag: *flag.NewFlagSet("aptly-mirror", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-mirror", flag.ExitOnError),
|
||||||
|
|||||||
@@ -489,6 +489,35 @@ func aptlySnapshotMerge(cmd *commander.Command, args []string) error {
|
|||||||
return err
|
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 {
|
func makeCmdSnapshotCreate() *commander.Command {
|
||||||
cmd := &commander.Command{
|
cmd := &commander.Command{
|
||||||
Run: aptlySnapshotCreate,
|
Run: aptlySnapshotCreate,
|
||||||
@@ -623,6 +652,26 @@ ex.
|
|||||||
return cmd
|
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 {
|
func makeCmdSnapshot() *commander.Command {
|
||||||
return &commander.Command{
|
return &commander.Command{
|
||||||
UsageLine: "snapshot",
|
UsageLine: "snapshot",
|
||||||
@@ -635,7 +684,7 @@ func makeCmdSnapshot() *commander.Command {
|
|||||||
makeCmdSnapshotPull(),
|
makeCmdSnapshotPull(),
|
||||||
makeCmdSnapshotDiff(),
|
makeCmdSnapshotDiff(),
|
||||||
makeCmdSnapshotMerge(),
|
makeCmdSnapshotMerge(),
|
||||||
//makeCmdSnapshotDestroy(),
|
makeCmdSnapshotDrop(),
|
||||||
},
|
},
|
||||||
Flag: *flag.NewFlagSet("aptly-snapshot", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-snapshot", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,8 +104,8 @@ class BaseTest(object):
|
|||||||
def check_output(self):
|
def check_output(self):
|
||||||
self.verify_match(self.get_gold(), self.output, match_prepare=self.outputMatchPrepare)
|
self.verify_match(self.get_gold(), self.output, match_prepare=self.outputMatchPrepare)
|
||||||
|
|
||||||
def check_cmd_output(self, command, gold_name, match_prepare=None):
|
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), match_prepare)
|
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):
|
def verify_match(self, a, b, match_prepare=None):
|
||||||
if match_prepare is not None:
|
if match_prepare is not None:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ aptly mirror - manage mirrors of remote repositories
|
|||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
create create new mirror of Debian repository
|
create create new mirror of Debian repository
|
||||||
|
drop delete remote repository mirror
|
||||||
list list mirrors of remote repositories
|
list list mirrors of remote repositories
|
||||||
show show details about remote repository mirror
|
show show details about remote repository mirror
|
||||||
update update packages from remote mirror
|
update update packages from remote mirror
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ aptly mirror - manage mirrors of remote repositories
|
|||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
create create new mirror of Debian repository
|
create create new mirror of Debian repository
|
||||||
|
drop delete remote repository mirror
|
||||||
list list mirrors of remote repositories
|
list list mirrors of remote repositories
|
||||||
show show details about remote repository mirror
|
show show details about remote repository mirror
|
||||||
update update packages from remote mirror
|
update update packages from remote mirror
|
||||||
|
|||||||
1
system/t04_mirror/DropMirror1Test_gold
Normal file
1
system/t04_mirror/DropMirror1Test_gold
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Mirror `mirror1` has been removed.
|
||||||
1
system/t04_mirror/DropMirror1Test_mirror_show
Normal file
1
system/t04_mirror/DropMirror1Test_mirror_show
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ERROR: unable to show: mirror with name mirror1 not found
|
||||||
3
system/t04_mirror/DropMirror2Test_gold
Normal file
3
system/t04_mirror/DropMirror2Test_gold
Normal 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
|
||||||
1
system/t04_mirror/DropMirror3Test_gold
Normal file
1
system/t04_mirror/DropMirror3Test_gold
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Mirror `wheezy-main` has been removed.
|
||||||
1
system/t04_mirror/DropMirror4Test_gold
Normal file
1
system/t04_mirror/DropMirror4Test_gold
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ERROR: unable to drop: mirror with name mirror1 not found
|
||||||
@@ -6,3 +6,4 @@ from .create import *
|
|||||||
from .show import *
|
from .show import *
|
||||||
from .list import *
|
from .list import *
|
||||||
from .update import *
|
from .update import *
|
||||||
|
from .drop import *
|
||||||
|
|||||||
46
system/t04_mirror/drop.py
Normal file
46
system/t04_mirror/drop.py
Normal 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
|
||||||
Reference in New Issue
Block a user