Merge "Python 3: replace long with int"

This commit is contained in:
Jenkins 2015-05-19 07:20:36 +00:00 committed by Gerrit Code Review
commit b48528a82d
15 changed files with 160 additions and 159 deletions

View File

@ -41,7 +41,7 @@ class HyperVInspector(virt_inspector.Inspector):
cpu_percent_used = (cpu_clock_used /
float(host_cpu_clock * cpu_count))
# Nanoseconds
cpu_time = (long(uptime * cpu_percent_used) * units.k)
cpu_time = (int(uptime * cpu_percent_used) * units.k)
return virt_inspector.CPUStats(number=cpu_count, time=cpu_time)

View File

@ -92,11 +92,11 @@ class UtilsV2(object):
cpu_used = 0
if cpu_metric_aggr:
cpu_used = long(cpu_metric_aggr[0].MetricValue)
cpu_used = int(cpu_metric_aggr[0].MetricValue)
return (cpu_used,
int(cpu_sd.VirtualQuantity),
long(vm.OnTimeInMilliseconds))
int(vm.OnTimeInMilliseconds))
def get_memory_metrics(self, vm_name):
vm = self._lookup_vm(vm_name)
@ -104,7 +104,7 @@ class UtilsV2(object):
metric_memory = self._get_metrics(vm, memory_def)
memory_usage = 0
if metric_memory:
memory_usage = long(metric_memory[0].MetricValue)
memory_usage = int(metric_memory[0].MetricValue)
return memory_usage
def get_vnic_metrics(self, vm_name):
@ -186,7 +186,7 @@ class UtilsV2(object):
def _sum_metric_values(metrics):
tot_metric_val = 0
for metric in metrics:
tot_metric_val += long(metric.MetricValue)
tot_metric_val += int(metric.MetricValue)
return tot_metric_val
def _sum_metric_values_by_defs(self, element_metrics, metric_defs):

View File

@ -125,7 +125,7 @@ class XenapiInspector(virt_inspector.Inspector):
metrics_rec = self._call_xenapi("VM_metrics.get_record",
metrics_ref)
# Stat provided from XenServer is in B, converting it to MB.
memory = long(metrics_rec['memory_actual']) / units.Mi
memory = int(metrics_rec['memory_actual']) / units.Mi
return virt_inspector.MemoryUsageStats(usage=memory)
def inspect_vnic_rates(self, instance, duration=None):

View File

@ -665,7 +665,7 @@ class Connection(base.Connection):
@staticmethod
def _stats_result_aggregates(result, aggregate):
stats_args = {}
if isinstance(result.count, (int, long)):
if isinstance(result.count, six.integer_types):
stats_args['count'] = result.count
for attr in ['min', 'max', 'sum', 'avg']:
if hasattr(result, attr):

View File

@ -60,7 +60,7 @@ def upgrade(migrate_engine):
ins = meta_tables['metadata_text'].insert()
elif isinstance(v, bool):
ins = meta_tables['metadata_bool'].insert()
elif isinstance(v, (int, long)):
elif isinstance(v, six.integer_types):
ins = meta_tables['metadata_int'].insert()
elif isinstance(v, float):
ins = meta_tables['metadata_float'].insert()

View File

@ -31,8 +31,9 @@ META_TYPE_MAP = {bool: models.MetaBool,
six.text_type: models.MetaText,
types.NoneType: models.MetaText,
int: models.MetaBigInt,
long: models.MetaBigInt,
float: models.MetaFloat}
if six.PY2:
META_TYPE_MAP[long] = models.MetaBigInt
class QueryTransformer(object):

View File

