Exemplo n.º 1
0
    def PUT(self, cluster_id):
        data = json.loads(web.data())
        cluster = self.get_object_or_404(Cluster, cluster_id)

        task_manager = CheckNetworksTaskManager(cluster_id=cluster.id)
        task = task_manager.execute(data)

        if task.status != 'error':
            try:
                if 'networks' in data:
                    network_configuration = self.validator.\
                        validate_networks_update(json.dumps(data))

                NetworkConfiguration.update(cluster, data)
            except web.webapi.badrequest as exc:
                TaskHelper.set_error(task.uuid, exc.data)
                logger.error(traceback.format_exc())
            except Exception as exc:
                TaskHelper.set_error(task.uuid, exc)
                logger.error(traceback.format_exc())

        data = build_json_response(TaskHandler.render(task))
        if task.status == 'error':
            db().rollback()
        else:
            db().commit()
        raise web.accepted(data=data)
Exemplo n.º 2
0
    def PUT(self, cluster_id):
        data = json.loads(web.data())
        cluster = self.get_object_or_404(Cluster, cluster_id)

        task_manager = CheckNetworksTaskManager(cluster_id=cluster.id)
        task = task_manager.execute(data)

        if task.status != 'error':
            if 'networks' in data:
                network_configuration = self.validator.\
                    validate_networks_update(json.dumps(data))
            try:
                NetworkConfiguration.update(cluster, data)
            except Exception as exc:
                err = str(exc)
                TaskHelper.update_task_status(task.uuid,
                                              status="error",
                                              progress=100,
                                              msg=err)
                logger.error(traceback.format_exc())

        data = build_json_response(TaskHandler.render(task))
        if task.status == 'error':
            self.db.rollback()
        else:
            self.db.commit()
        raise web.accepted(data=data)
