Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service config version [T1031] #322

Merged
merged 41 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9d758e0
export version as metric
Lagovas Feb 21, 2019
2038bb8
export version as metric
Lagovas Feb 22, 2019
7995802
Merge remote-tracking branch 'origin/master' into lagovas/T1002-expor…
Lagovas Feb 22, 2019
ea7ac0d
export metrics for translator/connector
Lagovas Feb 22, 2019
379b247
move prometheus logic for exporting versions to cmd package
Lagovas Feb 22, 2019
bdf11d6
check censor version; run tests in a loop
Lagovas Feb 22, 2019
00f9683
fix circleci config
Lagovas Feb 26, 2019
b41841e
fix golint issues
Lagovas Feb 26, 2019
7b58bfe
fix identation
Lagovas Feb 26, 2019
b976062
fix
Lagovas Feb 26, 2019
9a7e4b6
update tests requirements
Lagovas Feb 26, 2019
4054945
update censor's tests
Lagovas Feb 26, 2019
666229c
update network tests to support go1.12
Lagovas Feb 26, 2019
af7fd57
Merge remote-tracking branch 'origin/master' into lagovas/T971-censor…
Lagovas Feb 26, 2019
8e1e5e2
fix tests for tls1.3
Lagovas Feb 26, 2019
7ce0741
run go test with GODEBUG=tls13=1
Lagovas Feb 26, 2019
9a52545
fix loop for tests
Lagovas Feb 26, 2019
71f0867
log iterations too
Lagovas Feb 27, 2019
d04df59
store retries in artifacts
Lagovas Feb 27, 2019
5fe8724
save log to artifacts, log status to distinguish timeout error from o…
Lagovas Feb 27, 2019
6b986a0
add tests for version functions
Lagovas Feb 27, 2019
9723346
add version to services configs
Lagovas Feb 28, 2019
d7850f3
correctly fetch status of bash commands; requested messages changes;
Lagovas Feb 28, 2019
0a145c7
change error text for ErrInvalidVersionFormat
Lagovas Feb 28, 2019
652824c
Merge branch 'lagovas/T971-censor-versioning' into lagovas/T1031-serv…
Lagovas Feb 28, 2019
1a0fd92
fix comparison of parts; add tests;
Lagovas Feb 28, 2019
35a4755
fix comparison; cleanup after configs check
Lagovas Feb 28, 2019
0a845ee
remove hardcoded test value
Lagovas Feb 28, 2019
925557c
don't suppress output from config generation script
Lagovas Feb 28, 2019
022fc1e
run checks with configured gopath
Lagovas Feb 28, 2019
f2aeaad
ignore version from configs in tests when pass default args
Lagovas Feb 28, 2019
d69bbe8
unify error message for failed parsing parameters
Lagovas Mar 4, 2019
5359067
Merge remote-tracking branch 'origin/master' into lagovas/T1031-servi…
Lagovas Mar 4, 2019
0540ccc
don't check config version if config wasn't used
Lagovas Mar 5, 2019
8589b85
replace versions via pyyaml instead sed
Lagovas Mar 5, 2019
e20dc27
change error message, back removed line from encryptor config
Lagovas Mar 7, 2019
0c5c99b
udpate tests according to updated error messages
Lagovas Mar 7, 2019
e3f4bda
remove overriding status
Lagovas Mar 7, 2019
24800d1
remove unsupported golang version
Lagovas Mar 7, 2019
c021f15
set default goroot
Lagovas Mar 7, 2019
d6e6bb8
use correct golang
Lagovas Mar 7, 2019
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
24 changes: 24 additions & 0 deletions .circleci/check_configs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

function compare_configs() {
folder_a=$1
folder_b=$2
binaries=(server connector translator addzone webconfig rollback keymaker poisonrecordmaker authmanager rotate)
for cmd in "${binaries[@]}"; do
cmp ${folder_a}/acra-${cmd}.yaml ${folder_b}/acra-${cmd}.yaml
cmp_status="$?"
if [[ "${cmp_status}" != "0" ]]; then
status=1
fi
done
}
# use go from GOROOT instead installed in system
PATH=$GOROOT/bin:$PATH
temp_configs=`mktemp -d`
bash configs/regenerate.sh ${temp_configs}

status=0
compare_configs configs ${temp_configs}

rm -rf ${temp_configs}
exit ${status}
90 changes: 60 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
version: 2
jobs:
general_validation:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very good move!!

