VM diagnostics: introduce Diagnostics model object
There is no formal definition for the VM diagnostics. This patch introduces a model object that will be used by the virt drivers to return instance diagnostics. The model will have a version. Each update to the model will require a version change. Part of the blueprint v3-diagnostics Change-Id: I5527bc9904417489ec9bde844c9ff24cb02233fd
This commit is contained in:
120
nova/tests/virt/test_diagnostics.py
Normal file
120
nova/tests/virt/test_diagnostics.py
Normal file
@@ -0,0 +1,120 @@
|
||||
# Copyright (c) 2014 VMware, Inc.
|
||||
#
|
||||
# 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 test
|
||||
from nova.virt import diagnostics
|
||||
|
||||
|
||||
class DiagnosticsTests(test.NoDBTestCase):
|
||||
|
||||
def test_cpu_diagnostics_default(self):
|
||||
cpu = diagnostics.CpuDiagnostics()
|
||||
self.assertEqual(0, cpu.time)
|
||||
|
||||
def test_cpu_diagnostics(self):
|
||||
cpu = diagnostics.CpuDiagnostics(time=7)
|
||||
self.assertEqual(7, cpu.time)
|
||||
|
||||
def test_nic_diagnostics_default(self):
|
||||
nic = diagnostics.NicDiagnostics()
|
||||
self.assertEqual('00:00:00:00:00:00', nic.mac_address)
|
||||
self.assertEqual(0, nic.rx_octets)
|
||||
self.assertEqual(0, nic.rx_errors)
|
||||
self.assertEqual(0, nic.rx_drop)
|
||||
self.assertEqual(0, nic.rx_packets)
|
||||
self.assertEqual(0, nic.tx_octets)
|
||||
self.assertEqual(0, nic.tx_errors)
|
||||
self.assertEqual(0, nic.tx_drop)
|
||||
self.assertEqual(0, nic.tx_packets)
|
||||
|
||||
def test_nic_diagnostics(self):
|
||||
nic = diagnostics.NicDiagnostics(mac_address='00:00:ca:fe:00:00',
|
||||
rx_octets=1, rx_errors=2, rx_drop=3, rx_packets=4,
|
||||
tx_octets=5, tx_errors=6, tx_drop=7, tx_packets=8)
|
||||
self.assertEqual('00:00:ca:fe:00:00', nic.mac_address)
|
||||
self.assertEqual(1, nic.rx_octets)
|
||||
self.assertEqual(2, nic.rx_errors)
|
||||
self.assertEqual(3, nic.rx_drop)
|
||||
self.assertEqual(4, nic.rx_packets)
|
||||
self.assertEqual(5, nic.tx_octets)
|
||||
self.assertEqual(6, nic.tx_errors)
|
||||
self.assertEqual(7, nic.tx_drop)
|
||||
self.assertEqual(8, nic.tx_packets)
|
||||
|
||||
def test_disk_diagnostics_default(self):
|
||||
disk = diagnostics.DiskDiagnostics()
|
||||
self.assertEqual('', disk.id)
|
||||
self.assertEqual(0, disk.read_bytes)
|
||||
self.assertEqual(0, disk.read_requests)
|
||||
self.assertEqual(0, disk.write_bytes)
|
||||
self.assertEqual(0, disk.write_requests)
|
||||
self.assertEqual(0, disk.errors_count)
|
||||
|
||||
def test_disk_diagnostics(self):
|
||||
disk = diagnostics.DiskDiagnostics(id='fake_disk_id',
|
||||
read_bytes=1, read_requests=2,
|
||||
write_bytes=3, write_requests=4,
|
||||
errors_count=5)
|
||||
self.assertEqual('fake_disk_id', disk.id)
|
||||
self.assertEqual(1, disk.read_bytes)
|
||||
self.assertEqual(2, disk.read_requests)
|
||||
self.assertEqual(3, disk.write_bytes)
|
||||
self.assertEqual(4, disk.write_requests)
|
||||
self.assertEqual(5, disk.errors_count)
|
||||
|
||||
def test_memory_diagnostics_default(self):
|
||||
memory = diagnostics.MemoryDiagnostics()
|
||||
self.assertEqual(0, memory.maximum)
|
||||
self.assertEqual(0, memory.used)
|
||||
|
||||
def test_memory_diagnostics(self):
|
||||
memory = diagnostics.MemoryDiagnostics(maximum=1, used=2)
|
||||
self.assertEqual(1, memory.maximum)
|
||||
self.assertEqual(2, memory.used)
|
||||
|
||||
def test_diagnostics_default(self):
|
||||
diags = diagnostics.Diagnostics()
|
||||
self.assertIsNone(diags.state)
|
||||
self.assertIsNone(diags.driver)
|
||||
self.assertIsNone(diags.hypervisor_os)
|
||||
self.assertEqual(0, diags.uptime)
|
||||
self.assertFalse(diags.config_drive)
|
||||
self.assertEqual([], diags.cpu_details)
|
||||
self.assertEqual([], diags.nic_details)
|
||||
self.assertEqual([], diags.disk_details)
|
||||
self.assertEqual(0, diags.memory_details.maximum)
|
||||
self.assertEqual(0, diags.memory_details.used)
|
||||
self.assertEqual('1.0', diags.version)
|
||||
|
||||
def test_diagnostics(self):
|
||||
cpu_details = [diagnostics.CpuDiagnostics()]
|
||||
nic_details = [diagnostics.NicDiagnostics()]
|
||||
disk_details = [diagnostics.DiskDiagnostics()]
|
||||
diags = diagnostics.Diagnostics(
|
||||
state='fake-state', driver='fake-driver',
|
||||
hypervisor_os='fake-os',
|
||||
uptime=1, cpu_details=cpu_details,
|
||||
nic_details=nic_details, disk_details=disk_details,
|
||||
config_drive=True)
|
||||
self.assertEqual('fake-state', diags.state)
|
||||
self.assertEqual('fake-driver', diags.driver)
|
||||
self.assertEqual('fake-os', diags.hypervisor_os)
|
||||
self.assertEqual(1, diags.uptime)
|
||||
self.assertTrue(diags.config_drive)
|
||||
self.assertEqual(1, len(diags.cpu_details))
|
||||
self.assertEqual(1, len(diags.nic_details))
|
||||
self.assertEqual(1, len(diags.disk_details))
|
||||
self.assertEqual(0, diags.memory_details.maximum)
|
||||
self.assertEqual(0, diags.memory_details.used)
|
||||
self.assertEqual('1.0', diags.version)
|
||||
131
nova/virt/diagnostics.py
Normal file
131
nova/virt/diagnostics.py
Normal file
@@ -0,0 +1,131 @@
|
||||
# Copyright (c) 2014 VMware, 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.
|
||||
|
||||
|
||||
class CpuDiagnostics(object):
|
||||
|
||||
def __init__(self, time=0):
|
||||
"""Create a new CpuDiagnostics object
|
||||
|
||||
:param time: CPU Time in nano seconds (Integer)
|
||||
"""
|
||||
self.time = time
|
||||
|
||||
|
||||
class NicDiagnostics(object):
|
||||
|
||||
def __init__(self, mac_address='00:00:00:00:00:00',
|
||||
rx_octets=0, rx_errors=0, rx_drop=0, rx_packets=0,
|
||||
tx_octets=0, tx_errors=0, tx_drop=0, tx_packets=0):
|
||||
"""Create a new NicDiagnostics object
|
||||
|
||||
:param mac_address: Mac address of the interface (String)
|
||||
:param rx_octets: Received octets (Integer)
|
||||
:param rx_errors: Received errors (Integer)
|
||||
:param rx_drop: Received packets dropped (Integer)
|
||||
:param rx_packets: Received packets (Integer)
|
||||
:param tx_octets: Transmitted Octets (Integer)
|
||||
:param tx_errors: Transmit errors (Integer)
|
||||
:param tx_drop: Transmit dropped packets (Integer)
|
||||
:param tx_packets: Transmit packets (Integer)
|
||||
"""
|
||||
self.mac_address = mac_address
|
||||
self.rx_octets = rx_octets
|
||||
self.rx_errors = rx_errors
|
||||
self.rx_drop = rx_drop
|
||||
self.rx_packets = rx_packets
|
||||
self.tx_octets = tx_octets
|
||||
self.tx_errors = tx_errors
|
||||
self.tx_drop = tx_drop
|
||||
self.tx_packets = tx_packets
|
||||
|
||||
|
||||
class DiskDiagnostics(object):
|
||||
|
||||
def __init__(self, id='', read_bytes=0, read_requests=0,
|
||||
write_bytes=0, write_requests=0, errors_count=0):
|
||||
"""Create a new DiskDiagnostics object
|
||||
|
||||
:param id: Disk ID (String)
|
||||
:param read_bytes: Disk reads in bytes(Integer)
|
||||
:param read_requests: Read requests (Integer)
|
||||
:param write_bytes: Disk writes in bytes (Integer)
|
||||
:param write_requests: Write requests (Integer)
|
||||
:param errors_count: Disk errors (Integer)
|
||||
"""
|
||||
self.id = id
|
||||
self.read_bytes = read_bytes
|
||||
self.read_requests = read_requests
|
||||
self.write_bytes = write_bytes
|
||||
self.write_requests = write_requests
|
||||
self.errors_count = errors_count
|
||||
|
||||
|
||||
class MemoryDiagnostics(object):
|
||||
|
||||
def __init__(self, maximum=0, used=0):
|
||||
"""Create a new MemoryDiagnostics object
|
||||
|
||||
:param maximum: Amount of memory provisioned for the VM in MB (Integer)
|
||||
:param used: Amount of memory used by the VM in MB (Integer)
|
||||
"""
|
||||
self.maximum = maximum
|
||||
self.used = used
|
||||
|
||||
|
||||
class Diagnostics(object):
|
||||
|
||||
# Version 1.0: Initial version
|
||||
version = '1.0'
|
||||
|
||||
def __init__(self, state=None, driver=None, hypervisor_os=None,
|
||||
uptime=0, cpu_details=None, nic_details=None,
|
||||
disk_details=None, config_drive=False):
|
||||
"""Create a new diagnostics object
|
||||
|
||||
:param state: The current state of the VM. Example values are:
|
||||
'pending', 'running', 'paused', 'shutdown', 'crashed',
|
||||
'suspended' and 'building' (String)
|
||||
:param driver: A string denoting the driver on which the VM is running.
|
||||
Examples may be: 'libvirt', 'xenapi', 'hyperv' and
|
||||
'vmwareapi' (String)
|
||||
:param hypervisor_os: A string denoting the hypervisor OS (String)
|
||||
:param uptime: The amount of time in seconds that the VM has been
|
||||
running (Integer)
|
||||
:param cpu_details: And array of CpuDiagnostics or None.
|
||||
:param nic_details: And array of NicDiagnostics or None.
|
||||
:param disk_details: And array of DiskDiagnostics or None.
|
||||
:param config_drive: Indicates if the config drive is supported on the
|
||||
instance (Boolean)
|
||||
"""
|
||||
|
||||
self.state = state
|
||||
self.driver = driver
|
||||
self.hypervisor_os = hypervisor_os
|
||||
self.uptime = uptime
|
||||
self.config_drive = config_drive
|
||||
if cpu_details:
|
||||
self.cpu_details = cpu_details
|
||||
else:
|
||||
self.cpu_details = []
|
||||
if nic_details:
|
||||
self.nic_details = nic_details
|
||||
else:
|
||||
self.nic_details = []
|
||||
if disk_details:
|
||||
self.disk_details = disk_details
|
||||
else:
|
||||
self.disk_details = []
|
||||
self.memory_details = MemoryDiagnostics()
|
||||
Reference in New Issue
Block a user