Skip to content

Commit

Permalink
Merge pull request #214 from HewlettPackard/cicd-acc
Browse files Browse the repository at this point in the history
Include IaC testing for cicd
  • Loading branch information
reubenur-rahman authored Jan 4, 2024
2 parents 60c1421 + 4d2d994 commit 10f0e71
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 99 deletions.
33 changes: 33 additions & 0 deletions .github/parse_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# (C) Copyright 2024 Hewlett Packard Enterprise Development LP

import os
import sys


def main(args):
n = len(args)
if n != 2:
print("Pass the log directory or txt file path")
return 1
log_path = args[1]
file_content = ''
if log_path.endswith(".txt"):
with open(log_path) as f:
file_content += (f.read())
else:
for x in os.listdir(log_path):
if x.endswith(".txt"):
with open(os.path.join(log_path, x)) as f:
file_content += (f.read())
test_count = file_content.count('RUN') - file_content.count('SKIP:')
pass_count = file_content.count('PASS:')
fail_count = file_content.count('FAIL:')
print(
f"\nTestcases Ran: {test_count}; \n"
f"Testcases Passed: {pass_count}; \n"
f"Testcases Failed: {fail_count}; \n")
return 0

if __name__ == "__main__":
exit(main(sys.argv))
65 changes: 26 additions & 39 deletions .github/workflows/acc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,33 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
test_case:
description: 'Enter testcases sperated by space. Leave empty for all'
required: false
default: ''
type: string
test_description:
description: 'Enter description for the test'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
default: 'Check all Terraform Testcases'
type: string

release:
types: [published]
env:
HPEGL_IAM_SERVICE_URL: ${{ secrets.HPEGL_IAM_SERVICE_URL }}
HPEGL_TENANT_ID: ${{ secrets.HPEGL_TENANT_ID }}
HPEGL_USER_SECRET: ${{ secrets.HPEGL_USER_SECRET }}
HPEGL_USER_ID: ${{ secrets.HPEGL_USER_ID }}
HPEGL_VMAAS_API_URL: ${{ secrets.HPEGL_VMAAS_API_URL }}
HPEGL_VMAAS_LOCATION: ${{ secrets.HPEGL_VMAAS_LOCATION }}
HPEGL_VMAAS_SPACE_NAME: ${{ secrets.HPEGL_VMAAS_SPACE_NAME}}
TF_ACC: ${{ secrets.TF_ACC }}
jobs:
acc:
runs-on: ubuntu-20.04
strategy:
matrix:
go: [ '1.17' ]
name: Acceptance Tests
steps:
- name: Checkout workspace
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17
- name: Install dependencies
run: |
sudo apt-get install -y wget jq
wget https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_linux_amd64.zip
sudo unzip -fo terraform_1.0.0_linux_amd64.zip -d /usr/local/bin

- name: Install necessary tools
run: make tools

- name: Run Acceptance test
run: |
make acceptance
jobs:
acc-test:
uses: ./.github/workflows/reusable-dev-acc.yml
with:
test_case: ${{ inputs.test_case }}
test_description: ${{ inputs.test_description }}
test_case_folder: 'acc-testcases'
secrets:
DEV_HPEGL_IAM_SERVICE_URL: ${{ secrets.HPEGL_IAM_SERVICE_URL }}
DEV_HPEGL_TENANT_ID: ${{ secrets.HPEGL_TENANT_ID }}
DEV_HPEGL_USER_SECRET: ${{ secrets.HPEGL_USER_SECRET }}
DEV_HPEGL_USER_ID: ${{ secrets.HPEGL_USER_ID }}
DEV_HPEGL_VMAAS_API_URL: ${{ secrets.HPEGL_VMAAS_API_URL }}
DEV_HPEGL_VMAAS_LOCATION: ${{ secrets.HPEGL_VMAAS_LOCATION }}
DEV_HPEGL_VMAAS_SPACE_NAME: ${{ secrets.HPEGL_VMAAS_SPACE_NAME}}
TF_ACC: ${{ secrets.TF_ACC }}
63 changes: 55 additions & 8 deletions .github/workflows/cicd-dev-acc.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,73 @@
name: Dev Acceptance Tests for CI CD
name: IaC Tests for CI CD Gating Job
# This workflow runs all the acc-dev-testcases

