示例#1
0
 def test_delete_backup_success(self):
     volume = self.create_volume('ACTIVE')
     # create controller
     c = Controller({
         'account_id': self.account.id,
         'id': 'backup1'
     }, self.mock_app)
     params = {
         'volume': volume.id,
     }
     req = Request.blank('?%s' % urlencode(params))
     # success returns dict
     resp = c.create(req)
     self.assertEquals(resp.body['account_id'], self.account.id)
     self.assertEquals(resp.body['volume_id'], volume.id)
     self.assertEquals(resp.body['status'], 'SAVING')
     # create controller for named request
     c = Controller({
         'account_id': self.account.id,
         'id': 'backup1'
     }, self.mock_app)
     # make delete request
     resp = c.delete(Request.blank(''))
     self.assertEquals(resp.body['account_id'], self.account.id)
     self.assertEquals(resp.body['volume_id'], volume.id)
     self.assertEquals(resp.body['status'], 'DELETING')
示例#2
0
 def test_filtered_backups(self):
     vol1 = self.create_volume('ACTIVE')
     vol2 = self.create_volume('ACTIVE')
     # vol1/backup1
     req = Request.blank('?%s' % urlencode({'volume': vol1.id}))
     c = Controller({'id': 'backup1', 'account_id': self.account.id},
                    self.mock_app)
     resp = c.create(req)
     # vol2/backup2
     req = Request.blank('?%s' % urlencode({'volume': vol2.id}))
     c = Controller({'id': 'backup2', 'account_id': self.account.id},
                    self.mock_app)
     resp = c.create(req)
     # vol1/backup3
     req = Request.blank('?%s' % urlencode({'volume': vol1.id}))
     c = Controller({'id': 'backup3', 'account_id': self.account.id},
                    self.mock_app)
     resp = c.create(req)
     # un-filtered backups
     req = Request.blank('')
     resp = c.index(req)
     self.assertEquals(len(resp.body), 3)
     # filter backups for vol2 (should just be backup2)
     req = Request.blank('?volume_id=%s' % vol2.id)
     resp = c.index(req)
     self.assertEquals(len(resp.body), 1)
     backup2 = resp.body[0]
     self.assertEquals(backup2['volume_id'], vol2.id)
     # filter backups for vol1 (should have backup1 & backup3)
     req = Request.blank('?volume_id=%s' % vol1.id)
     resp = c.index(req)
     self.assertEquals(len(resp.body), 2)
     for backup in resp.body:
         self.assertEquals(backup['volume_id'], vol1.id)
示例#3
0
 def test_get_single_backup(self):
     # create a volume directly in the db
     volume = self.create_volume('ACTIVE')
     # create controller
     c = Controller({
         'account_id': self.account.id,
         'id': 'backup1'
     }, self.mock_app)
     # use the api to create a backup
     params = {
         'volume': volume.id,
     }
     req = Request.blank('?%s' % urlencode(params))
     resp = c.create(req)
     self.assertEquals(resp.body['id'], 'backup1')
     self.assertEquals(resp.body['volume_id'], volume.id)
     self.assertEquals(resp.body['status'], 'SAVING')
     # make a new request against show for the name of backup
     c = Controller({
         'account_id': self.account.id,
         'id': 'backup1'
     }, self.mock_app)
     req = Request.blank('')
     resp = c.show(req)
     self.assertEquals(resp.body['id'], 'backup1')
     self.assertEquals(resp.body['volume_id'], volume.id)
     self.assertEquals(resp.body['status'], 'SAVING')
示例#4
0
 def test_list_populated_backups(self):
     # create a volume directly in the db
     volume = self.create_volume('ACTIVE')
     # use the api to create a few backups
     for i in range(3):
         backup_id = 'backup%s' % i
         c = Controller({
             'account_id': self.account.id,
             'id': backup_id
         }, self.mock_app)
         params = {
             'volume': volume.id,
         }
         req = Request.blank('?%s' % urlencode(params))
         resp = c.create(req)
         self.assertEqual(resp.body['id'], backup_id)
         self.assertEquals(resp.body['volume_id'], volume.id)
         self.assertEquals(resp.body['status'], 'SAVING')
     # get the index/listing of the newly created backups
     c = Controller({'account_id': self.account.id}, self.mock_app)
     req = Request.blank('')
     resp = c.index(req)
     # make sure everything looks to be there
     self.assertEquals(len(resp.body), 3)
     for backup in resp.body:
         self.assert_(backup['id'].startswith('backup'))
示例#5
0
 def test_delete_backup_waiting_for_audit(self):
     v = self.create_volume()
     b = db.models.Backup(v, status='AUDITING')
     self.db.add(b)
     self.db.commit()
     c = Controller({'account_id': self.account.id,
                     'id': b.id}, self.mock_app)
     self.assertRaises(HTTPNotFound, c.delete, Request.blank(''))
示例#6
0
 def test_delete_backup_already_deleted(self):
     v = self.create_volume()
     b = db.models.Backup(v, status='DELETED')
     self.db.add(b)
     self.db.commit()
     c = Controller({'account_id': self.account.id,
                     'id': b.id}, self.mock_app)
     self.assertRaises(HTTPNotFound, c.delete, Request.blank(''))
示例#7
0
 def test_delete_backup_not_found(self):
     # create controller for named request
     c = Controller({
         'account_id': self.account.id,
         'id': 'backup1'
     }, self.mock_app)
     # make delete request
     self.assertRaises(HTTPNotFound, c.delete, Request.blank(''))
