Beispiel #1
0
        def teardown():
            """Teardown the setup from create_multi_nets.
            """
            # Query the DB for nodes on this project
            project = api.get_or_404(model.Project, 'anvil-nextgen')
            nodes = project.nodes
            ports = self.get_all_ports(nodes)

            # Remove all nodes from their networks using port_revert.
            for node in nodes:
                port = node.nics[0].port
                api.port_revert(port.owner.label, port.label)
            deferred.apply_networking()

            # Assert that none of the nodes are on any network
            port_networks = self.get_port_networks(ports)
            for node in nodes:
                assert self.get_network(node.nics[0].port, port_networks) == \
                    set()

            # Delete the networks
            api.network_delete('net-0')
            api.network_delete('net-1')
            api.network_delete('net-2')
            api.network_delete('net-3')
Beispiel #2
0
        def delete_networks():
            """Tear down things set up by create_networks

            again, we do various checks along the way.
            """
            # Query the DB for nodes on this project
            project = api._must_find(model.Project, 'anvil-nextgen')
            nodes = project.nodes
            ports = self.get_all_ports(nodes)

            # Remove all nodes from their networks. We do this in two different
            # ways for different ports to test the different mechanisms. For
            # the first two nodes we explicity remove the attachments. For the
            # latter two we call port_revert.
            for node in nodes[:2]:
                attachment = model.NetworkAttachment.query \
                    .filter_by(nic=node.nics[0]).one()
                api.node_detach_network(node.label, node.nics[0].label,
                                        attachment.network.label)
            for node in nodes[2:]:
                port = node.nics[0].port
                api.port_revert(port.owner.label, port.label)
            deferred.apply_networking()

            # Assert that none of the nodes are on any network
            port_networks = self.get_port_networks(ports)
            for node in nodes:
                assert self.get_network(node.nics[0].port, port_networks) == \
                    set()

            # Delete the networks
            api.network_delete('net-0')
            api.network_delete('net-1')
Beispiel #3
0
        def teardown():
            """Teardown the setup from create_multi_nets.
            """
            # Query the DB for nodes on this project
            project = api.get_or_404(model.Project, 'anvil-nextgen')
            nodes = project.nodes
            ports = self.get_all_ports(nodes)

            # Remove all nodes from their networks using port_revert.
            for node in nodes:
                port = node.nics[0].port
                api.port_revert(port.owner.label, port.label)
            deferred.apply_networking()

            # Assert that none of the nodes are on any network
            port_networks = self.get_port_networks(ports)
            for node in nodes:
                assert self.get_network(node.nics[0].port, port_networks) == \
                    set()

            # Delete the networks
            api.network_delete('net-0')
            api.network_delete('net-1')
            api.network_delete('net-2')
            api.network_delete('net-3')
Beispiel #4
0
 def test_no_nic(self):
     """port_revert on a port with no nic should raise not found."""
     with pytest.raises(errors.NotFoundError):
         # free_port_0 is not attached to a nic.
         api.port_revert('stock_switch_0', 'free_port_0')
     deferred.apply_networking()
     assert self.LOCAL_STATE['stock_switch_0']['free_port_0'] == {}
Beispiel #5
0
    def test_one_network(self):
        """Test port_revert on a port attached to one network."""
        api.node_connect_network('runway_node_0',
                                 'nic-with-port',
                                 'runway_pxe',
                                 'vlan/native')
        deferred.apply_networking()

        net_id = model.Network.query.filter_by(label='runway_pxe')\
            .one().network_id
        assert self.LOCAL_STATE['stock_switch_0']['runway_node_0_port'] == {
            'vlan/native': net_id,
        }

        api.port_revert('stock_switch_0', 'runway_node_0_port')
        deferred.apply_networking()

        assert self.LOCAL_STATE['stock_switch_0']['runway_node_0_port'] == {},\
            "port_revert did not detach the port from the networks!"

        network = model.Network.query.filter_by(label='runway_pxe').one()
        assert model.NetworkAttachment.query.filter_by(
            network_id=network.id,
        ).first() is None, (
            "port_revert did not remove the network attachment object in "
            "the database!"
        )
