Skip to content

Commit

Permalink
Merge pull request #1 from Nilsty/logs
Browse files Browse the repository at this point in the history
Add keyword and tests for "Get Pod Logs"
  • Loading branch information
Nilsty authored Aug 6, 2020
2 parents 1d3b424 + 56c0373 commit e545044
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
*.pyo
src/robotframework_kubelibrary.egg-info/
dist/
build/
build/

log.html
output.xml
report.html
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ export KLIB_RESOURCE_REQUESTS_MEMORY=20Mi
robot -i octopus testcases/
# run other library tests
kubectl create namespace kubelib-tests
helm install kubelib-test ./test-objects-chart -n kubelib-tests
kubectl create namespace $KLIB_POD_NAMESPACE
helm install kubelib-test ./test-objects-chart -n $KLIB_POD_NAMESPACE
export KLIB_POD_PATTERN='busybox.*'
export KLIB_POD_NAMESPACE=kubelib-tests
robot -i other testcases/
```
Expand Down
2 changes: 1 addition & 1 deletion docs/KubeLibrary.html

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/KubeLibrary/KubeLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ def get_pods_in_namespace(self, name_pattern, namespace):
r = re.compile(name_pattern)
pods = [item for item in ret.items if r.match(item.metadata.name)]
return pods

def get_pod_logs(self, name, namespace, container):
"""Gets container logs of given pod in given namespace.
Returns logs.
- ``name``:
Pod name to check
- ``namespace``:
Namespace to check
- ``container``:
Container to check
"""
pod_logs = self.v1.read_namespaced_pod_log(name=name, namespace=namespace, container=container, follow=False)
return pod_logs

def get_configmaps_in_namespace(self, name_pattern, namespace):
"""Gets configmaps matching pattern in given namespace.
Expand Down
7 changes: 7 additions & 0 deletions testcases/pod/pod.robot
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ Pod has correct env variables
Given waited for pods matching "${KLIB_POD_PATTERN}" in namespace "${KLIB_POD_NAMESPACE}" to be running
When getting pods matching "${KLIB_POD_PATTERN}" in namespace "${KLIB_POD_NAMESPACE}"
Then pods containers have env variables "${KLIB_ENV_VARS}"

Logs of pod are available
[Tags] other
Given waited for pods matching "${KLIB_POD_PATTERN}" in namespace "${KLIB_POD_NAMESPACE}" to be running
When getting pods matching "${KLIB_POD_PATTERN}" in namespace "${KLIB_POD_NAMESPACE}"
Then logs of pod can be retrived
And logs contain expected string
9 changes: 9 additions & 0 deletions testcases/pod/pod_kw.robot
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ pods containers have env variables "${container_env_vars}"
${assertion}= assert_container_has_env_vars ${container} ${container_env_vars}
Should Be True ${assertion}
END

logs of pod can be retrived
Set Test Variable ${POD_NAME} ${namespace_pods[0].metadata.name}
${pod_logs}= Get Pod Logs ${POD_NAME} ${KLIB_POD_NAMESPACE} busybox
Log ${pod_logs} console=True
Set Test Variable ${POD_LOGS} ${pod_logs}

logs contain expected string
Should Contain ${POD_LOGS} I am

0 comments on commit e545044

Please sign in to comment.