Beispiel #1
0
    def test_create_share_availability_zone(self):
        share_id = 'fake'
        fake_share = {'id': share_id,
                      'availability_zone': 'fake:fake',
                      'size': 1}

        fake_service_1 = {'disabled': False, 'host': 'fake_host1',
                          'availability_zone': 'fake'}

        fake_service_2 = {'disabled': False, 'host': 'fake_host2',
                          'availability_zone': 'super_fake'}

        fake_result = [(fake_service_1, 0), (fake_service_2, 1)]

        fake_request_spec = {'share_id': share_id,
                             'share_properties': fake_share}

        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(driver, 'share_update_db')
        self.mox.StubOutWithMock(db, 'service_get_all_share_sorted')

        db.service_get_all_share_sorted(IsA(context.RequestContext))\
            .AndReturn(fake_result)

        utils.service_is_up(fake_service_1).AndReturn(True)
        driver.share_update_db(IsA(context.RequestContext), share_id,
                               fake_service_1['host']).AndReturn(fake_share)

        self.mox.ReplayAll()
        self.driver.schedule_create_share(self.context, fake_request_spec, {})
Beispiel #2
0
    def test_create_share_if_two_services_up(self):
        share_id = 'fake'
        fake_share = {'id': share_id, 'size': 1}

        fake_service_1 = {'disabled': False, 'host': 'fake_host1'}

        fake_service_2 = {'disabled': False, 'host': 'fake_host2'}

        fake_result = [(fake_service_1, 2), (fake_service_2, 1)]

        self.mox.StubOutWithMock(db, 'service_get_all_share_sorted')
        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(driver, 'share_update_db')

        fake_request_spec = {'share_id': share_id,
                             'share_properties': fake_share}

        db.service_get_all_share_sorted(IsA(context.RequestContext))\
            .AndReturn(fake_result)
        utils.service_is_up(IsA(dict)).AndReturn(True)
        driver.share_update_db(IsA(context.RequestContext), share_id,
                               'fake_host1').AndReturn(fake_share)
        self.mox.ReplayAll()

        self.driver.schedule_create_share(self.context, fake_request_spec, {})
Beispiel #3
0
    def test_create_share_if_services_not_available(self):
        share_id = 'fake'
        fake_share = {'id': share_id, 'size': 1}

        fake_result = []

        fake_request_spec = {'share_id': share_id,
                             'share_properties': fake_share}

        self.mox.StubOutWithMock(db, 'service_get_all_share_sorted')

        db.service_get_all_share_sorted(IsA(context.RequestContext))\
            .AndReturn(fake_result)

        self.mox.ReplayAll()

        self.assertRaises(exception.NoValidHost,
                          self.driver.schedule_create_share,
                          self.context, fake_request_spec, {})
Beispiel #4
0
    def schedule_create_share(self, context, request_spec, filter_properties):
        """Picks a host that is up and has the fewest shares."""
        # TODO(rushiagr) - pick only hosts that run shares
        elevated = context.elevated()

        share_id = request_spec.get('share_id')
        snapshot_id = request_spec.get('snapshot_id')
        share_properties = request_spec.get('share_properties')
        share_size = share_properties.get('size')
        availability_zone = share_properties.get('availability_zone')

        zone, host = None, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')
        if host and context.is_admin:
            service = db.service_get_by_args(elevated, host, CONF.share_topic)
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            updated_share = driver.share_update_db(context, share_id, host)
            self.share_rpcapi.create_share_instance(
                context,
                updated_share.instance,
                host,
                request_spec,
                None,
                snapshot_id=snapshot_id
            )
            return None

        results = db.service_get_all_share_sorted(elevated)
        if zone:
            results = [(service_g, gigs) for (service_g, gigs) in results
                       if service_g['availability_zone'] == zone]
        for result in results:
            (service, share_gigabytes) = result
            if share_gigabytes + share_size > CONF.max_gigabytes:
                msg = _("Not enough allocatable share gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                updated_share = driver.share_update_db(context, share_id,
                                                       service['host'])
                self.share_rpcapi.create_share_instance(
                    context,
                    updated_share.instance,
                    service['host'],
                    request_spec,
                    None,
                    snapshot_id=snapshot_id)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
