def test_get_ceph_request_rbd(self, uuid1, mock_create_pool,
                               mock_request_access,
                               mock_bluestore_compression):
     self.assert_libvirt_rbd_imagebackend_allowed.return_value = True
     self.test_config.set('rbd-pool', 'nova')
     self.test_config.set('ceph-osd-replication-count', 3)
     self.test_config.set('ceph-pool-weight', 28)
     self.test_config.set('libvirt-image-backend', 'rbd')
     uuid1.return_value = 'my_uuid'
     expected = hooks.CephBrokerRq(request_id="my_uuid")
     result = hooks.get_ceph_request()
     mock_create_pool.assert_called_with(name='nova',
                                         replica_count=3,
                                         weight=28,
                                         group='vms',
                                         app_name='rbd')
     mock_request_access.assert_not_called()
     self.assertEqual(expected, result)
     # confirm operation with bluestore compression
     mock_create_pool.reset_mock()
     mock_bluestore_compression().get_kwargs.return_value = {
         'compression_mode': 'fake',
     }
     hooks.get_ceph_request()
     mock_create_pool.assert_called_once_with(name='nova',
                                              replica_count=3,
                                              weight=28,
                                              group='vms',
                                              app_name='rbd',
                                              compression_mode='fake')
 def test_get_ceph_request_perms(self, uuid1, mock_create_pool,
                                 mock_request_access):
     self.assert_libvirt_rbd_imagebackend_allowed.return_value = True
     self.test_config.set('rbd-pool', 'nova')
     self.test_config.set('ceph-osd-replication-count', 3)
     self.test_config.set('ceph-pool-weight', 28)
     self.test_config.set('libvirt-image-backend', 'rbd')
     self.test_config.set('restrict-ceph-pools', True)
     uuid1.return_value = 'my_uuid'
     expected = hooks.CephBrokerRq(request_id="my_uuid")
     result = hooks.get_ceph_request()
     mock_create_pool.assert_called_with(name='nova',
                                         replica_count=3,
                                         weight=28,
                                         group='vms',
                                         app_name='rbd')
     mock_request_access.assert_has_calls([
         call(name='volumes',
              object_prefix_permissions={'class-read': ['rbd_children']},
              permission='rwx'),
         call(name='images',
              object_prefix_permissions={'class-read': ['rbd_children']},
              permission='rwx'),
         call(name='vms',
              object_prefix_permissions={'class-read': ['rbd_children']},
              permission='rwx'),
     ])
     self.assertEqual(expected, result)
 def test_get_ceph_request_rbd_ec(self, uuid1, mock_create_pool,
                                  mock_request_access,
                                  mock_create_erasure_profile,
                                  mock_create_erasure_pool,
                                  mock_bluestore_compression):
     self.assert_libvirt_rbd_imagebackend_allowed.return_value = True
     self.test_config.set('rbd-pool', 'nova')
     self.test_config.set('ceph-osd-replication-count', 3)
     self.test_config.set('ceph-pool-weight', 28)
     self.test_config.set('libvirt-image-backend', 'rbd')
     self.test_config.set('pool-type', 'erasure-coded')
     self.test_config.set('ec-profile-plugin', 'shec')
     self.test_config.set('ec-profile-k', 6)
     self.test_config.set('ec-profile-m', 2)
     self.test_config.set('ec-profile-durability-estimator', 2)
     uuid1.return_value = 'my_uuid'
     expected = hooks.CephBrokerRq(request_id="my_uuid")
     result = hooks.get_ceph_request()
     mock_create_pool.assert_called_with(name='nova-metadata',
                                         replica_count=3,
                                         weight=0.28,
                                         group='vms',
                                         app_name='rbd')
     mock_create_erasure_profile.assert_called_with(
         name='nova-profile',
         k=6,
         m=2,
         lrc_locality=None,
         lrc_crush_locality=None,
         shec_durability_estimator=2,
         clay_helper_chunks=None,
         clay_scalar_mds=None,
         device_class=None,
         erasure_type='shec',
         erasure_technique=None)
     mock_create_erasure_pool.assert_called_with(
         name='nova',
         erasure_profile='nova-profile',
         weight=27.72,
         group='vms',
         app_name='rbd',
         allow_ec_overwrites=True)
     mock_request_access.assert_not_called()
     self.assertEqual(expected, result)
     # confirm operation with bluestore compression
     mock_create_erasure_pool.reset_mock()
     mock_bluestore_compression().get_kwargs.return_value = {
         'compression_mode': 'fake',
     }
     hooks.get_ceph_request()
     mock_create_erasure_pool.assert_called_with(
         name='nova',
         erasure_profile='nova-profile',
         weight=27.72,
         group='vms',
         app_name='rbd',
         allow_ec_overwrites=True,
         compression_mode='fake',
     )
 def test_get_ceph_request(self, uuid1, mock_create_pool,
                           mock_request_access, mock_bluestore_compression):
     self.assert_libvirt_rbd_imagebackend_allowed.return_value = True
     self.test_config.set('rbd-pool', 'nova')
     self.test_config.set('ceph-osd-replication-count', 3)
     self.test_config.set('ceph-pool-weight', 28)
     uuid1.return_value = 'my_uuid'
     expected = hooks.CephBrokerRq(request_id="my_uuid")
     result = hooks.get_ceph_request()
     mock_create_pool.assert_not_called()
     mock_request_access.assert_not_called()
     self.assertEqual(expected, result)
