Ejemplo n.º 1
0
    def test_cluster_get_all_matches(self):
        """Basic test of get_all with a matching filter."""
        cluster1, svcs = utils.create_populated_cluster(self.ctxt, 3, 1)
        cluster2, svcs = utils.create_populated_cluster(self.ctxt, 3, 2,
                                                        name='cluster2')
        cluster3, svcs = utils.create_populated_cluster(self.ctxt, 3, 3,
                                                        name='cluster3')

        expected = {cluster1.id, cluster2.id}
        result = db.cluster_get_all(self.ctxt, is_up=True)
        self.assertEqual(len(expected), len(result))
        self.assertSetEqual(expected, {cluster.id for cluster in result})
Ejemplo n.º 2
0
    def test_cluster_get_all_matches(self):
        """Basic test of get_all with a matching filter."""
        cluster1, svcs = utils.create_populated_cluster(self.ctxt, 3, 1)
        cluster2, svcs = utils.create_populated_cluster(self.ctxt, 3, 2,
                                                        name='cluster2')
        cluster3, svcs = utils.create_populated_cluster(self.ctxt, 3, 3,
                                                        name='cluster3')

        expected = {cluster1.id, cluster2.id}
        result = db.cluster_get_all(self.ctxt, is_up=True)
        self.assertEqual(len(expected), len(result))
        self.assertSetEqual(expected, {cluster.id for cluster in result})
Ejemplo n.º 3
0
 def test_cluster_get_services(self):
     """Test services is properly populated on non empty cluster."""
     # We create another cluster to see we do the selection correctly
     utils.create_populated_cluster(self.ctxt, 2, name='cluster2')
     # We create our cluster with 2 up nodes and 1 down
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 1)
     # Add a deleted service to the cluster
     db.service_create(self.ctxt,
                       {'cluster_name': cluster.name,
                        'deleted': True})
     db_cluster = db.cluster_get(self.ctxt, name=cluster.name,
                                 get_services=True)
     self.assertEqual(3, len(db_cluster.services))
     self.assertSetEqual({svc.id for svc in svcs},
                         {svc.id for svc in db_cluster.services})
Ejemplo n.º 4
0
 def test_cluster_get_services(self):
     """Test services is properly populated on non empty cluster."""
     # We create another cluster to see we do the selection correctly
     utils.create_populated_cluster(self.ctxt, 2, name='cluster2')
     # We create our cluster with 2 up nodes and 1 down
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 1)
     # Add a deleted service to the cluster
     db.service_create(self.ctxt,
                       {'cluster_name': cluster.name,
                        'deleted': True})
     db_cluster = db.cluster_get(self.ctxt, name=cluster.name,
                                 get_services=True)
     self.assertEqual(3, len(db_cluster.services))
     self.assertSetEqual({svc.id for svc in svcs},
                         {svc.id for svc in db_cluster.services})
Ejemplo n.º 5
0
 def test_cluster_get_is_up_all_are_down(self):
     """Test that is_up filter works when all services are down."""
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 3)
     self.assertRaises(exception.ClusterNotFound,
                       db.cluster_get, self.ctxt, cluster.id, is_up=True)
     db_cluster = db.cluster_get(self.ctxt, name=cluster.name, is_up=False)
     self.assertEqual(cluster.id, db_cluster.id)
Ejemplo n.º 6
0
 def test_cluster_get_is_up_all_are_down(self):
     """Test that is_up filter works when all services are down."""
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 3)
     self.assertRaises(exception.ClusterNotFound,
                       db.cluster_get, self.ctxt, cluster.id, is_up=True)
     db_cluster = db.cluster_get(self.ctxt, name=cluster.name, is_up=False)
     self.assertEqual(cluster.id, db_cluster.id)
Ejemplo n.º 7
0
 def test_cluster_get_with_summary(self):
     """Test getting cluster with summary information."""
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 1)
     db_cluster = db.cluster_get(self.ctxt, cluster.id,
                                 services_summary=True)
     self.assertEqual(3, db_cluster.num_hosts)
     self.assertEqual(1, db_cluster.num_down_hosts)
     self.assertEqual(svcs[1].updated_at, db_cluster.last_heartbeat)
Ejemplo n.º 8
0
 def test_cluster_get_with_summary(self):
     """Test getting cluster with summary information."""
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 1)
     db_cluster = db.cluster_get(self.ctxt, cluster.id,
                                 services_summary=True)
     self.assertEqual(3, db_cluster.num_hosts)
     self.assertEqual(1, db_cluster.num_down_hosts)
     self.assertEqual(svcs[1].updated_at, db_cluster.last_heartbeat)
Ejemplo n.º 9
0
 def test_cluster_get_all_no_match(self):
     """Basic test of get_all with a non matching filter."""
     cluster1, svcs = utils.create_populated_cluster(self.ctxt, 3, 3)
     result = db.cluster_get_all(self.ctxt, is_up=True)
     self.assertListEqual([], result)
Ejemplo n.º 10
0
 def test_cluster_destroy_has_services(self):
     """Test that we cannot delete a cluster with non deleted services."""
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 1)
     self.assertRaises(exception.ClusterHasHosts,
                       db.cluster_destroy, self.ctxt, cluster.id)
Ejemplo n.º 11
0
 def test_cluster_get_by_num_hosts(self):
     """Test cluster_get by subquery field num_hosts."""
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 2)
     result = db.cluster_get(self.ctxt, num_hosts=3)
     self.assertEqual(cluster.id, result.id)
Ejemplo n.º 12
0
 def test_cluster_get_all_no_match(self):
     """Basic test of get_all with a non matching filter."""
     cluster1, svcs = utils.create_populated_cluster(self.ctxt, 3, 3)
     result = db.cluster_get_all(self.ctxt, is_up=True)
     self.assertListEqual([], result)
Ejemplo n.º 13
0
 def test_cluster_destroy_has_services(self):
     """Test that we cannot delete a cluster with non deleted services."""
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 1)
     self.assertRaises(exception.ClusterHasHosts,
                       db.cluster_destroy, self.ctxt, cluster.id)
Ejemplo n.º 14
0
 def test_cluster_get_by_num_hosts(self):
     """Test cluster_get by subquery field num_hosts."""
     cluster, svcs = utils.create_populated_cluster(self.ctxt, 3, 2)
     result = db.cluster_get(self.ctxt, num_hosts=3)
     self.assertEqual(cluster.id, result.id)