on:
workflow_dispatch:

jobs:
test-provider:
uses: ./.github/workflows/dev-acc.yml
uses: ./.github/workflows/reusable-dev-acc.yml
with:
test_case: TestProvider
test_description: Check for valid terraform provider
secrets: inherit

test-datasouces:
needs:
- test-provider
if: "${{ always() && needs.test-provider.result != 'failed' }}"
uses: ./.github/workflows/dev-acc.yml
needs: [test-provider]
if: "always() && ${{ needs.test-provider.result == 'success' }}"
uses: ./.github/workflows/reusable-dev-acc.yml
with:
test_case: TestAccDataSource
test_description: GET call usecase validations
secrets: inherit

test-vmaas-instance:
uses: ./.github/workflows/dev-acc.yml
uses: ./.github/workflows/reusable-dev-acc.yml
needs: [test-datasouces]
if: "always()"
with:
test_case: TestVmaasInstance
test_case: TestVmaasInstance TestAccResourceInstance
test_description: Instance usecase validations
secrets: inherit

test-vmaas-lb:
uses: ./.github/workflows/reusable-dev-acc.yml
needs: [test-vmaas-instance]
if: "always()"
with:
test_case: TestVmaasLB TestAccResourceLB TestVmaasLoadBalancerPlan TestAccResourceLoadBalancerCreate
test_description: Loadbalancer usecase validations
secrets: inherit

test-vmaas-network:
uses: ./.github/workflows/reusable-dev-acc.yml
needs: [test-vmaas-lb]
if: "always()"
with:
test_case: TestVmaasNetworkPlan TestAccResourceNetworkCreate TestAccResourceRouter TestVmaasRouter TestAccResourceTier TestVmaasRouteBGPNeighborPlan
test_description: NSX Network usecase validations
secrets: inherit

process-logs:
runs-on: ubuntu-20.04
needs:
- test-vmaas-network
if: "always()"
steps:
- name: Checkout workspace
uses: actions/checkout@v4
- name: Download logs
id: logs
uses: actions/download-artifact@v4
with:
path: tmp/artifacts
merge-multiple: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Print Result and Publish
run: |
LOG_RESULT=$(python .github/parse_logs.py '${{ steps.logs.outputs.download-path }}')
echo $LOG_RESULT
curl -X POST -H 'Content-type: application/json' --data "{'text':'CICD Terraform IaC Test results $LOG_RESULT and report link - https://github.com/HewlettPackard/hpegl-vmaas-terraform-resources/actions/runs/${{ github.run_id }}'}" '${{ secrets.TEAMS_URL_CICD }}'
44 changes: 44 additions & 0 deletions .github/workflows/cicd-prod-acc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: IaC Tests for CI CD Solution Job

on:
workflow_dispatch:

jobs:
acc-test:
uses: ./.github/workflows/reusable-dev-acc.yml
with:
test_description: IaC Terraform Testcase
test_case_folder: 'acc-testcases'
secrets:
DEV_HPEGL_IAM_SERVICE_URL: ${{ secrets.HPEGL_IAM_SERVICE_URL }}
DEV_HPEGL_TENANT_ID: ${{ secrets.HPEGL_TENANT_ID }}
DEV_HPEGL_USER_SECRET: ${{ secrets.HPEGL_USER_SECRET }}
DEV_HPEGL_USER_ID: ${{ secrets.HPEGL_USER_ID }}
DEV_HPEGL_VMAAS_API_URL: ${{ secrets.HPEGL_VMAAS_API_URL }}
DEV_HPEGL_VMAAS_LOCATION: ${{ secrets.HPEGL_VMAAS_LOCATION }}
DEV_HPEGL_VMAAS_SPACE_NAME: ${{ secrets.HPEGL_VMAAS_SPACE_NAME}}
TF_ACC: ${{ secrets.TF_ACC }}

