def test_cluster_get_all_passes_parameters(self, cluster_query_mock): """Test that get_all passes all parameters. Since we have already tested all filters and parameters with cluster_get method all we have to do for get_all is to check that we are passing them to the query building method. """ args = ( mock.sentinel.read_deleted, mock.sentinel.get_services, mock.sentinel.services_summary, mock.sentinel.is_up, mock.sentinel.name_match_level, ) filters = { "session": mock.sentinel.session, "name": mock.sentinel.name, "disabled": mock.sentinel.disabled, "disabled_reason": mock.sentinel.disabled_reason, "race_preventer": mock.sentinel.race_preventer, "last_heartbeat": mock.sentinel.last_heartbeat, "num_hosts": mock.sentinel.num_hosts, "num_down_hosts": mock.sentinel.num_down_hosts, } db.cluster_get_all(self.ctxt, *args, **filters) cluster_query_mock.assert_called_once_with(self.ctxt, *args, **filters)
def get_all(cls, context, is_up=None, get_services=False, services_summary=False, read_deleted='no', **filters): """Get all clusters that match the criteria. :param is_up: Boolean value to filter based on the cluster's up status. :param get_services: If we want to load all services from this cluster. :param services_summary: If we want to load num_nodes and num_down_nodes fields. :param read_deleted: Filtering based on delete status. Default value is "no". :param filters: Field based filters in the form of key/value. """ expected_attrs = Cluster._get_expected_attrs( context, get_services=get_services, services_summary=services_summary) clusters = db.cluster_get_all(context, is_up=is_up, get_services=get_services, services_summary=services_summary, read_deleted=read_deleted, **filters) return base.obj_make_list(context, cls(context), Cluster, clusters, expected_attrs=expected_attrs)
def test_cluster_get_all_matches(self): """Basic test of get_all with a matching filter.""" cluster1, svcs = self._create_populated_cluster(3, 1) cluster2, svcs = self._create_populated_cluster(3, 2, name='cluster2') cluster3, svcs = self._create_populated_cluster(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})
def test_cluster_get_all_matches(self): """Basic test of get_all with a matching filter.""" cluster1, svcs = self._create_populated_cluster(3, 1) cluster2, svcs = self._create_populated_cluster(3, 2, name="cluster2") cluster3, svcs = self._create_populated_cluster(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})
def test_cluster_get_all_passes_parameters(self, cluster_query_mock): """Test that get_all passes all parameters. Since we have already tested all filters and parameters with cluster_get method all we have to do for get_all is to check that we are passing them to the query building method. """ args = (mock.sentinel.read_deleted, mock.sentinel.get_services, mock.sentinel.services_summary, mock.sentinel.is_up, mock.sentinel.name_match_level) filters = {'session': mock.sentinel.session, 'name': mock.sentinel.name, 'disabled': mock.sentinel.disabled, 'disabled_reason': mock.sentinel.disabled_reason, 'race_preventer': mock.sentinel.race_preventer, 'last_heartbeat': mock.sentinel.last_heartbeat, 'num_hosts': mock.sentinel.num_hosts, 'num_down_hosts': mock.sentinel.num_down_hosts} db.cluster_get_all(self.ctxt, *args, **filters) cluster_query_mock.assert_called_once_with(self.ctxt, *args, **filters)
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)
def test_cluster_get_all_empty(self): """Test basic empty cluster get_all.""" self.assertListEqual([], db.cluster_get_all(self.ctxt))