Beispiel #6
0
 def test_two_networks(self):
     """Test port_revert on a port attached to two networks."""
     pxe_net_id = model.Network.query.filter_by(label='runway_pxe')\
         .one().network_id
     pub_net_id = model.Network.query.filter_by(label='stock_int_pub')\
         .one().network_id
     api.node_connect_network('runway_node_0',
                              'nic-with-port',
                              'runway_pxe',
                              'vlan/native')
     deferred.apply_networking()
     assert self.LOCAL_STATE['stock_switch_0']['runway_node_0_port'] == {
         'vlan/native': pxe_net_id,
     }
     api.node_connect_network('runway_node_0',
                              'nic-with-port',
                              'stock_int_pub',
                              'vlan/' + pub_net_id)
     deferred.apply_networking()
     assert self.LOCAL_STATE['stock_switch_0']['runway_node_0_port'] == {
         'vlan/native': pxe_net_id,
         'vlan/' + pub_net_id: pub_net_id,
     }
     api.port_revert('stock_switch_0', 'runway_node_0_port')
     deferred.apply_networking()
     assert self.LOCAL_STATE['stock_switch_0']['runway_node_0_port'] == {}
Beispiel #7
0
 def test_no_nic(self):
     """port_revert on a port with no nic should raise not found."""
     with pytest.raises(errors.NotFoundError):
         # free_port_0 is not attached to a nic.
         api.port_revert('stock_switch_0', 'free_port_0')
     deferred.apply_networking()
     assert self.LOCAL_STATE['stock_switch_0']['free_port_0'] == {}
Beispiel #8
0
        def delete_networks():
            """Tear down things set up by create_networks

            again, we do various checks along the way.
            """
            # Query the DB for nodes on this project
            project = api.get_or_404(model.Project, 'anvil-nextgen')
            nodes = project.nodes
            ports = self.get_all_ports(nodes)

            # Remove all nodes from their networks. We do this in two different
            # ways for different ports to test the different mechanisms. For
            # the first two nodes we explicity remove the attachments. For the
            # latter two we call port_revert.
            for node in nodes[:2]:
                attachment = model.NetworkAttachment.query \
                    .filter_by(nic=node.nics[0]).one()
                api.node_detach_network(node.label,
                                        node.nics[0].label,
                                        attachment.network.label)
            for node in nodes[2:]:
                port = node.nics[0].port
                api.port_revert(port.owner.label, port.label)
            deferred.apply_networking()

            # Assert that none of the nodes are on any network
            port_networks = self.get_port_networks(ports)
            for node in nodes:
                assert self.get_network(node.nics[0].port, port_networks) == \
                    set()

            # Delete the networks
            api.network_delete('net-0')
            api.network_delete('net-1')
Beispiel #9
0
        def delete_networks():
            """Tear down things set up by create_networks

            again, we do various checks along the way.
            """
            # Query the DB for nodes on this project
            project = api._must_find(model.Project, 'anvil-nextgen')
            nodes = project.nodes
            ports = self.get_all_ports(nodes)

            # Remove all nodes from their networks. We do this in two ways, to
            # test the different mechanisms.

            # For the first two nodes, we first build up a list of
            # the arguments to the API calls, which has no direct references to
            # database objects, and then make the API calls and invoke
            # deferred.apply_networking after. This is important --
            # The API calls and apply_networking normally run in their own
            # transaction. We get away with not doing this in the tests because
            # we serialize everything ourselves, so there's no risk of
            # interference. If we were to hang on to references to database
            # objects across such calls however, things could get harry.
            all_attachments = []
            for node in nodes[:2]:
                attachments = model.NetworkAttachment.query \
                    .filter_by(nic=node.nics[0]).all()
                for attachment in attachments:
                    all_attachments.append((node.label, node.nics[0].label,
                                            attachment.network.label))
            for attachment in all_attachments:
                api.node_detach_network(*attachment)
                deferred.apply_networking()

            # For the second two nodes, we just call port_revert on the nic's
            # port.
            for node in nodes[2:]:
                port = node.nics[0].port
                api.port_revert(port.owner.label, port.label)
            deferred.apply_networking()

            # Assert that none of the nodes are on any network
            port_networks = self.get_port_networks(ports)
            for node in nodes:
                assert self.get_network(node.nics[0].port, port_networks) == \
                    set()

            # Delete the networks
            api.network_delete('net-0')
            api.network_delete('net-1')
