Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ ifeq ($(CAPTURE),1)
CAPTURE_ARG := --capture
endif

# export DEBUG=1 to enable debug output in system tests
ifeq ($(DEBUG),1)
DEBUG_ARG := --debug
endif

help: ## Print this help
@grep -E '^[a-zA-Z][a-zA-Z0-9_-]*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

Expand Down Expand Up @@ -121,7 +126,7 @@ system-test: prepare swagger etcd-install ## Run system tests
if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi
test -f ~/etcd.db || (curl -o ~/etcd.db.xz http://repo.aptly.info/system-tests/etcd.db.xz && xz -d ~/etcd.db.xz)
# Run system tests
PATH=$(BINPATH)/:$(PATH) FORCE_COLOR=1 $(PYTHON) system/run.py --long $(COVERAGE_ARG_TEST) $(CAPTURE_ARG) $(TEST)
PATH=$(BINPATH)/:$(PATH) FORCE_COLOR=1 $(PYTHON) system/run.py --long $(COVERAGE_ARG_TEST) $(CAPTURE_ARG) $(DEBUG_ARG) $(TEST)

bench:
@echo "\e[33m\e[1mRunning benchmark ...\e[0m"
Expand Down Expand Up @@ -211,7 +216,7 @@ docker-system-test: ## Run system tests in docker container (add TEST=t04_mirro
AZURE_STORAGE_ACCESS_KEY="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" \
AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) \
AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) \
system-test TEST=$(TEST) CAPTURE=$(CAPTURE) COVERAGE_SKIP=$(COVERAGE_SKIP) \
system-test TEST=$(TEST) CAPTURE=$(CAPTURE) COVERAGE_SKIP=$(COVERAGE_SKIP) DEBUG=$(DEBUG) \
azurite-stop

