Esempio n. 1
0
    def check_cant_udp(self, ip, retries=0):
        """
        Execute a udp check from this workload to the ip.  Assert that
        the workload cannot connect via udp to an IP.
        Use retries to allow for convergence.

        Use of this method assumes the network will be transitioning from a
        state where the destination is currently reachable.

        :param ip:  The ip to check connectivity to.
        :param retries: The number of retries.
        :return: None.
        """
        udp_check = self._get_udp_function(ip)

        def cant_udp():
            try:
                udp_check()
            except CommandExecError:
                pass
            else:
                raise _PingError()

        try:
            retry_until_success(cant_udp,
                                retries=retries,
                                ex_class=_PingError)
        except _PingError:
            return False

        return True
Esempio n. 2
0
    def __init__(self, name, start_calico=True, as_num=None):
        """
        Create a container using an image made for docker-in-docker. Load saved
        images into it.
        """
        self.name = name
        self.as_num = None

        pwd = sh.pwd().stdout.rstrip()
        docker.run("--privileged", "-v", pwd+":/code", "--name", self.name, "-tid", "jpetazzo/dind")

        # Since `calicoctl node` doesn't fix ipv6 forwarding and module loading, we must manually fix it
        self.calicoctl("checksystem --fix")

        self.ip = docker.inspect("--format", "{{ .NetworkSettings.IPAddress }}",
                                 self.name).stdout.rstrip()

        self.ip6 = docker.inspect("--format", "{{ .NetworkSettings.GlobalIPv6Address }}",
                             self.name).stdout.rstrip()

        # Make sure docker is up
        docker_ps = partial(self.execute, "docker ps")
        retry_until_success(docker_ps, ex_class=ErrorReturnCode)
        self.execute("docker load --input /code/calico_containers/calico-node.tar")
        self.execute("docker load --input /code/calico_containers/busybox.tar")

        if start_calico:
            self.start_calico_node()
            self.assert_powerstrip_up()
Esempio n. 3
0
    def __init__(self, name, start_calico=True, dind=True,
                 additional_docker_options="",
                 post_docker_commands=["docker load -i /code/calico-node.tar",
                                       "docker load -i /code/busybox.tar"]):
        self.name = name
        self.dind = dind
        self.workloads = set()

        # This variable is used to assert on destruction that this object was
        # cleaned up.  If not used as a context manager, users of this object
        self._cleaned = False

        if dind:
            log_and_run("docker rm -f %s || true" % self.name)
            log_and_run("docker run --privileged -tid "
                        "-v %s/docker:/usr/local/bin/docker "
                        "-v %s:/code --name %s "
                        "calico/dind:latest docker daemon --storage-driver=aufs %s" %
                    (CHECKOUT_DIR, CHECKOUT_DIR, self.name, additional_docker_options))

            self.ip = log_and_run("docker inspect --format "
                              "'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" % self.name)

            # Make sure docker is up
            docker_ps = partial(self.execute, "docker ps")
            retry_until_success(docker_ps, ex_class=CalledProcessError,
                                retries=10)
            for command in post_docker_commands:
                self.execute(command)
        else:
            self.ip = get_ip(v6=False)
            self.ip6 = get_ip(v6=True)

        if start_calico:
            self.start_calico_node()
Esempio n. 4
0
    def assert_cant_tcp(self, ip, retries=0):
        """
        Execute a ping from this workload to an ip.
        Assert that the workload cannot connect to an IP using tcp.
        Use retries to allow for convergence.

        Use of this method assumes the network will be transitioning from a
        state where the destination is currently reachable.

        :param ip:  The ip to check connectivity to.
        :param retries: The number of retries.
        :return: None.
        """
        tcp_check = self._get_tcp_function(ip)

        def cant_tcp():
            try:
                tcp_check()
            except CommandExecError:
                pass
            else:
                raise _PingError()

        try:
            retry_until_success(cant_tcp, retries=retries, ex_class=_PingError)
        except _PingError:
            raise AssertionError("%s can connect with tcp to %s" % (self, ip))
