Пример #1
0
def test_get_updated_host_label_files(discovered_host_labels_dir: Path) -> None:
    time_1 = 1616655912.123
    time_2 = 1616655912.234

    save_updated_host_label_files(
        [
            ("host1.mk", time_1, "{'äbc': {'value': '123', 'plugin_name': 'plugin_1'}}\n"),
            ("host2.mk", time_2, "{'äbc': {'value': 'xyz', 'plugin_name': 'plugin_1'}}\n"),
        ]
    )

    assert get_updated_host_label_files(newer_than=time_1 - 1) == [
        ("host1.mk", time_1, "{'äbc': {'value': '123', 'plugin_name': 'plugin_1'}}\n"),
        ("host2.mk", time_2, "{'äbc': {'value': 'xyz', 'plugin_name': 'plugin_1'}}\n"),
    ]
    assert get_updated_host_label_files(newer_than=time_1) == [
        ("host2.mk", time_2, "{'äbc': {'value': 'xyz', 'plugin_name': 'plugin_1'}}\n"),
    ]
    assert get_updated_host_label_files(newer_than=time_2) == []
Пример #2
0
    def execute(self, api_request: SiteRequest) -> Dict[str, Any]:
        if api_request.enforce_host:
            try:
                response = DiscoveredHostLabelSyncResponse(
                    [get_host_labels_entry_of_host(api_request.enforce_host.host_name)])
            except FileNotFoundError:
                response = DiscoveredHostLabelSyncResponse([])
        else:
            response = DiscoveredHostLabelSyncResponse(
                get_updated_host_label_files(newer_than=api_request.newest_host_labels))

        return asdict(response)