diff options
author | Joe Gordon <jogo@cloudscaling.com> | 2012-02-29 23:06:09 -0800 |
---|---|---|
committer | Joe Gordon <jogo@cloudscaling.com> | 2012-03-01 13:22:30 -0800 |
commit | f1bf4661ff1e1938a5bc1ef55ccec99cae4f2af7 (patch) | |
tree | d6ebd3f56debc05e6b48686f11bf1795afe92c3a | |
parent | 04e57f169646dff5309177ce5dfa444f668bf8a1 (diff) | |
download | nova-f1bf4661ff1e1938a5bc1ef55ccec99cae4f2af7.tar.gz nova-f1bf4661ff1e1938a5bc1ef55ccec99cae4f2af7.tar.xz nova-f1bf4661ff1e1938a5bc1ef55ccec99cae4f2af7.zip |
Minor cleanup based on HACKING
Change-Id: I59f02c33c3ecb0c446755a07562060a12f85e177
-rw-r--r-- | nova/api/openstack/compute/contrib/simple_tenant_usage.py | 22 | ||||
-rw-r--r-- | nova/image/glance.py | 4 | ||||
-rw-r--r-- | nova/network/quantum/melange_ipam_lib.py | 9 | ||||
-rw-r--r-- | nova/notifier/list_notifier.py | 4 | ||||
-rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_users.py | 11 | ||||
-rw-r--r-- | nova/tests/api/openstack/fakes.py | 17 | ||||
-rw-r--r-- | nova/tests/scheduler/test_distributed_scheduler.py | 3 | ||||
-rw-r--r-- | nova/tests/test_misc.py | 5 | ||||
-rw-r--r-- | nova/tests/test_utils.py | 3 |
9 files changed, 43 insertions, 35 deletions
diff --git a/nova/api/openstack/compute/contrib/simple_tenant_usage.py b/nova/api/openstack/compute/contrib/simple_tenant_usage.py index fd1a95949..61fceb39c 100644 --- a/nova/api/openstack/compute/contrib/simple_tenant_usage.py +++ b/nova/api/openstack/compute/contrib/simple_tenant_usage.py @@ -15,7 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. -from datetime import datetime +import datetime import urlparse import webob @@ -73,12 +73,12 @@ class SimpleTenantUsageController(object): launched_at = instance['launched_at'] terminated_at = instance['terminated_at'] if terminated_at is not None: - if not isinstance(terminated_at, datetime): + if not isinstance(terminated_at, datetime.datetime): terminated_at = datetime.strptime(terminated_at, "%Y-%m-%d %H:%M:%S.%f") if launched_at is not None: - if not isinstance(launched_at, datetime): + if not isinstance(launched_at, datetime.datetime): launched_at = datetime.strptime(launched_at, "%Y-%m-%d %H:%M:%S.%f") @@ -153,7 +153,7 @@ class SimpleTenantUsageController(object): else: info['state'] = instance['vm_state'] - now = datetime.utcnow() + now = datetime.datetime.utcnow() if info['state'] == 'terminated': delta = info['ended_at'] - info['started_at'] @@ -188,23 +188,25 @@ class SimpleTenantUsageController(object): return rval.values() def _parse_datetime(self, dtstr): - if isinstance(dtstr, datetime): + if isinstance(dtstr, datetime.datetime): return dtstr try: - return datetime.strptime(dtstr, "%Y-%m-%dT%H:%M:%S") + return datetime.datetime.strptime(dtstr, "%Y-%m-%dT%H:%M:%S") except Exception: try: - return datetime.strptime(dtstr, "%Y-%m-%dT%H:%M:%S.%f") + return datetime.datetime.strptime(dtstr, + "%Y-%m-%dT%H:%M:%S.%f") except Exception: - return datetime.strptime(dtstr, "%Y-%m-%d %H:%M:%S.%f") + return datetime.datetime.strptime(dtstr, + "%Y-%m-%d %H:%M:%S.%f") def _get_datetime_range(self, req): qs = req.environ.get('QUERY_STRING', '') env = urlparse.parse_qs(qs) period_start = self._parse_datetime(env.get('start', - [datetime.utcnow().isoformat()])[0]) + [datetime.datetime.utcnow().isoformat()])[0]) period_stop = self._parse_datetime(env.get('end', - [datetime.utcnow().isoformat()])[0]) + [datetime.datetime.utcnow().isoformat()])[0]) detailed = bool(env.get('detailed', False)) return (period_start, period_stop, detailed) diff --git a/nova/image/glance.py b/nova/image/glance.py index 776273209..f999bb390 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -24,7 +24,7 @@ import datetime import json import random import time -from urlparse import urlparse +import urlparse from glance.common import exception as glance_exception @@ -52,7 +52,7 @@ def _parse_image_ref(image_href): :raises ValueError """ - o = urlparse(image_href) + o = urlparse.urlparse(image_href) port = o.port or 80 host = o.netloc.split(':', 1)[0] image_id = o.path.split('/')[-1] diff --git a/nova/network/quantum/melange_ipam_lib.py b/nova/network/quantum/melange_ipam_lib.py index 3502c58e3..c68d83c5b 100644 --- a/nova/network/quantum/melange_ipam_lib.py +++ b/nova/network/quantum/melange_ipam_lib.py @@ -15,7 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. -from netaddr import IPNetwork, IPAddress +import netaddr + from nova import db from nova import exception from nova import flags @@ -72,8 +73,8 @@ class QuantumMelangeIPAMLib(object): "label": label} if FLAGS.quantum_use_dhcp: if cidr: - n = IPNetwork(cidr) - net['dhcp_start'] = IPAddress(n.first + 2) + n = netaddr.IPNetwork(cidr) + net['dhcp_start'] = netaddr.IPAddress(n.first + 2) else: net['dhcp_start'] = None admin_context = context.elevated() @@ -216,7 +217,7 @@ class QuantumMelangeIPAMLib(object): tenant_id = project_id or FLAGS.quantum_default_tenant_id ip_list = self.m_conn.get_allocated_ips(net_id, vif_id, tenant_id) return [ip['address'] for ip in ip_list - if IPNetwork(ip['address']).version == ip_version] + if netaddr.IPNetwork(ip['address']).version == ip_version] def verify_subnet_exists(self, context, project_id, quantum_net_id): """Confirms that a subnet exists that is associated with the diff --git a/nova/notifier/list_notifier.py b/nova/notifier/list_notifier.py index 886e30c73..2f5c9e4a8 100644 --- a/nova/notifier/list_notifier.py +++ b/nova/notifier/list_notifier.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +import nova.exception from nova import flags from nova import log as logging from nova.openstack.common import cfg from nova import utils -from nova.exception import ClassNotFound list_notifier_drivers_opt = cfg.MultiStrOpt('list_notifier_drivers', @@ -50,7 +50,7 @@ def _get_drivers(): for notification_driver in FLAGS.list_notifier_drivers: try: drivers.append(utils.import_object(notification_driver)) - except ClassNotFound as e: + except nova.exception.ClassNotFound as e: drivers.append(ImportFailureNotifier(e)) return drivers diff --git a/nova/tests/api/openstack/compute/contrib/test_users.py b/nova/tests/api/openstack/compute/contrib/test_users.py index 3dd0b3074..c67cdf692 100644 --- a/nova/tests/api/openstack/compute/contrib/test_users.py +++ b/nova/tests/api/openstack/compute/contrib/test_users.py @@ -16,7 +16,7 @@ from lxml import etree from nova.api.openstack.compute.contrib import users -from nova.auth.manager import User, Project +import nova.auth.manager as auth_manager from nova import test from nova.tests.api.openstack import fakes from nova import utils @@ -33,7 +33,8 @@ class UsersTest(test.TestCase): self.stubs.Set(users.Controller, '__init__', fake_init) fakes.FakeAuthManager.clear_fakes() - fakes.FakeAuthManager.projects = dict(testacct=Project('testacct', + fakes.FakeAuthManager.projects = dict(testacct=auth_manager.Project( + 'testacct', 'testacct', 'id1', 'test', @@ -44,8 +45,10 @@ class UsersTest(test.TestCase): fakes.stub_out_auth(self.stubs) fakemgr = fakes.FakeAuthManager() - fakemgr.add_user(User('id1', 'guy1', 'acc1', 'secret1', False)) - fakemgr.add_user(User('id2', 'guy2', 'acc2', 'secret2', True)) + fakemgr.add_user(auth_manager.User('id1', 'guy1', + 'acc1', 'secret1', False)) + fakemgr.add_user(auth_manager.User('id2', 'guy2', + 'acc2', 'secret2', True)) self.controller = users.Controller() diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py index fe48dd88d..78d0d6da4 100644 --- a/nova/tests/api/openstack/fakes.py +++ b/nova/tests/api/openstack/fakes.py @@ -32,7 +32,7 @@ from nova.api.openstack.compute import limits from nova.api.openstack import urlmap from nova.api.openstack.compute import versions from nova.api.openstack import wsgi as os_wsgi -from nova.auth.manager import User, Project +import nova.auth.manager as auth_manager from nova.compute import instance_types from nova.compute import vm_states from nova import context @@ -349,9 +349,9 @@ class FakeAuthManager(object): @classmethod def reset_fake_data(cls): - u1 = User('id1', 'guy1', 'acc1', 'secret1', False) + u1 = auth_manager.User('id1', 'guy1', 'acc1', 'secret1', False) cls.auth_data = [u1] - cls.projects = dict(testacct=Project('testacct', + cls.projects = dict(testacct=auth_manager.Project('testacct', 'testacct', 'id1', 'test', @@ -382,7 +382,7 @@ class FakeAuthManager(object): return None def create_user(self, name, access=None, secret=None, admin=False): - u = User(name, name, access, secret, admin) + u = auth_manager.User(name, name, access, secret, admin) FakeAuthManager.auth_data.append(u) return u @@ -399,7 +399,7 @@ class FakeAuthManager(object): return user.admin def is_project_member(self, user_id, project): - if not isinstance(project, Project): + if not isinstance(project, auth_manager.Project): try: project = self.get_project(project) except exc.NotFound: @@ -409,9 +409,10 @@ class FakeAuthManager(object): def create_project(self, name, manager_user, description=None, member_users=None): - member_ids = ([User.safe_id(m) for m in member_users] + member_ids = ([auto_manager.User.safe_id(m) for m in member_users] if member_users else []) - p = Project(name, name, User.safe_id(manager_user), + p = auth_manager.Project(name, name, + auth_manager.User.safe_id(manager_user), description, member_ids) FakeAuthManager.projects[name] = p return p @@ -422,7 +423,7 @@ class FakeAuthManager(object): def modify_project(self, project, manager_user=None, description=None): p = FakeAuthManager.projects.get(project) - p.project_manager_id = User.safe_id(manager_user) + p.project_manager_id = auth_manager.User.safe_id(manager_user) p.description = description def get_project(self, pid): diff --git a/nova/tests/scheduler/test_distributed_scheduler.py b/nova/tests/scheduler/test_distributed_scheduler.py index a8e2d9317..950280442 100644 --- a/nova/tests/scheduler/test_distributed_scheduler.py +++ b/nova/tests/scheduler/test_distributed_scheduler.py @@ -24,7 +24,8 @@ from nova.scheduler import least_cost from nova.scheduler import host_manager from nova.scheduler import distributed_scheduler from nova import test -from nova.tests.scheduler import fakes, test_scheduler +from nova.tests.scheduler import fakes +from nova.tests.scheduler import test_scheduler def fake_filter_hosts(hosts, filter_properties): diff --git a/nova/tests/test_misc.py b/nova/tests/test_misc.py index 0a673e68e..ab352b547 100644 --- a/nova/tests/test_misc.py +++ b/nova/tests/test_misc.py @@ -26,7 +26,6 @@ from eventlet import greenthread from nova import exception from nova import test from nova import utils -from nova.utils import parse_mailmap, str_dict_replace class ExceptionTestCase(test.TestCase): @@ -46,7 +45,7 @@ class ProjectTestCase(test.TestCase): topdir = os.path.normpath(os.path.dirname(__file__) + '/../../') missing = set() contributors = set() - mailmap = parse_mailmap(os.path.join(topdir, '.mailmap')) + mailmap = utils.parse_mailmap(os.path.join(topdir, '.mailmap')) authors_file = open(os.path.join(topdir, 'Authors'), 'r').read().lower() @@ -57,7 +56,7 @@ class ProjectTestCase(test.TestCase): if "jenkins" in email and "openstack.org" in email: continue email = '<' + email.lower() + '>' - contributors.add(str_dict_replace(email, mailmap)) + contributors.add(utils.str_dict_replace(email, mailmap)) else: return diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py index 5258efdc4..454d1fb7a 100644 --- a/nova/tests/test_utils.py +++ b/nova/tests/test_utils.py @@ -529,7 +529,8 @@ class MonkeyPatchTestCase(test.TestCase): def test_monkey_patch(self): utils.monkey_patch() nova.tests.monkey_patch_example.CALLED_FUNCTION = [] - from nova.tests.monkey_patch_example import example_a, example_b + from nova.tests.monkey_patch_example import example_a + from nova.tests.monkey_patch_example import example_b self.assertEqual('Example function', example_a.example_function_a()) exampleA = example_a.ExampleClassA() |