docker-serve: ## Run development server (auto recompiling) on http://localhost:3142
Expand Down
78 changes: 64 additions & 14 deletions api/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
if b.SourceKind == deb.SourceSnapshot {
var snapshot *deb.Snapshot

snapshotCollection := collectionFactory.SnapshotCollection()
tmpCollection := collectionFactory.SnapshotCollection()

for _, source := range b.Sources {
components = append(components, source.Component)
names = append(names, source.Name)

snapshot, err = snapshotCollection.ByName(source.Name)
snapshot, err = tmpCollection.ByName(source.Name)
if err != nil {
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to publish: %s", err))
return
Expand All @@ -273,13 +273,13 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
} else if b.SourceKind == deb.SourceLocalRepo {
var localRepo *deb.LocalRepo

localCollection := collectionFactory.LocalRepoCollection()
tmpCollection := collectionFactory.LocalRepoCollection()

for _, source := range b.Sources {
components = append(components, source.Component)
names = append(names, source.Name)

localRepo, err = localCollection.ByName(source.Name)
localRepo, err = tmpCollection.ByName(source.Name)
if err != nil {
AbortWithJSONError(c, http.StatusNotFound, fmt.Errorf("unable to publish: %s", err))
return
Expand Down Expand Up @@ -332,8 +332,6 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to publish: %s", err)
}

resources = append(resources, string(published.Key()))

if b.Origin != "" {
published.Origin = b.Origin
}
Expand Down Expand Up @@ -387,6 +385,46 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
})
}

// Return resources to be locked for a Snapshot name
func getSnapshotResources(snapshotCollection *deb.SnapshotCollection, snapshotName string) (resources []string, err error) {
snapshot, err := snapshotCollection.ByName(snapshotName)
if err != nil {
return
}
resources = append(resources, string(snapshot.ResourceKey()))

for _, sourceID := range snapshot.SourceIDs {
if snapshot.SourceKind == deb.SourceSnapshot {
snapshot2, err2 := snapshotCollection.ByUUID(sourceID)
if err2 != nil {
err = err2
return
}
res, err3 := getSnapshotResources(snapshotCollection, snapshot2.Name)
if err3 != nil {
err = err3
return
}
resources = append(resources, res...)
} else if snapshot.SourceKind == deb.SourceLocalRepo {
var repo *deb.LocalRepo
repo, err = context.NewCollectionFactory().LocalRepoCollection().ByUUID(sourceID)
if err != nil {
return
}
resources = append(resources, string(repo.Key()))
} else if snapshot.SourceKind == deb.SourceRemoteRepo {
var mirror *deb.RemoteRepo
mirror, err = context.NewCollectionFactory().RemoteRepoCollection().ByUUID(sourceID)
if err != nil {
return
}
resources = append(resources, string(mirror.Key()))
}
}
return
}

type publishedRepoUpdateSwitchParams struct {
// when publishing, overwrite files in pool/ directory without notice
ForceOverwrite bool ` json:"ForceOverwrite" example:"false"`
Expand All @@ -406,12 +444,12 @@ type publishedRepoUpdateSwitchParams struct {
SignedBy *string ` json:"SignedBy" example:""`
// Enable multiple packages with the same filename in different distributions
MultiDist *bool ` json:"MultiDist" example:"false"`
// Value of Label: field in published repository stanza
Label *string ` json:"Label" example:"Debian"`
// Value of Origin: field in published repository stanza
Origin *string ` json:"Origin" example:"Debian"`
// Version of the release: Optional
Version *string ` json:"Version" example:"13.3"`
// Value of Label: field in published repository stanza
Label *string ` json:"Label" example:"Debian"`
// Value of Origin: field in published repository stanza
Origin *string ` json:"Origin" example:"Debian"`
// Version of the release: Optional
Version *string ` json:"Version" example:"13.3"`
}

// @Summary Update Published Repository
Expand Down Expand Up @@ -465,18 +503,31 @@ func apiPublishUpdateSwitch(c *gin.Context) {
return
}

resources := []string{string(published.Key())}

if published.SourceKind == deb.SourceLocalRepo {
if len(b.Snapshots) > 0 {
AbortWithJSONError(c, http.StatusBadRequest, fmt.Errorf("snapshots shouldn't be given when updating local repo"))
return
}

localCollection := collectionFactory.LocalRepoCollection()
for _, sourceID := range published.Sources {
localRepo, err2 := localCollection.ByUUID(sourceID)
if err2 != nil {
AbortWithJSONError(c, http.StatusNotFound, err2)
return
}
resources = append(resources, string(localRepo.Key()))
}
} else if published.SourceKind == deb.SourceSnapshot {
for _, snapshotInfo := range b.Snapshots {
_, err2 := snapshotCollection.ByName(snapshotInfo.Name)
res, err2 := getSnapshotResources(snapshotCollection, snapshotInfo.Name)
if err2 != nil {
AbortWithJSONError(c, http.StatusNotFound, err2)
return
}
resources = append(resources, res...)
}
} else {
AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unknown published repository type"))
Expand Down Expand Up @@ -515,7 +566,6 @@ func apiPublishUpdateSwitch(c *gin.Context) {
published.Version = *b.Version
}

resources := []string{string(published.Key())}
taskName := fmt.Sprintf("Update published %s repository %s/%s", published.SourceKind, published.StoragePrefix(), published.Distribution)
maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, _ *task.Detail) (*task.ProcessReturnValue, error) {
err = collection.LoadComplete(published, collectionFactory)
Expand Down
7 changes: 6 additions & 1 deletion deb/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,12 @@ func (p *PublishedRepo) StoragePrefix() string {

// Key returns unique key identifying PublishedRepo
func (p *PublishedRepo) Key() []byte {
return []byte("U" + p.StoragePrefix() + ">>" + p.Distribution)
if p.MultiDist {
// do not lock Distribution in MultiDist
return []byte("UM" + p.StoragePrefix())
} else {
return []byte("U" + p.StoragePrefix() + ">>" + p.Distribution)
}
}

// RefKey is a unique id for package reference list
Expand Down
2 changes: 1 addition & 1 deletion system/api_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class APITest(BaseTest):
"""
aptly_server = None
aptly_out = None
debugOutput = True
debugOutput = False # Controlled by --debug flag in run.py
base_url = "127.0.0.1:8765"
configOverride = {
"FileSystemPublishEndpoints": {
Expand Down
4 changes: 2 additions & 2 deletions system/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ def test(self):
self.run()
self.check()
except Exception as exc:
if self.debugOutput:
print(f"API log:\n{self.debug_output()}")
raise exc
finally:
if self.debugOutput:
print(f"API log:\n{self.debug_output()}")
self.teardown()

def prepare_remove_all(self):
Expand Down
11 changes: 9 additions & 2 deletions system/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def natural_key(string_):
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_)]


def run(include_long_tests=False, capture_results=False, tests=None, filters=None, coverage_dir=None, coverage_skip=False):
def run(include_long_tests=False, capture_results=False, tests=None, filters=None, coverage_dir=None, coverage_skip=False, debug=False):
"""
Run system test.
"""
Expand All @@ -50,6 +50,9 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
if not coverage_dir and not coverage_skip:
coverage_dir = mkdtemp(suffix="aptly-coverage")

# Set debug output globally for all test classes
BaseTest.debugOutput = debug

failed = False
for test in tests:
orig_stdout = sys.stdout
Expand Down Expand Up @@ -155,6 +158,7 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
traceback.print_exception(typ, val, tb, file=orig_stdout)
else:
orig_stdout.write(colored("\b\b\b\bOK", color="green", attrs=["bold"]) + f" {duration}\n")
orig_stdout.write(testout.get_contents())

t.shutdown()

Expand Down Expand Up @@ -214,6 +218,7 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
capture_results = False
coverage_dir = None
coverage_skip = False
debug = False
tests = None
args = sys.argv[1:]

Expand All @@ -227,6 +232,8 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
args = args[1:]
elif args[0] == "--coverage-skip":
coverage_skip = True
elif args[0] == "--debug":
debug = True

args = args[1:]

Expand All @@ -239,4 +246,4 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
else:
filters.append(arg)

run(include_long_tests, capture_results, tests, filters, coverage_dir, coverage_skip)
run(include_long_tests, capture_results, tests, filters, coverage_dir, coverage_skip, debug)
Loading
Loading