Esempio n. 1
0
 def test_sets_gateway_link_v6_on_node_when_link_id(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     ipv6_link = self.make_ip_family_link(interface,
                                          factory.make_ipv6_network())
     self.make_ip_family_link(interface, factory.make_ipv6_network())
     form = InterfaceSetDefaultGatwayForm(instance=interface,
                                          data={"link_id": ipv6_link.id})
     self.assertTrue(form.is_valid(), form.errors)
     interface = form.save()
     node = interface.get_node()
     self.assertEqual(ipv6_link, node.gateway_link_ipv6)
Esempio n. 2
0
 def test__requires_link_id_if_more_than_one_gateway_per_family(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     self.make_ip_family_link(interface, factory.make_ipv4_network())
     self.make_ip_family_link(interface, factory.make_ipv6_network())
     self.make_ip_family_link(interface, factory.make_ipv4_network())
     self.make_ip_family_link(interface, factory.make_ipv6_network())
     form = InterfaceSetDefaultGatwayForm(instance=interface, data={})
     self.assertFalse(form.is_valid(), form.errors)
     self.assertEqual(
         {
             "link_id": [
                 "This field is required; Interface has more than one "
                 "usable IPv4 and IPv6 gateways."
             ],
         }, form.errors)
Esempio n. 3
0
    def test_creates_lease_for_physical_interface_keeps_other_ip_family(self):
        subnet = factory.make_ipv4_Subnet_with_IPRanges(
            with_static_range=False, dhcp_on=True)
        node = factory.make_Node_with_Interface_on_Subnet(subnet=subnet)
        boot_interface = node.get_boot_interface()
        dynamic_range = subnet.get_dynamic_ranges()[0]
        ip = factory.pick_ip_in_IPRange(dynamic_range)
        kwargs = self.make_kwargs(action="commit",
                                  mac=boot_interface.mac_address,
                                  ip=ip)

        # Make DISCOVERED in the other address family to make sure it is
        # not removed.
        network = subnet.get_ipnetwork()
        if network.version == IPADDRESS_FAMILY.IPv4:
            other_network = factory.make_ipv6_network()
        else:
            other_network = factory.make_ipv4_network()
        other_subnet = factory.make_Subnet(cidr=str(other_network.cidr))
        other_ip = factory.make_StaticIPAddress(
            alloc_type=IPADDRESS_TYPE.DISCOVERED,
            ip="",
            subnet=other_subnet,
            interface=boot_interface,
        )

        update_lease(**kwargs)
        self.assertIsNotNone(
            reload_object(other_ip),
            "DISCOVERED IP address from the other address family should not "
            "have been deleted.",
        )
Esempio n. 4
0
 def test__returns_empty_list_for_full_ipv6_subnet(self):
     network = factory.make_ipv6_network(slash=random.randint(112, 119))
     subnet = factory.make_Subnet(cidr=str(network.cidr), dns_servers=[])
     network = subnet.get_ipnetwork()
     first_address = inet_ntop(network.first + 2)  # Skip gateway, network.
     last_address = inet_ntop(network.last)
     self._unreserved_ip_ranges_empty(subnet, first_address, last_address)
Esempio n. 5
0
    def test__returns_at_most_60kiB_of_JSON(self):
        # Configure the rack controller subnet to be very large so it
        # can hold that many BMC connected to the interface for the rack
        # controller.
        rack = factory.make_RackController(power_type='')
        rack_interface = rack.get_boot_interface()
        subnet = factory.make_Subnet(
            cidr=str(factory.make_ipv6_network(slash=8)))
        factory.make_StaticIPAddress(ip=factory.pick_ip_in_Subnet(subnet),
                                     subnet=subnet,
                                     interface=rack_interface)

        # Ensure that there are at least 64kiB of power parameters (when
        # converted to JSON) in the database.
        example_parameters = {"key%d" % i: "value%d" % i for i in range(250)}
        remaining = 2**16
        while remaining > 0:
            node = self.make_Node(bmc_connected_to=rack,
                                  power_parameters=example_parameters)
            remaining -= len(json.dumps(node.get_effective_power_parameters()))

        nodes = list_cluster_nodes_power_parameters(
            rack.system_id, limit=None)  # Remove numeric limit.

        # The total size of the JSON is less than 60kiB, but only a bit.
        nodes_json = map(json.dumps, nodes)
        nodes_json_lengths = map(len, nodes_json)
        nodes_json_length = sum(nodes_json_lengths)
        expected_maximum = 60 * (2**10)  # 60kiB
        self.expectThat(nodes_json_length, LessThan(expected_maximum + 1))
        expected_minimum = 50 * (2**10)  # 50kiB
        self.expectThat(nodes_json_length, GreaterThan(expected_minimum - 1))
Esempio n. 6
0
 def test_adds_connected_multiple_racks_ipv6(self):
     rack1 = factory.make_RackController()
     factory.make_RegionRackRPCConnection(rack1)
     rack2 = factory.make_RackController()
     factory.make_RegionRackRPCConnection(rack2)
     network = factory.make_ipv6_network()
     subnet = factory.make_Subnet(cidr=str(network.cidr))
     static_ip1 = factory.make_StaticIPAddress(
         alloc_type=IPADDRESS_TYPE.AUTO,
         ip=factory.pick_ip_in_Subnet(subnet),
         subnet=subnet,
         interface=rack1.get_boot_interface(),
     )
     static_ip2 = factory.make_StaticIPAddress(
         alloc_type=IPADDRESS_TYPE.AUTO,
         ip=factory.pick_ip_in_Subnet(subnet),
         subnet=subnet,
         interface=rack2.get_boot_interface(),
     )
     domain = get_internal_domain()
     self.assertEqual(get_resource_name_for_subnet(subnet),
                      domain.resources[0].name)
     self.assertThat(
         domain.resources[0].records,
         MatchesSetwise(
             Equals(
                 InternalDomainResourseRecord(rrtype="AAAA",
                                              rrdata=static_ip1.ip)),
             Equals(
                 InternalDomainResourseRecord(rrtype="AAAA",
                                              rrdata=static_ip2.ip)),
         ),
     )
Esempio n. 7
0
 def test_settings_dns_POST(self):
     # Disable boot source cache signals.
     self.addCleanup(bootsources.signals.enable)
     bootsources.signals.disable()
     self.client.login(user=factory.make_admin())
     new_upstream = "8.8.8.8 8.8.4.4"
     new_ipv4_subnet = factory.make_ipv4_network()
     new_ipv6_subnet = factory.make_ipv6_network()
     new_subnets = "%s %s" % (new_ipv4_subnet, new_ipv6_subnet)
     response = self.client.post(
         reverse("settings_network"),
         get_prefixed_form_data(
             prefix="dns",
             data={
                 "upstream_dns": new_upstream,
                 "dnssec_validation": "no",
                 "dns_trusted_acl": new_subnets,
             },
         ),
     )
     self.assertEqual(http.client.FOUND, response.status_code,
                      response.content)
     self.assertEqual(new_upstream,
                      Config.objects.get_config("upstream_dns"))
     self.assertEqual("no", Config.objects.get_config("dnssec_validation"))
     self.assertEqual(new_subnets,
                      Config.objects.get_config("dns_trusted_acl"))
Esempio n. 8
0
 def test_raises_LeaseUpdateError_for_ipv4_mismatch(self):
     ipv6_network = factory.make_ipv6_network()
     subnet = factory.make_Subnet(cidr=str(ipv6_network.cidr))
     kwargs = self.make_kwargs(subnet=subnet)
     kwargs["ip_family"] = "ipv4"
     error = self.assertRaises(LeaseUpdateError, update_lease, **kwargs)
     self.assertEqual(
         "Family for the subnet does not match. Expected: ipv4", str(error))
Esempio n. 9
0
 def test_bind_configuration_includes_ipv6_zone(self):
     self.patch(settings, 'DNS_CONNECT', True)
     network = factory.make_ipv6_network(slash=random.randint(118, 125))
     subnet = factory.make_Subnet(cidr=str(network.cidr))
     node, static = self.create_node_with_static_ip(subnet=subnet)
     dns_update_all_zones()
     self.assertDNSMatches(
         node.hostname, node.domain.name, static.ip, version=6)
Esempio n. 10
0
 def test__returns_empty_list_for_full_ipv6_slash_64_subnet(self):
     network = factory.make_ipv6_network(slash=64)
     subnet = factory.make_Subnet(cidr=str(network.cidr), dns_servers=[])
     network = subnet.get_ipnetwork()
     strip64 = (network.first >> 8) << 8
     # Skip the automatically reserved range on /64's.
     first_address = inet_ntop(strip64 + 0x100000000)
     last_address = inet_ntop(network.last)
     self._unreserved_ip_ranges_empty(subnet, first_address, last_address)
Esempio n. 11
0
def make_region_with_address(space):
    region = factory.make_RegionController()
    iface = factory.make_Interface(node=region)
    cidr4 = factory.make_ipv4_network(24)
    subnet4 = factory.make_Subnet(space=space, cidr=cidr4)
    cidr6 = factory.make_ipv6_network(64)
    subnet6 = factory.make_Subnet(space=space, cidr=cidr6)
    sip4 = factory.make_StaticIPAddress(interface=iface, subnet=subnet4)
    sip6 = factory.make_StaticIPAddress(interface=iface, subnet=subnet6)
    return region, sip4, sip6
Esempio n. 12
0
 def test_dns_update_all_zones_writes_trusted_networks_params_extra(self):
     self.patch(settings, 'DNS_CONNECT', True)
     extra_trusted_network = factory.make_ipv6_network()
     get_trusted_acls_patch = self.patch(
         dns_config_module, 'get_trusted_acls')
     get_trusted_acls_patch.return_value = [extra_trusted_network.cidr]
     dns_update_all_zones()
     self.assertThat(
         compose_config_path(DNSConfig.target_file_name),
         FileContains(matcher=Contains(str(extra_trusted_network))))
Esempio n. 13
0
 def test__sets_gateway_links_works_on_dhcp_with_gateway_ip(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     ipv4_link = self.make_ip_family_link(
         interface, factory.make_ipv4_network(), IPADDRESS_TYPE.DHCP
     )
     ipv6_link = self.make_ip_family_link(
         interface, factory.make_ipv6_network(), IPADDRESS_TYPE.DHCP
     )
     form = InterfaceSetDefaultGatwayForm(instance=interface, data={})
     self.assertTrue(form.is_valid(), form.errors)
     interface = form.save()
     node = interface.get_node()
     self.assertEqual(ipv4_link, node.gateway_link_ipv4)
     self.assertEqual(ipv6_link, node.gateway_link_ipv6)
Esempio n. 14
0
 def test_link_id_fields_setup_correctly(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     links = []
     for _ in range(2):
         links.append(
             self.make_ip_family_link(interface,
                                      factory.make_ipv4_network()))
     for _ in range(2):
         links.append(
             self.make_ip_family_link(interface,
                                      factory.make_ipv6_network()))
     link_ids = [link.id for link in links]
     form = InterfaceSetDefaultGatwayForm(instance=interface, data={})
     choice_ids = [choice[0] for choice in form.fields["link_id"].choices]
     self.assertItemsEqual(link_ids, choice_ids)
Esempio n. 15
0
 def test__adds_connected_rack_ipv6(self):
     rack = factory.make_RackController()
     factory.make_RegionRackRPCConnection(rack)
     nic = rack.get_boot_interface()
     network = factory.make_ipv6_network()
     subnet = factory.make_Subnet(cidr=str(network.cidr))
     static_ip = factory.make_StaticIPAddress(
         alloc_type=IPADDRESS_TYPE.AUTO,
         ip=factory.pick_ip_in_Subnet(subnet),
         subnet=subnet, interface=nic)
     domain = get_internal_domain()
     self.assertEqual(
         get_resource_name_for_subnet(subnet), domain.resources[0].name)
     self.assertEqual(
         InternalDomainResourseRecord(rrtype='AAAA', rrdata=static_ip.ip),
         domain.resources[0].records[0])
Esempio n. 16
0
 def test__AUTO_sets_node_gateway_link_v6(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     network = factory.make_ipv6_network()
     auto_subnet = factory.make_Subnet(cidr=str(network.cidr),
                                       vlan=interface.vlan)
     form = InterfaceLinkForm(instance=interface,
                              data={
                                  "mode": INTERFACE_LINK_TYPE.AUTO,
                                  "subnet": auto_subnet.id,
                                  "default_gateway": True,
                              })
     self.assertTrue(form.is_valid(), form.errors)
     interface = form.save()
     auto_ip = interface.ip_addresses.get(alloc_type=IPADDRESS_TYPE.AUTO)
     node = interface.get_node()
     self.assertEqual(auto_ip, node.gateway_link_ipv6)
Esempio n. 17
0
    def test__limited_to_10_nodes_at_a_time_by_default(self):
        # Configure the rack controller subnet to be large enough.
        rack = factory.make_RackController(power_type='')
        rack_interface = rack.get_boot_interface()
        subnet = factory.make_Subnet(
            cidr=str(factory.make_ipv6_network(slash=8)))
        factory.make_StaticIPAddress(ip=factory.pick_ip_in_Subnet(subnet),
                                     subnet=subnet,
                                     interface=rack_interface)

        # Create at least 11 nodes connected to the rack.
        for _ in range(11):
            self.make_Node(bmc_connected_to=rack)

        # Only 10 nodes' power parameters are returned.
        self.assertThat(list_cluster_nodes_power_parameters(rack.system_id),
                        HasLength(10))
Esempio n. 18
0
 def test__STATIC_sets_node_gateway_link_ipv6(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     network = factory.make_ipv6_network()
     subnet = factory.make_Subnet(cidr=str(network.cidr),
                                  vlan=interface.vlan)
     form = InterfaceLinkForm(instance=interface,
                              data={
                                  "mode": INTERFACE_LINK_TYPE.STATIC,
                                  "subnet": subnet.id,
                                  "default_gateway": True,
                              })
     self.assertTrue(form.is_valid(), form.errors)
     interface = form.save()
     ip_address = get_one(
         interface.ip_addresses.filter(alloc_type=IPADDRESS_TYPE.STICKY,
                                       subnet=subnet))
     node = interface.get_node()
     self.assertEqual(ip_address, node.gateway_link_ipv6)
Esempio n. 19
0
 def test_returns_single_network(self):
     subnet = factory.make_ipv6_network()
     Config.objects.set_config("dns_trusted_acl", str(subnet))
     expected = [str(subnet)]
     self.assertEqual(expected, get_trusted_acls())
Esempio n. 20
0
 def test_rejects_invalid_ipv6_subnet(self):
     input = "%s 100::/300" % factory.make_ipv6_network()
     error = self.assertRaises(ValidationError,
                               SubnetListFormField().clean, input)
     self.assertThat(error.message, Equals("Invalid network: 100::/300."))
Esempio n. 21
0
 def test_accepts_space_separated_subnets(self):
     subnets = [str(factory.make_ipv6_network()) for _ in range(5)]
     input = " ".join(subnets)
     self.assertEqual(input, SubnetListFormField().clean(input))
Esempio n. 22
0
 def test__doesnt_require_link_id_if_only_one_gateway_per_family(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     self.make_ip_family_link(interface, factory.make_ipv4_network())
     self.make_ip_family_link(interface, factory.make_ipv6_network())
     form = InterfaceSetDefaultGatwayForm(instance=interface, data={})
     self.assertTrue(form.is_valid(), form.errors)