@ -36,16 +36,16 @@ METRICS_UPDATE = {
'name': 'cpu.frequency', 'value': 1600,
'source': 'libvirt.LibvirtDriver'},
{'timestamp': u'2013-07-29T06:51:34.472416',
'name': 'cpu.user.time', 'value': 17421440000000L,
'name': 'cpu.user.time', 'value': 17421440000000,
'source': 'libvirt.LibvirtDriver'},
{'timestamp': u'2013-07-29T06:51:34.472416',
'name': 'cpu.kernel.time', 'value': 7852600000000L,
'name': 'cpu.kernel.time', 'value': 7852600000000,
'source': 'libvirt.LibvirtDriver'},
{'timestamp': u'2013-07-29T06:51:34.472416',
'name': 'cpu.idle.time', 'value': 1307374400000000L,
'name': 'cpu.idle.time', 'value': 1307374400000000,
'source': 'libvirt.LibvirtDriver'},
{'timestamp': u'2013-07-29T06:51:34.472416',
'name': 'cpu.iowait.time', 'value': 11697470000000L,
'name': 'cpu.iowait.time', 'value': 11697470000000,
'source': 'libvirt.LibvirtDriver'},
{'timestamp': u'2013-07-29T06:51:34.472416',
'name': 'cpu.user.percent', 'value': 0.012959045637294348,
@ -114,22 +114,22 @@ class TestMetricsNotifications(base.BaseTestCase):
def test_compute_cpu_user_time(self):
c = self._process_notification(cpu.CpuUserTime(None))
self.assertEqual('compute.node.cpu.user.time', c.name)
self.assertEqual(17421440000000L, c.volume)
self.assertEqual(17421440000000, c.volume)
def test_compute_cpu_kernel_time(self):
c = self._process_notification(cpu.CpuKernelTime(None))
self.assertEqual('compute.node.cpu.kernel.time', c.name)
self.assertEqual(7852600000000L, c.volume)
self.assertEqual(7852600000000, c.volume)
def test_compute_cpu_idle_time(self):
c = self._process_notification(cpu.CpuIdleTime(None))
self.assertEqual('compute.node.cpu.idle.time', c.name)
self.assertEqual(1307374400000000L, c.volume)
self.assertEqual(1307374400000000, c.volume)
def test_compute_cpu_iowait_time(self):
c = self._process_notification(cpu.CpuIowaitTime(None))
self.assertEqual('compute.node.cpu.iowait.time', c.name)
self.assertEqual(11697470000000L, c.volume)
self.assertEqual(11697470000000, c.volume)
def test_compute_cpu_kernel_percent(self):
c = self._process_notification(cpu.CpuKernelPercent(None))

View File

@ -113,13 +113,13 @@ class TestDiskPollsters(TestBaseDiskIO):
DISKS = [
(virt_inspector.Disk(device='vda1'),
virt_inspector.DiskStats(read_bytes=1L, read_requests=2L,
write_bytes=3L, write_requests=4L,
errors=-1L)),
virt_inspector.DiskStats(read_bytes=1, read_requests=2,
write_bytes=3, write_requests=4,
errors=-1)),
(virt_inspector.Disk(device='vda2'),
virt_inspector.DiskStats(read_bytes=2L, read_requests=3L,
write_bytes=5L, write_requests=7L,
errors=-1L)),
virt_inspector.DiskStats(read_bytes=2, read_requests=3,
write_bytes=5, write_requests=7,
errors=-1)),
]
CACHE_KEY = "CACHE_KEY_DISK"
@ -129,54 +129,54 @@ class TestDiskPollsters(TestBaseDiskIO):
def test_disk_read_requests(self):
self._check_aggregate_samples(disk.ReadRequestsPollster,
'disk.read.requests', 5L,
'disk.read.requests', 5,
expected_device=['vda1', 'vda2'])
def test_disk_read_bytes(self):
self._check_aggregate_samples(disk.ReadBytesPollster,
'disk.read.bytes', 3L,
'disk.read.bytes', 3,
expected_device=['vda1', 'vda2'])
def test_disk_write_requests(self):
self._check_aggregate_samples(disk.WriteRequestsPollster,
'disk.write.requests', 11L,
'disk.write.requests', 11,
expected_device=['vda1', 'vda2'])
def test_disk_write_bytes(self):
self._check_aggregate_samples(disk.WriteBytesPollster,
'disk.write.bytes', 8L,
'disk.write.bytes', 8,
expected_device=['vda1', 'vda2'])
def test_per_disk_read_requests(self):
self._check_per_device_samples(disk.PerDeviceReadRequestsPollster,
'disk.device.read.requests', 2L,
'disk.device.read.requests', 2,
'vda1')
self._check_per_device_samples(disk.PerDeviceReadRequestsPollster,
'disk.device.read.requests', 3L,
'disk.device.read.requests', 3,
'vda2')
def test_per_disk_write_requests(self):
self._check_per_device_samples(disk.PerDeviceWriteRequestsPollster,
'disk.device.write.requests', 4L,
'disk.device.write.requests', 4,
'vda1')
self._check_per_device_samples(disk.PerDeviceWriteRequestsPollster,
'disk.device.write.requests', 7L,
'disk.device.write.requests', 7,
'vda2')
def test_per_disk_read_bytes(self):
self._check_per_device_samples(disk.PerDeviceReadBytesPollster,
'disk.device.read.bytes', 1L,
'disk.device.read.bytes', 1,
'vda1')
self._check_per_device_samples(disk.PerDeviceReadBytesPollster,
'disk.device.read.bytes', 2L,
'disk.device.read.bytes', 2,
'vda2')
def test_per_disk_write_bytes(self):
self._check_per_device_samples(disk.PerDeviceWriteBytesPollster,
'disk.device.write.bytes', 3L,
'disk.device.write.bytes', 3,
'vda1')
self._check_per_device_samples(disk.PerDeviceWriteBytesPollster,
'disk.device.write.bytes', 5L,
'disk.device.write.bytes', 5,
'vda2')
@ -198,54 +198,54 @@ class TestDiskRatePollsters(TestBaseDiskIO):
def test_disk_read_bytes_rate(self):
self._check_aggregate_samples(disk.ReadBytesRatePollster,
'disk.read.bytes.rate', 3072L,
'disk.read.bytes.rate', 3072,
expected_device=['disk1', 'disk2'])
def test_disk_read_requests_rate(self):
self._check_aggregate_samples(disk.ReadRequestsRatePollster,
'disk.read.requests.rate', 700L,
'disk.read.requests.rate', 700,
expected_device=['disk1', 'disk2'])
def test_disk_write_bytes_rate(self):
self._check_aggregate_samples(disk.WriteBytesRatePollster,
'disk.write.bytes.rate', 11264L,
'disk.write.bytes.rate', 11264,
expected_device=['disk1', 'disk2'])
def test_disk_write_requests_rate(self):
self._check_aggregate_samples(disk.WriteRequestsRatePollster,
'disk.write.requests.rate', 1500L,
'disk.write.requests.rate', 1500,
expected_device=['disk1', 'disk2'])
def test_per_disk_read_bytes_rate(self):
self._check_per_device_samples(disk.PerDeviceReadBytesRatePollster,
'disk.device.read.bytes.rate',
1024L, 'disk1')
1024, 'disk1')
self._check_per_device_samples(disk.PerDeviceReadBytesRatePollster,
'disk.device.read.bytes.rate',
2048L, 'disk2')
2048, 'disk2')
def test_per_disk_read_requests_rate(self):
self._check_per_device_samples(disk.PerDeviceReadRequestsRatePollster,
'disk.device.read.requests.rate',
300L, 'disk1')
300, 'disk1')
self._check_per_device_samples(disk.PerDeviceReadRequestsRatePollster,
'disk.device.read.requests.rate',
400L, 'disk2')
400, 'disk2')
def test_per_disk_write_bytes_rate(self):
self._check_per_device_samples(disk.PerDeviceWriteBytesRatePollster,
'disk.device.write.bytes.rate',
5120L, 'disk1')
5120, 'disk1')
self._check_per_device_samples(disk.PerDeviceWriteBytesRatePollster,
'disk.device.write.bytes.rate', 6144L,
'disk.device.write.bytes.rate', 6144,
'disk2')
def test_per_disk_write_requests_rate(self):
self._check_per_device_samples(disk.PerDeviceWriteRequestsRatePollster,
'disk.device.write.requests.rate', 700L,
'disk.device.write.requests.rate', 700,
'disk1')
self._check_per_device_samples(disk.PerDeviceWriteRequestsRatePollster,
'disk.device.write.requests.rate', 800L,
'disk.device.write.requests.rate', 800,
'disk2')
@ -296,23 +296,23 @@ class TestDiskIOPSPollsters(TestBaseDiskIO):
def test_disk_iops(self):
self._check_aggregate_samples(disk.DiskIOPSPollster,
'disk.iops', 30L)
'disk.iops', 30)
def test_per_device_iops(self):
self._check_per_device_samples(disk.PerDeviceDiskIOPSPollster,
'disk.device.iops', 10L, 'disk1')
'disk.device.iops', 10, 'disk1')
self._check_per_device_samples(disk.PerDeviceDiskIOPSPollster,
'disk.device.iops', 20L, 'disk2')
'disk.device.iops', 20, 'disk2')
class TestDiskInfoPollsters(TestBaseDiskIO):
DISKS = [
(virt_inspector.Disk(device='vda1'),
virt_inspector.DiskInfo(capacity=3L, allocation=2L, physical=1L)),
virt_inspector.DiskInfo(capacity=3, allocation=2, physical=1)),
(virt_inspector.Disk(device='vda2'),
virt_inspector.DiskInfo(capacity=4L, allocation=3L, physical=2L)),
virt_inspector.DiskInfo(capacity=4, allocation=3, physical=2)),
]
TYPE = 'gauge'
CACHE_KEY = "CACHE_KEY_DISK_INFO"
@ -323,39 +323,39 @@ class TestDiskInfoPollsters(TestBaseDiskIO):
def test_disk_capacity(self):
self._check_aggregate_samples(disk.CapacityPollster,
'disk.capacity', 7L,
'disk.capacity', 7,
expected_device=['vda1', 'vda2'])
def test_disk_allocation(self):
self._check_aggregate_samples(disk.AllocationPollster,
'disk.allocation', 5L,
'disk.allocation', 5,
expected_device=['vda1', 'vda2'])
def test_disk_physical(self):
self._check_aggregate_samples(disk.PhysicalPollster,
'disk.usage', 3L,
'disk.usage', 3,
expected_device=['vda1', 'vda2'])
def test_per_disk_capacity(self):
self._check_per_device_samples(disk.PerDeviceCapacityPollster,
'disk.device.capacity', 3L,
'disk.device.capacity', 3,
'vda1')
self._check_per_device_samples(disk.PerDeviceCapacityPollster,
'disk.device.capacity', 4L,
'disk.device.capacity', 4,
'vda2')
def test_per_disk_allocation(self):
self._check_per_device_samples(disk.PerDeviceAllocationPollster,
'disk.device.allocation', 2L,
'disk.device.allocation', 2,
'vda1')
self._check_per_device_samples(disk.PerDeviceAllocationPollster,
'disk.device.allocation', 3L,
'disk.device.allocation', 3,
'vda2')
def test_per_disk_physical(self):
self._check_per_device_samples(disk.PerDevicePhysicalPollster,
'disk.device.usage', 1L,
'disk.device.usage', 1,
'vda1')
self._check_per_device_samples(disk.PerDevicePhysicalPollster,
'disk.device.usage', 2L,
'disk.device.usage', 2,
'vda2')

