Fix hacking N302 import only modules

* Includes some general tools/hacking cleanup
* Fix several N302 cases
* Disable N302 until all cases are fixed

Change-Id: Iddba07ff13e10dc41a6930749044bb8c0572d279
This commit is contained in:
Joe Gordon 2013-01-17 18:06:53 -05:00
parent 4220e0110e
commit 4845fc2720
17 changed files with 154 additions and 141 deletions

@ -25,7 +25,7 @@ import os
import sys import sys
from nova import config from nova import config
from nova.console import websocketproxy as ws from nova import console
from nova.openstack.common import cfg from nova.openstack.common import cfg
@ -77,7 +77,8 @@ if __name__ == '__main__':
sys.exit(-1) sys.exit(-1)
# Create and start the NovaWebSockets proxy # Create and start the NovaWebSockets proxy
server = ws.NovaWebSocketProxy(listen_host=CONF.novncproxy_host, server = console.websocketproxy.NovaWebSocketProxy(
listen_host=CONF.novncproxy_host,
listen_port=CONF.novncproxy_port, listen_port=CONF.novncproxy_port,
source_is_ipv6=CONF.source_is_ipv6, source_is_ipv6=CONF.source_is_ipv6,
verbose=CONF.verbose, verbose=CONF.verbose,

@ -25,7 +25,7 @@ import os
import sys import sys
from nova import config from nova import config
from nova.console import websocketproxy as ws from nova import console
from nova.openstack.common import cfg from nova.openstack.common import cfg
@ -77,7 +77,8 @@ if __name__ == '__main__':
sys.exit(-1) sys.exit(-1)
# Create and start the NovaWebSockets proxy # Create and start the NovaWebSockets proxy
server = ws.NovaWebSocketProxy(listen_host=CONF.spicehtml5proxy_host, server = console.websocketproxy.NovaWebSocketProxy(
listen_host=CONF.spicehtml5proxy_host,
listen_port=CONF.spicehtml5proxy_port, listen_port=CONF.spicehtml5proxy_port,
source_is_ipv6=CONF.source_is_ipv6, source_is_ipv6=CONF.source_is_ipv6,
verbose=CONF.verbose, verbose=CONF.verbose,

@ -6,7 +6,7 @@ Created on 2010/12/20
import base64 import base64
import boto import boto
import boto.ec2 import boto.ec2
from boto.ec2.securitygroup import SecurityGroup import boto.ec2.securitygroup as securitygroup
from boto_v6.ec2.instance import ReservationV6 from boto_v6.ec2.instance import ReservationV6
@ -114,7 +114,7 @@ class EC2ConnectionV6(boto.ec2.EC2Connection):
if security_groups: if security_groups:
l = [] l = []
for group in security_groups: for group in security_groups:
if isinstance(group, SecurityGroup): if isinstance(group, securitygroup.SecurityGroup):
l.append(group.name) l.append(group.name)
else: else:
l.append(group) l.append(group)

@ -3,31 +3,29 @@ Created on 2010/12/20
@author: Nachi Ueno <ueno.nachi@lab.ntt.co.jp> @author: Nachi Ueno <ueno.nachi@lab.ntt.co.jp>
''' '''
from boto.ec2.instance import Group import boto.ec2.instance
from boto.ec2.instance import Instance
from boto.ec2.instance import Reservation
from boto.resultset import ResultSet from boto.resultset import ResultSet
class ReservationV6(Reservation): class ReservationV6(boto.ec2.instance.Reservation):
def startElement(self, name, attrs, connection): def startElement(self, name, attrs, connection):
if name == 'instancesSet': if name == 'instancesSet':
self.instances = ResultSet([('item', InstanceV6)]) self.instances = ResultSet([('item', InstanceV6)])
return self.instances return self.instances
elif name == 'groupSet': elif name == 'groupSet':
self.groups = ResultSet([('item', Group)]) self.groups = ResultSet([('item', boto.ec2.instance.Group)])
return self.groups return self.groups
else: else:
return None return None
class InstanceV6(Instance): class InstanceV6(boto.ec2.instance.Instance):
def __init__(self, connection=None): def __init__(self, connection=None):
Instance.__init__(self, connection) boto.ec2.instance.Instance.__init__(self, connection)
self.dns_name_v6 = None self.dns_name_v6 = None
def endElement(self, name, value, connection): def endElement(self, name, value, connection):
Instance.endElement(self, name, value, connection) boto.ec2.instance.Instance.endElement(self, name, value, connection)
if name == 'dnsNameV6': if name == 'dnsNameV6':
self.dns_name_v6 = value self.dns_name_v6 = value

@ -236,9 +236,7 @@ import sqlalchemy.orm
from sqlalchemy.pool import NullPool, StaticPool from sqlalchemy.pool import NullPool, StaticPool
from sqlalchemy.sql.expression import literal_column from sqlalchemy.sql.expression import literal_column
from nova.exception import DBDuplicateEntry import nova.exception
from nova.exception import DBError
from nova.exception import InvalidUnicodeParameter
from nova.openstack.common import cfg from nova.openstack.common import cfg
import nova.openstack.common.log as logging import nova.openstack.common.log as logging
from nova.openstack.common import timeutils from nova.openstack.common import timeutils
@ -362,7 +360,7 @@ def raise_if_duplicate_entry_error(integrity_error, engine_name):
columns = columns.strip().split(", ") columns = columns.strip().split(", ")
else: else:
columns = get_columns_from_uniq_cons_or_name(columns) columns = get_columns_from_uniq_cons_or_name(columns)
raise DBDuplicateEntry(columns, integrity_error) raise nova.exception.DBDuplicateEntry(columns, integrity_error)
def wrap_db_error(f): def wrap_db_error(f):
@ -370,7 +368,7 @@ def wrap_db_error(f):
try: try:
return f(*args, **kwargs) return f(*args, **kwargs)
except UnicodeEncodeError: except UnicodeEncodeError:
raise InvalidUnicodeParameter() raise nova.exception.InvalidUnicodeParameter()
# note(boris-42): We should catch unique constraint violation and # note(boris-42): We should catch unique constraint violation and
# wrap it by our own DBDuplicateEntry exception. Unique constraint # wrap it by our own DBDuplicateEntry exception. Unique constraint
# violation is wrapped by IntegrityError. # violation is wrapped by IntegrityError.
@ -381,10 +379,10 @@ def wrap_db_error(f):
# means we should get names of columns, which values violate # means we should get names of columns, which values violate
# unique constraint, from error message. # unique constraint, from error message.
raise_if_duplicate_entry_error(e, get_engine().name) raise_if_duplicate_entry_error(e, get_engine().name)
raise DBError(e) raise nova.exception.DBError(e)
except Exception, e: except Exception, e:
LOG.exception(_('DB exception wrapped.')) LOG.exception(_('DB exception wrapped.'))
raise DBError(e) raise nova.exception.DBError(e)
_wrap.func_name = f.func_name _wrap.func_name = f.func_name
return _wrap return _wrap

@ -23,7 +23,7 @@ from nova.openstack.common import lockutils
from nova.openstack.common import log as logging from nova.openstack.common import log as logging
from nova import utils from nova import utils
from random import choice import random
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -144,4 +144,4 @@ class ServiceGroupDriver(object):
length = len(members) length = len(members)
if length == 0: if length == 0:
return None return None
return choice(members) return random.choice(members)

@ -13,7 +13,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 datetime import datetime import datetime
from lxml import etree from lxml import etree
import webob import webob
@ -40,29 +40,29 @@ def fake_service_get_all(context, disabled=None):
if disabled: if disabled:
return [__fake_service("nova-compute", "zone-2", return [__fake_service("nova-compute", "zone-2",
datetime(2012, 11, 14, 9, 53, 25, 0), datetime.datetime(2012, 11, 14, 9, 53, 25, 0),
datetime(2012, 12, 26, 14, 45, 25, 0), datetime.datetime(2012, 12, 26, 14, 45, 25, 0),
"fake_host-1", True), "fake_host-1", True),
__fake_service("nova-scheduler", "internal", __fake_service("nova-scheduler", "internal",
datetime(2012, 11, 14, 9, 57, 3, 0), datetime.datetime(2012, 11, 14, 9, 57, 3, 0),
datetime(2012, 12, 26, 14, 45, 25, 0), datetime.datetime(2012, 12, 26, 14, 45, 25, 0),
"fake_host-1", True), "fake_host-1", True),
__fake_service("nova-network", "internal", __fake_service("nova-network", "internal",
datetime(2012, 11, 16, 7, 25, 46, 0), datetime.datetime(2012, 11, 16, 7, 25, 46, 0),
datetime(2012, 12, 26, 14, 45, 24, 0), datetime.datetime(2012, 12, 26, 14, 45, 24, 0),
"fake_host-2", True)] "fake_host-2", True)]
else: else:
return [__fake_service("nova-compute", "zone-1", return [__fake_service("nova-compute", "zone-1",
datetime(2012, 11, 14, 9, 53, 25, 0), datetime.datetime(2012, 11, 14, 9, 53, 25, 0),
datetime(2012, 12, 26, 14, 45, 25, 0), datetime.datetime(2012, 12, 26, 14, 45, 25, 0),
"fake_host-1", False), "fake_host-1", False),
__fake_service("nova-sched", "internal", __fake_service("nova-sched", "internal",
datetime(2012, 11, 14, 9, 57, 03, 0), datetime.datetime(2012, 11, 14, 9, 57, 03, 0),
datetime(2012, 12, 26, 14, 45, 25, 0), datetime.datetime(2012, 12, 26, 14, 45, 25, 0),
"fake_host-1", False), "fake_host-1", False),
__fake_service("nova-network", "internal", __fake_service("nova-network", "internal",
datetime(2012, 11, 16, 7, 25, 46, 0), datetime.datetime(2012, 11, 16, 7, 25, 46, 0),
datetime(2012, 12, 26, 14, 45, 24, 0), datetime.datetime(2012, 12, 26, 14, 45, 24, 0),
"fake_host-2", False)] "fake_host-2", False)]
@ -218,18 +218,21 @@ class AvailabilityZoneSerializerTest(test.TestCase):
'hosts': {'fake_host-1': { 'hosts': {'fake_host-1': {
'nova-compute': {'active': True, 'available': True, 'nova-compute': {'active': True, 'available': True,
'updated_at': 'updated_at':
datetime(2012, 12, 26, 14, 45, 25)}}}}, datetime.datetime(
2012, 12, 26, 14, 45, 25)}}}},
{'zoneName': 'internal', {'zoneName': 'internal',
'zoneState': {'available': True}, 'zoneState': {'available': True},
'hosts': {'fake_host-1': { 'hosts': {'fake_host-1': {
'nova-sched': {'active': True, 'available': True, 'nova-sched': {'active': True, 'available': True,
'updated_at': 'updated_at':
datetime(2012, 12, 26, 14, 45, 25)}}, datetime.datetime(
2012, 12, 26, 14, 45, 25)}},
'fake_host-2': { 'fake_host-2': {
'nova-network': {'active': True, 'nova-network': {'active': True,
'available': False, 'available': False,
'updated_at': 'updated_at':
datetime(2012, 12, 26, 14, 45, 24)}}}}, datetime.datetime(
2012, 12, 26, 14, 45, 24)}}}},
{'zoneName': 'zone-2', {'zoneName': 'zone-2',
'zoneState': {'available': False}, 'zoneState': {'available': False},
'hosts': None}] 'hosts': None}]

