Ejemplo n.º 1
0
    def test_interface_rest(self, ):
        #regular iface creation with IP
        request = create_machine_creation_request(
            self.user,
            None,
            self.z_ib,
            self.env_pro,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server)
        machine = simplejson.loads(
            (MachineViewSet.as_view({"post": "create"})(request)).render().content)

        request = create_iface_creation_request(
            self.user,
            machine,
            self.vlan_man1,
            "6.6.6.6",)

        response = IfaceViewSet.as_view({"post": "create"})(request)
        response.render()
        self.assertEquals(
            201,
            response.status_code,
            "Not properly creating iface. (should: 201; does: %s) %s" %
                  (response.status_code, response.content))

        self.assertEquals(
            simplejson.loads(response.content)["ip"],
            "6.6.6.6",
            "Not properly creating ifaces when IP is assigned by user")

        # creating the same vlan for the same machine, should create it
        request = create_iface_creation_request(
            self.user,
            machine,
            self.vlan_man1)
        response = IfaceViewSet.as_view({"post": "create"})(request)
        self.assertEquals(
            201,
            response.status_code,
            "Not properly creating second iface on same machine and vlan. (should: 201; does: %s): %s" %
                (response.status_code, response.render().content))

        #regular iface creation without IP
        request = create_iface_creation_request(
            self.user,
            machine,
            self.vlan_man1)

        response = IfaceViewSet.as_view({"post": "create"})(request)
        response.render()
        self.assertEquals(
            201,
            response.status_code,
            "Not properly creating iface. (should: 201; does: %s) %s" %
                (response.status_code, response.content))
Ejemplo n.º 2
0
    def off_test_many_machines_for_one_iface(self, ):
        #TODO write test_many_machines_for_one_iface
        request = create_machine_creation_request(
            self.user,
            None,
            self.z_ib,
            self.env_pro,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server)
        machine1 = simplejson.loads(
            (MachineViewSet.as_view({"post": "create"})(request)).render().content)

        request = create_machine_creation_request(
            self.user,
            None,
            self.z_ib,
            self.env_pro,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server)
        machine2 = simplejson.loads(
            (MachineViewSet.as_view({"post": "create"})(request)).render().content)

        request = create_iface_creation_request(
            self.user,
            machine1,
            self.vlan_man1)
        response = IfaceViewSet.as_view({"post": "create"})(request)

        iface = simplejson.loads(response.render().content)

        requestfactory = RequestFactory()
        data = simplejson.dumps({
            "machine": reverse("iface-detail", args=[machine1["id"], ]),
        })
        request = requestfactory.post(
            reverse("iface-list"),
            data=data,
            content_type="application/json", )

        request.user = user
        request.session = {}
        print data
Ejemplo n.º 3
0
    def test_excluded_ip_ranges(self, ):

        #create an ip range who's first IP is not suitable for the assigned vlan
        request = create_excluded_ip_range_request(
            self.user,
            "172.21.200.10",
            "172.21.229.10",
            self.vlan_patio)

        func = ExcludedIPRangeViewSet.as_view({"post": "create"})
        self.assertRaises(
            ipaddr.AddressValueError,
            func, request,
            "creating an excluded ip range, not properly checking if first ip is valid for assigned vlan")

        #create an ip range who's second IP is not suitable for the assigned vlan
        request = create_excluded_ip_range_request(
            self.user,
            "172.21.229.10",
            "172.21.200.10",
            self.vlan_patio)

        self.assertRaises(
            ipaddr.AddressValueError,
            func, request,
            "creating an excluded ip range, not properly checking if second ip is valid for assigned vlan")

        #create an ip range correctly for vlan addressing with one IP
        request = create_excluded_ip_range_request(
            self.user,
            "172.21.228.10",
            "172.21.228.10",
            self.vlan_patio)

        response = (ExcludedIPRangeViewSet.as_view({"post": "create"})(request)).render()
        eir = simplejson.loads(response.content)

        self.assertEquals(
            201,
            response.status_code,
            "Is not properly creating excluded_ip_ranges (single IP)")

        #create an ip range correctly for vlan addressing with more than one IP
        request = create_excluded_ip_range_request(
            self.user,
            "172.21.228.1",
            "172.21.228.8",
            self.vlan_patio)

        response = (ExcludedIPRangeViewSet.as_view({"post": "create"})(request)).render()
        eir = simplejson.loads(response.content)
        self.assertEquals(
            201,
            response.status_code,
            "Is not properly creating excluded_ip_ranges (more than one IP)")

        #does it respect excluded ranges at iface creation??
        request = create_machine_creation_request(
            self.user,
            None,
            self.z_ib,
            self.env_pro,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server)
        machine = simplejson.loads(
            (MachineViewSet.as_view({"post": "create"})(request)).render().content)

        request = create_iface_creation_request(
            self.user,
            machine,
            self.vlan_patio)
        print request
        response = IfaceViewSet.as_view({"post": "create"})(request)
        iface = simplejson.loads(response.render().content)

        print iface
        self.assertEquals(
            iface["ip"],
            "172.21.228.9",
            "Creating an iface is not looking at created excluded_ip_ranges")

        request = create_iface_creation_request(
            self.user,
            machine,
            self.vlan_patio)

        response = IfaceViewSet.as_view({"post": "create"})(request)
        iface = simplejson.loads(response.render().content)

        print iface
        self.assertEquals(
            iface["ip"],
            "172.21.228.11",
            "Creating an iface is not looking at created excluded_ip_ranges")