示例#1
0
    def test_merge_by_overriding_current(self):
        dns_state = DnsState(
            {DNS.CONFIG: DNS_CONFIG2}, {DNS.CONFIG: DNS_CONFIG1},
        )

        assert dns_state.config == DNS_CONFIG2
        assert dns_state.current_config == DNS_CONFIG1
示例#2
0
    def test_gen_metadadata_use_default_gateway_ipv4_server_prefered(self):
        ifaces = self._gen_static_ifaces()
        route_state = self._gen_route_state(ifaces)
        dns_state = DnsState({DNS.CONFIG: DNS_CONFIG1}, {})
        ifaces.gen_dns_metadata(dns_state, route_state)
        ipv4_iface = ifaces[IPV4_ROUTE_IFACE_NAME]
        ipv6_iface = ifaces[IPV6_ROUTE_IFACE_NAME]

        assert dns_state.config == DNS_CONFIG1
        assert ipv4_iface.to_dict()[Interface.IPV4][
            BaseIface.DNS_METADATA] == {
                DnsState.PRIORITY_METADATA: 0,
                DNS.SERVER: [IPV4_DNS_SERVER1],
                DNS.SEARCH: DNS_SEARCHES_1,
            }
        assert ipv6_iface.to_dict()[Interface.IPV6][
            BaseIface.DNS_METADATA] == {
                DnsState.PRIORITY_METADATA: 1,
                DNS.SERVER: [IPV6_DNS_SERVER1],
                DNS.SEARCH: [],
            }
示例#3
0
    def test_3_dns_ipv6_servers(self):
        dns_config = deepcopy(DNS_CONFIG1)
        dns_config[DNS.SERVER] = [
            IPV6_DNS_SERVER1,
            IPV6_DNS_SERVER2,
            IPV6_DNS_SERVER3,
        ]

        ifaces = self._gen_static_ifaces()
        route_state = self._gen_route_state(ifaces)
        dns_state = DnsState({DNS.CONFIG: dns_config}, {})
        ifaces.gen_dns_metadata(dns_state, route_state)
        ipv6_iface = ifaces[IPV6_ROUTE_IFACE_NAME]

        assert dns_state.config == dns_config
        assert ipv6_iface.to_dict()[Interface.IPV6][
            BaseIface.DNS_METADATA] == {
                DnsState.PRIORITY_METADATA: 0,
                DNS.SERVER: dns_config[DNS.SERVER],
                DNS.SEARCH: DNS_SEARCHES_1,
            }
示例#4
0
    def with_dns_metadata(self):
        ifaces = self._gen_static_ifaces()
        route_state = self._gen_route_state(ifaces)
        dns_state = DnsState({}, {DNS.CONFIG: DNS_CONFIG1})
        ifaces.gen_dns_metadata(dns_state, route_state)
        ipv4_iface = ifaces[IPV4_ROUTE_IFACE_NAME]
        ipv6_iface = ifaces[IPV6_ROUTE_IFACE_NAME]

        assert dns_state.config == DNS_CONFIG1
        assert ipv4_iface.to_dict()[Interface.IPV4][
            BaseIface.DNS_METADATA] == {
                DnsState.PRIORITY_METADATA: 0,
                DNS.SERVER: [IPV4_DNS_SERVER1],
                DNS.SEARCH: DNS_SEARCHES_1,
            }
        assert ipv6_iface.to_dict()[Interface.IPV6][
            BaseIface.DNS_METADATA] == {
                DnsState.PRIORITY_METADATA: 1,
                DNS.SERVER: [IPV6_DNS_SERVER1],
                DNS.SEARCH: [],
            }
        yield ipv4_iface, ipv6_iface
示例#5
0
    def test_merge_by_discarding_current(self):
        dns_state = DnsState({DNS.CONFIG: []}, {DNS.CONFIG: DNS_CONFIG1})

        assert dns_state.config == {DNS.SERVER: [], DNS.SEARCH: []}
        assert dns_state.current_config == DNS_CONFIG1
示例#6
0
    def test_merge_without_desire_with_current(self):
        dns_state = DnsState({}, {DNS.CONFIG: DNS_CONFIG1})

        assert dns_state.config == DNS_CONFIG1
        assert dns_state.current_config == DNS_CONFIG1
示例#7
0
    def test_3_ipv4_ipv6_mixed_name_servers(self):
        dns_config = deepcopy(DNS_CONFIG1)
        dns_config[DNS.SERVER].append(IPV4_DNS_SERVER3)

        with pytest.raises(NmstateNotImplementedError):
            DnsState({DNS.CONFIG: dns_config}, {})
示例#8
0
 def test_verify_not_match(self):
     dns_state = DnsState({DNS.CONFIG: DNS_CONFIG1}, {})
     with pytest.raises(NmstateVerificationError):
         dns_state.verify({DNS.CONFIG: DNS_CONFIG2})
示例#9
0
 def test_verify_identical_state(self):
     dns_state = DnsState({DNS.CONFIG: DNS_CONFIG1}, {})
     dns_state.verify({DNS.CONFIG: DNS_CONFIG1})