Esempio n. 5
0
    def assert_cant_ping(self, ip, retries=0):
        """
        Execute a ping from this workload to the ip.  Assert that the workload
        cannot ping an IP.  Use retries to allow for convergence.

        Use of this method assumes the network will be transitioning from a
        state where the destination is currently reachable.

        :param ip:  The IP address (str or IPAddress) to ping.
        :param retries: The number of retries.
        :return: None.
        """
        ping = self._get_ping_function(ip)

        def cant_ping():
            try:
                ping()
            except CommandExecError:
                pass
            else:
                raise _PingError()

        try:
            retry_until_success(cant_ping,
                                retries=retries,
                                ex_class=_PingError)
        except _PingError:
            raise AssertionError("%s can ping %s" % (self, ip))
Esempio n. 6
0
    def check_cant_udp(self, ip, retries=0):
        """
        Execute a udp check from this workload to the ip.  Assert that
        the workload cannot connect via udp to an IP.
        Use retries to allow for convergence.

        Use of this method assumes the network will be transitioning from a
        state where the destination is currently reachable.

        :param ip:  The ip to check connectivity to.
        :param retries: The number of retries.
        :return: None.
        """
        udp_check = self._get_udp_function(ip)

        def cant_udp():
            try:
                udp_check()
            except CommandExecError:
                pass
            else:
                raise _PingError()

        try:
            retry_until_success(cant_udp, retries=retries, ex_class=_PingError)
        except _PingError:
            return False

        return True
Esempio n. 7
0
    def __init__(self, host, name, image="busybox", network="bridge", ip=None, labels=[]):
        """
        Create the workload and detect its IPs.

        :param host: The host container on which this workload is instantiated.
        All commands executed by this container will be passed through the host
        via docker exec.
        :param name: The name given to the workload container. This name is
        passed to docker and can be used inside docker commands.
        :param image: The docker image to be used to instantiate this
        container. busybox used by default because it is extremely small and
        has ping.
        :param network: The DockerNetwork to connect to.  Set to None to use
        default Docker networking.
        :param ip: The ip address to assign to the container.
        :param labels: List of labels '<var>=<value>' to add to workload.
        """
        self.host = host
        self.name = name

        lbl_args = ""
        for label in labels:
            lbl_args += " --label %s" % (label)

        ip_option = ("--ip %s" % ip) if ip else ""
        command = "docker run -tid --name %s --net %s %s %s %s" % \
                  (name, network, lbl_args, ip_option, image)
        docker_run_wl = partial(host.execute, command)
        retry_until_success(docker_run_wl)
        self.ip = host.execute(
            "docker inspect --format "
            "'{{.NetworkSettings.Networks.%s.IPAddress}}' %s"
            % (network, name))
