Esempio n. 1
0
    def launch_verify(self, cluster):
        try:
            data = self.validator.validate_networks_update(web.data())
        except web.webapi.badrequest as exc:
            task = Task.create({
                "name": "check_networks",
                "cluster_id": cluster.id
            })
            TaskHelper.set_error(task.uuid, exc.data)
            logger.error(traceback.format_exc())

            json_task = build_json_response(Task.to_json(task))
            raise web.accepted(data=json_task)

        data["networks"] = [
            n for n in data["networks"] if n.get("name") != "fuelweb_admin"
        ]

        vlan_ids = [{
                    'name': n['name'],
                    'vlans': cluster.network_manager.generate_vlan_ids_list(
                        data, cluster, n)
                    } for n in data['networks']]

        task_manager = VerifyNetworksTaskManager(cluster_id=cluster.id)
        try:
            task = task_manager.execute(data, vlan_ids)
        except errors.CantRemoveOldVerificationTask:
            raise web.badrequest("You cannot delete running task manually")
        return Task.to_json(task)
Esempio n. 2
0
    def create(cls, data):
        topic = data.get("topic")
        node_id = data.get("node_id")
        task_uuid = data.pop("task_uuid", None)
        message = data.get("message")

        if topic == 'discover' and node_id is None:
            raise errors.CannotFindNodeIDForDiscovering(
                "No node id in discover notification"
            )

        if "datetime" not in data:
            data["datetime"] = datetime.now()

        task = None
        exist = None
        if task_uuid:
            task = Task.get_by_uuid(task_uuid)
            if task and node_id:
                exist = NotificationCollection.filter_by(
                    query=None,
                    node_id=node_id,
                    message=message,
                    task_id=task.id
                ).first()

        if not exist:
            super(Notification, cls).create(data)
            logger.info(
                u"Notification: topic: {0} message: {1}".format(
                    data.get("topic"),
                    data.get("message")
                )
            )
    def create(cls, data):
        """Creates and returns a notification instance.

        :param data: a dict with notification data
        :returns: a notification instance in case of notification
            doesn't exist; otherwise - None
        """
        topic = data.get("topic")
        node_id = data.get("node_id")
        task_uuid = data.pop("task_uuid", None)
        message = data.get("message")

        if topic == "discover" and node_id is None:
            raise errors.CannotFindNodeIDForDiscovering("No node id in discover notification")

        if "datetime" not in data:
            data["datetime"] = datetime.now()

        exist = None
        if task_uuid:
            task = Task.get_by_uuid(task_uuid)
            if task and node_id:
                exist = NotificationCollection.count(
                    NotificationCollection.filter_by(None, node_id=node_id, message=message, task_id=task.id)
                )

        if not exist:
            notification = super(Notification, cls).create(data)
            logger.info(u"Notification: topic: {0} message: {1}".format(data.get("topic"), data.get("message")))
            return notification
        return None
Esempio n. 4
0
    def test_task_deploy_specified_tasks(self, rpc_cast, *_):
        compute = next(
            (x for x in self.env.nodes if 'compute' in x.roles), None
        )
        self.assertIsNotNone(compute)
        compute.status = consts.NODE_STATUSES.provisioned
        compute.pending_addition = False
        self.db.flush()

        resp = self.app.put(
            reverse(
                'DeploySelectedNodesWithTasks',
                kwargs={'cluster_id': self.cluster.id}
            ) + '?nodes={0}'.format(compute.uid),
            params='["deploy_legacy"]',
            headers=self.default_headers
        )
        self.assertNotEqual(
            consts.TASK_STATUSES.error,
            Task.get_by_uuid(
                uuid=resp.json_body['uuid'], fail_if_not_found=True
            ).status
        )

        links = rpc_cast.call_args[0][1]['args']['tasks_graph']
        self.assertItemsEqual(
            ["deploy_legacy"],
            (task["id"] for task in links[compute.uid]
             if task['type'] != consts.ORCHESTRATOR_TASK_TYPES.skipped)
        )
