本文整理汇总了Python中lunr.api.controller.volume.VolumeController类的典型用法代码示例。如果您正苦于以下问题:Python VolumeController类的具体用法?Python VolumeController怎么用?Python VolumeController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VolumeController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deep_recommended_nodes
def test_deep_recommended_nodes(self):
self.mock_app.fill_strategy = 'deep_fill'
c = Controller({'account_id': self.account_id}, self.mock_app)
nodes = c.get_recommended_nodes(self.vtype.name, 1)
node_ids = [node.id for node in nodes]
# Our test nodes are in order by size, 0 = 10, 1 = 11, etc.
expected_ids = [self.node0.id, self.node1.id, self.node2.id]
self.assertEqual(node_ids, expected_ids)
# Add Volume from a different account,
self.db.add(db.models.Volume(1, 'vtype', node=self.node0,
account_id=self.account_id2,
volume_type=self.vtype))
# node0 should still be preferred
nodes = c.get_recommended_nodes(self.vtype.name, 1)
self.assertEquals(3, len(nodes))
self.assertEquals(nodes[0].id, self.node0.id)
# Now add a volume for this account
self.db.add(db.models.Volume(1, 'vtype', node=self.node0,
account_id=self.account_id,
volume_type=self.vtype))
# Should prefer the second node
nodes = c.get_recommended_nodes(self.vtype.name, 3)
self.assertEquals(3, len(nodes))
self.assertEquals(nodes[0].id, self.node1.id)
# Add a volume to the second node
self.db.add(db.models.Volume(3, 'vtype', node=self.node1,
account_id=self.account_id,
volume_type=self.vtype))
# Should prefer the last node
nodes = c.get_recommended_nodes(self.vtype.name, 1)
self.assertEquals(3, len(nodes))
self.assertEquals(nodes[0].id, self.node2.id)
示例2: test_recommend_nodes_ordered_by_volumes_with_weights
def test_recommend_nodes_ordered_by_volumes_with_weights(self):
c = Controller({'account_id': self.account_id}, self.mock_app)
n = db.models.Node('node3', 13, volume_type=self.vtype,
hostname='10.127.0.3', port=8083)
self.db.add(n)
self.db.add(db.models.Volume(1, 'vtype', node=self.node1,
account_id=self.account_id,
volume_type=self.vtype))
self.db.add(db.models.Volume(1, 'vtype', node=n,
account_id=self.account_id))
n.calc_storage_used()
self.db.commit()
nodes = c.get_recommended_nodes(self.vtype.name, 1)
# node0/2 have 0 volumes, they should be included.
# node1/3 have 1 volume. 3 should be included because it's bigger.
node_ids = [node.id for node in nodes]
expected_ids = [self.node0.id, self.node2.id, n.id]
self.assertEqual(sorted(node_ids), sorted(expected_ids))
# Weight should override these.
self.node1.weight = 200
self.node2.weight = 200
n.weight = 200
self.db.add_all([self.node1, self.node2, n])
self.db.commit
nodes = c.get_recommended_nodes(self.vtype.name, 1)
node_ids = [node.id for node in nodes]
# Due to weights, we should want 1, 2, and 3
expected_ids = [self.node1.id, self.node2.id, n.id]
self.assertEqual(sorted(node_ids), sorted(expected_ids))
示例3: test_recommended_nodes_affinity_node
def test_recommended_nodes_affinity_node(self):
self.mock_app.fill_strategy = 'deep_fill'
c = Controller({'account_id': self.account_id}, self.mock_app)
nodes = c.get_recommended_nodes(self.vtype.name, 1)
node_ids = [node.id for node in nodes]
# Our test nodes are in order by size, 0 = 10, 1 = 11, etc.
expected_ids = [self.node0.id, self.node1.id, self.node2.id]
self.assertEqual(node_ids, expected_ids)
# Now add a volume for this account
v1 = db.models.Volume(1, 'vtype', node=self.node0,
account_id=self.account_id, volume_type=self.vtype)
v2 = db.models.Volume(2, 'vtype', node=self.node1,
account_id=self.account_id, volume_type=self.vtype)
v3 = db.models.Volume(2, 'vtype', node=self.node2,
account_id=self.account_id, volume_type=self.vtype)
self.db.add_all([v1, v2, v3])
self.db.commit()
# Should prefer the second node
affinity = 'different_node:%s' % v1.id
nodes = c.get_recommended_nodes(self.vtype.name, 3,
affinity=affinity)
self.assertEquals(2, len(nodes))
self.assertEquals(nodes[0].id, self.node1.id)
# Add a volume to the second node
# Should prefer the last node
affinity = 'different_node:%s,%s' % (v1.id, v2.id)
nodes = c.get_recommended_nodes(self.vtype.name, 1,
affinity=affinity)
self.assertEquals(1, len(nodes))
self.assertEquals(nodes[0].id, self.node2.id)
# Recommendation fails.
affinity = 'different_node:%s,%s,%s' % (v1.id, v2.id, v3.id)
self.assertRaises(HTTPInsufficientStorage, c.get_recommended_nodes,
self.vtype.name, 1, affinity=affinity)
示例4: test_create_fail
def test_create_fail(self):
base.urlopen = MockUrlopenBlowup
c = Controller({'account_id': self.account_id, 'id': 'test'},
self.mock_app)
req = Request.blank('?size=1000&volume_type_name=vtype')
self.assertRaises(HTTPError, c.create, req)
try:
c.create(req)
except HTTPError, e:
self.assertEquals(e.code // 100, 5)
示例5: test_create_duplicate_fails
def test_create_duplicate_fails(self):
c = Controller({'account_id': self.account_id, 'id': 'test'},
self.mock_app)
req = Request.blank('?size=1&volume_type_name=vtype')
res = c.create(req)
self.assertEqual(res.body['id'], 'test')
self.assert_(res.body['node_id'])
# test create duplicate
req = Request.blank('?size=1&volume_type_name=vtype')
self.assertRaises(HTTPConflict, c.create, req)
示例6: test_create_success
def test_create_success(self):
c = Controller({'account_id': self.account_id, 'id': 'test'},
self.mock_app)
req = Request.blank('?size=1&volume_type_name=vtype')
res = c.create(req)
self.assertEqual(res.body['id'], 'test')
self.assert_(res.body['node_id'])
self.assert_(res.body['status'], 'ACTIVE')
# For use with the volume manager.
self.assert_(res.body['cinder_host'])
示例7: test_transfer_success
def test_transfer_success(self):
volume = db.models.Volume(node=self.node0, account=self.account,
status='ACTIVE', size=1)
self.db.add(volume)
self.db.commit()
c = Controller({'account_id': self.account_id, 'id': volume.id},
self.mock_app)
new_account_id = 'new_account_id'
req = Request.blank('?account_id=%s' % new_account_id)
res = c.update(req)
self.assertEqual(res.body['id'], volume.id)
self.assertEqual(res.body['account_id'], new_account_id)
示例8: test_index_filtered_by_restore_of
def test_index_filtered_by_restore_of(self):
volume = db.models.Volume(node=None, account=self.account,
status='ACTIVE', size=1, restore_of='foo')
self.db.add(volume)
self.db.commit()
self.assertEqual(volume.restore_of, 'foo')
c = Controller({'account_id': self.account_id, 'id': volume.id},
self.mock_app)
req = Request.blank('?restore_of=foo')
res = c.index(req)
self.assertEqual(len(res.body), 1)
self.assertEqual(res.body[0]['id'], volume.id)
self.assertEqual(res.body[0]['restore_of'], 'foo')
示例9: test_delete_no_node_restore_of
def test_delete_no_node_restore_of(self):
volume = db.models.Volume(node=None, account=self.account,
status='ACTIVE', size=1, restore_of='foo')
self.db.add(volume)
self.db.commit()
self.assertEqual(volume.restore_of, 'foo')
c = Controller({'account_id': self.account_id, 'id': volume.id},
self.mock_app)
req = Request.blank('')
res = c.delete(req)
self.assertEqual(res.body['id'], volume.id)
self.assertEqual(res.body['status'], 'DELETED')
self.assertEqual(res.body['restore_of'], None)
self.assertEqual(volume.restore_of, None)
示例10: test_dont_recommend_full_nodes
def test_dont_recommend_full_nodes(self):
c = Controller({'account_id': self.account_id}, self.mock_app)
size = 2
# (10 - (10 - 3 - 2)) / 10 == .5, IN!
self.db.add(db.models.Volume(3, 'vtype', node=self.node0,
account_id=self.account_id))
# (11 - (11 - 4 - 2)) / 11 > .5, OUT!
self.db.add(db.models.Volume(4, 'vtype', node=self.node1,
account_id=self.account_id))
# (12 - (12 - 20 - 2)) / 12 > .5, OUT!
self.db.add(db.models.Volume(5, 'vtype', node=self.node2,
account_id=self.account_id))
nodes1 = c.get_recommended_nodes(self.vtype.name, size)
self.assertEquals(nodes1, [self.node0])
示例11: test_create_source_success
def test_create_source_success(self):
c = Controller({'account_id': self.account_id, 'id': 'test1'},
self.mock_app)
source_vol = db.models.Volume(node=self.node0, account=self.account,
status='ACTIVE', size=1)
self.db.add(source_vol)
self.db.commit()
req = Request.blank('?size=2&volume_type_name=vtype&source_volume=%s' %
source_vol.id)
res = c.create(req)
self.assertEqual(res.body['id'], 'test1')
self.assertEqual(res.body['size'], 2)
self.assert_(res.body['node_id'], self.node0.id)
self.assert_(res.body['status'], 'CLONING')
示例12: test_recommended_nodes_force_node
def test_recommended_nodes_force_node(self):
self.mock_app.fill_strategy = 'deep_fill'
c = Controller({'account_id': self.account_id}, self.mock_app)
node = self.node0
nodes = c.get_recommended_nodes(self.vtype.name, 1,
force_node=node.name)
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].id, node.id)
nodes = c.get_recommended_nodes(self.vtype.name, 1,
force_node=node.id)
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].id, node.id)
示例13: test_get_recommended_nodes_weights
def test_get_recommended_nodes_weights(self):
c = Controller({'account_id': self.account_id}, self.mock_app)
size = 1
count = 1
nodes = c.get_recommended_nodes(self.vtype.name, size, count)
# 2 is preferred since it's biggest
self.assertEqual(nodes[0].id, self.node2.id)
self.node0.weight = 202
self.node1.weight = 201
self.node2.weight = 200
self.db.add_all([self.node0, self.node1, self.node2])
self.db.commit()
# 0 is preferred due to weight
nodes = c.get_recommended_nodes(self.vtype.name, size, count)
self.assertEqual(nodes[0].id, self.node0.id)
示例14: test_show
def test_show(self):
c = Controller({'account_id': self.account_id, 'id': 'test'},
self.mock_app)
req = Request.blank('?size=1&volume_type_name=vtype')
c.create(req)
req = Request.blank('')
res = c.show(req)
self.assertEqual(res.body['id'], 'test')
c = Controller(
{
'account_id': self.account_id,
'id': '00000000-0000-0000-0000-000000000000',
}, self.mock_app)
req = Request.blank('')
self.assertRaises(HTTPNotFound, c.show, req)
示例15: test_validate_force_node
def test_validate_force_node(self):
n = db.models.Node('mynode', 100, volume_type=self.vtype,
hostname='10.127.0.72', port=8152)
self.db.add(n)
self.db.commit()
c = Controller({'account_id': self.account_id, 'id': 'test'},
self.mock_app)
req = Request.blank('?force_node=%s' % n.id)
force_node = c._validate_force_node(req.params)
self.assertEquals(force_node, n.id)
req = Request.blank('?force_node=%s' % n.name)
force_node = c._validate_force_node(req.params)
self.assertEquals(force_node, n.name)
req = Request.blank('?force_node=garbage')
self.assertRaises(HTTPPreconditionFailed, c._validate_force_node,
req.params)