Esempio n. 1
0
def test_unmirror_mac():
    class MockBcfProxy(BcfProxy):
        def __init__(self):
            self.endpoints = None
            self.span_fabric = None
            self.logger = MockLogger().logger

        def mirror_traffic(self,
                           seq,
                           mirror=True,
                           span_name='SPAN_FABRIC',
                           s_dict=None,
                           fabric_span_endpoint='',
                           **target_kwargs):
            pass

        def get_span_fabric(self):
            return self.span_fabric

    bcf = MockBcfProxy()

    filemap = {
        '/data/controller/applications/bcf/info/fabric/switch':
        'sample_switches.json',
        '/data/controller/applications/bcf/info/endpoint-manager/tenant':
        'sample_tenants.json',
        '/data/controller/applications/bcf/info/endpoint-manager/segment':
        'sample_segments.json',
        '/data/controller/applications/bcf/info/endpoint-manager/endpoint':
        'sample_endpoints.json',
        '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22]':
        'sample_span_fabric.json',
        # %22 = url-encoded double quotes
        '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22][dest-interface-group=%22INTERFACE_GROUP%22]':
        'sample_span_fabric.json',
    }
    proxy = None
    endpoints = None
    span_fabric = None
    controller = {
        'URI': 'http://localhost',
        'USER': username,
        'PASS': password,
        'SPAN_FABRIC_NAME': 'SPAN_FABRIC',
        'INTERFACE_GROUP': 'INTERFACE_GROUP'
    }
    with HTTMock(mock_factory(r'.*', filemap)):
        proxy = BcfProxy(controller, 'login')

        endpoints = proxy.get_endpoints()
        span_fabric = proxy.get_span_fabric()

    bcf.endpoints = endpoints
    bcf.span_fabric = span_fabric
    ret_val = bcf.unmirror_mac('00:00:00:00:00:01')
Esempio n. 2
0
def test_get_seq_by_mac():
    class MockBcfProxy(BcfProxy):
        def __init__(self):
            self.endpoints = None
            self.span_fabric = None
            self.logger = MockLogger().logger
            self.trust_self_signed_cert = True

        def get_endpoints(self):
            return self.endpoints

        def get_span_fabric(self):
            return self.span_fabric

    bcf = MockBcfProxy()

    filemap = {
        '/data/controller/applications/bcf/info/fabric/switch':
        'sample_switches.json',
        '/data/controller/applications/bcf/info/endpoint-manager/tenant':
        'sample_tenants.json',
        '/data/controller/applications/bcf/info/endpoint-manager/segment':
        'sample_segments.json',
        '/data/controller/applications/bcf/info/endpoint-manager/endpoint':
        'sample_endpoints.json',
        '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22]':
        'sample_span_fabric.json',
        # %22 = url-encoded double quotes
        '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22][dest-interface-group=%22INTERFACE_GROUP%22]':
        'sample_span_fabric.json',
    }
    proxy = None
    endpoints = None
    span_fabric = None
    controller = {
        'URI': 'http://localhost',
        'USER': username,
        'PASS': password,
        'SPAN_FABRIC_NAME': 'SPAN_FABRIC',
        'INTERFACE_GROUP': 'INTERFACE_GROUP',
        'TRUST_SELF_SIGNED_CERT': True
    }
    with HTTMock(mock_factory(r'.*', filemap)):
        proxy = BcfProxy(controller, 'login')

        endpoints = proxy.get_endpoints()
        span_fabric = proxy.get_span_fabric()

    bcf.endpoints = endpoints
    bcf.span_fabric = span_fabric
    ret_val = bcf.get_seq_by_mac('00:00:00:00:00:02')
    # TODO this test needs to actually do something with the switch/interface
    answer = []
    assert answer == ret_val