Esempio n. 5
0
    def test_task_deploy_specified_tasks(self, rpc_cast, *_):
        compute = next(
            (x for x in self.env.nodes if 'compute' in x.roles), None
        )
        self.assertIsNotNone(compute)
        compute.status = consts.NODE_STATUSES.provisioned
        compute.pending_addition = False
        self.db.flush()

        resp = self.app.put(
            reverse(
                'DeploySelectedNodesWithTasks',
                kwargs={'cluster_id': self.cluster.id}
            ) + '?nodes={0}'.format(compute.uid),
            params='["deploy_legacy"]',
            headers=self.default_headers
        )
        self.assertNotEqual(
            consts.TASK_STATUSES.error,
            Task.get_by_uuid(
                uuid=resp.json_body['uuid'], fail_if_not_found=True
            ).status
        )

        links = rpc_cast.call_args[0][1]['args']['tasks_graph']
        self.assertItemsEqual(
            ["deploy_legacy"],
            (task["id"] for task in links[compute.uid]
             if task['type'] != consts.ORCHESTRATOR_TASK_TYPES.skipped)
        )
Esempio n. 6
0
    def create(cls, data):
        """Creates and returns a notification instance.

        :param data: a dict with notification data
        :returns: a notification instance in case of notification
            doesn't exist; otherwise - None
        """
        topic = data.get("topic")
        node_id = data.get("node_id")
        task_uuid = data.pop("task_uuid", None)
        message = data.get("message")

        if topic == 'discover' and node_id is None:
            raise errors.CannotFindNodeIDForDiscovering(
                "No node id in discover notification")

        if "datetime" not in data:
            data["datetime"] = datetime.now()

        exist = None
        if task_uuid:
            task = Task.get_by_uuid(task_uuid)
            if task and node_id:
                exist = NotificationCollection.count(
                    NotificationCollection.filter_by(None,
                                                     node_id=node_id,
                                                     message=message,
                                                     task_id=task.id))

        if not exist:
            notification = super(Notification, cls).create(data)
            logger.info(u"Notification: topic: {0} message: {1}".format(
                data.get("topic"), data.get("message")))
            return notification
        return None
Esempio n. 7
0
    def PUT(self):
        """Starts capacity data generation.

        :returns: JSONized Task object.
        :http: * 202 (setup task created and started)
        """
        manager = GenerateCapacityLogTaskManager()
        task = manager.execute()

        raise self.http(202, Task.to_json(task))
Esempio n. 8
0
    def PUT(self):
        """Starts capacity data generation.

        :returns: JSONized Task object.
        :http: * 202 (setup task created and started)
        """
        manager = GenerateCapacityLogTaskManager()
        task = manager.execute()

        data = build_json_response(Task.to_json(task))
        raise web.accepted(data=data)
Esempio n. 9
0
 def PUT(self):
     """:returns: JSONized Task object.
     :http: * 200 (task successfully executed)
            * 400 (failed to execute task)
     """
     try:
         task_manager = DumpTaskManager()
         task = task_manager.execute()
     except Exception as exc:
         logger.warn(u'DumpTask: error while execution '
                     'dump environment task: {0}'.format(str(exc)))
         raise self.http(400, str(exc))
     raise self.http(202, Task.to_json(task))
Esempio n. 10
0
 def PUT(self):
     """:returns: JSONized Task object.
     :http: * 200 (task successfully executed)
            * 400 (failed to execute task)
     """
     try:
         task_manager = DumpTaskManager()
         task = task_manager.execute()
     except Exception as exc:
         logger.warn(u'DumpTask: error while execution '
                     'dump environment task: {0}'.format(str(exc)))
         raise self.http(400, str(exc))
     raise self.http(202, Task.to_json(task))
    def PUT(self, cluster_id):
        """:returns: JSONized Task object.
        :http: * 202 (network checking task created)
               * 404 (cluster not found in db)
        """
        data = jsonutils.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)
        self.check_net_provider(cluster)

        self.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(
                        jsonutils.dumps(data)
                    )

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

                objects.Cluster.get_network_manager(
                    cluster
                ).update(cluster, data)
            except Exception as exc:
                # set task status to error and update its corresponding data
                data = {'status': 'error',
                        'progress': 100,
                        'message': six.text_type(exc)}
                objects.Task.update(task, data)

                logger.error(traceback.format_exc())

        #TODO(enchantner): research this behaviour
        if task.status == 'error':
            db().rollback()
        else:
            db().commit()

        raise self.http(202, Task.to_json(task))