docker:
- image: cossacklabs/android-build
environment:
FILEPATH_ERROR_FLAG: /tmp/test_fail
VERSIONS: 1.11.5 1.12
TEST_DB_PORT: 5432
GOPATH_FOLDER: gopath
TEST_RANDOM_DATA_FOLDER: /tmp/test_data
TEST_TLS: "on"
# $HOME/$GOPATH_FOLDER
GOPATH: /home/user/gopath
# set default goroot instead system available
GOROOT: /home/user/go_root_1.11.5/go
steps:
# prepare
- checkout
- run: .circleci/prepare.sh
# validation
- run: .circleci/check_gofmt.sh
- run: .circleci/check_configs.sh | tee /home/user/tests_output
- run: .circleci/check_golint.sh
- run: .circleci/check_gotest.sh
# check python wrapper
- run: PYTHONPATH=`pwd`/wrappers/python python3 wrappers/python/acrawriter/tests.py
- store_artifacts:
path: /home/user/tests_output

postgresql-ssl:
docker:
- image: cossacklabs/android-build
Expand All @@ -10,27 +38,22 @@ jobs:
POSTGRES_DB: test
environment:
FILEPATH_ERROR_FLAG: /tmp/test_fail
VERSIONS: 1.10.8 1.11.5 1.12
VERSIONS: 1.11.5 1.12
TEST_DB_PORT: 5432
GOPATH_FOLDER: gopath
TEST_RANDOM_DATA_FOLDER: /tmp/test_data
TEST_TLS: "on"
# $HOME/$GOPATH_FOLDER
GOPATH: /home/user/gopath
# set default goroot instead system available
GOROOT: /home/user/go_root_1.11.5/go
steps:
# prepare
- checkout
- run: .circleci/prepare.sh
- run: sudo apt-get install -y postgresql-client
- run: pg_isready -U${POSTGRES_USER} -d${POSTGRES_DB} -h127.0.0.1
# testing
# check that code formatted with gofmt
- run: .circleci/check_gofmt.sh
# check that code doesn't have a lot of golint issues (currently removed because golint version is very different on other planforms)
- run: GOPATH=$HOME/$GOPATH_FOLDER .circleci/check_golint.sh
# delete file if exists
- run: if [ -f $FILEPATH_ERROR_FLAG ]; then rm "$FILEPATH_ERROR_FLAG"; fi
- run: .circleci/check_gotest.sh
# check python wrapper
- run: PYTHONPATH=`pwd`/wrappers/python python3 wrappers/python/acrawriter/tests.py
# testing
# generate test data for integration tests
- run: python3 tests/generate_random_data.py
# each iteration pass to test different ports for forks to avoid problems with TCP TIME WAIT between tests
Expand All @@ -51,11 +74,15 @@ jobs:
POSTGRES_DB: test
environment:
FILEPATH_ERROR_FLAG: /tmp/test_fail
VERSIONS: 1.10.8 1.11.5 1.12
VERSIONS: 1.11.5 1.12
TEST_DB_PORT: 5432
GOPATH_FOLDER: gopath
TEST_RANDOM_DATA_FOLDER: /tmp/test_data
TEST_TLS: "off"
# $HOME/$GOPATH_FOLDER
GOPATH: /home/user/gopath
# set default goroot instead system available
GOROOT: /home/user/go_root_1.11.5/go
steps:
# prepare
- checkout
Expand Down Expand Up @@ -85,26 +112,23 @@ jobs:
MYSQL_ROOT_PASSWORD: root
environment:
FILEPATH_ERROR_FLAG: /tmp/test_fail
VERSIONS: 1.10.8 1.11.5 1.12
VERSIONS: 1.11.5 1.12
TEST_MYSQL: true
TEST_DB_PORT: 3306
GOPATH_FOLDER: gopath
TEST_RANDOM_DATA_FOLDER: /tmp/test_data
TEST_TLS: "on"
# $HOME/$GOPATH_FOLDER
GOPATH: /home/user/gopath
# set default goroot instead system available
GOROOT: /home/user/go_root_1.11.5/go
steps:
# prepare
- checkout
- run: .circleci/prepare.sh
- run: sudo apt-get install -y mysql-client
- run: mysqladmin ping -h127.0.0.1
# testing
# check that code formatted with gofmt
- run: .circleci/check_gofmt.sh
# check that code doesn't have a lot of golint issues (currently removed because golint version is very different on other planforms)
- run: GOPATH=$HOME/$GOPATH_FOLDER .circleci/check_golint.sh
# delete file if exists
- run: if [ -f $FILEPATH_ERROR_FLAG ]; then rm "$FILEPATH_ERROR_FLAG"; fi
- run: .circleci/check_gotest.sh
# generate test data for integration tests
- run: python3 tests/generate_random_data.py
# each iteration pass to test different ports for forks to avoid problems with TCP TIME WAIT between tests
Expand All @@ -128,12 +152,16 @@ jobs:
MYSQL_ROOT_PASSWORD: root
environment:
FILEPATH_ERROR_FLAG: /tmp/test_fail
VERSIONS: 1.10.8 1.11.5 1.12
VERSIONS: 1.11.5 1.12
TEST_MYSQL: true
TEST_DB_PORT: 3306
GOPATH_FOLDER: gopath
TEST_RANDOM_DATA_FOLDER: /tmp/test_data
TEST_TLS: "off"
# $HOME/$GOPATH_FOLDER
GOPATH: /home/user/gopath
# set default goroot instead system available
GOROOT: /home/user/go_root_1.11.5/go
steps:
# prepare
- checkout
Expand Down Expand Up @@ -164,26 +192,23 @@ jobs:
MYSQL_ROOT_PASSWORD: root
environment:
FILEPATH_ERROR_FLAG: /tmp/test_fail
VERSIONS: 1.10.8 1.11.5 1.12
VERSIONS: 1.11.5 1.12
TEST_MYSQL: true
TEST_DB_PORT: 3306
GOPATH_FOLDER: gopath
TEST_RANDOM_DATA_FOLDER: /tmp/test_data
TEST_TLS: "on"
# $HOME/$GOPATH_FOLDER
GOPATH: /home/user/gopath
# set default goroot instead system available
GOROOT: /home/user/go_root_1.11.5/go
steps:
# prepare
- checkout
- run: .circleci/prepare.sh
- run: sudo apt-get install -y mysql-client
- run: mysqladmin ping -h127.0.0.1
# testing
# check that code formatted with gofmt
- run: .circleci/check_gofmt.sh
# check that code doesn't have a lot of golint issues (currently removed because golint version is very different on other planforms)
- run: GOPATH=$HOME/$GOPATH_FOLDER .circleci/check_golint.sh
# delete file if exists
- run: if [ -f $FILEPATH_ERROR_FLAG ]; then rm "$FILEPATH_ERROR_FLAG"; fi
- run: .circleci/check_gotest.sh
# generate test data for integration tests
- run: python3 tests/generate_random_data.py
# each iteration pass to test different ports for forks to avoid problems with TCP TIME WAIT between tests
Expand All @@ -205,12 +230,16 @@ jobs:
MYSQL_ROOT_PASSWORD: root
environment:
FILEPATH_ERROR_FLAG: /tmp/test_fail
VERSIONS: 1.10.8 1.11.5 1.12
VERSIONS: 1.11.5 1.12
TEST_MYSQL: true
TEST_DB_PORT: 3306
GOPATH_FOLDER: gopath
TEST_RANDOM_DATA_FOLDER: /tmp/test_data
TEST_TLS: "off"
# $HOME/$GOPATH_FOLDER
GOPATH: /home/user/gopath
# set default goroot instead system available
GOROOT: /home/user/go_root_1.11.5/go
steps:
# prepare
- checkout
Expand All @@ -232,6 +261,7 @@ workflows:
version: 2
tests:
jobs:
- general_validation
- postgresql
- postgresql-ssl
- mysql
Expand Down
1 change: 0 additions & 1 deletion .circleci/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ for version in $VERSIONS; do
timeout ${TEST_RUN_TIMEOUT} python3 tests/test.py -v | tee "${LOG_OUTPUT}";
status="$?"
if [[ "${status}" != "0" ]]; then
status="$?"
echo "${context}. status=${status}" >> "$FILEPATH_ERROR_FLAG";
continue
else
Expand Down
3 changes: 2 additions & 1 deletion cmd/acra-addzone/acra-addzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func main() {

err := cmd.Parse(defaultConfigPath, serviceName)
if err != nil {
log.WithError(err).Errorln("Can't parse args")
log.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCantReadServiceConfig).
Errorln("Can't parse args")
os.Exit(1)
}
//LoadFromConfig(defaultConfigPath)
Expand Down
3 changes: 2 additions & 1 deletion cmd/acra-authmanager/acra_authmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ func main() {
debug := flag.Bool("d", false, "Turn on debug logging")

if err := cmd.Parse(defaultConfigPath, serviceName); err != nil {
log.WithError(err).Errorln("Can't parse cmd arguments")
log.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCantReadServiceConfig).
Errorln("Can't parse cmd args")
os.Exit(1)
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/acra-keymaker/acra-keymaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func main() {

err := cmd.Parse(defaultConfigPath, serviceName)
if err != nil {
log.WithError(err).Errorln("Can't parse args")
log.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCantReadServiceConfig).
Errorln("Can't parse args")
os.Exit(1)
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/acra-poisonrecordmaker/acra-poisonrecordmaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func main() {

err := cmd.Parse(defaultConfigPath, serviceName)
if err != nil {
log.WithError(err).Errorln("can't parse args")
log.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCantReadServiceConfig).
Errorln("can't parse args")
os.Exit(1)
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/acra-rollback/acra-rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ func main() {

err := cmd.Parse(defaultConfigPath, serviceName)
if err != nil {
log.WithError(err).Errorln("Can't parse args")
log.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCantReadServiceConfig).
Errorln("Can't parse args")
os.Exit(1)
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/acra-rotate/acra-rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func main() {

err := cmd.Parse(DefaultConfigPath, ServiceName)
if err != nil {
log.WithError(err).Errorln("Can't parse args")
log.WithError(err).WithField(logging.FieldKeyEventCode, logging.EventCodeErrorCantReadServiceConfig).
Errorln("Can't parse args")
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/acra-server/acra-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func main() {
log.WithField(logging.FieldKeyEventCode, logging.EventCodeErrorWrongConfiguration).
Errorln("db_host is empty: you must specify db_host")
flag.Usage()
return
os.Exit(1)
}
config.setDBConnectionSettings(*dbHost, *dbPort)

Expand Down
39 changes: 38 additions & 1 deletion cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package cmd

import (
"errors"
flag_ "flag"
"fmt"
"github.com/cossacklabs/acra/logging"
Expand Down Expand Up @@ -175,6 +176,10 @@ func PrintDefaults() {

// GenerateYaml generates YAML file from CLI params
func GenerateYaml(output io.Writer, useDefault bool) {
// write version as first line in yaml format
if _, err := fmt.Fprintf(output, "version: %s\n", utils.VERSION); err != nil {
panic(err)
}
flag_.CommandLine.VisitAll(func(flag *flag_.Flag) {
var s string
if useDefault {
Expand Down Expand Up @@ -245,6 +250,35 @@ func DumpConfig(configPath, serviceName string, useDefault bool) error {
return nil
}

func checkVersion(config map[string]interface{}) error {
if config == nil {
return nil
}
configVersion, ok := config["version"]
if !ok {
return errors.New("config hasn't version key")
}
versionValue, ok := configVersion.(string)
if !ok {
return errors.New("value of version is not string")
}

version, err := utils.ParseVersion(versionValue)
if err != nil {
return err
}

serverVersion, err := utils.GetParsedVersion()
if err != nil {
return err
}

if serverVersion.CompareOnly(utils.MajorFlag|utils.MinorFlag, version) != utils.Equal {
return fmt.Errorf("config version \"%s\" is not supported, expects \"%s\" version", version.String(), serverVersion.String())
}
return nil
}

// Parse loads CLI params from yaml config and cli
func Parse(configPath, serviceName string) error {
/*load from yaml config and cli. if dumpconfig option pass than generate config and exit*/
Expand All @@ -258,6 +292,7 @@ func Parse(configPath, serviceName string) error {
if *config != "" {
configPath = *config
}
var yamlConfig map[string]interface{}
var args []string
// parse yaml and add params that wasn't passed from cli
if configPath != "" {
Expand All @@ -275,7 +310,6 @@ func Parse(configPath, serviceName string) error {
if err != nil {
return err
}
yamlConfig := map[string]interface{}{}
err = yaml.Unmarshal([]byte(data), &yamlConfig)
if err != nil {
return err
Expand Down Expand Up @@ -307,6 +341,9 @@ func Parse(configPath, serviceName string) error {
DumpConfig(configPath, serviceName, true)
os.Exit(0)
}
if err = checkVersion(yamlConfig); err != nil {
return err
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions configs/acra-addzone.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 0.84.2
# path to config
config_file:

Expand Down
1 change: 1 addition & 0 deletions configs/acra-authmanager.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 0.84.2
# path to config
config_file:

Expand Down
1 change: 1 addition & 0 deletions configs/acra-connector.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 0.84.2
# Port of Acra HTTP API
acraserver_api_connection_port: 9090

Expand Down
1 change: 1 addition & 0 deletions configs/acra-keymaker.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 0.84.2
# Client ID
client_id: client

Expand Down
Loading