Skip to content

Commit

Permalink
enable python integration tests. (#1024)
Browse files Browse the repository at this point in the history
* improve cli functionality, list account by id, export to named file, list address by index, parsable list balance for accounts.
* use host network for devcontainer
* improve startup scripts for sync jobs, charts for same namespace deployment
* reduce amount sent in tests
* create helpers and add python integration tests into workflow
* use network_status calls and use "all" instead of manually calculating fees
  • Loading branch information
jgreat authored Dec 5, 2024
1 parent e4d8762 commit f3ea165
Show file tree
Hide file tree
Showing 15 changed files with 629 additions and 90 deletions.
9 changes: 5 additions & 4 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"image": "mobilecoin/fat-devcontainer:v0.0.38",
"forwardPorts": [
9090
"runArgs": [
"--network=host"
],
"capAdd": ["SYS_PTRACE"],
"containerEnv": {
"MC_CHAIN_ID": "local",
"RUST_BACKTRACE": "1",
"SGX_MODE": "SW"
"SGX_MODE": "HW"
},
"remoteUser": "sentz",
"postCreateCommand": "/usr/local/bin/startup-devcontainer.sh",
Expand All @@ -21,7 +21,8 @@
"rust-lang.rust-analyzer",
"timonwong.shellcheck",
"be5invis.toml",
"redhat.vscode-yaml"
"redhat.vscode-yaml",
"ms-python.python"
]
}
}
Expand Down
114 changes: 114 additions & 0 deletions .github/actions/test-python-integration/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Test - Python Integration
description: Set up environment and run integration tests

inputs:
network:
description: "main|test"
required: true
cache_buster:
description: "cache buster"
required: true
version:
description: "Version of the full-service to test"
required: true
rancher_cluster:
description: "Rancher cluster to deploy to"
required: true
rancher_url:
description: "Rancher URL"
required: true
rancher_token:
description: "Rancher token"
required: true

runs:
using: composite
steps:
- name: Install pip
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y python3-pip
# Deploy fs chart with cloned volume
# All tests will need to be deployed in the full-service-ledger namespace so we can clone the target PVC
- name: Generate full-service values file
shell: bash
run: |
mkdir -p .mob/
cat <<EOF > .mob/${{ inputs.network }}.values.yaml
fullService:
persistence:
enabled: true
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 128Gi
dataSource:
name: full-service-ledger-${{ inputs.network }}net
kind: PersistentVolumeClaim
EOF
- name: Deploy Full-Service
uses: mobilecoinofficial/gha-k8s-toolbox@v1
with:
action: helm-deploy
chart_repo: https://harbor.mobilecoin.com/chartrepo/mobilecoinofficial-public
chart_name: full-service
chart_version: ${{ inputs.version }}-${{ inputs.network }}net
chart_values: .mob/${{ inputs.network }}.values.yaml
chart_wait_timeout: 30m
release_name: ${{ inputs.version }}-${{ inputs.network }}net
namespace: full-service-ledger
rancher_cluster: ${{ inputs.rancher_cluster }}
rancher_url: ${{ inputs.rancher_url }}
rancher_token: ${{ inputs.rancher_token }}

