示例#1
0
 def test_create_erasure_profile(self, mock_create_erasure):
     req = json.dumps({
         'api-version':
         1,
         'ops': [{
             'op': 'create-erasure-profile',
             'name': 'foo',
             'erasure-type': 'jerasure',
             'failure-domain': 'rack',
             'k': 3,
             'm': 2,
         }]
     })
     rc = broker.process_requests(req)
     mock_create_erasure.assert_called_with(service='admin',
                                            erasure_plugin_name='jerasure',
                                            profile_name='foo',
                                            failure_domain='rack',
                                            data_chunks=3,
                                            coding_chunks=2,
                                            locality=None,
                                            durability_estimator=None,
                                            helper_chunks=None,
                                            scalar_mds=None,
                                            crush_locality=None,
                                            device_class=None,
                                            erasure_plugin_technique=None)
     self.assertEqual(json.loads(rc), {'exit-code': 0})
示例#2
0
def handle_broker_request(relid,
                          unit,
                          add_legacy_response=False,
                          recurse=True):
    """Retrieve broker request from relation, process, return response data.

    :param relid: Realtion ID
    :type relid: str
    :param unit: Remote unit name
    :type unit: str
    :param add_legacy_response: (Optional) Adds the legacy ``broker_rsp`` key
                                to the response in addition to the new way.
    :type add_legacy_response: bool
    :param recurse: Whether we should call out to update relation functions or
                    not.  Mainly used to handle recursion when called from
                    notify_rbd_mirrors()
    :type recurse: bool
    :returns: Dictionary of response data ready for use with relation_set.
    :rtype: dict
    """
    response = {}
    if not unit:
        unit = remote_unit()
    settings = relation_get(rid=relid, unit=unit)
    if 'broker_req' in settings:
        if not ceph.is_leader():
            log("Not leader - ignoring broker request", level=DEBUG)
        else:
            rsp = process_requests(settings['broker_req'])
            unit_id = settings.get('unit-name', unit).replace('/', '-')
            unit_response_key = 'broker-rsp-' + unit_id
            response.update({unit_response_key: rsp})
            if add_legacy_response:
                response.update({'broker_rsp': rsp})

            if relation_ids('rbd-mirror'):
                # NOTE(fnordahl): juju relation level data candidate
                # notify mons to flag that the other mon units should update
                # their ``rbd-mirror`` relations with information about new
                # pools.
                log('Notifying peers after processing broker request.',
                    level=DEBUG)
                notify_mons()

                if recurse:
                    # update ``rbd-mirror`` relations for this unit with
                    # information about new pools.
                    log(
                        'Notifying this units rbd-mirror relations after '
                        'processing broker request.',
                        level=DEBUG)
                    notify_rbd_mirrors()

    return response
示例#3
0
 def test_process_requests_delete_pool(self, mock_delete_pool):
     reqs = json.dumps({
         'api-version': 1,
         'ops': [{
             'op': 'delete-pool',
             'name': 'foo',
         }]
     })
     mock_delete_pool.return_value = {'exit-code': 0}
     rc = broker.process_requests(reqs)
     mock_delete_pool.assert_called_with(service='admin', name='foo')
     self.assertEqual(json.loads(rc), {'exit-code': 0})
示例#4
0
 def test_set_invalid_pool_value(self):
     reqs = json.dumps({
         'api-version':
         1,
         'ops': [{
             'op': 'set-pool-value',
             'name': 'foo',
             'key': 'size',
             'value': 'abc',
         }]
     })
     rc = broker.process_requests(reqs)
     self.assertEqual(json.loads(rc)['exit-code'], 1)
示例#5
0
 def test_remove_pool_snapshot(self, mock_snapshot_pool):
     reqs = json.dumps({
         'api-version':
         1,
         'ops': [{
             'op': 'remove-pool-snapshot',
             'name': 'foo',
             'snapshot-name': 'foo-snap1',
         }]
     })
     mock_snapshot_pool.return_value = {'exit-code': 0}
     rc = broker.process_requests(reqs)
     mock_snapshot_pool.assert_called_with(service='admin',
                                           pool_name='foo',
                                           snapshot_name='foo-snap1')
     self.assertEqual(json.loads(rc), {'exit-code': 0})
示例#6
0
 def test_set_pool_value(self, mock_set_pool):
     reqs = json.dumps({
         'api-version':
         1,
         'ops': [{
             'op': 'set-pool-value',
             'name': 'foo',
             'key': 'size',
             'value': 3,
         }]
     })
     mock_set_pool.return_value = {'exit-code': 0}
     rc = broker.process_requests(reqs)
     mock_set_pool.assert_called_with(service='admin',
                                      pool_name='foo',
                                      key='size',
                                      value=3)
     self.assertEqual(json.loads(rc), {'exit-code': 0})
示例#7
0
    def test_process_requests_remove_cache_tier(self, mock_pool,
                                                mock_pool_exists,
                                                mock_cmp_pkgrevno):
        mock_pool_exists.return_value = True
        mock_cmp_pkgrevno.return_value = 1
        reqs = json.dumps({
            'api-version':
            1,
            'ops': [{
                'op': 'remove-cache-tier',
                'hot-pool': 'foo-ssd',
            }]
        })
        rc = broker.process_requests(reqs)
        self.assertEqual(json.loads(rc), {'exit-code': 0})
        mock_pool_exists.assert_any_call(service='admin', name='foo-ssd')

        mock_pool.assert_called_with(cache_pool='foo-ssd')
示例#8
0
 def test_process_requests_create_erasure_pool(self, mock_profile_exists,
                                               mock_erasure_pool,
                                               mock_pool_exists,
                                               mock_cmp_pkgrevno):
     mock_pool_exists.return_value = False
     mock_cmp_pkgrevno.return_value = 1
     reqs = json.dumps({
         'api-version':
         1,
         'ops': [{
             'op': 'create-pool',
             'pool-type': 'erasure',
             'name': 'foo',
             'erasure-profile': 'default'
         }]
     })
     rc = broker.process_requests(reqs)
     mock_profile_exists.assert_called_with(service='admin', name='default')
     mock_pool_exists.assert_called_with(service='admin', name='foo')
     mock_erasure_pool.assert_called_with()
     self.assertEqual(json.loads(rc), {'exit-code': 0})
示例#9
0
    def test_process_requests_create_cache_tier(self, mock_pool,
                                                mock_pool_exists,
                                                mock_cmp_pkgrevno):
        mock_pool_exists.return_value = True
        mock_cmp_pkgrevno.return_value = 1
        reqs = json.dumps({
            'api-version':
            1,
            'ops': [{
                'op': 'create-cache-tier',
                'cold-pool': 'foo',
                'hot-pool': 'foo-ssd',
                'mode': 'writeback',
                'erasure-profile': 'default'
            }]
        })
        rc = broker.process_requests(reqs)
        self.assertEqual(json.loads(rc), {'exit-code': 0})

        mock_pool_exists.assert_any_call(service='admin', name='foo')
        mock_pool_exists.assert_any_call(service='admin', name='foo-ssd')

        mock_pool.assert_called_with(cache_pool='foo-ssd', mode='writeback')