Exemple #1
0
 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)
Exemple #2
0
    def test_create_from_image(self):
        image_id = 'my_image'
        base.urlopen = MockUrlopenWithImage
        c = Controller({
            'account_id': self.account_id,
            'id': 'test1'
        }, self.mock_app)
        self.mock_called = False

        def mock_get_recommended_nodes(*args, **kwargs):
            self.assert_('imaging' in kwargs)
            self.assertTrue(kwargs['imaging'])
            self.mock_called = True
            return [self.node0]

        c.get_recommended_nodes = mock_get_recommended_nodes

        req = Request.blank('?size=2&volume_type_name=vtype&image_id=%s' %
                            image_id)
        res = c.create(req)

        self.assertTrue(self.mock_called)
        self.assertEqual(res.body['id'], 'test1')
        self.assertEqual(res.body['size'], 2)
        self.assertEqual(res.body['status'], 'IMAGING')
        self.assertEqual(res.body['image_id'], image_id)
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 def test_recommended_nodes_for_image(self):
     self.mock_app.fill_strategy = 'deep_fill'
     self.mock_app.image_convert_limit = 1
     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 an imaging volume to node0
     self.db.add(
         db.models.Volume(1,
                          'vtype',
                          node=self.node0,
                          account_id=self.account_id2,
                          volume_type=self.vtype,
                          status='IMAGING'))
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     self.assertEquals(3, len(nodes))
     node_ids = [node.id for node in nodes]
     self.assertIn(self.node0.id, node_ids)
     # Now try recommendations for imaging
     nodes = c.get_recommended_nodes(self.vtype.name, 1, imaging=True)
     self.assertEquals(2, len(nodes))
     node_ids = [node.id for node in nodes]
     self.assertNotIn(self.node0.id, node_ids)
Exemple #6
0
 def test_get_recommended_ignores_deleted_volumes(self):
     c = Controller({'account_id': self.account_id}, self.mock_app)
     vtype = db.models.VolumeType('something_else')
     n = db.models.Node('newnode',
                        10,
                        volume_type=vtype,
                        hostname='10.127.0.42',
                        port=8242)
     self.db.add_all([vtype, n])
     self.db.commit()
     nodes = c.get_recommended_nodes('something_else', 1)
     self.assertNotEquals([], nodes)
     self.assertEquals(n.id, nodes[0].id)
     # Fill it to the gills.
     v = db.models.Volume(10,
                          'something_else',
                          node=n,
                          account_id=self.account_id)
     self.db.add(v)
     self.db.commit()
     self.assertRaises(HTTPError, c.get_recommended_nodes, 'something_else',
                       1)
     v.status = 'DELETED'
     self.db.add(v)
     self.db.commit()
     nodes = c.get_recommended_nodes('something_else', 1)
     self.assertNotEquals([], nodes)
     self.assertEquals(n.id, nodes[0].id)
Exemple #7
0
    def test_delete_different_name(self):
        volume_id = 'test'
        volume_name = 'nottest'
        c = Controller({
            'account_id': self.account_id,
            'id': volume_id
        }, self.mock_app)
        req = Request.blank('?size=1&volume_type_name=vtype&name=%s' %
                            volume_name)
        c.create(req)
        c = Controller({
            'account_id': self.account_id,
            'id': volume_id
        }, self.mock_app)
        req = Request.blank('')

        node_request_path = []

        def raise_exc(self, node, method, path, **kwargs):
            node_request_path.append(path)
            raise base.NodeError(MockRequest(), URLError("something bad"))

        with patch(Controller, 'node_request', raise_exc):
            self.assertRaises(base.NodeError, c.delete, req)

        self.assertEquals(str(node_request_path[0]),
                          '/volumes/%s' % volume_name)
Exemple #8
0
    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))
Exemple #9
0
 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)
