Beispiel #1
0
 def _create_allow_rules_on_hosts(self, source, destinations):
     rule_list = []
     for destination in destinations:
         rule_list.append(
             (TrafficRule(Endpoint(source), Endpoint(destination),
                          Port(12345), Protocol.TCP, Connected.CONNECTED,
                          Action.ALLOW)))
         rule_list.append(
             (TrafficRule(Endpoint(source), Endpoint(destination),
                          Port(12345), Protocol.UDP, Connected.CONNECTED,
                          Action.ALLOW)))
     return rule_list
Beispiel #2
0
def create_mesh_ping_topo_from_cidr(hosts):
    """This function Returns list of rules for mesh ping"""
    rule_list = []
    for index, host in enumerate(hosts):
        destinations = hosts[index + 1:len(hosts)] + hosts[0:index]
        for destination in destinations:
            rule_list.append(
                TrafficRule(Endpoint(host), Endpoint(destination), Port(12345),
                            Protocol.TCP, Connected.CONNECTED, Action.ALLOW))
            rule_list.append(
                TrafficRule(Endpoint(host), Endpoint(destination), Port(12345),
                            Protocol.UDP, Connected.CONNECTED, Action.ALLOW))
    return rule_list
Beispiel #3
0
 def test_valid_endpoint_elements(self):
     self.traffic_element = TrafficRule(Endpoint('1.2.3.4'),
                                        Endpoint('2.3.4.5'),
                                        Port(12345),
                                        Protocol.UDP,
                                        Connected.CONNECTED,
                                        Action.ALLOW)
     self.assertIsInstance(self.traffic_element.src_eps, Endpoint)
     self.traffic_element.__repr__()
Beispiel #4
0
 def test_invalid_action_element(self):
     try:
         self.traffic_element = TrafficRule(Endpoint('1.2.3.4'),
                                            Endpoint('2.3.4.5'),
                                            Port(12345),
                                            'TCP',
                                            True,
                                            'FAKE_ACTION')
     except InvalidRuleError:
         pass
     except Exception as e:
         raise RuntimeError('Wrong exception is raised - %s' % e)
Beispiel #5
0
 def test_invalid_collected_element(self):
     try:
         self.traffic_element = TrafficRule(Endpoint('1.2.3.4'),
                                            Endpoint('2.3.4.5'),
                                            Port(12345),
                                            'TCP',
                                            'FAKE_CONNECTED',
                                            Action.ALLOW)
     except InvalidRuleError:
         pass
     except Exception as e:
         raise RuntimeError('Wrong exception is raised - %s' % e)
Beispiel #6
0
 def test_invalid_protocol_element(self):
     try:
         self.traffic_element = TrafficRule(Endpoint('1.2.3.4'),
                                            Endpoint('2.3.4.5'),
                                            Port(12345),
                                            'FAKE_PROTOCOL',
                                            Connected.CONNECTED,
                                            Action.ALLOW)
     except InvalidRuleError:
         pass
     except Exception as e:
         raise RuntimeError('Wrong exception is raised - %s' % e)
Beispiel #7
0
#!/usr/bin/env python
# Copyright (c) 2019 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: BSD-2 License
# The full license information can be found in LICENSE.txt
# in the root directory of this project.

import mock

from axon.tests import base as test_base
from axon.client.traffic_elements import TrafficRule, \
    Endpoint, Port, Protocol, Action, Connected
from axon.client.basic_traffic_controller import BasicTrafficController

rule_list = list()
rule_list.append(
    TrafficRule(Endpoint('1.2.3.4'), Endpoint('1.2.3.5'), Port(12345),
                Protocol.UDP, Connected.CONNECTED, Action.ALLOW))


class TestBasicTrafficController(test_base.BaseTestCase):
    """
    Test for Basic Traffic Controller utilities
    """
    def setUp(self):
        super(TestBasicTrafficController, self).setUp()
        self.traffic_controller = BasicTrafficController()

    @mock.patch('axon.client.axon_client.TrafficManger.register_traffic')
    @mock.patch('rpyc.connect')
    def test_register_traffic(self, mock_rpyc_conn, mock_register):
        rpyc_conn = mock_rpyc_conn.return_value
Beispiel #8
0
# SPDX-License-Identifier: BSD-2 License
# The full license information can be found in LICENSE.txt
# in the root directory of this project.

import mock

from axon.tests import base as test_base
from axon.client.traffic_elements import TrafficRule, \
    Endpoint, Port, Protocol, Action, Connected
from axon.client.datacenter_traffic_controller import \
    DataCenterTrafficController

rule_list = list()
rule_list.append(
    TrafficRule(Endpoint('1.2.3.4'), Endpoint('1.2.3.5'),
                Port(12345), Protocol.UDP, Connected.CONNECTED,
                Action.ALLOW)
)

workload_vif_map = {'1.2.3.4': '1.2.3.4', '1.2.3.5': '1.2.3.5'}


class TestDataCenterTrafficController(test_base.BaseTestCase):
    """
    Test for DataCenterTrafficController utilities
    """

    def setUp(self):
        super(TestDataCenterTrafficController, self).setUp()
        self._local_setup()