Exemplo n.º 1
0
    def test_grow_cluster(self):
        cluster = self.trove_clusters.first()
        trove_api.trove.cluster_get(IsA(http.HttpRequest), cluster.id)\
            .AndReturn(cluster)
        cluster_volume = 1
        flavor = self.flavors.first()
        cluster_flavor = flavor.id
        cluster_flavor_name = flavor.name
        instances = [
            cluster_manager.ClusterInstance("id1", "name1", cluster_flavor,
                                            cluster_flavor_name,
                                            cluster_volume, "master", None),
            cluster_manager.ClusterInstance("id2", "name2", cluster_flavor,
                                            cluster_flavor_name,
                                            cluster_volume, "slave", "master"),
            cluster_manager.ClusterInstance("id3", None, cluster_flavor,
                                            cluster_flavor_name,
                                            cluster_volume, None, None),
        ]

        manager = cluster_manager.ClusterInstanceManager(cluster.id)
        manager.instances = instances
        cluster_manager.get(cluster.id).MultipleTimes().AndReturn(manager)
        trove_api.trove.cluster_grow(IsA(http.HttpRequest),
                                     cluster.id,
                                     instances)
        self.mox.ReplayAll()

        url = reverse('horizon:project:database_clusters:cluster_grow_details',
                      args=[cluster.id])
        res = self.client.get(url)
        self.assertTemplateUsed(
            res, 'project/database_clusters/cluster_grow_details.html')
        table = res.context_data[
            "".join([tables.ClusterGrowInstancesTable.Meta.name, '_table'])]
        self.assertEqual(len(cluster.instances), len(table.data))

        action = "".join([tables.ClusterGrowInstancesTable.Meta.name, '__',
                          tables.ClusterGrowRemoveInstance.name, '__',
                          'id1'])
        self.client.post(url, {'action': action})
        self.assertEqual(len(cluster.instances) - 1, len(table.data))

        action = "".join([tables.ClusterGrowInstancesTable.Meta.name, '__',
                          tables.ClusterGrowAction.name, '__',
                          cluster.id])
        res = self.client.post(url, {'action': action})
        self.assertMessageCount(success=1)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 2
0
 def handle(self, request, data):
     try:
         flavor = trove_api.trove.flavor_get(request, data['flavor'])
         manager = cluster_manager.get(data['cluster_id'])
         manager.add_instance(str(uuid.uuid4()),
                              data.get('name', None),
                              data['flavor'],
                              flavor.name,
                              data['volume'],
                              data.get('type', None),
                              data.get('related_to', None))
     except Exception as e:
         redirect = reverse("horizon:project:database_clusters:index")
         exceptions.handle(request,
                           _('Unable to grow cluster. %s') % e.message,
                           redirect=redirect)
     return True
Exemplo n.º 3
0
 def action(self, request, datum_id):
     manager = cluster_manager.get(self.table.kwargs['cluster_id'])
     manager.delete_instance(datum_id)
Exemplo n.º 4
0
 def get_data(self):
     manager = cluster_manager.get(self.kwargs['cluster_id'])
     return manager.get_instances()