Clean imports in code
In some part in the code we import objects. In the Openstack style guidelines they recommend to import only modules. http://docs.openstack.org/developer/hacking/#imports Change-Id: Ib3ded82524071c97f4e0508af7933ead63cc2dc5
This commit is contained in:
@@ -16,13 +16,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import keystonemiddleware.audit as audit_middleware
|
import keystonemiddleware.audit as audit_middleware
|
||||||
from keystonemiddleware.audit import PycadfAuditApiConfigError
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
import oslo_middleware.cors as cors_middleware
|
import oslo_middleware.cors as cors_middleware
|
||||||
import pecan
|
import pecan
|
||||||
|
|
||||||
from ironic.api import config
|
from ironic.api import config
|
||||||
from ironic.api.controllers.base import Version
|
from ironic.api.controllers import base
|
||||||
from ironic.api import hooks
|
from ironic.api import hooks
|
||||||
from ironic.api import middleware
|
from ironic.api import middleware
|
||||||
from ironic.api.middleware import auth_token
|
from ironic.api.middleware import auth_token
|
||||||
@@ -67,7 +66,8 @@ def setup_app(pecan_config=None, extra_hooks=None):
|
|||||||
audit_map_file=CONF.audit.audit_map_file,
|
audit_map_file=CONF.audit.audit_map_file,
|
||||||
ignore_req_list=CONF.audit.ignore_req_list
|
ignore_req_list=CONF.audit.ignore_req_list
|
||||||
)
|
)
|
||||||
except (EnvironmentError, OSError, PycadfAuditApiConfigError) as e:
|
except (EnvironmentError, OSError,
|
||||||
|
audit_middleware.PycadfAuditApiConfigError) as e:
|
||||||
raise exception.InputFileError(
|
raise exception.InputFileError(
|
||||||
file_name=CONF.audit.audit_map_file,
|
file_name=CONF.audit.audit_map_file,
|
||||||
reason=e
|
reason=e
|
||||||
@@ -82,9 +82,11 @@ def setup_app(pecan_config=None, extra_hooks=None):
|
|||||||
# included in all CORS responses.
|
# included in all CORS responses.
|
||||||
app = cors_middleware.CORS(app, CONF)
|
app = cors_middleware.CORS(app, CONF)
|
||||||
app.set_latent(
|
app.set_latent(
|
||||||
allow_headers=[Version.max_string, Version.min_string, Version.string],
|
allow_headers=[base.Version.max_string, base.Version.min_string,
|
||||||
|
base.Version.string],
|
||||||
allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'],
|
allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'],
|
||||||
expose_headers=[Version.max_string, Version.min_string, Version.string]
|
expose_headers=[base.Version.max_string, base.Version.min_string,
|
||||||
|
base.Version.string]
|
||||||
)
|
)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import pecan
|
|||||||
from pecan import rest
|
from pecan import rest
|
||||||
import six
|
import six
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
from webob.static import FileIter
|
from webob import static
|
||||||
import wsme
|
import wsme
|
||||||
|
|
||||||
from ironic.api.controllers.v1 import versions
|
from ironic.api.controllers.v1 import versions
|
||||||
@@ -203,7 +203,7 @@ def vendor_passthru(ident, method, topic, data=None, driver_passthru=False):
|
|||||||
# If unicode, convert to bytes
|
# If unicode, convert to bytes
|
||||||
return_value = return_value.encode('utf-8')
|
return_value = return_value.encode('utf-8')
|
||||||
file_ = wsme.types.File(content=return_value)
|
file_ = wsme.types.File(content=return_value)
|
||||||
pecan.response.app_iter = FileIter(file_.file)
|
pecan.response.app_iter = static.FileIter(file_.file)
|
||||||
# Since we've attached the return value to the response
|
# Since we've attached the return value to the response
|
||||||
# object the response body should now be empty.
|
# object the response body should now be empty.
|
||||||
return_value = None
|
return_value = None
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
Common functionalities for AMT Driver
|
Common functionalities for AMT Driver
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
from xml.etree import ElementTree
|
from xml import etree
|
||||||
|
|
||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
@@ -216,7 +216,7 @@ def xml_find(doc, namespace, item):
|
|||||||
"""
|
"""
|
||||||
if doc is None:
|
if doc is None:
|
||||||
raise exception.AMTConnectFailure()
|
raise exception.AMTConnectFailure()
|
||||||
tree = ElementTree.fromstring(doc.root().string())
|
tree = etree.ElementTree.fromstring(doc.root().string())
|
||||||
query = ('.//{%(namespace)s}%(item)s' % {'namespace': namespace,
|
query = ('.//{%(namespace)s}%(item)s' % {'namespace': namespace,
|
||||||
'item': item})
|
'item': item})
|
||||||
return tree.find(query)
|
return tree.find(query)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ https://github.com/MSOpenTech/ChassisManager
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import posixpath
|
import posixpath
|
||||||
from xml.etree import ElementTree
|
from xml import etree
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import requests
|
import requests
|
||||||
@@ -80,8 +80,8 @@ class MSFTOCSClientApi(object):
|
|||||||
|
|
||||||
def _check_completion_code(self, xml_response):
|
def _check_completion_code(self, xml_response):
|
||||||
try:
|
try:
|
||||||
et = ElementTree.fromstring(xml_response)
|
et = etree.ElementTree.fromstring(xml_response)
|
||||||
except ElementTree.ParseError as ex:
|
except etree.ElementTree.ParseError as ex:
|
||||||
LOG.exception(_LE("XML parsing failed: %s"), ex)
|
LOG.exception(_LE("XML parsing failed: %s"), ex)
|
||||||
raise exception.MSFTOCSClientApiException(
|
raise exception.MSFTOCSClientApiException(
|
||||||
_("Invalid XML: %s") % xml_response)
|
_("Invalid XML: %s") % xml_response)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import json
|
|||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
from testtools.matchers import HasLength
|
from testtools import matchers
|
||||||
|
|
||||||
from ironic.api.controllers import base as api_base
|
from ironic.api.controllers import base as api_base
|
||||||
from ironic.api.controllers.v1 import driver
|
from ironic.api.controllers.v1 import driver
|
||||||
@@ -50,7 +50,7 @@ class TestListDrivers(base.BaseApiTest):
|
|||||||
{'name': self.d2, 'hosts': [self.h1, self.h2]},
|
{'name': self.d2, 'hosts': [self.h1, self.h2]},
|
||||||
], key=lambda d: d['name'])
|
], key=lambda d: d['name'])
|
||||||
data = self.get_json('/drivers')
|
data = self.get_json('/drivers')
|
||||||
self.assertThat(data['drivers'], HasLength(2))
|
self.assertThat(data['drivers'], matchers.HasLength(2))
|
||||||
drivers = sorted(data['drivers'], key=lambda d: d['name'])
|
drivers = sorted(data['drivers'], key=lambda d: d['name'])
|
||||||
for i in range(len(expected)):
|
for i in range(len(expected)):
|
||||||
d = drivers[i]
|
d = drivers[i]
|
||||||
@@ -61,7 +61,7 @@ class TestListDrivers(base.BaseApiTest):
|
|||||||
|
|
||||||
def test_drivers_no_active_conductor(self):
|
def test_drivers_no_active_conductor(self):
|
||||||
data = self.get_json('/drivers')
|
data = self.get_json('/drivers')
|
||||||
self.assertThat(data['drivers'], HasLength(0))
|
self.assertThat(data['drivers'], matchers.HasLength(0))
|
||||||
self.assertEqual([], data['drivers'])
|
self.assertEqual([], data['drivers'])
|
||||||
|
|
||||||
@mock.patch.object(rpcapi.ConductorAPI, 'get_driver_properties')
|
@mock.patch.object(rpcapi.ConductorAPI, 'get_driver_properties')
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ from oslo_utils import uuidutils
|
|||||||
import six
|
import six
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
from testtools.matchers import HasLength
|
from testtools import matchers
|
||||||
from wsme import types as wtypes
|
from wsme import types as wtypes
|
||||||
|
|
||||||
from ironic.api.controllers import base as api_base
|
from ironic.api.controllers import base as api_base
|
||||||
@@ -560,7 +560,7 @@ class TestListNodes(test_api_base.BaseApiTest):
|
|||||||
data = self.get_json('/nodes?instance_uuid=%s' % instance_uuid,
|
data = self.get_json('/nodes?instance_uuid=%s' % instance_uuid,
|
||||||
headers={api_base.Version.string: "1.5"})
|
headers={api_base.Version.string: "1.5"})
|
||||||
|
|
||||||
self.assertThat(data['nodes'], HasLength(1))
|
self.assertThat(data['nodes'], matchers.HasLength(1))
|
||||||
self.assertEqual(node['instance_uuid'],
|
self.assertEqual(node['instance_uuid'],
|
||||||
data['nodes'][0]["instance_uuid"])
|
data['nodes'][0]["instance_uuid"])
|
||||||
|
|
||||||
@@ -572,7 +572,7 @@ class TestListNodes(test_api_base.BaseApiTest):
|
|||||||
|
|
||||||
data = self.get_json('/nodes?instance_uuid=%s' % wrong_uuid)
|
data = self.get_json('/nodes?instance_uuid=%s' % wrong_uuid)
|
||||||
|
|
||||||
self.assertThat(data['nodes'], HasLength(0))
|
self.assertThat(data['nodes'], matchers.HasLength(0))
|
||||||
|
|
||||||
def test_node_by_instance_uuid_invalid_uuid(self):
|
def test_node_by_instance_uuid_invalid_uuid(self):
|
||||||
response = self.get_json('/nodes?instance_uuid=fake',
|
response = self.get_json('/nodes?instance_uuid=fake',
|
||||||
@@ -618,13 +618,13 @@ class TestListNodes(test_api_base.BaseApiTest):
|
|||||||
|
|
||||||
data = self.get_json('/nodes?associated=False&limit=2')
|
data = self.get_json('/nodes?associated=False&limit=2')
|
||||||
|
|
||||||
self.assertThat(data['nodes'], HasLength(2))
|
self.assertThat(data['nodes'], matchers.HasLength(2))
|
||||||
self.assertIn(data['nodes'][0]['uuid'], unassociated_nodes)
|
self.assertIn(data['nodes'][0]['uuid'], unassociated_nodes)
|
||||||
|
|
||||||
def test_next_link_with_association(self):
|
def test_next_link_with_association(self):
|
||||||
self._create_association_test_nodes()
|
self._create_association_test_nodes()
|
||||||
data = self.get_json('/nodes/?limit=3&associated=True')
|
data = self.get_json('/nodes/?limit=3&associated=True')
|
||||||
self.assertThat(data['nodes'], HasLength(3))
|
self.assertThat(data['nodes'], matchers.HasLength(3))
|
||||||
self.assertIn('associated=True', data['next'])
|
self.assertIn('associated=True', data['next'])
|
||||||
|
|
||||||
def test_detail_with_association_filter(self):
|
def test_detail_with_association_filter(self):
|
||||||
@@ -637,7 +637,7 @@ class TestListNodes(test_api_base.BaseApiTest):
|
|||||||
def test_next_link_with_association_with_detail(self):
|
def test_next_link_with_association_with_detail(self):
|
||||||
self._create_association_test_nodes()
|
self._create_association_test_nodes()
|
||||||
data = self.get_json('/nodes/detail?limit=3&associated=true')
|
data = self.get_json('/nodes/detail?limit=3&associated=true')
|
||||||
self.assertThat(data['nodes'], HasLength(3))
|
self.assertThat(data['nodes'], matchers.HasLength(3))
|
||||||
self.assertIn('driver', data['nodes'][0])
|
self.assertIn('driver', data['nodes'][0])
|
||||||
self.assertIn('associated=True', data['next'])
|
self.assertIn('associated=True', data['next'])
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from oslo_utils import uuidutils
|
|||||||
import six
|
import six
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
from testtools.matchers import HasLength
|
from testtools import matchers
|
||||||
from wsme import types as wtypes
|
from wsme import types as wtypes
|
||||||
|
|
||||||
from ironic.api.controllers import base as api_base
|
from ironic.api.controllers import base as api_base
|
||||||
@@ -249,13 +249,13 @@ class TestListPorts(test_api_base.BaseApiTest):
|
|||||||
|
|
||||||
target_address = address_template % 1
|
target_address = address_template % 1
|
||||||
data = self.get_json('/ports?address=%s' % target_address)
|
data = self.get_json('/ports?address=%s' % target_address)
|
||||||
self.assertThat(data['ports'], HasLength(1))
|
self.assertThat(data['ports'], matchers.HasLength(1))
|
||||||
self.assertEqual(target_address, data['ports'][0]['address'])
|
self.assertEqual(target_address, data['ports'][0]['address'])
|
||||||
|
|
||||||
def test_port_by_address_non_existent_address(self):
|
def test_port_by_address_non_existent_address(self):
|
||||||
# non-existent address
|
# non-existent address
|
||||||
data = self.get_json('/ports?address=%s' % 'aa:bb:cc:dd:ee:ff')
|
data = self.get_json('/ports?address=%s' % 'aa:bb:cc:dd:ee:ff')
|
||||||
self.assertThat(data['ports'], HasLength(0))
|
self.assertThat(data['ports'], matchers.HasLength(0))
|
||||||
|
|
||||||
def test_port_by_address_invalid_address_format(self):
|
def test_port_by_address_invalid_address_format(self):
|
||||||
obj_utils.create_test_port(self.context, node_id=self.node.id)
|
obj_utils.create_test_port(self.context, node_id=self.node.id)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from oslo_config import cfg
|
|||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
import pecan
|
import pecan
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
from webob.static import FileIter
|
from webob import static
|
||||||
import wsme
|
import wsme
|
||||||
|
|
||||||
from ironic.api.controllers.v1 import node as api_node
|
from ironic.api.controllers.v1 import node as api_node
|
||||||
@@ -443,7 +443,7 @@ class TestVendorPassthru(base.TestCase):
|
|||||||
'fake-data', 'fake-topic')
|
'fake-data', 'fake-topic')
|
||||||
|
|
||||||
# Assert file was attached to the response object
|
# Assert file was attached to the response object
|
||||||
self.assertIsInstance(mock_response.app_iter, FileIter)
|
self.assertIsInstance(mock_response.app_iter, static.FileIter)
|
||||||
self.assertEqual(expct_return_value,
|
self.assertEqual(expct_return_value,
|
||||||
mock_response.app_iter.file.read())
|
mock_response.app_iter.file.read())
|
||||||
# Assert response message is none
|
# Assert response message is none
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from xml.etree import ElementTree
|
from xml import etree
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
@@ -37,13 +37,14 @@ def build_soap_xml(items, namespace=None):
|
|||||||
xml_string = "{%(namespace)s}%(item)s" % {'namespace': namespace,
|
xml_string = "{%(namespace)s}%(item)s" % {'namespace': namespace,
|
||||||
'item': xml_string}
|
'item': xml_string}
|
||||||
|
|
||||||
element = ElementTree.Element(xml_string)
|
element = etree.ElementTree.Element(xml_string)
|
||||||
element.text = value
|
element.text = value
|
||||||
return element
|
return element
|
||||||
|
|
||||||
soap_namespace = "http://www.w3.org/2003/05/soap-envelope"
|
soap_namespace = "http://www.w3.org/2003/05/soap-envelope"
|
||||||
envelope_element = ElementTree.Element("{%s}Envelope" % soap_namespace)
|
envelope_element = etree.ElementTree.Element(
|
||||||
body_element = ElementTree.Element("{%s}Body" % soap_namespace)
|
"{%s}Envelope" % soap_namespace)
|
||||||
|
body_element = etree.ElementTree.Element("{%s}Body" % soap_namespace)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
for i in item:
|
for i in item:
|
||||||
@@ -57,7 +58,7 @@ def build_soap_xml(items, namespace=None):
|
|||||||
body_element.append(insertion_point)
|
body_element.append(insertion_point)
|
||||||
|
|
||||||
envelope_element.append(body_element)
|
envelope_element.append(body_element)
|
||||||
return ElementTree.tostring(envelope_element)
|
return etree.ElementTree.tostring(envelope_element)
|
||||||
|
|
||||||
|
|
||||||
def mock_wsman_root(return_value):
|
def mock_wsman_root(return_value):
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import mock
|
import mock
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
from testtools.matchers import HasLength
|
from testtools import matchers
|
||||||
|
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
from ironic import objects
|
from ironic import objects
|
||||||
@@ -99,6 +99,6 @@ class TestChassisObject(base.DbTestCase):
|
|||||||
autospec=True) as mock_get_list:
|
autospec=True) as mock_get_list:
|
||||||
mock_get_list.return_value = [self.fake_chassis]
|
mock_get_list.return_value = [self.fake_chassis]
|
||||||
chassis = objects.Chassis.list(self.context)
|
chassis = objects.Chassis.list(self.context)
|
||||||
self.assertThat(chassis, HasLength(1))
|
self.assertThat(chassis, matchers.HasLength(1))
|
||||||
self.assertIsInstance(chassis[0], objects.Chassis)
|
self.assertIsInstance(chassis[0], objects.Chassis)
|
||||||
self.assertEqual(self.context, chassis[0]._context)
|
self.assertEqual(self.context, chassis[0]._context)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from testtools.matchers import HasLength
|
from testtools import matchers
|
||||||
|
|
||||||
from ironic.common import context
|
from ironic.common import context
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
@@ -113,7 +113,7 @@ class TestNodeObject(base.DbTestCase):
|
|||||||
autospec=True) as mock_get_list:
|
autospec=True) as mock_get_list:
|
||||||
mock_get_list.return_value = [self.fake_node]
|
mock_get_list.return_value = [self.fake_node]
|
||||||
nodes = objects.Node.list(self.context)
|
nodes = objects.Node.list(self.context)
|
||||||
self.assertThat(nodes, HasLength(1))
|
self.assertThat(nodes, matchers.HasLength(1))
|
||||||
self.assertIsInstance(nodes[0], objects.Node)
|
self.assertIsInstance(nodes[0], objects.Node)
|
||||||
self.assertEqual(self.context, nodes[0]._context)
|
self.assertEqual(self.context, nodes[0]._context)
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import mock
|
import mock
|
||||||
from testtools.matchers import HasLength
|
from testtools import matchers
|
||||||
|
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
from ironic import objects
|
from ironic import objects
|
||||||
@@ -109,6 +109,6 @@ class TestPortObject(base.DbTestCase):
|
|||||||
autospec=True) as mock_get_list:
|
autospec=True) as mock_get_list:
|
||||||
mock_get_list.return_value = [self.fake_port]
|
mock_get_list.return_value = [self.fake_port]
|
||||||
ports = objects.Port.list(self.context)
|
ports = objects.Port.list(self.context)
|
||||||
self.assertThat(ports, HasLength(1))
|
self.assertThat(ports, matchers.HasLength(1))
|
||||||
self.assertIsInstance(ports[0], objects.Port)
|
self.assertIsInstance(ports[0], objects.Port)
|
||||||
self.assertEqual(self.context, ports[0]._context)
|
self.assertEqual(self.context, ports[0]._context)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import mock
|
import mock
|
||||||
from testtools.matchers import HasLength
|
from testtools import matchers
|
||||||
|
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
from ironic import objects
|
from ironic import objects
|
||||||
@@ -119,7 +119,7 @@ class TestPortgroupObject(base.DbTestCase):
|
|||||||
autospec=True) as mock_get_list:
|
autospec=True) as mock_get_list:
|
||||||
mock_get_list.return_value = [self.fake_portgroup]
|
mock_get_list.return_value = [self.fake_portgroup]
|
||||||
portgroups = objects.Portgroup.list(self.context)
|
portgroups = objects.Portgroup.list(self.context)
|
||||||
self.assertThat(portgroups, HasLength(1))
|
self.assertThat(portgroups, matchers.HasLength(1))
|
||||||
self.assertIsInstance(portgroups[0], objects.Portgroup)
|
self.assertIsInstance(portgroups[0], objects.Portgroup)
|
||||||
self.assertEqual(self.context, portgroups[0]._context)
|
self.assertEqual(self.context, portgroups[0]._context)
|
||||||
|
|
||||||
@@ -130,6 +130,6 @@ class TestPortgroupObject(base.DbTestCase):
|
|||||||
node_id = self.fake_portgroup['node_id']
|
node_id = self.fake_portgroup['node_id']
|
||||||
portgroups = objects.Portgroup.list_by_node_id(self.context,
|
portgroups = objects.Portgroup.list_by_node_id(self.context,
|
||||||
node_id)
|
node_id)
|
||||||
self.assertThat(portgroups, HasLength(1))
|
self.assertThat(portgroups, matchers.HasLength(1))
|
||||||
self.assertIsInstance(portgroups[0], objects.Portgroup)
|
self.assertIsInstance(portgroups[0], objects.Portgroup)
|
||||||
self.assertEqual(self.context, portgroups[0]._context)
|
self.assertEqual(self.context, portgroups[0]._context)
|
||||||
|
|||||||
Reference in New Issue
Block a user