Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge "Minor cleanup based on HACKING"

  • Loading branch information...
commit 07ca6f64de76b5955c233b830122877dc07df142 2 parents 34d50ed + f1bf466
Jenkins authored openstack-gerrit committed
View
22 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
from nova.api.openstack import extensions
@@ -71,12 +71,12 @@ def _hours_for(self, instance, period_start, period_stop):
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")
@@ -151,7 +151,7 @@ def _tenant_usages_for_period(self, context, period_start,
else:
info['state'] = instance['vm_state']
- now = datetime.utcnow()
+ now = datetime.datetime.utcnow()
if info['state'] == 'terminated':
delta = info['ended_at'] - info['started_at']
@@ -186,23 +186,25 @@ def _tenant_usages_for_period(self, context, period_start,
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)
View
4 nova/image/glance.py
@@ -24,7 +24,7 @@
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]
View
9 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 @@ def create_subnet(self, context, label, project_id,
"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 @@ def _get_ips_by_interface(self, context, net_id, vif_id, project_id,
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
View
4 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
View
11 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 @@ def setUp(self):
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 @@ def setUp(self):
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()
View
17 nova/tests/api/openstack/fakes.py
@@ -32,7 +32,7 @@
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 @@ def clear_fakes(cls):
@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 @@ def delete_user(self, uid):
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 @@ def is_admin(self, user_id):
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 @@ def is_project_member(self, user_id, project):
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 @@ def delete_project(self, pid):
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):
View
3  nova/tests/scheduler/test_distributed_scheduler.py
@@ -24,7 +24,8 @@
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):
View
5 nova/tests/test_misc.py
@@ -26,7 +26,6 @@
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 @@ def test_authors_up_to_date(self):
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 @@ def test_authors_up_to_date(self):
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
View
3  nova/tests/test_utils.py
@@ -529,7 +529,8 @@ def setUp(self):
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()
Please sign in to comment.
Something went wrong with that request. Please try again.