The Docker Integration Tests
(aka BDI
) is image for integration tests. Supposed that this image will not be used to execute integration tests directly
but real images for integration tests will use this image as basic (FROM
command in the particular docker file). BDI builds some sandbox
which
includes python
interpreter, Robot Framework, some useful tools such as bash
, shadow
, vim
, rsync
, ttyd
, common custom Robot Framework libraries
(for example, PlatformLibrary
) and customized docker entry point script.
The Docker Integration Tests
contains the following pre-installed Linux tools:
python
(version 3.10.13)bash
shadow
vim
rsync
ttyd
PlatformLibrary
documentation is autogenerated by Robot Framework libdoc tool. It can be found here
To generate new doc you should navigate to current project repository and execute the following command:
python -m robot.libdoc PlatformLibrary.py PlatformLibrary.html
and move PlatformLibrary.html
file to documentation directory.
A docker entry point script is a script which will be executed after docker container is created. If you override the image, its entry point script
will be executed by default. But if you override the entry point as well, your own entry point will be run.
Docker Integration Tests contains simple and customized entry point script - /docker-entrypoint.sh
with the following command (possible CMD
arguments):
-
run-robot
is a defaultCMD
command which executes Robot Framework test cases, can resolve Robot Framework tags to be excluded, can createresult.txt
file with parsed Robot Framework tests results in pretty format. After tests executionttyd
tool is started. -
run-ttyd
command startsttyd
tool.ttyd
is Web-console which rather useful for dev and troubleshooting purposes. -
custom
command executes custom bash script if this script's path is provided. To provide custom script this script should exist within container and environment variableCUSTOM_ENTRYPOINT_SCRIPT
should contain path to the script. Actually,custom
command is equivalent to overriding the entry point script but we recommend implementing custom script instead of entry point overriding.
Example of equivalent console command:
/docker-entrypoint.sh run-robot
Below is detailed description regarding run-robot
command.
run-robot
command contains 4 customized steps:
-
service checker script
. Sometimes we want to make sure that "tested" service is ready for testing and start execution only for "ready" service. For this purpose inheritor image should implement "service checker script" (python) which givestimeout
argument in seconds (by defaulttimeout
is 300 second but can be overridden bySERVICE_CHECKER_SCRIPT_TIMEOUT
environment variable) and checks if the service is ready. If the service is ready entry point script goes to the next step. To specify "service checker script"SERVICE_CHECKER_SCRIPT
environment variable should not be empty and should contain path to custom python script. By default,SERVICE_CHECKER_SCRIPT
is empty and current entry point script step is skipped. -
excluded tags resolver
. Sometimes some Robot Framework tests can not be executed in given configuration. For example, test should checkElasticsearch
service butelasticsearch
URL is not given and we want to skip this test. The Robot Framework paradigm supposed that this case should be resolved by tag approach. We can point which tests should be skipped by its tags. For example,robot -e my-excluded_tag ./tests
. Docker Integration Tests entry point script provides development approach to recognize which tests should be skipped before tests execution. Supposed that.robot
files are contained some root folder (for, exampletests
).robot_tags_resolver.py
script recursively bypasses all inner folder to look up alltags_exclusion.py
modules. For each found moduleget_excluded_tags(environ)
function will be executed, where where environ is a list of environment variables.get_excluded_tags
function should return list or dictionary of excluded tags. If list is returned, all tags will be added to result set of excluded tags. If dictionary is returned, all keys will be added to result set of excluded tags and the particular dictionary will update result dictionary which will be printed to console as some map where keys are excluded tags and values are reasons why these tags are excluded. Default tags resolver script isrobot_tags_resolver.py
but inheritor image can override it byTAGS_RESOLVER_SCRIPT
environment variable which contains path to custom tags resolver script. To skip excluded tags resolving process environment variableIS_TAGS_RESOLVER_ENABLED
should befalse
(it istrue
by default). -
robot tests execution
. This step can not be skipped. It executes Robot Framework tests without excluded ones. IfTAGS
environment variable is presented only these tags will be executed. This is an example of specifying onlyfirst
andsecond
tests fromfirst
,second
andthird
:
firstORsecond
If tag of test is contained in included and excluded tags it will not be executed.
-
analyze results
. Sometimes text file with Robot Framework results should be generated in pretty human readable format. For example, we want to copy this result from Kubernetes Pod to Jenkins job and we want text results instead of all Pod's logs orhtml
formatted file. For this purposeanalyze_result.py
module will be executed. This module createsresult.txt
file inoutput
folder (with all Robot Framework results) with tests results in pretty format. To skip this step environment variableIS_ANALYZER_RESULT_ENABLED
should befalse
(it istrue
by default). Default analyzer script isanalyze_result.py
but inheritor image can override it byANALYZE_RESULT_SCRIPT
environment variable which contains path to custom analyzer script. -
write status
. To integrate with deployer Jenkins Job status of integration tests should be set to watched by Jenkins Job Kubernetes entity. It can be as custom resource (CR) as native Kubernetes entities (deployments, pods, etc.). The BDI provides an ability to write status of executed tests to some Kubernetes entity out of the box. Status is written as Kubernetes status condition with the following fields:
lastTransitionTime
- timestamp.message
- parsed results of Robot framework integration tests as string.reason
- static field withIntegrationTestsExecutionStatus
value.status
- can beTrue
orFalse
. This field depends ontype
field. It isTrue
iftype
isReady
orSuccessful
andFalse
iftype
isFailed
orIn progress
.type
- can beReady
,Successful
,Failed
orIn progress
.
For example,
lastTransitionTime: "2021-04-21T11:21:31.332Z"
message: <Robot Framework parsed results>
reason: IntegrationTestsExecutionStatus
status: "True"
type: Ready
In some cases, it is necessary to have status
field as boolean
instead of string
.
For example,
lastTransitionTime: "2021-04-21T11:21:31.332Z"
message: <Robot Framework parsed results>
reason: IntegrationTestsExecutionStatus
status: true
type: Ready
To support this, environment variable IS_STATUS_BOOLEAN
must be set to true
.
By default, IS_STATUS_BOOLEAN
is considered to be false
.
Note! For using feature write status
in restricted environment, the user or service account used by the Deployer should have
permissions on entity group with the verbs get
, patch
and resources <resource_plural>/status
in current the namespace or project.
For example, permissions for write status in Custom Resource:
- apiGroups:
- qubership.org
resources:
- platformmonitorings/status
verbs:
- get
- patch
To write status to some k8s entity you should specify the entity. There are two ways to do this. The first one is to specify
full path. For example, you have ZooKeeperService
custom resource which has
metadata.selfLink
field with value - /apis/qubership.org/v1/namespaces/zookeeper-service/zookeeperservices/zookeeper
,
in the current approach you should specify STATUS_CUSTOM_RESOURCE_PATH
environment variable with value from selfLink
without
apis
prefix and namespaces
part:
STATUS_CUSTOM_RESOURCE_PATH=qubership.org/v1/zookeeper-service/zookeeperservices/zookeeper
The second approach is to point the path in parts using the following environment variables:
STATUS_CUSTOM_RESOURCE_GROUP=qubership.org
STATUS_CUSTOM_RESOURCE_VERSION=v1
STATUS_CUSTOM_RESOURCE_NAMESPACE=zookeeper-service
STATUS_CUSTOM_RESOURCE_PLURAL=zookeeperservices
STATUS_CUSTOM_RESOURCE_NAME=zookeeper
If your k8s pod with integration tests always writes status to well-known custom resource you can override all this environment
variables (excluding STATUS_CUSTOM_RESOURCE_NAMESPACE
) in your docker file and set namespace in helm chart.
Both of this approaches work with native k8s entities too. For example,
STATUS_CUSTOM_RESOURCE_GROUP=apps
STATUS_CUSTOM_RESOURCE_VERSION=v1
STATUS_CUSTOM_RESOURCE_NAMESPACE=zookeeper-service
STATUS_CUSTOM_RESOURCE_PLURAL=deployments
STATUS_CUSTOM_RESOURCE_NAME=zookeeper-1
If feature is available write_status.py
script is called two times. The first time immediately after docker entrypoint script
was started to set In progress
condition. The second time after tests are finished and parsed by analyze results
script
to set in the message
field tests results. Default analyzer script is write_status.py
but inheritor image can override it
by WRITE_STATUS_SCRIPT
environment variable which contains path to custom "write status" script.
By default, if all tests are passed BDI set Ready
value to type
condition field. There is an ability to deploy only
integration tests without any component (component was installed before). In this case you should set ONLY_INTEGRATION_TESTS
environment variable as true
and BDI will set Successful
as value of type
condition field.
The message
field in the status condition by default contains first line from result.txt
file (which is generated in the
previous step). To write full parsed result you should set IS_SHORT_STATUS_MESSAGE
environment variable to false
.
Important! If you use custom script to parse result (ANALYZE_RESULT_SCRIPT
is not empty) please pay attention that result
should be placed in the result.txt
file and the first line will be used as short status message.
Note! This feature (write status to k8s entities) is disabled by default! To turn on it please set the STATUS_WRITING_ENABLED
environment variable to true
.
For example in your docker file as
ENV STATUS_WRITING_ENABLED=true
Docker Integration Tests uses the following environment variables:
- DEBUG
- TTYD_PORT
- CUSTOM_ENTRYPOINT_SCRIPT
- SERVICE_CHECKER_SCRIPT
- SERVICE_CHECKER_SCRIPT_TIMEOUT
- IS_TAGS_RESOLVER_ENABLED
- IS_ANALYZER_RESULT_ENABLED
- ANALYZE_RESULT_SCRIPT
- STATUS_CUSTOM_RESOURCE_GROUP
- STATUS_CUSTOM_RESOURCE_VERSION
- STATUS_CUSTOM_RESOURCE_NAMESPACE
- STATUS_CUSTOM_RESOURCE_PLURAL
- STATUS_CUSTOM_RESOURCE_NAME
- ONLY_INTEGRATION_TESTS
- STATUS_CUSTOM_RESOURCE_PATH
- STATUS_WRITING_ENABLED
- WRITE_STATUS_SCRIPT
- IS_SHORT_STATUS_MESSAGE
- TAGS
- IS_STATUS_BOOLEAN
All of them instead of TAGS
, ONLY_INTEGRATION_TESTS
, STATUS_CUSTOM_RESOURCE_NAMESPACE
, STATUS_CUSTOM_RESOURCE_PATH
and maybe DEBUG
we recommend overriding in the docker file and do not forward them to the integration tests deployment environment.