Site24x7-970x250

KubeLibrary: Testing Kubernetes with RobotFramework

in DevOps , Kubernetes , Configuration Management

KubeLibrary.png

This article explores the RobotFramework library KubeLibrary. KubeLibrary is a wrapper for the Python Kubernetes Client. It enables you to assert the status of various objects in your Kubernetes Clusters. As the library can be integrated with any RobotFramework test suite, it is ideal to verify the testability of your System-under-Test by asserting the status of your nodes, deployments, pods, configmaps, and others Kubernetes objects before running any end to end tests.


    What is the KubeLibrary?

    As KubeLibrary is based on the official python kubernetes client you can connect to your Kubernetes cluster while executing any Kubernetes API command.

    Being part of the broader RobotFramework Library, all code is wrapped into keywords that can be used in test cases defined in ATDD (Acceptance Test Driven Development) or in BDD (Behavioral Driven Development) syntax.

    Why use the KubeLibrary?

    When running end to end tests, you need to ensure that your system-under-test is fully available and runs the latest deployed version. With the KubeLibrary you can easily build tests to verify that all objects in your Kubernetes cluster are up and running and in the state that you expect them. This ensures that a successful end to end test run can be performed.

    How to use the KubeLibrary

    There are many different examples available within the GitHub repository of the KubeLibrary. But let’s show you a small example here:

    Let’s say you want to make sure that all pods in a certain namespace are running and use a specific image version.

    https://gist.github.com/Nilsty/83ad625eb76a3fe5f9891919bb4f169a (sorry, can't embed on here)

    If you run this test in your Kubernetes cluster, it would check for pods matching the name pattern in ${POD_NAME_PATTERN} in a namespace ${NAMESPACE}. It will search for running pods for 2 minutes. Once the pods are confirmed running it will confirm the image they are using.
    After you have confirmed that your pods are running you can continue with any application-level testing.
    The KubeLibrary can be also used for checking nodes, jobs, configmaps, persistent volume claims, services, and other Kubernetes objects. Current keyword documentation is available on GitHub (link).

    Contributing to the KubeLibrary

    Almost every week new keywords are added to the library, but the Kubernetes API is big and not all of its functionality is covered in the KubeLibrary, yet. If you are missing certain functionality please file an issue in the GitHub project or create a pull request. Adding new functionality can be quite easy as the python client for kubernetes is well documented and often only a wrapper for the existing definitions is required.

    How do we use the KubeLibrary at Humanitec?

    At Humanitec our end to end test automation is organized in Robot Framework test suites. We utilize several libraries to gain a holistic view through our testing. For API testing we use the Requests Library, for UI testing we use the Selenium Library.
    Humanitec enables the user to develop, maintain, and deploy applications to Kubernetes clusters. Thus, we also utilize the KubeLibrary to verify the expected state of Kubernetes objects created and updated by Humanitec. For example, if you choose to update environment variables for your application through Humanitec, this will trigger an update to a configmap object in your applications cluster. In our tests, we trigger this update with an API call to the Humanitec API, then verify with the KubeLibrary if the update was done as expected in the cluster.

    This way, we can build easily automated regression tests for all the features provided by Humanitec.

    If you want to learn more about KubeLibrary, join our next webinar!


    Get similar stories in your inbox weekly, for free



    Share this story:
    humanitec
    Humanitec

    Humanitec builds your Internal Developer Platform. You create and deploy your best software, while leveraging full DevOps and Continuous Delivery.

    APM-970x250

    Latest stories


    How ManageEngine Applications Manager Can Help Overcome Challenges In Kubernetes Monitoring

    We tested ManageEngine Applications Manager to monitor different Kubernetes clusters. This post shares our review …

    AIOps with Site24x7: Maximizing Efficiency at an Affordable Cost

    In this post we'll dive deep into integrating AIOps in your business suing Site24x7 to …

    A Review of Zoho ManageEngine

    Zoho Corp., formerly known as AdventNet Inc., has established itself as a major player in …

    Should I learn Java in 2023? A Practical Guide

    Java is one of the most widely used programming languages in the world. It has …

    The fastest way to ramp up on DevOps

    You probably have been thinking of moving to DevOps or learning DevOps as a beginner. …

    Why You Need a Blockchain Node Provider

    In this article, we briefly cover the concept of blockchain nodes provider and explain why …

    Top 5 Virtual desktop Provides in 2022

    Here are the top 5 virtual desktop providers who offer a range of benefits such …