nova/nova/tests/unit/fake_diagnostics.py
Sergey Nikitin 2cf846e1e7 Added nova objects for intance diagnostics
Following objects were added:

* CpuDiagnostics
* NicDiagnostics
* DiskDiagnostics
* MemoryDiagnostics
* Diagnostics

These objects will be used to transmit data via RPC.
They are based on same objects from nova.virt.diagnostics.
But old objects were used only for storing data.
During RPC transmission they are transform into dictionaries.
It is not right approach.  We will have some problems
in case of adding new diagnostics fields.

New nova objects will allow us to have a good control of objects
versioning. It will force contributors to dump objects
version in case of any changes.

Also some new fields were added/modified to be in accordance with
updated diagnostic spec Ibcc2b98ae5b3731a9e5a1a3f28fc7ce4655c8ea6

blueprint: restore-vm-diagnostics

Change-Id: I6b15001e6f4e649df983071464ec8642bfc89b61
2017-05-30 00:39:44 +04:00

43 lines
1.3 KiB
Python

# Copyright (c) 2017 Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova import objects
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