diff --git a/nova/tests/baremetal/test_proxy_bare_metal.py b/nova/tests/baremetal/test_proxy_bare_metal.py index 580f8986..0ea74622 100644 --- a/nova/tests/baremetal/test_proxy_bare_metal.py +++ b/nova/tests/baremetal/test_proxy_bare_metal.py @@ -95,9 +95,9 @@ class DomainReadWriteTestCase(test.TestCase): self.mox.StubOutWithMock(__builtin__, 'open') try: - open('/tftpboot/test_fake_dom_file', 'r').AndRaise(\ - IOError(2, 'No such file or directory', - '/tftpboot/test_fake_dom_file')) + open('/tftpboot/test_fake_dom_file', + 'r').AndRaise(IOError(2, 'No such file or directory', + '/tftpboot/test_fake_dom_file')) self.mox.ReplayAll() @@ -128,8 +128,8 @@ class DomainReadWriteTestCase(test.TestCase): # Python object as expected_json # We can't do an exact string comparison # because of ordering and whitespace - mock_file.write(mox.Func(functools.partial(self.assertJSONEquals,\ - expected_json))) + mock_file.write(mox.Func(functools.partial(self.assertJSONEquals, + expected_json))) mock_file.close() self.mox.ReplayAll() @@ -236,8 +236,8 @@ class BareMetalDomTestCase(test.TestCase): self.mox.StubOutWithMock(dom, 'write_domains') # Expected calls - dom.read_domains('/tftpboot/test_fake_dom_file')\ - .AndReturn(fake_domains) + dom.read_domains('/tftpboot/' + 'test_fake_dom_file').AndReturn(fake_domains) dom.write_domains('/tftpboot/test_fake_dom_file', fake_domains) self.mox.ReplayAll() @@ -274,8 +274,8 @@ class ProxyBareMetalTestCase(test.TestCase): self.mox.StubOutWithMock(dom, 'write_domains') # Expected calls - dom.read_domains('/tftpboot/test_fake_dom_file')\ - .AndReturn(fake_domains) + dom.read_domains('/tftpboot/' + 'test_fake_dom_file').AndReturn(fake_domains) dom.write_domains('/tftpboot/test_fake_dom_file', fake_domains) self.mox.ReplayAll() diff --git a/nova/tests/baremetal/test_tilera.py b/nova/tests/baremetal/test_tilera.py index 7b58282e..e98ade86 100644 --- a/nova/tests/baremetal/test_tilera.py +++ b/nova/tests/baremetal/test_tilera.py @@ -26,26 +26,29 @@ class TileraBareMetalNodesTestCase(test.TestCase): def setUp(self): super(TileraBareMetalNodesTestCase, self).setUp() - self.board_info = """\ -# board_id ip_address mac_address 00:1A:CA:00:57:90 \ -00:1A:CA:00:58:98 00:1A:CA:00:58:50 -6 10.0.2.7 00:1A:CA:00:58:5C 10 16218 917 476 1 tilera_hv 1 \ -{"vendor":"tilera","model":"TILEmpower","arch":"TILEPro64","features":\ -["8x8Grid","32bVLIW","5.6MBCache","443BOPS","37TbMesh","700MHz-866MHz",\ -"4DDR2","2XAUIMAC/PHY","2GbEMAC"],"topology":{"cores":"64"}} -7 10.0.2.8 00:1A:CA:00:58:A4 10 16218 917 476 1 tilera_hv 1 \ -{"vendor":"tilera","model":"TILEmpower","arch":"TILEPro64","features":\ -["8x8Grid","32bVLIW","5.6MBCache","443BOPS","37TbMesh","700MHz-866MHz",\ -"4DDR2","2XAUIMAC/PHY","2GbEMAC"],"topology":{"cores":"64"}} -8 10.0.2.9 00:1A:CA:00:58:1A 10 16218 917 476 1 tilera_hv 1 \ -{"vendor":"tilera","model":"TILEmpower","arch":"TILEPro64","features":\ -["8x8Grid","32bVLIW","5.6MBCache","443BOPS","37TbMesh","700MHz-866MHz",\ -"4DDR2","2XAUIMAC/PHY","2GbEMAC"],"topology":{"cores":"64"}} -9 10.0.2.10 00:1A:CA:00:58:38 10 16385 1000 0 0 tilera_hv 1 \ -{"vendor":"tilera","model":"TILEmpower","arch":"TILEPro64","features":\ -["8x8Grid","32bVLIW","5.6MBCache","443BOPS","37TbMesh","700MHz-866MHz",\ -"4DDR2","2XAUIMAC/PHY","2GbEMAC"],"topology":{"cores":"64"}} -""" + self.board_info = "\n".join([ +'# board_id ip_address mac_address 00:1A:CA:00:57:90 ' +'00:1A:CA:00:58:98 00:1A:CA:00:58:50', +'6 10.0.2.7 00:1A:CA:00:58:5C 10 16218 917 476 1 tilera_hv 1 ' +'{"vendor":"tilera","model":"TILEmpower","arch":"TILEPro64",' + '"features":["8x8Grid","32bVLIW","5.6MBCache","443BOPS","37TbMesh",' + '"700MHz-866MHz","4DDR2","2XAUIMAC/PHY","2GbEMAC"],' + '"topology":{"cores":"64"}}', +'7 10.0.2.8 00:1A:CA:00:58:A4 10 16218 917 476 1 tilera_hv 1 ' +'{"vendor":"tilera","model":"TILEmpower","arch":"TILEPro64",' + '"features":["8x8Grid","32bVLIW","5.6MBCache","443BOPS","37TbMesh",' + '"700MHz-866MHz","4DDR2","2XAUIMAC/PHY","2GbEMAC"],' + '"topology":{"cores":"64"}}', +'8 10.0.2.9 00:1A:CA:00:58:1A 10 16218 917 476 1 tilera_hv 1 ' +'{"vendor":"tilera","model":"TILEmpower","arch":"TILEPro64",' + '"features":["8x8Grid","32bVLIW","5.6MBCache","443BOPS","37TbMesh",' + '"700MHz-866MHz","4DDR2","2XAUIMAC/PHY","2GbEMAC"],' + '"topology":{"cores":"64"}}', +'9 10.0.2.10 00:1A:CA:00:58:38 10 16385 1000 0 0 tilera_hv 1 ' +'{"vendor":"tilera","model":"TILEmpower","arch":"TILEPro64",' + '"features":["8x8Grid","32bVLIW","5.6MBCache","443BOPS","37TbMesh",' + '"700MHz-866MHz","4DDR2","2XAUIMAC/PHY","2GbEMAC"],' + '"topology":{"cores":"64"}}']) def tearDown(self): super(TileraBareMetalNodesTestCase, self).tearDown() @@ -63,8 +66,8 @@ class TileraBareMetalNodesTestCase(test.TestCase): try: self.mox.StubOutWithMock(__builtin__, 'open') - open("/tftpboot/tilera_boards", "r").AndReturn(\ - StringIO.StringIO(self.board_info)) + open("/tftpboot/tilera_boards", + "r").AndReturn(StringIO.StringIO(self.board_info)) self.mox.ReplayAll() @@ -78,8 +81,8 @@ class TileraBareMetalNodesTestCase(test.TestCase): self.mox.StubOutWithMock(__builtin__, 'open') - open("/tftpboot/tilera_boards", "r").AndReturn(\ - StringIO.StringIO(self.board_info)) + open("/tftpboot/tilera_boards", + "r").AndReturn(StringIO.StringIO(self.board_info)) self.mox.ReplayAll() nodes = tilera.BareMetalNodes() diff --git a/nova/tests/scheduler/test_vsa_scheduler.py b/nova/tests/scheduler/test_vsa_scheduler.py index 8e465271..853ac983 100644 --- a/nova/tests/scheduler/test_vsa_scheduler.py +++ b/nova/tests/scheduler/test_vsa_scheduler.py @@ -122,10 +122,10 @@ class VsaSchedulerTestCase(test_scheduler.SchedulerTestCase): dtype['DriveType'] = 'type_' + str(j) dtype['TotalDrives'] = 2 * (self.init_num_drives + i) dtype['DriveCapacity'] = vsa_sched.GB_TO_BYTES(1 + 100 * j) - dtype['TotalCapacity'] = dtype['TotalDrives'] * \ - dtype['DriveCapacity'] - dtype['AvailableCapacity'] = (dtype['TotalDrives'] - i) * \ - dtype['DriveCapacity'] + dtype['TotalCapacity'] = (dtype['TotalDrives'] * + dtype['DriveCapacity']) + dtype['AvailableCapacity'] = ((dtype['TotalDrives'] - i) * + dtype['DriveCapacity']) dtype['DriveRpm'] = 7200 dtype['DifCapable'] = 0 dtype['SedCapable'] = 0 @@ -150,18 +150,20 @@ class VsaSchedulerTestCase(test_scheduler.SchedulerTestCase): qos = host_val['volume']['drive_qos_info'] for k, d in qos.iteritems(): - LOG.info("\t%s: type %s: drives (used %2d, total %2d) "\ - "size %3d, total %4d, used %4d, avail %d", - k, d['DriveType'], - d['FullDrive']['NumOccupiedDrives'], d['TotalDrives'], - vsa_sched.BYTES_TO_GB(d['DriveCapacity']), - vsa_sched.BYTES_TO_GB(d['TotalCapacity']), - vsa_sched.BYTES_TO_GB(d['TotalCapacity'] - \ - d['AvailableCapacity']), - vsa_sched.BYTES_TO_GB(d['AvailableCapacity'])) + LOG.info("\t%s: type %s: drives (used %2d, total %2d) " + "size %3d, total %4d, used %4d, avail %d", + k, + d['DriveType'], + d['FullDrive']['NumOccupiedDrives'], + d['TotalDrives'], + vsa_sched.BYTES_TO_GB(d['DriveCapacity']), + vsa_sched.BYTES_TO_GB(d['TotalCapacity']), + vsa_sched.BYTES_TO_GB(d['TotalCapacity'] - + d['AvailableCapacity']), + vsa_sched.BYTES_TO_GB(d['AvailableCapacity'])) - total_used += vsa_sched.BYTES_TO_GB(d['TotalCapacity'] - \ - d['AvailableCapacity']) + total_used += vsa_sched.BYTES_TO_GB(d['TotalCapacity'] - + d['AvailableCapacity']) total_available += vsa_sched.BYTES_TO_GB( d['AvailableCapacity']) LOG.info("Host %s: used %d, avail %d", @@ -196,7 +198,7 @@ class VsaSchedulerTestCase(test_scheduler.SchedulerTestCase): LOG.debug(_("\t vol=%(vol)s"), locals()) def _fake_vsa_update(self, context, vsa_id, values): - LOG.debug(_("Test: VSA update request: vsa_id=%(vsa_id)s "\ + LOG.debug(_("Test: VSA update request: vsa_id=%(vsa_id)s " "values=%(values)s"), locals()) def _fake_volume_create(self, context, options): @@ -214,7 +216,7 @@ class VsaSchedulerTestCase(test_scheduler.SchedulerTestCase): return global_volume def _fake_volume_update(self, context, volume_id, values): - LOG.debug(_("Test: Volume update request: id=%(volume_id)s "\ + LOG.debug(_("Test: Volume update request: id=%(volume_id)s " "values=%(values)s"), locals()) global scheduled_volume scheduled_volume = {'id': volume_id, 'host': values['host']} diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py index f7548ceb..51efbeec 100644 --- a/nova/tests/test_api.py +++ b/nova/tests/test_api.py @@ -279,7 +279,7 @@ class ApiEc2TestCase(test.TestCase): a key pair, that the API call to list key pairs works properly""" self.expect_http() self.mox.ReplayAll() - keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd") \ + keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd") for x in range(random.randint(4, 8))) # NOTE(vish): create depends on pool, so call helper directly cloud._gen_key(context.get_admin_context(), 'fake', keyname) @@ -293,7 +293,7 @@ class ApiEc2TestCase(test.TestCase): requesting a second keypair with the same name fails sanely""" self.expect_http() self.mox.ReplayAll() - keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd") \ + keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd") for x in range(random.randint(4, 8))) # NOTE(vish): create depends on pool, so call helper directly self.ec2.create_key_pair('test') diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 6cbfb534..cbf496d0 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -74,8 +74,8 @@ orig_rpc_cast = rpc.cast def rpc_call_wrapper(context, topic, msg, do_cast=True): """Stub out the scheduler creating the instance entry""" - if topic == FLAGS.scheduler_topic and \ - msg['method'] == 'run_instance': + if (topic == FLAGS.scheduler_topic and + msg['method'] == 'run_instance'): request_spec = msg['args']['request_spec'] scheduler = scheduler_driver.Scheduler num_instances = request_spec.get('num_instances', 1) @@ -892,11 +892,11 @@ class ComputeTestCase(BaseTestCase): fake_get_nw_info) self.mox.StubOutWithMock(self.compute.network_api, "allocate_for_instance") - self.compute.network_api.allocate_for_instance(mox.IgnoreArg(), - mox.IgnoreArg(), - requested_networks=None, - vpn=False).\ - AndRaise(quantum_client.QuantumServerException()) + self.compute.network_api.allocate_for_instance( + mox.IgnoreArg(), + mox.IgnoreArg(), + requested_networks=None, + vpn=False).AndRaise(quantum_client.QuantumServerException()) self.flags(stub_network=False) @@ -918,9 +918,9 @@ class ComputeTestCase(BaseTestCase): instance = self._create_fake_instance() self.mox.StubOutWithMock(self.compute, "_setup_block_device_mapping") - self.compute._setup_block_device_mapping(mox.IgnoreArg(), - mox.IgnoreArg()).\ - AndRaise(rpc.common.RemoteError('', '', '')) + self.compute._setup_block_device_mapping( + mox.IgnoreArg(), + mox.IgnoreArg()).AndRaise(rpc.common.RemoteError('', '', '')) self.mox.ReplayAll() @@ -1339,11 +1339,12 @@ class ComputeTestCase(BaseTestCase): self.mox.StubOutWithMock(self.compute.driver, 'get_instance_disk_info') self.compute.driver.get_instance_disk_info(inst_ref.name) - rpc.call(c, topic, {"method": "pre_live_migration", - "args": {'instance_id': instance_id, - 'block_migration': True, - 'disk': None}}).\ - AndRaise(rpc.common.RemoteError('', '', '')) + rpc.call(c, topic, + {"method": "pre_live_migration", + "args": {'instance_id': instance_id, + 'block_migration': True, + 'disk': None} + }).AndRaise(rpc.common.RemoteError('', '', '')) # mocks for rollback rpc.call(c, topic, {"method": "remove_volume_connection", "args": {'instance_id': instance_id, diff --git a/nova/tests/test_direct.py b/nova/tests/test_direct.py index afd20dd6..cf92dfca 100644 --- a/nova/tests/test_direct.py +++ b/nova/tests/test_direct.py @@ -125,8 +125,8 @@ class DirectTestCase(test.TestCase): req = webob.Request.blank('/fake/echo') req.environ['openstack.context'] = self.context req.method = 'POST' - req.body = 'data=foo&_underscored=ignoreMe&self=ignoreMe&context='\ - 'ignoreMe' + req.body = ('data=foo&_underscored=ignoreMe&self=ignoreMe&context=' + 'ignoreMe') resp = req.get_response(self.router) self.assertEqual(resp.status_int, 200) resp_parsed = json.loads(resp.body) diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index dfa7d613..12d39f71 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -49,8 +49,8 @@ class InstanceTypeTestCase(test.TestCase): def _generate_flavorid(self): """return a flavorid not in the DB""" nonexistent_flavor = 2700 - flavor_ids = [value["id"] for key, value in\ - instance_types.get_all_types().iteritems()] + flavor_ids = [value["id"] for key, value in + instance_types.get_all_types().iteritems()] while nonexistent_flavor in flavor_ids: nonexistent_flavor += 1 else: diff --git a/nova/tests/test_iscsi.py b/nova/tests/test_iscsi.py index d7aed0fb..1008a9a0 100644 --- a/nova/tests/test_iscsi.py +++ b/nova/tests/test_iscsi.py @@ -83,17 +83,17 @@ class TgtAdmTestCase(test.TestCase, TargetAdminTestCase): super(TgtAdmTestCase, self).setUp() TargetAdminTestCase.setUp(self) self.flags(iscsi_helper='tgtadm') - self.script_template = """ -tgtadm --op new --lld=iscsi --mode=target --tid=%(tid)s \ ---targetname=%(target_name)s -tgtadm --op bind --lld=iscsi --mode=target --initiator-address=ALL \ ---tid=%(tid)s -tgtadm --op show --lld=iscsi --mode=target --tid=%(tid)s -tgtadm --op new --lld=iscsi --mode=logicalunit --tid=%(tid)s --lun=%(lun)d \ ---backing-store=%(path)s -tgtadm --op delete --lld=iscsi --mode=logicalunit --tid=%(tid)s --lun=%(lun)d -tgtadm --op delete --lld=iscsi --mode=target --tid=%(tid)s -""" + self.script_template = "\n".join([ + "tgtadm --op new --lld=iscsi --mode=target --tid=%(tid)s " + "--targetname=%(target_name)s", + "tgtadm --op bind --lld=iscsi --mode=target --initiator-address=ALL " + "--tid=%(tid)s", + "tgtadm --op show --lld=iscsi --mode=target --tid=%(tid)s", + "tgtadm --op new --lld=iscsi --mode=logicalunit --tid=%(tid)s " + "--lun=%(lun)d --backing-store=%(path)s", + "tgtadm --op delete --lld=iscsi --mode=logicalunit --tid=%(tid)s " + "--lun=%(lun)d", + "tgtadm --op delete --lld=iscsi --mode=target --tid=%(tid)s"]) def get_script_params(self): params = super(TgtAdmTestCase, self).get_script_params() @@ -107,10 +107,10 @@ class IetAdmTestCase(test.TestCase, TargetAdminTestCase): super(IetAdmTestCase, self).setUp() TargetAdminTestCase.setUp(self) self.flags(iscsi_helper='ietadm') - self.script_template = """ -ietadm --op new --tid=%(tid)s --params Name=%(target_name)s -ietadm --op show --tid=%(tid)s -ietadm --op new --tid=%(tid)s --lun=%(lun)d --params Path=%(path)s,Type=fileio -ietadm --op delete --tid=%(tid)s --lun=%(lun)d -ietadm --op delete --tid=%(tid)s -""" + self.script_template = "\n".join([ + "ietadm --op new --tid=%(tid)s --params Name=%(target_name)s", + "ietadm --op show --tid=%(tid)s", + "ietadm --op new --tid=%(tid)s --lun=%(lun)d " + "--params Path=%(path)s,Type=fileio", + "ietadm --op delete --tid=%(tid)s --lun=%(lun)d", + "ietadm --op delete --tid=%(tid)s"]) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 2eede7ed..3c5ae475 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -906,10 +906,11 @@ class LibvirtConnTestCase(test.TestCase): # Preparing mocks vdmock = self.mox.CreateMock(libvirt.virDomain) self.mox.StubOutWithMock(vdmock, "migrateToURI") + _bandwidth = FLAGS.live_migration_bandwidth vdmock.migrateToURI(FLAGS.live_migration_uri % 'dest', mox.IgnoreArg(), - None, FLAGS.live_migration_bandwidth).\ - AndRaise(libvirt.libvirtError('ERR')) + None, + _bandwidth).AndRaise(libvirt.libvirtError('ERR')) def fake_lookup(instance_name): if instance_name == instance_ref.name: @@ -1025,8 +1026,8 @@ class LibvirtConnTestCase(test.TestCase): os.path.getsize('/test/disk').AndReturn((10737418240)) self.mox.StubOutWithMock(utils, "execute") - utils.execute('qemu-img', 'info', '/test/disk.local').\ - AndReturn((ret, '')) + utils.execute('qemu-img', 'info', + '/test/disk.local').AndReturn((ret, '')) os.path.getsize('/test/disk.local').AndReturn((21474836480)) @@ -1185,10 +1186,11 @@ class LibvirtConnTestCase(test.TestCase): class HostStateTestCase(test.TestCase): - cpu_info = '{"vendor": "Intel", "model": "pentium", "arch": "i686", '\ - '"features": ["ssse3", "monitor", "pni", "sse2", "sse", "fxsr", '\ - '"clflush", "pse36", "pat", "cmov", "mca", "pge", "mtrr", "sep", '\ - '"apic"], "topology": {"cores": "1", "threads": "1", "sockets": "1"}}' + cpu_info = ('{"vendor": "Intel", "model": "pentium", "arch": "i686", ' + '"features": ["ssse3", "monitor", "pni", "sse2", "sse", ' + '"fxsr", "clflush", "pse36", "pat", "cmov", "mca", "pge", ' + '"mtrr", "sep", "apic"], ' + '"topology": {"cores": "1", "threads": "1", "sockets": "1"}}') class FakeConnection(object): """Fake connection object""" @@ -1232,13 +1234,13 @@ class HostStateTestCase(test.TestCase): stats = hs._stats self.assertEquals(stats["vcpus"], 1) self.assertEquals(stats["vcpus_used"], 0) - self.assertEquals(stats["cpu_info"], \ - {"vendor": "Intel", "model": "pentium", "arch": "i686", - "features": ["ssse3", "monitor", "pni", "sse2", "sse", "fxsr", - "clflush", "pse36", "pat", "cmov", "mca", "pge", - "mtrr", "sep", "apic"], - "topology": {"cores": "1", "threads": "1", "sockets": "1"} - }) + self.assertEquals(stats["cpu_info"], + {"vendor": "Intel", "model": "pentium", "arch": "i686", + "features": ["ssse3", "monitor", "pni", "sse2", "sse", + "fxsr", "clflush", "pse36", "pat", "cmov", + "mca", "pge", "mtrr", "sep", "apic"], + "topology": {"cores": "1", "threads": "1", "sockets": "1"} + }) self.assertEquals(stats["disk_total"], 100) self.assertEquals(stats["disk_used"], 20) self.assertEquals(stats["disk_available"], 80) @@ -1523,10 +1525,10 @@ class IptablesFirewallTestCase(test.TestCase): admin_ctxt = context.get_admin_context() fakefilter = NWFilterFakes() - self.fw.nwfilter._conn.nwfilterDefineXML =\ - fakefilter.filterDefineXMLMock - self.fw.nwfilter._conn.nwfilterLookupByName =\ - fakefilter.nwfilterLookupByName + _xml_mock = fakefilter.filterDefineXMLMock + self.fw.nwfilter._conn.nwfilterDefineXML = _xml_mock + _lookup_name = fakefilter.nwfilterLookupByName + self.fw.nwfilter._conn.nwfilterLookupByName = _lookup_name instance_ref = self._create_instance_ref() network_info = _fake_network_info(self.stubs, 1) diff --git a/nova/tests/test_linux_net.py b/nova/tests/test_linux_net.py index 0eb9cdff..1c57220d 100644 --- a/nova/tests/test_linux_net.py +++ b/nova/tests/test_linux_net.py @@ -206,21 +206,19 @@ class LinuxNetworkTestCase(test.TestCase): self.mox.StubOutWithMock(self.driver, 'ensure_path') self.mox.StubOutWithMock(os, 'chmod') - db.network_get_associated_fixed_ips(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([fixed_ips[0], - fixed_ips[3]]) + db.network_get_associated_fixed_ips( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([fixed_ips[0], fixed_ips[3]]) - db.network_get_associated_fixed_ips(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([fixed_ips[0], - fixed_ips[3]]) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([vifs[0], vifs[1]]) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([vifs[2], vifs[3]]) + db.network_get_associated_fixed_ips( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([fixed_ips[0], fixed_ips[3]]) + db.virtual_interface_get_by_instance( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([vifs[0], vifs[1]]) + db.virtual_interface_get_by_instance( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([vifs[2], vifs[3]]) self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg()) self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg()) self.driver.ensure_path(mox.IgnoreArg()) @@ -254,21 +252,19 @@ class LinuxNetworkTestCase(test.TestCase): self.mox.StubOutWithMock(self.driver, 'ensure_path') self.mox.StubOutWithMock(os, 'chmod') - db.network_get_associated_fixed_ips(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([fixed_ips[1], - fixed_ips[2]]) + db.network_get_associated_fixed_ips( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([fixed_ips[1], fixed_ips[2]]) - db.network_get_associated_fixed_ips(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([fixed_ips[1], - fixed_ips[2]]) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([vifs[0], vifs[1]]) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([vifs[2], vifs[3]]) + db.network_get_associated_fixed_ips( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([fixed_ips[1], fixed_ips[2]]) + db.virtual_interface_get_by_instance( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([vifs[0], vifs[1]]) + db.virtual_interface_get_by_instance( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([vifs[2], vifs[3]]) self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg()) self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg()) self.driver.ensure_path(mox.IgnoreArg()) @@ -298,17 +294,15 @@ class LinuxNetworkTestCase(test.TestCase): self.stubs.Set(db, 'instance_get', get_instance) self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') - db.network_get_associated_fixed_ips(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([fixed_ips[0], - fixed_ips[3]]) + db.network_get_associated_fixed_ips( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([fixed_ips[0], fixed_ips[3]]) self.mox.ReplayAll() - expected = \ - "DE:AD:BE:EF:00:00,fake_instance00.novalocal,"\ - "192.168.0.100,net:NW-i00000000-0\n"\ - "DE:AD:BE:EF:00:03,fake_instance01.novalocal,"\ - "192.168.1.101,net:NW-i00000001-0" + expected = ("DE:AD:BE:EF:00:00,fake_instance00.novalocal," + "192.168.0.100,net:NW-i00000000-0\n" + "DE:AD:BE:EF:00:03,fake_instance01.novalocal," + "192.168.1.101,net:NW-i00000001-0") actual_hosts = self.driver.get_dhcp_hosts(self.context, networks[1]) self.assertEquals(actual_hosts, expected) @@ -326,17 +320,15 @@ class LinuxNetworkTestCase(test.TestCase): self.stubs.Set(db, 'instance_get', get_instance) self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') - db.network_get_associated_fixed_ips(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([fixed_ips[1], - fixed_ips[2]]) + db.network_get_associated_fixed_ips( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([fixed_ips[1], fixed_ips[2]]) self.mox.ReplayAll() - expected = \ - "DE:AD:BE:EF:00:01,fake_instance00.novalocal,"\ - "192.168.1.100,net:NW-i00000000-1\n"\ - "DE:AD:BE:EF:00:02,fake_instance01.novalocal,"\ - "192.168.0.101,net:NW-i00000001-1" + expected = ("DE:AD:BE:EF:00:01,fake_instance00.novalocal," + "192.168.1.100,net:NW-i00000000-1\n" + "DE:AD:BE:EF:00:02,fake_instance01.novalocal," + "192.168.0.101,net:NW-i00000001-1") actual_hosts = self.driver.get_dhcp_hosts(self.context, networks[0]) self.assertEquals(actual_hosts, expected) @@ -349,21 +341,16 @@ class LinuxNetworkTestCase(test.TestCase): self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance') - db.network_get_associated_fixed_ips(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([fixed_ips[0], - fixed_ips[3], - fixed_ips[4]]) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([vifs[0], - vifs[1], - vifs[4]]) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([vifs[2], - vifs[3], - vifs[5]]) + db.network_get_associated_fixed_ips( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([fixed_ips[0], fixed_ips[3], + fixed_ips[4]]) + db.virtual_interface_get_by_instance( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([vifs[0], vifs[1], vifs[4]]) + db.virtual_interface_get_by_instance( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([vifs[2], vifs[3], vifs[5]]) self.mox.ReplayAll() expected_opts = 'NW-i00000001-0,3' @@ -380,21 +367,16 @@ class LinuxNetworkTestCase(test.TestCase): self.mox.StubOutWithMock(db, 'network_get_associated_fixed_ips') self.mox.StubOutWithMock(db, 'virtual_interface_get_by_instance') - db.network_get_associated_fixed_ips(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([fixed_ips[1], - fixed_ips[2], - fixed_ips[5]]) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([vifs[0], - vifs[1], - vifs[4]]) - db.virtual_interface_get_by_instance(mox.IgnoreArg(), - mox.IgnoreArg())\ - .AndReturn([vifs[2], - vifs[3], - vifs[5]]) + db.network_get_associated_fixed_ips( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([fixed_ips[1], fixed_ips[2], + fixed_ips[5]]) + db.virtual_interface_get_by_instance( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([vifs[0], vifs[1], vifs[4]]) + db.virtual_interface_get_by_instance( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([vifs[2], vifs[3], vifs[5]]) self.mox.ReplayAll() expected_opts = "NW-i00000000-1,3" @@ -498,8 +480,8 @@ class LinuxNetworkTestCase(test.TestCase): self._test_initialize_gateway(existing, expected) def test_initialize_gateway_resets_route(self): - routes = "0.0.0.0 192.68.0.1 0.0.0.0 " \ - "UG 100 0 0 eth0" + routes = ("0.0.0.0 192.68.0.1 0.0.0.0 " + "UG 100 0 0 eth0") existing = ("2: eth0: " " mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000\n" " link/ether de:ad:be:ef:be:ef brd ff:ff:ff:ff:ff:ff\n" diff --git a/nova/tests/test_log.py b/nova/tests/test_log.py index 122351ff..30839594 100644 --- a/nova/tests/test_log.py +++ b/nova/tests/test_log.py @@ -80,8 +80,9 @@ class LogHandlerTestCase(test.TestCase): class NovaFormatterTestCase(test.TestCase): def setUp(self): super(NovaFormatterTestCase, self).setUp() - self.flags(logging_context_format_string="HAS CONTEXT "\ - "[%(request_id)s]: %(message)s", + self.flags(logging_context_format_string="HAS CONTEXT " + "[%(request_id)s]: " + "%(message)s", logging_default_format_string="NOCTXT: %(message)s", logging_debug_format_suffix="--DBG") self.log = log.logging.root diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 695d90ba..832aaca9 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -1171,9 +1171,9 @@ class CommonNetworkTestCase(test.TestCase): manager = fake_network.FakeNetworkManager() fake_context = context.RequestContext('user', 'project') self.mox.StubOutWithMock(manager.db, 'network_get_all_by_uuids') - manager.db.network_get_all_by_uuids(mox.IgnoreArg(), - mox.IgnoreArg()).\ - AndReturn(networks) + manager.db.network_get_all_by_uuids( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn(networks) self.mox.ReplayAll() uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' network = manager.get_network(fake_context, uuid) @@ -1184,8 +1184,7 @@ class CommonNetworkTestCase(test.TestCase): fake_context = context.RequestContext('user', 'project') self.mox.StubOutWithMock(manager.db, 'network_get_all_by_uuids') manager.db.network_get_all_by_uuids(mox.IgnoreArg(), - mox.IgnoreArg()).\ - AndReturn([]) + mox.IgnoreArg()).AndReturn([]) self.mox.ReplayAll() uuid = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee' self.assertRaises(exception.NetworkNotFound, @@ -1195,8 +1194,7 @@ class CommonNetworkTestCase(test.TestCase): manager = fake_network.FakeNetworkManager() fake_context = context.RequestContext('user', 'project') self.mox.StubOutWithMock(manager.db, 'network_get_all') - manager.db.network_get_all(mox.IgnoreArg()).\ - AndReturn(networks) + manager.db.network_get_all(mox.IgnoreArg()).AndReturn(networks) self.mox.ReplayAll() output = manager.get_all_networks(fake_context) self.assertEqual(len(networks), 2) @@ -1209,9 +1207,9 @@ class CommonNetworkTestCase(test.TestCase): manager = fake_network.FakeNetworkManager() fake_context = context.RequestContext('user', 'project') self.mox.StubOutWithMock(manager.db, 'network_get_all_by_uuids') - manager.db.network_get_all_by_uuids(mox.IgnoreArg(), - mox.IgnoreArg()).\ - AndReturn(networks) + manager.db.network_get_all_by_uuids( + mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn(networks) self.mox.ReplayAll() uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' manager.disassociate_network(fake_context, uuid) @@ -1221,8 +1219,7 @@ class CommonNetworkTestCase(test.TestCase): fake_context = context.RequestContext('user', 'project') self.mox.StubOutWithMock(manager.db, 'network_get_all_by_uuids') manager.db.network_get_all_by_uuids(mox.IgnoreArg(), - mox.IgnoreArg()).\ - AndReturn([]) + mox.IgnoreArg()).AndReturn([]) self.mox.ReplayAll() uuid = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee' self.assertRaises(exception.NetworkNotFound, diff --git a/nova/tests/test_quantum.py b/nova/tests/test_quantum.py index 7a2dc07d..4042b35d 100644 --- a/nova/tests/test_quantum.py +++ b/nova/tests/test_quantum.py @@ -465,8 +465,8 @@ class QuantumNovaPortSecurityTestCase(QuantumNovaTestCase): self.assertTrue(pairs[0]['mac_address'] == fake_mac) self.net_man.q_conn.create_and_attach_port = oldfunc return oldfunc(tenant_id, net_id, interface_id, **kwargs) - self.net_man.q_conn.create_and_attach_port = \ - _instrumented_create_and_attach_port + _port_attach = _instrumented_create_and_attach_port + self.net_man.q_conn.create_and_attach_port = _port_attach nw_info = self.net_man.allocate_for_instance(ctx, instance_id=instance_ref['id'], host="", rxtx_factor=3, @@ -500,8 +500,8 @@ class QuantumNovaPortSecurityTestCase(QuantumNovaTestCase): self.assertTrue(len(pairs) == 0) self.net_man.q_conn.create_and_attach_port = oldfunc return oldfunc(tenant_id, net_id, interface_id, **kwargs) - self.net_man.q_conn.create_and_attach_port = \ - _instrumented_create_and_attach_port + _port_attach = _instrumented_create_and_attach_port + self.net_man.q_conn.create_and_attach_port = _port_attach nw_info = self.net_man.allocate_for_instance(ctx, instance_id=instance_ref['id'], host="", rxtx_factor=3, diff --git a/nova/tests/test_volume_types.py b/nova/tests/test_volume_types.py index b0663d1b..809ab129 100644 --- a/nova/tests/test_volume_types.py +++ b/nova/tests/test_volume_types.py @@ -78,8 +78,7 @@ class VolumeTypeTestCase(test.TestCase): def test_get_all_volume_types(self): """Ensures that all volume types can be retrieved""" session = get_session() - total_volume_types = session.query(models.VolumeTypes).\ - count() + total_volume_types = session.query(models.VolumeTypes).count() vol_types = volume_types.get_all_types(self.ctxt) self.assertEqual(total_volume_types, len(vol_types)) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 2b1f99f7..12792e54 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -513,8 +513,8 @@ class XenAPIVMTestCase(test.TestCase): # Change the default host_call_plugin to one that'll return # a swap disk orig_func = stubs.FakeSessionForVMTests.host_call_plugin - stubs.FakeSessionForVMTests.host_call_plugin = \ - stubs.FakeSessionForVMTests.host_call_plugin_swap + _host_call_plugin = stubs.FakeSessionForVMTests.host_call_plugin_swap + stubs.FakeSessionForVMTests.host_call_plugin = _host_call_plugin # Stubbing out firewall driver as previous stub sets a particular # stub for async plugin calls stubs.stubout_firewall_driver(self.stubs, self.conn) @@ -954,8 +954,8 @@ class XenAPIMigrateInstance(test.TestCase): self.assertEqual(self.fake_vm_start_called, True) def test_finish_migrate_no_local_storage(self): - tiny_type_id = \ - instance_types.get_instance_type_by_name('m1.tiny')['id'] + tiny_type = instance_types.get_instance_type_by_name('m1.tiny') + tiny_type_id = tiny_type['id'] self.instance_values.update({'instance_type_id': tiny_type_id, 'root_gb': 0}) instance = db.instance_create(self.context, self.instance_values) @@ -1550,10 +1550,10 @@ class XenAPIDom0IptablesFirewallTestCase(test.TestCase): ipv6_addr_per_network = 1 networks_count = 5 instance_ref = self._create_instance_ref() - network_info = fake_network.\ - fake_get_instance_nw_info(self.stubs, - networks_count, - ipv4_addr_per_network) + _get_instance_nw_info = fake_network.fake_get_instance_nw_info + network_info = _get_instance_nw_info(self.stubs, + networks_count, + ipv4_addr_per_network) ipv4_len = len(self.fw.iptables.ipv4['filter'].rules) ipv6_len = len(self.fw.iptables.ipv6['filter'].rules) inst_ipv4, inst_ipv6 = self.fw.instance_rules(instance_ref, @@ -1681,8 +1681,8 @@ class XenAPISRSelectionTestCase(test.TestCase): helper = vm_utils.VMHelper helper.XenAPI = session.get_imported_xenapi() host_ref = xenapi_fake.get_all('host')[0] - local_sr = xenapi_fake.\ - create_sr(name_label='Fake Storage', + local_sr = xenapi_fake.create_sr( + name_label='Fake Storage', type='lvm', other_config={'i18n-original-value-name_label': 'Local storage', @@ -1699,11 +1699,10 @@ class XenAPISRSelectionTestCase(test.TestCase): helper = vm_utils.VMHelper helper.XenAPI = session.get_imported_xenapi() host_ref = xenapi_fake.get_all('host')[0] - local_sr = xenapi_fake.\ - create_sr(name_label='Fake Storage', - type='lvm', - other_config={'my_fake_sr': 'true'}, - host_ref=host_ref) + local_sr = xenapi_fake.create_sr(name_label='Fake Storage', + type='lvm', + other_config={'my_fake_sr': 'true'}, + host_ref=host_ref) expected = helper.safe_find_sr(session) self.assertEqual(local_sr, expected) diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 27e2acd9..df444d51 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -160,14 +160,14 @@ def _make_fake_vdi(): class FakeSessionForVMTests(fake.SessionBase): """ 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"\ - "*filter\n"\ - ":INPUT ACCEPT [0:0]\n"\ - ":FORWARD ACCEPT [0:0]\n"\ - ":OUTPUT ACCEPT [0:0]\n"\ - "COMMIT\n"\ - "# Completed on Sun Nov 6 22:49:02 2011\n" + _fake_iptables_save_output = ("# Generated by iptables-save v1.4.10 on " + "Sun Nov 6 22:49:02 2011\n" + "*filter\n" + ":INPUT ACCEPT [0:0]\n" + ":FORWARD ACCEPT [0:0]\n" + ":OUTPUT ACCEPT [0:0]\n" + "COMMIT\n" + "# Completed on Sun Nov 6 22:49:02 2011\n") def __init__(self, uri): super(FakeSessionForVMTests, self).__init__(uri)