Skip to content

Commit

Permalink
feat(cdn): requires at least one storage that is not cds (#5747)
Browse files Browse the repository at this point in the history
Signed-off-by: richardlt <[email protected]>
  • Loading branch information
richardlt authored Mar 9, 2021
1 parent aef2102 commit 855efde
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
36 changes: 25 additions & 11 deletions engine/cdn/cdn_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cdn

import (
"context"
"io/ioutil"
"testing"
"time"

Expand Down Expand Up @@ -29,6 +30,9 @@ func TestSyncBuffer(t *testing.T) {
cdntest.ClearItem(t, context.Background(), m, db)
cdntest.ClearUnits(t, context.Background(), m, db)

tmpDir, err := ioutil.TempDir("", t.Name()+"-cdn-*")
require.NoError(t, err)

// Create cdn service
s := Service{
DBConnectionFactory: factory,
Expand All @@ -38,10 +42,6 @@ func TestSyncBuffer(t *testing.T) {
GoRoutines: sdk.NewGoRoutines(),
},
}
cdsConfig := &storage.CDSStorageConfiguration{
Host: "http://lolcat.host:8081",
Token: "mytoken",
}
cdnUnits, err := storage.Init(context.Background(), m, cache, db.DbMap, sdk.NewGoRoutines(), storage.Configuration{
HashLocatorSalt: "thisismysalt",
Buffers: map[string]storage.BufferConfiguration{
Expand All @@ -55,7 +55,15 @@ func TestSyncBuffer(t *testing.T) {
},
Storages: map[string]storage.StorageConfiguration{
"test-cds-backend.TestSyncBuffer": {
CDS: cdsConfig,
CDS: &storage.CDSStorageConfiguration{
Host: "http://lolcat.host:8081",
Token: "mytoken",
},
},
"test-local.TestSyncBuffer": {
Local: &storage.LocalStorageConfiguration{
Path: tmpDir,
},
},
},
})
Expand Down Expand Up @@ -92,14 +100,12 @@ func TestSyncLog(t *testing.T) {
},
}

cdsConfig := &storage.CDSStorageConfiguration{
Host: "http://lolcat.host:8081",
Token: "mytoken",
}

ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
t.Cleanup(cancel)

tmpDir, err := ioutil.TempDir("", t.Name()+"-cdn-*")
require.NoError(t, err)

cdnUnits, err := storage.Init(ctx, m, cache, db.DbMap, sdk.NewGoRoutines(), storage.Configuration{
HashLocatorSalt: "thisismysalt",
SyncNbElements: 100,
Expand All @@ -116,7 +122,15 @@ func TestSyncLog(t *testing.T) {
},
Storages: map[string]storage.StorageConfiguration{
"test-cds-backend.TestSyncLog": {
CDS: cdsConfig,
CDS: &storage.CDSStorageConfiguration{
Host: "http://lolcat.host:8081",
Token: "mytoken",
},
},
"test-local.TestSyncLog": {
Local: &storage.LocalStorageConfiguration{
Path: tmpDir,
},
},
},
})
Expand Down
6 changes: 4 additions & 2 deletions engine/cdn/storage/storageunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ func Init(ctx context.Context, m *gorpmapper.Mapper, store cache.Store, db *gorp
countFileBuffer++
}
}
if countLogBuffer == 0 || countLogBuffer > 1 {
if countLogBuffer != 1 {
return nil, sdk.WithStack(fmt.Errorf("missing or too much CDN Buffer for log items"))
}
// TODO set file buffer as required when CDN will be use by default for files
if countFileBuffer > 1 {
return nil, sdk.WithStack(fmt.Errorf("too much CDN Buffer for file items"))
}

// We should have at least one storage backend that is not of type cds to store logs and artifacts
activeStorage := 0
for _, s := range config.Storages {
if !s.DisableSync {
if !s.DisableSync && s.CDS == nil {
activeStorage++
}
}
Expand Down

0 comments on commit 855efde

Please sign in to comment.