예제 #1
0
    def test_register_port_invalid_name_nexus(self):
        """Registering a port with an invalid name should fail"""

        api.switch_register('nexus',
                            type=NEXUS,
                            username="******",
                            password="******",
                            hostname="switchname",
                            dummy_vlan=2222)

        # test some random invalid port names for cisco nexus
        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('nexus', 'blah-blah')

        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('nexus', 'eethernet1/2')

        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('nexus', 'Ethernet1')

        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('nexus', 'Ethernet/12')

        # register some valid port names
        api.switch_register_port('nexus', 'Ethernet1/8')
        api.switch_register_port('nexus', 'Ethernet1/0/1')
        api.switch_register_port('nexus', 'ethernet1/2')
예제 #2
0
파일: dellnos9.py 프로젝트: CCI-MOC/hil
def test_ensure_legal_operations():
    """Test to ensure that ensure_legal_operations works as expected"""

    # create a project and a network
    api.project_create('anvil-nextgen')
    network_create_simple('hammernet', 'anvil-nextgen')
    network_create_simple('pineapple', 'anvil-nextgen')

    # register a switch of type dellnos9 and add a port to it
    api.switch_register('s3048',
                        type=SWITCH_TYPE,
                        username="******",
                        password="******",
                        hostname="switchname",
                        interface_type="GigabitEthernet")
    api.switch_register_port('s3048', '1/3')
    switch = api.get_or_404(model.Switch, 's3048')

    # register a ndoe and a nic
    api.node_register(
        node='compute-01',
        obmd={
            'uri': 'http://obmd.example.com',
            'admin_token': 'secret',
        },
    )
    api.project_connect_node('anvil-nextgen', 'compute-01')
    api.node_register_nic('compute-01', 'eth0', 'DE:AD:BE:EF:20:14')
    nic = api.get_or_404(model.Nic, 'eth0')

    api.port_connect_nic('s3048', '1/3', 'compute-01', 'eth0')

    # connecting a trunked network wihtout having a native should fail.
    # call the method directly and test the API too.
    with pytest.raises(BlockedError):
        switch.ensure_legal_operation(nic, 'connect', 'vlan/1212')

    with pytest.raises(BlockedError):
        api.node_connect_network('compute-01', 'eth0', 'hammernet', 'vlan/40')

    # doing these operations in the correct order, that is native network first
    # and then trunked, should work.
    api.node_connect_network('compute-01', 'eth0', 'hammernet', 'vlan/native')
    mock_networking_action()
    api.node_connect_network('compute-01', 'eth0', 'pineapple', 'vlan/41')
    mock_networking_action()

    # removing these networks in the wrong order should not work.
    with pytest.raises(BlockedError):
        switch.ensure_legal_operation(nic, 'detach', 'vlan/native')

    with pytest.raises(BlockedError):
        api.node_detach_network('compute-01', 'eth0', 'hammernet')

    # removing networks in the right order should work
    api.node_detach_network('compute-01', 'eth0', 'pineapple')
    mock_networking_action()
    api.node_detach_network('compute-01', 'eth0', 'hammernet')
    mock_networking_action()
    db.session.close()
예제 #3
0
def site_layout():
    """Load the file site-layout.json, and populate the database accordingly.

    This is meant to be used as a pytest fixture, but isn't declared
    here as such; individual modules should declare it as a fixture.

    Full documentation for the site-layout.json file format is located in
    ``docs/testing.md``.
    """
    layout_json_data = open('site-layout.json')
    layout = json.load(layout_json_data)
    layout_json_data.close()

    for switch in layout['switches']:
        api.switch_register(**switch)

    for node in layout['nodes']:
        api.node_register(
            node=node['name'],
            obm=node['obm'],
            obmd=node['obmd'],
        )
        for nic in node['nics']:
            api.node_register_nic(node['name'], nic['name'], nic['mac'])
            api.switch_register_port(nic['switch'], nic['port'])
            api.port_connect_nic(nic['switch'], nic['port'], node['name'],
                                 nic['name'])
예제 #4
0
def test_ensure_legal_operations():
    """Test to ensure that ensure_legal_operations works as expected"""

    # create a project and a network
    api.project_create('anvil-nextgen')
    network_create_simple('hammernet', 'anvil-nextgen')
    network_create_simple('pineapple', 'anvil-nextgen')

    # register a switch of type dellnos9 and add a port to it
    api.switch_register('s3048',
                        type=SWITCH_TYPE,
                        username="******",
                        password="******",
                        hostname="switchname",
                        interface_type="GigabitEthernet")
    api.switch_register_port('s3048', '1/3')
    switch = api.get_or_404(model.Switch, 's3048')

    # register a ndoe and a nic
    api.node_register(
        node='compute-01',
        obmd={
            'uri': 'http://obmd.example.com',
            'admin_token': 'secret',
        },
    )
    api.project_connect_node('anvil-nextgen', 'compute-01')
    api.node_register_nic('compute-01', 'eth0', 'DE:AD:BE:EF:20:14')
    nic = api.get_or_404(model.Nic, 'eth0')

    api.port_connect_nic('s3048', '1/3', 'compute-01', 'eth0')

    # connecting a trunked network wihtout having a native should fail.
    # call the method directly and test the API too.
    with pytest.raises(BlockedError):
        switch.ensure_legal_operation(nic, 'connect', 'vlan/1212')

    with pytest.raises(BlockedError):
        api.node_connect_network('compute-01', 'eth0', 'hammernet', 'vlan/40')

    # doing these operations in the correct order, that is native network first
    # and then trunked, should work.
    api.node_connect_network('compute-01', 'eth0', 'hammernet', 'vlan/native')
    mock_networking_action()
    api.node_connect_network('compute-01', 'eth0', 'pineapple', 'vlan/41')
    mock_networking_action()

    # removing these networks in the wrong order should not work.
    with pytest.raises(BlockedError):
        switch.ensure_legal_operation(nic, 'detach', 'vlan/native')

    with pytest.raises(BlockedError):
        api.node_detach_network('compute-01', 'eth0', 'hammernet')

    # removing networks in the right order should work
    api.node_detach_network('compute-01', 'eth0', 'pineapple')
    mock_networking_action()
    api.node_detach_network('compute-01', 'eth0', 'hammernet')
    mock_networking_action()
    db.session.close()
