Ejemplo n.º 1
0
def fake_diagnostics_obj(**updates):
    diag = objects.Diagnostics()
    cpu_details = updates.pop('cpu_details', [])
    nic_details = updates.pop('nic_details', [])
    disk_details = updates.pop('disk_details', [])
    memory_details = updates.pop('memory_details', {})

    for field in objects.Diagnostics.fields:
        if field in updates:
            setattr(diag, field, updates[field])

    for cpu in cpu_details:
        diag.add_cpu(**cpu)

    for nic in nic_details:
        diag.add_nic(**nic)

    for disk in disk_details:
        diag.add_disk(**disk)

    for k, v in memory_details.items():
        setattr(diag.memory_details, k, v)

    return diag
Ejemplo n.º 2
0
    def test_get_diagnostics(self):
        return_value = objects.Diagnostics(
            config_drive=False,
            state='running',
            driver='libvirt',
            uptime=5,
            hypervisor='hypervisor',
            # hypervisor_os is unset
            cpu_details=[
                objects.CpuDiagnostics(id=0, time=1111, utilisation=11),
                objects.CpuDiagnostics(id=1, time=None, utilisation=22),
                objects.CpuDiagnostics(id=2, time=3333, utilisation=None),
                objects.CpuDiagnostics(id=None, time=4444, utilisation=44)
            ],
            nic_details=[
                objects.NicDiagnostics(
                    mac_address='de:ad:be:ef:00:01',
                    rx_drop=1,
                    rx_errors=2,
                    rx_octets=3,
                    rx_packets=4,
                    rx_rate=5,
                    tx_drop=6,
                    tx_errors=7,
                    tx_octets=8,
                    # tx_packets is unset
                    tx_rate=None)
            ],
            disk_details=[
                objects.DiskDiagnostics(
                    errors_count=1,
                    read_bytes=2,
                    read_requests=3,
                    # write_bytes is unset
                    write_requests=None)
            ],
            num_cpus=4,
            num_disks=1,
            num_nics=1,
            memory_details=objects.MemoryDiagnostics(maximum=8192, used=3072))

        expected = {
            'config_drive':
            False,
            'state':
            'running',
            'driver':
            'libvirt',
            'uptime':
            5,
            'hypervisor':
            'hypervisor',
            'hypervisor_os':
            None,
            'cpu_details': [{
                'id': 0,
                'time': 1111,
                'utilisation': 11
            }, {
                'id': 1,
                'time': None,
                'utilisation': 22
            }, {
                'id': 2,
                'time': 3333,
                'utilisation': None
            }, {
                'id': None,
                'time': 4444,
                'utilisation': 44
            }],
            'nic_details': [{
                'mac_address': 'de:ad:be:ef:00:01',
                'rx_drop': 1,
                'rx_errors': 2,
                'rx_octets': 3,
                'rx_packets': 4,
                'rx_rate': 5,
                'tx_drop': 6,
                'tx_errors': 7,
                'tx_octets': 8,
                'tx_packets': None,
                'tx_rate': None
            }],
            'disk_details': [{
                'errors_count': 1,
                'read_bytes': 2,
                'read_requests': 3,
                'write_bytes': None,
                'write_requests': None
            }],
            'num_cpus':
            4,
            'num_disks':
            1,
            'num_nics':
            1,
            'memory_details': {
                'maximum': 8192,
                'used': 3072
            }
        }

        self._test_get_diagnostics(expected, return_value)