Beispiel #1
0
    def test_node_get_all_sort_keys_and_dir(self):
        values = [{'id': '001', 'name': 'node1', 'status': 'ACTIVE'},
                  {'id': '002', 'name': 'node3', 'status': 'ERROR'},
                  {'id': '003', 'name': 'node2', 'status': 'UPDATING'}]
        for v in values:
            shared.create_node(self.ctx, self.cluster, self.profile, **v)

        nodes = db_api.node_get_all(self.ctx, sort_keys=['name', 'status'],
                                    sort_dir='asc')
        self.assertEqual(3, len(nodes))
        # Sorted by name
        self.assertEqual('001', nodes[0].id)
        self.assertEqual('003', nodes[1].id)
        self.assertEqual('002', nodes[2].id)

        nodes = db_api.node_get_all(self.ctx, sort_keys=['status', 'name'],
                                    sort_dir='asc')
        self.assertEqual(3, len(nodes))
        # Sorted by statuses (ascending)
        self.assertEqual('001', nodes[0].id)
        self.assertEqual('002', nodes[1].id)
        self.assertEqual('003', nodes[2].id)

        nodes = db_api.node_get_all(self.ctx, sort_keys=['status', 'name'],
                                    sort_dir='desc')
        self.assertEqual(3, len(nodes))
        # Sorted by statuses (descending)
        self.assertEqual('003', nodes[0].id)
        self.assertEqual('002', nodes[1].id)
        self.assertEqual('001', nodes[2].id)
Beispiel #2
0
    def test_node_get_all_sorting(self):
        values = [{'id': '001', 'name': 'node1', 'status': 'ACTIVE'},
                  {'id': '002', 'name': 'node3', 'status': 'ERROR'},
                  {'id': '003', 'name': 'node2', 'status': 'UPDATING'}]
        for v in values:
            shared.create_node(self.ctx, self.cluster, self.profile, **v)

        nodes = db_api.node_get_all(self.ctx, sort='name,status')
        self.assertEqual(3, len(nodes))
        # Sorted by name
        self.assertEqual('001', nodes[0].id)
        self.assertEqual('003', nodes[1].id)
        self.assertEqual('002', nodes[2].id)

        nodes = db_api.node_get_all(self.ctx, sort='status,name')
        self.assertEqual(3, len(nodes))
        # Sorted by statuses (ascending)
        self.assertEqual('001', nodes[0].id)
        self.assertEqual('002', nodes[1].id)
        self.assertEqual('003', nodes[2].id)

        nodes = db_api.node_get_all(self.ctx, sort='status:desc,name:desc')
        self.assertEqual(3, len(nodes))
        # Sorted by statuses (descending)
        self.assertEqual('003', nodes[0].id)
        self.assertEqual('002', nodes[1].id)
        self.assertEqual('001', nodes[2].id)
Beispiel #3
0
    def test_node_get_all_with_admin_context(self):
        shared.create_node(self.ctx, None, self.profile, name='node1')
        shared.create_node(self.ctx, None, self.profile, name='node2')

        admin_ctx = utils.dummy_context(project='a_different_project',
                                        is_admin=True)
        results = db_api.node_get_all(admin_ctx, project_safe=True)
        self.assertEqual(0, len(results))
        results = db_api.node_get_all(admin_ctx, project_safe=False)
        self.assertEqual(2, len(results))
Beispiel #4
0
    def test_node_get_all_with_filters(self):
        shared.create_node(self.ctx, None, self.profile, name='node1')
        shared.create_node(self.ctx, None, self.profile, name='node2')

        filters = {'name': ['node1', 'nodex']}
        results = db_api.node_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('node1', results[0]['name'])

        filters = {'name': 'node1'}
        results = db_api.node_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('node1', results[0]['name'])