Exemplo n.º 3
0
    def PUT(self, cluster_id):
        """:returns: JSONized Task object.
        :http: * 202 (network checking task created)
               * 404 (cluster not found in db)
        """
        data = json.loads(web.data())
        cluster = self.get_object_or_404(Cluster, cluster_id)

        task_manager = CheckNetworksTaskManager(cluster_id=cluster.id)
        task = task_manager.execute(data)

        if task.status != 'error':
            try:
                if 'networks' in data:
                    self.validator.validate_networks_update(json.dumps(data))

                NetworkConfiguration.update(cluster, data)
            except web.webapi.badrequest as exc:
                TaskHelper.set_error(task.uuid, exc.data)
                logger.error(traceback.format_exc())
            except Exception as exc:
                TaskHelper.set_error(task.uuid, exc)
                logger.error(traceback.format_exc())

        data = build_json_response(TaskHandler.render(task))
        if task.status == 'error':
            db().rollback()
        else:
            db().commit()
        raise web.accepted(data=data)
    def test_cluster_create_no_ip_addresses(self):
        """In this test we check that no error is occured
        if two clusters will have same networks updated to use
        full CIDR
        """
        cluster = self.env.create_cluster(api=True)
        cluster_db = self.db.query(Cluster).get(cluster["id"])
        cluster2 = self.env.create_cluster(api=True,
                                           release=cluster_db.release.id)
        cluster2_db = self.db.query(Cluster).get(cluster2["id"])

        for clstr in (cluster_db, cluster2_db):
            management_net = self.db.query(NetworkGroup).filter_by(
                name="management",
                cluster_id=clstr.id
            ).first()
            NetworkConfiguration.update(
                clstr,
                {
                    "networks": [
                        {
                            "network_size": 65536,
                            "name": "management",
                            "ip_ranges": [
                                ["192.168.0.2", "192.168.255.254"]
                            ],
                            "amount": 1,
                            "id": management_net.id,
                            "netmask": "255.255.255.0",
                            "cluster_id": clstr.id,
                            "vlan_start": 101,
                            "cidr": "192.168.0.0/16",
                            "gateway": "192.168.0.1"
                        }
                    ]
                }
            )

        cluster1_nets = self._get_cluster_networks(cluster["id"])
        cluster2_nets = self._get_cluster_networks(cluster2["id"])

        for net1, net2 in zip(cluster1_nets, cluster2_nets):
            for f in ('cluster_id', 'id'):
                del net1[f]
                del net2[f]

        self.assertEquals(cluster1_nets, cluster2_nets)
    def test_cluster_create_no_ip_addresses(self):
        """In this test we check that no error is occured
        if two clusters will have same networks updated to use
        full CIDR
        """
        cluster = self.env.create_cluster(api=True)
        cluster_db = self.db.query(Cluster).get(cluster["id"])
        cluster2 = self.env.create_cluster(api=True,
                                           release=cluster_db.release.id)
        cluster2_db = self.db.query(Cluster).get(cluster2["id"])

        for clstr in (cluster_db, cluster2_db):
            management_net = self.db.query(NetworkGroup).filter_by(
                name="management",
                cluster_id=clstr.id
            ).first()
            NetworkConfiguration.update(
                clstr,
                {
                    "networks": [
                        {
                            "network_size": 65536,
                            "name": "management",
                            "ip_ranges": [
                                ["192.168.0.2", "192.168.255.254"]
                            ],
                            "amount": 1,
                            "id": management_net.id,
                            "netmask": "255.255.255.0",
                            "cluster_id": clstr.id,
                            "vlan_start": 101,
                            "cidr": "192.168.0.0/16",
                            "gateway": "192.168.0.1"
                        }
                    ]
                }
            )

        cluster1_nets = self._get_cluster_networks(cluster["id"])
        cluster2_nets = self._get_cluster_networks(cluster2["id"])

        for net1, net2 in zip(cluster1_nets, cluster2_nets):
            for f in ('cluster_id', 'id'):
                del net1[f]
                del net2[f]

        self.assertEquals(cluster1_nets, cluster2_nets)
    def PUT(self, cluster_id):
        """:returns: JSONized Task object.
        :http: * 202 (network checking task created)
               * 404 (cluster not found in db)
        """
        data = json.loads(web.data())
        if data.get("networks"):
            data["networks"] = [
                n for n in data["networks"] if n.get("name") != "fuelweb_admin"
            ]

        cluster = self.get_object_or_404(Cluster, cluster_id)

        check_if_network_configuration_locked(cluster)

        task_manager = CheckNetworksTaskManager(cluster_id=cluster.id)
        task = task_manager.execute(data)

        if task.status != 'error':
            try:
                if 'networks' in data:
                    self.validator.validate_networks_update(
                        json.dumps(data)
                    )

                if 'dns_nameservers' in data:
                    self.validator.validate_dns_servers_update(
                        json.dumps(data)
                    )

                NetworkConfiguration.update(cluster, data)
            except web.webapi.badrequest as exc:
                TaskHelper.set_error(task.uuid, exc.data)
                logger.error(traceback.format_exc())
            except Exception as exc:
                TaskHelper.set_error(task.uuid, exc)
                logger.error(traceback.format_exc())

        data = build_json_response(TaskHandler.render(task))
        if task.status == 'error':
            db().rollback()
        else:
            db().commit()
        raise web.accepted(data=data)
    def test_cluster_create_no_ip_addresses(self):
        cluster = self.env.create_cluster(api=True)
        cluster_db = self.db.query(Cluster).get(cluster["id"])
        management_net = self.db.query(NetworkGroup).filter_by(
            name="management",
            cluster_id=cluster["id"]
        ).first()
        NetworkConfiguration.update(
            cluster_db,
            {
                "networks": [
                    {
                        "network_size": 65536,
                        "name": "management",
                        "ip_ranges": [
                            ["192.168.0.2", "192.168.255.254"]
                        ],
                        "amount": 1,
                        "id": management_net.id,
                        "netmask": "255.255.255.0",
                        "cluster_id": cluster["id"],
                        "vlan_start": 101,
                        "cidr": "192.168.0.0/16",
                        "gateway": "192.168.0.1"
                    }
                ]
            }
        )

        resp = self.app.post(
            reverse('ClusterCollectionHandler'),
            json.dumps({
                'name': 'cluster-name',
                'release': cluster_db.release.id,
            }),
            headers=self.default_headers,
            expect_errors=True
        )
        self.assertEquals(400, resp.status)