Exemple #10
0
    def test_index_name_and_cinder_host(self):
        cinder_host = 'somehost'
        name = 'somehostvolume'
        n = db.models.Node('somehostnode',
                           1000,
                           volume_type=self.vtype,
                           hostname='10.127.0.99',
                           port=8099,
                           cinder_host=cinder_host)
        # Two volumes, same name
        v1 = db.models.Volume(node=self.node0,
                              account=self.account,
                              status='ACTIVE',
                              size=1,
                              name=name)
        v2 = db.models.Volume(node=n,
                              account=self.account,
                              status='ACTIVE',
                              size=1,
                              name=name)
        # One one the right node, different name
        v3 = db.models.Volume(node=n,
                              account=self.account,
                              status='ACTIVE',
                              size=1)
        self.db.add_all([n, v1, v2])
        self.db.commit()

        # Query by name
        c = Controller({
            'account_id': self.account_id,
            'id': 'test'
        }, self.mock_app)
        req = Request.blank('?name=%s' % name)
        res = c.index(req)
        self.assertEqual(len(res.body), 2)
        vol_ids = (
            v1.id,
            v2.id,
        )
        self.assertEqual((res.body[0]['id'], res.body[1]['id']), vol_ids)

        # Query by cinder_host
        req = Request.blank('?cinder_host=%s' % cinder_host)
        res = c.index(req)
        self.assertEqual(len(res.body), 2)
        vol_ids = (
            v2.id,
            v3.id,
        )
        self.assertEqual((res.body[0]['id'], res.body[1]['id']), vol_ids)

        # Query by both
        req = Request.blank('?cinder_host=%s&name=%s' % (cinder_host, name))
        res = c.index(req)
        self.assertEqual(len(res.body), 1)
        self.assertEqual(res.body[0]['id'], v2.id)
Exemple #11
0
 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)
Exemple #12
0
 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'])
Exemple #13
0
 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'])
Exemple #14
0
 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)
Exemple #15
0
 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)
Exemple #16
0
 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)
Exemple #17
0
 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)
Exemple #18
0
 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)
Exemple #19
0
 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')
Exemple #20
0
 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')
Exemple #21
0
 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)
Exemple #22
0
 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')
Exemple #23
0
 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')
Exemple #24
0
 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])
Exemple #25
0
 def test_recommended_nodes_affinity_cab(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)
     # Set up cabs.
     self.node0.affinity_group = 'cab1'
     self.node1.affinity_group = 'cab2'
     self.node2.affinity_group = 'cab1'
     # Now add some volumes to these cabs.
     # v1,v3 = cab1, v2 = cab2
     self.db.add_all([self.node0, self.node1, self.node2])
     v1 = db.models.Volume(1,
                           'vtype',
                           node=self.node0,
                           account_id=self.account_id,
                           volume_type=self.vtype)
     v2 = db.models.Volume(1,
                           'vtype',
                           node=self.node1,
                           account_id=self.account_id,
                           volume_type=self.vtype)
     v3 = db.models.Volume(1,
                           'vtype',
                           node=self.node2,
                           account_id=self.account_id,
                           volume_type=self.vtype)
     self.db.add_all([v1, v2, v3])
     self.db.commit()
     # Should only show node1 (cab2)
     affinity = 'different_group:%s' % v1.id
     nodes = c.get_recommended_nodes(self.vtype.name, 3, affinity=affinity)
     self.assertEquals(1, len(nodes))
     self.assertEquals(nodes[0].id, self.node1.id)
     # Should show node0 and node2 (cab1)
     affinity = 'different_group:%s' % v2.id
     nodes = c.get_recommended_nodes(self.vtype.name, 1, affinity=affinity)
     self.assertEquals(2, len(nodes))
     self.assertEquals(nodes[0].id, self.node0.id)
     self.assertEquals(nodes[1].id, self.node2.id)
     # Recommendation fails.
     affinity = 'different_group:%s,%s' % (v1.id, v2.id)
     self.assertRaises(HTTPInsufficientStorage,
                       c.get_recommended_nodes,
                       self.vtype.name,
                       1,
                       affinity=affinity)
Exemple #26
0
 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])
Exemple #27
0
 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)
Exemple #28
0
    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)
Exemple #29
0
    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)
Exemple #30
0
 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)
Exemple #31
0
 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)
Exemple #32
0
 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)
Exemple #33
0
    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)
Exemple #34
0
    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)
Exemple #35
0
    def test_create_from_backup_with_new_size(self):
        volume = db.models.Volume(node=self.node0, account=self.account,
                                  status='ACTIVE', size=1)
        self.db.add(volume)
        backup = db.models.Backup(volume, status='AVAILABLE')
        self.db.add(backup)
        self.db.commit()

        c = Controller({'account_id': self.account_id, 'id': 'test1'},
                       self.mock_app)
        req = Request.blank('?size=2&volume_type_name=vtype&backup=%s' %
                            backup.id)
        res = c.create(req)
        self.assertEqual(res.body['id'], 'test1')
        self.assertEqual(res.body['size'], 2)
        self.assert_(res.body['node_id'])
        self.assert_(res.body['status'], 'ACTIVE')