Beispiel #5
0
    def test_node_get_all_with_filters(self):
        shared.create_node(self.ctx, None, self.profile, name='node1')
        shared.create_node(self.ctx, None, self.profile, name='node2')

        filters = {'name': ['node1', 'nodex']}
        results = db_api.node_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('node1', results[0]['name'])

        filters = {'name': 'node1'}
        results = db_api.node_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('node1', results[0]['name'])
Beispiel #6
0
    def test_node_get_all_with_project_safe(self):
        shared.create_node(self.ctx, None, self.profile, name='node1')
        shared.create_node(self.ctx, None, self.profile, name='node2')

        self.ctx.project = 'a-different-project'
        results = db_api.node_get_all(self.ctx, project_safe=False)
        self.assertEqual(2, len(results))

        self.ctx.project = 'a-different-project'
        results = db_api.node_get_all(self.ctx)
        self.assertEqual(0, len(results))

        results = db_api.node_get_all(self.ctx, project_safe=True)
        self.assertEqual(0, len(results))
Beispiel #7
0
    def test_node_get_all_used_sort_keys(self, mock_paginate):
        node_ids = ['node1', 'node2', 'node3']
        for v in node_ids:
            shared.create_node(self.ctx, self.cluster, self.profile, id=v)

        sort = ','.join(consts.NODE_SORT_KEYS)

        db_api.node_get_all(self.ctx, sort=sort)
        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        sort_keys = consts.NODE_SORT_KEYS
        sort_keys.append('id')
        expected_keys = set(sort_keys)
        self.assertEqual(expected_keys, used_sort_keys)
Beispiel #8
0
    def test_node_get_all_used_sort_keys(self, mock_paginate):
        node_ids = ['node1', 'node2', 'node3']
        for v in node_ids:
            shared.create_node(self.ctx, self.cluster, self.profile, id=v)

        sort = ','.join(consts.NODE_SORT_KEYS)

        db_api.node_get_all(self.ctx, sort=sort)
        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        sort_keys = consts.NODE_SORT_KEYS
        sort_keys.append('id')
        expected_keys = set(sort_keys)
        self.assertEqual(expected_keys, used_sort_keys)
Beispiel #9
0
    def test_node_get_all_with_tenant_safe(self):
        shared.create_node(self.ctx, None, self.profile, name='node1')
        shared.create_node(self.ctx, None, self.profile, name='node2')

        self.ctx.tenant_id = 'a-different-tenant'
        results = db_api.node_get_all(self.ctx, tenant_safe=False)
        self.assertEqual(2, len(results))

        self.ctx.tenant_id = 'a-different-tenant'
        results = db_api.node_get_all(self.ctx)
        self.assertEqual(0, len(results))

        results = db_api.node_get_all(self.ctx, tenant_safe=True)
        self.assertEqual(0, len(results))
Beispiel #10
0
    def test_node_get_all_show_deleted(self):
        values = [{'id': 'node1'}, {'id': 'node2'}, {'id': 'node3'}]
        for v in values:
            shared.create_node(self.ctx, self.cluster, self.profile, **v)

        db_api.node_delete(self.ctx, 'node2')

        nodes = db_api.node_get_all(self.ctx)
        self.assertEqual(2, len(nodes))

        nodes = db_api.node_get_all(self.ctx, show_deleted=False)
        self.assertEqual(2, len(nodes))

        nodes = db_api.node_get_all(self.ctx, show_deleted=True)
        self.assertEqual(3, len(nodes))
Beispiel #11
0
    def test_node_get_all_used_sort_keys(self):
        node_ids = ['node1', 'node2', 'node3']
        for v in node_ids:
            shared.create_node(self.ctx, self.cluster, self.profile, id=v)

        mock_paginate = self.patchobject(db_api.utils, 'paginate_query')
        sort_keys = ['index', 'name', 'created_time', 'updated_time',
                     'deleted_time', 'status']

        db_api.node_get_all(self.ctx, sort_keys=sort_keys)
        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        expected_keys = set(['index', 'name', 'created_time', 'updated_time',
                             'deleted_time', 'status', 'id'])
        self.assertEqual(expected_keys, used_sort_keys)