示例#8
0
 def test_get_backup_not_found(self):
     # create controller
     c = Controller({
         'account_id': self.account.id,
         'id': 'backup1'
     }, self.mock_app)
     req = Request.blank('')
     self.assertRaises(HTTPNotFound, c.show, req)
示例#9
0
 def test_create_backup_invalid_params(self):
     # create controller
     c = Controller({'account_id': self.account.id, 'id': 'backup1'},
                    self.mock_app)
     # test missing name
     req = Request.blank('')
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     # test missing volume
     params = {}
     req = Request.blank('?%s' % urlencode(params))
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
示例#10
0
 def test_delete_backup_node_request_fails(self):
     v = self.create_volume()
     b = db.models.Backup(v, status='AVAILABLE')
     self.db.add(b)
     self.db.commit()
     c = Controller({'account_id': self.account.id,
                     'id': b.id}, self.mock_app)
     error = json.dumps({'reason': 'failed'})
     self.mock_urlopen.resp = [HTTPError('', 500, 'kaboom!', {},
                                         StringIO(error))]
     self.assertRaises(base.NodeError, c.delete, Request.blank(''))
     self.assertEquals(b.status, 'AVAILABLE')
示例#11
0
    def test_per_volume_limit(self):
        volume = self.create_volume('ACTIVE')

        # 8 active
        for i in range(8):
            backup_id = 'backup%s' % i
            b = db.models.Backup(volume, id=backup_id, status='ACTIVE')
            self.db.add(b)

        # 1 DELETING
        b = db.models.Backup(volume, id='backup8', status='DELETING')
        self.db.add(b)
        b = db.models.Backup(volume, id='backup9', status='AUDITING')
        self.db.add(b)
        b = db.models.Backup(volume, id='backup10', status='DELETED')
        self.db.add(b)
        b = db.models.Backup(volume, id='backup11', status='AUDITING')
        self.db.add(b)
        self.db.commit()

        c = Controller({'account_id': self.account.id, 'id': 'backup12'},
                       self.mock_app)
        params = {'volume': volume.id}
        req = Request.blank('?%s' % urlencode(params))
        resp = c.create(req)
        self.assertEquals(resp.body['account_id'], self.account.id)
        self.assertEquals(resp.body['volume_id'], volume.id)
        self.assertEquals(resp.body['id'], 'backup12')
        self.assertEquals(resp.body['status'], 'SAVING')

        c = Controller({'account_id': self.account.id, 'id': 'backup13'},
                       self.mock_app)
        params = {'volume': volume.id}
        req = Request.blank('?%s' % urlencode(params))
        self.assertRaises(HTTPPreconditionFailed, c.create, req)
        try:
            c.create(req)
        except HTTPPreconditionFailed, e:
            self.assert_(volume.id in e.detail)
示例#12
0
 def test_create_backup_imaging_scrub(self):
     volume = self.create_volume('IMAGING_SCRUB')
     # create controller
     c = Controller({'account_id': self.account.id, 'id': 'backup1'},
                    self.mock_app)
     params = {
         'volume': volume.id,
     }
     req = Request.blank('?%s' % urlencode(params))
     # success returns dict
     resp = c.create(req)
     self.assertEquals(resp.body['account_id'], self.account.id)
     self.assertEquals(resp.body['volume_id'], volume.id)
     self.assertEquals(resp.body['status'], 'SAVING')
示例#13
0
 def test_create_backup_volume_not_found(self):
     volume_id = 'volume-not-found'
     # create controller
     c = Controller({'account_id': self.account.id, 'id': 'backup1'},
                    self.mock_app)
     params = {
         'volume': volume_id,
     }
     req = Request.blank('?%s' % urlencode(params))
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     try:
         c.create(req)
     except HTTPPreconditionFailed, e:
         self.assert_(volume_id in e.detail)
示例#14
0
 def test_create_backup_invalid_volume(self):
     # create volume in non-ACTIVE state
     volume = self.create_volume('ERROR')
     # create controller
     c = Controller({'account_id': self.account.id, 'id': 'backup1'},
                    self.mock_app)
     params = {
         'volume': volume.id,
     }
     req = Request.blank('?%s' % urlencode(params))
     self.assertRaises(HTTPPreconditionFailed, c.create, req)
     try:
         c.create(req)
     except HTTPPreconditionFailed, e:
         self.assert_(volume.id in e.detail)
示例#15
0
 def test_create_stacked_backup(self):
     # create volume in db
     volume = self.create_volume('ACTIVE')
     # create controller
     c = Controller({'account_id': self.account.id, 'id': 'backup1'},
                    self.mock_app)
     # setup backup params
     params = {
         'volume': volume.id,
     }
     req = Request.blank('?%s' % urlencode(params))
     # prime urlopen response with Exception
     error = json.dumps({'reason': 'failed'})
     self.mock_urlopen.resp = [HTTPError('', 409, 'already snapped!', {},
                                         StringIO(error))]
     self.assertRaises(base.NodeError, c.create, req)
     # Node error should not leave a backup record around
     backup = self.db.query(db.models.Backup).get('backup1')
     self.assertEquals(backup, None)
示例#16
0
 def test_list_empty_backups(self):
     # create controller
     c = Controller({'account_id': self.account.id}, self.mock_app)
     req = Request.blank('')
     resp = c.index(req)
     self.assertEquals(len(resp.body), 0)