NSX|V: fix validations for non-ascii characters
A non-ascii names will be ignored. Change-Id: Ia7aa1b054f6b01111f7fb25f921a6e3469001395 (cherry picked from commit3a65ce0ae0
) (cherry picked from commit8e07af16b6
)
This commit is contained in:
parent
53beb032bd
commit
f56f23f183
|
@ -23,6 +23,7 @@ from oslo_config import cfg
|
|||
from oslo_log import log
|
||||
import retrying
|
||||
import six
|
||||
import xml.etree.ElementTree as et
|
||||
|
||||
from vmware_nsx._i18n import _, _LE
|
||||
|
||||
|
@ -112,6 +113,11 @@ def is_internal_resource(nsx_resource):
|
|||
return False
|
||||
|
||||
|
||||
def normalize_xml(data):
|
||||
data = data.encode('ascii', 'ignore')
|
||||
return et.fromstring(data)
|
||||
|
||||
|
||||
def build_v3_api_version_tag():
|
||||
"""
|
||||
Some resources are created on the manager that do not have a corresponding
|
||||
|
|
|
@ -25,6 +25,7 @@ import xml.etree.ElementTree as et
|
|||
|
||||
from vmware_nsx._i18n import _LE
|
||||
from vmware_nsx.common import nsxv_constants
|
||||
from vmware_nsx.common import utils
|
||||
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions
|
||||
from vmware_nsx.plugins.nsx_v.vshield.common import VcnsApiClient
|
||||
|
||||
|
@ -529,7 +530,7 @@ class Vcns(object):
|
|||
def get_security_group_id(self, sg_name):
|
||||
"""Returns NSXv security group id which match the given name."""
|
||||
h, secgroups = self.list_security_groups()
|
||||
root = et.fromstring(secgroups)
|
||||
root = utils.normalize_xml(secgroups)
|
||||
for sg in root.iter('securitygroup'):
|
||||
if sg.find('name').text == sg_name:
|
||||
return sg.find('objectId').text
|
||||
|
@ -590,7 +591,7 @@ class Vcns(object):
|
|||
def get_section_id(self, section_name):
|
||||
"""Retrieve the id of a section from nsx."""
|
||||
h, firewall_config = self.get_dfw_config()
|
||||
root = et.fromstring(firewall_config)
|
||||
root = utils.normalize_xml(firewall_config)
|
||||
for sec in root.iter('section'):
|
||||
if sec.attrib['name'] == section_name:
|
||||
return sec.attrib['id']
|
||||
|
@ -762,8 +763,7 @@ class Vcns(object):
|
|||
uri = '%s/usermgmt/scopingobjects' % SERVICES_PREFIX
|
||||
h, so_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||
format='xml')
|
||||
|
||||
root = et.fromstring(so_list)
|
||||
root = utils.normalize_xml(so_list)
|
||||
for obj in root.iter('object'):
|
||||
if (obj.find('objectTypeName').text == type_name and
|
||||
obj.find('objectId').text == object_id and
|
||||
|
@ -791,8 +791,7 @@ class Vcns(object):
|
|||
uri = '%s/scopes' % VDN_PREFIX
|
||||
h, scope_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||
format='xml')
|
||||
|
||||
root = et.fromstring(scope_list)
|
||||
root = utils.normalize_xml(scope_list)
|
||||
for obj_id in root.iter('objectId'):
|
||||
if obj_id.text == object_id:
|
||||
return True
|
||||
|
@ -803,8 +802,7 @@ class Vcns(object):
|
|||
uri = '%s/switches' % VDN_PREFIX
|
||||
h, dvs_list = self.do_request(HTTP_GET, uri, decode=False,
|
||||
format='xml')
|
||||
|
||||
root = et.fromstring(dvs_list)
|
||||
root = utils.normalize_xml(dvs_list)
|
||||
for obj_id in root.iter('objectId'):
|
||||
if obj_id.text == object_id:
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue