コード例 #1
0
    def recvRpdResetCtrl(self, cfgMsg):
        rcp_msg = self.DeSerializeConfigMsgPayload(cfgMsg)
        if rcp_msg is None:
            return {
                "Status": HalCommon_pb2.FAILED,
                "ErrorDescription": "DeSerialize ConfigMsgPayload fail"
            }
        self.logger.debug("\nProvMgr receive RpdResetCtrl:" + str(rcp_msg))
        operation = rcp_msg.RpdDataMessage.RpdDataOperation

        recv_rcp_msg = rcp_msg.RpdDataMessage.RpdData
        if recv_rcp_msg.HasField("RpdCtrl") and recv_rcp_msg.RpdCtrl.HasField(
                "ResetCtrl"):
            if operation not in [
                    t_RpdDataMessage.RPD_CFG_WRITE,
                    t_RpdDataMessage.RPD_CFG_READ
            ]:
                return {
                    "Status":
                    HalCommon_pb2.FAILED,
                    "ErrorDescription":
                    "Operation %d for RpdResetCtrl is not supported" %
                    operation
                }
            rcp_rpd_resetctrl = recv_rcp_msg.RpdCtrl.ResetCtrl
            if operation == t_RpdDataMessage.RPD_CFG_WRITE:
                reset = rcp_rpd_resetctrl.Reset
                reset_type = rcp_tlv_def.RESET_TYPE[reset]
                with open(self.RESET_CTRL_FILENAME, 'w') as f:
                    f.write(str(reset) + ":" + str(reset_type) + "\n")
                for ccap_core in CCAPCore.ccap_core_db.values():
                    ccap_core.del_ccap_core()
                SysTools.reboot(reset_type)
            if operation == t_RpdDataMessage.RPD_CFG_READ:
                try:
                    with open(self.RESET_CTRL_FILENAME, 'r') as fr:
                        reset_rd = fr.read()
                        rcp_rpd_resetctrl.Reset = int(reset_rd.strip(":")[0])
                except IOError:
                    # file don't exist,skip check
                    pass
            cfgMsg.CfgMsgPayload = rcp_msg.SerializeToString()
            return {
                "Status":
                HalCommon_pb2.SUCCESS,
                "ErrorDescription":
                "ProMgr handle RpdResetCtrl success for %d" % operation
            }
        else:
            return {
                "Status": HalCommon_pb2.SUCCESS_IGNORE_RESULT,
                "ErrorDescription": "ProvMgr Do not Have RpdCtrl Filed."
            }
コード例 #2
0
ファイル: test_utils.py プロジェクト: hujiangyi/or
    def test_sys_tools(self):
        SysTools.touch('/tmp/test_utils')
        SysTools.REBOOT_SKIP_FILES = ('/tmp/test_utils')

        self.assertFalse(SysTools.is_system_openwrt())
        self.assertEqual(SysTools.get_mac_address('if_test'),
                         "00:00:00:00:00:00")
        self.assertEqual(SysTools.get_sys_mac_address(), "00:00:00:00:00:00")

        with open('/tmp/test_mac', 'w') as f:
            f.write('01:02:03:04:05:06')
            f.close()
        SysTools.SYS_MAC_FILE = '/tmp/test_mac'
        self.assertEqual(SysTools.get_sys_mac_address(), "01:02:03:04:05:06")
        SysTools.SYS_MAC_FILE = '/etc/gshadow'
        self.assertEqual(SysTools.get_sys_mac_address(), "00:00:00:00:00:00")

        print(SysTools.get_host_name())
        print(SysTools.get_ip_address('if_test'))
        if not SysTools.reboot():
            SysTools.sys_failure_reboot('skip files exist')
        SysTools.external_reboot(('test', 'test'))
        if os.path.exists('/tmp/test_utils'):
            os.remove('/tmp/test_utils')

        # d = Dispatcher()
        # timestamp = time.time() + 1000
        # SysTools.set_system_time(d, timestamp)
        # SysTools.touch('/etc/openwrt_release')
        # SysTools.set_system_time(d, timestamp)
        # time.sleep(2)
        # self.assertTrue(timestamp > time.time()) #should no permission to change system time
        # del d
        # if os.path.exists('/etc/openwrt_release'):
        #     os.remove('/etc/openwrt_release')
        self.assertIsNotNone(SysTools.sys_up_time())
        ret = SysTools.if_indextoname(1)
        print "ifname of index 1:", ret
        self.assertIsNotNone(ret)
        ret = SysTools.if_indextoname("test")
        self.assertIsNone(ret)
        ret = SysTools.if_indextoname(600)
        self.assertIsNone(ret)

        ret = SysTools.if_nametoindex("lo")
        print "ifindex of lo:", ret
        self.assertIsNotNone(ret)
        ret = SysTools.if_nametoindex(5)
        self.assertIsNone(ret)
        ret = SysTools.if_nametoindex("dafsd")
        self.assertIsNone(ret)
        ret = SysTools.is_if_oper_up('eth0')
        self.assertTrue(ret)