Beispiel #1
0
 def test_rejects_undersize_overlay(self):
     slash = random.randint(4, 28)
     with ExpectedException(ValidationError):
         factory.make_FanNetwork(
             underlay=factory.make_ipv4_network(slash=slash),
             overlay=factory.make_ipv4_network(slash=slash + 2),
         )
Beispiel #2
0
 def test_rejects_host_reserve_too_big(self):
     with ExpectedException(ValidationError):
         factory.make_FanNetwork(
             underlay=factory.make_ipv4_network(slash=16),
             overlay=factory.make_ipv4_network(slash=8),
             host_reserve=256,
         )
Beispiel #3
0
 def test_delete_403_when_not_admin(self):
     fannetwork = factory.make_FanNetwork()
     uri = get_fannetwork_uri(fannetwork)
     response = self.client.delete(uri)
     self.assertEqual(http.client.FORBIDDEN, response.status_code,
                      response.content)
     self.assertIsNotNone(reload_object(fannetwork))
Beispiel #4
0
 def test_updates_fannetwork(self):
     new_name = factory.make_name("fannetwork")
     fannetwork = factory.make_FanNetwork()
     form = FanNetworkForm(instance=fannetwork, data={"name": new_name})
     self.assertTrue(form.is_valid(), form.errors)
     form.save()
     self.assertEqual(new_name, reload_object(fannetwork).name)
Beispiel #5
0
 def test_stores_host_reserve(self):
     host_reserve = random.randint(1, 200)
     fannetwork = factory.make_FanNetwork(
         underlay=factory.make_ipv4_network(slash=16),
         overlay=factory.make_ipv4_network(slash=8),
         host_reserve=host_reserve)
     self.assertEqual(host_reserve, fannetwork.host_reserve)
Beispiel #6
0
 def test__admin_admin_returns_fannetwork(self):
     admin = factory.make_admin()
     fannetwork = factory.make_FanNetwork()
     self.assertEqual(
         fannetwork,
         FanNetwork.objects.get_fannetwork_or_404(fannetwork.id, admin,
                                                  NodePermission.admin))
Beispiel #7
0
 def test__user_view_returns_fannetwork(self):
     user = factory.make_User()
     fannetwork = factory.make_FanNetwork()
     self.assertEqual(
         fannetwork,
         FanNetwork.objects.get_fannetwork_or_404(fannetwork.id, user,
                                                  NodePermission.view))
Beispiel #8
0
 def test_update_admin_only(self):
     fannetwork = factory.make_FanNetwork()
     new_name = factory.make_name("fannetwork")
     uri = get_fannetwork_uri(fannetwork)
     response = self.client.put(uri, {"name": new_name})
     self.assertEqual(http.client.FORBIDDEN, response.status_code,
                      response.content)
Beispiel #9
0
 def test__admin_admin_returns_fannetwork(self):
     admin = factory.make_admin()
     fannetwork = factory.make_FanNetwork()
     self.assertEqual(
         fannetwork,
         FanNetwork.objects.get_fannetwork_or_404(fannetwork.id, admin,
                                                  NODE_PERMISSION.ADMIN))
Beispiel #10
0
 def test__user_view_returns_fannetwork(self):
     user = factory.make_User()
     fannetwork = factory.make_FanNetwork()
     self.assertEqual(
         fannetwork,
         FanNetwork.objects.get_fannetwork_or_404(fannetwork.id, user,
                                                  NODE_PERMISSION.VIEW))
Beispiel #11
0
 def test_delete_deletes_fannetwork(self):
     self.become_admin()
     fannetwork = factory.make_FanNetwork()
     uri = get_fannetwork_uri(fannetwork)
     response = self.client.delete(uri)
     self.assertEqual(http.client.NO_CONTENT, response.status_code,
                      response.content)
     self.assertIsNone(reload_object(fannetwork))
Beispiel #12
0
 def test_update(self):
     self.become_admin()
     fannetwork = factory.make_FanNetwork()
     new_name = factory.make_name("fannetwork")
     uri = get_fannetwork_uri(fannetwork)
     response = self.client.put(uri, {"name": new_name})
     self.assertEqual(http.client.OK, response.status_code,
                      response.content)
     self.assertEqual(new_name, json_load_bytes(response.content)["name"])
     self.assertEqual(new_name, reload_object(fannetwork).name)
