Esempio n. 1
0
 def test_share_host_update_db(self):
     with mock.patch.object(timeutils, 'utcnow',
                            mock.Mock(return_value='fake-now')):
         driver.share_update_db(self.context, 31337, 'fake_host')
         db.share_update.assert_called_once_with(
             self.context, 31337,
             {'host': 'fake_host', 'scheduled_at': 'fake-now'})
Esempio n. 2
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, {})
Esempio n. 3
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, {})
Esempio n. 4
0
    def test_share_host_update_db(self):
        self.mox.StubOutWithMock(timeutils, 'utcnow')
        self.mox.StubOutWithMock(db, 'share_update')

        timeutils.utcnow().AndReturn('fake-now')
        db.share_update(self.context, 31337,
                        {'host': 'fake_host',
                         'scheduled_at': 'fake-now'})

        self.mox.ReplayAll()
        driver.share_update_db(self.context, 31337, 'fake_host')
Esempio n. 5
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)
Esempio n. 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)
    def schedule_create_share(self, context, request_spec, filter_properties):
        weighed_host = self._schedule_share(context, request_spec,
                                            filter_properties)

        if not weighed_host:
            raise exception.NoValidHost(reason="")

        host = weighed_host.obj.host
        share_id = request_spec['share_id']
        snapshot_id = request_spec['snapshot_id']

        updated_share = driver.share_update_db(context, share_id, host)
        self._post_select_populate_filter_properties(filter_properties,
                                                     weighed_host.obj)

        # context is not serializable
        filter_properties.pop('context', None)

        self.share_rpcapi.create_share_instance(
            context,
            updated_share.instance,
            host,
            request_spec=request_spec,
            filter_properties=filter_properties,
            snapshot_id=snapshot_id)
Esempio n. 8
0
    def schedule_create_share(self, context, request_spec, filter_properties):
        weighed_host = self._schedule_share(context,
                                            request_spec,
                                            filter_properties)

        if not weighed_host:
            raise exception.NoValidHost(reason="")

        host = weighed_host.obj.host
        share_id = request_spec['share_id']
        snapshot_id = request_spec['snapshot_id']

        updated_share = driver.share_update_db(context, share_id, host)
        self._post_select_populate_filter_properties(filter_properties,
                                                     weighed_host.obj)

        # context is not serializable
        filter_properties.pop('context', None)

        self.share_rpcapi.create_share_instance(
            context, updated_share.instance, host,
            request_spec=request_spec,
            filter_properties=filter_properties,
            snapshot_id=snapshot_id
        )
Esempio n. 9
0
    def schedule_create_share(self, context, request_spec, filter_properties):
        """Picks a host that is up at random."""
        topic = CONF.share_topic
        host = self._schedule(context, topic, request_spec,
                              filter_properties=filter_properties)
        share_id = request_spec['share_id']
        snapshot_id = request_spec['snapshot_id']

        updated_share = driver.share_update_db(context, share_id, host)
        self.share_rpcapi.create_share(context, updated_share, host,
                                       request_spec,
                                       filter_properties,
                                       snapshot_id)
Esempio n. 10
0
    def schedule_create_share(self, context, request_spec, filter_properties):
        """Picks a host that is up at random."""
        topic = CONF.share_topic
        host = self._schedule(context, topic, request_spec,
                              filter_properties=filter_properties)
        share_id = request_spec['share_id']
        snapshot_id = request_spec['snapshot_id']

        updated_share = driver.share_update_db(context, share_id, host)
        self.share_rpcapi.create_share(context, updated_share, host,
                                       request_spec,
                                       filter_properties,
                                       snapshot_id)
Esempio n. 11
0
    def test_create_share_availability_zone_on_host(self):
        share_id = 'fake'
        fake_share = {'id': share_id,
                      'availability_zone': 'fake:fake',
                      'size': 1}

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

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

        db.service_get_by_args(IsA(context.RequestContext), 'fake',
                               'manila-share').AndReturn('fake_service')
        utils.service_is_up('fake_service').AndReturn(True)
        driver.share_update_db(IsA(context.RequestContext), share_id,
                               'fake').AndReturn(fake_share)

        self.mox.ReplayAll()
        self.driver.schedule_create_share(self.admin_context,
                                          fake_request_spec, {})
Esempio n. 12
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 = 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)
Esempio n. 13
0
 def test_share_host_update_db(self):
     with mock.patch.object(timeutils, "utcnow", mock.Mock(return_value="fake-now")):
         driver.share_update_db(self.context, 31337, "fake_host")
         db.share_update.assert_called_once_with(
             self.context, 31337, {"host": "fake_host", "scheduled_at": "fake-now"}
         )