Remove object imports.
This patch modifies import statements to import only modules and remove object imports as per the OpenStack import guidelines. Change-Id: Id4841375a15f41dd166bf16d4c8736954ca61440 Closes-Bug: #1650063
This commit is contained in:
parent
a8909293b5
commit
1706b3cff5
@ -11,13 +11,13 @@
|
||||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
import os.path
|
||||
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
import flask
|
||||
|
||||
from valence import config as cfg
|
||||
import valence.config as cfg
|
||||
|
||||
_app = None
|
||||
|
||||
@ -29,8 +29,9 @@ def setup_app():
|
||||
TEN_KB = 10 * 1024
|
||||
|
||||
# Configure logging
|
||||
if os.path.isfile(cfg.log_file) and os.access(cfg.log_file, os.W_OK):
|
||||
handler = RotatingFileHandler(
|
||||
if os.path.isfile(cfg.log_file) and os.access(cfg.log_file,
|
||||
os.W_OK):
|
||||
handler = logging.handlers.RotatingFileHandler(
|
||||
cfg.log_file, maxBytes=TEN_KB, backupCount=1)
|
||||
handler.setLevel(cfg.log_level)
|
||||
formatter = logging.Formatter(cfg.log_format)
|
||||
|
@ -13,7 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
from flask import request
|
||||
import flask
|
||||
|
||||
from valence.common import base
|
||||
from valence.common import types
|
||||
@ -21,7 +21,7 @@ from valence.common import types
|
||||
|
||||
def build_url(resource, resource_args, bookmark=False, base_url=None):
|
||||
if base_url is None:
|
||||
base_url = request.root_url
|
||||
base_url = flask.request.root_url
|
||||
base_url = base_url.rstrip("//")
|
||||
template = '%(url)s/%(res)s' if bookmark else '%(url)s/v1/%(res)s'
|
||||
template += '%(args)s' if resource_args.startswith('?') else '/%(args)s'
|
||||
|
@ -12,10 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from flask import abort
|
||||
from flask import request
|
||||
from flask import Response
|
||||
from flask_restful import Resource
|
||||
import flask
|
||||
import flask_restful
|
||||
from six.moves import http_client
|
||||
|
||||
from valence.api import link
|
||||
@ -52,7 +50,7 @@ class Version(base.ObjectBase):
|
||||
version.id = id
|
||||
version.status = "CURRENT" if current else "DEPRECTED"
|
||||
version.min_version = min_version
|
||||
version.links = [link.Link.make_link('self', request.url_root,
|
||||
version.links = [link.Link.make_link('self', flask.request.url_root,
|
||||
id, '', bookmark=True)]
|
||||
return version
|
||||
|
||||
@ -83,14 +81,14 @@ class RootBase(base.ObjectBase):
|
||||
return root
|
||||
|
||||
|
||||
class Root(Resource):
|
||||
class Root(flask_restful.Resource):
|
||||
|
||||
def get(self):
|
||||
obj = RootBase.convert()
|
||||
return utils.make_response(http_client.OK, obj.as_dict())
|
||||
|
||||
|
||||
class PODMProxy(Resource):
|
||||
class PODMProxy(flask_restful.Resource):
|
||||
"""Passthrough Proxy for PODM.
|
||||
|
||||
This function bypasses valence processing
|
||||
@ -106,30 +104,34 @@ class PODMProxy(Resource):
|
||||
filterext = ["Chassis", "Services", "Managers", "Systems",
|
||||
"EventService", "Nodes", "EthernetSwitches"]
|
||||
if resource not in filterext:
|
||||
abort(http_client.NOT_FOUND)
|
||||
flask.abort(http_client.NOT_FOUND)
|
||||
|
||||
def get(self, url):
|
||||
self.check_url(url)
|
||||
resp = rfs.send_request(url)
|
||||
return Response(resp.text, resp.status_code, resp.headers.items())
|
||||
return flask.Response(resp.text, resp.status_code,
|
||||
resp.headers.items())
|
||||
|
||||
def post(self, url):
|
||||
self.check_url(url)
|
||||
resp = rfs.send_request(url,
|
||||
"POST",
|
||||
headers={'Content-type': 'application/json'},
|
||||
data=request.data)
|
||||
return Response(resp.text, resp.status_code, resp.headers.items())
|
||||
data=flask.request.data)
|
||||
return flask.Response(resp.text, resp.status_code,
|
||||
resp.headers.items())
|
||||
|
||||
def delete(self, url):
|
||||
self.check_url(url)
|
||||
resp = rfs.send_request(url, "DELETE")
|
||||
return Response(resp.text, resp.status_code, resp.headers.items())
|
||||
return flask.Response(resp.text, resp.status_code,
|
||||
resp.headers.items())
|
||||
|
||||
def patch(self, url):
|
||||
self.check_url(url)
|
||||
resp = rfs.send_request(url,
|
||||
"PATCH",
|
||||
headers={'Content-type': 'application/json'},
|
||||
data=request.data)
|
||||
return Response(resp.text, resp.status_code, resp.headers.items())
|
||||
data=flask.request.data)
|
||||
return flask.Response(resp.text, resp.status_code,
|
||||
resp.headers.items())
|
||||
|
@ -15,32 +15,28 @@
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
from flask_cors import CORS
|
||||
from flask_restful import Api
|
||||
import flask_cors
|
||||
import flask_restful
|
||||
from six.moves import http_client
|
||||
|
||||
from valence.api import app as flaskapp
|
||||
from valence.api.root import PODMProxy
|
||||
from valence.api.root import Root
|
||||
from valence.api.v1.flavors import Flavors as v1Flavors
|
||||
from valence.api.v1.nodes import Nodes as v1Nodes
|
||||
from valence.api.v1.nodes import NodesList as v1NodesList
|
||||
from valence.api.v1.nodes import NodesStorage as v1NodesStorage
|
||||
from valence.api.v1.storages import Storages as v1Storages
|
||||
from valence.api.v1.storages import StoragesList as v1StoragesList
|
||||
from valence.api.v1.systems import Systems as v1Systems
|
||||
from valence.api.v1.systems import SystemsList as v1SystemsList
|
||||
from valence.api.v1.version import V1
|
||||
import valence.api.root as api_root
|
||||
import valence.api.v1.flavors as v1_flavors
|
||||
import valence.api.v1.nodes as v1_nodes
|
||||
import valence.api.v1.storages as v1_storages
|
||||
import valence.api.v1.systems as v1_systems
|
||||
import valence.api.v1.version as v1_version
|
||||
|
||||
from valence.common import exception
|
||||
from valence.common import utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
app = flaskapp.get_app()
|
||||
cors = CORS(app)
|
||||
cors = flask_cors.CORS(app)
|
||||
|
||||
|
||||
class ValenceService(Api):
|
||||
class ValenceService(flask_restful.Api):
|
||||
"""Overriding Flask Restful Error handler"""
|
||||
|
||||
def handle_error(self, error):
|
||||
@ -65,30 +61,31 @@ api = ValenceService(app)
|
||||
|
||||
|
||||
# API Root operation
|
||||
api.add_resource(Root, '/', endpoint='root')
|
||||
api.add_resource(api_root.Root, '/', endpoint='root')
|
||||
|
||||
# V1 Root operations
|
||||
api.add_resource(V1, '/v1', endpoint='v1')
|
||||
api.add_resource(v1_version.V1, '/v1', endpoint='v1')
|
||||
|
||||
# Node(s) operations
|
||||
api.add_resource(v1NodesList, '/v1/nodes', endpoint='nodes')
|
||||
api.add_resource(v1Nodes, '/v1/nodes/<string:nodeid>', endpoint='node')
|
||||
api.add_resource(v1NodesStorage,
|
||||
api.add_resource(v1_nodes.NodesList, '/v1/nodes', endpoint='nodes')
|
||||
api.add_resource(v1_nodes.Nodes, '/v1/nodes/<string:nodeid>', endpoint='node')
|
||||
api.add_resource(v1_nodes.NodesStorage,
|
||||
'/v1/nodes/<string:nodeid>/storages',
|
||||
endpoint='nodes_storages')
|
||||
|
||||
# System(s) operations
|
||||
api.add_resource(v1SystemsList, '/v1/systems', endpoint='systems')
|
||||
api.add_resource(v1Systems, '/v1/systems/<string:systemid>', endpoint='system')
|
||||
api.add_resource(v1_systems.SystemsList, '/v1/systems', endpoint='systems')
|
||||
api.add_resource(v1_systems.Systems, '/v1/systems/<string:systemid>',
|
||||
endpoint='system')
|
||||
|
||||
# Flavor(s) operations
|
||||
api.add_resource(v1Flavors, '/v1/flavors', endpoint='flavors')
|
||||
api.add_resource(v1_flavors.Flavors, '/v1/flavors', endpoint='flavors')
|
||||
|
||||
|
||||
# Storage(s) operations
|
||||
api.add_resource(v1StoragesList, '/v1/storages', endpoint='storages')
|
||||
api.add_resource(v1Storages,
|
||||
api.add_resource(v1_storages.StoragesList, '/v1/storages', endpoint='storages')
|
||||
api.add_resource(v1_storages.Storages,
|
||||
'/v1/storages/<string:storageid>', endpoint='storage')
|
||||
|
||||
# Proxy to PODM
|
||||
api.add_resource(PODMProxy, '/<path:url>', endpoint='podmproxy')
|
||||
api.add_resource(api_root.PODMProxy, '/<path:url>', endpoint='podmproxy')
|
||||
|
@ -16,13 +16,13 @@
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from valence.db import etcd_db
|
||||
import valence.db.etcd_db as valence_etcdb
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def init():
|
||||
etcd_db.init_etcd_db()
|
||||
valence_etcdb.init_etcd_db()
|
||||
|
||||
|
||||
def migrate():
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from flask import jsonify
|
||||
import flask
|
||||
import six
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -90,7 +90,7 @@ def make_response(status_code, content="", headers=None):
|
||||
:returns: return_type -- flask Response object
|
||||
"""
|
||||
|
||||
response = jsonify(content)
|
||||
response = flask.jsonify(content)
|
||||
|
||||
if isinstance(status_code, int):
|
||||
response.status_code = status_code
|
||||
|
@ -18,7 +18,6 @@ import logging
|
||||
import os
|
||||
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
from six.moves import http_client
|
||||
|
||||
from valence.common import exception
|
||||
@ -69,7 +68,8 @@ def send_request(resource, method="GET", **kwargs):
|
||||
LOG.debug(url)
|
||||
try:
|
||||
resp = requests.request(method, url, verify=False,
|
||||
auth=HTTPBasicAuth(httpuser, httppwd),
|
||||
auth=requests.auth.HTTPBasicAuth(
|
||||
httpuser, httppwd),
|
||||
**kwargs)
|
||||
except requests.exceptions.RequestException as e:
|
||||
LOG.error(e)
|
||||
|
@ -10,12 +10,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from unittest import TestCase
|
||||
import unittest
|
||||
|
||||
from valence.api import link as link_module
|
||||
|
||||
|
||||
class TestLink(TestCase):
|
||||
class TestLink(unittest.TestCase):
|
||||
def test_build_url_with_bookmark(self):
|
||||
link = link_module.build_url(
|
||||
'v1', 'flavors', bookmark=True, base_url='http://localhost:8181')
|
||||
|
@ -10,12 +10,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from unittest import TestCase
|
||||
import unittest
|
||||
|
||||
from valence.api import route
|
||||
|
||||
|
||||
class TestRoute(TestCase):
|
||||
class TestRoute(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.app = route.app
|
||||
|
@ -10,13 +10,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from unittest import TestCase
|
||||
import unittest
|
||||
|
||||
from valence.common import base
|
||||
from valence.common import types
|
||||
|
||||
|
||||
class TestTypes(TestCase):
|
||||
class TestTypes(unittest.TestCase):
|
||||
def test_text(self):
|
||||
self.assertIsNone(types.Text.validate(None))
|
||||
|
||||
|
@ -11,14 +11,13 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from unittest import TestCase
|
||||
import unittest
|
||||
|
||||
from valence.flavors import flavors
|
||||
from valence.flavors.plugins.assettag import assettagGenerator
|
||||
from valence.flavors.plugins.default import defaultGenerator
|
||||
from valence.tests.unit.fakes import flavors_fakes as fakes
|
||||
|
||||
|
||||
class TestFlavors(TestCase):
|
||||
class TestFlavors(unittest.TestCase):
|
||||
|
||||
def test_get_available_criteria(self):
|
||||
expected = {'criteria': [{'name': 'default',
|
||||
@ -36,7 +35,8 @@ class TestFlavors(TestCase):
|
||||
result = sorted(result['criteria'], key=lambda x: x['name'])
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
@mock.patch.object(assettagGenerator, 'generate')
|
||||
@mock.patch(
|
||||
'valence.flavors.plugins.assettag.assettagGenerator.generate')
|
||||
@mock.patch('uuid.uuid4')
|
||||
@mock.patch('valence.redfish.redfish.systems_list')
|
||||
def test_create_flavors_asserttag(self, mock_systems,
|
||||
@ -50,7 +50,8 @@ class TestFlavors(TestCase):
|
||||
expected = [fakes.fake_assettag_flavors()]
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
@mock.patch.object(defaultGenerator, 'generate')
|
||||
@mock.patch(
|
||||
'valence.flavors.plugins.default.defaultGenerator.generate')
|
||||
@mock.patch('uuid.uuid4')
|
||||
@mock.patch('valence.redfish.redfish.systems_list')
|
||||
def test_create_flavors_default(self, mock_systems,
|
||||
@ -64,8 +65,10 @@ class TestFlavors(TestCase):
|
||||
expected = [fakes.fake_default_flavors()]
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
@mock.patch.object(defaultGenerator, 'generate')
|
||||
@mock.patch.object(assettagGenerator, 'generate')
|
||||
@mock.patch(
|
||||
'valence.flavors.plugins.default.defaultGenerator.generate')
|
||||
@mock.patch(
|
||||
'valence.flavors.plugins.assettag.assettagGenerator.generate')
|
||||
@mock.patch('uuid.uuid4')
|
||||
@mock.patch('valence.redfish.redfish.systems_list')
|
||||
def test_create_flavors_asserttag_and_default(self, mock_systems,
|
||||
|
Loading…
Reference in New Issue
Block a user