def test_log_throttling_happens(self, logging_chart_throttled_deployment, test_namespace): """Check that logs are throttled per container""" pod_manifest = { 'apiVersion': 'v1', 'kind': 'Pod', 'metadata': { 'name': 'flood-logs', 'namespace': test_namespace }, 'spec': { 'containers': [{ 'image': 'alpine:latest', 'name': 'flood-logs', "args": [ "/bin/sh", "-c", "while true; do echo \"Flood the logs\" | tee /dev/stderr; sleep 0.25; done" ] }], 'restartPolicy': 'Never' } } logging_chart_throttled_deployment.launch_pod_manifest(pod_manifest) def _wait_for_elastic_hits(): result = self.query_elasticsearch_for_log(logging_chart_throttled_deployment, '(rate exceeded group_key) AND (period_s=1 limit=20 rate_limit_s=20 reset_rate_s=5)') return result['hits']['total']['value'] != 0 wait_until(_wait_for_elastic_hits, retry_timeout=500)
def _proxy(self, wait=True): self._proxy_proc = subprocess.Popen( "kubectl port-forward -n {} pod/echoserver {}:{}".format( self.namespace, self.local_port, self.LISTEN_PORT).split()) if wait: wait_until(self.is_proxied_locally)
def test_fluentd_ingests_logs_from_pod_stdout_into_elasticsearch(self, logging_chart_deployment, echoserver, test_namespace): expected_log = "simple were so well compounded" echoserver.print_to_stdout(expected_log) def _wait_for_elastic_hits(): result = self.query_elasticsearch_for_log(logging_chart_deployment, expected_log) return result['hits']['total']['value'] != 0 wait_until(_wait_for_elastic_hits, retry_timeout=500)
def launch_pod_manifest(self, manifest): """Starts a pod manifest in the namespace and waits for the status != Pending Helm does not know about this pod, so we delete it manually before the chart itself is deleted Parameters ---------- launch_pod_manifest : dict The manifest dictioenary: E.g { 'apiVersion': 'v1', 'kind': 'Pod', 'metadata': { 'name': 'flood-logs' }, 'spec': { 'containers': [{ 'image': 'alpine:latest', 'name': 'flood-logs' }] } } Returns ------- String The name of the pod """ api_instance = self._k8s_api.CoreV1Api() assert manifest['metadata'][ 'name'], "The manifest should have a pod name" pod_name = manifest['metadata']['name'] logging.info("+++ Launching pod: %s", pod_name) resp = api_instance.create_namespaced_pod( body=manifest, namespace=self._helm_adaptor.namespace) def _wait_for_pod_launch(): resp = api_instance.read_namespaced_pod( name=manifest['metadata']['name'], namespace=self._helm_adaptor.namespace) return resp.status.phase != 'Pending' wait_until(_wait_for_pod_launch, retry_timeout=500) logging.info("+++ Launced pod: %s", pod_name) self.additional_pods.append(pod_name) return pod_name
def test_tangodb_pod_should_have_mysql_server_running(tango_base_release, test_namespace): pod_name = [ pod.metadata.name for pod in tango_base_release.get_pods() if pod.metadata.name.startswith('tangodb-') ].pop() def tangodb_pod_is_running(): return tango_base_release.is_running(pod_name) wait_until(tangodb_pod_is_running) host = _connect_to_pod(pod_name, test_namespace) mysqld_proc = host.process.get(command="mysqld") assert mysqld_proc is not None
def _deploy(self, wait=True): subprocess.run("kubectl apply -n {} -f {}".format( self.namespace, self.DEFINITION_FILE).split(), check=True) if wait: wait_until(self.is_running)