Esempio n. 8
0
    def __init__(self, name, start_calico=True, dind=True,
                 additional_docker_options="",
                 post_docker_commands=["docker load -i /code/calico-node.tar",
                                       "docker load -i /code/busybox.tar"],
                 calico_node_autodetect_ip=False):
        self.name = name
        self.dind = dind
        self.workloads = set()
        self.ip = None
        """
        An IP address value to pass to calicoctl as `--ip`. If left as None, no value will be passed,
        forcing calicoctl to do auto-detection.
        """

        self.ip6 = None
        """
        An IPv6 address value to pass to calicoctl as `--ipv6`. If left as None, no value will be passed.
        """

        # This variable is used to assert on destruction that this object was
        # cleaned up.  If not used as a context manager, users of this object
        self._cleaned = False

        docker_args = "--privileged -tid " \
                      "-v /lib/modules:/lib/modules " \
                      "-v %s/certs:%s/certs -v %s:/code --name %s" % \
                      (CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR,
                       self.name)
        if ETCD_SCHEME == "https":
            docker_args += " --add-host %s:%s" % (ETCD_HOSTNAME_SSL, get_ip())

        if dind:
            log_and_run("docker rm -f %s || true" % self.name)
            # Pass the certs directory as a volume since the etcd SSL/TLS
            # environment variables use the full path on the host.
            # Set iptables=false to prevent iptables error when using dind libnetwork
            log_and_run("docker run %s "
                        "calico/dind:latest "
                        " --storage-driver=aufs "
                        "--iptables=false "
                        "%s" %
                    (docker_args, additional_docker_options))

            self.ip = log_and_run("docker inspect --format "
                              "'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" % self.name)

            # Make sure docker is up
            docker_ps = partial(self.execute, "docker ps")
            retry_until_success(docker_ps, ex_class=CalledProcessError,
                                retries=10)
            for command in post_docker_commands:
                self.execute(command)
        elif not calico_node_autodetect_ip:
            # Find the IP so it can be specified as `--ip` when launching node later.
            self.ip = get_ip(v6=False)
            self.ip6 = get_ip(v6=True)

        if start_calico:
            self.start_calico_node()
Esempio n. 9
0
    def __init__(self,
                 host,
                 name,
                 image="busybox",
                 network="bridge",
                 ip=None,
                 labels=[],
                 namespace=None):
        """
        Create the workload and detect its IPs.

        :param host: The host container on which this workload is instantiated.
        All commands executed by this container will be passed through the host
        via docker exec.
        :param name: The name given to the workload container. This name is
        passed to docker and can be used inside docker commands.
        :param image: The docker image to be used to instantiate this
        container. busybox used by default because it is extremely small and
        has ping.
        :param network: The name of the network to connect to.
        :param ip: The ip address to assign to the container.
        :param labels: List of labels '<var>=<value>' to add to workload.
        :param namespace: The namespace this pod should be in.  'None' is valid and will cause
        CNI to be called without the namespace being set (useful for checking that it
        defaults correctly)
        """
        self.host = host
        self.name = name
        self.network = network
        assert self.network is not None
        self.namespace = namespace

        lbl_args = ""
        for label in labels:
            lbl_args += " --label %s" % (label)

        net_options = "--net=none"
        if self.host.networking == NETWORKING_LIBNETWORK:
            ip_option = (" --ip %s" % ip) if ip else ""
            net_options = "--net %s%s" % (network, ip_option)

        command = "docker run -tid --name %s %s %s %s" % (name, net_options,
                                                          lbl_args, image)
        docker_run_wl = partial(host.execute, command)
        retry_until_success(docker_run_wl)

        if self.host.networking == NETWORKING_LIBNETWORK:
            self.ip = host.execute(
                "docker inspect --format "
                "'{{.NetworkSettings.Networks.%s.IPAddress}}' %s" %
                (network, name))
        else:
            self.run_cni("ADD", ip=ip)
Esempio n. 10
0
    def __init__(self,
                 name,
                 start_calico=True,
                 dind=True,
                 additional_docker_options="",
                 post_docker_commands=[
                     "docker load -i /code/calico-node.tar",
                     "docker load -i /code/busybox.tar"
                 ]):
        self.name = name
        self.dind = dind
        self.workloads = set()

        # This variable is used to assert on destruction that this object was
        # cleaned up.  If not used as a context manager, users of this object
        self._cleaned = False

        docker_args = "--privileged -tid -v %s/docker:/usr/local/bin/docker " \
                      "-v %s/certs:%s/certs -v %s:/code --name %s" % \
                      (CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR,
                       self.name)
        if ETCD_SCHEME == "https":
            docker_args += " --add-host %s:%s" % (ETCD_HOSTNAME_SSL, get_ip())

        if dind:
            log_and_run("docker rm -f %s || true" % self.name)
            # Pass the certs directory as a volume since the etcd SSL/TLS
            # environment variables use the full path on the host.
            log_and_run("docker run %s "
                        "calico/dind:latest "
                        "docker daemon --storage-driver=aufs %s" %
                        (docker_args, additional_docker_options))

            self.ip = log_and_run(
                "docker inspect --format "
                "'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" %
                self.name)

            # Make sure docker is up
            docker_ps = partial(self.execute, "docker ps")
            retry_until_success(docker_ps,
                                ex_class=CalledProcessError,
                                retries=10)
            for command in post_docker_commands:
                self.execute(command)
        else:
            self.ip = get_ip(v6=False)
            self.ip6 = get_ip(v6=True)

        if start_calico:
            self.start_calico_node()