process-logs:
runs-on: ubuntu-20.04
needs:
- acc-test
if: "always()"
steps:
- name: Checkout workspace
uses: actions/checkout@v4
- name: Download logs
id: logs
uses: actions/download-artifact@v4
with:
path: tmp/artifacts
merge-multiple: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Print Result and Publish
run: |
LOG_RESULT=$(python .github/parse_logs.py '${{ steps.logs.outputs.download-path }}')
echo $LOG_RESULT
curl -X POST -H 'Content-type: application/json' --data "{'text':'CICD Terraform IaC Test results $LOG_RESULT and report link - https://github.com/HewlettPackard/hpegl-vmaas-terraform-resources/actions/runs/${{ github.run_id }}'}" '${{ secrets.SLACK_URL_CICD }}'
76 changes: 25 additions & 51 deletions .github/workflows/dev-acc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: Dev Acceptance Tests
name: Dev Acceptance Testing
# This workflow is intended to run a particular set of testcases
# If want to execute all test, consider running cicd-dev-acc.yml

on:
# Runs every 2 days once at 3AM
Expand All @@ -8,56 +10,28 @@ on:
workflow_dispatch:
inputs:
test_case:
description: 'Enter testcase'
required: false
default: ''
description: 'Enter testcases sperated by space'
required: true
default: 'TestProvider'
type: string
test_description:
description: 'Enter description for the test'
required: true
default: 'Check Terraform Dev Testcase'
type: string

# release:
# types: [published]
env:
HPEGL_IAM_SERVICE_URL: ${{ secrets.DEV_HPEGL_IAM_SERVICE_URL }}
HPEGL_TENANT_ID: ${{ secrets.DEV_HPEGL_TENANT_ID }}
HPEGL_USER_SECRET: ${{ secrets.DEV_HPEGL_USER_SECRET }}
HPEGL_USER_ID: ${{ secrets.DEV_HPEGL_USER_ID }}
HPEGL_VMAAS_API_URL: ${{ secrets.DEV_HPEGL_VMAAS_API_URL }}
HPEGL_VMAAS_LOCATION: ${{ secrets.DEV_HPEGL_VMAAS_LOCATION }}
HPEGL_VMAAS_SPACE_NAME: ${{ secrets.DEV_HPEGL_VMAAS_SPACE_NAME}}
TF_ACC: ${{ secrets.TF_ACC }}
LOG_FILE: "${{ github.event.inputs.test_case }}Logs.txt"
jobs:
acc:
runs-on: ubuntu-20.04
strategy:
matrix:
go: [ '1.17' ]
name: Dev Acceptance Tests
steps:
- name: Checkout workspace
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17
- name: Install dependencies
run: |
sudo apt-get install -y wget jq
wget https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_linux_amd64.zip
sudo unzip -fo terraform_1.0.0_linux_amd64.zip -d /usr/local/bin
- name: Install necessary tools
run: make tools

- name: Run Acceptance test
run: |
echo "Run Date: $(date +'%Y-%m-%d Time: %H:%M:%S %z' )" >> $LOG_FILE
export TF_ACC_TEST_PATH="$(pwd)/acc-dev-testcases" && make acceptance case='${{ github.event.inputs.test_case }}' >> $LOG_FILE
- name: Print testcases output
run: cat $LOG_FILE

- name: Push the report to github artifacts
uses: actions/upload-artifact@v3
with:
name: "Terraform Test report: ${{ github.event.inputs.test_case }}"
path: ${{ env.LOG_FILE }}
acc-test:
uses: ./.github/workflows/reusable-dev-acc.yml
with:
test_case: ${{ inputs.test_case }}
test_description: ${{ inputs.test_description }}
secrets:
DEV_HPEGL_IAM_SERVICE_URL: ${{ secrets.DEV_HPEGL_IAM_SERVICE_URL }}
DEV_HPEGL_TENANT_ID: ${{ secrets.DEV_HPEGL_TENANT_ID }}
DEV_HPEGL_USER_SECRET: ${{ secrets.DEV_HPEGL_USER_SECRET }}
DEV_HPEGL_USER_ID: ${{ secrets.DEV_HPEGL_USER_ID }}
DEV_HPEGL_VMAAS_API_URL: ${{ secrets.DEV_HPEGL_VMAAS_API_URL }}
DEV_HPEGL_VMAAS_LOCATION: ${{ secrets.DEV_HPEGL_VMAAS_LOCATION }}
DEV_HPEGL_VMAAS_SPACE_NAME: ${{ secrets.DEV_HPEGL_VMAAS_SPACE_NAME}}
TF_ACC: ${{ secrets.TF_ACC }}
Loading

0 comments on commit 10f0e71

Please sign in to comment.