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

Feature dependencies upgrade #162

Merged
merged 17 commits into from
Dec 4, 2019
Merged
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
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ jobs:
name: Wait for Migrations
command: |
bin/dc exec engine-rpc /wait-for-it.sh localhost:2000 -t 120
bin/dc exec profiles-django /wait-for-it.sh localhost:8000 -t 120
bin/dc exec transmission-django /wait-for-it.sh localhost:8000 -t 120
- run:
name: Load profiles fixtures
command: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Base image with python and entrypoint scripts ##
## ============================================= ##
FROM python:3.6.8-alpine3.10 AS base
FROM python:3.6.9-alpine3.9 AS base
ajhodges marked this conversation as resolved.
Show resolved Hide resolved

LABEL maintainer="Adam Hodges <[email protected]>"

Expand Down
38 changes: 28 additions & 10 deletions apps/shipments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,19 @@ class ShipmentSerializer(EnumSupportSerializerMixin, serializers.ModelSerializer
Serializer for a shipment object
"""
load_data = LoadShipmentSerializer(source='loadshipment', required=False)
ship_from_location = LocationSerializer(required=False)
ship_to_location = LocationSerializer(required=False)
bill_to_location = LocationSerializer(required=False)
final_destination_location = LocationSerializer(required=False)
device = DeviceSerializer(required=False)

state = UpperEnumField(TransitState, lenient=True, ints_as_names=True, required=False, read_only=True)
exception = UpperEnumField(ExceptionType, lenient=True, ints_as_names=True, required=False)

included_serializers = {
'ship_from_location': LocationSerializer,
'ship_to_location': LocationSerializer,
'bill_to_location': LocationSerializer,
'final_destination_location': LocationSerializer,
'load_data': LoadShipmentSerializer,
'device': DeviceSerializer
}

class Meta:
model = Shipment
exclude = ('version', 'background_data_hash_interval', 'manual_update_hash_interval')
Expand All @@ -121,6 +125,11 @@ class JSONAPIMeta:

class ShipmentCreateSerializer(ShipmentSerializer):
device_id = serializers.CharField(max_length=36, required=False)
ship_from_location = LocationSerializer(required=False)
ship_to_location = LocationSerializer(required=False)
bill_to_location = LocationSerializer(required=False)
final_destination_location = LocationSerializer(required=False)
device = DeviceSerializer(required=False)

def create(self, validated_data):
extra_args = {}
Expand Down Expand Up @@ -176,6 +185,11 @@ def validate_storage_credentials_id(self, storage_credentials_id):

class ShipmentUpdateSerializer(ShipmentSerializer):
device_id = serializers.CharField(max_length=36, allow_null=True)
ship_from_location = LocationSerializer(required=False)
ship_to_location = LocationSerializer(required=False)
bill_to_location = LocationSerializer(required=False)
final_destination_location = LocationSerializer(required=False)
device = DeviceSerializer(required=False)

class Meta:
model = Shipment
Expand Down Expand Up @@ -280,15 +294,19 @@ class ShipmentTxSerializer(serializers.ModelSerializer):
async_job_id = serializers.CharField(max_length=36)

load_data = LoadShipmentSerializer(source='loadshipment', required=False)
ship_from_location = LocationSerializer(required=False)
ship_to_location = LocationSerializer(required=False)
bill_to_location = LocationSerializer(required=False)
final_destination_location = LocationSerializer(required=False)
device = DeviceSerializer(required=False)

state = UpperEnumField(TransitState, ints_as_names=True)
exception = UpperEnumField(ExceptionType, ints_as_names=True)

included_serializers = {
'ship_from_location': LocationSerializer,
'ship_to_location': LocationSerializer,
'bill_to_location': LocationSerializer,
'final_destination_location': LocationSerializer,
'load_data': LoadShipmentSerializer,
'device': DeviceSerializer
}

class Meta:
model = Shipment
exclude = ('version', 'background_data_hash_interval', 'manual_update_hash_interval')
Expand Down
4 changes: 4 additions & 0 deletions bin/integration_tests
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ bin/dc build

bin/dc up -d

bin/dc exec profiles-django /wait-for-it.sh localhost:8000 -t 120

bin/dc exec transmission-django /wait-for-it.sh localhost:8000 -t 120

bin/dc exec engine-rpc /wait-for-it.sh localhost:2000 -t 120

bin/dc exec profiles-django python manage.py loaddata oidc_clients.json new_users.json
Expand Down
175 changes: 67 additions & 108 deletions compose/django/wait-for-it.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available

WAITFORIT_cmdname=${0##*/}
cmdname=$(basename $0)

echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
cat << USAGE >&2
Usage:
$WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
Expand All @@ -24,133 +24,101 @@ USAGE

wait_for()
{
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
WAITFORIT_start_ts=$(date +%s)
start_ts=$(date +%s)
while :
do
if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
WAITFORIT_result=$?
if [[ $ISBUSY -eq 1 ]]; then
nc -z $HOST $PORT
result=$?
else
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
WAITFORIT_result=$?
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
fi
if [[ $WAITFORIT_result -eq 0 ]]; then
WAITFORIT_end_ts=$(date +%s)
echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $WAITFORIT_result
return $result
}

wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
if [[ $QUIET -eq 1 ]]; then
timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
WAITFORIT_PID=$!
trap "kill -INT -$WAITFORIT_PID" INT
wait $WAITFORIT_PID
WAITFORIT_RESULT=$?
if [[ $WAITFORIT_RESULT -ne 0 ]]; then
echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $WAITFORIT_RESULT
}

# taken from: https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash/4025065#4025065
version_comparison () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
return $RESULT
}

# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
WAITFORIT_hostport=(${1//:/ })
WAITFORIT_HOST=${WAITFORIT_hostport[0]}
WAITFORIT_PORT=${WAITFORIT_hostport[1]}
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
WAITFORIT_CHILD=1
CHILD=1
shift 1
;;
-q | --quiet)
WAITFORIT_QUIET=1
QUIET=1
shift 1
;;
-s | --strict)
WAITFORIT_STRICT=1
STRICT=1
shift 1
;;
-h)
WAITFORIT_HOST="$2"
if [[ $WAITFORIT_HOST == "" ]]; then break; fi
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
WAITFORIT_HOST="${1#*=}"
HOST="${1#*=}"
shift 1
;;
-p)
WAITFORIT_PORT="$2"
if [[ $WAITFORIT_PORT == "" ]]; then break; fi
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
WAITFORIT_PORT="${1#*=}"
PORT="${1#*=}"
shift 1
;;
-t)
WAITFORIT_TIMEOUT="$2"
if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
WAITFORIT_TIMEOUT="${1#*=}"
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
WAITFORIT_CLI=("$@")
CLI=("$@")
break
;;
--help)
Expand All @@ -163,56 +131,47 @@ do
esac
done

if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi

WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}

# check to see if timeout is from busybox?
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
WAITFORIT_ISBUSY=1

WAITFORIT_BUSYVERSION=$(busybox | head -1 | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')
version_comparison $WAITFORIT_BUSYVERSION "1.29"

if [ "$?" = "1" ]; then
WAITFORIT_BUSYTIMEFLAG=""
else
WAITFORIT_BUSYTIMEFLAG="-t"
fi

# check to see if timeout is from busybox?
TIMEOUT_PATH=$(realpath $(which timeout))
if [[ $TIMEOUT_PATH =~ "busybox" ]]; then
ISBUSY=1
BUSYTIMEFLAG="-t"
else
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
ISBUSY=0
BUSYTIMEFLAG=""
fi

if [[ $WAITFORIT_CHILD -gt 0 ]]; then
if [[ $CHILD -gt 0 ]]; then
wait_for
WAITFORIT_RESULT=$?
exit $WAITFORIT_RESULT
RESULT=$?
exit $RESULT
else
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
WAITFORIT_RESULT=$?
RESULT=$?
else
wait_for
WAITFORIT_RESULT=$?
RESULT=$?
fi
fi

if [[ $WAITFORIT_CLI != "" ]]; then
if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
exit $WAITFORIT_RESULT
if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec "${WAITFORIT_CLI[@]}"
exec "${CLI[@]}"
else
exit $WAITFORIT_RESULT
fi
exit $RESULT
fi
2 changes: 1 addition & 1 deletion conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
'PAGE_SIZE': 10,
'EXCEPTION_HANDLER': 'shipchain_common.exceptions.exception_handler',
'DEFAULT_PAGINATION_CLASS':
'rest_framework_json_api.pagination.PageNumberPagination',
'shipchain_common.pagination.JsonApiPagePagination',
'DEFAULT_PARSER_CLASSES': (
'rest_framework_json_api.parsers.JSONParser',
'rest_framework.parsers.JSONParser',
Expand Down
Loading