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

{AKS} create ssh-key in advance when perform concurrent tests #3756

Merged
merged 8 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update ssh storage
  • Loading branch information
FumingZhang committed Aug 10, 2021
commit 7615d19910339baac4644a330c1014a529b1a823
10 changes: 8 additions & 2 deletions src/aks-preview/azcli_aks_live_test/scripts/setup_venv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# check var
# specify the version of python3, e.g. 3.6
[[ -z "${PYTHON_VERSION}" ]] && (echo "PYTHON_VERSION is empty"; exit 1)
[[ -z "${ACS_BASE_DIR}" ]] && (echo "ACS_BASE_DIR is empty"; exit 1)

setupVenv(){
# delete existing venv
Expand Down Expand Up @@ -109,8 +110,13 @@ setupAKSPreview(){
createSSHKey(){
# create ssh-key in advance to avoid the race condition that is prone to occur when key creation is handled by
# azure-cli when performing test cases concurrently, this command will not overwrite the existing ssh-key
custom_ssh_dir=${1:-"/tmp/azaks/.ssh"}
mkdir -p ${custom_ssh_dir}
custom_ssh_dir=${1:-"${ACS_BASE_DIR}/tests/latest/data/.ssh"}
# remove dir if exists (clean up), otherwise create it
if [[ -d ${custom_ssh_dir} ]]; then
rm -rf ${custom_ssh_dir}
else
mkdir -p ${custom_ssh_dir}
fi
ssh-keygen -t rsa -b 2048 -C "azcli_aks_live_test@example.com" -f ${custom_ssh_dir}/id_rsa -N "" -q <<< n
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ set -o xtrace
[[ -z "${IMAGE_TAG}" ]] && (echo "IMAGE_TAG is empty"; exit 1)
# specify the version of python3
[[ -z "${PYTHON_VERSION}" ]] && (echo "PYTHON_VERSION is empty"; exit 1)
# base directories for acs, aks-preview and live test
[[ -z "${ACS_BASE_DIR}" ]] && (echo "ACS_BASE_DIR is empty"; exit 1)
[[ -z "${AKS_PREVIEW_BASE_DIR}" ]] && (echo "AKS_PREVIEW_BASE_DIR is empty"; exit 1)
[[ -z "${LIVE_TEST_BASE_DIR}" ]] && (echo "LIVE_TEST_BASE_DIR is empty"; exit 1)

# from azure devops
[[ -z "${BUILD_REASON}" ]] && (echo "BUILD_REASON is empty")
Expand Down Expand Up @@ -60,6 +64,11 @@ echo "SYSTEM_PULLREQUEST_TARGETBRANCH=${SYSTEM_PULLREQUEST_TARGETBRANCH}" >> env
# python version
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> env.list

# base directories
echo "ACS_BASE_DIR=${ACS_BASE_DIR}" >> env.list
echo "AKS_PREVIEW_BASE_DIR=${AKS_PREVIEW_BASE_DIR}" >> env.list
echo "LIVE_TEST_BASE_DIR=${LIVE_TEST_BASE_DIR}" >> env.list

# azdev env
echo "AZURE_CLI_TEST_DEV_SP_NAME=${AZCLI_ALT_CLIENT_ID}" >> env.list
echo "AZURE_CLI_TEST_DEV_RESOURCE_GROUP_LOCATION=${TEST_LOCATION}" >> env.list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ variables:
value: "azcli-aks-live-test"
- name: REPO_NAME
value: "azure-cli-extensions"
- name: LIVE_TEST_BASE_DIR
FumingZhang marked this conversation as resolved.
Show resolved Hide resolved
value: "azure-cli-extensions/src/aks-preview/azcli_aks_live_test"
- name: ACS_BASE_DIR
value: "azure-cli/src/azure-cli/azure/cli/command_modules/acs"
- name: AKS_PREVIEW_BASE_DIR
value: "azure-cli-extensions/src/aks-preview/azext_aks_preview"

jobs:
- job: LiveTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ variables:
value: "azcli-aks-unit-test"
- name: REPO_NAME
value: "azure-cli-extensions"
- name: LIVE_TEST_BASE_DIR
value: "azure-cli-extensions/src/aks-preview/azcli_aks_live_test"

jobs:
- job: UnitTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ def generate_ssh_keys(self):
# In order to avoid misuse of personal ssh-key during testing and the race condition that is prone to occur when key creation
# is handled by azure-cli when performing test cases concurrently, we provide this function as a workround.

# In the scenario of runner and AKS check-in pipeline, a temporary ssh-key will be generated in advance under the "/tmp/azaks/.ssh"
# directory when setting up the environment. Each test case will read the ssh-key from a pre-generated file during execution,
# so there will be no race conditions caused by concurrent reading and writing/creating of the same file.
pre_generated_ssh_key_path = "/tmp/azaks/.ssh/id_rsa.pub"
if os.path.exists(pre_generated_ssh_key_path):
return pre_generated_ssh_key_path.replace('\\', '\\\\')
# In the scenario of runner and AKS check-in pipeline, a temporary ssh-key will be generated in advance under the
# "tests/latest/data/.ssh" sub-directory of the acs module in the cloned azure-cli repository when setting up the
# environment. Each test case will read the ssh-key from a pre-generated file during execution, so there will be no
# race conditions caused by concurrent reading and writing/creating of the same file.
acs_base_dir = os.getenv("ACS_BASE_DIR", None)
if acs_base_dir:
pre_generated_ssh_key_path = os.path.join(acs_base_dir, "tests/latest/data/.ssh")
if os.path.exists(pre_generated_ssh_key_path):
return pre_generated_ssh_key_path.replace('\\', '\\\\')

# In the CLI check-in pipeline scenario, the following fake ssh-key will be used. Each test case will read the ssh-key from
# a different temporary file during execution, so there will be no race conditions caused by concurrent reading and
Expand Down