Beispiel #13
0
    def test_read(self):
        fannetwork = factory.make_FanNetwork()
        uri = get_fannetwork_uri(fannetwork)
        response = self.client.get(uri)

        self.assertEqual(
            http.client.OK, response.status_code, response.content)
        parsed_fannetwork = json_load_bytes(response.content)
        self.assertThat(parsed_fannetwork, ContainsDict({
            "id": Equals(fannetwork.id),
            "name": Equals(fannetwork.name),
            }))
Beispiel #14
0
    def test_read(self):
        # Create specific fan networks so creation doesn't fail because of
        # randomness. Reported in bug lp:1512832.
        factory.make_FanNetwork(overlay="10.0.0.0/8", underlay="172.16.0.0/16")
        factory.make_FanNetwork(overlay="11.0.0.0/8", underlay="172.17.0.0/16")
        factory.make_FanNetwork(overlay="12.0.0.0/8", underlay="172.18.0.0/16")
        uri = get_fannetworks_uri()
        response = self.client.get(uri)

        self.assertEqual(http.client.OK, response.status_code,
                         response.content)
        expected_ids = [
            fannetwork.id for fannetwork in FanNetwork.objects.all()
        ]
        result_ids = [
            fannetwork["id"]
            for fannetwork in json_load_bytes(response.content)
        ]
        self.assertItemsEqual(expected_ids, result_ids)
Beispiel #15
0
 def test_rejects_overlapping_networks(self):
     with ExpectedException(ValidationError):
         factory.make_FanNetwork(underlay="10.0.0.0/8",
                                 overlay="10.0.1.0/24")
Beispiel #16
0
 def test_handler_path(self):
     fannetwork = factory.make_FanNetwork()
     self.assertEqual(
         "/MAAS/api/2.0/fannetworks/%s/" % fannetwork.id,
         get_fannetwork_uri(fannetwork),
     )
Beispiel #17
0
 def test_cannot_create_ipv6_fannetwork(self):
     with ExpectedException(ValidationError):
         factory.make_FanNetwork(underlay="2001:db8:1:1::/96",
                                 overlay="2001:db8:2:1::/64")
Beispiel #18
0
 def test_doest_require_name_on_update(self):
     fannetwork = factory.make_FanNetwork()
     form = FanNetworkForm(instance=fannetwork, data={})
     self.assertTrue(form.is_valid(), form.errors)
Beispiel #19
0
 def test_creates_fannetwork(self):
     name = factory.make_name("name")
     fannetwork = factory.make_FanNetwork(name=name)
     self.assertEqual(name, fannetwork.name)
Beispiel #20
0
 def test_can_delete_fannetwork(self):
     fannetwork = factory.make_FanNetwork()
     fannetwork.delete()
     self.assertItemsEqual([], FanNetwork.objects.filter(id=fannetwork.id))
Beispiel #21
0
 def test_rejects_invalid_bridge_name(self):
     bridge = factory.make_name(prefix="bridge", sep=".")
     with ExpectedException(ValidationError):
         factory.make_FanNetwork(bridge=bridge)
Beispiel #22
0
 def test__user_admin_raises_PermissionError(self):
     user = factory.make_User()
     fannetwork = factory.make_FanNetwork()
     with ExpectedException(PermissionDenied):
         FanNetwork.objects.get_fannetwork_or_404(fannetwork.id, user,
                                                  NodePermission.admin)
Beispiel #23
0
 def test_stores_off(self):
     off = factory.pick_bool()
     fannetwork = factory.make_FanNetwork(off=off)
     self.assertEqual(off, fannetwork.off)
Beispiel #24
0
 def test_stores_bridge(self):
     bridge = factory.make_name("bridge")
     fannetwork = factory.make_FanNetwork(bridge=bridge)
     self.assertEqual(bridge, fannetwork.bridge)
Beispiel #25
0
 def test_stores_dhcp(self):
     dhcp = factory.pick_bool()
     fannetwork = factory.make_FanNetwork(dhcp=dhcp)
     self.assertEqual(dhcp, fannetwork.dhcp)
Beispiel #26
0
 def test__user_edit_raises_PermissionError(self):
     user = factory.make_User()
     fannetwork = factory.make_FanNetwork()
     with ExpectedException(PermissionDenied):
         FanNetwork.objects.get_fannetwork_or_404(fannetwork.id, user,
                                                  NODE_PERMISSION.EDIT)
Beispiel #27
0
 def test_rejects_negative_host_reserve(self):
     with ExpectedException(ValidationError):
         factory.make_FanNetwork(host_reserve=-1)