Beispiel #12
0
    def test_node_get_all_show_deleted(self):
        values = [{'id': 'node1'}, {'id': 'node2'}, {'id': 'node3'}]
        for v in values:
            shared.create_node(self.ctx, self.cluster, self.profile, **v)

        db_api.node_delete(self.ctx, 'node2')

        nodes = db_api.node_get_all(self.ctx)
        self.assertEqual(2, len(nodes))

        nodes = db_api.node_get_all(self.ctx, show_deleted=False)
        self.assertEqual(2, len(nodes))

        nodes = db_api.node_get_all(self.ctx, show_deleted=True)
        self.assertEqual(3, len(nodes))
Beispiel #13
0
    def test_node_get_all_used_sort_keys(self):
        node_ids = ['node1', 'node2', 'node3']
        for v in node_ids:
            shared.create_node(self.ctx, self.cluster, self.profile, id=v)

        mock_paginate = self.patchobject(db_api.utils, 'paginate_query')
        sort_keys = ['index', 'name', 'created_time', 'updated_time',
                     'deleted_time', 'status']

        db_api.node_get_all(self.ctx, sort_keys=sort_keys)
        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        expected_keys = set(['index', 'name', 'created_time', 'updated_time',
                             'deleted_time', 'status', 'id'])
        self.assertEqual(expected_keys, used_sort_keys)
Beispiel #14
0
    def test_node_get_all_with_empty_filters(self):
        shared.create_node(self.ctx, None, self.profile, name='node1')
        shared.create_node(self.ctx, None, self.profile, name='node2')

        filters = None
        results = db_api.node_get_all(self.ctx, filters=filters)
        self.assertEqual(2, len(results))
Beispiel #15
0
    def test_node_get_all_with_empty_filters(self):
        shared.create_node(self.ctx, None, self.profile, name='node1')
        shared.create_node(self.ctx, None, self.profile, name='node2')

        filters = None
        results = db_api.node_get_all(self.ctx, filters=filters)
        self.assertEqual(2, len(results))
Beispiel #16
0
    def test_node_get_all_with_admin_context(self):
        shared.create_node(self.ctx, None, self.profile, name='node1')
        shared.create_node(self.ctx, None, self.profile, name='node2')

        admin_ctx = utils.dummy_context(project='a_different_project',
                                        is_admin=True)
        results = db_api.node_get_all(admin_ctx, project_safe=True)
        self.assertEqual(2, len(results))
Beispiel #17
0
    def test_node_get_all_with_limit_marker(self):
        node_ids = ['node1', 'node2', 'node3']
        for v in node_ids:
            shared.create_node(self.ctx, self.cluster, self.profile,
                               id=v, init_time=datetime.datetime.utcnow())

        nodes = db_api.node_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(nodes))

        nodes = db_api.node_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(nodes))

        nodes = db_api.node_get_all(self.ctx, limit=5)
        self.assertEqual(3, len(nodes))

        nodes = db_api.node_get_all(self.ctx, marker='node1')
        self.assertEqual(2, len(nodes))

        nodes = db_api.node_get_all(self.ctx, marker='node2')
        self.assertEqual(1, len(nodes))

        nodes = db_api.node_get_all(self.ctx, marker='node3')
        self.assertEqual(0, len(nodes))

        nodes = db_api.node_get_all(self.ctx, limit=1, marker='node1')
        self.assertEqual(1, len(nodes))
Beispiel #18
0
    def test_node_get_all_with_limit_marker(self):
        node_ids = ['node1', 'node2', 'node3']
        for v in node_ids:
            shared.create_node(self.ctx,
                               self.cluster,
                               self.profile,
                               id=v,
                               init_at=tu.utcnow(True))

        nodes = db_api.node_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(nodes))

        nodes = db_api.node_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(nodes))

        nodes = db_api.node_get_all(self.ctx, limit=5)
        self.assertEqual(3, len(nodes))

        nodes = db_api.node_get_all(self.ctx, marker='node1')
        self.assertEqual(2, len(nodes))

        nodes = db_api.node_get_all(self.ctx, marker='node2')
        self.assertEqual(1, len(nodes))

        nodes = db_api.node_get_all(self.ctx, marker='node3')
        self.assertEqual(0, len(nodes))

        nodes = db_api.node_get_all(self.ctx, limit=1, marker='node1')
        self.assertEqual(1, len(nodes))
