Replace deprecated xml.etree.cElementTree
cElementTree was deprecated in Python 3.3 . Use defusedxml instead of the built-in xml module to avoid potentially malicious operation[1]. [1] https://docs.python.org/3/library/xml.html#xml-vulnerabilities Change-Id: I7b2d2843fb82873e6194c040c6cdfd515de2cefe
This commit is contained in:
parent
05c9446bd9
commit
e047b428a5
|
@ -17,8 +17,8 @@
|
|||
|
||||
|
||||
import re
|
||||
import xml.etree.cElementTree as etree
|
||||
|
||||
from defusedxml import ElementTree as etree
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
import math
|
||||
import os
|
||||
|
||||
from defusedxml import ElementTree as etree
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import xml.etree.cElementTree as etree
|
||||
|
||||
from manila import exception
|
||||
from manila.i18n import _
|
||||
|
|
|
@ -21,8 +21,8 @@ import re
|
|||
import shutil
|
||||
import string
|
||||
import tempfile
|
||||
import xml.etree.cElementTree as etree
|
||||
|
||||
from defusedxml import ElementTree as etree
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import re
|
|||
import ssl
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from defusedxml import ElementTree as ET
|
||||
from defusedxml import ElementTree as etree
|
||||
from oslo_log import log as logging
|
||||
|
||||
from manila import exception
|
||||
|
@ -104,7 +104,7 @@ class QnapAPIExecutor(object):
|
|||
data = response.read()
|
||||
LOG.debug('response data: %s', data)
|
||||
|
||||
root = ET.fromstring(data)
|
||||
root = etree.fromstring(data)
|
||||
|
||||
display_model_name = root.find('model/displayModelName').text
|
||||
internal_model_name = root.find('model/internalModelName').text
|
||||
|
@ -154,7 +154,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/authLogin.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
|
@ -221,7 +221,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/wizReq.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
|
@ -258,7 +258,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/disk/disk_manage.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
|
@ -283,7 +283,7 @@ class QnapAPIExecutor(object):
|
|||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
@ -317,7 +317,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/disk/disk_manage.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
|
||||
|
@ -354,7 +354,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/disk/disk_manage.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
|
||||
|
@ -382,7 +382,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/disk/snapshot.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
@ -424,7 +424,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/disk/snapshot.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
|
@ -446,7 +446,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/disk/snapshot.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
# snapshot not exist
|
||||
|
@ -478,7 +478,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/disk/snapshot.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
@ -518,7 +518,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/priv/privWizard.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
|
@ -541,7 +541,7 @@ class QnapAPIExecutor(object):
|
|||
sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
@ -577,7 +577,7 @@ class QnapAPIExecutor(object):
|
|||
sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
@ -601,7 +601,7 @@ class QnapAPIExecutor(object):
|
|||
sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
@ -623,7 +623,7 @@ class QnapAPIExecutor(object):
|
|||
sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
@ -646,7 +646,7 @@ class QnapAPIExecutor(object):
|
|||
url = ('/cgi-bin/priv/privWizard.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
@ -677,7 +677,7 @@ class QnapAPIExecutorTS(QnapAPIExecutor):
|
|||
url = ('/cgi-bin/disk/snapshot.cgi?%s' % sanitized_params)
|
||||
|
||||
res_details = self._execute_and_get_response_details(self.ip, url)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
root = etree.fromstring(res_details['data'])
|
||||
if root.find('authPassed').text == '0':
|
||||
raise exception.ShareBackendException(msg=MSG_SESSION_EXPIRED)
|
||||
if root.find('result').text < '0':
|
||||
|
|
|
@ -17,12 +17,8 @@ from http import client as http_client
|
|||
import time
|
||||
from unittest import mock
|
||||
|
||||
try:
|
||||
import xml.etree.cElementTree as ET
|
||||
except ImportError:
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import ddt
|
||||
from defusedxml import ElementTree as etree
|
||||
from eventlet import greenthread
|
||||
from oslo_config import cfg
|
||||
|
||||
|
@ -269,7 +265,7 @@ class QnapShareDriverTestCase(QnapShareDriverBaseTestCase):
|
|||
|
||||
def get_share_info_return_value(self):
|
||||
"""Return the share info form get_share_info method."""
|
||||
root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_SHARE_INFO)
|
||||
root = etree.fromstring(fakes.FAKE_RES_DETAIL_DATA_SHARE_INFO)
|
||||
|
||||
share_list = root.find('Volume_Info')
|
||||
share_info_tree = share_list.findall('row')
|
||||
|
@ -278,7 +274,7 @@ class QnapShareDriverTestCase(QnapShareDriverBaseTestCase):
|
|||
|
||||
def get_snapshot_info_return_value(self):
|
||||
"""Return the snapshot info form get_snapshot_info method."""
|
||||
root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_SNAPSHOT)
|
||||
root = etree.fromstring(fakes.FAKE_RES_DETAIL_DATA_SNAPSHOT)
|
||||
|
||||
snapshot_list = root.find('SnapshotList')
|
||||
snapshot_info_tree = snapshot_list.findall('row')
|
||||
|
@ -287,7 +283,7 @@ class QnapShareDriverTestCase(QnapShareDriverBaseTestCase):
|
|||
|
||||
def get_specific_volinfo_return_value(self):
|
||||
"""Return the volume info form get_specific_volinfo method."""
|
||||
root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_VOLUME_INFO)
|
||||
root = etree.fromstring(fakes.FAKE_RES_DETAIL_DATA_VOLUME_INFO)
|
||||
|
||||
volume_list = root.find('Volume_Info')
|
||||
volume_info_tree = volume_list.findall('row')
|
||||
|
@ -296,7 +292,7 @@ class QnapShareDriverTestCase(QnapShareDriverBaseTestCase):
|
|||
|
||||
def get_specific_poolinfo_return_value(self):
|
||||
"""Get specific pool info."""
|
||||
root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_SPECIFIC_POOL_INFO)
|
||||
root = etree.fromstring(fakes.FAKE_RES_DETAIL_DATA_SPECIFIC_POOL_INFO)
|
||||
|
||||
pool_list = root.find('Pool_Index')
|
||||
pool_info_tree = pool_list.findall('row')
|
||||
|
@ -305,7 +301,7 @@ class QnapShareDriverTestCase(QnapShareDriverBaseTestCase):
|
|||
|
||||
def get_host_list_return_value(self):
|
||||
"""Get host list."""
|
||||
root = ET.fromstring(fakes.FAKE_RES_DETAIL_DATA_GET_HOST_LIST)
|
||||
root = etree.fromstring(fakes.FAKE_RES_DETAIL_DATA_GET_HOST_LIST)
|
||||
|
||||
hosts = []
|
||||
host_list = root.find('host_list')
|
||||
|
|
Loading…
Reference in New Issue