Example #1
0
 def test_cluster_get_by_name(self):
     """Getting a cluster by name will include backends if not specified."""
     cluster = utils.create_cluster(self.ctxt, name='cluster@backend')
     # Get without the backend
     db_cluster = db.cluster_get(self.ctxt, name='cluster')
     self.assertEqual(cluster.id, db_cluster.id)
     # Get with the backend detail
     db_cluster = db.cluster_get(self.ctxt, name='cluster@backend')
     self.assertEqual(cluster.id, db_cluster.id)
Example #2
0
 def test_cluster_get_by_name(self):
     """Getting a cluster by name will include backends if not specified."""
     cluster = utils.create_cluster(self.ctxt, name='cluster@backend')
     # Get without the backend
     db_cluster = db.cluster_get(self.ctxt, name='cluster')
     self.assertEqual(cluster.id, db_cluster.id)
     # Get with the backend detail
     db_cluster = db.cluster_get(self.ctxt, name='cluster@backend')
     self.assertEqual(cluster.id, db_cluster.id)
Example #3
0
 def test_cluster_update(self):
     """Test basic cluster update."""
     cluster = self._create_cluster()
     self.assertFalse(cluster.disabled)
     db.cluster_update(self.ctxt, cluster.id, {"disabled": True})
     db_cluster = db.cluster_get(self.ctxt, cluster.id)
     self.assertTrue(db_cluster.disabled)
Example #4
0
 def test_cluster_get_with_summary(self):
     """Test getting cluster with summary information."""
     cluster, svcs = self._create_populated_cluster(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)
Example #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)
Example #6
0
 def test_cluster_get_without_summary(self):
     """Test getting cluster without summary information."""
     cluster = self._create_cluster()
     db_cluster = db.cluster_get(self.ctxt, cluster.id)
     self.assertRaises(exc.DetachedInstanceError, getattr, db_cluster, "num_hosts")
     self.assertRaises(exc.DetachedInstanceError, getattr, db_cluster, "num_down_hosts")
     self.assertIsNone(db_cluster.last_heartbeat)
Example #7
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)
Example #8
0
 def test_cluster_update(self):
     """Test basic cluster update."""
     cluster = utils.create_cluster(self.ctxt)
     self.assertFalse(cluster.disabled)
     db.cluster_update(self.ctxt, cluster.id, {'disabled': True})
     db_cluster = db.cluster_get(self.ctxt, cluster.id)
     self.assertTrue(db_cluster.disabled)
Example #9
0
 def test_cluster_get_with_summary_empty_cluster(self):
     """Test getting empty cluster with summary information."""
     cluster = self._create_cluster()
     db_cluster = db.cluster_get(self.ctxt, cluster.id, services_summary=True)
     self.assertEqual(0, db_cluster.num_hosts)
     self.assertEqual(0, db_cluster.num_down_hosts)
     self.assertIsNone(db_cluster.last_heartbeat)
Example #10
0
 def test_cluster_get_is_up_on_empty_cluster(self):
     """Test is_up filter works on empty clusters."""
     cluster = utils.create_cluster(self.ctxt)
     db_cluster = db.cluster_get(self.ctxt, cluster.id, is_up=False)
     self.assertEqual(cluster.id, db_cluster.id)
     self.assertRaises(exception.ClusterNotFound,
                       db.cluster_get, self.ctxt, cluster.id, is_up=True)
Example #11
0
 def test_cluster_get_is_up_on_empty_cluster(self):
     """Test is_up filter works on empty clusters."""
     cluster = utils.create_cluster(self.ctxt)
     db_cluster = db.cluster_get(self.ctxt, cluster.id, is_up=False)
     self.assertEqual(cluster.id, db_cluster.id)
     self.assertRaises(exception.ClusterNotFound,
                       db.cluster_get, self.ctxt, cluster.id, is_up=True)
Example #12
0
 def test_cluster_update(self):
     """Test basic cluster update."""
     cluster = utils.create_cluster(self.ctxt)
     self.assertFalse(cluster.disabled)
     db.cluster_update(self.ctxt, cluster.id, {'disabled': True})
     db_cluster = db.cluster_get(self.ctxt, cluster.id)
     self.assertTrue(db_cluster.disabled)
Example #13
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)
Example #14
0
 def test_cluster_get_with_summary_empty_cluster(self):
     """Test getting empty cluster with summary information."""
     cluster = utils.create_cluster(self.ctxt)
     db_cluster = db.cluster_get(self.ctxt, cluster.id,
                                 services_summary=True)
     self.assertEqual(0, db_cluster.num_hosts)
     self.assertEqual(0, db_cluster.num_down_hosts)
     self.assertIsNone(db_cluster.last_heartbeat)