Esempio n. 3
0
def test_mirror_mac():

    class MockBcfProxy(BcfProxy):

        def __init__(self):
            self.endpoints = None
            self.span_fabric = None
            self.trust_self_signed_cert = True
            self.base_uri = None
            self.logger = MockLogger().logger

        def get_bymac(self, mac):
            return [{'mac': mac, 'name': 'foo', 'tenant': 'foo', 'segment': 'foo', 'attachment-point': 'foo'}]

        def get_span_fabric(self):
            return self.span_fabric

        def bad_get_highest(self, spanFabric):
            return None

    bcf = MockBcfProxy()

    filemap = {
        '/data/controller/applications/bcf/info/fabric/switch': 'sample_switches.json',
        '/data/controller/applications/bcf/info/endpoint-manager/tenant': 'sample_tenants.json',
        '/data/controller/applications/bcf/info/endpoint-manager/segment': 'sample_segments.json',
        '/data/controller/applications/bcf/info/endpoint-manager/endpoint': 'sample_endpoints.json',
        '/data/controller/applications/bcf/span-fabric%5Bname=%22SPAN_FABRIC%22%5D': 'sample_span_fabric.json',
        # %22 = url-encoded double quotes
        '/data/controller/applications/bcf/span-fabric%5Bname=%22SPAN_FABRIC%22%5D%5Bdest-interface-group=%22INTERFACE_GROUP%22%5D': 'sample_span_fabric.json',
    }

    proxy = None
    endpoints = None
    span_fabric = None
    controller = {'URI': 'http://localhost',
                  'USER': username, 'PASS': password, 'SPAN_FABRIC_NAME': 'SPAN_FABRIC', 'INTERFACE_GROUP': 'INTERFACE_GROUP', 'TRUST_SELF_SIGNED_CERT': True}
    with HTTMock(mock_factory(r'.*', filemap)):
        proxy = BcfProxy(controller, 'login')

        endpoints = proxy.get_endpoints()
        span_fabric = proxy.get_span_fabric()

    bcf.endpoints = endpoints
    bcf.span_fabric = span_fabric
    ret_val = bcf.mirror_mac('00:00:00:00:00:02', None, None)

    bcf.get_highest = bcf.bad_get_highest
    ret_val = bcf.mirror_mac('00:00:00:00:00:02', None, None)
Esempio n. 4
0
def test_get_seq_by_ip():
    class MockBcfProxy(BcfProxy):
        def __init__(self):
            self.endpoints = None
            self.span_fabric = None
            self.logger = MockLogger().logger

        def get_span_fabric(self):
            return self.span_fabric

    bcf = MockBcfProxy()

    filemap = {
        '/data/controller/applications/bcf/info/fabric/switch':
        'sample_switches.json',
        '/data/controller/applications/bcf/info/endpoint-manager/tenant':
        'sample_tenants.json',
        '/data/controller/applications/bcf/info/endpoint-manager/segment':
        'sample_segments.json',
        '/data/controller/applications/bcf/info/endpoint-manager/endpoint':
        'sample_endpoints.json',
        '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22]':
        'sample_span_fabric.json',
        # %22 = url-encoded double quotes
        '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22][dest-interface-group=%22INTERFACE_GROUP%22]':
        'sample_span_fabric.json',
    }
    proxy = None
    endpoints = None
    span_fabric = None
    controller = {
        'URI': 'http://localhost',
        'USER': username,
        'PASS': password,
        'SPAN_FABRIC_NAME': 'SPAN_FABRIC',
        'INTERFACE_GROUP': 'INTERFACE_GROUP'
    }
    with HTTMock(mock_factory(r'.*', filemap)):
        proxy = BcfProxy(controller, 'login')

        endpoints = proxy.get_endpoints()
        span_fabric = proxy.get_span_fabric()

    bcf.endpoints = endpoints
    bcf.span_fabric = span_fabric
    ret_val = bcf.get_seq_by_ip('10.0.0.2')
    answer = list()
    assert answer == ret_val