Exemple #36
0
    def test_create_from_backup_with_new_size(self):
        volume = db.models.Volume(node=self.node0, account=self.account,
                                  status='ACTIVE', size=1)
        self.db.add(volume)
        backup = db.models.Backup(volume, status='AVAILABLE')
        self.db.add(backup)
        self.db.commit()

        c = Controller({'account_id': self.account_id, 'id': 'test1'},
                       self.mock_app)
        req = Request.blank('?size=2&volume_type_name=vtype&backup=%s' %
                            backup.id)
        res = c.create(req)
        self.assertEqual(res.body['id'], 'test1')
        self.assertEqual(res.body['size'], 2)
        self.assert_(res.body['node_id'])
        self.assert_(res.body['status'], 'ACTIVE')
Exemple #37
0
 def test_delete(self):
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('?size=1&volume_type_name=vtype')
     id = c.create(req).body['id']
     c = Controller({'account_id': self.account_id, 'id': id},
                    self.mock_app)
     req = Request.blank('')
     res = c.delete(req)
     self.assertEqual(res.body['id'], id)
     self.assertEqual(res.body['status'], 'DELETING')
     c = Controller(
             {
                 'account_id': self.account_id,
                 'id': '00000000-0000-0000-0000-000000000000',
             }, self.mock_app)
     req = Request.blank('')
     self.assertRaises(HTTPNotFound, c.delete, req)
Exemple #38
0
 def test_validate_volume_type_limits(self):
     n = db.models.Node('bignode', 10000, volume_type=self.vtype,
                        hostname='10.127.0.72', port=8152)
     self.db.add(n)
     self.vtype.min_size = 100
     self.vtype.max_size = 1000
     self.db.add(self.vtype)
     self.db.commit()
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('?size=1234&volume_type_name=vtype')
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     req = Request.blank('?size=12&volume_type_name=vtype')
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     req = Request.blank('?size=123&volume_type_name=vtype')
     res = c.create(req)
     self.assertEqual(res.body['id'], 'test')
     self.assertEqual(res.body['size'], 123)
Exemple #39
0
 def test_validate_affinity(self):
     c = Controller({'account_id': self.account_id, 'id': 'test'},
             self.mock_app)
     req = Request.blank('?somethingelse=2')
     affinity = c._validate_affinity(req.params)
     self.assertEquals(affinity, '')
     req = Request.blank('?affinity=badformat')
     self.assertRaises(HTTPPreconditionFailed, c._validate_affinity,
                       req.params)
     req = Request.blank('?affinity=badtypeof_affinity:abcde')
     self.assertRaises(HTTPPreconditionFailed, c._validate_affinity,
                       req.params)
     req = Request.blank('?affinity=different_node:volume_id')
     affinity = c._validate_affinity(req.params)
     self.assertEquals(affinity, 'different_node:volume_id')
     req = Request.blank('?affinity=different_group:volume_id')
     affinity = c._validate_affinity(req.params)
     self.assertEquals(affinity, 'different_group:volume_id')
Exemple #40
0
 def test_validate_volume_type_limits(self):
     n = db.models.Node('bignode', 10000, volume_type=self.vtype,
                        hostname='10.127.0.72', port=8152)
     self.db.add(n)
     self.vtype.min_size = 100
     self.vtype.max_size = 1000
     self.db.add(self.vtype)
     self.db.commit()
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('?size=1234&volume_type_name=vtype')
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     req = Request.blank('?size=12&volume_type_name=vtype')
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     req = Request.blank('?size=123&volume_type_name=vtype')
     res = c.create(req)
     self.assertEqual(res.body['id'], 'test')
     self.assertEqual(res.body['size'], 123)
Exemple #41
0
 def test_validate_affinity(self):
     c = Controller({'account_id': self.account_id, 'id': 'test'},
             self.mock_app)
     req = Request.blank('?somethingelse=2')
     affinity = c._validate_affinity(req.params)
     self.assertEquals(affinity, '')
     req = Request.blank('?affinity=badformat')
     self.assertRaises(HTTPPreconditionFailed, c._validate_affinity,
                       req.params)
     req = Request.blank('?affinity=badtypeof_affinity:abcde')
     self.assertRaises(HTTPPreconditionFailed, c._validate_affinity,
                       req.params)
     req = Request.blank('?affinity=different_node:volume_id')
     affinity = c._validate_affinity(req.params)
     self.assertEquals(affinity, 'different_node:volume_id')
     req = Request.blank('?affinity=different_group:volume_id')
     affinity = c._validate_affinity(req.params)
     self.assertEquals(affinity, 'different_group:volume_id')