Esempio n. 11
0
    def __init__(
        self,
        name,
        start_calico=True,
        dind=True,
        additional_docker_options="",
        post_docker_commands=[
            "docker load --input /code/calico_containers/calico-node.tar",
            "docker load --input /code/calico_containers/busybox.tar"
        ]):
        self.name = name
        self.dind = dind
        self.workloads = set()

        # This variable is used to assert on destruction that this object was
        # cleaned up.  If not used as a context manager, users of this object
        self._cleaned = False

        if dind:
            log_and_run("docker rm -f %s || true" % self.name)
            log_and_run(
                "docker run --privileged -tid "
                "-v %s/docker:/usr/local/bin/docker "
                "-v %s:/code --name %s "
                "calico/dind:latest docker daemon --storage-driver=aufs %s" %
                (os.getcwd(), os.getcwd(), self.name,
                 additional_docker_options))

            self.ip = log_and_run(
                "docker inspect --format "
                "'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" %
                self.name)

            # Make sure docker is up
            docker_ps = partial(self.execute, "docker ps")
            retry_until_success(docker_ps,
                                ex_class=CalledProcessError,
                                retries=10)
            for command in post_docker_commands:
                self.execute(command)
        else:
            self.ip = get_ip()

        if start_calico:
            self.start_calico_node()
    def test_add_container(self):
        """
        Test adding container to calico networking after it exists.
        """
        host = DockerHost('host')

        node = host.create_workload("node")

        # Use the `container add` command instead of passing a CALICO_IP on
        # container creation. Note this no longer needs DOCKER_HOST specified.
        host.calicoctl("container add %s 192.168.1.1" % node.name)

        host.calicoctl("profile add TEST_GROUP")
        host.calicoctl("profile TEST_GROUP member add %s" % node.name)

        # Wait for felix to program down the route.
        check_route = partial(host.execute, "ip route | grep '192\.168\.1\.1'")
        retry_until_success(check_route, ex_class=ErrorReturnCode)
Esempio n. 13
0
    def check_can_tcp_asym(self, ip, retries=0):
        """
        Execute a tcp check from this ip to the other ip.
        Assert that a ip can connect to another ip.
        Use retries to allow for convergence.
        Use of this method assumes the network will be transitioning from a
        state where the destination is currently unreachable.
        :param ip:  The ip to check connectivity to.
        :param retries: The number of retries.
        :return: None.
        """
        try:
            retry_until_success(self._get_tcp_asym_function(ip),
                                retries=retries,
                                ex_class=CommandExecError)
        except CommandExecError:
            return False

        return True
Esempio n. 14
0
    def check_can_tcp_asym(self, ip, retries=0):
        """
        Execute a tcp check from this ip to the other ip.
        Assert that a ip can connect to another ip.
        Use retries to allow for convergence.
        Use of this method assumes the network will be transitioning from a
        state where the destination is currently unreachable.
        :param ip:  The ip to check connectivity to.
        :param retries: The number of retries.
        :return: None.
        """
        try:
            retry_until_success(self._get_tcp_asym_function(ip),
                                retries=retries,
                                ex_class=CommandExecError)
        except CommandExecError:
            return False

        return True
