Esempio n. 1
0
    def test_suspects(self):
        backup = ScrubSuspects(self.conf, self.db)

        not_expected1 = Volume(0, 'vtype', status='AVAILABLE', id='n1',
                               last_modified=datetime(2000, 01, 01, 1, 1, 1),
                               node=self.node, account=self.account)
        self.db.add(not_expected1)

        not_expected2 = Volume(0, 'vtype', status='DELETING', id='n2',
                               last_modified=datetime(2000, 01, 01, 1, 1, 25),
                               node=self.node, account=self.account)

        self.db.add(not_expected1)
        expected = Volume(0, 'vtype', status='DELETING', id='v1',
                          last_modified=datetime(2000, 01, 01, 1, 1, 1),
                          node=self.node, account=self.account)
        self.db.add(expected)

        # Query the suspects for scrubs that are older than 10 seconds ago
        results = backup.suspects(
            timedelta(seconds=10), datetime(2000, 01, 01, 1, 1, 30)).all()

        # Assert the correct scrubs are in the results
        self.assertIn(expected, results)
        self.assertNotIn(not_expected1, results)
        self.assertNotIn(not_expected2, results)
Esempio n. 2
0
    def create(self, request):
        """
        PUT /v1.0/{account_id}/volumes/{id}?size=X&volume_type_name=Z

        Create volume
        """
        volume_type = self._validate_volume_type(request.params)
        backup = self._validate_backup(request.params)
        source = self._validate_source(request.params)
        size = self._validate_size(request.params, volume_type, backup, source)
        affinity = self._validate_affinity(request.params)
        image_id = request.params.get('image_id')
        status = 'NEW'
        imaging = False
        if image_id:
            # We don't want a huge race condition about scheduling with images
            # running on a node so we'll go ahead and create in that state.
            status = 'IMAGING'
            imaging = True

        nodes = self.get_recommended_nodes(volume_type.name, size,
                                           imaging=imaging,
                                           affinity=affinity)

        volume = Volume(id=self.id, account_id=self.account_id, status=status,
                        volume_type=volume_type, size=size, image_id=image_id)
        self.db.add(volume)

        # issue backend request(s)
        try:
            volume_info = self._assign_node(volume, backup, source, nodes)
        except IntegrityError:
            # duplicate id
            self.db.rollback()
            update_params = {
                'status': status,
                'size': size,
                'volume_type_name': volume_type.name,
                'image_id': image_id,
            }
            # optomistic lock
            count = self.db.query(Volume).\
                filter(and_(Volume.id == self.id,
                            Volume.account_id == self.account_id,
                            Volume.status.in_(['ERROR', 'DELETED']))).\
                update(update_params, synchronize_session=False)
            if not count:
                raise HTTPConflict("Volume '%s' already exists" % self.id)
            # still in uncommited update transaction
            volume = self.db.query(Volume).get(self.id)
            volume_info = self._assign_node(volume, backup, source, nodes)

        volume.status = volume_info['status']
        self.db.commit()
        response = dict(volume)
        response['cinder_host'] = volume.node.cinder_host
        return Response(response)
Esempio n. 3
0
 def create(self, status, last_modified):
     volume = Volume(0, 'vtype', status=status,
                     id=str(uuid.uuid4()), node=self.node,
                     account=self.account)
     backup = Backup(volume, status='AVAILABLE',
                     volume_id=str(uuid.uuid4()))
     self.db.add_all([volume, backup])
     self.db.commit()
     # Assign the backup as the restore of the volume
     volume.restore_of = backup.id
     volume.last_modified = last_modified
     self.db.commit()
     return volume
Esempio n. 4
0
 def create(self, status, last_modified):
     volume = Volume(0, 'vtype', status=status,
                     id=str(uuid.uuid4()), node=self.node,
                     account=self.account)
     backup = Backup(volume, status='AVAILABLE',
                     volume_id=str(uuid.uuid4()))
     self.db.add_all([volume, backup])
     self.db.commit()
     # Assign the backup as the restore of the volume
     volume.restore_of = backup.id
     volume.last_modified = last_modified
     self.db.commit()
     return volume
Esempio n. 5
0
    def setUp(self):
        self.conf = LunrConfig({
            'db': {'auto_create': True, 'url': 'sqlite://'},
            'scrub-suspects': {'span': 'seconds=10'},
        })
        self.db = db.configure(self.conf)

        self.account = Account()
        vtype = VolumeType('vtype')
        self.node = Node('node', 10, volume_type=vtype,
                         hostname='10.127.0.1', port=8080)
        self.db.add_all([vtype, self.node])
        volume = Volume(0, 'vtype', status='AVAILABLE', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        volume = Volume(0, 'vtype', status='DELETED', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        volume = Volume(0, 'vtype', status='DELETING', id=str(uuid.uuid4()),
                        node=self.node, account=self.account)
        self.db.add(volume)
        self.db.commit()
Esempio n. 6
0
    def setUp(self):
        self.conf = LunrConfig({'db': {'auto_create': True,
                                       'url': 'sqlite://'}})
        self.sess = db.configure(self.conf)

        vtype = VolumeType('vtype')
        node = Node('node1', volume_type=vtype,
                    hostname='10.127.0.1', port=8080)
        account_id = self.sess.get_or_create_account('test_account').id
        self.volume = Volume(1, 'vtype', node=node, account_id=account_id)
        self.sess.add_all([vtype, node, self.volume])
        self.sess.commit()
Esempio n. 7
0
    def create(self, request):
        """
        PUT /v1.0/{account_id}/volumes/{id}?size=X&volume_type_name=Z

        Create volume
        """
        name = self._validate_name(request.params)
        volume_type = self._validate_volume_type(request.params)
        backup = self._validate_backup(request.params)
        source = self._validate_source(request.params)
        size = self._validate_size(request.params, volume_type, backup, source)
        affinity = self._validate_affinity(request.params)
        force_node = self._validate_force_node(request.params)
        image_id = request.params.get('image_id')
        status = 'NEW'
        imaging = False
        if image_id:
            # We don't want a huge race condition about scheduling with images
            # running on a node so we'll go ahead and create in that state.
            status = 'IMAGING'
            imaging = True

        nodes = self.get_recommended_nodes(volume_type.name,
                                           size,
                                           imaging=imaging,
                                           affinity=affinity,
                                           force_node=force_node)

        volume = Volume(id=self.id,
                        account_id=self.account_id,
                        status=status,
                        volume_type=volume_type,
                        size=size,
                        image_id=image_id,
                        name=name)
        self.db.add(volume)

        # issue backend request(s)
        try:
            volume_info = self._assign_node(volume, backup, source, nodes)
        except IntegrityError:
            # duplicate id
            self.db.rollback()
            update_params = {
                'status': status,
                'size': size,
                'volume_type_name': volume_type.name,
                'image_id': image_id,
                'name': name,
            }
            # optomistic lock
            count = self.db.query(Volume).\
                filter(and_(Volume.id == self.id,
                            Volume.account_id == self.account_id,
                            Volume.status.in_(['ERROR', 'DELETED']))).\
                update(update_params, synchronize_session=False)
            if not count:
                raise HTTPConflict("Volume '%s' already exists" % self.id)
            # still in uncommited update transaction
            volume = self.db.query(Volume).get(self.id)
            volume_info = self._assign_node(volume, backup, source, nodes)

        volume.status = volume_info['status']
        self.db.commit()
        response = dict(volume)
        response['cinder_host'] = volume.node.cinder_host
        return Response(response)