def test_QueryvSwitchInfo(self): response = self.ovs_stub.QueryvSwitchInfo( OvsManager_pb2.vSwitchInfoQueryRequest( vswitch_names=[self.switch_name])) logging.info('QueryvSwitchInfo:vswitch_name: %s', response.vswitch_infos[0].vswitch_conf.vswitch_name) logging.info('QueryvSwitchInfo:mode: %d', response.vswitch_infos[0].vswitch_conf.mode) logging.info('QueryvSwitchInfo:is_multicast: %d', response.vswitch_infos[0].vswitch_conf.is_multicast) logging.info('QueryvSwitchInfo:is_link: %d', response.vswitch_infos[0].is_link) logging.info('QueryvSwitchInfo:errno: %d', response.vswitch_infos[0].errno) assert response.vswitch_infos[0].errno == ErrNo_pb2.SYS_OK response = self.ovs_stub.QueryvSwitchInfo( OvsManager_pb2.vSwitchInfoQueryRequest(vswitch_names=[])) if len(response.vswitch_infos) == 0: assert 1 response = self.ovs_stub.QueryvSwitchInfo( OvsManager_pb2.vSwitchInfoQueryRequest( vswitch_names=["fail@vswitch"])) if len(response.vswitch_infos) == 0: assert 1
def test_ModifyvSwitch(self): vswitch_conf = OvsManager_pb2.vSwitchConf() vswitch_conf.vswitch_name = self.switch_name vswitch_conf.mode = OvsManager_pb2.vSwitchConf.VEB vswitch_conf.is_multicast = True response = self.ovs_stub.ModifyvSwitch( OvsManager_pb2.vSwitchModifyRequest(vswitch_conf=vswitch_conf)) assert response.errno == ErrNo_pb2.SYS_OK
def create_default_vswitch(cls): vswitch_conf = OvsManager_pb2.vSwitchConf() vswitch_conf.vswitch_name = cls.switch_name vswitch_conf.mode = OvsManager_pb2.vSwitchConf.VEB vswitch_conf.is_multicast = False response = cls.ovs_stub.AddvSwitch( OvsManager_pb2.vSwitchAddRequest(vswitch_conf=vswitch_conf)) if response == ErrNo_pb2.SYS_FAIL: raise net_agentd_exception.NetAgentException( "create default vswitch failed")
def GetInternalNicParam(self, request, context): vlan = "" mtu = "" ip_addr = "" net_mask = "" gate_way = "" errno = ErrNo_pb2.SYS_FAIL ovs_object = OvsManager.OvsHandle(request.vswitch_name, request.internal_nic_name) if ovs_object.is_vswitch_exist() is True: try: vlan = ovs_object.get_vlan() mtu = ovs_object.get_mtu() ip_addr = ovs_object.get_ip() net_mask = ovs_object.get_netmask() gate_way = ovs_object.get_gateway() errno = ErrNo_pb2.SYS_OK except net_agentd_exception.NetAgentException: logging.error(traceback.format_exc()) logging.error("Modify br %s failed" % request.vswitch_name) else: logging.error("Modify: br %s doesnt exist" % request.vswitch_name) return OvsManager_pb2.InternalNicParamGetReply(vswitch_name=request.vswitch_name, internal_nic_name=request.internal_nic_name, vlan=vlan, mtu=mtu, ip_addr=ip_addr, netmask=net_mask, gateway=gate_way, errno=errno)
def test_QueryvSwitchList(self): response = self.ovs_stub.QueryvSwitchList( OvsManager_pb2.vSwitchListQueryRequest(host_name='me')) logging.info('TestOtherManager:vswitch list: %s!', response.vswitch_names) logging.info('TestOtherManager:errno: %d!', response.errno) assert response.errno == ErrNo_pb2.SYS_OK
def test_AddvSwitch_DelvSwitch(self): vswitch_name = "test_tmp" vswitch_conf = OvsManager_pb2.vSwitchConf() vswitch_conf.vswitch_name = vswitch_name vswitch_conf.mode = OvsManager_pb2.vSwitchConf.VEB vswitch_conf.is_multicast = False response = self.ovs_stub.AddvSwitch( OvsManager_pb2.vSwitchAddRequest(vswitch_conf=vswitch_conf)) assert response.errno == ErrNo_pb2.SYS_OK '''repeated add same name vswitch''' response = self.ovs_stub.AddvSwitch( OvsManager_pb2.vSwitchAddRequest(vswitch_conf=vswitch_conf)) assert response.errno == ErrNo_pb2.SYS_FAIL response = self.ovs_stub.DelvSwitch( OvsManager_pb2.vSwitchDelRequest(vswitch_name=vswitch_name)) assert response.errno == ErrNo_pb2.SYS_OK
def QueryvSwitchList(self, request, context): errno = ErrNo_pb2.SYS_FAIL vswitch_names = [] try: vswitch_names = OvsManager.get_vswitch_list() errno = ErrNo_pb2.SYS_OK except net_agentd_exception.NetAgentException: logging.error(traceback.format_exc()) logging.error("QueryvSwitchList failed") return OvsManager_pb2.vSwitchListQueryReply(vswitch_names=vswitch_names, errno=errno)
def QueryvSwitchInfo(self, request, context): vswitch_infos = [] for vswitch_name in request.vswitch_names: ovs_object = OvsManager.OvsHandle(vswitch_name) if ovs_object.is_vswitch_exist() is True: try: vswitch_info = OvsManager_pb2.vSwitchInfo() vswitch_info.vswitch_conf.vswitch_name = vswitch_name vswitch_info.vswitch_conf.mode = ovs_object.get_mode() vswitch_info.vswitch_conf.is_multicast = ovs_object.get_vswitch_multicast() vswitch_info.is_link = ovs_object.is_vswitch_link() vswitch_info.errno = ErrNo_pb2.SYS_OK except net_agentd_exception.NetAgentException: vswitch_infos.errno = ErrNo_pb2.SYS_FAIL logging.error(traceback.format_exc()) logging.error("%s QueryvSwitchInfo failed" % vswitch_name) vswitch_infos.append(vswitch_info) else: logging.error("Query: br %s doesnt exist" % vswitch_name) return OvsManager_pb2.vSwitchInfoQueryReply(vswitch_infos=vswitch_infos)
def DelvSwitch(self, request, context): errno = ErrNo_pb2.SYS_FAIL ovs_object = OvsManager.OvsHandle(request.vswitch_name) if ovs_object.is_vswitch_exist() is True: try: ovs_object.destroy_vswitch() ovs_object.remove_conf_file() errno = ErrNo_pb2.SYS_OK except net_agentd_exception.NetAgentException: logging.error(traceback.format_exc()) logging.error("destroy br %s failed" % request.vswitch_name) else: logging.error("Del: br %s doesnt exist" % request.vswitch_name) return OvsManager_pb2.vSwitchAddReply(errno=errno)
def test_GetInternalNicParam(self): response = self.ovs_stub.GetInternalNicParam( OvsManager_pb2.InternalNicParamGetRequest( vswitch_name=self.switch_name, internal_nic_name=self.switch_name)) logging.info('GetInternalNicParam:vswitch_name: %s', response.vswitch_name) logging.info('GetInternalNicParam:internal_nic_name: %s', response.internal_nic_name) logging.info('GetInternalNicParam:vlan: %s', response.vlan) logging.info('GetInternalNicParam:mtu: %s', response.mtu) logging.info('GetInternalNicParam:ip_addr: %s', response.ip_addr) logging.info('GetInternalNicParam:netmask: %s', response.netmask) logging.info('GetInternalNicParam:gateway: %s', response.gateway) logging.info('GetInternalNicParam:errno: %d', response.errno) assert response.errno == ErrNo_pb2.SYS_OK
def SetInternalNicParam(self, request, context): old_vlan = "" old_mtu = "" old_ip = "" old_netmask = "" operate_success = [] errno = ErrNo_pb2.SYS_FAIL ovs_object = OvsManager.OvsHandle(request.vswitch_name, request.internal_nic_name) if ovs_object.is_vswitch_exist() is True: try: '''make sure internal_nic status is up''' ovs_object.start_nic() if request.vlan: old_vlan = ovs_object.get_vlan() ovs_object.set_vlan(request.vlan) operate_success.append("vlan") if request.mtu: old_mtu = ovs_object.get_mtu() ovs_object.set_mtu(request.mtu) operate_success.append("mtu") if request.ip_addr: old_ip = ovs_object.get_ip() old_netmask = ovs_object.get_netmask() ovs_object.set_ip_netmask(request.ip_addr, request.netmask) operate_success.append("ip_addr") if request.gateway: ovs_object.set_gateway(request.gateway) operate_success.append("gateway") errno = ErrNo_pb2.SYS_OK except net_agentd_exception.NetAgentException: if "ip_addr" in operate_success: ovs_object.set_ip_netmask(old_ip, old_netmask) if "mtu" in operate_success: ovs_object.set_mtu(old_mtu) if "vlan" in operate_success: ovs_object.set_vlan(old_vlan) logging.error(traceback.format_exc()) logging.error("SetInternalNicParam br %s vnic %s failed" % (request.vswitch_name, request.internal_nic_name)) else: logging.error("SetInternalNicParam: br %s doesnt exist" % request.vswitch_name) return OvsManager_pb2.InternalNicParamSetReply(errno=errno)
def ModifyvSwitch(self, request, context): retval = ErrNo_pb2.SYS_FAIL ovs_object = OvsManager.OvsHandle(request.vswitch_conf.vswitch_name) if ovs_object.is_vswitch_exist() is True: try: if request.vswitch_conf.is_multicast: ovs_object.set_vswitch_multicast(request.vswitch_conf.is_multicast) retval = ErrNo_pb2.SYS_OK except net_agentd_exception.NetAgentException: logging.error(traceback.format_exc()) logging.error("Modify br %s failed" % request.vswitch_name) else: logging.error("Modify: br %s doesnt exist" % request.vswitch_conf.vswitch_name) return OvsManager_pb2.vSwitchAddReply(errno=retval)
def AddvSwitch(self, request, context): retval = ErrNo_pb2.SYS_FAIL ovs_object = OvsManager.OvsHandle(request.vswitch_conf.vswitch_name) if ovs_object.is_vswitch_exist() is False: try: ovs_object.create_vswitch() ovs_object.generate_conf_file() if request.vswitch_conf.is_multicast: ovs_object.set_vswitch_multicast(request.vswitch_conf.is_multicast) retval = ErrNo_pb2.SYS_OK except net_agentd_exception.NetAgentException: logging.error(traceback.format_exc()) logging.error("create br %s failed" % request.vswitch_conf.vswitch_name) else: logging.error("Add: br %s already exist" % request.vswitch_conf.vswitch_name) return OvsManager_pb2.vSwitchAddReply(errno=retval)
def ClearInternalNicParam(self, request, context): errno = ErrNo_pb2.SYS_FAIL ovs_object = OvsManager.OvsHandle(request.vswitch_name, request.internal_nic_name) if ovs_object.is_vswitch_exist() is True: try: ovs_object.clear_ip() ovs_object.save_conf_file_item("IPADDR", "") ovs_object.save_conf_file_item("NETMASK", "") ovs_object.save_conf_file_item("GATEWAY", "") errno = ErrNo_pb2.SYS_OK except net_agentd_exception.NetAgentException: logging.error(traceback.format_exc()) logging.error("ClearInternalNicParam br %s vnic %s failed" % (request.vswitch_name, request.internal_nic_name)) else: logging.error("ClearInternalNicParam: br %s doesnt exist" % request.vswitch_name) return OvsManager_pb2.InternalNicParamClearReply(errno=errno)
def destroy_default_vswitch(cls): response = cls.ovs_stub.DelvSwitch( OvsManager_pb2.vSwitchDelRequest(vswitch_name=cls.switch_name)) if response == ErrNo_pb2.SYS_FAIL: raise net_agentd_exception.NetAgentException( "del default vswitch failed")
def test_SetInternalNicParam(self): response = self.ovs_stub.SetInternalNicParam( OvsManager_pb2.InternalNicParamSetRequest( vswitch_name=self.switch_name, internal_nic_name=self.switch_name, vlan="256", mtu="1718", ip_addr="192.168.25.12", netmask="255.255.255.0", gateway="192.168.25.23")) assert response.errno == ErrNo_pb2.SYS_OK response = self.ovs_stub.SetInternalNicParam( OvsManager_pb2.InternalNicParamSetRequest( vswitch_name=self.switch_name, internal_nic_name=self.switch_name, vlan="5000", mtu="1718", ip_addr="192.168.25.12", netmask="255.255.255.0", gateway="192.168.25.23")) assert response.errno == ErrNo_pb2.SYS_FAIL response = self.ovs_stub.SetInternalNicParam( OvsManager_pb2.InternalNicParamSetRequest( vswitch_name=self.switch_name, internal_nic_name=self.switch_name, vlan="256", mtu="10890", ip_addr="192.168.25.12", netmask="255.255.255.0", gateway="192.168.25.23")) assert response.errno == ErrNo_pb2.SYS_FAIL response = self.ovs_stub.SetInternalNicParam( OvsManager_pb2.InternalNicParamSetRequest( vswitch_name=self.switch_name, internal_nic_name=self.switch_name, vlan="256", mtu="1718", ip_addr="342.168.25.12", netmask="255.255.255.0", gateway="192.168.25.23")) assert response.errno == ErrNo_pb2.SYS_FAIL response = self.ovs_stub.SetInternalNicParam( OvsManager_pb2.InternalNicParamSetRequest( vswitch_name=self.switch_name, internal_nic_name=self.switch_name, vlan="256", mtu="1718", ip_addr="192.168.25.12", netmask="255.200.255.0", gateway="192.168.25.23")) assert response.errno == ErrNo_pb2.SYS_FAIL response = self.ovs_stub.SetInternalNicParam( OvsManager_pb2.InternalNicParamSetRequest( vswitch_name=self.switch_name, internal_nic_name=self.switch_name, vlan="256", mtu="1718", ip_addr="192.168.25.12", netmask="255.255.255.0", gateway="192.378.25.23")) assert response.errno == ErrNo_pb2.SYS_FAIL
def test_ClearInternalNicParam(self): response = self.ovs_stub.ClearInternalNicParam( OvsManager_pb2.InternalNicParamClearRequest( vswitch_name=self.switch_name, internal_nic_name=self.switch_name)) assert response.errno == ErrNo_pb2.SYS_OK