~ltrager/maas/remove_di_from_kernel_opts

« back to all changes in this revision

Viewing changes to src/maasserver/models/tests/test_vlan.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:
6
6
__all__ = []
7
7
 
8
8
import random
9
 
import re
10
9
 
11
10
from django.core.exceptions import ValidationError
12
11
from django.db.models import ProtectedError
19
18
from maasserver.testing.factory import factory
20
19
from maasserver.testing.testcase import MAASServerTestCase
21
20
from maasserver.utils.orm import reload_object
22
 
from testtools.matchers import (
23
 
    Equals,
24
 
    Is,
25
 
    MatchesStructure,
26
 
)
 
21
from testtools.matchers import MatchesStructure
27
22
from testtools.testcase import ExpectedException
28
23
 
29
24
 
184
179
            reload_object(subnet).vlan, fabric.get_default_vlan())
185
180
 
186
181
 
187
 
class TestVLANConfigureDHCP(MAASServerTestCase):
188
 
 
189
 
    def _regex(self, string):
190
 
        """Returns an escaped regular expression for the given string, which
191
 
        will match the given string anywhere in the input to the regex.
192
 
        """
193
 
        return ".*" + re.escape(string) + ".*"
194
 
 
195
 
    def test__unconfigures_dhcp(self):
196
 
        primary = factory.make_RackController()
197
 
        secondary = factory.make_RackController()
198
 
        vlan = factory.make_VLAN()
199
 
        vlan.dhcp_on = True
200
 
        vlan.primary_rack = primary
201
 
        vlan.secondary_rack = secondary
202
 
        vlan.configure_dhcp([])
203
 
        self.assertThat(vlan.dhcp_on, Equals(False))
204
 
        self.assertThat(vlan.primary_rack, Is(None))
205
 
        self.assertThat(vlan.secondary_rack, Is(None))
206
 
 
207
 
    def test__configures_dhcp_with_one_controller(self):
208
 
        primary = factory.make_RackController()
209
 
        secondary = factory.make_RackController()
210
 
        vlan = factory.make_VLAN()
211
 
        vlan.dhcp_on = False
212
 
        vlan.primary_rack = primary
213
 
        vlan.secondary_rack = secondary
214
 
        vlan.configure_dhcp([primary])
215
 
        self.assertThat(vlan.dhcp_on, Equals(True))
216
 
        self.assertThat(vlan.primary_rack, Is(primary))
217
 
        self.assertThat(vlan.secondary_rack, Is(None))
218
 
 
219
 
    def test__configures_dhcp_with_two_controllers(self):
220
 
        primary = factory.make_RackController()
221
 
        secondary = factory.make_RackController()
222
 
        vlan = factory.make_VLAN()
223
 
        vlan.configure_dhcp([primary, secondary])
224
 
        self.assertThat(vlan.dhcp_on, Equals(True))
225
 
        self.assertThat(vlan.primary_rack, Is(primary))
226
 
        self.assertThat(vlan.secondary_rack, Is(secondary))
227
 
 
228
 
    def test__rejects_non_list(self):
229
 
        vlan = factory.make_VLAN()
230
 
        with ExpectedException(
231
 
                AssertionError, self._regex(VLAN.MUST_SPECIFY_LIST_ERROR)):
232
 
            vlan.configure_dhcp(1)
233
 
 
234
 
    def test__rejects_three_item_list(self):
235
 
        rack1 = factory.make_RackController()
236
 
        rack2 = factory.make_RackController()
237
 
        rack3 = factory.make_RackController()
238
 
        vlan = factory.make_VLAN()
239
 
        with ExpectedException(
240
 
                ValueError, self._regex(
241
 
                    VLAN.INVALID_NUMBER_OF_CONTROLLERS_ERROR % 3)):
242
 
            vlan.configure_dhcp([rack1, rack2, rack3])
243
 
 
244
 
    def test__rejects_list_with_duplicate_items(self):
245
 
        rack = factory.make_RackController()
246
 
        vlan = factory.make_VLAN()
247
 
        with ExpectedException(
248
 
                ValidationError, self._regex(VLAN.DUPLICATE_CONTROLLER_ERROR)):
249
 
            vlan.configure_dhcp([rack, rack])
250
 
 
251
 
 
252
182
class TestVLANVidValidation(MAASServerTestCase):
253
183
 
254
184
    scenarios = [