Example #15
0
 def test_cluster_get_without_summary(self):
     """Test getting cluster without summary information."""
     cluster = utils.create_cluster(self.ctxt)
     db_cluster = db.cluster_get(self.ctxt, cluster.id)
     self.assertRaises(exc.DetachedInstanceError,
                       getattr, db_cluster, 'num_hosts')
     self.assertRaises(exc.DetachedInstanceError,
                       getattr, db_cluster, 'num_down_hosts')
     self.assertIsNone(db_cluster.last_heartbeat)
Example #16
0
 def test_cluster_destroy(self):
     """Test basic cluster destroy."""
     cluster = utils.create_cluster(self.ctxt)
     # On creation race_preventer is marked with a 0
     self.assertEqual(0, cluster.race_preventer)
     db.cluster_destroy(self.ctxt, cluster.id)
     db_cluster = db.cluster_get(self.ctxt, cluster.id, read_deleted='yes')
     self.assertTrue(db_cluster.deleted)
     self.assertIsNotNone(db_cluster.deleted_at)
     # On deletion race_preventer is marked with the id
     self.assertEqual(cluster.id, db_cluster.race_preventer)
Example #17
0
 def test_cluster_destroy(self):
     """Test basic cluster destroy."""
     cluster = utils.create_cluster(self.ctxt)
     # On creation race_preventer is marked with a 0
     self.assertEqual(0, cluster.race_preventer)
     db.cluster_destroy(self.ctxt, cluster.id)
     db_cluster = db.cluster_get(self.ctxt, cluster.id, read_deleted='yes')
     self.assertTrue(db_cluster.deleted)
     self.assertIsNotNone(db_cluster.deleted_at)
     # On deletion race_preventer is marked with the id
     self.assertEqual(cluster.id, db_cluster.race_preventer)
Example #18
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
     self._create_populated_cluster(2, name="cluster2")
     # We create our cluster with 2 up nodes and 1 down
     cluster, svcs = self._create_populated_cluster(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})
Example #19
0
    def test_cluster_create_and_get(self):
        """Basic cluster creation test."""
        values = self._default_cluster_values()
        cluster = db.cluster_create(self.ctxt, values)
        values["last_heartbeat"] = None
        self.assertEqual(0, cluster.race_preventer)
        for k, v in values.items():
            self.assertEqual(v, getattr(cluster, k))

        db_cluster = db.cluster_get(self.ctxt, cluster.id, services_summary=True)
        for k, v in values.items():
            self.assertEqual(v, getattr(db_cluster, k))
        self.assertEqual(0, db_cluster.race_preventer)
Example #20
0
    def test_cluster_create_and_get(self):
        """Basic cluster creation test."""
        values = utils.default_cluster_values()
        cluster = db.cluster_create(self.ctxt, values)
        values['last_heartbeat'] = None
        self.assertEqual(0, cluster.race_preventer)
        for k, v in values.items():
            self.assertEqual(v, getattr(cluster, k))

        db_cluster = db.cluster_get(self.ctxt, cluster.id,
                                    services_summary=True)
        for k, v in values.items():
            self.assertEqual(v, getattr(db_cluster, k))
        self.assertEqual(0, db_cluster.race_preventer)
Example #21
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})
Example #22
0
def create_cluster(ctxt, **values):
    create_values = default_cluster_values()
    create_values.update(values)
    cluster = db.cluster_create(ctxt, create_values)
    return db.cluster_get(ctxt, cluster.id, services_summary=True)
Example #23
0
def create_cluster(ctxt, **values):
    create_values = default_cluster_values()
    create_values.update(values)
    cluster = db.cluster_create(ctxt, create_values)
    return db.cluster_get(ctxt, cluster.id, services_summary=True)
Example #24
0
 def test_cluster_get_services_on_empty_cluster(self):
     """Test get_services filter works on empty clusters."""
     cluster = utils.create_cluster(self.ctxt)
     db_cluster = db.cluster_get(self.ctxt, cluster.id, get_services=True)
     self.assertEqual(cluster.id, db_cluster.id)
     self.assertListEqual([], db_cluster.services)
Example #25
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)
Example #26
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)
Example #27
0
 def _create_cluster(self, **values):
     create_values = self._default_cluster_values()
     create_values.update(values)
     cluster = db.cluster_create(self.ctxt, create_values)
     return db.cluster_get(self.ctxt, cluster.id, services_summary=True)
Example #28
0
 def test_cluster_get_services_on_empty_cluster(self):
     """Test get_services filter works on empty clusters."""
     cluster = utils.create_cluster(self.ctxt)
     db_cluster = db.cluster_get(self.ctxt, cluster.id, get_services=True)
     self.assertEqual(cluster.id, db_cluster.id)
     self.assertListEqual([], db_cluster.services)
Example #29
0
 def _create_cluster(self, **values):
     create_values = self._default_cluster_values()
     create_values.update(values)
     cluster = db.cluster_create(self.ctxt, create_values)
     return db.cluster_get(self.ctxt, cluster.id, services_summary=True)