Exemplo n.º 5
0
    def test__handle_ceph_request_already_sent(
            self, get_request_states, get_ceph_request):
        request = hooks.CephBrokerRq()
        get_ceph_request.return_value = request
        get_request_states.return_value = {
            'ceph:43': {'complete': False, 'sent': True}
        }
        hooks._handle_ceph_request()

        get_ceph_request.assert_called_once_with()
        get_request_states.assert_called_once_with(request, relation='ceph')
        self.relation_set.assert_not_called()
Exemplo n.º 6
0
    def test__handle_ceph_request_complete_no_broker(
            self, _get_broker_rid_unit_for_previous_request,
            get_request_states, get_ceph_request, is_broker_action_done):
        request = hooks.CephBrokerRq()
        get_ceph_request.return_value = request
        get_request_states.return_value = {
            'ceph:43': {'complete': True, 'sent': True}
        }
        _get_broker_rid_unit_for_previous_request.return_value = None, None
        hooks._handle_ceph_request()

        is_broker_action_done.assert_not_called()
        get_ceph_request.assert_called_once_with()
        get_request_states.assert_called_once_with(request, relation='ceph')
Exemplo n.º 7
0
    def test__handle_ceph_request_send_request(
            self, get_request_states, get_ceph_request):
        request = hooks.CephBrokerRq()
        get_ceph_request.return_value = request
        get_request_states.return_value = {
            'ceph:43': {'complete': False, 'sent': False}
        }
        self.relation_ids.return_value = ['ceph:43']
        hooks._handle_ceph_request()

        get_ceph_request.assert_called_once_with()
        get_request_states.assert_called_once_with(request, relation='ceph')
        self.relation_set.assert_called_once_with(
            relation_id='ceph:43', broker_req=request.request)
 def test__get_broker_rid_unit_for_previous_request_not_found(
         self, get_previous_request, get_broker_rsp_key):
     request = hooks.CephBrokerRq()
     get_broker_rsp_key.return_value = "my_key"
     get_previous_request.return_value = request
     self.relation_ids.return_value = ['ceph:43']
     self.related_units.return_value = ['ceph-mon/0', 'ceph-mon/1']
     self.relation_get.side_effect = [{}, {}]
     rid, unit = hooks._get_broker_rid_unit_for_previous_request()
     get_previous_request.assert_called_once_with('ceph:43')
     get_broker_rsp_key.assert_called_once_with()
     self.relation_get.assert_has_calls = [
         call(rid='ceph:43', unit='ceph-mon/0'),
         call(rid='ceph:43', unit='ceph-mon/1')
     ]
     self.assertIsNone(unit)
     self.assertIsNone(rid)
 def test_get_ceph_request_rbd(self, uuid1, mock_create_pool,
                               mock_request_access):
     self.assert_libvirt_rbd_imagebackend_allowed.return_value = True
     self.test_config.set('rbd-pool', 'nova')
     self.test_config.set('ceph-osd-replication-count', 3)
     self.test_config.set('ceph-pool-weight', 28)
     self.test_config.set('libvirt-image-backend', 'rbd')
     uuid1.return_value = 'my_uuid'
     expected = hooks.CephBrokerRq(request_id="my_uuid")
     result = hooks.get_ceph_request()
     mock_create_pool.assert_called_with(name='nova',
                                         replica_count=3,
                                         weight=28,
                                         group='vms',
                                         app_name='rbd')
     mock_request_access.assert_not_called()
     self.assertEqual(expected, result)
Exemplo n.º 10
0
    def test__handle_ceph_request_complete_no_restart(
            self, _get_broker_rid_unit_for_previous_request,
            get_request_states, get_ceph_request, is_broker_action_done,
            service_restart):
        request = hooks.CephBrokerRq()
        get_ceph_request.return_value = request
        get_request_states.return_value = {
            'ceph:43': {'complete': True, 'sent': True}
        }
        _get_broker_rid_unit_for_previous_request.return_value = 'ceph:43',\
                                                                 'ceph-mon/0'
        is_broker_action_done.return_value = True
        hooks._handle_ceph_request()

        service_restart.assert_not_called()
        is_broker_action_done.assert_called_once_with(
            'nova_compute_restart', 'ceph:43', 'ceph-mon/0')
        get_ceph_request.assert_called_once_with()
        get_request_states.assert_called_once_with(request, relation='ceph')
Exemplo n.º 11
0
 def test__get_broker_rid_unit_for_previous_request(
         self, get_previous_request, get_broker_rsp_key):
     request = hooks.CephBrokerRq()
     get_broker_rsp_key.return_value = "my_key"
     get_previous_request.return_value = request
     self.relation_ids.return_value = ['ceph:43']
     self.related_units.return_value = ['ceph-mon/0', 'ceph-mon/1']
     self.relation_get.side_effect = [{}, {
         'my_key': '{"api-version": 1, "ops": [], '
                   '"request-id": "' + request.request_id + '"}'
     }]
     rid, unit = hooks._get_broker_rid_unit_for_previous_request()
     get_previous_request.assert_called_once_with('ceph:43')
     get_broker_rsp_key.assert_called_once_with()
     self.relation_get.assert_has_calls = [
         call(rid='ceph:43', unit='ceph-mon/0'),
         call(rid='ceph:43', unit='ceph-mon/1')
     ]
     self.assertEqual('ceph-mon/1', unit)
     self.assertEqual('ceph:43', rid)