Esempio n. 12
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())
        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)
        self.check_net_provider(cluster)

        self.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)
                    )

                NovaNetworkManager.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(Task.to_json(task))
        if task.status == 'error':
            db().rollback()
        else:
            db().commit()
        raise web.accepted(data=data)
Esempio n. 13
0
    def PUT(self, cluster_id):
        """:returns: JSONized Task object.
        :http: * 200 (task successfully executed)
               * 404 (cluster or nodes not found in db)
               * 400 (failed to execute task)
        """
        cluster = self.get_object_or_404(Cluster, cluster_id)
        nodes = self.get_nodes(cluster)

        try:
            task_manager = self.task_manager(cluster_id=cluster.id)
            task = task_manager.execute(nodes)
        except Exception as exc:
            logger.warn(u'Cannot execute {0} task nodes: {1}'.format(
                task_manager.__class__.__name__, traceback.format_exc()))
            raise self.http(400, message=str(exc))

        raise self.http(202, Task.to_json(task))
Esempio n. 14
0
    def PUT(self, cluster_id):
        """:returns: JSONized Task object.
        :http: * 200 (task successfully executed)
               * 404 (cluster or nodes not found in db)
               * 400 (failed to execute task)
        """
        cluster = self.get_object_or_404(Cluster, cluster_id)
        nodes = self.get_nodes(cluster)

        try:
            task_manager = self.task_manager(cluster_id=cluster.id)
            task = task_manager.execute(nodes)
        except Exception as exc:
            logger.warn(u'Cannot execute {0} task nodes: {1}'.format(
                task_manager.__class__.__name__, traceback.format_exc()))
            raise self.http(400, message=str(exc))

        raise self.http(202, Task.to_json(task))
Esempio n. 15
0
    def POST(self):
        """Starts Red Hat setup and download process

        :returns: JSONized Task object.
        :http: * 202 (setup task created and started)
               * 400 (invalid account data specified)
               * 404 (release not found in db)
        """
        data = self.checked_data()

        license_type = data.get("license_type")
        if license_type == 'rhsm':
            data["satellite"] = ""
            data["activation_key"] = ""

        release_data = {'release_id': data['release_id']}
        release_id = data.pop('release_id')
        release_db = db().query(Release).get(release_id)
        if not release_db:
            raise self.http(
                404, "No release with ID={0} found".format(release_id)
            )
        release_data['redhat'] = data
        release_data['release_name'] = release_db.name

        account = db().query(RedHatAccount).first()
        if account:
            db().query(RedHatAccount).update(data)
        else:
            account = RedHatAccount(**data)
            db().add(account)
        db().flush()

        task_manager = RedHatSetupTaskManager(release_data)
        try:
            task = task_manager.execute()
        except Exception as exc:
            logger.error(u'RedHatAccountHandler: error while execution'
                         ' Red Hat validation task: {0}'.format(str(exc)))
            logger.error(traceback.format_exc())
            raise self.http(400, message=str(exc))

        raise self.http(202, Task.to_json(task))