Esempio n. 15
0
    def __init__(self, name, start_calico=True, dind=True,
                 additional_docker_options="",
                 post_docker_commands=["docker load -i /code/calico-node.tar",
                                       "docker load -i /code/busybox.tar"]):
        self.name = name
        self.dind = dind
        self.workloads = set()

        # This variable is used to assert on destruction that this object was
        # cleaned up.  If not used as a context manager, users of this object
        self._cleaned = False

        docker_args = "--privileged -tid -v %s/docker:/usr/local/bin/docker " \
                      "-v %s/certs:%s/certs -v %s:/code --name %s" % \
                      (CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR,
                       self.name)
        if ETCD_SCHEME == "https":
            docker_args += " --add-host %s:%s" % (ETCD_HOSTNAME_SSL, get_ip())

        if dind:
            log_and_run("docker rm -f %s || true" % self.name)
            # Pass the certs directory as a volume since the etcd SSL/TLS
            # environment variables use the full path on the host.
            log_and_run("docker run %s "
                        "calico/dind:latest "
                        "docker daemon --storage-driver=aufs %s" %
                    (docker_args, additional_docker_options))

            self.ip = log_and_run("docker inspect --format "
                              "'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" % self.name)

            # Make sure docker is up
            docker_ps = partial(self.execute, "docker ps")
            retry_until_success(docker_ps, ex_class=CalledProcessError,
                                retries=10)
            for command in post_docker_commands:
                self.execute(command)
        else:
            self.ip = get_ip(v6=False)
            self.ip6 = get_ip(v6=True)

        if start_calico:
            self.start_calico_node()
Esempio n. 16
0
    def assert_can_udp(self, ip, retries=0):
        """
        Execute a udp check from this workload to an ip.
        Assert that this workload can connect to another ip.
        Use retries to allow for convergence.

        Use of this method assumes the network will be transitioning from a
        state where the destination is currently unreachable.

        :param ip:  The ip to check connectivity to.
        :param retries: The number of retries.
        :return: None.
        """
        try:
            retry_until_success(self._get_udp_function(ip),
                                retries=retries,
                                ex_class=CommandExecError)
        except CommandExecError:
            raise AssertionError("%s cannot connect with udp to %s" %
                                 (self, ip))
Esempio n. 17
0
    def check_can_ping(self, ip, retries=0):
        """
        Execute a ping from this workload to the ip. Assert than a workload
        can ping an IP. Use retries to allow for convergence.

        Use of this method assumes the network will be transitioning from a
        state where the destination is currently unreachable.

        :param ip:  The IP address (str or IPAddress) to ping.
        :param retries: The number of retries.
        :return: None.
        """
        try:
            retry_until_success(self._get_ping_function(ip),
                                retries=retries,
                                ex_class=CommandExecError)
        except CommandExecError:
            return False

        return True
Esempio n. 18
0
    def check_can_ping(self, ip, retries=0):
        """
        Execute a ping from this workload to the ip. Assert than a workload
        can ping an IP. Use retries to allow for convergence.

        Use of this method assumes the network will be transitioning from a
        state where the destination is currently unreachable.

        :param ip:  The IP address (str or IPAddress) to ping.
        :param retries: The number of retries.
        :return: None.
        """
        try:
            retry_until_success(self._get_ping_function(ip),
                                retries=retries,
                                ex_class=CommandExecError)
        except CommandExecError:
            return False

        return True
Esempio n. 19
0
    def assert_can_ping(self, ip, retries=0):
        """
        Execute a ping from this workload to the ip. Assert than a workload
        can ping an IP. Use retries to compensate for network uncertainty and
        convergence.
        """
        version = IPAddress(ip).version
        assert version in [4, 6]
        if version == 4:
            ping = "ping"
        elif version == 6:
            ping = "ping6"

        args = [
            ping,
            "-c", "1",  # Number of pings
            "-W", "1",  # Timeout for each ping
            ip,
        ]
        command = ' '.join(args)

        ping = partial(self.execute, command)
        return retry_until_success(ping, retries=retries, ex_class=ErrorReturnCode_1)