Exemple #42
0
 def test_get_recommended_nodes_is_random(self):
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     size = 1
     nodes1 = c.get_recommended_nodes(self.vtype.name, size)
     attempts = 0
     while True:
         nodes2 = c.get_recommended_nodes(self.vtype.name, size)
         try:
             self.assertNotEquals(nodes1, nodes2)
         except AssertionError:
             if attempts >= 3:
                 raise
         else:
             break
         attempts += 1
     self.assertEquals(len(nodes1), len(nodes2))
     nodes1.sort()
     nodes2.sort()
     self.assertEqual(nodes1, nodes2)
Exemple #43
0
 def test_get_recommended_nodes_is_random(self):
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     size = 1
     nodes1 = c.get_recommended_nodes(self.vtype.name, size)
     attempts = 0
     while True:
         nodes2 = c.get_recommended_nodes(self.vtype.name, size)
         try:
             self.assertNotEquals(nodes1, nodes2)
         except AssertionError:
             if attempts >= 3:
                 raise
         else:
             break
         attempts += 1
     self.assertEquals(len(nodes1), len(nodes2))
     nodes1.sort()
     nodes2.sort()
     self.assertEqual(nodes1, nodes2)
Exemple #44
0
 def test_recommended_nodes_affinity_cab(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)
     # Set up cabs.
     self.node0.affinity_group = 'cab1'
     self.node1.affinity_group = 'cab2'
     self.node2.affinity_group = 'cab1'
     # Now add some volumes to these cabs.
     # v1,v3 = cab1, v2 = cab2
     self.db.add_all([self.node0, self.node1, self.node2])
     v1 = db.models.Volume(1, 'vtype', node=self.node0,
         account_id=self.account_id, volume_type=self.vtype)
     v2 = db.models.Volume(1, 'vtype', node=self.node1,
         account_id=self.account_id, volume_type=self.vtype)
     v3 = db.models.Volume(1, 'vtype', node=self.node2,
         account_id=self.account_id, volume_type=self.vtype)
     self.db.add_all([v1, v2, v3])
     self.db.commit()
     # Should only show node1 (cab2)
     affinity = 'different_group:%s' % v1.id
     nodes = c.get_recommended_nodes(self.vtype.name, 3,
                                     affinity=affinity)
     self.assertEquals(1, len(nodes))
     self.assertEquals(nodes[0].id, self.node1.id)
     # Should show node0 and node2 (cab1)
     affinity = 'different_group:%s' % v2.id
     nodes = c.get_recommended_nodes(self.vtype.name, 1,
                                     affinity=affinity)
     self.assertEquals(2, len(nodes))
     self.assertEquals(nodes[0].id, self.node0.id)
     self.assertEquals(nodes[1].id, self.node2.id)
     # Recommendation fails.
     affinity = 'different_group:%s,%s' % (v1.id, v2.id)
     self.assertRaises(HTTPInsufficientStorage, c.get_recommended_nodes,
                       self.vtype.name, 1, affinity=affinity)
Exemple #45
0
    def test_delete_different_name(self):
        volume_id = 'test'
        volume_name = 'nottest'
        c = Controller({'account_id': self.account_id, 'id': volume_id},
                       self.mock_app)
        req = Request.blank(
            '?size=1&volume_type_name=vtype&name=%s' % volume_name)
        c.create(req)
        c = Controller({'account_id': self.account_id, 'id': volume_id},
                       self.mock_app)
        req = Request.blank('')

        node_request_path = []
        def raise_exc(self, node, method, path, **kwargs):
            node_request_path.append(path)
            raise base.NodeError(MockRequest(), URLError("something bad"))

        with patch(Controller, 'node_request', raise_exc):
            self.assertRaises(base.NodeError, c.delete, req)

        self.assertEquals(str(node_request_path[0]),
                          '/volumes/%s' % volume_name)
Exemple #46
0
 def test_validate_name(self):
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('')
     valid_name = c._validate_name(req.params)
     # default to id
     self.assertEqual(valid_name, 'test')
     name = 'aSDf'
     req = Request.blank('?name=%s' % name)
     valid_name = c._validate_name(req.params)
     self.assertEqual(valid_name, name)
     # only allow alphanumeric and dashes
     name = 'asdf_42'
     req = Request.blank('?name=%s' % name)
     self.assertRaises(HTTPPreconditionFailed, c._validate_name, req.params)
     # only allow alphanumeric and dashes
     name = 'asdf*+42'
     req = Request.blank('?name=%s' % name)
     self.assertRaises(HTTPPreconditionFailed, c._validate_name, req.params)
     name = 'asdf  2'
     req = Request.blank('?name=%s' % name)
     self.assertRaises(HTTPPreconditionFailed, c._validate_name, req.params)
