Пример #1
0
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
Пример #2
0
    def inspect_network(self, host):
        net_interfaces = self._walk_oid(self._interface_index_oid, host)

        for interface in net_interfaces:
            for object_name, value in interface:
                ip = self._get_ip_for_interface(host, value)
                name_oid = "%s.%s" % (self._interface_name_oid,
                                      str(value))
                name = self._get_value_from_oid(name_oid, host)
                mac_oid = "%s.%s" % (self._interface_mac_oid,
                                     str(value))
                mac = self._get_value_from_oid(mac_oid, host)
                bw_oid = "%s.%s" % (self._interface_bandwidth_oid,
                                    str(value))
                # bits/s to byte/s
                bandwidth = self._get_value_from_oid(bw_oid, host) / 8
                rx_oid = "%s.%s" % (self._interface_received_oid,
                                    str(value))
                rx_bytes = self._get_value_from_oid(rx_oid, host)
                tx_oid = "%s.%s" % (self._interface_transmitted_oid,
                                    str(value))
                tx_bytes = self._get_value_from_oid(tx_oid, host)
                error_oid = "%s.%s" % (self._interface_error_oid,
                                       str(value))
                error = self._get_value_from_oid(error_oid, host)

                adapted_mac = mac.prettyPrint().replace('0x', '')
                interface = base.Interface(name=str(name),
                                           mac=adapted_mac,
                                           ip=str(ip))
                stats = base.InterfaceStats(bandwidth=int(bandwidth),
                                            rx_bytes=int(rx_bytes),
                                            tx_bytes=int(tx_bytes),
                                            error=int(error))
                yield (interface, stats)
Пример #3
0
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
Пример #4
0
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)