properly expose AcquireByHash through the api

- new publish calls can now enable AcquireByHash by right away (previously
  one would have had to create a new publishing endpoint and then
  explicitly switch it to AcquireByHash)
- all json marshals of PublishedRepo now contain AcquireByHash (allows
  inspecting if a given endpoint has AcquireByHash enabled already; also
  enables verification that a switch/update actually applied a
  potential AcquireByHash change
- update all tests to reflect that default state of AcquireByHash
- update creation and switch testing to explicitly toggle AcquireByHash to
  make sure state mutation works as expected
This commit is contained in:
Harald Sitter
2018-01-15 17:04:05 +01:00
parent 1aa88701fb
commit 75c4d6da3b
3 changed files with 22 additions and 0 deletions

View File

@@ -104,6 +104,7 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
SkipContents *bool
Architectures []string
Signing SigningOptions
AcquireByHash *bool
}
if c.Bind(&b) != nil {
@@ -201,6 +202,10 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
published.SkipContents = *b.SkipContents
}
if b.AcquireByHash != nil {
published.AcquireByHash = *b.AcquireByHash
}
duplicate := collection.CheckDuplicate(published)
if duplicate != nil {
context.CollectionFactory().PublishedRepoCollection().LoadComplete(duplicate, context.CollectionFactory())

View File

@@ -315,6 +315,7 @@ func (p *PublishedRepo) MarshalJSON() ([]byte, error) {
"Sources": sources,
"Storage": p.Storage,
"SkipContents": p.SkipContents,
"AcquireByHash": p.AcquireByHash,
})
}

View File

@@ -36,6 +36,7 @@ class PublishAPITestRepo(APITest):
"Signing": DefaultSigningOptions,
})
repo_expected = {
'AcquireByHash': False,
'Architectures': ['i386', 'source'],
'Distribution': 'wheezy',
'Label': '',
@@ -72,6 +73,7 @@ class PublishAPITestRepo(APITest):
"Architectures": ["i386", "amd64"],
})
repo2_expected = {
'AcquireByHash': False,
'Architectures': ['amd64', 'i386'],
'Distribution': distribution,
'Label': '',
@@ -120,6 +122,7 @@ class PublishSnapshotAPITest(APITest):
prefix = self.random_name()
resp = self.post("/api/publish/" + prefix,
json={
"AcquireByHash": True,
"SourceKind": "snapshot",
"Sources": [{"Name": snapshot_name}],
"Signing": DefaultSigningOptions,
@@ -129,6 +132,7 @@ class PublishSnapshotAPITest(APITest):
})
self.check_equal(resp.status_code, 201)
self.check_equal(resp.json(), {
'AcquireByHash': True,
'Architectures': ['i386'],
'Distribution': 'squeeze',
'Label': '',
@@ -142,6 +146,7 @@ class PublishSnapshotAPITest(APITest):
'Storage': ''})
self.check_exists("public/" + prefix + "/dists/squeeze/Release")
self.check_exists("public/" + prefix + "/dists/squeeze/main/binary-i386/by-hash")
self.check_exists("public/" + prefix + "/dists/squeeze/main/binary-i386/Packages")
self.check_exists("public/" + prefix + "/dists/squeeze/main/Contents-i386.gz")
self.check_exists("public/" + prefix + "/pool/main/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb")
@@ -187,11 +192,14 @@ class PublishUpdateAPITestRepo(APITest):
self.check_equal(self.delete("/api/repos/" + repo_name + "/packages/",
json={"PackageRefs": ['Psource pyspi 0.6.1-1.4 f8f1daa806004e89']}).status_code, 200)
# Update and switch AcquireByHash on.
resp = self.put("/api/publish/" + prefix + "/wheezy",
json={
"AcquireByHash": True,
"Signing": DefaultSigningOptions,
})
repo_expected = {
'AcquireByHash': True,
'Architectures': ['i386', 'source'],
'Distribution': 'wheezy',
'Label': '',
@@ -207,6 +215,8 @@ class PublishUpdateAPITestRepo(APITest):
self.check_equal(resp.status_code, 200)
self.check_equal(resp.json(), repo_expected)
self.check_exists("public/" + prefix + "/dists/wheezy/main/binary-i386/by-hash")
self.check_exists("public/" + prefix + "/pool/main/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb")
self.check_not_exists("public/" + prefix + "/pool/main/p/pyspi/pyspi-0.6.1-1.3.stripped.dsc")
@@ -273,6 +283,7 @@ class PublishUpdateSkipCleanupAPITestRepo(APITest):
"SkipCleanup": True,
})
repo_expected = {
'AcquireByHash': False,
'Architectures': ['i386', 'source'],
'Distribution': 'wheezy',
'Label': '',
@@ -328,6 +339,7 @@ class PublishSwitchAPITestRepo(APITest):
self.check_equal(resp.status_code, 201)
repo_expected = {
'AcquireByHash': False,
'Architectures': ['i386', 'source'],
'Distribution': 'wheezy',
'Label': '',
@@ -362,6 +374,7 @@ class PublishSwitchAPITestRepo(APITest):
"SkipContents": True,
})
repo_expected = {
'AcquireByHash': False,
'Architectures': ['i386', 'source'],
'Distribution': 'wheezy',
'Label': '',
@@ -416,6 +429,7 @@ class PublishSwitchAPISkipCleanupTestRepo(APITest):
self.check_equal(resp.status_code, 201)
repo_expected = {
'AcquireByHash': False,
'Architectures': ['i386', 'source'],
'Distribution': 'wheezy',
'Label': '',
@@ -445,6 +459,7 @@ class PublishSwitchAPISkipCleanupTestRepo(APITest):
self.check_equal(resp.status_code, 201)
repo_expected = {
'AcquireByHash': False,
'Architectures': ['i386', 'source'],
'Distribution': 'otherdist',
'Label': '',
@@ -477,6 +492,7 @@ class PublishSwitchAPISkipCleanupTestRepo(APITest):
"SkipContents": True,
})
repo_expected = {
'AcquireByHash': False,
'Architectures': ['i386', 'source'],
'Distribution': 'wheezy',
'Label': '',