Skip to content

Commit

Permalink
ci: support azurtize on pytest and e2e
Browse files Browse the repository at this point in the history
longhorn/longhorn-9699

Signed-off-by: Chris <[email protected]>
  • Loading branch information
chriscchien committed Nov 6, 2024
1 parent 88cd8b8 commit 19842e9
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 42 deletions.
7 changes: 5 additions & 2 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/master/scripts/en

### Run the test

1. Deploy all backupstore servers (including `NFS` server and `Minio` as s3 server) for test purposes.
1. Deploy all backupstore servers (including `NFS` server and `Minio` as s3 server, `CIFS` and `Azurite` server) for test purposes.

For Azurite, there are some manual steps need to be done after manifest deployed(https://confluence.suse.com/display/LON/Setup+Azurite+Backupstore+For+Testing).
```
kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/minio-backupstore.yaml \
-f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/nfs-backupstore.yaml \
-f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml
-f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml \
-f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/azurite-backupstore.yaml
```

1. Expose Longhorn API:
Expand Down
7 changes: 5 additions & 2 deletions manager/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ Requirement:
6. Make sure `nfs-common` or equivalent has been installed on the node to allow the NFS client to work.

Run the test:
1. Deploy all backupstore servers(including `NFS` server and `Minio` as s3 server) for test purposes.
1. Deploy all backupstore servers(including `NFS` server and `Minio` as s3 server `CIFS` and `Azurite` server) for test purposes.

For Azurite, there are some manual steps need to be done after manifest deployed(https://confluence.suse.com/display/LON/Setup+Azurite+Backupstore+For+Testing).
```
kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/minio-backupstore.yaml \
-f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/nfs-backupstore.yaml \
-f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml
-f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml \
-f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/azurite-backupstore.yaml
```
2. Deploy the test script to the Kubernetes cluster.
```
Expand Down
2 changes: 1 addition & 1 deletion manager/integration/deploy/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
- name: LONGHORN_JUNIT_REPORT_PATH
value: /tmp/test-report/longhorn-test-junit-report.xml
- name: LONGHORN_BACKUPSTORES
value: "s3://backupbucket@us-east-1/backupstore$minio-secret, nfs://longhorn-test-nfs-svc.default:/opt/backupstore, cifs://longhorn-test-cifs-svc.default/backupstore$cifs-secret"
value: "s3://backupbucket@us-east-1/backupstore$minio-secret, nfs://longhorn-test-nfs-svc.default:/opt/backupstore, cifs://longhorn-test-cifs-svc.default/backupstore$cifs-secret, azblob://[email protected]/$azblob-secret"
- name: LONGHORN_BACKUPSTORE_POLL_INTERVAL
value: "30"
- name: LONGHORN_DISK_TYPE
Expand Down
48 changes: 37 additions & 11 deletions manager/integration/tests/backupstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from common import is_backupTarget_s3
from common import is_backupTarget_nfs
from common import is_backupTarget_cifs
from common import is_backupTarget_azurite
from common import get_longhorn_api_client
from common import delete_backup_volume
from common import delete_backup_backing_image
Expand Down Expand Up @@ -67,6 +68,8 @@ def set_random_backupstore(request, client):
mount_nfs_backupstore(client)
elif request.param == "cifs":
set_backupstore_cifs(client)
elif request.param == "azblob":
set_backupstore_azurite(client)

yield
cleanup_all_volumes(client)
Expand Down Expand Up @@ -131,6 +134,18 @@ def set_backupstore_cifs(client):
break


def set_backupstore_azurite(client):
backupstores = get_backupstore_url()
poll_interval = get_backupstore_poll_interval()
for backupstore in backupstores:
if is_backupTarget_azurite(backupstore):
backupsettings = backupstore.split("$")
set_backupstore_url(client, backupsettings[0])
set_backupstore_credential_secret(client, backupsettings[1])
set_backupstore_poll_interval(client, poll_interval)
break


def set_backupstore_url(client, url):
backup_target_setting = client.by_id_setting(SETTING_BACKUP_TARGET)
backup_target_setting = client.update(backup_target_setting,
Expand Down Expand Up @@ -289,7 +304,8 @@ def backupstore_get_backup_volume_prefix(client, volume_name):
return nfs_get_backup_volume_prefix(client, volume_name)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def minio_get_backup_volume_prefix(volume_name):
Expand Down Expand Up @@ -326,7 +342,8 @@ def backupstore_get_backup_cfg_file_path(client, volume_name, backup_name):
return nfs_get_backup_cfg_file_path(client, volume_name, backup_name)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def minio_get_backup_cfg_file_path(volume_name, backup_name):
Expand All @@ -349,7 +366,8 @@ def backupstore_get_volume_cfg_file_path(client, volume_name):
return nfs_get_volume_cfg_file_path(client, volume_name)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def nfs_get_volume_cfg_file_path(client, volume_name):
Expand All @@ -372,7 +390,8 @@ def backupstore_get_backup_blocks_dir(client, volume_name):
return nfs_get_backup_blocks_dir(client, volume_name)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def minio_get_backup_blocks_dir(volume_name):
Expand All @@ -398,7 +417,8 @@ def backupstore_create_file(client, core_api, file_path, data={}):
return nfs_create_file_in_backupstore(file_path, data={})

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def mino_create_file_in_backupstore(client, core_api, file_path, data={}): # NOQA
Expand Down Expand Up @@ -448,7 +468,8 @@ def backupstore_write_backup_cfg_file(client, core_api, volume_name, backup_name
data)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def nfs_write_backup_cfg_file(client, volume_name, backup_name, data):
Expand Down Expand Up @@ -496,7 +517,8 @@ def backupstore_delete_file(client, core_api, file_path):
return nfs_delete_file_in_backupstore(file_path)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def mino_delete_file_in_backupstore(client, core_api, file_path):
Expand Down Expand Up @@ -536,7 +558,8 @@ def backupstore_delete_backup_cfg_file(client, core_api, volume_name, backup_nam
nfs_delete_backup_cfg_file(client, volume_name, backup_name)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def nfs_delete_backup_cfg_file(client, volume_name, backup_name):
Expand Down Expand Up @@ -578,7 +601,8 @@ def backupstore_delete_volume_cfg_file(client, core_api, volume_name): # NOQA
nfs_delete_volume_cfg_file(client, volume_name)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def nfs_delete_volume_cfg_file(client, volume_name):
Expand Down Expand Up @@ -647,7 +671,8 @@ def backupstore_delete_random_backup_block(client, core_api, volume_name):
nfs_delete_random_backup_block(client, volume_name)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def nfs_delete_random_backup_block(client, volume_name):
Expand Down Expand Up @@ -696,7 +721,8 @@ def backupstore_count_backup_block_files(client, core_api, volume_name):
return nfs_count_backup_block_files(client, volume_name)

else:
raise NotImplementedError
pytest.skip("Skip test case because the backup store type \
is not supported")


def nfs_count_backup_block_files(client, volume_name):
Expand Down
4 changes: 4 additions & 0 deletions manager/integration/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3899,6 +3899,10 @@ def is_backupTarget_cifs(s):
return s.startswith("cifs://")


def is_backupTarget_azurite(s):
return s.startswith("azblob://")


def wait_for_backup_volume(client, vol_name, backing_image=""):
for _ in range(RETRY_BACKUP_COUNTS):
bv = client.by_id_backupVolume(vol_name)
Expand Down
10 changes: 1 addition & 9 deletions pipelines/gke/scripts/longhorn-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ create_longhorn_namespace(){
install_backupstores(){
MINIO_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/minio-backupstore.yaml"
NFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/nfs-backupstore.yaml"
CIFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml"
kubectl create -f ${MINIO_BACKUPSTORE_URL} \
-f ${NFS_BACKUPSTORE_URL} \
-f ${CIFS_BACKUPSTORE_URL}
-f ${NFS_BACKUPSTORE_URL}
}


Expand Down Expand Up @@ -180,9 +178,6 @@ run_longhorn_upgrade_test(){
elif [[ $BACKUP_STORE_TYPE = "nfs" ]]; then
BACKUP_STORE_FOR_TEST=`yq e 'select(.spec.containers[0] != null).spec.containers[0].env[1].value' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH} | awk -F ',' '{print $2}' | sed 's/ *//'`
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${BACKUP_STORE_FOR_TEST}'"' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH}
elif [[ $BACKUP_STORE_TYPE = "cifs" ]]; then
BACKUP_STORE_FOR_TEST=`yq e 'select(.spec.containers[0] != null).spec.containers[0].env[1].value' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH} | awk -F ',' '{print $3}' | sed 's/ *//'`
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${BACKUP_STORE_FOR_TEST}'"' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH}
fi

yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[4].value="'${LONGHORN_UPGRADE_TYPE}'"' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH}
Expand Down Expand Up @@ -231,9 +226,6 @@ run_longhorn_tests(){
elif [[ $BACKUP_STORE_TYPE = "nfs" ]]; then
BACKUP_STORE_FOR_TEST=`yq e 'select(.spec.containers[0] != null).spec.containers[0].env[1].value' ${LONGHORN_TESTS_MANIFEST_FILE_PATH} | awk -F ',' '{print $2}' | sed 's/ *//'`
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${BACKUP_STORE_FOR_TEST}'"' ${LONGHORN_TESTS_MANIFEST_FILE_PATH}
elif [[ $BACKUP_STORE_TYPE = "cifs" ]]; then
BACKUP_STORE_FOR_TEST=`yq e 'select(.spec.containers[0] != null).spec.containers[0].env[1].value' ${LONGHORN_TESTS_MANIFEST_FILE_PATH} | awk -F ',' '{print $3}' | sed 's/ *//'`
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${BACKUP_STORE_FOR_TEST}'"' ${LONGHORN_TESTS_MANIFEST_FILE_PATH}
fi

# set MANAGED_K8S_CLUSTER to true
Expand Down
29 changes: 28 additions & 1 deletion pipelines/utilities/install_backupstores.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,34 @@ install_backupstores(){
MINIO_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/minio-backupstore.yaml"
NFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/nfs-backupstore.yaml"
CIFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml"
AZURITE_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/azurite-backupstore.yaml"
kubectl create -f ${MINIO_BACKUPSTORE_URL} \
-f ${NFS_BACKUPSTORE_URL} \
-f ${CIFS_BACKUPSTORE_URL}
-f ${CIFS_BACKUPSTORE_URL} \
-f ${AZURITE_BACKUPSTORE_URL}
setup_azuitize_backup_store
}

setup_azuitize_backup_store(){
RETRY=0
MAX_RETRY=60
until (kubectl get pods | grep 'longhorn-test-azblob' | grep 'Running'); do
echo 'Waiting azurite pod running'
sleep 5
if [ $RETRY -eq $MAX_RETRY ]; then
break
fi
RETRY=$((RETRY+1))
done

AZBLOB_ENDPOINT=$(echo -n "http://$(kubectl get svc azblob-service -o jsonpath='{.spec.clusterIP}'):10000/" | base64)
kubectl -n longhorn-system patch secret azblob-secret \
--type=json \
-p="[{'op': 'replace', 'path': '/data/AZBLOB_ENDPOINT', 'value': \"${AZBLOB_ENDPOINT}\"}]"

CONTROL_PLANE_PUBLIC_IP=$(cat /tmp/controlplane_public_ip)
CONTROL_PLANE_PRIVATE_IP=$(kubectl get nodes -o wide | awk '/control-plane/ {print $6}')
# port forward and az container create need to be run on control node
ssh ec2-user@${CONTROL_PLANE_PUBLIC_IP} "nohup kubectl port-forward --address 0.0.0.0 service/azblob-service 20001:10000 > /dev/null 2>&1 &"
ssh ec2-user@${CONTROL_PLANE_PUBLIC_IP} "az storage container create -n longhorn-test-azurite --connection-string 'DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://${CONTROL_PLANE_PRIVATE_IP}:20001/devstoreaccount1;'"
}
5 changes: 5 additions & 0 deletions pipelines/utilities/run_longhorn_e2e_test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
S3_BACKUP_STORE='s3://backupbucket@us-east-1/backupstore$minio-secret'
NFS_BACKUP_STORE='nfs://longhorn-test-nfs-svc.default:/opt/backupstore'
CIFS_BACKUP_STORE='cifs://longhorn-test-cifs-svc.default/backupstore$cifs-secret'
AZURITE_BACKUP_STORE='azblob://[email protected]/$azblob-secret'

run_longhorn_e2e_test(){

Expand All @@ -25,6 +26,8 @@ run_longhorn_e2e_test(){
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${NFS_BACKUP_STORE}'"' ${LONGHORN_TESTS_MANIFEST_FILE_PATH}
elif [[ $BACKUP_STORE_TYPE = "cifs" ]]; then
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${CIFS_BACKUP_STORE}'"' ${LONGHORN_TESTS_MANIFEST_FILE_PATH}
elif [[ $BACKUP_STORE_TYPE = "azurite" ]]; then
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${AZURITE_BACKUP_STORE}'"' ${LONGHORN_TESTS_MANIFEST_FILE_PATH}
fi

if [[ "${TF_VAR_use_hdd}" == true ]]; then
Expand Down Expand Up @@ -80,6 +83,8 @@ run_longhorn_e2e_test_out_of_cluster(){
LONGHORN_BACKUPSTORES=${NFS_BACKUP_STORE}
elif [[ $BACKUP_STORE_TYPE = "cifs" ]]; then
LONGHORN_BACKUPSTORES=${CIFS_BACKUP_STORE}
elif [[ $BACKUP_STORE_TYPE = "azurite" ]]; then
LONGHORN_BACKUPSTORES=${AZURITE_BACKUP_STORE}
fi
LONGHORN_BACKUPSTORE_POLL_INTERVAL="30"

Expand Down
6 changes: 6 additions & 0 deletions pipelines/utilities/run_longhorn_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ run_longhorn_test(){
elif [[ $BACKUP_STORE_TYPE = "cifs" ]]; then
BACKUP_STORE_FOR_TEST=`yq e 'select(.spec.containers[0] != null).spec.containers[0].env[1].value' ${LONGHORN_TESTS_MANIFEST_FILE_PATH} | awk -F ',' '{print $3}' | sed 's/ *//'`
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${BACKUP_STORE_FOR_TEST}'"' ${LONGHORN_TESTS_MANIFEST_FILE_PATH}
elif [[ $BACKUP_STORE_TYPE = "azurite" ]]; then
BACKUP_STORE_FOR_TEST=`yq e 'select(.spec.containers[0] != null).spec.containers[0].env[1].value' ${LONGHORN_TESTS_MANIFEST_FILE_PATH} | awk -F ',' '{print $4}' | sed 's/ *//'`
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${BACKUP_STORE_FOR_TEST}'"' ${LONGHORN_TESTS_MANIFEST_FILE_PATH}
fi

if [[ "${TF_VAR_use_hdd}" == true ]]; then
Expand Down Expand Up @@ -113,6 +116,9 @@ run_longhorn_upgrade_test(){
elif [[ $BACKUP_STORE_TYPE = "cifs" ]]; then
BACKUP_STORE_FOR_TEST=`yq e 'select(.spec.containers[0] != null).spec.containers[0].env[1].value' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH} | awk -F ',' '{print $3}' | sed 's/ *//'`
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${BACKUP_STORE_FOR_TEST}'"' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH}
elif [[ $BACKUP_STORE_TYPE = "azurite" ]]; then
BACKUP_STORE_FOR_TEST=`yq e 'select(.spec.containers[0] != null).spec.containers[0].env[1].value' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH} | awk -F ',' '{print $4}' | sed 's/ *//'`
yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[1].value="'${BACKUP_STORE_FOR_TEST}'"' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH}
fi

yq e -i 'select(.spec.containers[0] != null).spec.containers[0].env[4].value="'${LONGHORN_UPGRADE_TYPE}'"' ${LONGHORN_UPGRADE_TESTS_MANIFEST_FILE_PATH}
Expand Down
Loading

0 comments on commit 19842e9

Please sign in to comment.