diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index d40f25c4d947..a764a99bfc51 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -201,7 +201,7 @@ def _format_mappings(properties, result): class CloudController(object): - """ CloudController provides the critical dispatch between + """CloudController provides the critical dispatch between inbound API calls through the endpoint and messages sent to the other nodes. """ diff --git a/nova/api/openstack/compute/contrib/flavorextraspecs.py b/nova/api/openstack/compute/contrib/flavorextraspecs.py index 77af25c9f6ff..1abb525adab4 100644 --- a/nova/api/openstack/compute/contrib/flavorextraspecs.py +++ b/nova/api/openstack/compute/contrib/flavorextraspecs.py @@ -15,7 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. -""" The instance type extra specs extension""" +"""The instance type extra specs extension""" from webob import exc @@ -35,7 +35,7 @@ class ExtraSpecsTemplate(xmlutil.TemplateBuilder): class FlavorExtraSpecsController(object): - """ The flavor extra specs API controller for the OpenStack API """ + """The flavor extra specs API controller for the OpenStack API """ def _get_extra_specs(self, context, flavor_id): extra_specs = db.instance_type_extra_specs_get(context, flavor_id) @@ -51,7 +51,7 @@ class FlavorExtraSpecsController(object): @wsgi.serializers(xml=ExtraSpecsTemplate) def index(self, req, flavor_id): - """ Returns the list of extra specs for a givenflavor """ + """Returns the list of extra specs for a givenflavor """ context = req.environ['nova.context'] authorize(context) return self._get_extra_specs(context, flavor_id) @@ -92,7 +92,7 @@ class FlavorExtraSpecsController(object): @wsgi.serializers(xml=ExtraSpecsTemplate) def show(self, req, flavor_id, id): - """ Return a single extra spec item """ + """Return a single extra spec item """ context = req.environ['nova.context'] authorize(context) specs = self._get_extra_specs(context, flavor_id) @@ -102,7 +102,7 @@ class FlavorExtraSpecsController(object): raise exc.HTTPNotFound() def delete(self, req, flavor_id, id): - """ Deletes an existing extra spec """ + """Deletes an existing extra spec """ context = req.environ['nova.context'] authorize(context) db.instance_type_extra_specs_delete(context, flavor_id, id) diff --git a/nova/api/openstack/compute/contrib/keypairs.py b/nova/api/openstack/compute/contrib/keypairs.py index e5e1e37fda73..9b3b39384b26 100644 --- a/nova/api/openstack/compute/contrib/keypairs.py +++ b/nova/api/openstack/compute/contrib/keypairs.py @@ -15,7 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. -""" Keypair management extension""" +"""Keypair management extension""" import webob import webob.exc @@ -49,7 +49,7 @@ class KeypairsTemplate(xmlutil.TemplateBuilder): class KeypairController(object): - """ Keypair API controller for the OpenStack API """ + """Keypair API controller for the OpenStack API """ def __init__(self): self.api = compute_api.KeypairAPI() diff --git a/nova/api/openstack/compute/server_metadata.py b/nova/api/openstack/compute/server_metadata.py index 4e5a3ee02db9..910d88c30b58 100644 --- a/nova/api/openstack/compute/server_metadata.py +++ b/nova/api/openstack/compute/server_metadata.py @@ -24,7 +24,7 @@ from nova import exception class Controller(object): - """ The server metadata API controller for the OpenStack API """ + """The server metadata API controller for the OpenStack API """ def __init__(self): self.compute_api = compute.API() @@ -45,7 +45,7 @@ class Controller(object): @wsgi.serializers(xml=common.MetadataTemplate) def index(self, req, server_id): - """ Returns the list of metadata for a given instance """ + """Returns the list of metadata for a given instance """ context = req.environ['nova.context'] return {'metadata': self._get_metadata(context, server_id)} @@ -138,7 +138,7 @@ class Controller(object): @wsgi.serializers(xml=common.MetaItemTemplate) def show(self, req, server_id, id): - """ Return a single metadata item """ + """Return a single metadata item """ context = req.environ['nova.context'] data = self._get_metadata(context, server_id) @@ -150,7 +150,7 @@ class Controller(object): @wsgi.response(204) def delete(self, req, server_id, id): - """ Deletes an existing metadata """ + """Deletes an existing metadata """ context = req.environ['nova.context'] metadata = self._get_metadata(context, server_id) diff --git a/nova/block_device.py b/nova/block_device.py index ea4ff9c3b566..7e1e5374a4c5 100644 --- a/nova/block_device.py +++ b/nova/block_device.py @@ -83,7 +83,7 @@ _pref = re.compile('^((x?v|s)d)') def strip_prefix(device_name): - """ remove both leading /dev/ and xvd or sd or vd """ + """remove both leading /dev/ and xvd or sd or vd """ device_name = strip_dev(device_name) return _pref.sub('', device_name) diff --git a/nova/compute/api.py b/nova/compute/api.py index abbc0bd92f75..f42891f895ec 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -313,9 +313,10 @@ class API(base.Base): raise exception.InvalidMetadataSize(reason=msg) def _check_requested_networks(self, context, requested_networks): - """ Check if the networks requested belongs to the project - and the fixed IP address for each network provided is within - same the network block + """ + Check if the networks requested belongs to the project + and the fixed IP address for each network provided is within + same the network block """ if not requested_networks: return diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 80db50156ac2..5a0113bf65e5 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2779,7 +2779,7 @@ class ComputeManager(manager.SchedulerDependentManager): instance_ref, dest) def rollback_live_migration_at_destination(self, context, instance): - """ Cleaning up image directory that is created pre_live_migration. + """Cleaning up image directory that is created pre_live_migration. :param context: security context :param instance: an Instance dict sent over rpc diff --git a/nova/db/sqlalchemy/session.py b/nova/db/sqlalchemy/session.py index ae8fec32df4e..b50d5f969e8d 100644 --- a/nova/db/sqlalchemy/session.py +++ b/nova/db/sqlalchemy/session.py @@ -335,8 +335,10 @@ _RE_DB = { def raise_if_duplicate_entry_error(integrity_error, engine_name): - """ In this function will be raised DBDuplicateEntry exception if integrity - error wrap unique constraint violation. """ + """ + In this function will be raised DBDuplicateEntry exception if integrity + error wrap unique constraint violation. + """ def get_columns_from_uniq_cons_or_name(columns): # note(boris-42): UniqueConstraint name convention: "uniq_c1_x_c2_x_c3" diff --git a/nova/network/dns_driver.py b/nova/network/dns_driver.py index 09335b7cca2c..6e7cbf556a45 100644 --- a/nova/network/dns_driver.py +++ b/nova/network/dns_driver.py @@ -14,7 +14,7 @@ class DNSDriver(object): - """ Defines the DNS manager interface. Does nothing. """ + """Defines the DNS manager interface. Does nothing. """ def __init__(self): pass diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index e803488d2e6c..3caf964a2b72 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -1136,8 +1136,10 @@ def get_dev(network): class LinuxNetInterfaceDriver(object): - """Abstract class that defines generic network host API""" - """ for for all Linux interface drivers.""" + """ + Abstract class that defines generic network host API + for for all Linux interface drivers. + """ def plug(self, network, mac_address): """Create Linux device, return device name""" diff --git a/nova/network/minidns.py b/nova/network/minidns.py index 11c59dcc94f1..c565f368eb83 100644 --- a/nova/network/minidns.py +++ b/nova/network/minidns.py @@ -27,14 +27,16 @@ LOG = logging.getLogger(__name__) class MiniDNS(dns_driver.DNSDriver): - """ Trivial DNS driver. This will read/write to a local, flat file - and have no effect on your actual DNS system. This class is - strictly for testing purposes, and should keep you out of dependency - hell. + """ + Trivial DNS driver. This will read/write to a local, flat file + and have no effect on your actual DNS system. This class is + strictly for testing purposes, and should keep you out of dependency + hell. - Note that there is almost certainly a race condition here that - will manifest anytime instances are rapidly created and deleted. - A proper implementation will need some manner of locking.""" + Note that there is almost certainly a race condition here that + will manifest anytime instances are rapidly created and deleted. + A proper implementation will need some manner of locking. + """ def __init__(self): if CONF.log_dir: diff --git a/nova/network/noop_dns_driver.py b/nova/network/noop_dns_driver.py index 23d1d1f3e939..be29f4d9a170 100644 --- a/nova/network/noop_dns_driver.py +++ b/nova/network/noop_dns_driver.py @@ -19,7 +19,7 @@ from nova.network import dns_driver class NoopDNSDriver(dns_driver.DNSDriver): - """ No-op DNS manager. Does nothing. """ + """No-op DNS manager. Does nothing. """ def __init__(self): pass diff --git a/nova/servicegroup/api.py b/nova/servicegroup/api.py index 59afb68e0b10..895fc84900f9 100644 --- a/nova/servicegroup/api.py +++ b/nova/servicegroup/api.py @@ -110,7 +110,7 @@ class ServiceGroupDriver(object): raise NotImplementedError() def is_up(self, member): - """ Check whether the given member is up. """ + """Check whether the given member is up. """ raise NotImplementedError() def leave(self, member_id, group_id): diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 734297501a6a..6938922ad2f8 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1782,17 +1782,12 @@ class ServersControllerCreateTest(test.TestCase): fake_method) def _check_admin_pass_len(self, server_dict): - """ utility function - check server_dict for adminPass - length. - - """ + """utility function - check server_dict for adminPass length.""" self.assertEqual(CONF.password_length, len(server_dict["adminPass"])) def _check_admin_pass_missing(self, server_dict): - """ utility function - check server_dict for absence - of adminPass - """ + """utility function - check server_dict for absence of adminPass.""" self.assertTrue("adminPass" not in server_dict) def _test_create_instance(self): diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 28bbb3d257ae..db1c9ede2fb8 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -43,7 +43,7 @@ class LimiterTest(test.TestCase): """ def setUp(self): - """ Run before each test. """ + """Run before each test. """ super(LimiterTest, self).setUp() self.tiny = range(1) self.small = range(10) @@ -51,7 +51,7 @@ class LimiterTest(test.TestCase): self.large = range(10000) def test_limiter_offset_zero(self): - """ Test offset key works with 0. """ + """Test offset key works with 0. """ req = webob.Request.blank('/?offset=0') self.assertEqual(common.limited(self.tiny, req), self.tiny) self.assertEqual(common.limited(self.small, req), self.small) @@ -59,7 +59,7 @@ class LimiterTest(test.TestCase): self.assertEqual(common.limited(self.large, req), self.large[:1000]) def test_limiter_offset_medium(self): - """ Test offset key works with a medium sized number. """ + """Test offset key works with a medium sized number. """ req = webob.Request.blank('/?offset=10') self.assertEqual(common.limited(self.tiny, req), []) self.assertEqual(common.limited(self.small, req), self.small[10:]) @@ -67,7 +67,7 @@ class LimiterTest(test.TestCase): self.assertEqual(common.limited(self.large, req), self.large[10:1010]) def test_limiter_offset_over_max(self): - """ Test offset key works with a number over 1000 (max_limit). """ + """Test offset key works with a number over 1000 (max_limit). """ req = webob.Request.blank('/?offset=1001') self.assertEqual(common.limited(self.tiny, req), []) self.assertEqual(common.limited(self.small, req), []) @@ -76,19 +76,19 @@ class LimiterTest(test.TestCase): common.limited(self.large, req), self.large[1001:2001]) def test_limiter_offset_blank(self): - """ Test offset key works with a blank offset. """ + """Test offset key works with a blank offset. """ req = webob.Request.blank('/?offset=') self.assertRaises( webob.exc.HTTPBadRequest, common.limited, self.tiny, req) def test_limiter_offset_bad(self): - """ Test offset key works with a BAD offset. """ + """Test offset key works with a BAD offset. """ req = webob.Request.blank(u'/?offset=\u0020aa') self.assertRaises( webob.exc.HTTPBadRequest, common.limited, self.tiny, req) def test_limiter_nothing(self): - """ Test request with no offset or limit """ + """Test request with no offset or limit """ req = webob.Request.blank('/') self.assertEqual(common.limited(self.tiny, req), self.tiny) self.assertEqual(common.limited(self.small, req), self.small) @@ -96,7 +96,7 @@ class LimiterTest(test.TestCase): self.assertEqual(common.limited(self.large, req), self.large[:1000]) def test_limiter_limit_zero(self): - """ Test limit of zero. """ + """Test limit of zero. """ req = webob.Request.blank('/?limit=0') self.assertEqual(common.limited(self.tiny, req), self.tiny) self.assertEqual(common.limited(self.small, req), self.small) @@ -104,7 +104,7 @@ class LimiterTest(test.TestCase): self.assertEqual(common.limited(self.large, req), self.large[:1000]) def test_limiter_limit_medium(self): - """ Test limit of 10. """ + """Test limit of 10. """ req = webob.Request.blank('/?limit=10') self.assertEqual(common.limited(self.tiny, req), self.tiny) self.assertEqual(common.limited(self.small, req), self.small) @@ -112,7 +112,7 @@ class LimiterTest(test.TestCase): self.assertEqual(common.limited(self.large, req), self.large[:10]) def test_limiter_limit_over_max(self): - """ Test limit of 3000. """ + """Test limit of 3000. """ req = webob.Request.blank('/?limit=3000') self.assertEqual(common.limited(self.tiny, req), self.tiny) self.assertEqual(common.limited(self.small, req), self.small) @@ -120,7 +120,7 @@ class LimiterTest(test.TestCase): self.assertEqual(common.limited(self.large, req), self.large[:1000]) def test_limiter_limit_and_offset(self): - """ Test request with both limit and offset. """ + """Test request with both limit and offset. """ items = range(2000) req = webob.Request.blank('/?offset=1&limit=3') self.assertEqual(common.limited(items, req), items[1:4]) @@ -132,7 +132,7 @@ class LimiterTest(test.TestCase): self.assertEqual(common.limited(items, req), []) def test_limiter_custom_max_limit(self): - """ Test a max_limit other than 1000. """ + """Test a max_limit other than 1000. """ items = range(2000) req = webob.Request.blank('/?offset=1&limit=3') self.assertEqual( @@ -147,13 +147,13 @@ class LimiterTest(test.TestCase): self.assertEqual(common.limited(items, req, max_limit=2000), []) def test_limiter_negative_limit(self): - """ Test a negative limit. """ + """Test a negative limit. """ req = webob.Request.blank('/?limit=-3000') self.assertRaises( webob.exc.HTTPBadRequest, common.limited, self.tiny, req) def test_limiter_negative_offset(self): - """ Test a negative offset. """ + """Test a negative offset. """ req = webob.Request.blank('/?offset=-30') self.assertRaises( webob.exc.HTTPBadRequest, common.limited, self.tiny, req) @@ -167,30 +167,30 @@ class PaginationParamsTest(test.TestCase): """ def test_no_params(self): - """ Test no params. """ + """Test no params. """ req = webob.Request.blank('/') self.assertEqual(common.get_pagination_params(req), {}) def test_valid_marker(self): - """ Test valid marker param. """ + """Test valid marker param. """ req = webob.Request.blank( '/?marker=263abb28-1de6-412f-b00b-f0ee0c4333c2') self.assertEqual(common.get_pagination_params(req), {'marker': '263abb28-1de6-412f-b00b-f0ee0c4333c2'}) def test_valid_limit(self): - """ Test valid limit param. """ + """Test valid limit param. """ req = webob.Request.blank('/?limit=10') self.assertEqual(common.get_pagination_params(req), {'limit': 10}) def test_invalid_limit(self): - """ Test invalid limit param. """ + """Test invalid limit param. """ req = webob.Request.blank('/?limit=-2') self.assertRaises( webob.exc.HTTPBadRequest, common.get_pagination_params, req) def test_valid_limit_and_marker(self): - """ Test valid limit and marker parameters. """ + """Test valid limit and marker parameters. """ marker = '263abb28-1de6-412f-b00b-f0ee0c4333c2' req = webob.Request.blank('/?limit=20&marker=%s' % marker) self.assertEqual(common.get_pagination_params(req), diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 57c2347343a1..b8f0fc0b97d2 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -573,7 +573,7 @@ class ComputeTestCase(BaseTestCase): 'task_state': task_states.SCHEDULING}) def test_run_instance_setup_block_device_mapping_fail(self): - """ block device mapping failure test. + """block device mapping failure test. Make sure that when there is a block device mapping problem, the instance goes to ERROR state, keeping the task state @@ -593,7 +593,7 @@ class ComputeTestCase(BaseTestCase): 'task_state': None}) def test_run_instance_spawn_fail(self): - """ spawn failure test. + """spawn failure test. Make sure that when there is a spawning problem, the instance goes to ERROR state, keeping the task state""" @@ -611,7 +611,7 @@ class ComputeTestCase(BaseTestCase): 'task_state': None}) def test_run_instance_dealloc_network_instance_not_found(self): - """ spawn network deallocate test. + """spawn network deallocate test. Make sure that when an instance is not found during spawn that the network is deallocated""" diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index e5f3b9ad5a4f..dfaf235af638 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -1533,7 +1533,7 @@ class AgentsJsonTest(ApiSampleTestBase): return project def test_agent_list(self): - """ Return a list of all agent builds.""" + """Return a list of all agent builds.""" response = self._do_get('os-agents') self.assertEqual(response.status, 200) project = {'url': 'xxxxxxxxxxxx', diff --git a/nova/tests/monkey_patch_example/__init__.py b/nova/tests/monkey_patch_example/__init__.py index 25cf9ccfe68c..779dc72f3d65 100644 --- a/nova/tests/monkey_patch_example/__init__.py +++ b/nova/tests/monkey_patch_example/__init__.py @@ -21,7 +21,7 @@ CALLED_FUNCTION = [] def example_decorator(name, function): - """ decorator for notify which is used from utils.monkey_patch() + """decorator for notify which is used from utils.monkey_patch() :param name: name of the function :param function: - object of the function diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py index 163afda7d8cf..0835df51d26b 100644 --- a/nova/tests/test_api.py +++ b/nova/tests/test_api.py @@ -350,7 +350,7 @@ class ApiEc2TestCase(test.TestCase): self.ec2.delete_security_group(security_group_name) def test_group_name_valid_chars_security_group(self): - """ Test that we sanely handle invalid security group names. + """Test that we sanely handle invalid security group names. EC2 API Spec states we should only accept alphanumeric characters, spaces, dashes, and underscores. Amazon implementation accepts more characters - so, [:print:] is ok. """ diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index af329daf68ce..dc0c57c19a2e 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -321,7 +321,7 @@ class DbApiTestCase(test.TestCase): inst['uuid'], 'vm_state', [None, 'disable'], 'run') def test_instance_update_with_instance_uuid(self): - """ test instance_update() works when an instance UUID is passed """ + """test instance_update() works when an instance UUID is passed """ ctxt = context.get_admin_context() # Create an instance with some metadata @@ -479,7 +479,7 @@ class DbApiTestCase(test.TestCase): self.assertEqual(404, faults[uuid][0]['code']) def test_instance_fault_get_by_instance(self): - """ ensure we can retrieve an instance fault by instance UUID """ + """ensure we can retrieve an instance fault by instance UUID """ ctxt = context.get_admin_context() instance1 = db.instance_create(ctxt, {}) instance2 = db.instance_create(ctxt, {}) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 6bc18251f522..a64b72695f6b 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -4303,12 +4303,12 @@ class LibvirtDriverTestCase(test.TestCase): self.stubs.Set(utils, 'execute', fake_execute) ins_ref = self._create_instance() - """ dest is different host case """ + # dest is different host case out = self.libvirtconnection.migrate_disk_and_power_off( None, ins_ref, '10.0.0.2', None, None) self.assertEquals(out, disk_info_text) - """ dest is same host case """ + # dest is same host case out = self.libvirtconnection.migrate_disk_and_power_off( None, ins_ref, '10.0.0.1', None, None) self.assertEquals(out, disk_info_text) @@ -4325,19 +4325,19 @@ class LibvirtDriverTestCase(test.TestCase): self.stubs.Set(self.libvirtconnection, 'get_info', fake_get_info) - """ instance not found case """ + # instance not found case self.assertRaises(exception.NotFound, self.libvirtconnection._wait_for_running, {'name': 'not_found', 'uuid': 'not_found_uuid'}) - """ instance is running case """ + # instance is running case self.assertRaises(utils.LoopingCallDone, self.libvirtconnection._wait_for_running, {'name': 'running', 'uuid': 'running_uuid'}) - """ else case """ + # else case self.libvirtconnection._wait_for_running({'name': 'else', 'uuid': 'other_uuid'}) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 8b57dfef4195..5b347fc0fa19 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -2509,7 +2509,7 @@ class StubDependencies(object): class ResourcePoolWithStubs(StubDependencies, pool.ResourcePool): - """ A ResourcePool, use stub dependencies """ + """A ResourcePool, use stub dependencies """ class HypervisorPoolTestCase(test.TestCase): diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index ca82812953c7..a44f3e9fd406 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -98,7 +98,7 @@ def stubout_determine_is_pv_objectstore(stubs): def stubout_is_snapshot(stubs): - """ Always returns true + """Always returns true xenapi fake driver does not create vmrefs for snapshots """ def f(*args): @@ -158,7 +158,7 @@ def _make_fake_vdi(): class FakeSessionForVMTests(fake.SessionBase): - """ Stubs out a XenAPISession for VM tests """ + """Stubs out a XenAPISession for VM tests """ _fake_iptables_save_output = ("# Generated by iptables-save v1.4.10 on " "Sun Nov 6 22:49:02 2011\n" @@ -204,7 +204,7 @@ class FakeSessionForVMTests(fake.SessionBase): class FakeSessionForFirewallTests(FakeSessionForVMTests): - """ Stubs out a XenApi Session for doing IPTable Firewall tests """ + """Stubs out a XenApi Session for doing IPTable Firewall tests """ def __init__(self, uri, test_case=None): super(FakeSessionForFirewallTests, self).__init__(uri) @@ -270,7 +270,7 @@ def stub_out_vm_methods(stubs): class FakeSessionForVolumeTests(fake.SessionBase): - """ Stubs out a XenAPISession for Volume tests """ + """Stubs out a XenAPISession for Volume tests """ def VDI_introduce(self, _1, uuid, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11): valid_vdi = False @@ -284,7 +284,7 @@ class FakeSessionForVolumeTests(fake.SessionBase): class FakeSessionForVolumeFailedTests(FakeSessionForVolumeTests): - """ Stubs out a XenAPISession for Volume tests: it injects failures """ + """Stubs out a XenAPISession for Volume tests: it injects failures """ def VDI_introduce(self, _1, uuid, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11): # This is for testing failure diff --git a/nova/utils.py b/nova/utils.py index 26468868a9c3..72de5f0f007a 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -866,7 +866,7 @@ def is_valid_cidr(address): def monkey_patch(): - """ If the Flags.monkey_patch set as True, + """If the Flags.monkey_patch set as True, this function patches a decorator for all functions in specified modules. You can set decorators for each modules diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 5d3b3c9269fb..c044a9abf735 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -349,7 +349,7 @@ class FakeDriver(driver.ComputeDriver): raise NotImplementedError('This method is supported only by libvirt.') def test_remove_vm(self, instance_name): - """ Removes the named VM, as if it crashed. For testing""" + """Removes the named VM, as if it crashed. For testing""" self.instances.pop(instance_name) def get_host_stats(self, refresh=False): @@ -386,7 +386,6 @@ class FakeDriver(driver.ComputeDriver): return 'disabled' def get_disk_available_least(self): - """ """ pass def get_volume_connector(self, instance): diff --git a/nova/virt/firewall.py b/nova/virt/firewall.py index d7a5cbc31380..178d35882f25 100644 --- a/nova/virt/firewall.py +++ b/nova/virt/firewall.py @@ -50,7 +50,7 @@ def load_driver(default, *args, **kwargs): class FirewallDriver(object): - """ Firewall Driver base class. + """Firewall Driver base class. Defines methods that any driver providing security groups and provider firewall functionality should implement. diff --git a/nova/virt/hyperv/hostops.py b/nova/virt/hyperv/hostops.py index 8c501ab3046a..5cbe46c1cbd3 100644 --- a/nova/virt/hyperv/hostops.py +++ b/nova/virt/hyperv/hostops.py @@ -39,7 +39,7 @@ class HostOps(baseops.BaseOps): self._stats = None def _get_cpu_info(self): - """ Get the CPU information. + """Get the CPU information. :returns: A dictionary containing the main properties of the central processor in the hypervisor. """ @@ -107,7 +107,7 @@ class HostOps(baseops.BaseOps): return total_gb, used_gb def _get_vcpu_used(self): - """ Get vcpu usage number of physical computer. + """Get vcpu usage number of physical computer. :returns: The total number of vcpu that currently used. """ #TODO(jordanrinke) figure out a way to count assigned VCPUs diff --git a/nova/virt/hyperv/vmops.py b/nova/virt/hyperv/vmops.py index 46fbd6cbc323..680d57ce1293 100644 --- a/nova/virt/hyperv/vmops.py +++ b/nova/virt/hyperv/vmops.py @@ -69,7 +69,7 @@ class VMOps(baseops.BaseOps): self._volumeops = volumeops def list_instances(self): - """ Return the names of all the instances known to Hyper-V. """ + """Return the names of all the instances known to Hyper-V. """ vms = [v.ElementName for v in self._conn.Msvm_ComputerSystem(['ElementName'], Caption="Virtual Machine")] @@ -118,7 +118,7 @@ class VMOps(baseops.BaseOps): def spawn(self, context, instance, image_meta, injected_files, admin_password, network_info, block_device_info=None): - """ Create a new VM and start it.""" + """Create a new VM and start it.""" vm = self._vmutils.lookup(self._conn, instance['name']) if vm is not None: raise exception.InstanceExists(name=instance['name']) @@ -271,7 +271,7 @@ class VMOps(baseops.BaseOps): LOG.debug(_('Set vcpus for vm %s...'), instance["name"]) def _create_scsi_controller(self, vm_name): - """ Create an iscsi controller ready to mount volumes """ + """Create an iscsi controller ready to mount volumes """ LOG.debug(_('Creating a scsi controller for %(vm_name)s for volume ' 'attaching') % locals()) vms = self._conn.MSVM_ComputerSystem(ElementName=vm_name) diff --git a/nova/virt/hyperv/volumeutils.py b/nova/virt/hyperv/volumeutils.py index 8ae437cf930c..31c05b9ad91d 100644 --- a/nova/virt/hyperv/volumeutils.py +++ b/nova/virt/hyperv/volumeutils.py @@ -68,7 +68,7 @@ class VolumeUtils(basevolumeutils.BaseVolumeUtils): time.sleep(CONF.hyperv_wait_between_attach_retry) def logout_storage_target(self, target_iqn): - """ Logs out storage target through its session id """ + """Logs out storage target through its session id """ sessions = self._conn_wmi.query( "SELECT * FROM MSiSCSIInitiator_SessionClass \ @@ -77,5 +77,5 @@ class VolumeUtils(basevolumeutils.BaseVolumeUtils): self.execute_log_out(session.SessionId) def execute_log_out(self, session_id): - """ Executes log out of the session described by its session ID """ + """Executes log out of the session described by its session ID """ self.execute('iscsicli.exe ' + 'logouttarget ' + session_id) diff --git a/nova/virt/hyperv/volumeutilsV2.py b/nova/virt/hyperv/volumeutilsV2.py index 8d7c91862202..03e3002f4ee3 100644 --- a/nova/virt/hyperv/volumeutilsV2.py +++ b/nova/virt/hyperv/volumeutilsV2.py @@ -53,7 +53,7 @@ class VolumeUtilsV2(basevolumeutils.BaseVolumeUtils): time.sleep(CONF.hyperv_wait_between_attach_retry) def logout_storage_target(self, target_iqn): - """ Logs out storage target through its session id """ + """Logs out storage target through its session id """ target = self._conn_storage.MSFT_iSCSITarget( NodeAddress=target_iqn)[0] diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 6befe429e1f1..da21fcf6b4dd 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -2024,7 +2024,7 @@ class LibvirtDriver(driver.ComputeDriver): return stats['total'] / (1024 ** 3) def get_vcpu_used(self): - """ Get vcpu usage number of physical computer. + """Get vcpu usage number of physical computer. :returns: The total number of vcpu that currently used. @@ -2579,9 +2579,7 @@ class LibvirtDriver(driver.ComputeDriver): timer.start(interval=0.5).wait() def _fetch_instance_kernel_ramdisk(self, context, instance): - """ Download kernel and ramdisk for given instance in the given - instance directory. - """ + """Download kernel and ramdisk for instance in instance directory.""" instance_dir = os.path.join(CONF.instances_path, instance['name']) if instance['kernel_id']: libvirt_utils.fetch_image(context, @@ -3000,8 +2998,7 @@ class LibvirtDriver(driver.ComputeDriver): def get_diagnostics(self, instance): def get_io_devices(xml_doc): - """ get the list of io devices from the - xml document.""" + """get the list of io devices from the xml document.""" result = {"volumes": [], "ifaces": []} try: doc = etree.fromstring(xml_doc) diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py index a3071e0c9a8e..f65fa4a7edc6 100644 --- a/nova/virt/libvirt/vif.py +++ b/nova/virt/libvirt/vif.py @@ -273,7 +273,7 @@ class LibvirtOpenVswitchVirtualPortDriver(LibvirtBaseVIFDriver): OVS virtual port XML (introduced in libvirt 0.9.11).""" def get_config(self, instance, network, mapping): - """ Pass data required to create OVS virtual port element""" + """Pass data required to create OVS virtual port element""" conf = super(LibvirtOpenVswitchVirtualPortDriver, self).get_config(instance, network, diff --git a/nova/virt/libvirt/volume_nfs.py b/nova/virt/libvirt/volume_nfs.py index 722760f0abeb..ebec36b6aef6 100644 --- a/nova/virt/libvirt/volume_nfs.py +++ b/nova/virt/libvirt/volume_nfs.py @@ -39,8 +39,8 @@ CONF.import_opt('state_path', 'nova.config') class NfsVolumeDriver(volume.LibvirtVolumeDriver): - """ Class implements libvirt part of volume driver for NFS - """ + """Class implements libvirt part of volume driver for NFS.""" + def __init__(self, *args, **kwargs): """Create back-end to nfs and check connection""" super(NfsVolumeDriver, self).__init__(*args, **kwargs) diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py index d3047d364142..a03e5eab1b7c 100644 --- a/nova/virt/xenapi/driver.py +++ b/nova/virt/xenapi/driver.py @@ -189,7 +189,7 @@ class XenAPIDriver(driver.ComputeDriver): block_device_info) def snapshot(self, context, instance, image_id, update_task_state): - """ Create snapshot from a running VM instance """ + """Create snapshot from a running VM instance.""" self._vmops.snapshot(context, instance, image_id, update_task_state) def reboot(self, instance, network_info, reboot_type, @@ -515,24 +515,24 @@ class XenAPIDriver(driver.ComputeDriver): return self._vmops.unfilter_instance(instance_ref, network_info) def refresh_security_group_rules(self, security_group_id): - """ Updates security group rules for all instances - associated with a given security group - Invoked when security group rules are updated - """ + """Updates security group rules for all instances associated with a + given security group. + + Invoked when security group rules are updated.""" return self._vmops.refresh_security_group_rules(security_group_id) def refresh_security_group_members(self, security_group_id): - """ Updates security group rules for all instances - associated with a given security group - Invoked when instances are added/removed to a security group - """ + """Updates security group rules for all instances associated with a + given security group. + + Invoked when instances are added/removed to a security group.""" return self._vmops.refresh_security_group_members(security_group_id) def refresh_instance_security_rules(self, instance): - """ Updates security group rules for specified instance - Invoked when instances are added/removed to a security group - or when a rule is added/removed to a security group - """ + """Updates security group rules for specified instance. + + Invoked when instances are added/removed to a security group + or when a rule is added/removed to a security group.""" return self._vmops.refresh_instance_security_rules(instance) def refresh_provider_fw_rules(self): diff --git a/nova/virt/xenapi/firewall.py b/nova/virt/xenapi/firewall.py index e30465741ce1..9c6a60d18a23 100644 --- a/nova/virt/xenapi/firewall.py +++ b/nova/virt/xenapi/firewall.py @@ -27,12 +27,11 @@ LOG = logging.getLogger(__name__) class Dom0IptablesFirewallDriver(firewall.IptablesFirewallDriver): - """ Dom0IptablesFirewallDriver class + """Dom0IptablesFirewallDriver class This class provides an implementation for nova.virt.Firewall using iptables. This class is meant to be used with the xenapi - backend and uses xenapi plugin to enforce iptables rules in dom0 - + backend and uses xenapi plugin to enforce iptables rules in dom0. """ def _plugin_execute(self, *cmd, **kwargs): # Prepare arguments for plugin call diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index fbf3e0599efb..06e950f438c2 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -1509,15 +1509,15 @@ class VMOps(object): self._session.call_xenapi('VM.remove_from_xenstore_data', vm_ref, key) def refresh_security_group_rules(self, security_group_id): - """ recreates security group rules for every instance """ + """recreates security group rules for every instance """ self.firewall_driver.refresh_security_group_rules(security_group_id) def refresh_security_group_members(self, security_group_id): - """ recreates security group rules for every instance """ + """recreates security group rules for every instance """ self.firewall_driver.refresh_security_group_members(security_group_id) def refresh_instance_security_rules(self, instance): - """ recreates security group rules for specified instance """ + """recreates security group rules for specified instance """ self.firewall_driver.refresh_instance_security_rules(instance) def refresh_provider_fw_rules(self): @@ -1600,8 +1600,8 @@ class VMOps(object): def check_can_live_migrate_source(self, ctxt, instance_ref, dest_check_data): - """ Check if it is possible to execute live migration - on the source side. + """Check if it's possible to execute live migration on the source side. + :param context: security context :param instance_ref: nova.db.sqlalchemy.models.Instance object :param dest_check_data: data returned by the check on the diff --git a/run_tests.sh b/run_tests.sh index a3ed978035bb..7bff66c7a3b0 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -121,7 +121,7 @@ function run_pep8 { srcfiles+=" setup.py" # Until all these issues get fixed, ignore. - ignore='--ignore=N4,E12,E711,E721,E712' + ignore='--ignore=N402,E12,E711,E721,E712' ${wrapper} python tools/hacking.py ${ignore} ${srcfiles} diff --git a/tools/hacking.py b/tools/hacking.py index bde4f42d4e5f..a860aa37b4c5 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -268,18 +268,23 @@ def nova_import_no_db_in_virt(logical_line, filename): yield (0, "NOVA N307: nova.db import not allowed in nova/virt/*") -def nova_docstring_start_space(physical_line): +def nova_docstring_start_space(physical_line, previous_logical): """Check for docstring not start with space. nova HACKING guide recommendation for docstring: Docstring should not start with space N401 """ - pos = max([physical_line.find(i) for i in DOCSTRING_TRIPLE]) # start - if (pos != -1 and len(physical_line) > pos + 1): - if (physical_line[pos + 3] == ' '): - return (pos, "NOVA N401: one line docstring should not start with" - " a space") + # it's important that we determine this is actually a docstring, + # and not a doc block used somewhere after the first line of a + # function def + if (previous_logical.startswith("def ") or + previous_logical.startswith("class ")): + pos = max([physical_line.find(i) for i in DOCSTRING_TRIPLE]) + if (pos != -1 and len(physical_line) > pos + 4): + if (physical_line[pos + 3] == ' '): + return (pos, "NOVA N401: docstring should not start with" + " a space") def nova_docstring_one_line(physical_line): diff --git a/tox.ini b/tox.ini index 4fa567518b18..bfec45f0ee31 100644 --- a/tox.ini +++ b/tox.ini @@ -21,9 +21,9 @@ downloadcache = ~/cache/pip [testenv:pep8] deps=pep8==1.3.3 commands = - python tools/hacking.py --ignore=N4,E12,E711,E721,E712 --repeat --show-source \ + python tools/hacking.py --ignore=N402,E12,E711,E721,E712 --repeat --show-source \ --exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg . - python tools/hacking.py --ignore=N4,E12,E711,E721,E712 --repeat --show-source \ + python tools/hacking.py --ignore=N402,E12,E711,E721,E712 --repeat --show-source \ --filename=nova* bin [testenv:pylint]