Esempio n. 5
0
def test_get_highest_no_filter():
    class MockBcfProxy(BcfProxy):
        def __init__(self):
            self.endpoints = None
            self.span_fabric = None
            self.logger = MockLogger().logger

    bcf = MockBcfProxy()

    filemap = {
        '/data/controller/applications/bcf/info/fabric/switch':
        'sample_switches.json',
        '/data/controller/applications/bcf/info/endpoint-manager/tenant':
        'sample_tenants.json',
        '/data/controller/applications/bcf/info/endpoint-manager/segment':
        'sample_segments.json',
        '/data/controller/applications/bcf/info/endpoint-manager/endpoint':
        'sample_endpoints.json',
        '/data/controller/applications/bcf/span-fabric%5Bname=%22SPAN_FABRIC%22%5D':
        'sample_span_fabric_empty.json',
        # %22 = url-encoded double quotes
        '/data/controller/applications/bcf/span-fabric%5Bname=%22SPAN_FABRIC%22%5D%5Bdest-interface-group=%22INTERFACE_GROUP%22%5D':
        'sample_span_fabric_empty.json',
    }
    proxy = None
    endpoints = None
    span_fabric = None
    controller = {
        'URI': 'http://localhost',
        'USER': username,
        'PASS': password,
        'SPAN_FABRIC_NAME': 'SPAN_FABRIC',
        'INTERFACE_GROUP': 'INTERFACE_GROUP',
        'TRUST_SELF_SIGNED_CERT': True
    }
    with HTTMock(mock_factory(r'.*', filemap)):
        proxy = BcfProxy(controller, 'login')

        proxy.check_connection()
        endpoints = proxy.get_endpoints()
        span_fabric = proxy.get_span_fabric()

    bcf.endpoints = endpoints
    bcf.span_fabric = span_fabric
    ret_val = bcf.get_highest(span_fabric)
    answer = 1

    assert answer == ret_val
Esempio n. 6
0
def test_BcfProxy():
    """
    Tests bcf
    """
    filemap = {
        '/data/controller/applications/bcf/info/fabric/switch':
        'sample_switches.json',
        '/data/controller/applications/bcf/info/endpoint-manager/tenant':
        'sample_tenants.json',
        '/data/controller/applications/bcf/info/endpoint-manager/segment':
        'sample_segments.json',
        '/data/controller/applications/bcf/info/endpoint-manager/endpoint':
        'sample_endpoints.json',
        '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22]':
        'sample_span_fabric.json',
        # %22 = url-encoded double quotes
        '/data/controller/applications/bcf/span-fabric[name=%22SPAN_FABRIC%22][dest-interface-group=%22INTERFACE_GROUP%22]':
        'sample_span_fabric.json',
        '/data/controller/applications/bcf/span-fabric[name=%22empty%22][dest-interface-group=%22empty%22]':
        'sample_span_fabric_empty.json',
    }
    proxy = None
    controller = {
        'URI': 'http://localhost',
        'USER': username,
        'PASS': password,
        'SPAN_FABRIC_NAME': 'SPAN_FABRIC',
        'INTERFACE_GROUP': 'INTERFACE_GROUP'
    }
    with HTTMock(mock_factory(r'.*', filemap)):
        proxy = BcfProxy(controller, 'login')

        endpoints = proxy.get_endpoints()
        assert endpoints
        switches = proxy.get_switches()
        assert switches
        tenants = proxy.get_tenants()
        assert tenants
        segments = proxy.get_segments()
        assert segments
        span_fabric = proxy.get_span_fabric()
        assert span_fabric
        span_fabric = proxy.get_span_fabric(span_name='SPAN_FABRIC')
        assert span_fabric
        span_fabric = proxy.get_span_fabric(span_name='empty',
                                            interface_group='empty')
        assert not span_fabric

    with HTTMock(mock_factory2(r'.*')):
        # Normally shutdown_endpoint does not return a value.
        # You should call get_endpoint() afterwards to verify that a shutdown request went through.
        # In addition, the mock endpoint generated does not check for duplicates.
        # TODO: ***This code below is temporary.***
        r = proxy.shutdown_endpoint(tenant='TENANT',
                                    segment='SEGMENT',
                                    endpoint_name='test',
                                    mac='00:00:00:00:00:00',
                                    shutdown=True)
        assert r
        r = proxy.shutdown_endpoint(tenant='TENANT',
                                    segment='SEGMENT',
                                    endpoint_name='test',
                                    mac='00:00:00:00:00:00',
                                    shutdown=False)
        assert r

        r = proxy.mirror_traffic(seq=2,
                                 mirror=True,
                                 tenant='TENANT',
                                 segment='SEGMENT')
        assert r
        r = proxy.mirror_traffic(seq=2, mirror=False)
        assert r

    def r():
        return True

    r.text = ''

    # cover object
    assert r()

    BcfProxy.parse_json(r)

    proxy.session.cookies.clear_session_cookies()

    proxy.base_uri = 'http://jsonplaceholder.typicode.com'
    r = proxy.post_resource('posts')
    r.raise_for_status()
    r = proxy.request_resource(
        method='PUT', url='http://jsonplaceholder.typicode.com/posts/1')
    r.raise_for_status()