Beispiel #5
0
    def test_create_share_if_max_gigabytes_exceeded(self):
        share_id = 'fake'
        fake_share = {'id': share_id, 'size': 10001}

        fake_service_1 = {'disabled': False, 'host': 'fake_host1'}

        fake_service_2 = {'disabled': False, 'host': 'fake_host2'}

        fake_result = [(fake_service_1, 5), (fake_service_2, 7)]

        fake_request_spec = {'share_id': share_id,
                             'share_properties': fake_share}

        self.mox.StubOutWithMock(db, 'service_get_all_share_sorted')

        db.service_get_all_share_sorted(IsA(context.RequestContext))\
            .AndReturn(fake_result)

        self.mox.ReplayAll()

        self.assertRaises(exception.NoValidHost,
                          self.driver.schedule_create_share,
                          self.context, fake_request_spec, {})
Beispiel #6
0
    def schedule_create_share(self, context, request_spec, filter_properties):
        """Picks a host that is up and has the fewest shares."""
        # TODO(rushiagr) - pick only hosts that run shares
        elevated = context.elevated()

        share_id = request_spec.get('share_id')
        snapshot_id = request_spec.get('snapshot_id')
        share_properties = request_spec.get('share_properties')
        share_size = share_properties.get('size')
        availability_zone = share_properties.get('availability_zone')

        zone, host = None, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')
        if host and context.is_admin:
            service = db.service_get_by_args(elevated, host, CONF.share_topic)
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            updated_share = driver.share_update_db(context, share_id, host)
            self.share_rpcapi.create_share(context,
                                           updated_share,
                                           host,
                                           request_spec,
                                           None,
                                           snapshot_id=snapshot_id)
            return None

        results = db.service_get_all_share_sorted(elevated)
        if zone:
            results = [(service, gigs) for (service, gigs) in results
                       if service['availability_zone'] == zone]
        for result in results:
            (service, share_gigabytes) = result
            if share_gigabytes + share_size > CONF.max_gigabytes:
                msg = _("Not enough allocatable share gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                updated_share = driver.share_update_db(context, share_id,
                                                       service['host'])
                self.share_rpcapi.create_share(context,
                                               updated_share,
                                               service['host'],
                                               request_spec,
                                               None,
                                               snapshot_id=snapshot_id)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
Beispiel #7
0
    def schedule_create_share(self, context, request_spec, filter_properties):
        """Picks a host that is up and has the fewest shares."""
        # TODO(rushiagr) - pick only hosts that run shares
        elevated = context.elevated()

        share_id = request_spec.get('share_id')
        snapshot_id = request_spec.get('snapshot_id')
        share_properties = request_spec.get('share_properties')
        share_size = share_properties.get('size')

        instance_properties = request_spec.get('share_instance_properties', {})
        availability_zone_id = instance_properties.get('availability_zone_id')

        results = db.service_get_all_share_sorted(elevated)
        if availability_zone_id:
            results = [
                (service_g, gigs) for (service_g, gigs) in results
                if (service_g['availability_zone_id'] == availability_zone_id)
            ]
        for result in results:
            (service, share_gigabytes) = result
            if share_gigabytes + share_size > CONF.max_gigabytes:
                msg = _("Not enough allocatable share gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                updated_share = base.share_update_db(context, share_id,
                                                     service['host'])
                self.share_rpcapi.create_share_instance(
                    context,
                    updated_share.instance,
                    service['host'],
                    request_spec,
                    None,
                    snapshot_id=snapshot_id)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
Beispiel #8
0
    def schedule_create_share(self, context, request_spec, filter_properties):
        """Picks a host that is up and has the fewest shares."""
        # TODO(rushiagr) - pick only hosts that run shares
        elevated = context.elevated()

        share_id = request_spec.get('share_id')
        snapshot_id = request_spec.get('snapshot_id')
        share_properties = request_spec.get('share_properties')
        share_size = share_properties.get('size')

        instance_properties = request_spec.get('share_instance_properties', {})
        availability_zone_id = instance_properties.get('availability_zone_id')

        results = db.service_get_all_share_sorted(elevated)
        if availability_zone_id:
            results = [(service_g, gigs) for (service_g, gigs) in results
                       if (service_g['availability_zone_id']
                           == availability_zone_id)]
        for result in results:
            (service, share_gigabytes) = result
            if share_gigabytes + share_size > CONF.max_gigabytes:
                msg = _("Not enough allocatable share gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                updated_share = base.share_update_db(context,
                                                     share_id,
                                                     service['host'])
                self.share_rpcapi.create_share_instance(
                    context,
                    updated_share.instance,
                    service['host'],
                    request_spec,
                    None,
                    snapshot_id=snapshot_id)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)