From 4372b93f5558e0089933c842bd7f732437ef8013 Mon Sep 17 00:00:00 2001 From: Johann Hoffmann Date: Tue, 22 Mar 2022 14:31:12 +0100 Subject: [PATCH] [WIFI-7277] Switch to dynamic virtual AP EC2 instance (#430) * Create composite action for dynamic virtual AP EC2 instance deployment Signed-off-by: Johann Hoffmann * Fix output description Signed-off-by: Johann Hoffmann * Fix step output name Signed-off-by: Johann Hoffmann * Checkout repo before using composite action Signed-off-by: Johann Hoffmann * Switch to inputs in composite action since secrets do not work Signed-off-by: Johann Hoffmann * Move env variable definition to step section Signed-off-by: Johann Hoffmann * Remove top level env section Signed-off-by: Johann Hoffmann * Fix job and step outputs Signed-off-by: Johann Hoffmann * Use SSH option to start ucentral in background Signed-off-by: Johann Hoffmann * Switch to SSH password until config override option is ready Signed-off-by: Johann Hoffmann * Adapt workflow to previous changes Signed-off-by: Johann Hoffmann * Remove key reference in SSH command line options Signed-off-by: Johann Hoffmann * Add instance_id output and switch to cut to get firmware version Signed-off-by: Johann Hoffmann * Fix terminate-instances command Signed-off-by: Johann Hoffmann * Switch back to awk command to get firmware version Signed-off-by: Johann Hoffmann * Wait for automated ucentral start before stopping and fix awk command Signed-off-by: Johann Hoffmann * Add owner tag to run-instances command Signed-off-by: Johann Hoffmann * Remove branch reference Signed-off-by: Johann Hoffmann --- .../deploy-virtual-ap-instance/action.yml | 66 ++++++++++++++++ .github/workflows/ow_docker-compose.yml | 76 +++++++++---------- 2 files changed, 100 insertions(+), 42 deletions(-) create mode 100644 .github/actions/deploy-virtual-ap-instance/action.yml diff --git a/.github/actions/deploy-virtual-ap-instance/action.yml b/.github/actions/deploy-virtual-ap-instance/action.yml new file mode 100644 index 000000000..169a475a1 --- /dev/null +++ b/.github/actions/deploy-virtual-ap-instance/action.yml @@ -0,0 +1,66 @@ +name: Deploy virtual AP instance +description: create EC2 instance running latest wlan-ap release and connect to gateway + +inputs: + virtual_ap_password: + description: SSH password used to connect to virtual AP instance + required: true + virtual_ap_cert: + description: AP cert which is uploaded and used to connect to the gateway + required: true + virtual_ap_key: + description: AP key which is uploaded and used to connect to the gateway + required: true + virtual_ap_dev_id: + description: Dev-id associated with the AP cert + required: true + gateway_url: + description: URL of the gateway the virtual AP should connect to + required: true + +outputs: + serial_number: + description: Serial number of the created virtual AP instance + value: ${{ steps.get_virtual_ap_facts.outputs.serial_number }} + instance_id: + description: ID of the created virtual AP EC2 instance + value: ${{ steps.get_virtual_ap_facts.outputs.instance_id }} + +runs: + using: "composite" + steps: + - name: Get AMI ID of most recent x64_vmware firmware image + shell: bash + id: get_ami_id + run: | + echo ::set-output name=id::"$(aws ec2 describe-images --owners self --filters 'Name=name,Values=*-x64_vmware-*' --query 'sort_by(Images, &CreationDate)[-1].ImageId' --output text)" + + - name: Create openwifi-virtual-ap EC2 instance + shell: bash + run: | + aws ec2 run-instances --key-name openwifi-virtual-ap --security-groups openwifi-virtual-ap --instance-type t2.nano --image-id ${{ steps.get_ami_id.outputs.id }} --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=openwifi-virtual-ap-${{ github.run_id }}},{Key=Owner,Value=gha-wlan-testing}]' + + - name: Get virtual AP instance facts + shell: bash + id: get_virtual_ap_facts + run: | + echo ::set-output name=public_ip::"$(aws ec2 describe-instances --filters 'Name=tag:Name,Values=openwifi-virtual-ap-${{ github.run_id }}' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text)" + echo ::set-output name=serial_number::"$(aws ec2 describe-instances --filters 'Name=tag:Name,Values=openwifi-virtual-ap-${{ github.run_id }}' --query 'Reservations[*].Instances[*].NetworkInterfaces[*].MacAddress' --output text | sed 's/://g')" + echo ::set-output name=instance_id::"$(aws ec2 describe-instances --filters 'Name=tag:Name,Values=openwifi-virtual-ap-${{ github.run_id }}' --query 'Reservations[*].Instances[*].InstanceId' --output text)" + + - name: Upload AP certificate, key and dev-id to instance + env: + VIRTUAL_AP_PASSWORD: ${{ inputs.virtual_ap_password }} + VIRTUAL_AP_CERT: ${{ inputs.virtual_ap_cert }} + VIRTUAL_AP_KEY: ${{ inputs.virtual_ap_key }} + VIRTUAL_AP_DEV_ID: ${{ inputs.virtual_ap_dev_id }} + shell: bash + run: | + sshpass -p ${{ env.VIRTUAL_AP_PASSWORD }} ssh -o StrictHostKeyChecking=accept-new root@${{ steps.get_virtual_ap_facts.outputs.public_ip }} 'echo "${{ env.VIRTUAL_AP_CERT }}" > /etc/ucentral/cert.pem; echo "${{ env.VIRTUAL_AP_KEY }}" > /etc/ucentral/key.pem && chmod 600 /etc/ucentral/key.pem; echo "${{ env.VIRTUAL_AP_DEV_ID }}" > /etc/ucentral/dev-id; sleep 10' + + - name: Stop ucentral service on AP and connect manually to gateway + env: + VIRTUAL_AP_PASSWORD: ${{ inputs.virtual_ap_password }} + shell: bash + run: | + sshpass -p ${{ env.VIRTUAL_AP_PASSWORD }} ssh -f -o StrictHostKeyChecking=accept-new root@${{ steps.get_virtual_ap_facts.outputs.public_ip }} "/etc/init.d/ucentral stop; /usr/sbin/ucentral -S ${{ steps.get_virtual_ap_facts.outputs.serial_number }} -s ${{ inputs.gateway_url }} -P 15002 -d -f \$(awk -F '=' 'FNR == 8 {print \$2}' /etc/openwrt_release | tr -d \') &> /dev/null" diff --git a/.github/workflows/ow_docker-compose.yml b/.github/workflows/ow_docker-compose.yml index 6ac5e8b6c..902d8c22f 100644 --- a/.github/workflows/ow_docker-compose.yml +++ b/.github/workflows/ow_docker-compose.yml @@ -336,73 +336,57 @@ jobs: -e OWSEC_NEW_PASSWORD \ tip-tip-wlan-cloud-ucentral.jfrog.io/clustersysteminfo:main - set-redirector-url: - name: Get virtual AP instance facts and set redirector URL - needs: deploy-controller + deploy-virtual-ap-instance: + name: Deploy virtual AP EC2 instance + needs: deploy-controller runs-on: ubuntu-latest env: AWS_DEFAULT_REGION: us-east-1 - VIRTUAL_AP_SSH_KEY: ${{ secrets.VIRTUAL_AP_SSH_KEY }} - DIGICERT_API_KEY: ${{ secrets.DIGICERT_API_KEY }} outputs: - mac_address: ${{ steps.get_virtual_ap_mac_address.outputs.value }} + serial_number: ${{ steps.deploy-virtual-ap-instance.outputs.serial_number }} + instance_id: ${{ steps.deploy-virtual-ap-instance.outputs.instance_id }} steps: - - name: Checkout wlan-pki-cert-scripts repo - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + + - name: Use deploy-virtual-ap-instance composite action + id: deploy-virtual-ap-instance + uses: ./.github/actions/deploy-virtual-ap-instance with: - repository: Telecominfraproject/wlan-pki-cert-scripts - path: wlan-pki-cert-scripts - - - name: Get public IP of virtual AP EC2 instance - id: get_virtual_ap_public_ip - run: | - echo ::set-output name=ip::"$(aws ec2 describe-instances --filters 'Name=tag:Name,Values=tip-wlan-main OpenWifi virtual AP (WIFI-7204)' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text)" - - - name: Get mac address of virtual AP EC2 instance - id: get_virtual_ap_mac_address - run: | - echo ::set-output name=value::"$(aws ec2 describe-instances --filters 'Name=tag:Name,Values=tip-wlan-main OpenWifi virtual AP (WIFI-7204)' --query 'Reservations[*].Instances[*].NetworkInterfaces[*].MacAddress' --output text | sed 's/://g')" - - - name: Set redirector URL - run: | - ./wlan-pki-cert-scripts/digicert-change-ap-redirector.sh 06:6f:df:5d:30:e2 ${{ needs.deploy-controller.outputs.gateway_url }} - - # starting the firstcontact service applies a default config, which is why we need to re-apply our config modifications in order to add the SSH key - - name: Connect to virtual AP, start firstcontact service and re-apply AP config - run: | - echo "${{ env.VIRTUAL_AP_SSH_KEY }}" > openwifi-virtual-ap.pem - chmod 600 openwifi-virtual-ap.pem - ssh -o StrictHostKeyChecking=accept-new -i openwifi-virtual-ap.pem root@${{ steps.get_virtual_ap_public_ip.outputs.ip }} '/etc/init.d/firstcontact start; sleep 10; /usr/share/ucentral/ucentral.uc /root/config.json' + virtual_ap_password: ${{ secrets.VIRTUAL_AP_PASSWORD }} + virtual_ap_cert: ${{ secrets.VIRTUAL_AP_CERT }} + virtual_ap_key: ${{ secrets.VIRTUAL_AP_KEY }} + virtual_ap_dev_id: ${{ secrets.VIRTUAL_AP_DEV_ID }} + gateway_url: ${{ needs.deploy-controller.outputs.gateway_url }} test: name: Test specified microservice - needs: [deploy-controller, set-redirector-url] + needs: [deploy-controller, deploy-virtual-ap-instance] runs-on: ubuntu-latest env: OWSEC: "${{ needs.deploy-controller.outputs.sec_url }}:16001" OWSEC_USERNAME: ${{ secrets.OWSEC_DEFAULT_USERNAME }} OWSEC_PASSWORD: ${{ secrets.OWSEC_NEW_PASSWORD }} steps: - - name: Checkout wlan-cloud-ucentralgw repo and test OWGW + - name: Get OWGW CLI script and test service if: github.event.inputs.microservice == 'owgw' || github.event.inputs.microservice == 'all' run: | curl -s https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-ucentralgw/master/test_scripts/curl/cli -o cli chmod +x cli - ./cli test_service ${{ needs.set-redirector-url.outputs.mac_address }} + ./cli test_service ${{ needs.deploy-virtual-ap-instance.outputs.serial_number }} - - name: Checkout wlan-cloud-ucentralsec repo and test OWSec + - name: Get OWSec CLI script and test service if: github.event.inputs.microservice == 'owsec' || github.event.inputs.microservice == 'all' run: | curl -s https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-ucentralsec/main/test_scripts/curl/cli -o cli chmod +x cli ./cli test_service - - name: Checkout wlan-cloud-ucentralfms repo and test OWFms + - name: Get OWFms CLI script and test service if: github.event.inputs.microservice == 'owfms' || github.event.inputs.microservice == 'all' run: | curl -s https://raw.githubusercontent.com/Telecominfraproject/wlan-cloud-ucentralfms/main/test_scripts/curl/cli -o cli chmod +x cli - ./cli test_service ${{ needs.set-redirector-url.outputs.mac_address }} + ./cli test_service ${{ needs.deploy-virtual-ap-instance.outputs.serial_number }} destroy-controller: name: Destroy controller namespace @@ -412,14 +396,22 @@ jobs: AWS_DEFAULT_REGION: us-east-2 if: always() steps: - - name: Checkout wlan-testing repo - uses: actions/checkout@v2 - with: - path: wlan-testing - - name: Fetch kubeconfig run: | aws eks update-kubeconfig --name ${{ env.AWS_EKS_NAME }} - name: Delete namespace run: kubectl delete ns --ignore-not-found=true ${{ needs.deploy-controller.outputs.namespace }} + + terminate-virtual-ap-instance: + name: Terminate virtual AP instance + needs: [deploy-virtual-ap-instance, test] + runs-on: ubuntu-latest + env: + AWS_DEFAULT_REGION: us-east-1 + if: always() + steps: + - name: Terminate virtual AP EC2 instance + continue-on-error: true + run: | + aws ec2 terminate-instances --instance-ids ${{ needs.deploy-virtual-ap-instance.outputs.instance_id }}