~ltrager/maas/remove_di_from_kernel_opts

« back to all changes in this revision

Viewing changes to src/maasserver/models/tests/test_staticipaddress.py

  • Committer: Lee Trager
  • Date: 2016-10-22 06:06:12 UTC
  • mfrom: (5457.1.44 maas)
  • Revision ID: lee.trager@canonical.com-20161022060612-ukar20f6ffs45nas
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from django.core.exceptions import ValidationError
16
16
from django.db import transaction
17
17
from maasserver import locks
 
18
from maasserver.dbviews import register_view
18
19
from maasserver.enum import (
19
20
    INTERFACE_LINK_TYPE,
20
21
    INTERFACE_TYPE,
21
22
    IPADDRESS_FAMILY,
22
23
    IPADDRESS_TYPE,
 
24
    IPADDRESS_TYPE_CHOICES_DICT,
23
25
    IPRANGE_TYPE,
24
26
)
25
27
from maasserver.exceptions import (
134
136
 
135
137
class TestStaticIPAddressManagerTransactional(MAASTransactionServerTestCase):
136
138
    """The following TestStaticIPAddressManager tests require
137
 
        MAASTransactionServerTestCase, and thus have been separated
138
 
        from the TestStaticIPAddressManager above.
 
139
    MAASTransactionServerTestCase, and thus have been separated from the
 
140
    TestStaticIPAddressManager above.
139
141
    """
140
142
 
 
143
    def setUp(self):
 
144
        register_view("maasserver_discovery")
 
145
        return super().setUp()
 
146
 
141
147
    def test_allocate_new_returns_ip_in_correct_range(self):
142
148
        with transaction.atomic():
143
149
            subnet = factory.make_managed_Subnet()
333
339
                StaticIPAddress.objects.allocate_new,
334
340
                subnet)
335
341
        self.assertEqual(
336
 
            "No more IPs available in subnet: %s" % subnet.cidr,
 
342
            "No more IPs available in subnet: %s." % subnet.cidr,
337
343
            str(e))
338
344
 
339
345
 
599
605
        staticip = factory.make_StaticIPAddress(
600
606
            alloc_type=IPADDRESS_TYPE.AUTO, interface=iface,
601
607
            subnet=subnet)
602
 
        discovered = factory.make_StaticIPAddress(
 
608
        factory.make_StaticIPAddress(
603
609
            alloc_type=IPADDRESS_TYPE.DISCOVERED, interface=iface,
604
610
            subnet=subnet)
605
611
        mapping = StaticIPAddress.objects.get_hostname_ip_mapping(
606
612
            node.domain)
607
613
        expected_mapping = {
608
614
            node.fqdn: HostnameIPMapping(
609
 
                node.system_id, 30, {staticip.ip}, node.node_type),
610
 
            "%s.%s" % (iface.name, node.fqdn): HostnameIPMapping(
611
 
                node.system_id, 30, {discovered.ip}, node.node_type)}
 
615
                node.system_id, 30, {staticip.ip}, node.node_type)}
612
616
        self.assertEqual(expected_mapping, mapping)
613
617
 
614
618
    def test_get_hostname_ip_mapping_prefers_bond_with_no_boot_interface(self):
827
831
        mapping = StaticIPAddress.objects.get_hostname_ip_mapping(domain)
828
832
        expected_mapping = {
829
833
            node.fqdn: HostnameIPMapping(
830
 
                node.system_id, 30, {sip0.ip}, node.node_type),
831
 
            "%s.%s" % (iface1.name, node.fqdn): HostnameIPMapping(
832
 
                node.system_id, 30, {sip1.ip}, node.node_type)}
 
834
                node.system_id, 30, {sip0.ip}, node.node_type)}
833
835
        self.assertEqual(expected_mapping, mapping)
834
836
 
835
837
    def test_get_hostname_ip_mapping_returns_correct_bond_ip(self):
876
878
        expected_mapping = {
877
879
            node.fqdn: HostnameIPMapping(
878
880
                node.system_id, 30, {bond_sip.ip}, node.node_type),
879
 
            "%s.%s" % (iface1.name, node.fqdn): HostnameIPMapping(
880
 
                node.system_id, 30, {sip1.ip}, node.node_type),
881
881
            }
882
882
        self.assertEqual(expected_mapping, mapping)
883
883
 
1062
1062
        node_summary = json["node_summary"]
1063
1063
        self.expectThat(node_summary["system_id"], Equals(node.system_id))
1064
1064
        self.expectThat(node_summary["node_type"], Equals(node.node_type))
 
1065
 
 
1066
 
 
1067
class TestAllocTypeName(MAASServerTestCase):
 
1068
 
 
1069
    def test__provides_human_readable_values_for_known_types(self):
 
1070
        ip = factory.make_StaticIPAddress()
 
1071
        self.assertThat(
 
1072
            ip.alloc_type_name,
 
1073
            Equals(IPADDRESS_TYPE_CHOICES_DICT[ip.alloc_type]))
 
1074
 
 
1075
    def test__returns_empty_string_for_unknown_types(self):
 
1076
        ip = factory.make_StaticIPAddress()
 
1077
        ip.alloc_type = randint(2**16, 2**32)
 
1078
        self.assertThat(
 
1079
            ip.alloc_type_name,
 
1080
            Equals(""))