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
def inspect_memory(self, host): #get total memory total = self._get_value_from_oid(self._memory_total_oid, host) #get used memory used = self._get_value_from_oid(self._memory_used_oid, host) yield base.MemoryStats(total=int(total), used=int(used))
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
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)