Esempio n. 20
0
    def __init__(self,
                 name,
                 start_calico=True,
                 dind=True,
                 additional_docker_options="",
                 post_docker_commands=[
                     "docker load -i /code/calico-node.tar",
                     "docker load -i /code/busybox.tar"
                 ],
                 calico_node_autodetect_ip=False,
                 simulate_gce_routing=False,
                 override_hostname=False,
                 networking=None):
        self.name = name
        self.dind = dind
        self.workloads = set()
        self.ip = None
        self.log_analyzer = None
        """
        An IP address value to pass to calicoctl as `--ip`. If left as None,
        no value will be passed, forcing calicoctl to do auto-detection.
        """

        self.ip6 = None
        """
        An IPv6 address value to pass to calicoctl as `--ipv6`. If left as
        None, no value will be passed.
        """

        self.override_hostname = None if not override_hostname else \
            uuid.uuid1().hex[:16]
        """
        Create an arbitrary hostname if we want to override.
        """

        if networking is None:
            self.networking = global_setting()
        else:
            self.networking = networking
        assert self.networking in [NETWORKING_CNI, NETWORKING_LIBNETWORK]

        # This variable is used to assert on destruction that this object was
        # cleaned up.  If not used as a context manager, users of this object
        # must invoke cleanup.
        self._cleaned = False

        docker_args = "--privileged -tid " \
                      "-v /lib/modules:/lib/modules " \
                      "-v %s/certs:%s/certs -v %s:/code --name %s" % \
                      (CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR,
                       self.name)
        if ETCD_SCHEME == "https":
            docker_args += " --add-host %s:%s" % (ETCD_HOSTNAME_SSL, get_ip())

        if dind:
            log_and_run("docker rm -f %s || true" % self.name)
            # Pass the certs directory as a volume since the etcd SSL/TLS
            # environment variables use the full path on the host.
            # Set iptables=false to prevent iptables error when using dind
            # libnetwork
            log_and_run("docker run %s "
                        "calico/dind:latest "
                        "--iptables=false "
                        "%s" % (docker_args, additional_docker_options))

            self.ip = log_and_run(
                "docker inspect --format "
                "'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" %
                self.name)

            # Make sure docker is up
            docker_ps = partial(self.execute, "docker ps")
            retry_until_success(docker_ps,
                                ex_class=CalledProcessError,
                                retries=10)

            if simulate_gce_routing:
                # Simulate addressing and routing setup as on a GCE instance:
                # the instance has a /32 address (which means that it appears
                # not to be directly connected to anything) and a default route
                # that does not have the 'onlink' flag to override that.
                #
                # First check that we can ping the Docker bridge, and trace out
                # initial state.
                self.execute("ping -c 1 -W 2 172.17.0.1")
                self.execute("ip a")
                self.execute("ip r")

                # Change the normal /16 IP address to /32.
                self.execute("ip a del %s/16 dev eth0" % self.ip)
                self.execute("ip a add %s/32 dev eth0" % self.ip)

                # Add a default route via the Docker bridge.
                self.execute("ip r a 172.17.0.1 dev eth0")
                self.execute("ip r a default via 172.17.0.1 dev eth0")

                # Trace out final state, and check that we can still ping the
                # Docker bridge.
                self.execute("ip a")
                self.execute("ip r")
                self.execute("ping -c 1 -W 2 172.17.0.1")

            for command in post_docker_commands:
                self.execute(command)
        elif not calico_node_autodetect_ip:
            # Find the IP so it can be specified as `--ip` when launching
            # node later.
            self.ip = get_ip(v6=False)
            self.ip6 = get_ip(v6=True)

        if start_calico:
            self.start_calico_node()
