<commit_before># -*- coding: utf-8 -*-

# This file is part of Cockpit.
#
# Copyright (C) 2016 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import os
import subprocess
import re
import sys
import time

try:
    import testlib
except ImportError:
    from common import testlib

base_dir = os.path.dirname(os.path.realpath(__file__))

__all__ = (
    'KubernetesCase',
    'KubernetesCommonTests',
    'OpenshiftCommonTests',
    'RegistryTests',
)

class KubernetesCase(testlib.MachineCase):
    provision = {
        "machine1": { "address": "10.111.113.1/20" }
    }

    def setUp(self):
        testlib.MachineCase.setUp(self)
        self.browser.wait_timeout(120)

    def stop_kubernetes(self):
        try:
            self.machine.execute('/etc/kubernetes/stop-kubernetes')
        except subprocess.CalledProcessError:
            self.machine.execute("systemctl stop kube-apiserver")

    def start_kubernetes(self):
        # kubelet needs the config to register to the API server
        self.machine.upload(["verify/files/mock-kube-config-basic.json"], "/etc/kubernetes/kubeconfig")
        self.machine.execute("""sed -i '/KUBELET_ARGS=/ { s%"$% --kubeconfig=/etc/kubernetes/kubeconfig"% }' /etc/kubernetes/kubelet""")

        # HACK: These are the default container secrets that which conflict
        # with kubernetes secrets and cause the pod to not start
        self.machine.execute("rm -rf /usr/share/rhel/secrets/* || true")
        self.machine.execute("systemctl start docker || journalctl -u docker")

        # HACK: work around https://github.com/kubernetes/kubernetes/issues/43805 until
        # the fix lands in Fedora 26
        if self.machine.image == "fedora-26":
            self.machine.execute("""sed -i '/KUBELET_ARGS=/ { s/"$/ --cgroup-driver=systemd"/ }' /etc/kubernetes/kubelet""")

        # disable swap, newer kubernetes versions don't like it:
        # failed to run Kubelet: Running with swap on is not supported, please disable swap! or set --fail-swap-on flag to false
        self.machine.execute("swapoff --all --verbose")

        self.machine.execute("echo 'KUBE_API_ADDRESS=\"$KUBE_API_ADDRESS --bind-address=10.111.113.1\"' >> /etc/kubernetes/apiserver")
        try:
            self.machine.execute('/etc/kubernetes/start-kubernetes')
        except subprocess.CalledProcessError:
            self.machine.execute("systemctl start etcd kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet")

    # HACK: https://github.com/GoogleCloudPlatform/kubernetes/issues/8311
    # Work around for the fact that kube-apiserver doesn't notify about startup
    # We wait until available or timeout.
    def wait_api_server(self, address="127.0.0.1", port=8080, timeout=120, scheme='http'):
        waiter = """
        for a in $(seq 0 {timeout}); do
            if curl -o /dev/null -k -s {scheme}://{address}:{port}; then
                if kubectl get all | grep -q s.*v.*c.*/kubernetes; then<commit_msg>test: Disable kubernetes image eviction<commit_after># -*- coding: utf-8 -*-

# This file is part of Cockpit.
#
# Copyright (C) 2016 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import os
import subprocess
import re
import sys
import time

try:
    import testlib
except ImportError:
    from common import testlib

base_dir = os.path.dirname(os.path.realpath(__file__))

__all__ = (
    'KubernetesCase',
    'KubernetesCommonTests',
    'OpenshiftCommonTests',
    'RegistryTests',
)

class KubernetesCase(testlib.MachineCase):
    provision = {
        "machine1": { "address": "10.111.113.1/20" }
    }

    def setUp(self):
        testlib.MachineCase.setUp(self)
        self.browser.wait_timeout(120)

    def stop_kubernetes(self):
        try:
            self.machine.execute('/etc/kubernetes/stop-kubernetes')
        except subprocess.CalledProcessError:
            self.machine.execute("systemctl stop kube-apiserver")

    def start_kubernetes(self):
        # kubelet needs the config to register to the API server
        self.machine.upload(["verify/files/mock-kube-config-basic.json"], "/etc/kubernetes/kubeconfig")
        self.machine.execute("""sed -i '/KUBELET_ARGS=/ { s%"$% --kubeconfig=/etc/kubernetes/kubeconfig"% }' /etc/kubernetes/kubelet""")

        # disable imagefs eviction to protect our docker images
        self.machine.execute("""sed -i '/KUBELET_ARGS=/ { s/"$/ --eviction-hard=imagefs.available<0% --eviction-soft=imagefs.available<0%"/ }' /etc/kubernetes/kubelet""")

        # HACK: These are the default container secrets that which conflict
        # with kubernetes secrets and cause the pod to not start
        self.machine.execute("rm -rf /usr/share/rhel/secrets/* || true")
        self.machine.execute("systemctl start docker || journalctl -u docker")

        # HACK: work around https://github.com/kubernetes/kubernetes/issues/43805 until
        # the fix lands in Fedora 26
        if self.machine.image == "fedora-26":
            self.machine.execute("""sed -i '/KUBELET_ARGS=/ { s/"$/ --cgroup-driver=systemd"/ }' /etc/kubernetes/kubelet""")

        # disable swap, newer kubernetes versions don't like it:
        # failed to run Kubelet: Running with swap on is not supported, please disable swap! or set --fail-swap-on flag to false
        self.machine.execute("swapoff --all --verbose")

        self.machine.execute("echo 'KUBE_API_ADDRESS=\"$KUBE_API_ADDRESS --bind-address=10.111.113.1\"' >> /etc/kubernetes/apiserver")
        try:
            self.machine.execute('/etc/kubernetes/start-kubernetes')
        except subprocess.CalledProcessError:
            self.machine.execute("systemctl start etcd kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet")

    # HACK: https://github.com/GoogleCloudPlatform/kubernetes/issues/8311
    # Work around for the fact that kube-apiserver doesn't notify about startup
    # We wait until available or timeout.
    def wait_api_server(self, address="127.0.0.1", port=8080, timeout=120, scheme='http'):
        waiter = """
        for a in $(seq 0 {timeout}); do
            if curl -o /dev/null -k -s {scheme}://{address}:{port}; then
                if kubectl get all | grep -q s.*v.*c.*/kubernetes; then
{'fraction_non_alphanumeric': 0.11686390532544379, 'fraction_numerical': 0.015868746637977407, 'mean_word_length': 3.0885101704233096, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7021678', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2154, 'n_words': 668}