@ -14,7 +14,8 @@
# under the License. # under the License.
from datetime import datetime import datetime
from nova.api.openstack.compute.contrib import services from nova.api.openstack.compute.contrib import services
from nova import context from nova import context
from nova import db from nova import db
@ -24,35 +25,36 @@ from nova import test
from nova.tests.api.openstack import fakes from nova.tests.api.openstack import fakes
fake_services_list = [{'binary': 'nova-scheduler', fake_services_list = [
'host': 'host1', {'binary': 'nova-scheduler',
'id': 1, 'host': 'host1',
'disabled': True, 'id': 1,
'topic': 'scheduler', 'disabled': True,
'updated_at': datetime(2012, 10, 29, 13, 42, 2), 'topic': 'scheduler',
'created_at': datetime(2012, 9, 18, 2, 46, 27)}, 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 2),
{'binary': 'nova-compute', 'created_at': datetime.datetime(2012, 9, 18, 2, 46, 27)},
'host': 'host1', {'binary': 'nova-compute',
'id': 2, 'host': 'host1',
'disabled': True, 'id': 2,
'topic': 'compute', 'disabled': True,
'updated_at': datetime(2012, 10, 29, 13, 42, 5), 'topic': 'compute',
'created_at': datetime(2012, 9, 18, 2, 46, 27)}, 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 5),
{'binary': 'nova-scheduler', 'created_at': datetime.datetime(2012, 9, 18, 2, 46, 27)},
'host': 'host2', {'binary': 'nova-scheduler',
'id': 3, 'host': 'host2',
'disabled': False, 'id': 3,
'topic': 'scheduler', 'disabled': False,
'updated_at': datetime(2012, 9, 19, 6, 55, 34), 'topic': 'scheduler',
'created_at': datetime(2012, 9, 18, 2, 46, 28)}, 'updated_at': datetime.datetime(2012, 9, 19, 6, 55, 34),
{'binary': 'nova-compute', 'created_at': datetime.datetime(2012, 9, 18, 2, 46, 28)},
'host': 'host2', {'binary': 'nova-compute',
'id': 4, 'host': 'host2',
'disabled': True, 'id': 4,
'topic': 'compute', 'disabled': True,
'updated_at': datetime(2012, 9, 18, 8, 3, 38), 'topic': 'compute',
'created_at': datetime(2012, 9, 18, 2, 46, 28)}, 'updated_at': datetime.datetime(2012, 9, 18, 8, 3, 38),
] 'created_at': datetime.datetime(2012, 9, 18, 2, 46, 28)},
]
class FakeRequest(object): class FakeRequest(object):
@ -103,7 +105,7 @@ def fake_service_update(context, service_id, values):
def fake_utcnow(): def fake_utcnow():
return datetime(2012, 10, 29, 13, 42, 11) return datetime.datetime(2012, 10, 29, 13, 42, 11)
class ServicesTest(test.TestCase): class ServicesTest(test.TestCase):
@ -130,19 +132,19 @@ class ServicesTest(test.TestCase):
response = {'services': [{'binary': 'nova-scheduler', response = {'services': [{'binary': 'nova-scheduler',
'host': 'host1', 'zone': 'internal', 'host': 'host1', 'zone': 'internal',
'status': 'disabled', 'state': 'up', 'status': 'disabled', 'state': 'up',
'updated_at': datetime(2012, 10, 29, 13, 42, 2)}, 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 2)},
{'binary': 'nova-compute', {'binary': 'nova-compute',
'host': 'host1', 'zone': 'nova', 'host': 'host1', 'zone': 'nova',
'status': 'disabled', 'state': 'up', 'status': 'disabled', 'state': 'up',
'updated_at': datetime(2012, 10, 29, 13, 42, 5)}, 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 5)},
{'binary': 'nova-scheduler', 'host': 'host2', {'binary': 'nova-scheduler', 'host': 'host2',
'zone': 'internal', 'zone': 'internal',
'status': 'enabled', 'state': 'down', 'status': 'enabled', 'state': 'down',
'updated_at': datetime(2012, 9, 19, 6, 55, 34)}, 'updated_at': datetime.datetime(2012, 9, 19, 6, 55, 34)},
{'binary': 'nova-compute', 'host': 'host2', {'binary': 'nova-compute', 'host': 'host2',
'zone': 'nova', 'zone': 'nova',
'status': 'disabled', 'state': 'down', 'status': 'disabled', 'state': 'down',
'updated_at': datetime(2012, 9, 18, 8, 3, 38)}]} 'updated_at': datetime.datetime(2012, 9, 18, 8, 3, 38)}]}
self.assertEqual(res_dict, response) self.assertEqual(res_dict, response)
def test_services_list_with_host(self): def test_services_list_with_host(self):
@ -152,11 +154,11 @@ class ServicesTest(test.TestCase):
response = {'services': [{'binary': 'nova-scheduler', 'host': 'host1', response = {'services': [{'binary': 'nova-scheduler', 'host': 'host1',
'zone': 'internal', 'zone': 'internal',
'status': 'disabled', 'state': 'up', 'status': 'disabled', 'state': 'up',
'updated_at': datetime(2012, 10, 29, 13, 42, 2)}, 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 2)},
{'binary': 'nova-compute', 'host': 'host1', {'binary': 'nova-compute', 'host': 'host1',
'zone': 'nova', 'zone': 'nova',
'status': 'disabled', 'state': 'up', 'status': 'disabled', 'state': 'up',
'updated_at': datetime(2012, 10, 29, 13, 42, 5)}]} 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 5)}]}
self.assertEqual(res_dict, response) self.assertEqual(res_dict, response)
def test_services_list_with_service(self): def test_services_list_with_service(self):
@ -166,11 +168,11 @@ class ServicesTest(test.TestCase):
response = {'services': [{'binary': 'nova-compute', 'host': 'host1', response = {'services': [{'binary': 'nova-compute', 'host': 'host1',
'zone': 'nova', 'zone': 'nova',
'status': 'disabled', 'state': 'up', 'status': 'disabled', 'state': 'up',
'updated_at': datetime(2012, 10, 29, 13, 42, 5)}, 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 5)},
{'binary': 'nova-compute', 'host': 'host2', {'binary': 'nova-compute', 'host': 'host2',
'zone': 'nova', 'zone': 'nova',
'status': 'disabled', 'state': 'down', 'status': 'disabled', 'state': 'down',
'updated_at': datetime(2012, 9, 18, 8, 3, 38)}]} 'updated_at': datetime.datetime(2012, 9, 18, 8, 3, 38)}]}
self.assertEqual(res_dict, response) self.assertEqual(res_dict, response)
def test_services_list_with_host_service(self): def test_services_list_with_host_service(self):
@ -180,7 +182,7 @@ class ServicesTest(test.TestCase):
response = {'services': [{'binary': 'nova-compute', 'host': 'host1', response = {'services': [{'binary': 'nova-compute', 'host': 'host1',
'zone': 'nova', 'zone': 'nova',
'status': 'disabled', 'state': 'up', 'status': 'disabled', 'state': 'up',
'updated_at': datetime(2012, 10, 29, 13, 42, 5)}]} 'updated_at': datetime.datetime(2012, 10, 29, 13, 42, 5)}]}
self.assertEqual(res_dict, response) self.assertEqual(res_dict, response)
def test_services_enable(self): def test_services_enable(self):

