diff --git a/Makefile b/Makefile index 74d069e2..fe171292 100644 --- a/Makefile +++ b/Makefile @@ -76,8 +76,8 @@ ifeq ($(RUN_LONG_TESTS), yes) if [ ! -e ~/aptly-fixture-db ]; then git clone https://github.com/aptly-dev/aptly-fixture-db.git ~/aptly-fixture-db/; fi if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi # TODO: maybe we can skip imgrading levledb data to etcd - PATH=$(BINPATH)/:$(PATH) && . system/env/bin/activate && APTLY_VERSION=$(VERSION) $(PYTHON) system/leveldb2etcd.py --datadir ~/aptly-fixture-db - PATH=$(BINPATH)/:$(PATH) && . system/env/bin/activate && APTLY_ETCD_DATABASE="127.0.0.1:2379" APTLY_VERSION=$(VERSION) $(PYTHON) system/run.py --long $(TESTS) + PATH=$(BINPATH)/:$(PATH) && . system/env/bin/activate && $(PYTHON) system/leveldb2etcd.py --datadir ~/aptly-fixture-db + PATH=$(BINPATH)/:$(PATH) && . system/env/bin/activate && APTLY_DATABASE_TYPE="etcd" APTLY_DATABASE_URL="127.0.0.1:2379" APTLY_VERSION=$(VERSION) $(PYTHON) system/run.py --long $(TESTS) endif bench: diff --git a/context/context.go b/context/context.go index 7f17b84d..8838f26b 100644 --- a/context/context.go +++ b/context/context.go @@ -3,6 +3,7 @@ package context import ( gocontext "context" + "errors" "fmt" "math/rand" "os" @@ -289,8 +290,15 @@ func (context *AptlyContext) _database() (database.Storage, error) { if context.database == nil { var err error - if context.config().DatabaseEtcd != "" { - context.database, err = etcddb.NewDB(context.config().DatabaseEtcd) + if context.config().DatabaseBackend.Type == "etcd" { + context.database, err = etcddb.NewDB(context.config().DatabaseBackend.URL) + } else if context.config().DatabaseBackend.Type == "leveldb" { + if context.config().DatabaseBackend.DbPath != "" { + dbPath := filepath.Join(context.config().RootDir, context.config().DatabaseBackend.DbPath) + context.database, err = goleveldb.NewDB(dbPath) + } else { + return nil, errors.New("leveldb databaseBackend config invalid") + } } else { context.database, err = goleveldb.NewDB(context.dbPath()) } diff --git a/man/aptly.1.ronn.tmpl b/man/aptly.1.ronn.tmpl index f892ef91..c7d7a076 100644 --- a/man/aptly.1.ronn.tmpl +++ b/man/aptly.1.ronn.tmpl @@ -28,7 +28,10 @@ Configuration file is stored in JSON format (default values shown below): { "rootDir": "$HOME/.aptly", - "databaseEtcd": "", + "databaseBackend": { + "type": "", + "url": "" + }, "downloadConcurrency": 4, "downloadSpeedLimit": 0, "downloadRetries": 0, @@ -120,8 +123,8 @@ Options: the default for downloaded packages (`rootDir`/pool) and the default for published repositories (`rootDir`/public) - * `databaseEtcd`: - the etcd database connection address is empty by default, which means it is not used + * `databaseBackend`: + the database config; if this config is empty, use levledb backend by default * `downloadConcurrency`: is a number of parallel download threads to use when downloading packages diff --git a/system/lib.py b/system/lib.py index 98d86d32..d4ce5e25 100644 --- a/system/lib.py +++ b/system/lib.py @@ -133,9 +133,17 @@ class BaseTest(object): aptlyDir = ".aptly" aptlyConfigFile = ".aptly.conf" expectedCode = 0 - databaseEtcd = os.environ.get("APTLY_ETCD_DATABASE") - if databaseEtcd is None: - databaseEtcd = "" + databaseType = os.environ.get("APTLY_DATABASE_TYPE") + databaseUrl = os.environ.get("APTLY_DATABASE_URL") + if databaseType is None: + databaseType = "" + if databaseUrl is None: + databaseUrl = "" + + databaseBackend = { + "type": databaseType, + "url": databaseUrl, + } configFile = { "rootDir": f"{os.environ['HOME']}/{aptlyDir}", @@ -157,6 +165,7 @@ class BaseTest(object): "logFormat": "default", "serveInAPIMode": True, "databaseEtcd": databaseEtcd, + "databaseBackend": databaseBackend, } configOverride = {} environmentOverride = {} diff --git a/system/t02_config/ConfigShowTest_gold b/system/t02_config/ConfigShowTest_gold index 58c65bf9..ad12f307 100644 --- a/system/t02_config/ConfigShowTest_gold +++ b/system/t02_config/ConfigShowTest_gold @@ -30,5 +30,6 @@ "logLevel": "debug", "logFormat": "default", "serveInAPIMode": true, - "databaseEtcd": "" + "databaseEtcd": "", + "databaseBackend": {} } diff --git a/system/t02_config/CreateConfigTest_gold b/system/t02_config/CreateConfigTest_gold index 2aaf7c64..24bed7f6 100644 --- a/system/t02_config/CreateConfigTest_gold +++ b/system/t02_config/CreateConfigTest_gold @@ -30,5 +30,6 @@ "logLevel": "debug", "logFormat": "default", "serveInAPIMode": false, - "databaseEtcd": "" + "databaseEtcd": "", + "databaseBackend": {} } diff --git a/utils/config.go b/utils/config.go index e9ebc536..29940811 100644 --- a/utils/config.go +++ b/utils/config.go @@ -41,6 +41,14 @@ type ConfigStructure struct { // nolint: maligned LogFormat string `json:"logFormat"` ServeInAPIMode bool `json:"serveInAPIMode"` DatabaseEtcd string `json:"databaseEtcd"` + DatabaseBackend DBConfig `json:"databaseBackend"` +} + +// DBConfig +type DBConfig struct { + Type string `json:"type"` + URL string `json:"url"` + DbPath string `json:"dbPath"` } type LocalPoolStorage struct { diff --git a/utils/config_test.go b/utils/config_test.go index 3036e8a8..8760c90c 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -144,7 +144,11 @@ func (s *ConfigSuite) TestSaveConfig(c *C) { " \"logLevel\": \"info\",\n"+ " \"logFormat\": \"json\",\n"+ " \"serveInAPIMode\": false,\n"+ - " \"databaseEtcd\": \"\"\n"+ + " \"databaseEtcd\": \"\",\n"+ + " \"databaseBackend\": {\n"+ + " \"type\": \"\",\n"+ + " \"url\": \"\"\n"+ + " }\n"+ "}") }