Using CNTI/CNF Test Catalog for Non-Telco Cloud-Native Microservices
The CNTI/CNF Test Catalog is a versatile tool initially designed for telco applications but can also validate the cloud nativeness of non-telco microservices.
Join the DZone community and get the full member experience.
Join For FreeThe Cloud Native Telecom Initiative (CNTI) and the Cloud-Native Network Functions (CNF) Test Catalog are powerful tools designed to ensure telco applications adhere to cloud-native principles and best practices. However, a common misconception is that this tool is limited to telco applications. In reality, the CNTI/CNF Test Catalog is highly versatile and can be effectively used to validate the cloud nativeness of non-telco microservices.
This article aims to guide you through the process of utilizing the CNTI/CNF Test Catalog for non-telco microservices, overcoming potential challenges, and adding custom tests.
Installation
To get started, download the latest CNTI test suite binary from the GitHub releases page. Extract the zip file to your preferred location and provide executable permissions. Ensure your machine meets the prerequisites.
Execute the following command to set up the test suite:
./cnf-testsuite setup
This command will create a cnt-testsuite
namespace in your cluster. For detailed preparation steps, refer to the installation guide.
Configuration
Before executing tests, note that the tool installs your microservice from the Helm charts or manifest location provided in the configuration file. This can be a challenge for non-telco applications, as they may have dependencies or require pre/post-scripting. To address this, you can run the suite on an already installed microservice using the same release name and namespace.
Here's a sample configuration file:
---
release_name: <release name of existing service>
helm_directory: <folder location> # or use manifest directory
helm_install_namespace: <namespace of existing service>
Save this as cnf-testsuite.yml
and ensure all paths are relative to the directory containing the CNTI binary. Use the following command to set up the test configuration:
cnf-testsuite cnf_setup cnf-config=./cnf-testsuite.yml
Execution
With the CNTI suite successfully configured, you can execute the suite for all categories, specific categories, or individual tests:
./cnf-testsuite compatibility
Refer to the test categories and execution guide to identify and run applicable tests for your service. Non-telco applications, for example, won't require 5G-specific tests.
Adding Custom Tests
To add custom tests, clone the CNTI test suite repository:
git
clonehttps://github.com/cnti-testcatalog/testsuite
Navigate to the src/tasks/workload
directory and edit the category test file where you want to add your custom test. The suite is written in Crystal, so it's advisable to use Ubuntu for development or perform changes on Windows and build on Ubuntu.
Custom Test Example
Here's an example of a custom test to check if resource requests are below specified limits:
desc "Check if resource requests are less than 0.5 CPU and 512 MB memory"
task "resource_requests" do |t, args|
CNFManager::Task.task_runner(args, task: t) do |args, config|
resp = ""
task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized|
test_passed = true
resource_ref = "#{resource[:kind]}/#{resource[:name]}"
cpu_request_value = 1
memory_request_value = 1024
begin
cpu_request = container.as_h["resources"].as_h["requests"].as_h["cpu"].as_s
memory_request = container.as_h["resources"].as_h["requests"].as_h["memory"].as_s
cpu_request_value = if cpu_request.ends_with?("m")
cpu_request.gsub("m", "").to_i / 1000.0
else
cpu_request.to_i
end
memory_request_value = if memory_request.ends_with?("Mi")
memory_request.gsub("Mi", "").to_i
elsif memory_request.ends_with?("Gi")
memory_request.gsub("Gi", "").to_i * 1024
else
memory_request.to_i
end
if cpu_request_value > 0.5 || memory_request_value > 512
test_passed = false
stdout_failure("Resource requests for container #{container.as_h["name"].as_s} part of #{resource_ref} in #{resource[:namespace]} namespace exceed limits (CPU: #{cpu_request}, Memory: #{memory_request})")
end
rescue ex
test_passed = false
stdout_failure("Error occurred while checking resource requests for container #{container.as_h["name"].as_s} part of #{resource_ref} in #{resource[:namespace]} namespace")
end
test_passed
end
if task_response
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "Resource requests within limits")
else
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "Resource requests exceed limits")
end
end
end
This test ensures that the CPU and memory requests for a container are within specified limits.
Conclusion
The CNTI/CNF Test Catalog is a robust tool, not just for telco applications, but for any cloud-native microservices. By following the steps outlined in this article, you can configure, execute, and even extend the capabilities of the CNTI test suite to fit your non-telco applications. Embrace the flexibility and power of the CNTI/CNF Test Catalog to enhance the reliability and performance of your microservices.
Opinions expressed by DZone contributors are their own.
Comments