@ -22,7 +22,7 @@ from nova import config
from nova import ipv6 from nova import ipv6
from nova.openstack.common import cfg from nova.openstack.common import cfg
from nova import paths from nova import paths
from nova.tests.utils import cleanup_dns_managers from nova.tests import utils
CONF = cfg.CONF CONF = cfg.CONF
CONF.import_opt('use_ipv6', 'nova.netconf') CONF.import_opt('use_ipv6', 'nova.netconf')
@ -70,5 +70,5 @@ class ConfFixture(fixtures.Fixture):
self.conf.set_default('vlan_interface', 'eth0') self.conf.set_default('vlan_interface', 'eth0')
config.parse_args([], default_config_files=[]) config.parse_args([], default_config_files=[])
self.addCleanup(self.conf.reset) self.addCleanup(self.conf.reset)
self.addCleanup(cleanup_dns_managers) self.addCleanup(utils.cleanup_dns_managers)
self.addCleanup(ipv6.api.reset_backend) self.addCleanup(ipv6.api.reset_backend)

@ -26,9 +26,9 @@ from boto.ec2 import regioninfo
from boto import exception as boto_exc from boto import exception as boto_exc
# newer versions of boto use their own wrapper on top of httplib.HTTPResponse # newer versions of boto use their own wrapper on top of httplib.HTTPResponse
try: try:
from boto.connection import HTTPResponse import boto.connection as httplib
except ImportError: except ImportError:
from httplib import HTTPResponse import httplib
import fixtures import fixtures
import webob import webob
@ -79,7 +79,7 @@ class FakeHttplibConnection(object):
# guess that's a function the web server usually provides. # guess that's a function the web server usually provides.
resp = "HTTP/1.0 %s" % resp resp = "HTTP/1.0 %s" % resp
self.sock = FakeHttplibSocket(resp) self.sock = FakeHttplibSocket(resp)
self.http_response = HTTPResponse(self.sock) self.http_response = httplib.HTTPResponse(self.sock)
# NOTE(vish): boto is accessing private variables for some reason # NOTE(vish): boto is accessing private variables for some reason
self._HTTPConnection__response = self.http_response self._HTTPConnection__response = self.http_response
self.http_response.begin() self.http_response.begin()

