def test_search_domains_regex_not_found(build_mock_libvirtconn, build_mock_domain): """ Search a non existing domain """ conn = build_mock_libvirtconn conn._domains = [build_mock_domain] matches = list(search_domains_regex("^dom$", conn)) assert matches == []
def test_search_domains_regex_not_found( build_mock_libvirtconn, build_mock_domain): """ Search a non existing domain """ conn = build_mock_libvirtconn conn._domains = [build_mock_domain] matches = list(search_domains_regex("^dom$", conn)) assert matches == []
def test_search_domains_regex(build_mock_libvirtconn): conn = build_mock_libvirtconn domain_names = ("dom1", "dom2", "dom3", "test") conn._domains = [MockDomain(name=dom_name, _conn=conn) for dom_name in domain_names] matches = list(sorted(search_domains_regex(r"^dom\d$", conn))) expected = list(sorted(domain_names)) expected.remove("test") assert matches == expected
def test_search_domains_regex(build_mock_libvirtconn): conn = build_mock_libvirtconn domain_names = ("dom1", "dom2", "dom3", "test") conn._domains = [ MockDomain(name=dom_name, _conn=conn) for dom_name in domain_names ] matches = list(sorted(search_domains_regex("^dom\d$", conn))) expected = list(sorted(domain_names)) expected.remove("test") assert matches == expected
def pattern_matching_domains_in_libvirt(pattern, conn): """ Parse the host pattern as written in the config and find matching hosts :param pattern: pattern to match on one or several domain names :param conn: connection with libvirt """ exclude, pattern = _handle_possible_exclusion_host_pattern(pattern) if pattern.startswith("r:"): pattern = pattern[2:] domains = search_domains_regex(pattern, conn) elif pattern.startswith("g:"): domains = _include_group_domains(pattern) else: try: # will raise libvirt.libvirtError if the domain is not found conn.lookupByName(pattern) domains = (pattern, ) except libvirt.libvirtError as e: logger.error(e) domains = tuple() return {"domains": domains, "exclude": exclude}
def pattern_matching_domains_in_libvirt(pattern, conn): """ Parse the host pattern as written in the config and find matching hosts :param pattern: pattern to match on one or several domain names :param conn: connection with libvirt """ exclude, pattern = _handle_possible_exclusion_host_pattern(pattern) if pattern.startswith("r:"): pattern = pattern[2:] domains = search_domains_regex(pattern, conn) elif pattern.startswith("g:"): domains = _include_group_domains(pattern) else: try: # will raise libvirt.libvirtError if the domain is not found conn.lookupByName(pattern) domains = (pattern,) except libvirt.libvirtError as e: logger.error(e) domains = tuple() return {"domains": domains, "exclude": exclude}