def test_wrong_project(self): """Project 'runway' cannot detach "manhattan"'s node.""" self.auth_backend.set_project(self.runway) with pytest.raises(AuthorizationError): api.node_detach_network('manhattan_node_0', 'boot-nic', 'stock_int_pub')
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')
def test_saving_config_file(self): """Test saving the switch config to flash.""" api.project_create('anvil-nextgen') nodes = self.collect_nodes() # Create two networks network_create_simple('net-0', 'anvil-nextgen') network_create_simple('net-1', 'anvil-nextgen') # save the old startup config before performing a networking action old_startup_config = self.get_config('startup') # Connect n0 and n1 to net-0 and net-1 respectively api.node_connect_network(nodes[0].label, nodes[0].nics[0].label, 'net-0') api.node_connect_network(nodes[1].label, nodes[1].nics[0].label, 'net-1') deferred.apply_networking() # get the running config, and the new startup config running_config = self.get_config('running') new_startup_config = self.get_config('startup') assert new_startup_config == running_config assert new_startup_config != old_startup_config # cleanup api.node_detach_network(nodes[0].label, nodes[0].nics[0].label, 'net-0') api.node_detach_network(nodes[1].label, nodes[1].nics[0].label, 'net-1') deferred.apply_networking()
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')
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')
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()
def test_saving_config_file(self): api.project_create('anvil-nextgen') nodes = self.collect_nodes() # Create two networks network_create_simple('net-0', 'anvil-nextgen') network_create_simple('net-1', 'anvil-nextgen') # save the old startup config before performing a networking action old_startup_config = self.get_config('startup') # Connect n0 and n1 to net-0 and net-1 respectively api.node_connect_network(nodes[0].label, nodes[0].nics[0].label, 'net-0') api.node_connect_network(nodes[1].label, nodes[1].nics[0].label, 'net-1') deferred.apply_networking() # get the running config, and the new startup config running_config = self.get_config('running') new_startup_config = self.get_config('startup') assert new_startup_config == running_config assert new_startup_config != old_startup_config # cleanup api.node_detach_network(nodes[0].label, nodes[0].nics[0].label, 'net-0') api.node_detach_network(nodes[1].label, nodes[1].nics[0].label, 'net-1') deferred.apply_networking()
def test_success(self): self.auth_backend.set_project(self.manhattan) api.node_detach_network('manhattan_node_0', 'boot-nic', 'stock_int_pub')
def test_success(self): """Project 'manhattan' can detach its own node.""" self.auth_backend.set_project(self.manhattan) api.node_detach_network('manhattan_node_0', 'boot-nic', 'stock_int_pub')
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')