提交 9041b0ca 编写于 作者: A alex_hold 提交者: Gitee

update extension/src/xdevice_extension/_core/environment/dmlib.py.

Signed-off-by: <hejian3@huawei.com>
上级 08979ee7
...@@ -217,14 +217,17 @@ class HdcMonitor: ...@@ -217,14 +217,17 @@ class HdcMonitor:
self.main_hdc_connection) self.main_hdc_connection)
if self.main_hdc_connection and not self.monitoring: if self.main_hdc_connection and not self.monitoring:
LOG.debug("start monitoring list targets")
self.monitoring_list_targets() self.monitoring_list_targets()
len_buf = HdcHelper.read(self.main_hdc_connection, len_buf = HdcHelper.read(self.main_hdc_connection,
DATA_UNIT_LENGTH) DATA_UNIT_LENGTH)
length = struct.unpack("!I", len_buf)[0] length = struct.unpack("!I", len_buf)[0]
LOG.debug("had received length is: %s" % length)
if length >= 0: if length >= 0:
self.monitoring = True self.monitoring = True
self.process_incoming_target_data(length) self.process_incoming_target_data(length)
except (HdcError, Exception) as _: except (HdcError, Exception) as _:
LOG.debug("loop_monitor happened error: %s" % _)
self.handle_exception_monitor_loop() self.handle_exception_monitor_loop()
break break
...@@ -273,22 +276,21 @@ class HdcMonitor: ...@@ -273,22 +276,21 @@ class HdcMonitor:
def process_incoming_target_data(self, length): def process_incoming_target_data(self, length):
local_array_list = [] local_array_list = []
if length > 0: data_buf = HdcHelper.read(self.main_hdc_connection, length)
data_buf = HdcHelper.read(self.main_hdc_connection, length) data_str = HdcHelper.reply_to_string(data_buf)
data_str = HdcHelper.reply_to_string(data_buf) if 'Empty' not in data_str:
if 'Empty' not in data_str: lines = data_str.split('\n')
lines = data_str.split('\n') for line in lines:
for line in lines: items = line.strip().split('\t')
items = line.strip().split('\t') if not items[0] :
if not items[0] : continue
continue items.append(DeviceState.ONLINE.value)
items.append(DeviceState.ONLINE.value) device_instance = self._get_device_instance(
device_instance = self._get_device_instance( items, DeviceOsType.default)
items, DeviceOsType.default) local_array_list.append(device_instance)
local_array_list.append(device_instance) else:
else: LOG.debug("please check device actually.[%s]" % data_str)
LOG.debug("please check device actually.[%s]" % data_str) LOG.debug("process target data, local_array_list" % local_array_list)
self.update_devices(local_array_list) self.update_devices(local_array_list)
def _get_device_instance(self, items, os_type): def _get_device_instance(self, items, os_type):
...@@ -751,7 +753,7 @@ class HdcHelper: ...@@ -751,7 +753,7 @@ class HdcHelper:
if not os.path.exists(local): if not os.path.exists(local):
raise HdcError("Local path doesn't exist.") raise HdcError("Local path doesn't exist.")
sock = HdcHelper.socket(host=device.host, port=device.port, sock = HdcHelper.socket(host=device.host, port=device.port,
timeout=DEFAULT_TIMEOUT) timeout=timeout)
HdcHelper.handle_shake(sock, device.device_sn) HdcHelper.handle_shake(sock, device.device_sn)
request = HdcHelper.form_hdc_request("file send %s %s" % request = HdcHelper.form_hdc_request("file send %s %s" %
(local, remote)) (local, remote))
...@@ -760,6 +762,7 @@ class HdcHelper: ...@@ -760,6 +762,7 @@ class HdcHelper:
length = struct.unpack("!I", reply)[0] length = struct.unpack("!I", reply)[0]
data_buf = HdcHelper.read(sock, length) data_buf = HdcHelper.read(sock, length)
data_str = HdcHelper.reply_to_string(data_buf) data_str = HdcHelper.reply_to_string(data_buf)
device.log.info(data_str)
@staticmethod @staticmethod
def pull_file(device, remote, local, is_create=False, def pull_file(device, remote, local, is_create=False,
...@@ -769,7 +772,7 @@ class HdcHelper: ...@@ -769,7 +772,7 @@ class HdcHelper:
(convert_serial(device.device_sn), remote, local)) (convert_serial(device.device_sn), remote, local))
sock = HdcHelper.socket(host=device.host, port=device.port, sock = HdcHelper.socket(host=device.host, port=device.port,
timeout=DEFAULT_TIMEOUT) timeout=timeout)
HdcHelper.handle_shake(sock, device.device_sn) HdcHelper.handle_shake(sock, device.device_sn)
request = HdcHelper.form_hdc_request("file recv %s %s" % request = HdcHelper.form_hdc_request("file recv %s %s" %
(local, remote)) (local, remote))
...@@ -778,6 +781,7 @@ class HdcHelper: ...@@ -778,6 +781,7 @@ class HdcHelper:
length = struct.unpack("!I", reply)[0] length = struct.unpack("!I", reply)[0]
data_buf = HdcHelper.read(sock, length) data_buf = HdcHelper.read(sock, length)
data_str = HdcHelper.reply_to_string(data_buf) data_str = HdcHelper.reply_to_string(data_buf)
device.log.info(data_str)
@staticmethod @staticmethod
def _install_remote_package(device, remote_file_path, command): def _install_remote_package(device, remote_file_path, command):
...@@ -844,6 +848,8 @@ class HdcHelper: ...@@ -844,6 +848,8 @@ class HdcHelper:
output_flag = kwargs.get("output_flag", True) output_flag = kwargs.get("output_flag", True)
timeout_msg = '' if (timeout/1000) == 300.0 else \ timeout_msg = '' if (timeout/1000) == 300.0 else \
" with timeout %ss" % str(timeout/1000) " with timeout %ss" % str(timeout/1000)
end_mark = kwargs.get("end_mark", "")
read_timeout = kwargs.get("read_timeout", None)
if device.usb_type == DeviceConnectorType.hdc: if device.usb_type == DeviceConnectorType.hdc:
message = "%s execute command: hdc shell %s%s" % \ message = "%s execute command: hdc shell %s%s" % \
(convert_serial(device.device_sn), command, (convert_serial(device.device_sn), command,
...@@ -856,26 +862,31 @@ class HdcHelper: ...@@ -856,26 +862,31 @@ class HdcHelper:
HdcHelper.handle_shake(sock, device.device_sn) HdcHelper.handle_shake(sock, device.device_sn)
request = HdcHelper.form_hdc_request("shell %s" % command) request = HdcHelper.form_hdc_request("shell %s" % command)
HdcHelper.write(sock, request) HdcHelper.write(sock, request)
len_buf = HdcHelper.read(sock, DATA_UNIT_LENGTH)
if len_buf:
length = struct.unpack("!I", len_buf)[0]
resp = HdcResponse() resp = HdcResponse()
resp.okay = True resp.okay = True
from xdevice import Scheduler from xdevice import Scheduler
data = sock.recv(SOCK_DATA_MAX) start_time = int(time.time())
while data != b'': while True:
len_buf = HdcHelper.read(sock, DATA_UNIT_LENGTH)
if len_buf:
length = struct.unpack("!I", len_buf)[0]
else:
break
data = sock.recv(length)
ret = HdcHelper.reply_to_string(data) ret = HdcHelper.reply_to_string(data)
if ret: if ret:
if receiver: if receiver:
receiver.__read__(ret) receiver.__read__(ret)
else: else:
LOG.debug(ret) LOG.debug(ret)
if end_mark and end_mark in ret:
break
if read_timeout and \
int(time.time()) - start_time > read_timeout:
break
if not Scheduler.is_execute: if not Scheduler.is_execute:
raise ExecuteTerminate() raise ExecuteTerminate()
data = HdcHelper.read(sock, SOCK_DATA_MAX)
return resp return resp
except socket.timeout as _: except socket.timeout as _:
device.log.error("%s shell %s timeout[%sS]" % ( device.log.error("%s shell %s timeout[%sS]" % (
...@@ -905,6 +916,8 @@ class HdcHelper: ...@@ -905,6 +916,8 @@ class HdcHelper:
Create an ASCII string preceded by four hex digits. Create an ASCII string preceded by four hex digits.
""" """
try: try:
if not req.endswith('\0'):
req = "%s\0" % req
req = req.encode("utf-8") req = req.encode("utf-8")
fmt = "!I%ss" % len(req) fmt = "!I%ss" % len(req)
result = struct.pack(fmt, len(req), req) result = struct.pack(fmt, len(req), req)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册