Exemple #47
0
 def test_validate_name(self):
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('')
     valid_name = c._validate_name(req.params)
     # default to id
     self.assertEqual(valid_name, 'test')
     name = 'aSDf'
     req = Request.blank('?name=%s' % name)
     valid_name = c._validate_name(req.params)
     self.assertEqual(valid_name, name)
     # only allow alphanumeric and dashes
     name = 'asdf_42'
     req = Request.blank('?name=%s' % name)
     self.assertRaises(HTTPPreconditionFailed, c._validate_name, req.params)
     # only allow alphanumeric and dashes
     name = 'asdf*+42'
     req = Request.blank('?name=%s' % name)
     self.assertRaises(HTTPPreconditionFailed, c._validate_name, req.params)
     name = 'asdf  2'
     req = Request.blank('?name=%s' % name)
     self.assertRaises(HTTPPreconditionFailed, c._validate_name, req.params)
Exemple #48
0
 def test_recommended_nodes_for_image(self):
     self.mock_app.fill_strategy = 'deep_fill'
     self.mock_app.image_convert_limit = 1
     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 an imaging volume to node0
     self.db.add(db.models.Volume(1, 'vtype', node=self.node0,
                                  account_id=self.account_id2,
                                  volume_type=self.vtype, status='IMAGING'))
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     self.assertEquals(3, len(nodes))
     node_ids = [node.id for node in nodes]
     self.assertIn(self.node0.id, node_ids)
     # Now try recommendations for imaging
     nodes = c.get_recommended_nodes(self.vtype.name, 1, imaging=True)
     self.assertEquals(2, len(nodes))
     node_ids = [node.id for node in nodes]
     self.assertNotIn(self.node0.id, node_ids)
Exemple #49
0
    def test_index_name_and_cinder_host(self):
        cinder_host = 'somehost'
        name = 'somehostvolume'
        n = db.models.Node('somehostnode', 1000, volume_type=self.vtype,
                           hostname='10.127.0.99', port=8099,
                           cinder_host=cinder_host)
        # Two volumes, same name
        v1 = db.models.Volume(node=self.node0, account=self.account,
                              status='ACTIVE', size=1, name=name)
        v2 = db.models.Volume(node=n, account=self.account,
                              status='ACTIVE', size=1, name=name)
        # One one the right node, different name
        v3 = db.models.Volume(node=n, account=self.account,
                              status='ACTIVE', size=1)
        self.db.add_all([n, v1, v2])
        self.db.commit()

        # Query by name
        c = Controller({'account_id':  self.account_id, 'id': 'test'},
                       self.mock_app)
        req = Request.blank('?name=%s' % name)
        res = c.index(req)
        self.assertEqual(len(res.body), 2)
        vol_ids = (v1.id, v2.id,)
        self.assertEqual((res.body[0]['id'], res.body[1]['id']), vol_ids)

        # Query by cinder_host
        req = Request.blank('?cinder_host=%s' % cinder_host)
        res = c.index(req)
        self.assertEqual(len(res.body), 2)
        vol_ids = (v2.id, v3.id,)
        self.assertEqual((res.body[0]['id'], res.body[1]['id']), vol_ids)

        # Query by both
        req = Request.blank('?cinder_host=%s&name=%s' % (cinder_host, name))
        res = c.index(req)
        self.assertEqual(len(res.body), 1)
        self.assertEqual(res.body[0]['id'], v2.id)
Exemple #50
0
    def test_create_from_image(self):
        image_id = 'my_image'
        base.urlopen = MockUrlopenWithImage
        c = Controller({'account_id': self.account_id, 'id': 'test1'},
                       self.mock_app)
        self.mock_called = False

        def mock_get_recommended_nodes(*args, **kwargs):
            self.assert_('imaging' in kwargs)
            self.assertTrue(kwargs['imaging'])
            self.mock_called = True
            return [self.node0]
        c.get_recommended_nodes = mock_get_recommended_nodes

        req = Request.blank('?size=2&volume_type_name=vtype&image_id=%s' %
                            image_id)
        res = c.create(req)

        self.assertTrue(self.mock_called)
        self.assertEqual(res.body['id'], 'test1')
        self.assertEqual(res.body['size'], 2)
        self.assertEqual(res.body['status'], 'IMAGING')
        self.assertEqual(res.body['image_id'], image_id)