예제 #5
0
def create_pending_actions_db():
    """Create database objects including a pending NetworkingAction.

    The first version of this function was used to create the dump
    'pending-networking-actions.sql'.
    """
    # At a minimum we need a project, node, nic, switch, port, and network:
    api.project_create('runway')
    api.node_register(
        'node-1',
        obm={
            'type': MOCK_OBM_TYPE,
            'user': '******',
            'host': 'host',
            'password': '******',
        },
    )
    api.node_register_nic('node-1', 'pxe', 'de:ad:be:ef:20:16')
    api.switch_register(
        'sw0',
        type=MOCK_SWITCH_TYPE,
        username='******',
        hostname='host',
        password='******',
    )
    api.switch_register_port('sw0', 'gi1/0/4')
    api.port_connect_nic('sw0', 'gi1/0/4', 'node-1', 'pxe')
    api.project_connect_node('runway', 'node-1')
    api.network_create('runway_pxe', 'runway', 'runway', '')

    # Queue up a networking action. Importantly, we do *not* call
    # deferred.apply_networking, as that would flush the action and
    # remove it from the database.
    api.node_connect_network('node-1', 'pxe', 'runway_pxe')
예제 #6
0
파일: test_common.py 프로젝트: CCI-MOC/hil
def site_layout():
    """Load the file site-layout.json, and populate the database accordingly.

    This is meant to be used as a pytest fixture, but isn't declared
    here as such; individual modules should declare it as a fixture.

    Full documentation for the site-layout.json file format is located in
    ``docs/testing.md``.
    """
    layout_json_data = open('site-layout.json')
    layout = json.load(layout_json_data)
    layout_json_data.close()

    for switch in layout['switches']:
        api.switch_register(**switch)

    for node in layout['nodes']:
        api.node_register(
            node=node['name'],
            obm=node['obm'],
            obmd=node['obmd'],
        )
        for nic in node['nics']:
            api.node_register_nic(node['name'], nic['name'], nic['mac'])
            api.switch_register_port(nic['switch'], nic['port'])
            api.port_connect_nic(nic['switch'], nic['port'],
                                 node['name'], nic['name'])
예제 #7
0
파일: migrations.py 프로젝트: shwsun/haas
def create_pending_actions_db():
    """Create database objects including a pending NetworkingAction.

    The first version of this function was used to create the dump
    'pending-networking-actions.sql'.
    """
    # At a minimum we need a project, node, nic, switch, port, and network:
    api.project_create('runway')
    api.node_register(
        'node-1',
        obm={
            'type': MOCK_OBM_TYPE,
            'user': '******',
            'host': 'host',
            'password': '******',
        },
    )
    api.node_register_nic('node-1', 'pxe', 'de:ad:be:ef:20:16')
    api.switch_register('sw0',
                        type=MOCK_SWITCH_TYPE,
                        username='******',
                        hostname='host',
                        password='******',
                        )
    api.switch_register_port('sw0', 'gi1/0/4')
    api.port_connect_nic('sw0', 'gi1/0/4', 'node-1', 'pxe')
    api.project_connect_node('runway', 'node-1')
    api.network_create('runway_pxe', 'runway', 'runway', '')

    # Queue up a networking action. Importantly, we do *not* call
    # deferred.apply_networking, as that would flush the action and
    # remove it from the database.
    api.node_connect_network('node-1', 'pxe', 'runway_pxe')
예제 #8
0
파일: port_register.py 프로젝트: vsemp/hil
    def test_register_port_invalid_name_brocade(self):
        """Registering a port with an invalid name should fail"""

        api.switch_register('brocade', type=BROCADE,
                            username="******",
                            password="******",
                            hostname="switchname",
                            interface_type="Tengigabitethernet")

        # test some random invalid port names for brocade switch
        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('brocade', 'blah-blah')

        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('brocade', '1/q/1')

        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('brocade', '1/12/32q')

        # register some valid port names
        api.switch_register_port('brocade', '1/0/12')
        api.switch_register_port('brocade', '1/12')
예제 #9
0
파일: port_register.py 프로젝트: vsemp/hil
    def test_register_port_invalid_name_dell(self):
        """Registering a port with an invalid name should fail"""

        api.switch_register('dell', type=DELL,
                            username="******",
                            password="******",
                            hostname="switchname")

        # test some random invalid port names for both delll switches
        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('dell', 'blah-blah')

        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('dell', 'gi1/0/1q')

        with pytest.raises(errors.BadArgumentError):
            api.switch_register_port('dell', 'gi/0/1')

        # register some valid port names
        api.switch_register_port('dell', 'gi1/0/1')
        api.switch_register_port('dell', 'te1/0/1')
        api.switch_register_port('dell', 'gi2/1')
        api.switch_register_port('dell', 'te1/12')