コード例 #1
0
ファイル: tests.py プロジェクト: jpardobl/naman
    def test_alta_router(self, ):
        request = create_machine_creation_request(
            self.user,
            None,
            self.z_ib,
            self.env_pro,
            self.role_ce,
            self.os_lin,
            mtype=self.mtype_router,
            hostname="CE_MAN1"
        )
        response = MachineViewSet.as_view({"post": "create"})(request).render()
        self.assertEquals(
            201,
            response.status_code,
            "Not properly return status after machine creation(should:201;does:%s" % response.status_code)

        machine = simplejson.loads(response.content)
        self.assertEquals(
            "CE_MAN1",
            machine["hostname"],
            "Not properly creating hostnames (should: %s; does: %s)" % (
                "CE_MAN1",
                machine["hostname"],
            )
        )
コード例 #2
0
ファイル: tests.py プロジェクト: jpardobl/naman
    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))
コード例 #3
0
ファイル: tests.py プロジェクト: jpardobl/naman
    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
コード例 #4
0
ファイル: tests.py プロジェクト: jpardobl/naman
 def test_alta_balanceador(self, ):
     request = create_machine_creation_request(
         self.user,
         None,
         self.z_ib,
         self.env_pro,
         self.role_bal,
         self.os_lin,
         mtype=self.mtype_router,
         hostname="bigip1"
     )
     response = MachineViewSet.as_view({"post": "create"})(request).render()
     self.assertEquals(
         201,
         response.status_code,
         "Not properly return status after load balancer creation(should:201;does:%s" % response.status_code)
     machine = simplejson.loads(response.content)
     self.assertEquals(
         machine["hostname"],
         "bigip1",
         "Not properly initializing load balancer hostname",
     )
コード例 #5
0
ファイル: tests.py プロジェクト: jpardobl/naman
    def off_test_no_auto_name(self, ):

        #creating machine without autoname and not sending hostname
        request = create_machine_creation_request(
            self.user,
            None,
            self.z_ib,
            self.env_pro,
            self.role_ce,
            self.os_lin,
            mtype=self.mtype_router)

        try:
            MachineViewSet.as_view({"post": "create"})(request)
            assert("No properly creating machine with no auto name. No hostname has been sent, it should return 400, does: %s" % response.status_code)
        except IntegrityError:
            pass

        #creating machine that should increment counter
        request = create_machine_creation_request(
            self.user,
            self.project_ibcom,
            self.z_ib,
            self.env_des,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server)

        response = MachineViewSet.as_view({"post": "create"})(request).render()
        self.assertEquals(
            201,
            response.status_code,
            "Not properly return status after machine creation(should:201;does:%s" % response.status_code)

        proper_name = ("%s%s%s%s1" % (
            self.role_bd.code,
            self.project_ibcom.code,
            self.os_lin.code,
            self.env_des.code)).lower()

        machine = simplejson.loads(response.content)
        self.assertEquals(
            proper_name,
            machine["hostname"],
            "Not properly creating hostnames (should: %s; does: %s)" % (
                proper_name,
                machine["hostname"],
            )
        )

        # creating machine that needs a specified hostname, even though there is
        # a previous cluster server with same properties
        request = create_machine_creation_request(
            self.user,
            self.project_ibcom,
            self.z_ib,
            self.env_des,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server_standalone,
            hostname="bdibcldes")

        response = MachineViewSet.as_view({"post": "create"})(request).render()
        self.assertEquals(
            201,
            response.status_code,
            "Not properly return status after machine creation(should:201;does:%s)" % response.status_code)

        proper_name = "bdibcldes"

        machine = simplejson.loads(response.content)
        self.assertEquals(
            proper_name,
            machine["hostname"],
            "Not properly creating hostnames (should: %s; does: %s)" % (
                proper_name,
                machine["hostname"],
            )
        )
        #creating the other cluster machine
        request = create_machine_creation_request(
            self.user,
            self.project_ibcom,
            self.z_ib,
            self.env_des,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server)

        response = MachineViewSet.as_view({"post": "create"})(request).render()
        self.assertEquals(
            201,
            response.status_code,
            "Not properly return status after machine creation(should:201;does:%s" % response.status_code)

        proper_name = ("%s%s%s%s2" % (
            self.role_bd.code,
            self.project_ibcom.code,
            self.os_lin.code,
            self.env_des.code)).lower()

        machine = simplejson.loads(response.content)
        self.assertEquals(
            proper_name,
            machine["hostname"],
            "Not properly creating hostnames (should: %s; does: %s)" % (
                proper_name,
                machine["hostname"],
            )
        )
コード例 #6
0
ファイル: tests.py プロジェクト: jpardobl/naman
    def test_standalone_hostnames_rest(self, ):

        #creating a regular server for CRM project
        request = create_machine_creation_request(
            self.user,
            self.project_crm,
            self.z_ib,
            self.env_des,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server,
        )
        response = MachineViewSet.as_view({"post": "create"})(request).render()
        proper_name = ("%s%s%s%s1" % (
            self.role_bd.code,
            self.project_crm.code,
            self.os_lin.code,
            self.env_des.code)).lower()

        machine = simplejson.loads(response.content)
        self.assertEquals(
            proper_name,
            machine["hostname"],
            "Not properly creating cluster server hostname (should: %s; does: %s)" % (
                proper_name,
                machine["hostname"],
            )
        )
        #creating an standalone server once already exists a regular server with same properties
        request = create_machine_creation_request(
            self.user,
            self.project_crm,
            self.z_ib,
            self.env_des,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server_standalone
        )
        response = MachineViewSet.as_view({"post": "create"})(request).render()
        proper_name = ("%s%s%s%s" % (
            self.role_bd.code,
            self.project_crm.code,
            self.os_lin.code,
            self.env_des.code)).lower()

        machine = simplejson.loads(response.content)
        self.assertEquals(
            proper_name,
            machine["hostname"],
            "Not properly creating standalone server hostname when a cluster server exist for the same properties (should: %s; does: %s)" % (
                proper_name,
                machine["hostname"],
            )
        )

        #creating the second regular server once already exists a
        #regular server and a standalone server with same properties
        request = create_machine_creation_request(
            self.user,
            self.project_crm,
            self.z_ib,
            self.env_des,
            self.role_bd,
            self.os_lin,
            mtype=self.mtype_server
        )
        response = MachineViewSet.as_view({"post": "create"})(request).render()
        proper_name = ("%s%s%s%s2" % (
            self.role_bd.code,
            self.project_crm.code,
            self.os_lin.code,
            self.env_des.code)).lower()

        machine = simplejson.loads(response.content)
        self.assertEquals(
            proper_name,
            machine["hostname"],
            "Not properly creating hostnames (should: %s; does: %s)" % (
                proper_name,
                machine["hostname"],
            )
        )
コード例 #7
0
ファイル: tests.py プロジェクト: jpardobl/naman
    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")