Пример #1
0
 def new_init(self):
     c1 = Container("host0", "pod", "container", "ip")
     c2 = Container("host1", "pod", "container", "ip")
     c3 = Container("host1", "pod", "container", "ip")
     c4 = Container("host2", "pod", "container", "ip")
     c5 = Container("host2", "pod", "container", "ip")
     self._containers = [c1, c2, c3, c4, c5]
Пример #2
0
def test_is_container_in_somelist_whitelist(monkeypatch):
    def new_init(self):
        self.is_whitelist = True
        self.is_blacklist = False
        self._somelist = [
            {'host': 1, 'pod': 2, 'container': 3, 'ip': 4},
            {'host': 1},
            {'container': 3},
            {'pod': 2},
            {'ip': 4},
            {'ip': 4, 'pod': 2},
        ]
    monkeypatch.setattr(SomeList, '__init__', new_init)
    containers = [
        (1, 2, 3, 4),
        (1, 0, 0, 0),
        (0, 2, 0, 0),
        (0, 0, 3, 0),
        (0, 0, 0, 4),
        (0, 2, 0, 4),
    ]
    for c in containers:
        cnt = Container(*c)
        sl = SomeList()
        assert sl.is_container_in_somelist(cnt)
Пример #3
0
def test_ncmp_check_connection(monkeypatch, mocker):
    def new_init(self):
        self._containers = []

    monkeypatch.setattr(NCMashedPotato, '__init__', new_init)

    c1 = Container("host0", "pod", "container", "ip")
    c2 = Container("host1", "pod", "container", "ip")

    ncmp = NCMashedPotato()

    ncmp.connect_get_namespaced_pod_exec = mocker.MagicMock()
    ncmp._check_connection(c1, c2)

    ncmp.connect_get_namespaced_pod_exec.assert_called_once_with(
        c1, ['/bin/sh', '-c', 'ping -c 2 ip'])
Пример #4
0
def test_container():
    host = "a"
    pod = "b"
    container = "c"
    ip = "d"
    cnt = Container(host, pod, container, ip)
    assert cnt.host == host
    assert cnt.pod == pod
    assert cnt.container == container
    assert cnt.ip == ip
Пример #5
0
def test_ncmp_validate_connection_between(monkeypatch, mocker):
    def new_init(self):
        self.connectivity_status = {}
        self.report = mocker.MagicMock()

    monkeypatch.setattr(NCMashedPotato, '__init__', new_init)

    c1 = Container("host0", "pod", "container", "ip")
    c2 = Container("host1", "pod", "container", "ip")

    ncmp = NCMashedPotato()

    ncmp._containers = [c1, c2]
    ncmp.connectivity_status = ncmp._generate_report_tempalte()

    ncmp._check_connection = mocker.MagicMock(return_value=ncmp.OK)

    ncmp._validate_connection_between(c1, c2)

    ncmp._check_connection.assert_called_once_with(c1, c2)
    ncmp.report.ok.assert_called_once()
Пример #6
0
def test_somelist_is_container_allowed_negative(monkeypatch):
    def new_init(self):
        self.is_whitelist = True
        self.is_blacklist = False
    def new_is_container_in_somelist(self, cnt):
        return False

    monkeypatch.setattr(SomeList, '__init__', new_init)
    monkeypatch.setattr(
        SomeList, 'is_container_in_somelist', new_is_container_in_somelist)
    
    cnt = Container(1, 2, 3, 4)    
    sl = SomeList()
    assert not sl.is_container_allowed(cnt)
Пример #7
0
def test_ncmp_containers_on_different_nodes(monkeypatch):
    def new_init(self):
        c1 = Container("host0", "pod", "container", "ip")
        c2 = Container("host1", "pod", "container", "ip")
        c3 = Container("host1", "pod", "container", "ip")
        c4 = Container("host2", "pod", "container", "ip")
        c5 = Container("host2", "pod", "container", "ip")
        self._containers = [c1, c2, c3, c4, c5]

    monkeypatch.setattr(NCMashedPotato, '__init__', new_init)
    cnt = Container("host0", "pod", "container", "ip")

    ncmp = NCMashedPotato()
    all_hosts = [i.host for i in
                 ncmp._containers_on_different_nodes(cnt)]
    assert len(all_hosts) == 3