Exemple #51
0
 def test_get_recommended_ignores_deleted_volumes(self):
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     vtype = db.models.VolumeType('something_else')
     n = db.models.Node('newnode', 10, volume_type=vtype,
                        hostname='10.127.0.42', port=8242)
     self.db.add_all([vtype, n])
     self.db.commit()
     nodes = c.get_recommended_nodes('something_else', 1)
     self.assertNotEquals([], nodes)
     self.assertEquals(n.id, nodes[0].id)
     # Fill it to the gills.
     v = db.models.Volume(10, 'something_else', node=n,
                          account_id=self.account_id)
     self.db.add(v)
     self.db.commit()
     self.assertRaises(HTTPError, c.get_recommended_nodes,
                       'something_else', 1)
     v.status = 'DELETED'
     self.db.add(v)
     self.db.commit()
     nodes = c.get_recommended_nodes('something_else', 1)
     self.assertNotEquals([], nodes)
     self.assertEquals(n.id, nodes[0].id)
Exemple #52
0
    def test_index_filtered(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)
        c = Controller({'account_id':  self.account_id, 'id': 'test2'},
                       self.mock_app)
        req = Request.blank('?size=1&volume_type_name=vtype')
        res = c.create(req)

        c = Controller({'account_id':  self.account_id}, self.mock_app)
        req = Request.blank('?id=test2')
        res = c.index(req)
        self.assertEqual(len(res.body), 1)
        self.assertEqual(res.body[0]['id'], 'test2')
Exemple #53
0
    def test_index_filtered(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)
        c = Controller({'account_id':  self.account_id, 'id': 'test2'},
                       self.mock_app)
        req = Request.blank('?size=1&volume_type_name=vtype')
        res = c.create(req)

        c = Controller({'account_id':  self.account_id}, self.mock_app)
        req = Request.blank('?id=test2')
        res = c.index(req)
        self.assertEqual(len(res.body), 1)
        self.assertEqual(res.body[0]['id'], 'test2')
Exemple #54
0
    def test_index_populated(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)
        c = Controller({'account_id':  self.account_id, 'id': 'test2'},
                       self.mock_app)
        req = Request.blank('?size=1&volume_type_name=vtype')
        res = c.create(req)

        c = Controller({'account_id':  self.account_id}, self.mock_app)
        req = Request.blank('')
        res = c.index(req)
        self.assertEqual(len(res.body), 2)
        for v in res.body:
            self.assert_(v['id'].startswith('test'))
Exemple #55
0
    def test_index_populated(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)
        c = Controller({'account_id':  self.account_id, 'id': 'test2'},
                       self.mock_app)
        req = Request.blank('?size=1&volume_type_name=vtype')
        res = c.create(req)

        c = Controller({'account_id':  self.account_id}, self.mock_app)
        req = Request.blank('')
        res = c.index(req)
        self.assertEqual(len(res.body), 2)
        for v in res.body:
            self.assert_(v['id'].startswith('test'))
Exemple #56
0
 def test_show_fails_after_account_is_deleted(self):
     # create volume
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('?size=1&volume_type_name=vtype')
     c.create(req)
     # delete account
     self.account.status = 'DELETED'
     self.db.add(self.account)
     self.db.commit()
     # should raise not found
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('')
     self.assertRaises(HTTPNotFound, c.show, req)
     # admin still works
     c = Controller({'account_id': 'admin', 'id': 'test'},
                    self.mock_app)
     req = Request.blank('')
     res = c.show(req)
     self.assertEqual(res.body['id'], 'test')
Exemple #57
0
 def test_show_fails_after_account_is_deleted(self):
     # create volume
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('?size=1&volume_type_name=vtype')
     c.create(req)
     # delete account
     self.account.status = 'DELETED'
     self.db.add(self.account)
     self.db.commit()
     # should raise not found
     c = Controller({'account_id': self.account_id, 'id': 'test'},
                    self.mock_app)
     req = Request.blank('')
     self.assertRaises(HTTPNotFound, c.show, req)
     # admin still works
     c = Controller({'account_id': 'admin', 'id': 'test'},
                    self.mock_app)
     req = Request.blank('')
     res = c.show(req)
     self.assertEqual(res.body['id'], 'test')