Skip to content

Commit

Permalink
typo fix for certificate template script in Automate HA (#8616)
Browse files Browse the repository at this point in the history
* typo fix for certificate error

Signed-off-by: punitmundra <pmundra@progress.com>

* add testcase for semver

Signed-off-by: punitmundra <pmundra@progress.com>

* fix path

Signed-off-by: punitmundra <pmundra@progress.com>

* fix path

Signed-off-by: punitmundra <pmundra@progress.com>

---------

Signed-off-by: punitmundra <pmundra@progress.com>
  • Loading branch information
punitmundra authored and kalroy committed Oct 8, 2024
1 parent c7b9970 commit 17c8fc1
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .expeditor/verify.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ steps:
- tfenv use 0.14.11
- cd terraform/a2ha-terraform
- make check
- cd modules/automate/templates/script/
- bash test_semver.sh
expeditor:
executor:
docker:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func (e *existingInfra) populateCertificateTomlFile() error {
var ips []IP
// Initialize Opensearch section
opensearch.RootCA = "/hab/a2_deploy_workspace/certificate/opensearch.fqdn.root.ca.cert"
opensearch.AdminPrivateKey = "/hab/a2_deploy_workspace/certificate/opensearch.admin.public.cert"
opensearch.AdminPublickey = "/hab/a2_deploy_workspace/certificate/opensearch.admin.private.cert"
opensearch.AdminPublickey = "/hab/a2_deploy_workspace/certificate/opensearch.admin.public.cert"
opensearch.AdminPrivateKey = "/hab/a2_deploy_workspace/certificate/opensearch.admin.private.cert"
for i := 0; i < OpensearchCount; i++ {
var ip IP
ip.IP = e.config.ExistingInfra.Config.OpensearchPrivateIps[i]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
semver_version_check() {
installed_version=$1
airgap_bundle_version=$2

IFS='.' read -r major1 minor1 patch1 <<< "$installed_version"
IFS='.' read -r major2 minor2 patch2 <<< "$airgap_bundle_version"

# Compare major versions
if (( major1 > major2 )); then
echo "$installed_version is greater than $airgap_bundle_version"
isSkipRequired=true
elif (( major1 < major2 )); then
echo "$airgap_bundle_version is greater than $installed_version, proceeding for upgrade"
else
# Compare minor versions
if (( minor1 > minor2 )); then
echo "$installed_version is greater than $airgap_bundle_version"
isSkipRequired=true
elif (( minor1 < minor2 )); then
echo "$airgap_bundle_version is greater than $installed_version, proceeding for upgrade"
else
# Compare patch versions
if (( patch1 > patch2 )); then
echo "$installed_version is greater than $airgap_bundle_version"
isSkipRequired=true
elif (( patch1 < patch2 )); then
echo "$airgap_bundle_version is greater than $installed_version, proceeding for upgrade"
else
echo "Both versions are equal"
isSkipRequired=true
fi
fi
fi
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
source ./semver.sh
# Function to assert equality of output
assert_equals() {
local expected="$1"
local actual="$2"
if [ "$expected" == "$actual" ]; then
echo "Test Passed"
else
echo "Test Failed: Expected '$expected', but got '$actual'"
exit 1
fi
}

# Test case 1: Installed version is greater than airgap bundle version
test_case_1() {
echo "Running Test Case 1: Installed version > Airgap bundle version"
result=$(semver_version_check "4.13.0" "4.12.144")
assert_equals "4.13.0 is greater than 4.12.144" "$result"
}

# Test case 2: Airgap bundle version is greater than installed version
test_case_2() {
echo "Running Test Case 2: Airgap bundle version > Installed version"
result=$(semver_version_check "4.12.144" "4.13.0")
assert_equals "4.13.0 is greater than 4.12.144, proceeding for upgrade" "$result"
}

# Test case 3: Both versions are equal
test_case_3() {
echo "Running Test Case 3: Both versions are equal"
result=$(semver_version_check "4.12.144" "4.12.144")
assert_equals "Both versions are equal" "$result"
}

# Test case 4: Different patch version
test_case_4() {
echo "Running Test Case 4: Installed version has greater patch version"
result=$(semver_version_check "4.12.145" "4.12.144")
assert_equals "4.12.145 is greater than 4.12.144" "$result"
}

# Test case 5: Different minor version
test_case_5() {
echo "Running Test Case 5: Airgap bundle has greater minor version"
result=$(semver_version_check "4.11.144" "4.12.0")
assert_equals "4.12.0 is greater than 4.11.144, proceeding for upgrade" "$result"
}

# Test case 6: Different major minor and patch version
test_case_6() {
echo "Running Test Case 6: Airgap bundle has greater major version"
result=$(semver_version_check "4.11.144" "5.12.99")
assert_equals "5.12.99 is greater than 4.11.144, proceeding for upgrade" "$result"
}
# Run all test cases
test_case_1
test_case_2
test_case_3
test_case_4
test_case_5
test_case_6
echo "All tests passed!"

0 comments on commit 17c8fc1

Please sign in to comment.