コード例 #1
0
ファイル: test_sysinfo.py プロジェクト: pyfarm/pyfarm-agent
 def testUnknownPlatform(self):
     with nested(
         patch.object(graphics, "WINDOWS", False),
         patch.object(graphics, "MAC", False),
         patch.object(graphics, "LINUX", False)
     ):
         with self.assertRaises(graphics.GPULookupError):
             graphics.graphics_cards()
コード例 #2
0
ファイル: test_sysinfo.py プロジェクト: pyfarm/pyfarm-agent
    def test_linux_error_while_calling_popen(self):
        def raise_(*args, **kwargs):
            raise OSError

        with nested(
            patch.object(graphics, "WINDOWS", False),
            patch.object(graphics, "MAC", True),
            patch.object(graphics, "LINUX", False),
            patch.object(graphics, "Popen", raise_),
            self.assertRaises(graphics.GPULookupError)
        ):
            graphics.graphics_cards()
コード例 #3
0
ファイル: test_sysinfo.py プロジェクト: pyfarm/pyfarm-agent
    def test_linux_lspci_parsing(self):
        sample_data = dedent("""
        00:00.0 Host bridge:
        00:02.0 VGA compatible controller: BestGPU1
        00:02.1 VGA compatible controller: BestGPU2
        00:14.0 USB controller:
        00:16.0 Communication controller:
        00:1a.0 USB controller:
        00:1c.0 PCI bridge:
        00:1d.0 USB controller:
        00:1f.0 ISA bridge:
        00:1f.2 SATA controller:
        00:1f.3 SMBus:
        02:00.0 Ethernet controller:
        """).strip()

        class FakePopenOutput(object):
            stdout = StringIO()
            stdout.write(sample_data)
            stdout.seek(0)

        with nested(
            patch.object(graphics, "WINDOWS", False),
            patch.object(graphics, "MAC", False),
            patch.object(graphics, "LINUX", True),
            patch.object(graphics, "Popen", return_value=FakePopenOutput)
        ):
            self.assertEqual(
                graphics.graphics_cards(), ["BestGPU1", "BestGPU2"])
コード例 #4
0
ファイル: test_sysinfo.py プロジェクト: pyfarm/pyfarm-agent
    def test_windows_wmi(self):
        class FakeGPU(object):
            def __init__(self, name):
                self.name = name

        class FakeWMI(object):
            class Win32_VideoController(object):
                @staticmethod
                def query():
                    return [FakeGPU("foo"), FakeGPU("bar")]

        with nested(
            patch.object(graphics, "WINDOWS", True),
            patch.object(graphics, "MAC", False),
            patch.object(graphics, "LINUX", False),
            patch.object(graphics, "WMI", FakeWMI),
        ):
            self.assertEqual(graphics.graphics_cards(), ["foo", "bar"])
コード例 #5
0
ファイル: test_sysinfo.py プロジェクト: pyfarm/pyfarm-agent
    def test_mac_system_profiler_parsing(self):
        sample_data = dedent("""
        <?xml version="1.0" encoding="UTF-8"?>
        <plist version="1.0">
        <array>
            <dict>
                <array>
                    <dict>
                        <key>sppci_model</key>
                        <string>Intel Iris Pro</string>
                    </dict>
                    <dict>
                        <key>sppci_model</key>
                        <string>NVIDIA GeForce GT 750M</string>
                    </dict>
                </array>
                <key>_timeStamp</key>
                <date>2015-09-24T01:26:52Z</date>
                <key>_versionInfo</key>
            </dict>
        </array>
        </plist>
        """).strip()

        class FakePopenOutput(object):
            stdout = StringIO()
            stdout.write(sample_data)
            stdout.seek(0)

        with nested(
            patch.object(graphics, "WINDOWS", False),
            patch.object(graphics, "MAC", True),
            patch.object(graphics, "LINUX", False),
            patch.object(graphics, "Popen", return_value=FakePopenOutput)
        ):
            self.assertEqual(
                graphics.graphics_cards(),
                ["Intel Iris Pro", "NVIDIA GeForce GT 750M"])
コード例 #6
0
ファイル: service.py プロジェクト: xlhtc007/pyfarm-agent
    def system_data(self, requery_timeoffset=False):
        """
        Returns a dictionary of data containing information about the
        agent.  This is the information that is also passed along to
        the master.
        """
        # query the time offset and then cache it since
        # this is typically a blocking operation
        if config["agent_time_offset"] == "auto":
            config["agent_time_offset"] = None

        if requery_timeoffset or config["agent_time_offset"] is None:
            ntplog.info(
                "Querying ntp server %r for current time",
                config["agent_ntp_server"])

            ntp_client = NTPClient()
            try:
                pool_time = ntp_client.request(
                    config["agent_ntp_server"],
                    version=config["agent_ntp_server_version"])

            except Exception as e:
                ntplog.warning("Failed to determine network time: %s", e)

            else:
                config["agent_time_offset"] = \
                    int(pool_time.tx_time - time.time())

                # format the offset for logging purposes
                utcoffset = datetime.utcfromtimestamp(pool_time.tx_time)
                iso_timestamp = utcoffset.isoformat()
                ntplog.debug(
                    "network time: %s (local offset: %r)",
                    iso_timestamp, config["agent_time_offset"])

                if config["agent_time_offset"] != 0:
                    ntplog.warning(
                        "Agent is %r second(s) off from ntp server at %r",
                        config["agent_time_offset"],
                        config["agent_ntp_server"])

        data = {
            "id": config["agent_id"],
            "hostname": config["agent_hostname"],
            "version": config.version,
            "os_class": system.operating_system(),
            "os_fullname": platform(),
            "ram": int(config["agent_ram"]),
            "cpus": config["agent_cpus"],
            "cpu_name": cpu.cpu_name(),
            "port": config["agent_api_port"],
            "free_ram": memory.free_ram(),
            "time_offset": config["agent_time_offset"] or 0,
            "state": config["state"],
            "mac_addresses": list(network.mac_addresses()),
            "current_assignments": config.get(
                "current_assignments", {}), # may not be set yet
            "disks": disks.disks(as_dict=True)
        }

        try:
            gpu_names = graphics.graphics_cards()
            data["gpus"] = gpu_names
        except graphics.GPULookupError:
            pass

        if "remote_ip" in config:
            data.update(remote_ip=config["remote_ip"])

        if config["farm_name"]:
            data["farm_name"] = config["farm_name"]

        return data