Пример #1
0
    def create_cluster(self, api=True, exclude=None, **kwargs):
        cluster_data = {'name': 'cluster-api-' + str(randint(0, 1000000))}
        if api:
            cluster_data['release'] = self.create_release(api=False).id
        else:
            cluster_data['release'] = self.create_release(api=False)

        if kwargs:
            cluster_data.update(kwargs)

        if exclude and isinstance(exclude, list):
            for ex in exclude:
                try:
                    del cluster_data[ex]
                except KeyError as err:
                    logger.warning(err)
        if api:
            resp = self.app.post(reverse('ClusterCollectionHandler'),
                                 json.dumps(cluster_data),
                                 headers=self.default_headers)
            self.tester.assertEquals(resp.status, 201)
            cluster = json.loads(resp.body)
            self.clusters.append(self.db.query(Cluster).get(cluster['id']))
        else:
            cluster = Cluster()
            for field, value in cluster_data.iteritems():
                setattr(cluster, field, value)
            self.db.add(cluster)
            self.db.commit()
            self.clusters.append(cluster)
        return cluster
Пример #2
0
 def test_cluster_name_length(self):
     cluster_data = {
         'name': u'ю' * 2048,
         'fuel_version': '',
         'release_id': self.env.create_release(api=False).id
     }
     cluster = Cluster(**cluster_data)
     self.db.add(cluster)
     self.db.commit()
Пример #3
0
    def test_cluster_fuel_version_length(self):
        fuel_version = 'a' * 1024
        cluster_data = {
            'name': 'cluster-api-' + str(randint(0, 1000000)),
            'fuel_version': fuel_version,
            'release_id': self.env.create_release(api=False).id
        }

        cluster = Cluster(**cluster_data)
        self.db.add(cluster)
        self.db.commit()
    def get_invalid_data_context(self, obj):
        json_obj = jsonutils.dumps(obj)

        with self.assertRaises(errors.InvalidData) as context:
            with mock.patch('nailgun.db.sqlalchemy.models.Cluster.is_locked',
                            new_callable=mock.PropertyMock) \
                    as mocked_property:
                mocked_property.return_value = False
                cluster_mock = Cluster()
                self.validator(json_obj, cluster_mock)

        return context
Пример #5
0
    def POST(self):
        """:returns: JSONized Cluster object.
        :http: * 201 (cluster successfully created)
               * 400 (invalid cluster data specified)
               * 409 (cluster with such parameters already exists)
        """
        # It's used for cluster creating only.
        data = self.checked_data()

        cluster = Cluster()
        cluster.release = db().query(Release).get(data["release"])
        # TODO(NAME): use fields
        for field in ("name", "mode", "net_provider", "net_segment_type",
                      "status"):
            if data.get(field):
                setattr(cluster, field, data.get(field))
        db().add(cluster)
        db().commit()
        attributes = Attributes(
            editable=cluster.release.attributes_metadata.get("editable"),
            generated=cluster.release.attributes_metadata.get("generated"),
            cluster=cluster)
        attributes.generate_fields()

        netmanager = cluster.network_manager

        try:
            netmanager.create_network_groups(cluster.id)
            if cluster.net_provider == 'neutron':
                netmanager.create_neutron_config(cluster)

            cluster.add_pending_changes("attributes")
            cluster.add_pending_changes("networks")

            if 'nodes' in data and data['nodes']:
                nodes = db().query(Node).filter(Node.id.in_(
                    data['nodes'])).all()
                map(cluster.nodes.append, nodes)
                db().commit()
                for node in nodes:
                    netmanager.allow_network_assignment_to_all_interfaces(node)
                    netmanager.assign_networks_by_default(node)

            raise web.webapi.created(
                json.dumps(ClusterHandler.render(cluster), indent=4))
        except (errors.OutOfVLANs, errors.OutOfIPs, errors.NoSuitableCIDR,
                errors.InvalidNetworkPool) as e:
            # Cluster was created in this request,
            # so we no need to use ClusterDeletionManager.
            # All relations wiil be cascade deleted automaticly.
            # TODO(NAME): investigate transactions
            db().delete(cluster)

            raise web.badrequest(e.message)
Пример #6
0
    def POST(self):
        """:returns: JSONized Cluster object.
        :http: * 201 (cluster successfully created)
               * 400 (invalid cluster data specified)
               * 409 (cluster with such parameters already exists)
        """
        # It's used for cluster creating only.
        data = self.checked_data()

        cluster = Cluster()
        cluster.release = db().query(Release).get(data["release"])
        # TODO(NAME): use fields
        for field in (
            "name",
            "mode",
            "net_provider",
            "net_segment_type",
            "status"
        ):
            if data.get(field):
                setattr(cluster, field, data.get(field))
        db().add(cluster)
        db().commit()
        attributes = Attributes(
            editable=cluster.release.attributes_metadata.get("editable"),
            generated=cluster.release.attributes_metadata.get("generated"),
            cluster=cluster
        )
        attributes.generate_fields()

        netmanager = cluster.network_manager

        try:
            netmanager.create_network_groups(cluster.id)
            if cluster.net_provider == 'neutron':
                netmanager.create_neutron_config(cluster)

            cluster.add_pending_changes("attributes")
            cluster.add_pending_changes("networks")

            if 'nodes' in data and data['nodes']:
                nodes = db().query(Node).filter(
                    Node.id.in_(data['nodes'])
                ).all()
                map(cluster.nodes.append, nodes)
                db().commit()
                for node in nodes:
                    netmanager.assign_networks_by_default(node)

            raise web.webapi.created(json.dumps(
                ClusterHandler.render(cluster),
                indent=4
            ))
        except (
            errors.OutOfVLANs,
            errors.OutOfIPs,
            errors.NoSuitableCIDR,
            errors.InvalidNetworkPool
        ) as e:
            # Cluster was created in this request,
            # so we no need to use ClusterDeletionManager.
            # All relations wiil be cascade deleted automaticly.
            # TODO(NAME): investigate transactions
            db().delete(cluster)

            raise web.badrequest(e.message)