@ -19,7 +19,7 @@
"""Tests for metadata service.""" """Tests for metadata service."""
import base64 import base64
from copy import copy import copy
import json import json
import re import re
@ -120,14 +120,14 @@ class MetadataTestCase(test.TestCase):
spectacular=True) spectacular=True)
def test_user_data(self): def test_user_data(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
inst['user_data'] = base64.b64encode("happy") inst['user_data'] = base64.b64encode("happy")
md = fake_InstanceMetadata(self.stubs, inst) md = fake_InstanceMetadata(self.stubs, inst)
self.assertEqual( self.assertEqual(
md.get_ec2_metadata(version='2009-04-04')['user-data'], "happy") md.get_ec2_metadata(version='2009-04-04')['user-data'], "happy")
def test_no_user_data(self): def test_no_user_data(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
del inst['user_data'] del inst['user_data']
md = fake_InstanceMetadata(self.stubs, inst) md = fake_InstanceMetadata(self.stubs, inst)
obj = object() obj = object()
@ -136,7 +136,7 @@ class MetadataTestCase(test.TestCase):
obj) obj)
def test_security_groups(self): def test_security_groups(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
sgroups = [{'name': 'default'}, {'name': 'other'}] sgroups = [{'name': 'default'}, {'name': 'other'}]
expected = ['default', 'other'] expected = ['default', 'other']
@ -145,7 +145,7 @@ class MetadataTestCase(test.TestCase):
self.assertEqual(data['meta-data']['security-groups'], expected) self.assertEqual(data['meta-data']['security-groups'], expected)
def test_local_hostname_fqdn(self): def test_local_hostname_fqdn(self):
md = fake_InstanceMetadata(self.stubs, copy(self.instance)) md = fake_InstanceMetadata(self.stubs, copy.copy(self.instance))
data = md.get_ec2_metadata(version='2009-04-04') data = md.get_ec2_metadata(version='2009-04-04')
self.assertEqual(data['meta-data']['local-hostname'], self.assertEqual(data['meta-data']['local-hostname'],
"%s.%s" % (self.instance['hostname'], CONF.dhcp_domain)) "%s.%s" % (self.instance['hostname'], CONF.dhcp_domain))
@ -195,7 +195,7 @@ class MetadataTestCase(test.TestCase):
expected) expected)
def test_pubkey(self): def test_pubkey(self):
md = fake_InstanceMetadata(self.stubs, copy(self.instance)) md = fake_InstanceMetadata(self.stubs, copy.copy(self.instance))
pubkey_ent = md.lookup("/2009-04-04/meta-data/public-keys") pubkey_ent = md.lookup("/2009-04-04/meta-data/public-keys")
self.assertEqual(base.ec2_md_print(pubkey_ent), self.assertEqual(base.ec2_md_print(pubkey_ent),
@ -204,7 +204,7 @@ class MetadataTestCase(test.TestCase):
self.instance['key_data']) self.instance['key_data'])
def test_image_type_ramdisk(self): def test_image_type_ramdisk(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
inst['ramdisk_id'] = 'ari-853667c0' inst['ramdisk_id'] = 'ari-853667c0'
md = fake_InstanceMetadata(self.stubs, inst) md = fake_InstanceMetadata(self.stubs, inst)
data = md.lookup("/latest/meta-data/ramdisk-id") data = md.lookup("/latest/meta-data/ramdisk-id")
@ -213,7 +213,7 @@ class MetadataTestCase(test.TestCase):
self.assertTrue(re.match('ari-[0-9a-f]{8}', data)) self.assertTrue(re.match('ari-[0-9a-f]{8}', data))
def test_image_type_kernel(self): def test_image_type_kernel(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
inst['kernel_id'] = 'aki-c2e26ff2' inst['kernel_id'] = 'aki-c2e26ff2'
md = fake_InstanceMetadata(self.stubs, inst) md = fake_InstanceMetadata(self.stubs, inst)
data = md.lookup("/2009-04-04/meta-data/kernel-id") data = md.lookup("/2009-04-04/meta-data/kernel-id")
@ -229,7 +229,7 @@ class MetadataTestCase(test.TestCase):
md.lookup, "/2009-04-04/meta-data/kernel-id") md.lookup, "/2009-04-04/meta-data/kernel-id")
def test_check_version(self): def test_check_version(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
md = fake_InstanceMetadata(self.stubs, inst) md = fake_InstanceMetadata(self.stubs, inst)
self.assertTrue(md._check_version('1.0', '2009-04-04')) self.assertTrue(md._check_version('1.0', '2009-04-04'))
@ -250,7 +250,7 @@ class OpenStackMetadataTestCase(test.TestCase):
def test_top_level_listing(self): def test_top_level_listing(self):
# request for /openstack/<version>/ should show metadata.json # request for /openstack/<version>/ should show metadata.json
inst = copy(self.instance) inst = copy.copy(self.instance)
mdinst = fake_InstanceMetadata(self.stubs, inst) mdinst = fake_InstanceMetadata(self.stubs, inst)
listing = mdinst.lookup("/openstack/") listing = mdinst.lookup("/openstack/")
@ -267,14 +267,14 @@ class OpenStackMetadataTestCase(test.TestCase):
def test_version_content_listing(self): def test_version_content_listing(self):
# request for /openstack/<version>/ should show metadata.json # request for /openstack/<version>/ should show metadata.json
inst = copy(self.instance) inst = copy.copy(self.instance)
mdinst = fake_InstanceMetadata(self.stubs, inst) mdinst = fake_InstanceMetadata(self.stubs, inst)
listing = mdinst.lookup("/openstack/2012-08-10") listing = mdinst.lookup("/openstack/2012-08-10")
self.assertTrue("meta_data.json" in listing) self.assertTrue("meta_data.json" in listing)
def test_metadata_json(self): def test_metadata_json(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
content = [ content = [
('/etc/my.conf', "content of my.conf"), ('/etc/my.conf', "content of my.conf"),
('/root/hello', "content of /root/hello"), ('/root/hello', "content of /root/hello"),
@ -309,7 +309,7 @@ class OpenStackMetadataTestCase(test.TestCase):
def test_extra_md(self): def test_extra_md(self):
# make sure extra_md makes it through to metadata # make sure extra_md makes it through to metadata
inst = copy(self.instance) inst = copy.copy(self.instance)
extra = {'foo': 'bar', 'mylist': [1, 2, 3], extra = {'foo': 'bar', 'mylist': [1, 2, 3],
'mydict': {"one": 1, "two": 2}} 'mydict': {"one": 1, "two": 2}}
mdinst = fake_InstanceMetadata(self.stubs, inst, extra_md=extra) mdinst = fake_InstanceMetadata(self.stubs, inst, extra_md=extra)
@ -322,14 +322,14 @@ class OpenStackMetadataTestCase(test.TestCase):
def test_password(self): def test_password(self):
# make sure extra_md makes it through to metadata # make sure extra_md makes it through to metadata
inst = copy(self.instance) inst = copy.copy(self.instance)
mdinst = fake_InstanceMetadata(self.stubs, inst) mdinst = fake_InstanceMetadata(self.stubs, inst)
result = mdinst.lookup("/openstack/latest/password") result = mdinst.lookup("/openstack/latest/password")
self.assertEqual(result, password.handle_password) self.assertEqual(result, password.handle_password)
def test_userdata(self): def test_userdata(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
mdinst = fake_InstanceMetadata(self.stubs, inst) mdinst = fake_InstanceMetadata(self.stubs, inst)
userdata_found = mdinst.lookup("/openstack/2012-08-10/user_data") userdata_found = mdinst.lookup("/openstack/2012-08-10/user_data")
@ -348,7 +348,7 @@ class OpenStackMetadataTestCase(test.TestCase):
mdinst.lookup, "/openstack/2012-08-10/user_data") mdinst.lookup, "/openstack/2012-08-10/user_data")
def test_random_seed(self): def test_random_seed(self):
inst = copy(self.instance) inst = copy.copy(self.instance)
mdinst = fake_InstanceMetadata(self.stubs, inst) mdinst = fake_InstanceMetadata(self.stubs, inst)
# verify that 2013-04-04 has the 'random' field # verify that 2013-04-04 has the 'random' field
@ -364,7 +364,7 @@ class OpenStackMetadataTestCase(test.TestCase):
def test_no_dashes_in_metadata(self): def test_no_dashes_in_metadata(self):
# top level entries in meta_data should not contain '-' in their name # top level entries in meta_data should not contain '-' in their name
inst = copy(self.instance) inst = copy.copy(self.instance)
mdinst = fake_InstanceMetadata(self.stubs, inst) mdinst = fake_InstanceMetadata(self.stubs, inst)
mdjson = json.loads(mdinst.lookup("/openstack/latest/meta_data.json")) mdjson = json.loads(mdinst.lookup("/openstack/latest/meta_data.json"))
@ -522,7 +522,7 @@ class MetadataPasswordTestCase(test.TestCase):
super(MetadataPasswordTestCase, self).setUp() super(MetadataPasswordTestCase, self).setUp()
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs, fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
spectacular=True) spectacular=True)
self.instance = copy(INSTANCES[0]) self.instance = copy.copy(INSTANCES[0])
self.mdinst = fake_InstanceMetadata(self.stubs, self.instance, self.mdinst = fake_InstanceMetadata(self.stubs, self.instance,
address=None, sgroups=None) address=None, sgroups=None)

@ -15,6 +15,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import abc
import sys import sys
import uuid import uuid
@ -22,11 +23,12 @@ import uuid
if sys.platform == 'win32': if sys.platform == 'win32':
import wmi import wmi
from abc import abstractmethod
from nova.openstack.common import cfg from nova.openstack.common import cfg
from nova.openstack.common import log as logging from nova.openstack.common import log as logging
from nova.virt.hyperv import vmutils from nova.virt.hyperv import vmutils
hyperv_opts = [ hyperv_opts = [
cfg.StrOpt('vswitch_name', cfg.StrOpt('vswitch_name',
default=None, default=None,
@ -42,11 +44,11 @@ LOG = logging.getLogger(__name__)
class HyperVBaseVIFDriver(object): class HyperVBaseVIFDriver(object):
@abstractmethod @abc.abstractmethod
def plug(self, instance, vif): def plug(self, instance, vif):
pass pass
@abstractmethod @abc.abstractmethod
def unplug(self, instance, vif): def unplug(self, instance, vif):
pass pass

@ -20,7 +20,7 @@
Handles all requests relating to volumes + cinder. Handles all requests relating to volumes + cinder.
""" """
from copy import deepcopy import copy
import sys import sys
from cinderclient import exceptions as cinder_exception from cinderclient import exceptions as cinder_exception
@ -139,7 +139,7 @@ def _untranslate_volume_summary_view(context, vol):
d['volume_metadata'].append(item) d['volume_metadata'].append(item)
if hasattr(vol, 'volume_image_metadata'): if hasattr(vol, 'volume_image_metadata'):
d['volume_image_metadata'] = deepcopy(vol.volume_image_metadata) d['volume_image_metadata'] = copy.deepcopy(vol.volume_image_metadata)
return d return d

@ -125,7 +125,7 @@ function run_pep8 {
srcfiles+=" setup.py" srcfiles+=" setup.py"
# Until all these issues get fixed, ignore. # Until all these issues get fixed, ignore.
ignore='--ignore=E12,E711,E721,E712,N403,N404' ignore='--ignore=E12,E711,E721,E712,N403,N404,N302'
# First run the hacking selftest, to make sure it's right # First run the hacking selftest, to make sure it's right
echo "Running hacking.py self test" echo "Running hacking.py self test"

@ -17,7 +17,7 @@
# under the License. # under the License.
import boto import boto
from boto.ec2.regioninfo import RegionInfo from boto.ec2 import regioninfo
import commands import commands
import httplib import httplib
import os import os
@ -123,7 +123,7 @@ class SmokeTestCase(unittest.TestCase):
return boto_v6.connect_ec2(aws_access_key_id=access_key, return boto_v6.connect_ec2(aws_access_key_id=access_key,
aws_secret_access_key=secret_key, aws_secret_access_key=secret_key,
is_secure=parts['is_secure'], is_secure=parts['is_secure'],
region=RegionInfo(None, region=regioninfo.RegionInfo(None,
'nova', 'nova',
parts['ip']), parts['ip']),
port=parts['port'], port=parts['port'],
@ -133,7 +133,7 @@ class SmokeTestCase(unittest.TestCase):
return boto.connect_ec2(aws_access_key_id=access_key, return boto.connect_ec2(aws_access_key_id=access_key,
aws_secret_access_key=secret_key, aws_secret_access_key=secret_key,
is_secure=parts['is_secure'], is_secure=parts['is_secure'],
region=RegionInfo(None, region=regioninfo.RegionInfo(None,
'nova', 'nova',
parts['ip']), parts['ip']),
port=parts['port'], port=parts['port'],

@ -18,7 +18,7 @@
"""nova HACKING file compliance testing """nova HACKING file compliance testing
built on top of pep8.py Built on top of pep8.py
""" """
import inspect import inspect
@ -49,6 +49,8 @@ START_DOCSTRING_TRIPLE = ['u"""', 'r"""', '"""', "u'''", "r'''", "'''"]
END_DOCSTRING_TRIPLE = ['"""', "'''"] END_DOCSTRING_TRIPLE = ['"""', "'''"]
VERBOSE_MISSING_IMPORT = os.getenv('HACKING_VERBOSE_MISSING_IMPORT', 'False') VERBOSE_MISSING_IMPORT = os.getenv('HACKING_VERBOSE_MISSING_IMPORT', 'False')
_missingImport = set([])
# Monkey patch broken excluded filter in pep8 # Monkey patch broken excluded filter in pep8
# See https://github.com/jcrocholl/pep8/pull/111 # See https://github.com/jcrocholl/pep8/pull/111
@ -103,7 +105,7 @@ def import_normalize(line):
return line return line
def nova_todo_format(physical_line): def nova_todo_format(physical_line, tokens):
"""Check for 'TODO()'. """Check for 'TODO()'.
nova HACKING guide recommendation for TODO: nova HACKING guide recommendation for TODO:
@ -111,14 +113,13 @@ def nova_todo_format(physical_line):
Okay: #TODO(sdague) Okay: #TODO(sdague)
N101: #TODO fail N101: #TODO fail
N101: #TODO (jogo) fail
""" """
# TODO(sdague): TODO check shouldn't fail inside of space # TODO(sdague): TODO check shouldn't fail inside of space
pos = physical_line.find('TODO') pos = physical_line.find('TODO')
pos1 = physical_line.find('TODO(') pos1 = physical_line.find('TODO(')
pos2 = physical_line.find('#') # make sure it's a comment pos2 = physical_line.find('#') # make sure it's a comment
# TODO(sdague): should be smarter on this test if (pos != pos1 and pos2 >= 0 and pos2 < pos and len(tokens) == 0):
this_test = physical_line.find('N101: #TODO fail')
if pos != pos1 and pos2 >= 0 and pos2 < pos and this_test == -1:
return pos, "N101: Use TODO(NAME)" return pos, "N101: Use TODO(NAME)"
@ -165,8 +166,6 @@ def nova_one_import_per_line(logical_line):
not is_import_exception(parts[1])): not is_import_exception(parts[1])):
yield pos, "N301: one import per line" yield pos, "N301: one import per line"
_missingImport = set([])
def nova_import_module_only(logical_line): def nova_import_module_only(logical_line):
r"""Check for import module only. r"""Check for import module only.
@ -175,20 +174,23 @@ def nova_import_module_only(logical_line):
Do not import objects, only modules Do not import objects, only modules
Okay: from os import path Okay: from os import path
N302 from os.path import mkdir as mkdir2 Okay: import os.path
N303 import bubba N302: from os.path import dirname as dirname2
N304 import blueblue N303 from os.path import *
N304 import flakes
""" """
# N302 import only modules # N302 import only modules
# N303 Invalid Import # N303 Invalid Import
# N304 Relative Import # N304 Relative Import
# TODO(sdague) actually get these tests working # TODO(sdague) actually get these tests working
def importModuleCheck(mod, parent=None, added=False): # TODO(jogo) simplify this code
"""Import Module helper function. def import_module_check(mod, parent=None, added=False):
"""Checks for relative, modules and invalid imports.
If can't find module on first try, recursively check for relative If can't find module on first try, recursively check for relative
imports imports.
When parsing 'from x import y,' x is the parent.
""" """
current_path = os.path.dirname(pep8.current_file) current_path = os.path.dirname(pep8.current_file)
try: try:
@ -196,8 +198,6 @@ def nova_import_module_only(logical_line):
warnings.simplefilter('ignore', DeprecationWarning) warnings.simplefilter('ignore', DeprecationWarning)
valid = True valid = True
if parent: if parent:
if is_import_exception(parent):
return
parent_mod = __import__(parent, globals(), locals(), parent_mod = __import__(parent, globals(), locals(),
[mod], -1) [mod], -1)
valid = inspect.ismodule(getattr(parent_mod, mod)) valid = inspect.ismodule(getattr(parent_mod, mod))
@ -209,7 +209,7 @@ def nova_import_module_only(logical_line):
sys.path.pop() sys.path.pop()
added = False added = False
return logical_line.find(mod), ("N304: No " return logical_line.find(mod), ("N304: No "
"relative imports. '%s' is a relative import" "relative imports. '%s' is a relative import"
% logical_line) % logical_line)
return logical_line.find(mod), ("N302: import only " return logical_line.find(mod), ("N302: import only "
"modules. '%s' does not import a module" "modules. '%s' does not import a module"
@ -219,7 +219,7 @@ def nova_import_module_only(logical_line):
if not added: if not added:
added = True added = True
sys.path.append(current_path) sys.path.append(current_path)
return importModuleCheck(mod, parent, added) return import_module_check(mod, parent, added)
else: else:
name = logical_line.split()[1] name = logical_line.split()[1]
if name not in _missingImport: if name not in _missingImport:
@ -234,23 +234,27 @@ def nova_import_module_only(logical_line):
except AttributeError: except AttributeError:
# Invalid import # Invalid import
if "import *" in logical_line:
# TODO(jogo): handle "from x import *, by checking all
# "objects in x"
return
return logical_line.find(mod), ("N303: Invalid import, " return logical_line.find(mod), ("N303: Invalid import, "
"AttributeError raised") "%s" % mod)
# convert "from x import y" to " import x.y"
# convert "from x import y as z" to " import x.y"
import_normalize(logical_line)
split_line = logical_line.split() split_line = logical_line.split()
if (", " not in logical_line and
if (logical_line.startswith("import ") and "," not in logical_line and split_line[0] in ('import', 'from') and
(len(split_line) == 2 or (len(split_line) in (2, 4, 6)) and
(len(split_line) == 4 and split_line[2] == "as"))): split_line[1] != "__future__"):
mod = split_line[1] if is_import_exception(split_line[1]):
rval = importModuleCheck(mod) return
if "from" == split_line[0]:
rval = import_module_check(split_line[3], parent=split_line[1])
else:
rval = import_module_check(split_line[1])
if rval is not None: if rval is not None:
yield rval yield rval
# TODO(jogo) handle "from x import *"
#TODO(jogo): import template: N305 #TODO(jogo): import template: N305
@ -329,6 +333,8 @@ def nova_docstring_one_line(physical_line):
A one line docstring looks like this and ends in punctuation. A one line docstring looks like this and ends in punctuation.
Okay: '''This is good.''' Okay: '''This is good.'''
Okay: '''This is good too!'''
Okay: '''How about this?'''
N402: '''This is not''' N402: '''This is not'''
N402: '''Bad punctuation,''' N402: '''Bad punctuation,'''
""" """

@ -18,9 +18,11 @@ downloadcache = ~/cache/pip
deps=pep8==1.3.3 deps=pep8==1.3.3
commands = commands =
python tools/hacking.py --doctest python tools/hacking.py --doctest
python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404 --show-source \ python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404,N302 \
--show-source \
--exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg . --exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg .
python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404 --show-source \ python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404,N302 \
--show-source \
--filename=nova* bin --filename=nova* bin
[testenv:pylint] [testenv:pylint]