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

Include IaC testing for cicd #214

Merged
merged 37 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
21c0009
dev-acc fix
mahesh-hpe Dec 20, 2023
e68fc8b
dev-acc fix
mahesh-hpe Dec 20, 2023
5e7255b
fix
mahesh-hpe Dec 20, 2023
6a7a7aa
fix
mahesh-hpe Dec 20, 2023
0adcfdb
improvement
mahesh-hpe Dec 20, 2023
fae8a38
fix
mahesh-hpe Dec 20, 2023
4cc650c
fix
mahesh-hpe Dec 20, 2023
bc55ea6
fix
mahesh-hpe Dec 20, 2023
f2d064c
fix
mahesh-hpe Dec 20, 2023
7a3d881
fix
mahesh-hpe Dec 20, 2023
22883b4
nit
mahesh-hpe Dec 20, 2023
15e104a
increase timeout
mahesh-hpe Dec 21, 2023
257f562
network
mahesh-hpe Dec 21, 2023
c1d4e3b
improvement
mahesh-hpe Jan 2, 2024
7b9b70f
fix
mahesh-hpe Jan 2, 2024
42769ed
artifact name improvement
mahesh-hpe Jan 3, 2024
82a565c
test
mahesh-hpe Jan 3, 2024
41b71a9
improvement
mahesh-hpe Jan 3, 2024
6203318
improvement
mahesh-hpe Jan 3, 2024
15391c7
update versions
mahesh-hpe Jan 3, 2024
4edc258
fix
mahesh-hpe Jan 3, 2024
74127d7
parse logs
mahesh-hpe Jan 3, 2024
a442f55
testing
mahesh-hpe Jan 3, 2024
59327f6
undo test
mahesh-hpe Jan 3, 2024
c015abb
remove duplication
mahesh-hpe Jan 3, 2024
a7dbb2a
improvement
mahesh-hpe Jan 2, 2024
6bc75e5
name fix
mahesh-hpe Jan 3, 2024
b7f87ac
improvement
mahesh-hpe Jan 3, 2024
e0c13d1
network type
mahesh-hpe Jan 3, 2024
ef48440
undo network type
mahesh-hpe Jan 3, 2024
99ea557
added ci job for prod
mahesh-hpe Jan 3, 2024
79a24a6
improvement
mahesh-hpe Jan 3, 2024
b016658
fix
mahesh-hpe Jan 3, 2024
0fb4c96
fix
mahesh-hpe Jan 3, 2024
491d908
improvement
mahesh-hpe Jan 4, 2024
85c171b
always run
mahesh-hpe Jan 4, 2024
4d2d994
improvement
mahesh-hpe Jan 4, 2024
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
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
Loading