def test_01_11_br_set_external_id_clear(self): bridge = 's1' key = 'ext_id_key' command = vsctl.VSCtlCommand('br-set-external-id', (bridge, key)) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl br-get-external-id %s %s' % (bridge, key)) eq_([], result) # Clean up self._docker_exec_mn('mn --clean')
def test_08_03_get_03_map(self): table = 'Bridge' bridge = 's1' column = 'other_config' key = 'datapath-id' datapath_id = '1111111111111111' value = {key: datapath_id} command = vsctl.VSCtlCommand('get', (table, bridge, column)) self._run_commands([command]) # command.result[0] is a dict eq_(value, command.result[0])
def test_01_02_add_br_parent_vlan(self): bridge = 'sub-s1-100' parent = 's1' vlan = '100' command = vsctl.VSCtlCommand('add-br', (bridge, parent, vlan)) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl list-br') ok_(bridge in result) result = self._docker_exec_mn('ovs-vsctl br-to-parent %s' % bridge) eq_(parent, result[0]) result = self._docker_exec_mn('ovs-vsctl br-to-vlan %s' % bridge) eq_(vlan, result[0])
def test_01_04_list_br(self): bridge = 's1' child = 'sub-s1-100' vlan = '100' self._docker_exec_mn('ovs-vsctl add-br %s' % bridge) self._docker_exec_mn('ovs-vsctl add-br %s %s %s' % (child, bridge, vlan)) command = vsctl.VSCtlCommand('list-br') self._run_commands([command]) ok_(bridge in command.result) ok_(child in command.result)
def remove_db_attribute(self, table, record, column, value, key=None): """ Removes ('key'=)'value' into 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl remove TBL REC COL [KEY=]VALUE """ if key is not None: value = '%s=%s' % (key, value) command = ovs_vsctl.VSCtlCommand('remove', (table, record, column, value)) self.run_command([command])
def set_db_attribute(self, table, record, column, value, key=None): """ Sets 'value' into 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl set TBL REC COL[:KEY]=VALUE """ if key is not None: column = '%s:%s' % (column, key) command = ovs_vsctl.VSCtlCommand('set', (table, record, '%s=%s' % (column, value))) self.run_command([command])
def list_db_attributes(self, table, record=None): """ Lists 'record' (or all records) in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl list TBL [REC] """ command = ovs_vsctl.VSCtlCommand('list', (table, record)) self.run_command([command]) if command.result: return command.result return []
def test_08_05_add_02_set(self): table = 'Port' bridge = 's1' column = 'trunks' value = '100,200' command = vsctl.VSCtlCommand('add', (table, bridge, column, value)) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl get %s %s %s' % (table, bridge, column)) expected_value = '[100, 200]' eq_(expected_value, result[0])
def test_08_04_set_01_value(self): table = 'Bridge' bridge = 's1' column = 'fail_mode' value = 'standalone' command = vsctl.VSCtlCommand('set', (table, bridge, '%s=%s' % (column, value))) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl get %s %s %s' % (table, bridge, column)) eq_(value, result[0])
def test_08_04_set_02_set(self): table = 'Bridge' bridge = 's1' column = 'protocols' value = 'OpenFlow10,OpenFlow12,OpenFlow13' command = vsctl.VSCtlCommand('set', (table, bridge, '%s=%s' % (column, value))) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl get %s %s %s' % (table, bridge, column)) expected_value = '["OpenFlow10", "OpenFlow12", "OpenFlow13"]' eq_(expected_value, result[0])
def test_08_07_clear_01_value(self): table = 'Port' bridge = 's1' column = 'tag' value = '100' self._docker_exec_mn('ovs-vsctl set %s %s %s=%s' % (table, bridge, column, value)) command = vsctl.VSCtlCommand('clear', (table, bridge, column)) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl get %s %s %s' % (table, bridge, column)) expected_value = '[]' eq_(expected_value, result[0])
def test_08_05_add_03_map(self): table = 'Bridge' bridge = 's1' column = 'other_config' key = 'datapath-id' value = '0000000000000011' command = vsctl.VSCtlCommand('add', (table, bridge, column, '%s=%s' % (key, value))) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl get %s %s %s:%s' % (table, bridge, column, key)) expected_value = '"0000000000000011"' eq_(expected_value, result[0])
def test_02_03_add_bond(self): bridge = 's1' interface_1 = 's1-eth1' interface_2 = 's1-eth2' port = 's1-bond1' interface_list = [interface_1, interface_2] self._docker_exec_mn('ovs-vsctl del-br %s' % bridge) self._docker_exec_mn('ovs-vsctl add-br %s' % bridge) command = vsctl.VSCtlCommand('add-bond', (bridge, port, interface_list)) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl port-to-br %s' % port) eq_(bridge, result[0])
def get_db_attribute(self, table, record, column, key=None): """ Gets values of 'column' in 'record' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl get TBL REC COL[:KEY] """ if key is not None: column = '%s:%s' % (column, key) command = ovs_vsctl.VSCtlCommand('get', (table, record, column)) self.run_command([command]) if command.result: return command.result[0] return None
def add_tunnel_port(self, name, tunnel_type, remote_ip, local_ip=None, key=None, ofport=None): options = 'remote_ip=%(remote_ip)s' % locals() if key: options += ',key=%(key)s' % locals() if local_ip: options += ',local_ip=%(local_ip)s' % locals() args = [ 'Interface', name, 'type=%s' % tunnel_type, 'options:%s' % options ] if ofport: args.append('ofport_request=%(ofport)s' % locals()) command_add = ovs_vsctl.VSCtlCommand('add-port', (self.br_name, name)) command_set = ovs_vsctl.VSCtlCommand('set', args) self.run_command([command_add, command_set])
def test_08_02_find_complex(self): table = 'Bridge' bridge = 's1' fail_mode = 'secure' protocols = 'OpenFlow10,OpenFlow13' datapath_id = '1111111111111111' command = vsctl.VSCtlCommand( 'find', (table, 'fail_mode=%s' % fail_mode, 'protocols=%s' % protocols, 'other_config:datapath-id=%s' % datapath_id)) self._run_commands([command]) eq_(1, len(command.result)) # command.result[0] = <ovs.db.idl.Row object object> for Bridge eq_(bridge, command.result[0].name)
def test_02_05_port_to_br(self): bridge = 's1' port_1 = 's1-eth1' port_2 = 's1-eth2' self._docker_exec_mn('ovs-vsctl del-br %s' % bridge) self._docker_exec_mn('ovs-vsctl add-br %(bridge)s' ' -- add-port %(bridge)s %(port_1)s' ' -- add-port %(bridge)s %(port_2)s' % locals()) command = vsctl.VSCtlCommand('port-to-br', (port_1, )) self._run_commands([command]) eq_(bridge, command.result) # Clean up self._docker_exec_mn('mn --clean')
def test_08_06_remove_02_set(self): table = 'Port' bridge = 's1' column = 'trunks' init_value = '100,200,300' value = '100,200' self._docker_exec_mn('ovs-vsctl set %s %s %s=%s' % (table, bridge, column, init_value)) command = vsctl.VSCtlCommand('remove', (table, bridge, column, value)) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl get %s %s %s' % (table, bridge, column)) expected_value = '[300]' eq_(expected_value, result[0])
def test_03_01_list_ifaces(self): bridge = 's1' interface_1 = 's1-eth1' interface_2 = 's1-eth2' self._docker_exec_mn('ip link add %s type dummy' % interface_1) self._docker_exec_mn('ip link add %s type dummy' % interface_2) self._docker_exec_mn('ovs-vsctl add-br %(bridge)s' ' -- add-port %(bridge)s %(interface_1)s' ' -- add-port %(bridge)s %(interface_2)s' % locals()) command = vsctl.VSCtlCommand('list-ifaces', (bridge, )) self._run_commands([command]) ok_(interface_1 in command.result) ok_(interface_2 in command.result)
def test_08_06_remove_03_map(self): table = 'Port' bridge = 's1' column = 'other_config' key = 'priority-tag' value = 'true' self._docker_exec_mn('ovs-vsctl set %s %s %s:%s=%s' % (table, bridge, column, key, value)) command = vsctl.VSCtlCommand( 'remove', (table, bridge, column, '%s=%s' % (key, value))) self._run_commands([command]) result = self._docker_exec_mn('ovs-vsctl get %s %s %s' % (table, bridge, column)) expected_value = '{}' eq_(expected_value, result[0])
def find_db_attributes(self, table, *conditions): """ Lists records satisfying 'conditions' in 'table'. This method is corresponding to the following ovs-vsctl command:: $ ovs-vsctl find TBL CONDITION... .. Note:: Currently, only '=' condition is supported. To support other condition is TODO. """ args = [table] args.extend(conditions) command = ovs_vsctl.VSCtlCommand('find', args) self.run_command([command]) if command.result: return command.result return []
def add_bond(self, name, ifaces, bond_mode=None, lacp=None): """ Creates a bonded port. :param name: Port name to be created :param ifaces: List of interfaces containing at least 2 interfaces :param bond_mode: Bonding mode (active-backup, balance-tcp or balance-slb) :param lacp: LACP mode (active, passive or off) """ assert len(ifaces) >= 2 options = '' if bond_mode: options += 'bond_mode=%(bond_mode)s' % locals() if lacp: options += 'lacp=%(lacp)s' % locals() command_add = ovs_vsctl.VSCtlCommand( 'add-bond', (self.br_name, name, ifaces), options) self.run_command([command_add])
def del_qos(self, port_name): command = ovs_vsctl.VSCtlCommand( 'del-qos', [port_name]) self.run_command([command])
def del_port(self, port_name): command = ovs_vsctl.VSCtlCommand('del-port', (self.br_name, port_name)) self.run_command([command])
def get_port_name_list(self): command = ovs_vsctl.VSCtlCommand('list-ports', (self.br_name, )) self.run_command([command]) return command.result
def delete_port(self, port_name): command = ovs_vsctl.VSCtlCommand( 'del-port', (self.br_name, port_name), ('--if-exists')) self.run_command([command])
def db_get_val(self, table, record, column): command = ovs_vsctl.VSCtlCommand('get', (table, record, column)) self.run_command([command]) assert len(command.result) == 1 return command.result[0]
def clear_db_attribute(self, table_name, record, column): command = ovs_vsctl.VSCtlCommand('clear', (table_name, record, column)) self.run_command([command])
def set_db_attribute(self, table_name, record, column, value): command = ovs_vsctl.VSCtlCommand( 'set', (table_name, record, '%s=%s' % (column, value))) self.run_command([command])
def del_controller(self): command = ovs_vsctl.VSCtlCommand('del-controller', [self.br_name]) self.run_command([command])