- name: Get IP address of full-service
uses: mobilecoinofficial/gha-k8s-toolbox@v1
with:
action: kubectl-exec
rancher_cluster: ${{ inputs.rancher_cluster }}
rancher_url: ${{ inputs.rancher_url }}
rancher_token: ${{ inputs.rancher_token }}
command: |
target_ip=$(kubectl -n full-service-ledger get svc ${{ inputs.version }}-${{ inputs.network }}net-full-service -o jsonpath='{.spec.clusterIP}')
funding_ip=$(kubectl -n dev-wallet-${{ inputs.network }}net get svc full-service -o jsonpath='{.spec.clusterIP}')
echo "TARGET_IP=${target_ip}" >> "${GITHUB_ENV}"
echo "FUNDING_IP=${funding_ip}" >> "${GITHUB_ENV}"
- name: Run Integration Tests
env:
FUNDING_FS_URL: http://${{ env.FUNDING_IP }}:9090/wallet/v2
TARGET_FS_URL: http://${{ env.TARGET_IP }}:9090/wallet/v2
shell: bash
run: |
set -e
# Wait for the full-service to be ready
.internal-ci/util/wait-for-full-service.sh
# Run integration tests
./tools/test-python-integration.sh ${{ inputs.network }}
- name: Cleanup helm chart
uses: mobilecoinofficial/gha-k8s-toolbox@v1
with:
action: helm-release-delete
release_name: ${{ inputs.version }}-${{ inputs.network }}net
namespace: full-service-ledger
rancher_cluster: ${{ inputs.rancher_cluster }}
rancher_url: ${{ inputs.rancher_url }}
rancher_token: ${{ inputs.rancher_token }}

- name: Cleanup PVC
uses: mobilecoinofficial/gha-k8s-toolbox@v1
with:
action: pvc-delete
namespace: full-service-ledger
object_name: data-${{ inputs.version }}-${{ inputs.network }}net-full-service-0
rancher_cluster: ${{ inputs.rancher_cluster }}
rancher_url: ${{ inputs.rancher_url }}
rancher_token: ${{ inputs.rancher_token }}
29 changes: 29 additions & 0 deletions .github/workflows/on-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ jobs:
- meta
- build-rust-linux
strategy:
fail-fast: false
matrix:
runner:
- mco-dev-small-x64
Expand All @@ -248,6 +249,7 @@ jobs:
- meta
- build-containers
strategy:
fail-fast: false
matrix:
network:
- main
Expand All @@ -270,6 +272,7 @@ jobs:
- meta
- publish-containers
strategy:
fail-fast: false
matrix:
network:
- main
Expand All @@ -286,6 +289,31 @@ jobs:
repo_username: ${{ secrets.HARBOR_USERNAME }}
repo_password: ${{ secrets.HARBOR_PASSWORD }}

test-python-integration:
needs:
- meta
- build-publish-charts
strategy:
fail-fast: false
matrix:
network:
- main
- test
runs-on: mco-dev-small-x64
steps:
- name: Checkout
uses: mobilecoinofficial/gh-actions/checkout@v0

- name: Run Python Integration Tests
uses: ./.github/actions/test-python-integration
with:
version: ${{ needs.meta.outputs.version }}
network: ${{ matrix.network }}
cache_buster: ${{ vars.CACHE_BUSTER }}
rancher_cluster: ${{ secrets.DEV_RANCHER_CLUSTER }}
rancher_url: ${{ secrets.DEV_RANCHER_URL }}
rancher_token: ${{ secrets.DEV_RANCHER_TOKEN }}

checks-successful:
needs:
- lint-actions
Expand All @@ -296,6 +324,7 @@ jobs:
- test-rust
- build-rust-macos
- build-publish-charts
- test-python-integration
runs-on: mco-dev-small-x64
steps:
- name: Success
Expand Down
3 changes: 2 additions & 1 deletion .internal-ci/docker/Dockerfile.full-service
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN addgroup --system --gid 1000 app \

RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y ca-certificates curl libdbus-1-3 libusb-1.0-0 \
&& apt-get install -y jq ca-certificates curl libdbus-1-3 libusb-1.0-0 \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/* \
&& mkdir -p /usr/share/grpc \
Expand All @@ -33,6 +33,7 @@ COPY ${RUST_BIN_PATH}/wallet-service-mirror-public /usr/local/bin/
COPY ${RUST_BIN_PATH}/generate-rsa-keypair /usr/local/bin/
COPY ${RUST_BIN_PATH}/ingest-enclave.css /usr/local/bin/
COPY .internal-ci/docker/entrypoints/full-service.sh /usr/local/bin/entrypoint.sh
COPY .internal-ci/util/wait-for-full-service.sh /usr/local/bin/wait-for-full-service.sh
# not implemented yet
# COPY .internal-ci/docker/support/full-service/initialize-wallets.sh /usr/local/bin/initialize-wallets.sh

Expand Down
9 changes: 9 additions & 0 deletions .internal-ci/docker/entrypoints/full-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ then
fi
fi

# Run until we have a valid ledger database then quit.
if [[ -n "${SYNC_LEDGER_ONLY}" ]]
then
echo "SYNC_LEDGER_ONLY set. Exiting after syncing ledger."
RUST_LOG=error /usr/local/bin/full-service &
/usr/local/bin/wait-for-full-service.sh
exit 0
fi

# Check to see if leading argument starts with "--".
# If so execute with full-service for compatibility with the previous container/cli arg only configuration.
if [[ "${1}" =~ ^--.* ]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: Service
metadata:
name: full-service
name: {{ include "fullService.fullname" . }}
labels:
{{- include "fullService.labels" . | nindent 4 }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "fullService.fullname" . }}-full-service
name: {{ include "fullService.fullname" . }}
labels:
{{- include "fullService.labels" . | nindent 4 }}
spec:
Expand All @@ -11,7 +11,7 @@ spec:
matchLabels:
app: full-service
{{- include "fullService.selectorLabels" . | nindent 6 }}
serviceName: {{ include "fullService.fullname" . }}-full-service
serviceName: {{ include "fullService.fullname" . }}
template:
metadata:
annotations:
Expand Down
36 changes: 25 additions & 11 deletions .internal-ci/util/wait-for-full-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,42 @@ set -e
set -o pipefail


echo "Checking block height - wait for full-service to start"
sleep 15
echo "-- Checking block height - wait for full-service to start"

TARGET_FS_URL=${TARGET_FS_URL:-"http://localhost:9090/wallet/v2"}

curl_post()
{
curl --connect-timeout 2 -sSL -X POST -H 'Content-type: application/json' http://localhost:9090/wallet/v2 --data '{"method": "get_wallet_status", "jsonrpc": "2.0", "id": 1}' 2>/dev/null
curl --connect-timeout 2 -sSfL -X POST -H 'Content-type: application/json' "${TARGET_FS_URL}" --data '{"method": "get_network_status", "jsonrpc": "2.0", "id": 1}' 2>/dev/null
}

count=0
while ! curl_post
do
echo "-- Waiting for full-service to respond"
count=$((count + 1))
if [[ "${count}" -gt 300 ]]
then
echo "Full-service did not start"
exit 1
fi
sleep 2
done

# wait for blocks
wallet_json=$(curl_post)
network_block_height=$(echo "${wallet_json}" | jq -r .result.wallet_status.network_block_height)
local_block_height=$(echo "${wallet_json}" | jq -r .result.wallet_status.local_block_height)
network_json=$(curl_post)
network_block_height=$(echo "${network_json}" | jq -r .result.network_status.network_block_height)
local_block_height=$(echo "${network_json}" | jq -r .result.network_status.local_block_height)

while [[ "${local_block_height}" != "${network_block_height}" ]]
do
echo "- Waiting for blocks to download ${local_block_height} of ${network_block_height}"
echo "-- Waiting for blocks to download ${local_block_height} of ${network_block_height}"

wallet_json=$(curl_post)
network_block_height=$(echo "${wallet_json}" | jq -r .result.wallet_status.network_block_height)
local_block_height=$(echo "${wallet_json}" | jq -r .result.wallet_status.local_block_height)
network_json=$(curl_post)
network_block_height=$(echo "${network_json}" | jq -r .result.network_status.network_block_height)
local_block_height=$(echo "${network_json}" | jq -r .result.network_status.local_block_height)

sleep 10
done

echo "full-service sync is done"
echo "-- full-service sync is done"
Loading

0 comments on commit f3ea165

Please sign in to comment.