class FakeInspector(inspector_base.Inspector): CPU = inspector_base.CPUStats(cpu_1_min=0.99, cpu_5_min=0.77, cpu_15_min=0.55) DISK = (inspector_base.Disk(device='/dev/sda1', path='/'), inspector_base.DiskStats(size=1000, used=90)) MEMORY = inspector_base.MemoryStats(total=1000, used=90) NET = (inspector_base.Interface(name='test.teest', mac='001122334455', ip='10.0.0.2'), inspector_base.InterfaceStats(bandwidth=1000, rx_bytes=90, tx_bytes=80, error=1)) def inspect_cpu(self, host): yield self.CPU def inspect_disk(self, host): yield self.DISK def inspect_memory(self, host): yield self.MEMORY def inspect_network(self, host): yield self.NET
class InspectorBaseTest(object): """Subclass must set self.inspector and self.host in self.setUp() """ cpu = [ base.CPUStats(cpu_1_min=0.1, cpu_5_min=0.2, cpu_15_min=0.3), ] network = [ (base.Interface(name='eth0', mac='112233445566', ip='10.0.0.1'), base.InterfaceStats(bandwidth=1250000 / 8, rx_bytes=1000, tx_bytes=2000, error=1)), ] diskspace = [ ( base.Disk(device='/dev/sda1', path='/'), base.DiskStats(size=1000, used=500), ), ( base.Disk(device='/dev/sda2', path='/home'), base.DiskStats(size=2000, used=1000), ), ] memory = [base.MemoryStats(total=1000, used=500)] def test_inspect_cpu(self): self.assertEqual(list(self.inspector.inspect_cpu(self.host)), self.cpu) def test_inspect_network(self): self.assertEqual(list(self.inspector.inspect_network(self.host)), self.network) def test_inspect_disk(self): self.assertEqual(list(self.inspector.inspect_disk(self.host)), self.diskspace) def test_inspect_memory(self): self.assertEqual(list(self.inspector.inspect_memory(self.host)), self.memory)
def inspect_disk(self, host): disks = self._walk_oid(self._disk_index_oid, host) for disk in disks: for object_name, value in disk: path_oid = "%s.%s" % (self._disk_path_oid, str(value)) path = self._get_value_from_oid(path_oid, host) device_oid = "%s.%s" % (self._disk_device_oid, str(value)) device = self._get_value_from_oid(device_oid, host) size_oid = "%s.%s" % (self._disk_size_oid, str(value)) size = self._get_value_from_oid(size_oid, host) used_oid = "%s.%s" % (self._disk_used_oid, str(value)) used = self._get_value_from_oid(used_oid, host) disk = base.Disk(device=str(device), path=str(path)) stats = base.DiskStats(size=int(size), used=int(used)) yield (disk, stats)
class FakeInspector(inspector_base.Inspector): CPU = inspector_base.CPUStats(cpu_1_min=0.99, cpu_5_min=0.77, cpu_15_min=0.55) DISK = (inspector_base.Disk(device='/dev/sda1', path='/'), inspector_base.DiskStats(size=1000, used=90)) MEMORY = inspector_base.MemoryStats(total=1000, used=90) NET = (inspector_base.Interface(name='test.teest', mac='001122334455', ip='10.0.0.2'), inspector_base.InterfaceStats(bandwidth=1000, rx_bytes=90, tx_bytes=80, error=1)) RPM = (inspector_base.RPM(name="FAN"), inspector_base.RPMStats(speed=1470, status="ok")) VOLT = (inspector_base.Volt(name="Vcore"), inspector_base.VoltStats(voltage=0.896, status="ok")) DEGREE = (inspector_base.Degree(name="System Temp"), inspector_base.DegreeStats(temperature=30.000, status="ok")) def inspect_cpu(self, host): yield self.CPU def inspect_disk(self, host): yield self.DISK def inspect_memory(self, host): yield self.MEMORY def inspect_network(self, host): yield self.NET def inspect_speed(self, host): yield self.RPM def inspect_voltage(self, host): yield self.VOLT def inspect_temperature(self, host): yield self.DEGREE