本文整理汇总了Python中senlin.tests.unit.db.shared.create_node函数的典型用法代码示例。如果您正苦于以下问题:Python create_node函数的具体用法?Python create_node怎么用?Python create_node使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_node函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_node_get_all_with_empty_filters
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))
示例2: test_node_get_all_with_limit_marker
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())
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))
示例3: test_node_get_all_sorting
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)
示例4: test_node_get_by_cluster
def test_node_get_by_cluster(self):
cluster1 = shared.create_cluster(self.ctx, self.profile)
node0 = shared.create_node(self.ctx, None, self.profile)
node1 = shared.create_node(self.ctx, self.cluster, self.profile)
node2 = shared.create_node(self.ctx, self.cluster, self.profile)
node3 = shared.create_node(self.ctx, cluster1, self.profile)
nodes = db_api.node_get_all_by_cluster(self.ctx, self.cluster.id)
self.assertEqual(2, len(nodes))
self.assertEqual(set([node1.id, node2.id]),
set([nodes[0].id, nodes[1].id]))
# retrieve orphan nodes
nodes = db_api.node_get_all_by_cluster(self.ctx, '')
self.assertEqual(1, len(nodes))
self.assertEqual(node0.id, nodes[0].id)
# retrieve all nodes
nodes = db_api.node_get_all_by_cluster(self.ctx, None)
self.assertEqual(4, len(nodes))
self.assertEqual(node0.id, nodes[0].id)
nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
self.assertEqual(1, len(nodes))
self.assertEqual(node3.id, nodes[0].id)
示例5: test_node_count_by_cluster
def test_node_count_by_cluster(self):
shared.create_cluster(self.ctx, self.profile)
shared.create_node(self.ctx, self.cluster, self.profile)
shared.create_node(self.ctx, self.cluster, self.profile)
res = db_api.node_count_by_cluster(self.ctx, self.cluster.id)
self.assertEqual(2, res)
示例6: test_node_get_all_with_admin_context
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))
示例7: test_node_get_by_name
def test_node_get_by_name(self):
shared.create_node(self.ctx, self.cluster, self.profile)
node = db_api.node_get_by_name(self.ctx, 'test_node_name')
self.assertIsNotNone(node)
self.assertEqual('test_node_name', node.name)
self.assertEqual(self.cluster.id, node.cluster_id)
res = db_api.node_get_by_name(self.ctx, 'BogusName')
self.assertIsNone(res)
示例8: test_node_get_by_short_id_admin_context
def test_node_get_by_short_id_admin_context(self):
node_id = 'same-part-unique-part'
shared.create_node(self.ctx, None, self.profile,
id=node_id, name='node-1')
admin_ctx = utils.dummy_context(project='a_different_project',
is_admin=True)
res = db_api.node_get_by_short_id(admin_ctx, node_id[:11],
project_safe=True)
self.assertIsNotNone(res)
示例9: test_node_count_by_cluster_admin_context
def test_node_count_by_cluster_admin_context(self):
shared.create_cluster(self.ctx, self.profile)
shared.create_node(self.ctx, self.cluster, self.profile)
shared.create_node(self.ctx, self.cluster, self.profile)
admin_ctx = utils.dummy_context(project='a_different_project',
is_admin=True)
res = db_api.node_count_by_cluster(admin_ctx, self.cluster.id,
project_safe=True)
self.assertEqual(2, res)
示例10: test_node_get_by_physical_id
def test_node_get_by_physical_id(self):
shared.create_node(self.ctx, self.cluster, self.profile,
physical_id=UUID1)
node = db_api.node_get_by_physical_id(self.ctx, UUID1)
self.assertIsNotNone(node)
self.assertEqual(UUID1, node.physical_id)
node = db_api.node_get_by_physical_id(self.ctx, UUID2)
self.assertIsNone(node)
示例11: test_node_get_by_name_diff_project
def test_node_get_by_name_diff_project(self):
shared.create_node(self.ctx, self.cluster, self.profile)
res = db_api.node_get_by_name(self.ctx, 'test_node_name')
self.assertIsNotNone(res)
ctx_new = utils.dummy_context(project='a_different_project')
res = db_api.node_get_by_name(ctx_new, 'test_node_name')
self.assertIsNone(res)
res = db_api.node_get_by_name(ctx_new, 'test_node_name',
project_safe=False)
self.assertIsNotNone(res)
示例12: test_node_get_all_with_cluster_id
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]
示例13: test_event_get_all_by_cluster
def test_event_get_all_by_cluster(self):
cluster1 = shared.create_cluster(self.ctx, self.profile)
cluster2 = shared.create_cluster(self.ctx, self.profile)
node1_1 = shared.create_node(self.ctx, cluster1, self.profile)
node1_2 = shared.create_node(self.ctx, cluster1, self.profile)
node2_1 = shared.create_node(self.ctx, cluster2, self.profile)
node_orphan = shared.create_node(self.ctx, None, self.profile)
# 1 event for cluster 1
self.create_event(self.ctx, entity=cluster1)
events = db_api.event_get_all_by_cluster(self.ctx, cluster1.id)
self.assertEqual(1, len(events))
events = db_api.event_get_all_by_cluster(self.ctx, cluster2.id)
self.assertEqual(0, len(events))
# two more events for cluster 1, with one for an orphan node
self.create_event(self.ctx, entity=node1_1)
self.create_event(self.ctx, entity=node1_2)
self.create_event(self.ctx, entity=node_orphan)
events = db_api.event_get_all_by_cluster(self.ctx, cluster1.id)
self.assertEqual(3, len(events))
events = db_api.event_get_all_by_cluster(self.ctx, cluster2.id)
self.assertEqual(0, len(events))
# one more events for cluster 2, with one for an orphan node
self.create_event(self.ctx, entity=cluster2)
self.create_event(self.ctx, entity=node_orphan)
events = db_api.event_get_all_by_cluster(self.ctx, cluster1.id)
self.assertEqual(3, len(events))
events = db_api.event_get_all_by_cluster(self.ctx, cluster2.id)
self.assertEqual(1, len(events))
# two more events for cluster 2, with one for an orphan node
self.create_event(self.ctx, entity=node2_1)
self.create_event(self.ctx, entity=node2_1)
self.create_event(self.ctx, entity=node_orphan)
events = db_api.event_get_all_by_cluster(self.ctx, cluster1.id)
self.assertEqual(3, len(events))
events = db_api.event_get_all_by_cluster(self.ctx, cluster2.id)
self.assertEqual(3, len(events))
# two more events for cluster 1, with one for an orphan node
self.create_event(self.ctx, entity=cluster1)
self.create_event(self.ctx, entity=node1_1)
self.create_event(self.ctx, entity=node_orphan)
events = db_api.event_get_all_by_cluster(self.ctx, cluster1.id)
self.assertEqual(5, len(events))
events = db_api.event_get_all_by_cluster(self.ctx, cluster2.id)
self.assertEqual(3, len(events))
示例14: test_node_get_by_cluster_admin_context
def test_node_get_by_cluster_admin_context(self):
shared.create_cluster(self.ctx, self.profile)
node1 = shared.create_node(self.ctx, self.cluster, self.profile)
node2 = shared.create_node(self.ctx, self.cluster, self.profile)
admin_ctx = utils.dummy_context(project='a_different_project',
is_admin=True)
nodes = db_api.node_get_all_by_cluster(admin_ctx, self.cluster.id)
self.assertEqual(2, len(nodes))
self.assertEqual(set([node1.id, node2.id]),
set([nodes[0].id, nodes[1].id]))
示例15: test_node_get_by_short_id_diff_project
def test_node_get_by_short_id_diff_project(self):
node_id = 'same-part-unique-part'
shared.create_node(self.ctx, None, self.profile,
id=node_id, name='node-1')
res = db_api.node_get_by_short_id(self.ctx, node_id[:11])
self.assertIsNotNone(res)
ctx_new = utils.dummy_context(project='a_different_project')
res = db_api.node_get_by_short_id(ctx_new, node_id[:11])
self.assertIsNone(res)
res = db_api.node_get_by_short_id(ctx_new, node_id[:11],
project_safe=False)
self.assertIsNotNone(res)