Beispiel #19
0
    def test_node_get_all(self):
        values = [{'name': 'node1'}, {'name': 'node2'}, {'name': 'node3'}]
        [shared.create_node(self.ctx, None, self.profile, **v) for v in values]

        nodes = db_api.node_get_all(self.ctx)
        self.assertEqual(3, len(nodes))

        names = [node.name for node in nodes]
        [self.assertIn(val['name'], names) for val in values]
Beispiel #20
0
    def test_node_get_all(self):
        values = [{'name': 'node1'}, {'name': 'node2'}, {'name': 'node3'}]
        [shared.create_node(self.ctx, None, self.profile, **v) for v in values]

        nodes = db_api.node_get_all(self.ctx)
        self.assertEqual(3, len(nodes))

        names = [node.name for node in nodes]
        [self.assertIn(val['name'], names) for val in values]
Beispiel #21
0
    def test_node_get_all_default_sorting(self):
        nodes = [shared.create_node(self.ctx, None, self.profile,
                                    init_at=tu.utcnow())
                 for x in range(3)]

        results = db_api.node_get_all(self.ctx)
        self.assertEqual(3, len(results))
        self.assertEqual(nodes[0].id, results[0].id)
        self.assertEqual(nodes[1].id, results[1].id)
        self.assertEqual(nodes[2].id, results[2].id)
Beispiel #22
0
    def test_node_get_all_default_sort_dir(self):
        dt = datetime.datetime
        nodes = [shared.create_node(self.ctx, None, self.profile,
                                    init_time=dt.utcnow())
                 for x in range(3)]

        results = db_api.node_get_all(self.ctx, sort_dir='asc')
        self.assertEqual(3, len(results))
        self.assertEqual(nodes[0].id, results[0].id)
        self.assertEqual(nodes[1].id, results[1].id)
        self.assertEqual(nodes[2].id, results[2].id)
Beispiel #23
0
    def test_node_get_all_with_cluster_id(self):
        values = [{'name': 'node1'}, {'name': 'node2'}, {'name': 'node3'}]
        for v in values:
            shared.create_node(self.ctx, self.cluster, self.profile, **v)
        shared.create_node(self.ctx, None, self.profile, name='node0')

        nodes = db_api.node_get_all(self.ctx, cluster_id=self.cluster.id)
        self.assertEqual(3, len(nodes))

        names = [node.name for node in nodes]
        [self.assertIn(val['name'], names) for val in values]
Beispiel #24
0
    def test_node_get_all_with_cluster_id(self):
        values = [{'name': 'node1'}, {'name': 'node2'}, {'name': 'node3'}]
        for v in values:
            shared.create_node(self.ctx, self.cluster, self.profile, **v)
        shared.create_node(self.ctx, None, self.profile, name='node0')

        nodes = db_api.node_get_all(self.ctx, cluster_id=self.cluster.id)
        self.assertEqual(3, len(nodes))

        names = [node.name for node in nodes]
        [self.assertIn(val['name'], names) for val in values]
Beispiel #25
0
 def test_node_get_all_sort_keys_wont_change(self):
     sort_keys = ['id']
     db_api.node_get_all(self.ctx, sort_keys=sort_keys)
     self.assertEqual(['id'], sort_keys)
Beispiel #26
0
 def test_node_get_all_sort_keys_wont_change(self):
     sort_keys = ['id']
     db_api.node_get_all(self.ctx, sort_keys=sort_keys)
     self.assertEqual(['id'], sort_keys)