View File

@ -48,8 +48,8 @@ class TestNetPollster(base.TestPollsterBase):
projmask='255.255.255.0',
projnet='proj1',
dhcp_server='10.0.0.1'))
stats0 = virt_inspector.InterfaceStats(rx_bytes=1L, rx_packets=2L,
tx_bytes=3L, tx_packets=4L)
stats0 = virt_inspector.InterfaceStats(rx_bytes=1, rx_packets=2,
tx_bytes=3, tx_packets=4)
self.vnic1 = virt_inspector.Interface(
name='vnet1',
fref='fa163e71ec6f',
@ -58,8 +58,8 @@ class TestNetPollster(base.TestPollsterBase):
projmask='255.255.255.0',
projnet='proj2',
dhcp_server='10.0.0.2'))
stats1 = virt_inspector.InterfaceStats(rx_bytes=5L, rx_packets=6L,
tx_bytes=7L, tx_packets=8L)
stats1 = virt_inspector.InterfaceStats(rx_bytes=5, rx_packets=6,
tx_bytes=7, tx_packets=8)
self.vnic2 = virt_inspector.Interface(
name='vnet2',
fref=None,
@ -68,8 +68,8 @@ class TestNetPollster(base.TestPollsterBase):
projmask='255.255.255.0',
projnet='proj3',
dhcp_server='10.0.0.3'))
stats2 = virt_inspector.InterfaceStats(rx_bytes=9L, rx_packets=10L,
tx_bytes=11L, tx_packets=12L)
stats2 = virt_inspector.InterfaceStats(rx_bytes=9, rx_packets=10,
tx_bytes=11, tx_packets=12)
vnics = [
(self.vnic0, stats0),
@ -134,9 +134,9 @@ class TestNetPollster(base.TestPollsterBase):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_samples(
net.IncomingBytesPollster,
[('10.0.0.2', 1L, self.vnic0.fref),
('192.168.0.3', 5L, self.vnic1.fref),
('192.168.0.4', 9L,
[('10.0.0.2', 1, self.vnic0.fref),
('192.168.0.3', 5, self.vnic1.fref),
('192.168.0.4', 9,
"%s-%s" % (instance_name_id, self.vnic2.name)),
],
)
@ -145,9 +145,9 @@ class TestNetPollster(base.TestPollsterBase):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_samples(
net.OutgoingBytesPollster,
[('10.0.0.2', 3L, self.vnic0.fref),
('192.168.0.3', 7L, self.vnic1.fref),
('192.168.0.4', 11L,
[('10.0.0.2', 3, self.vnic0.fref),
('192.168.0.3', 7, self.vnic1.fref),
('192.168.0.4', 11,
"%s-%s" % (instance_name_id, self.vnic2.name)),
],
)
@ -156,9 +156,9 @@ class TestNetPollster(base.TestPollsterBase):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_samples(
net.IncomingPacketsPollster,
[('10.0.0.2', 2L, self.vnic0.fref),
('192.168.0.3', 6L, self.vnic1.fref),
('192.168.0.4', 10L,
[('10.0.0.2', 2, self.vnic0.fref),
('192.168.0.3', 6, self.vnic1.fref),
('192.168.0.4', 10,
"%s-%s" % (instance_name_id, self.vnic2.name)),
],
)
@ -167,9 +167,9 @@ class TestNetPollster(base.TestPollsterBase):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_samples(
net.OutgoingPacketsPollster,
[('10.0.0.2', 4L, self.vnic0.fref),
('192.168.0.3', 8L, self.vnic1.fref),
('192.168.0.4', 12L,
[('10.0.0.2', 4, self.vnic0.fref),
('192.168.0.3', 8, self.vnic1.fref),
('192.168.0.4', 12,
"%s-%s" % (instance_name_id, self.vnic2.name)),
],
)
@ -204,8 +204,8 @@ class TestNetPollsterCache(base.TestPollsterBase):
projmask='255.255.255.0',
projnet='proj1',
dhcp_server='10.0.0.1'))
stats0 = virt_inspector.InterfaceStats(rx_bytes=1L, rx_packets=2L,
tx_bytes=3L, tx_packets=4L)
stats0 = virt_inspector.InterfaceStats(rx_bytes=1, rx_packets=2,
tx_bytes=3, tx_packets=4)
vnics = [(vnic0, stats0)]
mgr = manager.AgentManager()
@ -243,8 +243,8 @@ class TestNetRatesPollster(base.TestPollsterBase):
projmask='255.255.255.0',
projnet='proj1',
dhcp_server='10.0.0.1'))
stats0 = virt_inspector.InterfaceRateStats(rx_bytes_rate=1L,
tx_bytes_rate=2L)
stats0 = virt_inspector.InterfaceRateStats(rx_bytes_rate=1,
tx_bytes_rate=2)
self.vnic1 = virt_inspector.Interface(
name='vnet1',
fref='fa163e71ec6f',
@ -253,8 +253,8 @@ class TestNetRatesPollster(base.TestPollsterBase):
projmask='255.255.255.0',
projnet='proj2',
dhcp_server='10.0.0.2'))
stats1 = virt_inspector.InterfaceRateStats(rx_bytes_rate=3L,
tx_bytes_rate=4L)
stats1 = virt_inspector.InterfaceRateStats(rx_bytes_rate=3,
tx_bytes_rate=4)
self.vnic2 = virt_inspector.Interface(
name='vnet2',
fref=None,
@ -263,8 +263,8 @@ class TestNetRatesPollster(base.TestPollsterBase):
projmask='255.255.255.0',
projnet='proj3',
dhcp_server='10.0.0.3'))
stats2 = virt_inspector.InterfaceRateStats(rx_bytes_rate=5L,
tx_bytes_rate=6L)
stats2 = virt_inspector.InterfaceRateStats(rx_bytes_rate=5,
tx_bytes_rate=6)
vnics = [
(self.vnic0, stats0),
@ -298,9 +298,9 @@ class TestNetRatesPollster(base.TestPollsterBase):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_samples(
net.IncomingBytesRatePollster,
[('10.0.0.2', 1L, self.vnic0.fref),
('192.168.0.3', 3L, self.vnic1.fref),
('192.168.0.4', 5L,
[('10.0.0.2', 1, self.vnic0.fref),
('192.168.0.3', 3, self.vnic1.fref),
('192.168.0.4', 5,
"%s-%s" % (instance_name_id, self.vnic2.name)),
],
)
@ -309,9 +309,9 @@ class TestNetRatesPollster(base.TestPollsterBase):
instance_name_id = "%s-%s" % (self.instance.name, self.instance.id)
self._check_get_samples(
net.OutgoingBytesRatePollster,
[('10.0.0.2', 2L, self.vnic0.fref),
('192.168.0.3', 4L, self.vnic1.fref),
('192.168.0.4', 6L,
[('10.0.0.2', 2, self.vnic0.fref),
('192.168.0.3', 4, self.vnic1.fref),
('192.168.0.4', 6,
"%s-%s" % (instance_name_id, self.vnic2.name)),
],
)

View File

@ -40,7 +40,7 @@ class TestHyperVInspection(base.BaseTestCase):
fake_cpu_percent_used = (fake_cpu_clock_used /
float(fake_host_cpu_clock * fake_cpu_count))
fake_cpu_time = (long(fake_uptime * fake_cpu_percent_used) *
fake_cpu_time = (int(fake_uptime * fake_cpu_percent_used) *
1000)
self._inspector._utils.get_host_cpu_info.return_value = (

View File

@ -269,7 +269,7 @@ class TestUtilsV2(base.BaseTestCase):
[mock_metric_def])
self.assertEqual(1, len(metric_values))
self.assertEqual(long(fake_metric_value), metric_values[0])
self.assertEqual(int(fake_metric_value), metric_values[0])
def test_get_vm_setting_data(self):
mock_vm_s = mock.MagicMock()

View File

@ -48,11 +48,11 @@ class TestLibvirtInspection(base.BaseTestCase):
'lookupByUUIDString',
return_value=self.domain),
mock.patch.object(self.domain, 'info',
return_value=(0L, 0L, 0L,
2L, 999999L))):
return_value=(0, 0, 0,
2, 999999))):
cpu_info = self.inspector.inspect_cpus(self.instance)
self.assertEqual(2L, cpu_info.number)
self.assertEqual(999999L, cpu_info.time)
self.assertEqual(2, cpu_info.number)
self.assertEqual(999999, cpu_info.time)
def test_inspect_vnics(self):
dom_xml = """
@ -113,9 +113,9 @@ class TestLibvirtInspection(base.BaseTestCase):
"""
interface_stats = {
'vnet0': (1L, 2L, 0L, 0L, 3L, 4L, 0L, 0L),
'vnet1': (5L, 6L, 0L, 0L, 7L, 8L, 0L, 0L),
'vnet2': (9L, 10L, 0L, 0L, 11L, 12L, 0L, 0L),
'vnet0': (1, 2, 0, 0, 3, 4, 0, 0),
'vnet1': (5, 6, 0, 0, 7, 8, 0, 0),
'vnet2': (9, 10, 0, 0, 11, 12, 0, 0),
}
interfaceStats = interface_stats.__getitem__
@ -129,8 +129,8 @@ class TestLibvirtInspection(base.BaseTestCase):
'interfaceStats',
side_effect=interfaceStats),
mock.patch.object(self.domain, 'info',
return_value=(0L, 0L, 0L,
2L, 999999L))):
return_value=(0, 0, 0,
2, 999999))):
interfaces = list(self.inspector.inspect_vnics(self.instance))
self.assertEqual(3, len(interfaces))
@ -142,10 +142,10 @@ class TestLibvirtInspection(base.BaseTestCase):
self.assertEqual('10.0.0.2', vnic0.parameters.get('ip'))
self.assertEqual('10.0.0.0', vnic0.parameters.get('projnet'))
self.assertEqual('10.0.0.1', vnic0.parameters.get('dhcpserver'))
self.assertEqual(1L, info0.rx_bytes)
self.assertEqual(2L, info0.rx_packets)
self.assertEqual(3L, info0.tx_bytes)
self.assertEqual(4L, info0.tx_packets)
self.assertEqual(1, info0.rx_bytes)
self.assertEqual(2, info0.rx_packets)
self.assertEqual(3, info0.tx_bytes)
self.assertEqual(4, info0.tx_packets)
vnic1, info1 = interfaces[1]
self.assertEqual('vnet1', vnic1.name)
@ -155,20 +155,20 @@ class TestLibvirtInspection(base.BaseTestCase):
self.assertEqual('192.168.0.2', vnic1.parameters.get('ip'))
self.assertEqual('192.168.0.0', vnic1.parameters.get('projnet'))
self.assertEqual('192.168.0.1', vnic1.parameters.get('dhcpserver'))
self.assertEqual(5L, info1.rx_bytes)
self.assertEqual(6L, info1.rx_packets)
self.assertEqual(7L, info1.tx_bytes)
self.assertEqual(8L, info1.tx_packets)
self.assertEqual(5, info1.rx_bytes)
self.assertEqual(6, info1.rx_packets)
self.assertEqual(7, info1.tx_bytes)
self.assertEqual(8, info1.tx_packets)
vnic2, info2 = interfaces[2]
self.assertEqual('vnet2', vnic2.name)
self.assertEqual('fa:16:3e:96:33:f0', vnic2.mac)
self.assertIsNone(vnic2.fref)
self.assertEqual(dict(), vnic2.parameters)
self.assertEqual(9L, info2.rx_bytes)
self.assertEqual(10L, info2.rx_packets)
self.assertEqual(11L, info2.tx_bytes)
self.assertEqual(12L, info2.tx_packets)
self.assertEqual(9, info2.rx_bytes)
self.assertEqual(10, info2.rx_packets)
self.assertEqual(11, info2.tx_bytes)
self.assertEqual(12, info2.tx_packets)
def test_inspect_vnics_with_domain_shutoff(self):
connection = self.inspector.connection
@ -176,8 +176,8 @@ class TestLibvirtInspection(base.BaseTestCase):
'lookupByUUIDString',
return_value=self.domain),
mock.patch.object(self.domain, 'info',
return_value=(5L, 0L, 0L,
2L, 999999L))):
return_value=(5, 0, 0,
2, 999999))):
inspect = self.inspector.inspect_vnics
self.assertRaises(virt_inspector.InstanceShutOffException,
list, inspect(self.instance))
@ -204,20 +204,20 @@ class TestLibvirtInspection(base.BaseTestCase):
mock.patch.object(self.domain, 'XMLDesc',
return_value=dom_xml),
mock.patch.object(self.domain, 'blockStats',
return_value=(1L, 2L, 3L,
4L, -1)),
return_value=(1, 2, 3,
4, -1)),
mock.patch.object(self.domain, 'info',
return_value=(0L, 0L, 0L,
2L, 999999L))):
return_value=(0, 0, 0,
2, 999999))):
disks = list(self.inspector.inspect_disks(self.instance))
self.assertEqual(1, len(disks))
disk0, info0 = disks[0]
self.assertEqual('vda', disk0.device)
self.assertEqual(1L, info0.read_requests)
self.assertEqual(2L, info0.read_bytes)
self.assertEqual(3L, info0.write_requests)
self.assertEqual(4L, info0.write_bytes)
self.assertEqual(1, info0.read_requests)
self.assertEqual(2, info0.read_bytes)
self.assertEqual(3, info0.write_requests)
self.assertEqual(4, info0.write_bytes)
def test_inspect_disks_with_domain_shutoff(self):
connection = self.inspector.connection
@ -225,25 +225,25 @@ class TestLibvirtInspection(base.BaseTestCase):
'lookupByUUIDString',
return_value=self.domain),
mock.patch.object(self.domain, 'info',
return_value=(5L, 0L, 0L,
2L, 999999L))):
return_value=(5, 0, 0,
2, 999999))):
inspect = self.inspector.inspect_disks
self.assertRaises(virt_inspector.InstanceShutOffException,
list, inspect(self.instance))
def test_inspect_memory_usage(self):
fake_memory_stats = {'available': 51200L, 'unused': 25600L}
fake_memory_stats = {'available': 51200, 'unused': 25600}
connection = self.inspector.connection
with mock.patch.object(connection, 'lookupByUUIDString',
return_value=self.domain):
with mock.patch.object(self.domain, 'info',
return_value=(0L, 0L, 51200L,
2L, 999999L)):
return_value=(0, 0, 51200,
2, 999999)):
with mock.patch.object(self.domain, 'memoryStats',
return_value=fake_memory_stats):
memory = self.inspector.inspect_memory_usage(
self.instance)
self.assertEqual(25600L / units.Ki, memory.usage)
self.assertEqual(25600 / units.Ki, memory.usage)
def test_inspect_disk_info(self):
dom_xml = """
@ -267,27 +267,27 @@ class TestLibvirtInspection(base.BaseTestCase):
mock.patch.object(self.domain, 'XMLDesc',
return_value=dom_xml),
mock.patch.object(self.domain, 'blockInfo',
return_value=(1L, 2L, 3L,
return_value=(1, 2, 3,
-1)),
mock.patch.object(self.domain, 'info',
return_value=(0L, 0L, 0L,
2L, 999999L))):
return_value=(0, 0, 0,
2, 999999))):
disks = list(self.inspector.inspect_disk_info(self.instance))
self.assertEqual(1, len(disks))
disk0, info0 = disks[0]
self.assertEqual('vda', disk0.device)
self.assertEqual(1L, info0.capacity)
self.assertEqual(2L, info0.allocation)
self.assertEqual(3L, info0.physical)
self.assertEqual(1, info0.capacity)
self.assertEqual(2, info0.allocation)
self.assertEqual(3, info0.physical)
def test_inspect_memory_usage_with_domain_shutoff(self):
connection = self.inspector.connection
with mock.patch.object(connection, 'lookupByUUIDString',
return_value=self.domain):
with mock.patch.object(self.domain, 'info',
return_value=(5L, 0L, 0L,
2L, 999999L)):
return_value=(5, 0, 0,
2, 999999)):
self.assertRaises(virt_inspector.InstanceShutOffException,
self.inspector.inspect_memory_usage,
self.instance)
@ -297,8 +297,8 @@ class TestLibvirtInspection(base.BaseTestCase):
with mock.patch.object(connection, 'lookupByUUIDString',
return_value=self.domain):
with mock.patch.object(self.domain, 'info',
return_value=(0L, 0L, 51200L,
2L, 999999L)):
return_value=(0, 0, 51200,
2, 999999)):
with mock.patch.object(self.domain, 'memoryStats',
return_value={}):
self.assertRaises(virt_inspector.NoDataException,

View File

@ -456,10 +456,10 @@ class TestLBStatsPollster(_BaseTestLBPollster):
@staticmethod
def fake_pool_stats():
return {'stats': {'active_connections': 2L,
'bytes_in': 1L,
'bytes_out': 3L,
'total_connections': 4L
return {'stats': {'active_connections': 2,
'bytes_in': 1,
'bytes_out': 3,
'total_connections': 4
}
}
@ -484,19 +484,19 @@ class TestLBStatsPollster(_BaseTestLBPollster):
def test_lb_total_connections(self):
self._check_get_samples(lbaas.LBTotalConnectionsPollster,
'network.services.lb.total.connections',
4L, 'cumulative')
4, 'cumulative')
def test_lb_active_connections(self):
self._check_get_samples(lbaas.LBActiveConnectionsPollster,
'network.services.lb.active.connections',
2L, 'gauge')
2, 'gauge')
def test_lb_incoming_bytes(self):
self._check_get_samples(lbaas.LBBytesInPollster,
'network.services.lb.incoming.bytes',
1L, 'cumulative')
1, 'cumulative')
def test_lb_outgoing_bytes(self):
self._check_get_samples(lbaas.LBBytesOutPollster,
'network.services.lb.outgoing.bytes',
3L, 'cumulative')
3, 'cumulative')

View File

@ -2763,7 +2763,7 @@ class CounterDataTypeTest(DBTestBase,
meter='dummySmallCounter',
)
results = list(self.conn.get_samples(f))
observed_num = long(results[0].counter_volume)
observed_num = int(results[0].counter_volume)
self.assertEqual(-337203685477580, observed_num)
def test_storage_can_handle_float_values(self):

View File

@ -175,10 +175,10 @@ class TestNeutronClient(base.BaseTestCase):
@staticmethod
def fake_pool_stats(fake_pool):
return {'stats':
[{'active_connections': 1L,
'total_connections': 2L,
'bytes_in': 3L,
'bytes_out': 4L
[{'active_connections': 1,
'total_connections': 2,
'bytes_in': 3,
'bytes_out': 4
}]}
def test_pool_stats(self):
@ -187,7 +187,7 @@ class TestNeutronClient(base.BaseTestCase):
stats = self.nc.pool_stats('fake_pool')['stats']
self.assertEqual(1, len(stats))
self.assertEqual(1L, stats[0]['active_connections'])
self.assertEqual(2L, stats[0]['total_connections'])
self.assertEqual(3L, stats[0]['bytes_in'])
self.assertEqual(4L, stats[0]['bytes_out'])
self.assertEqual(1, stats[0]['active_connections'])
self.assertEqual(2, stats[0]['total_connections'])
self.assertEqual(3, stats[0]['bytes_in'])
self.assertEqual(4, stats[0]['bytes_out'])