Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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')
Beispiel #7
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')
Beispiel #8
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'))
Beispiel #9
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'))
Beispiel #10
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)
Beispiel #11
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'])
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
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'])
Beispiel #15
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')
Beispiel #16
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')
Beispiel #17
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)
Beispiel #18
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')
Beispiel #19
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')
Beispiel #20
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')
Beispiel #21
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')
Beispiel #22
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)
Beispiel #23
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)
Beispiel #24
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)
Beispiel #25
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)