Esempio n. 16
0
    def POST(self):
        """Starts Red Hat setup and download process

        :returns: JSONized Task object.
        :http: * 202 (setup task created and started)
               * 400 (invalid account data specified)
               * 404 (release not found in db)
        """
        data = self.checked_data()

        license_type = data.get("license_type")
        if license_type == 'rhsm':
            data["satellite"] = ""
            data["activation_key"] = ""

        release_data = {'release_id': data['release_id']}
        release_id = data.pop('release_id')
        release_db = db().query(Release).get(release_id)
        if not release_db:
            raise self.http(404,
                            "No release with ID={0} found".format(release_id))
        release_data['redhat'] = data
        release_data['release_name'] = release_db.name

        account = db().query(RedHatAccount).first()
        if account:
            db().query(RedHatAccount).update(data)
        else:
            account = RedHatAccount(**data)
            db().add(account)
        db().flush()

        task_manager = RedHatSetupTaskManager(release_data)
        try:
            task = task_manager.execute()
        except Exception as exc:
            logger.error(u'RedHatAccountHandler: error while execution'
                         ' Red Hat validation task: {0}'.format(str(exc)))
            logger.error(traceback.format_exc())
            raise self.http(400, message=str(exc))

        raise self.http(202, Task.to_json(task))
Esempio n. 17
0
    def PUT(self, cluster_id):
        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)
        self.check_net_provider(cluster)

        self.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 'networking_parameters' in data:
                    self.validator.validate_neutron_params(
                        json.dumps(data),
                        cluster_id=cluster_id
                    )

                objects.Cluster.get_network_manager(
                    cluster
                ).update(cluster, data)
            except Exception as exc:
                TaskHelper.set_error(task.uuid, exc)
                logger.error(traceback.format_exc())

        #TODO(enchantner): research this behaviour
        if task.status == 'error':
            db().rollback()
        else:
            db().commit()

        raise self.http(202, Task.to_json(task))
Esempio n. 18
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())
        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)
        self.check_net_provider(cluster)

        self.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))

                objects.Cluster.get_network_manager(cluster).update(
                    cluster, data)
            except Exception as exc:
                TaskHelper.set_error(task.uuid, exc)
                logger.error(traceback.format_exc())

        #TODO(enchantner): research this behaviour
        if task.status == 'error':
            db().rollback()
        else:
            db().commit()

        raise self.http(202, Task.to_json(task))
Esempio n. 19
0
    def PUT(self, cluster_id):
        data = jsonutils.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)
        self.check_net_provider(cluster)

        self.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(
                        jsonutils.dumps(data)
                    )

                if 'networking_parameters' in data:
                    self.validator.validate_neutron_params(
                        jsonutils.dumps(data),
                        cluster_id=cluster_id
                    )

                objects.Cluster.get_network_manager(
                    cluster
                ).update(cluster, data)
            except Exception as exc:
                # set task status to error and update its corresponding data
                data = {'status': 'error',
                        'progress': 100,
                        'message': six.text_type(exc)}
                objects.Task.update(task, data)

                logger.error(traceback.format_exc())

        raise self.http(202, Task.to_json(task))
Esempio n. 20
0
    def launch_verify(self, cluster):
        data = self.validator.validate_networks_update(web.data())

        data["networks"] = [
            n for n in data["networks"] if n.get("name") != "fuelweb_admin"
        ]

        vlan_ids = [{
            'name':
            n['name'],
            'vlans':
            objects.Cluster.get_network_manager(
                cluster).generate_vlan_ids_list(data, cluster, n)
        } for n in data['networks']]

        task_manager = VerifyNetworksTaskManager(cluster_id=cluster.id)
        try:
            task = task_manager.execute(data, vlan_ids)
        except errors.CantRemoveOldVerificationTask:
            raise self.http(400, "You cannot delete running task manually")
        return Task.to_json(task)
Esempio n. 21
0
    def launch_verify(self, cluster):
        data = self.validator.validate_networks_update(web.data())

        data["networks"] = [
            n for n in data["networks"] if n.get("name") != "fuelweb_admin"
        ]

        vlan_ids = [{
                    'name': n['name'],
                    'vlans': objects.Cluster.get_network_manager(
                        cluster
                    ).generate_vlan_ids_list(
                        data, cluster, n)
                    } for n in data['networks']]

        task_manager = VerifyNetworksTaskManager(cluster_id=cluster.id)
        try:
            task = task_manager.execute(data, vlan_ids)
        except errors.CantRemoveOldVerificationTask:
            raise self.http(400, "You cannot delete running task manually")
        return Task.to_json(task)