Ejemplo n.º 1
0
def _tc_network_state(client, device):
    cmd = ["tc", "qdisc", "show", "dev", device]
    output = docker_run(' '.join(cmd), client=client)
    states = tuple(set(output.split()) & set(NETWORKSTATE.keys()))
    states = [NETWORKSTATE[state] for state in states]
    # return "-".join(states) if states else NETWORKSTATE['normal']
    return states if states else [NETWORKSTATE['normal']]
Ejemplo n.º 2
0
def _other_network_state(client, device):
    cmd = ["ip", "link", "show", device]
    output =docker_run(' '.join(cmd), client=client)
    if "state DOWN" in output:
        return [NETWORKSTATE['blackhole']]
    elif "state UP" in output:
        return [NETWORKSTATE['normal']]
    else:
        return [NETWORKSTATE['normal']]
Ejemplo n.º 3
0
    def update_network_devices(self):
        chaos_logger.debug("Getting network interfaces for containers")
        cmd = ["ip", "link"]
        host_res = docker_run(' '.join(cmd), client=self.client, stream=True)
        chaos_logger.debug("IP LINK \n %s" % host_res.decode('utf-8'))
        for service, val in self._services.items():
            chaos_logger.debug("Finding network interface for %s" % service)
            ctr = val['ctr_info']
            try:
                res = self.client.execute_command(
                    ctr, ['ip', 'link', 'show', 'eth0'],
                    split_res=False,
                    stream=False,
                    retry_on_error=False)
                if isinstance(res, (list, tuple)):
                    o, e = res
                    o = "".join(o) + "".join(e)
                    res = o
            except DockerClientException as e:
                res = e.message

            res = res.decode('utf-8')
            device = re.search('^([0-9]+):', res)
            if not device:
                chaos_logger.warning("Problem determining host device id"
                                     "for service '%s' - %s" % (service, res))
                self._services.pop(service)

            else:
                peer_idx = int(device.group(1))
                host_idx = peer_idx + 1
                host_rgx = '^%d: ([^:@]+)[:@]' % host_idx
                host_match = re.search(host_rgx, host_res, re.M)
                if not host_match:
                    chaos_logger.warning(
                        "Problem determining host network device "
                        "for service '%s' - %s, could not match host device "
                        "" % (service, res))
                    chaos_logger.debug("peer -id : %s , host_id: %s" %
                                       (peer_idx, host_idx))
                    self._services.pop(service)
                else:
                    host_device = host_match.group(1)
                    device = host_device  # NetworkDevice(host_device)
                    val['device'] = device
Ejemplo n.º 4
0
def _tc_netem(client, device, params):
    cmd = ["tc", "qdisc", "replace", "dev", device,
           "root", "netem"] + params
    resp = docker_run(' '.join(cmd), client=client)
    return resp
Ejemplo n.º 5
0
def _create_blackhole(client, device,):
    cmd = "ifconfig {} down".format(device)
    resp = docker_run(cmd, client=client)
    return resp
Ejemplo n.º 6
0
def _restore_other_nw_state(client, device):
    cmd = "ifconfig %s up" % device
    resp = docker_run(cmd, client=client)
    return resp
Ejemplo n.º 7
0
def _tc_restore(client, device):
    cmd = ["tc", "qdisc", "del", "dev", device, "root"]
    return docker_run(' '.join(cmd), client=client)