Beispiel #10
0
        def delete_networks():
            """Tear down things set up by create_networks

            again, we do various checks along the way.
            """
            # Query the DB for nodes on this project
            project = api.get_or_404(model.Project, 'anvil-nextgen')
            nodes = project.nodes
            ports = self.get_all_ports(nodes)

            # Remove all nodes from their networks. We do this in two ways, to
            # test the different mechanisms.

            # For the first two nodes, we first build up a list of
            # the arguments to the API calls, which has no direct references to
            # database objects, and then make the API calls and invoke
            # deferred.apply_networking after. This is important --
            # The API calls and apply_networking normally run in their own
            # transaction. We get away with not doing this in the tests because
            # we serialize everything ourselves, so there's no risk of
            # interference. If we were to hang on to references to database
            # objects across such calls however, things could get harry.
            all_attachments = []
            net = namedtuple('net', 'node nic network channel')
            for node in nodes[:2]:
                attachments = model.NetworkAttachment.query \
                    .filter_by(nic=node.nics[0]).all()
                for attachment in attachments:
                    all_attachments.append(
                        net(node=node.label,
                            nic=node.nics[0].label,
                            network=attachment.network.label,
                            channel=attachment.channel))

            switch = nodes[0].nics[0].port.owner
            # in some switches, the native network can only be disconnected
            # after we remove all tagged networks first. The following checks
            # for that and rearranges the networks (all_attachments) such that
            # tagged networks are removed first.

            if 'nativeless-trunk-mode' not in switch.get_capabilities():
                # sort by channel; vlan/<integer> comes before vlan/native
                # because the ASCII for numbers comes before ASCII for letters.
                all_attachments = sorted(all_attachments,
                                         key=lambda net: net.channel)

            for attachment in all_attachments:
                api.node_detach_network(attachment.node, attachment.nic,
                                        attachment.network)
                deferred.apply_networking()

            # For the second two nodes, we just call port_revert on the nic's
            # port.
            for node in nodes[2:]:
                port = node.nics[0].port
                api.port_revert(port.owner.label, port.label)
            deferred.apply_networking()

            # Assert that none of the nodes are on any network
            port_networks = self.get_port_networks(ports)
            for node in nodes:
                assert self.get_network(node.nics[0].port, port_networks) == \
                    set()

            # Delete the networks
            api.network_delete('net-0')
            api.network_delete('net-1')
            api.network_delete('net-2')
            api.network_delete('net-3')
Beispiel #11
0
 def test_no_nic(self):
     with pytest.raises(api.NotFoundError):
         # free_port_0 is not attached to a nic.
         api.port_revert('stock_switch_0', 'free_port_0')
     deferred.apply_networking()
     assert self.LOCAL_STATE['stock_switch_0']['free_port_0'] == {}
Beispiel #12
0
        def delete_networks():
            """Tear down things set up by create_networks

            again, we do various checks along the way.
            """
            # Query the DB for nodes on this project
            project = api.get_or_404(model.Project, 'anvil-nextgen')
            nodes = project.nodes
            ports = self.get_all_ports(nodes)

            # Remove all nodes from their networks. We do this in two ways, to
            # test the different mechanisms.

            # For the first two nodes, we first build up a list of
            # the arguments to the API calls, which has no direct references to
            # database objects, and then make the API calls and invoke
            # deferred.apply_networking after. This is important --
            # The API calls and apply_networking normally run in their own
            # transaction. We get away with not doing this in the tests because
            # we serialize everything ourselves, so there's no risk of
            # interference. If we were to hang on to references to database
            # objects across such calls however, things could get harry.
            all_attachments = []
            net = namedtuple('net', 'node nic network channel')
            for node in nodes[:2]:
                attachments = model.NetworkAttachment.query \
                    .filter_by(nic=node.nics[0]).all()
                for attachment in attachments:
                    all_attachments.append(
                                        net(node=node.label,
                                            nic=node.nics[0].label,
                                            network=attachment.network.label,
                                            channel=attachment.channel))

            switch = nodes[0].nics[0].port.owner
            # in some switches, the native network can only be disconnected
            # after we remove all tagged networks first. The following checks
            # for that and rearranges the networks (all_attachments) such that
            # tagged networks are removed first.

            if 'nativeless-trunk-mode' not in switch.get_capabilities():
                # sort by channel; vlan/<integer> comes before vlan/native
                # because the ASCII for numbers comes before ASCII for letters.
                all_attachments = sorted(all_attachments,
                                         key=lambda net: net.channel)

            for attachment in all_attachments:
                api.node_detach_network(attachment.node, attachment.nic,
                                        attachment.network)
                deferred.apply_networking()

            # For the second two nodes, we just call port_revert on the nic's
            # port.
            for node in nodes[2:]:
                port = node.nics[0].port
                api.port_revert(port.owner.label, port.label)
            deferred.apply_networking()

            # Assert that none of the nodes are on any network
            port_networks = self.get_port_networks(ports)
            for node in nodes:
                assert self.get_network(node.nics[0].port, port_networks) == \
                    set()

            # Delete the networks
            api.network_delete('net-0')
            api.network_delete('net-1')
            api.network_delete('net-2')
            api.network_delete('net-3')