Esempio n. 21
0
        {
            "_id": 2,
            "host": "database6:27018"
        },
    ],
    "settings": {
        "chainingAllowed": False,
        "electionTimeoutMillis": 2000,
        "heartbeatTimeoutSecs": 1,
        "catchUpTimeoutMillis": 0,
    },
}

# Create ConfigServerReplSet once all nodes are up
retry_until_success(mongo_process_running, {
    "host": "configsvr1",
    "port": 27019
})
retry_until_success(mongo_process_running, {
    "host": "configsvr2",
    "port": 27019
})
retry_until_success(mongo_process_running, {
    "host": "configsvr3",
    "port": 27019
})
retry_until_success(
    subprocess.run, {
        "args": [
            "mongo",
            "--host",
            "configsvr1",
Esempio n. 22
0
    def __init__(self, name, start_calico=True, dind=True,
                 additional_docker_options="",
                 post_docker_commands=["docker load -i /code/calico-node.tar",
                                       "docker load -i /code/busybox.tar"],
                 calico_node_autodetect_ip=False,
                 simulate_gce_routing=False,
                 override_hostname=False):
        self.name = name
        self.dind = dind
        self.workloads = set()
        self.ip = None
        self.log_analyzer = None
        """
        An IP address value to pass to calicoctl as `--ip`. If left as None,
        no value will be passed, forcing calicoctl to do auto-detection.
        """

        self.ip6 = None
        """
        An IPv6 address value to pass to calicoctl as `--ipv6`. If left as
        None, no value will be passed.
        """

        self.override_hostname = None if not override_hostname else \
            uuid.uuid1().hex[:16]
        """
        Create an arbitrary hostname if we want to override.
        """

        # This variable is used to assert on destruction that this object was
        # cleaned up.  If not used as a context manager, users of this object
        # must invoke cleanup.
        self._cleaned = False

        docker_args = "--privileged -tid " \
                      "-v /lib/modules:/lib/modules " \
                      "-v %s/certs:%s/certs -v %s:/code --name %s" % \
                      (CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR,
                       self.name)
        if ETCD_SCHEME == "https":
            docker_args += " --add-host %s:%s" % (ETCD_HOSTNAME_SSL, get_ip())

        if dind:
            log_and_run("docker rm -f %s || true" % self.name)
            # Pass the certs directory as a volume since the etcd SSL/TLS
            # environment variables use the full path on the host.
            # Set iptables=false to prevent iptables error when using dind
            # libnetwork
            log_and_run("docker run %s "
                        "calico/dind:latest "
                        "--iptables=false "
                        "%s" %
                        (docker_args, additional_docker_options))

            self.ip = log_and_run(
                "docker inspect --format "
                "'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" %
                self.name)

            # Make sure docker is up
            docker_ps = partial(self.execute, "docker ps")
            retry_until_success(docker_ps, ex_class=CalledProcessError,
                                retries=10)

            if simulate_gce_routing:
                # Simulate addressing and routing setup as on a GCE instance:
                # the instance has a /32 address (which means that it appears
                # not to be directly connected to anything) and a default route
                # that does not have the 'onlink' flag to override that.
                #
                # First check that we can ping the Docker bridge, and trace out
                # initial state.
                self.execute("ping -c 1 -W 2 172.17.0.1")
                self.execute("ip a")
                self.execute("ip r")

                # Change the normal /16 IP address to /32.
                self.execute("ip a del %s/16 dev eth0" % self.ip)
                self.execute("ip a add %s/32 dev eth0" % self.ip)

                # Add a default route via the Docker bridge.
                self.execute("ip r a 172.17.0.1 dev eth0")
                self.execute("ip r a default via 172.17.0.1 dev eth0")

                # Trace out final state, and check that we can still ping the
                # Docker bridge.
                self.execute("ip a")
                self.execute("ip r")
                self.execute("ping -c 1 -W 2 172.17.0.1")

            for command in post_docker_commands:
                self.execute(command)
        elif not calico_node_autodetect_ip:
            # Find the IP so it can be specified as `--ip` when launching
            # node later.
            self.ip = get_ip(v6=False)
            self.ip6 = get_ip(v6=True)

        if start_calico:
            self.start_calico_node()
Esempio n. 23
0
    def __init__(self,
                 name,
                 start_calico=True,
                 dind=True,
                 additional_docker_options="",
                 post_docker_commands=[
                     "docker load -i /code/calico-node.tar",
                     "docker load -i /code/busybox.tar"
                 ],
                 calico_node_autodetect_ip=False,
                 override_hostname=False):
        self.name = name
        self.dind = dind
        self.workloads = set()
        self.ip = None
        """
        An IP address value to pass to calicoctl as `--ip`. If left as None,
        no value will be passed, forcing calicoctl to do auto-detection.
        """

        self.ip6 = None
        """
        An IPv6 address value to pass to calicoctl as `--ipv6`. If left as
        None, no value will be passed.
        """

        self.override_hostname = None if not override_hostname else \
            uuid.uuid1().hex[:16]
        """
        Create an arbitrary hostname if we want to override.
        """

        # This variable is used to assert on destruction that this object was
        # cleaned up.  If not used as a context manager, users of this object
        self._cleaned = False

        docker_args = "--privileged -tid " \
                      "-v /lib/modules:/lib/modules " \
                      "-v %s/certs:%s/certs -v %s:/code --name %s" % \
                      (CHECKOUT_DIR, CHECKOUT_DIR, CHECKOUT_DIR,
                       self.name)
        if ETCD_SCHEME == "https":
            docker_args += " --add-host %s:%s" % (ETCD_HOSTNAME_SSL, get_ip())

        if dind:
            log_and_run("docker rm -f %s || true" % self.name)
            # Pass the certs directory as a volume since the etcd SSL/TLS
            # environment variables use the full path on the host.
            # Set iptables=false to prevent iptables error when using dind
            # libnetwork
            log_and_run("docker run %s "
                        "calico/dind:latest "
                        "--iptables=false "
                        "%s" % (docker_args, additional_docker_options))

            self.ip = log_and_run(
                "docker inspect --format "
                "'{{.NetworkSettings.Networks.bridge.IPAddress}}' %s" %
                self.name)

            # Make sure docker is up
            docker_ps = partial(self.execute, "docker ps")
            retry_until_success(docker_ps,
                                ex_class=CalledProcessError,
                                retries=10)
            for command in post_docker_commands:
                self.execute(command)
        elif not calico_node_autodetect_ip:
            # Find the IP so it can be specified as `--ip` when launching
            # node later.
            self.ip = get_ip(v6=False)
            self.ip6 = get_ip(v6=True)

        if start_calico:
            self.start_calico_node()
Esempio n. 24
0
    start = time()
    options = Options()
    options.add_argument("--headless")
    print("Opening browser")
    driver = webdriver.Firefox(options=options)
    driver.implicitly_wait(5)

    driver.get(env("URL"))

    driver.find_element_by_css_selector(".one-fourth > a").click()

    driver.execute_script("""
        $('#welcome-window').modal('hide')
    """)

    retry_until_success(lambda: driver.find_elements_by_css_selector(
        '.booking-list > li')[0].click())

    sleep(1)

    for element in driver.find_elements_by_css_selector('.booking-list > li'):
        if is_after_work(element) and has_available_spot(element):
            print(element.text.split('\n')[0])
            send_message(element.text)

    driver.quit()
    print(f"Done. ({time() - start}s)")

    sleep(60)
Esempio n. 25
0
 def assert_powerstrip_up(self):
     """
     Check that powerstrip is up by running 'docker ps' through port 2377.
     """
     powerstrip = partial(self.execute, "docker ps", use_powerstrip=True)
     retry_until_success(powerstrip, ex_class=ErrorReturnCode)