示例#1
0
 def test_qos_specs_delete(self, mock_qos_delete, mock_qos_get_specs):
     req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' % (
         fake.PROJECT_ID, fake.QOS_SPEC_ID))
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         self.controller.delete(req, fake.QOS_SPEC_ID)
         self.assertEqual(1, notifier.get_notification_count())
    def test_qos_specs_delete_keys(self, mock_qos_delete_keys):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/666/delete_keys')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.controller.delete_keys(req, '666', body)
            self.assertEqual(1, notifier.get_notification_count())
 def test_qos_specs_delete_not_found(self, mock_qos_delete,
                                     mock_qos_get_specs):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/777')
         self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
                           req, '777')
         self.assertEqual(1, notifier.get_notification_count())
 def test_update_not_found(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/777')
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
                           req, '777', body)
         self.assertEqual(1, notifier.get_notification_count())
    def test_qos_specs_delete_keys_get_notifier(self, mock_qos_delete_keys):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/666/delete_keys')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier,
                        autospec=True) as mock_get_notifier:
            self.controller.delete_keys(req, '666', body)
            mock_get_notifier.assert_called_once_with('QoSSpecs')
 def test_update(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/555')
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         res = self.controller.update(req, '555', body)
         self.assertDictMatch(body, res)
         self.assertEqual(1, notifier.get_notification_count())
示例#7
0
    def test_create_failed(self, mock_qos_get_specs, mock_qos_spec_create):
        body = {"qos_specs": {"name": "555",
                              "key1": "value1"}}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPInternalServerError,
                              self.controller.create, req, body)
            self.assertEqual(1, notifier.get_notification_count())
    def test_qos_specs_delete_keys_get_notifier(self, mock_qos_delete_keys):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/666/delete_keys')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier',
                        return_value=notifier,
                        autospec=True) as mock_get_notifier:
            self.controller.delete_keys(req, '666', body)
            mock_get_notifier.assert_called_once_with('QoSSpecs')
示例#9
0
 def test_update_invalid_input(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                       (fake.PROJECT_ID, fake.INVALID_ID))
         body = {'qos_specs': {'key1': 'value1', 'key2': 'value2'}}
         self.assertRaises(exception.InvalidQoSSpecs,
                           self.controller.update, req, fake.INVALID_ID,
                           body)
         self.assertEqual(1, notifier.get_notification_count())
    def test_qos_specs_delete_inuse_force(self, mock_qos_delete,
                                          mock_qos_get_specs):
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/666?force=True')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPInternalServerError,
                              self.controller.delete,
                              req, '666')
            self.assertEqual(1, notifier.get_notification_count())
示例#11
0
 def test_update(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                       (fake.PROJECT_ID, fake.QOS_SPEC_ID))
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         res = self.controller.update(req, fake.QOS_SPEC_ID, body)
         self.assertDictMatch(body, res)
         self.assertEqual(1, notifier.get_notification_count())
示例#12
0
    def test_qos_specs_delete_keys_badkey(self, mock_qos_specs_delete):
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/666/delete_keys')
        body = {"keys": ['foo', 'zoo']}

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPBadRequest,
                              self.controller.delete_keys,
                              req, '666', body)
            self.assertEqual(1, notifier.get_notification_count())
示例#13
0
 def test_update_not_found(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank(
             '/v2/%s/qos-specs/%s' %
             (fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))
         body = {'qos_specs': {'key1': 'value1', 'key2': 'value2'}}
         self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
                           req, fake.WILL_NOT_BE_FOUND_ID, body)
         self.assertEqual(1, notifier.get_notification_count())
示例#14
0
 def test_update(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                       (fake.PROJECT_ID, fake.QOS_SPEC_ID))
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         res = self.controller.update(req, fake.QOS_SPEC_ID, body)
         self.assertDictEqual(body, res)
         self.assertEqual(1, notifier.get_notification_count())
    def test_qos_specs_delete_keys_badkey(self, mock_qos_specs_delete):
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/666/delete_keys')
        body = {"keys": ['foo', 'zoo']}

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPBadRequest,
                              self.controller.delete_keys,
                              req, '666', body)
            self.assertEqual(1, notifier.get_notification_count())
示例#16
0
 def test_qos_specs_delete_not_found(self, mock_qos_delete,
                                     mock_qos_get_specs):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                       (fake.PROJECT_ID,
                                        fake.WILL_NOT_BE_FOUND_ID))
         self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
                           req, fake.WILL_NOT_BE_FOUND_ID)
         self.assertEqual(1, notifier.get_notification_count())
示例#17
0
    def test_create_invalid_input(self, mock_qos_get_specs):
        body = {"qos_specs": {"name": 'qos_spec_%s' % fake.INVALID_ID,
                              "consumer": "invalid_consumer"}}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPBadRequest,
                              self.controller.create, req, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#18
0
    def test_qos_specs_delete_keys(self, mock_qos_delete_keys):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID),
                                      use_admin_context=True)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.controller.delete_keys(req, fake.IN_USE_ID, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#19
0
    def test_create_conflict(self, mock_qos_spec_create):
        body = {"qos_specs": {"name": 'qos_spec_%s' % fake.ALREADY_EXISTS_ID,
                              "key1": "value1"}}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPConflict,
                              self.controller.create, req, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#20
0
    def test_create_failed(self, mock_qos_spec_create):
        body = {"qos_specs": {"name": 'qos_spec_%s' % fake.ACTION_FAILED_ID,
                              "key1": "value1"}}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPInternalServerError,
                              self.controller.create, req, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#21
0
    def test_qos_specs_delete_keys_qos_notfound(self, mock_qos_specs_delete):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/777/delete_keys')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPNotFound,
                              self.controller.delete_keys,
                              req, '777', body)
            self.assertEqual(1, notifier.get_notification_count())
    def test_qos_specs_delete_keys_qos_notfound(self, mock_qos_specs_delete):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/777/delete_keys')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPNotFound,
                              self.controller.delete_keys,
                              req, '777', body)
            self.assertEqual(1, notifier.get_notification_count())
示例#23
0
    def test_create_invalid_input(self, mock_qos_get_specs):
        body = {"qos_specs": {"name": "444",
                              "consumer": "invalid_consumer"}}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPBadRequest,
                              self.controller.create, req, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#24
0
    def test_qos_specs_delete_inuse_force(self, mock_qos_delete,
                                          mock_qos_get_specs):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s?force=True' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID))

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPInternalServerError,
                              self.controller.delete, req, fake.IN_USE_ID)
            self.assertEqual(1, notifier.get_notification_count())
示例#25
0
 def test_update_invalid_input(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/888')
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update,
                           req, '888', body)
         self.assertEqual(1, notifier.get_notification_count())
示例#26
0
 def test_qos_specs_delete_not_found(self, mock_qos_delete,
                                     mock_qos_get_specs):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                       (fake.PROJECT_ID,
                                        fake.WILL_NOT_BE_FOUND_ID))
         self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
                           req, fake.WILL_NOT_BE_FOUND_ID)
         self.assertEqual(1, notifier.get_notification_count())
示例#27
0
    def test_create_conflict(self, mock_qos_get_specs, mock_qos_spec_create):
        body = {"qos_specs": {"name": 'qos_spec_%s' % fake.ALREADY_EXISTS_ID,
                              "key1": "value1"}}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPConflict,
                              self.controller.create, req, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#28
0
 def test_update_failed(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/999')
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         self.assertRaises(webob.exc.HTTPInternalServerError,
                           self.controller.update,
                           req, '999', body)
         self.assertEqual(1, notifier.get_notification_count())
示例#29
0
    def test_create(self, mock_qos_get_specs, mock_qos_spec_create):

        body = {"qos_specs": {"name": "qos_specs_1", "key1": "value1"}}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            res_dict = self.controller.create(req, body)

            self.assertEqual(1, notifier.get_notification_count())
            self.assertEqual('qos_specs_1', res_dict['qos_specs']['name'])
示例#30
0
    def test_qos_specs_delete_keys_badkey(self, mock_qos_specs_delete):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID))
        body = {"keys": ['foo', 'zoo']}

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(exception.QoSSpecsKeyNotFound,
                              self.controller.delete_keys,
                              req, fake.IN_USE_ID, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#31
0
 def test_update_invalid_input(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                       (fake.PROJECT_ID, fake.INVALID_ID))
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         self.assertRaises(webob.exc.HTTPBadRequest,
                           self.controller.update,
                           req, fake.INVALID_ID, body)
         self.assertEqual(1, notifier.get_notification_count())
示例#32
0
    def test_qos_specs_delete_keys_badkey(self, mock_qos_specs_delete):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID))
        body = {"keys": ['foo', 'zoo']}

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(exception.QoSSpecsKeyNotFound,
                              self.controller.delete_keys, req, fake.IN_USE_ID,
                              body)
            self.assertEqual(1, notifier.get_notification_count())
示例#33
0
    def test_qos_specs_delete_keys_qos_notfound(self, mock_qos_specs_delete):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID,
                                       fake.WILL_NOT_BE_FOUND_ID))

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPNotFound,
                              self.controller.delete_keys,
                              req, fake.WILL_NOT_BE_FOUND_ID, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#34
0
 def test_update_failed(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                       (fake.PROJECT_ID,
                                        fake.UPDATE_FAILED_ID))
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         self.assertRaises(webob.exc.HTTPInternalServerError,
                           self.controller.update,
                           req, fake.UPDATE_FAILED_ID, body)
         self.assertEqual(1, notifier.get_notification_count())
示例#35
0
 def test_update_failed(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank(
             '/v2/%s/qos-specs/%s' %
             (fake.PROJECT_ID, fake.UPDATE_FAILED_ID),
             use_admin_context=True)
         body = {'qos_specs': {'key1': 'value1', 'key2': 'value2'}}
         self.assertRaises(webob.exc.HTTPInternalServerError,
                           self.controller.update, req,
                           fake.UPDATE_FAILED_ID, body)
         self.assertEqual(1, notifier.get_notification_count())
示例#36
0
 def test_update_not_found(self, mock_qos_update):
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                       (fake.PROJECT_ID,
                                        fake.WILL_NOT_BE_FOUND_ID))
         body = {'qos_specs': {'key1': 'value1',
                               'key2': 'value2'}}
         self.assertRaises(exception.QoSSpecsNotFound,
                           self.controller.update,
                           req, fake.WILL_NOT_BE_FOUND_ID, body)
         self.assertEqual(1, notifier.get_notification_count())
示例#37
0
    def test_qos_specs_delete_keys_qos_notfound(self, mock_qos_specs_delete):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/delete_keys' %
            (fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(exception.QoSSpecsNotFound,
                              self.controller.delete_keys, req,
                              fake.WILL_NOT_BE_FOUND_ID, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#38
0
    def test_qos_specs_delete_keys_get_notifier(self, mock_qos_delete_keys):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID),
                                      use_admin_context=True)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier',
                        return_value=notifier,
                        autospec=True) as mock_get_notifier:
            self.controller.delete_keys(req, fake.IN_USE_ID, body)
            mock_get_notifier.assert_called_once_with('QoSSpecs')
    def test_create(self, mock_qos_get_specs, mock_qos_spec_create):

        body = {"qos_specs": {"name": "qos_specs_1",
                              "key1": "value1"}}
        req = fakes.HTTPRequest.blank('/v2/fake/qos-specs')

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            res_dict = self.controller.create(req, body)

            self.assertEqual(1, notifier.get_notification_count())
            self.assertEqual('qos_specs_1', res_dict['qos_specs']['name'])
示例#40
0
    def test_create(self, mock_validate, mock_qos_spec_create):

        body = {"qos_specs": {"name": "qos_specs_%s" % fake.QOS_SPEC_ID,
                              "key1": "value1"}}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            res_dict = self.controller.create(req, body)

            self.assertEqual(1, notifier.get_notification_count())
            self.assertEqual('qos_specs_%s' % fake.QOS_SPEC_ID,
                             res_dict['qos_specs']['name'])
            self.assertTrue(mock_validate.called)
示例#41
0
    def test_create(self, mock_validate, mock_qos_spec_create):

        body = {"qos_specs": {"name": "qos_specs_%s" % fake.QOS_SPEC_ID,
                              "key1": "value1"}}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            res_dict = self.controller.create(req, body)

            self.assertEqual(1, notifier.get_notification_count())
            self.assertEqual('qos_specs_%s' % fake.QOS_SPEC_ID,
                             res_dict['qos_specs']['name'])
            self.assertTrue(mock_validate.called)
示例#42
0
    def test_create_failed(self, mock_qos_spec_create):
        body = {
            "qos_specs": {
                "name": 'qos_spec_%s' % fake.ACTION_FAILED_ID,
                "key1": "value1"
            }
        }
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID,
                                      use_admin_context=True)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPInternalServerError,
                              self.controller.create, req, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#43
0
    def test_create_invalid_input(self, mock_qos_get_specs):
        body = {
            "qos_specs": {
                "name": 'qos_spec_%s' % fake.INVALID_ID,
                "consumer": "invalid_consumer"
            }
        }
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID,
                                      use_admin_context=True)

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
                              req, body)
            self.assertEqual(1, notifier.get_notification_count())
示例#44
0
文件: test.py 项目: yenai2009/cinder
 def _get_joined_notifier(self, *args, **kwargs):
     # We create a new fake notifier but we join the notifications with
     # the default notifier
     notifier = fake_notifier.get_fake_notifier(*args, **kwargs)
     notifier.notifications = self.notifier.notifications
     return notifier
示例#45
0
文件: test.py 项目: yenai2009/cinder
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()

        # Create default notifier
        self.notifier = fake_notifier.get_fake_notifier()

        # Mock rpc get notifier with fake notifier method that joins all
        # notifications with the default notifier
        self.patch('cinder.rpc.get_notifier',
                   side_effect=self._get_joined_notifier)

        if self.MOCK_WORKER:
            # Mock worker creation for all tests that don't care about it
            clean_path = 'cinder.objects.cleanable.CinderCleanableObject.%s'
            for method in ('create_worker', 'set_worker', 'unset_worker'):
                self.patch(clean_path % method, return_value=None)

        # Unit tests do not need to use lazy gettext
        i18n.enable_lazy(False)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        environ_enabled = (lambda var_name: strutils.bool_from_string(
            os.environ.get(var_name)))
        if environ_enabled('OS_STDOUT_CAPTURE'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if environ_enabled('OS_STDERR_CAPTURE'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.useFixture(log_fixture.get_logging_handle_error_fixture())
        self.useFixture(cinder_fixtures.StandardLogging())

        rpc.add_extra_exmods("cinder.tests.unit")
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)

        # Load oslo_messaging_notifications config group so we can set an
        # override to prevent notifications from being ignored due to the
        # short-circuit mechanism.
        oslo_messaging.get_notification_transport(CONF)
        #  We need to use a valid driver for the notifications, so we use test.
        self.override_config('driver', ['test'],
                             group='oslo_messaging_notifications')
        rpc.init(CONF)

        # NOTE(geguileo): This is required because _determine_obj_version_cap
        # and _determine_rpc_version_cap functions in cinder.rpc.RPCAPI cache
        # versions in LAST_RPC_VERSIONS and LAST_OBJ_VERSIONS so we may have
        # weird interactions between tests if we don't clear them before each
        # test.
        rpc.LAST_OBJ_VERSIONS = {}
        rpc.LAST_RPC_VERSIONS = {}

        conf_fixture.set_defaults(CONF)
        CONF([], default_config_files=[])

        # NOTE(vish): We need a better method for creating fixtures for tests
        #             now that we have some required db setup for the system
        #             to work properly.
        self.start = timeutils.utcnow()

        CONF.set_default('connection', 'sqlite://', 'database')
        CONF.set_default('sqlite_synchronous', False, 'database')

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api,
                                 migration,
                                 sql_connection=CONF.database.connection)
        self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.CinderObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.CinderObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # emulate some of the mox stuff, we can't use the metaclass
        # because it screws with our generators
        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(CONF.reset)
        self.addCleanup(self._common_cleanup)
        self.injected = []
        self._services = []

        fake_notifier.mock_notifier(self)

        self.override_config('fatal_exception_format_errors', True)
        # This will be cleaned up by the NestedTempfile fixture
        lock_path = self.useFixture(fixtures.TempDir()).path
        self.fixture = self.useFixture(config_fixture.Config(lockutils.CONF))
        self.fixture.config(lock_path=lock_path, group='oslo_concurrency')
        lockutils.set_defaults(lock_path)
        self.override_config('policy_file',
                             os.path.join(
                                 os.path.abspath(
                                     os.path.join(
                                         os.path.dirname(__file__),
                                         '..',
                                     )), self.POLICY_PATH),
                             group='oslo_policy')

        self._disable_osprofiler()
        self._disallow_invalid_uuids()

        # NOTE(geguileo): This is required because common get_by_id method in
        # cinder.db.sqlalchemy.api caches get methods and if we use a mocked
        # get method in one test it would carry on to the next test.  So we
        # clear out the cache.
        sqla_api._GET_METHODS = {}

        self.override_config('backend_url',
                             'file://' + lock_path,
                             group='coordination')
        coordination.COORDINATOR.start()
        self.addCleanup(coordination.COORDINATOR.stop)
示例#46
0
文件: test.py 项目: joshw/cinder
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()

        # Create default notifier
        self.notifier = fake_notifier.get_fake_notifier()

        # Mock rpc get notifier with fake notifier method that joins all
        # notifications with the default notifier
        self.patch('cinder.rpc.get_notifier',
                   side_effect=self._get_joined_notifier)

        if self.MOCK_WORKER:
            # Mock worker creation for all tests that don't care about it
            clean_path = 'cinder.objects.cleanable.CinderCleanableObject.%s'
            for method in ('create_worker', 'set_worker', 'unset_worker'):
                self.patch(clean_path % method, return_value=None)

        if self.MOCK_TOOZ:
            self.patch('cinder.coordination.Coordinator.start')
            self.patch('cinder.coordination.Coordinator.stop')
            self.patch('cinder.coordination.Coordinator.get_lock')

        # Unit tests do not need to use lazy gettext
        i18n.enable_lazy(False)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        environ_enabled = (lambda var_name: strutils.bool_from_string(
            os.environ.get(var_name)))
        if environ_enabled('OS_STDOUT_CAPTURE'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if environ_enabled('OS_STDERR_CAPTURE'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.useFixture(log_fixture.get_logging_handle_error_fixture())
        self.useFixture(cinder_fixtures.StandardLogging())

        rpc.add_extra_exmods("cinder.tests.unit")
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_url = 'fake:/'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)

        # Load oslo_messaging_notifications config group so we can set an
        # override to prevent notifications from being ignored due to the
        # short-circuit mechanism.
        oslo_messaging.get_notification_transport(CONF)
        #  We need to use a valid driver for the notifications, so we use test.
        self.override_config('driver', ['test'],
                             group='oslo_messaging_notifications')
        rpc.init(CONF)

        # NOTE(geguileo): This is required because _determine_obj_version_cap
        # and _determine_rpc_version_cap functions in cinder.rpc.RPCAPI cache
        # versions in LAST_RPC_VERSIONS and LAST_OBJ_VERSIONS so we may have
        # weird interactions between tests if we don't clear them before each
        # test.
        rpc.LAST_OBJ_VERSIONS = {}
        rpc.LAST_RPC_VERSIONS = {}

        # Init AuthProtocol to register some base options first, such as
        # auth_url.
        auth_token.AuthProtocol('fake_app', {
            'auth_type': 'password',
            'auth_url': 'fake_url'
        })

        conf_fixture.set_defaults(CONF)
        CONF([], default_config_files=[])

        # NOTE(vish): We need a better method for creating fixtures for tests
        #             now that we have some required db setup for the system
        #             to work properly.
        self.start = timeutils.utcnow()

        CONF.set_default('connection', 'sqlite://', 'database')
        CONF.set_default('sqlite_synchronous', False, 'database')

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api,
                                 migration,
                                 sql_connection=CONF.database.connection)
        self.useFixture(_DB_CACHE)

        # NOTE(blk-u): WarningsFixture must be after the Database fixture
        # because sqlalchemy-migrate messes with the warnings filters.
        self.useFixture(cinder_fixtures.WarningsFixture())

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.CinderObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.CinderObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        self.addCleanup(CONF.reset)
        self.addCleanup(self._common_cleanup)
        self.injected = []
        self._services = []

        fake_notifier.mock_notifier(self)

        # This will be cleaned up by the NestedTempfile fixture
        lock_path = self.useFixture(fixtures.TempDir()).path
        self.fixture = self.useFixture(config_fixture.Config(lockutils.CONF))
        self.fixture.config(lock_path=lock_path, group='oslo_concurrency')
        lockutils.set_defaults(lock_path)
        self.override_config('policy_file',
                             os.path.join(
                                 os.path.abspath(
                                     os.path.join(
                                         os.path.dirname(__file__),
                                         '..',
                                     )), self.POLICY_PATH),
                             group='oslo_policy')
        self.override_config(
            'resource_query_filters_file',
            os.path.join(
                os.path.abspath(os.path.join(
                    os.path.dirname(__file__),
                    '..',
                )), self.RESOURCE_FILTER_PATH))
        self._disable_osprofiler()

        # NOTE(geguileo): This is required because common get_by_id method in
        # cinder.db.sqlalchemy.api caches get methods and if we use a mocked
        # get method in one test it would carry on to the next test.  So we
        # clear out the cache.
        sqla_api._GET_METHODS = {}

        self.override_config('backend_url',
                             'file://' + lock_path,
                             group='coordination')
        coordination.COORDINATOR.start()
        self.addCleanup(coordination.COORDINATOR.stop)

        if six.PY3:
            # TODO(smcginnis) Python 3 deprecates assertRaisesRegexp to
            # assertRaisesRegex, but Python 2 does not have the new name. This
            # can be removed once we stop supporting py2 or the new name is
            # added.
            self.assertRaisesRegexp = self.assertRaisesRegex

        # Ensure we have the default tpool size value and we don't carry
        # threads from other test runs.
        tpool.killall()
        tpool._nthreads = 20

        # NOTE(mikal): make sure we don't load a privsep helper accidentally
        self.useFixture(cinder_fixtures.PrivsepNoHelperFixture())
示例#47
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()

        # Create default notifier
        self.notifier = fake_notifier.get_fake_notifier()

        # Mock rpc get notifier with fake notifier method that joins all
        # notifications with the default notifier
        p = mock.patch('cinder.rpc.get_notifier',
                       side_effect=self._get_joined_notifier)
        p.start()

        # Import cinder objects for test cases
        objects.register_all()

        # Unit tests do not need to use lazy gettext
        i18n.enable_lazy(False)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        environ_enabled = (lambda var_name:
                           strutils.bool_from_string(os.environ.get(var_name)))
        if environ_enabled('OS_STDOUT_CAPTURE'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if environ_enabled('OS_STDERR_CAPTURE'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
        if environ_enabled('OS_LOG_CAPTURE'):
            log_format = '%(levelname)s [%(name)s] %(message)s'
            if environ_enabled('OS_DEBUG'):
                level = logging.DEBUG
            else:
                level = logging.INFO
            self.useFixture(fixtures.LoggerFixture(nuke_handlers=False,
                                                   format=log_format,
                                                   level=level))

        rpc.add_extra_exmods("cinder.tests.unit")
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)
        rpc.init(CONF)

        conf_fixture.set_defaults(CONF)
        CONF([], default_config_files=[])

        # NOTE(vish): We need a better method for creating fixtures for tests
        #             now that we have some required db setup for the system
        #             to work properly.
        self.start = timeutils.utcnow()

        CONF.set_default('connection', 'sqlite://', 'database')
        CONF.set_default('sqlite_synchronous', False, 'database')

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api, migration,
                                 sql_connection=CONF.database.connection,
                                 sqlite_db=CONF.database.sqlite_db,
                                 sqlite_clean_db=CONF.sqlite_clean_db)
        self.useFixture(_DB_CACHE)

        # emulate some of the mox stuff, we can't use the metaclass
        # because it screws with our generators
        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(CONF.reset)
        self.addCleanup(self._common_cleanup)
        self.injected = []
        self._services = []

        fake_notifier.stub_notifier(self.stubs)

        self.override_config('fatal_exception_format_errors', True)
        # This will be cleaned up by the NestedTempfile fixture
        lock_path = self.useFixture(fixtures.TempDir()).path
        self.fixture = self.useFixture(
            config_fixture.Config(lockutils.CONF))
        self.fixture.config(lock_path=lock_path,
                            group='oslo_concurrency')
        lockutils.set_defaults(lock_path)
        self.override_config('policy_file',
                             os.path.join(
                                 os.path.abspath(
                                     os.path.join(
                                         os.path.dirname(__file__),
                                         '..',
                                     )
                                 ),
                                 'cinder/tests/unit/policy.json'),
                             group='oslo_policy')

        self._disable_osprofiler()
示例#48
0
 def test_qos_specs_delete(self, mock_qos_delete, mock_qos_get_specs):
     req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/1')
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         self.controller.delete(req, 1)
         self.assertEqual(1, notifier.get_notification_count())
示例#49
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()

        # Create default notifier
        self.notifier = fake_notifier.get_fake_notifier()

        # Mock rpc get notifier with fake notifier method that joins all
        # notifications with the default notifier
        p = mock.patch('cinder.rpc.get_notifier',
                       side_effect=self._get_joined_notifier)
        p.start()

        # Unit tests do not need to use lazy gettext
        i18n.enable_lazy(False)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        environ_enabled = (lambda var_name:
                           strutils.bool_from_string(os.environ.get(var_name)))
        if environ_enabled('OS_STDOUT_CAPTURE'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if environ_enabled('OS_STDERR_CAPTURE'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.useFixture(log_fixture.get_logging_handle_error_fixture())
        self.useFixture(cinder_fixtures.StandardLogging())

        rpc.add_extra_exmods("cinder.tests.unit")
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)
        rpc.init(CONF)

        conf_fixture.set_defaults(CONF)
        CONF([], default_config_files=[])

        # NOTE(vish): We need a better method for creating fixtures for tests
        #             now that we have some required db setup for the system
        #             to work properly.
        self.start = timeutils.utcnow()

        CONF.set_default('connection', 'sqlite://', 'database')
        CONF.set_default('sqlite_synchronous', False, 'database')

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api, migration,
                                 sql_connection=CONF.database.connection,
                                 sqlite_db=CONF.database.sqlite_db,
                                 sqlite_clean_db=CONF.sqlite_clean_db)
        self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.CinderObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.CinderObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # emulate some of the mox stuff, we can't use the metaclass
        # because it screws with our generators
        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(CONF.reset)
        self.addCleanup(self._common_cleanup)
        self.injected = []
        self._services = []

        fake_notifier.stub_notifier(self.stubs)

        self.override_config('fatal_exception_format_errors', True)
        # This will be cleaned up by the NestedTempfile fixture
        lock_path = self.useFixture(fixtures.TempDir()).path
        self.fixture = self.useFixture(
            config_fixture.Config(lockutils.CONF))
        self.fixture.config(lock_path=lock_path,
                            group='oslo_concurrency')
        lockutils.set_defaults(lock_path)
        self.override_config('policy_file',
                             os.path.join(
                                 os.path.abspath(
                                     os.path.join(
                                         os.path.dirname(__file__),
                                         '..',
                                     )
                                 ),
                                 'cinder/tests/unit/policy.json'),
                             group='oslo_policy')

        self._disable_osprofiler()

        # NOTE(geguileo): This is required because common get_by_id method in
        # cinder.db.sqlalchemy.api caches get methods and if we use a mocked
        # get method in one test it would carry on to the next test.  So we
        # clear out the cache.
        sqla_api._GET_METHODS = {}
示例#50
0
文件: test.py 项目: j-griffith/cinder
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()

        # Create default notifier
        self.notifier = fake_notifier.get_fake_notifier()

        # Mock rpc get notifier with fake notifier method that joins all
        # notifications with the default notifier
        self.patch('cinder.rpc.get_notifier',
                   side_effect=self._get_joined_notifier)

        if self.MOCK_WORKER:
            # Mock worker creation for all tests that don't care about it
            clean_path = 'cinder.objects.cleanable.CinderCleanableObject.%s'
            for method in ('create_worker', 'set_worker', 'unset_worker'):
                self.patch(clean_path % method, return_value=None)

        if self.MOCK_TOOZ:
            self.patch('cinder.coordination.Coordinator.start')
            self.patch('cinder.coordination.Coordinator.stop')
            self.patch('cinder.coordination.Coordinator.get_lock')

        # Unit tests do not need to use lazy gettext
        i18n.enable_lazy(False)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        environ_enabled = (lambda var_name:
                           strutils.bool_from_string(os.environ.get(var_name)))
        if environ_enabled('OS_STDOUT_CAPTURE'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if environ_enabled('OS_STDERR_CAPTURE'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.useFixture(log_fixture.get_logging_handle_error_fixture())
        self.useFixture(cinder_fixtures.StandardLogging())

        rpc.add_extra_exmods("cinder.tests.unit")
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)

        # Load oslo_messaging_notifications config group so we can set an
        # override to prevent notifications from being ignored due to the
        # short-circuit mechanism.
        oslo_messaging.get_notification_transport(CONF)
        #  We need to use a valid driver for the notifications, so we use test.
        self.override_config('driver', ['test'],
                             group='oslo_messaging_notifications')
        rpc.init(CONF)

        # NOTE(geguileo): This is required because _determine_obj_version_cap
        # and _determine_rpc_version_cap functions in cinder.rpc.RPCAPI cache
        # versions in LAST_RPC_VERSIONS and LAST_OBJ_VERSIONS so we may have
        # weird interactions between tests if we don't clear them before each
        # test.
        rpc.LAST_OBJ_VERSIONS = {}
        rpc.LAST_RPC_VERSIONS = {}

        conf_fixture.set_defaults(CONF)
        CONF([], default_config_files=[])

        # NOTE(vish): We need a better method for creating fixtures for tests
        #             now that we have some required db setup for the system
        #             to work properly.
        self.start = timeutils.utcnow()

        CONF.set_default('connection', 'sqlite://', 'database')
        CONF.set_default('sqlite_synchronous', False, 'database')

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api, migration,
                                 sql_connection=CONF.database.connection)
        self.useFixture(_DB_CACHE)

        # NOTE(blk-u): WarningsFixture must be after the Database fixture
        # because sqlalchemy-migrate messes with the warnings filters.
        self.useFixture(cinder_fixtures.WarningsFixture())

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.CinderObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.CinderObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        self.addCleanup(CONF.reset)
        self.addCleanup(self._common_cleanup)
        self.injected = []
        self._services = []

        fake_notifier.mock_notifier(self)

        # This will be cleaned up by the NestedTempfile fixture
        lock_path = self.useFixture(fixtures.TempDir()).path
        self.fixture = self.useFixture(
            config_fixture.Config(lockutils.CONF))
        self.fixture.config(lock_path=lock_path,
                            group='oslo_concurrency')
        lockutils.set_defaults(lock_path)
        self.override_config('policy_file',
                             os.path.join(
                                 os.path.abspath(
                                     os.path.join(
                                         os.path.dirname(__file__),
                                         '..',
                                     )
                                 ),
                                 self.POLICY_PATH),
                             group='oslo_policy')
        self.override_config('resource_query_filters_file',
                             os.path.join(
                                 os.path.abspath(
                                     os.path.join(
                                         os.path.dirname(__file__),
                                         '..',
                                     )
                                 ),
                                 self.RESOURCE_FILTER_PATH))
        self._disable_osprofiler()

        # NOTE(geguileo): This is required because common get_by_id method in
        # cinder.db.sqlalchemy.api caches get methods and if we use a mocked
        # get method in one test it would carry on to the next test.  So we
        # clear out the cache.
        sqla_api._GET_METHODS = {}

        self.override_config('backend_url', 'file://' + lock_path,
                             group='coordination')
        coordination.COORDINATOR.start()
        self.addCleanup(coordination.COORDINATOR.stop)

        if six.PY3:
            # TODO(smcginnis) Python 3 deprecates assertRaisesRegexp to
            # assertRaisesRegex, but Python 2 does not have the new name. This
            # can be removed once we stop supporting py2 or the new name is
            # added.
            self.assertRaisesRegexp = self.assertRaisesRegex

        # Ensure we have the default tpool size value and we don't carry
        # threads from other test runs.
        tpool.killall()
        tpool._nthreads = 20
示例#51
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()

        # Create default notifier
        self.notifier = fake_notifier.get_fake_notifier()

        # Mock rpc get notifier with fake notifier method that joins all
        # notifications with the default notifier
        p = mock.patch('cinder.rpc.get_notifier',
                       side_effect=self._get_joined_notifier)
        p.start()

        # Import cinder objects for test cases
        objects.register_all()

        # Unit tests do not need to use lazy gettext
        i18n.enable_lazy(False)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        environ_enabled = (lambda var_name: strutils.bool_from_string(
            os.environ.get(var_name)))
        if environ_enabled('OS_STDOUT_CAPTURE'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if environ_enabled('OS_STDERR_CAPTURE'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
        if environ_enabled('OS_LOG_CAPTURE'):
            log_format = '%(levelname)s [%(name)s] %(message)s'
            if environ_enabled('OS_DEBUG'):
                level = logging.DEBUG
            else:
                level = logging.INFO
            self.useFixture(
                fixtures.LoggerFixture(nuke_handlers=False,
                                       format=log_format,
                                       level=level))

        rpc.add_extra_exmods("cinder.tests.unit")
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)
        rpc.init(CONF)

        conf_fixture.set_defaults(CONF)
        CONF([], default_config_files=[])

        # NOTE(vish): We need a better method for creating fixtures for tests
        #             now that we have some required db setup for the system
        #             to work properly.
        self.start = timeutils.utcnow()

        CONF.set_default('connection', 'sqlite://', 'database')
        CONF.set_default('sqlite_synchronous', False, 'database')

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api,
                                 migration,
                                 sql_connection=CONF.database.connection,
                                 sqlite_db=CONF.database.sqlite_db,
                                 sqlite_clean_db=CONF.sqlite_clean_db)
        self.useFixture(_DB_CACHE)

        # emulate some of the mox stuff, we can't use the metaclass
        # because it screws with our generators
        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(CONF.reset)
        self.addCleanup(self._common_cleanup)
        self.injected = []
        self._services = []

        fake_notifier.stub_notifier(self.stubs)

        self.override_config('fatal_exception_format_errors', True)
        # This will be cleaned up by the NestedTempfile fixture
        lock_path = self.useFixture(fixtures.TempDir()).path
        self.fixture = self.useFixture(config_fixture.Config(lockutils.CONF))
        self.fixture.config(lock_path=lock_path, group='oslo_concurrency')
        lockutils.set_defaults(lock_path)
        self.override_config('policy_file',
                             os.path.join(
                                 os.path.abspath(
                                     os.path.join(
                                         os.path.dirname(__file__),
                                         '..',
                                     )), 'cinder/tests/unit/policy.json'),
                             group='oslo_policy')

        self._disable_osprofiler()
示例#52
0
 def _get_joined_notifier(self, *args, **kwargs):
     # We create a new fake notifier but we join the notifications with
     # the default notifier
     notifier = fake_notifier.get_fake_notifier(*args, **kwargs)
     notifier.notifications = self.notifier.notifications
     return notifier
示例#53
0
    def setUp(self):
        """Run before each test method to initialize test environment."""
        super(TestCase, self).setUp()

        # Create default notifier
        self.notifier = fake_notifier.get_fake_notifier()

        # Mock rpc get notifier with fake notifier method that joins all
        # notifications with the default notifier
        p = mock.patch('cinder.rpc.get_notifier',
                       side_effect=self._get_joined_notifier)
        p.start()

        # Unit tests do not need to use lazy gettext
        i18n.enable_lazy(False)

        test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
        try:
            test_timeout = int(test_timeout)
        except ValueError:
            # If timeout value is invalid do not set a timeout.
            test_timeout = 0
        if test_timeout > 0:
            self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
        self.useFixture(fixtures.NestedTempfile())
        self.useFixture(fixtures.TempHomeDir())

        environ_enabled = (lambda var_name:
                           strutils.bool_from_string(os.environ.get(var_name)))
        if environ_enabled('OS_STDOUT_CAPTURE'):
            stdout = self.useFixture(fixtures.StringStream('stdout')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
        if environ_enabled('OS_STDERR_CAPTURE'):
            stderr = self.useFixture(fixtures.StringStream('stderr')).stream
            self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))

        self.useFixture(log_fixture.get_logging_handle_error_fixture())
        self.useFixture(cinder_fixtures.StandardLogging())

        rpc.add_extra_exmods("cinder.tests.unit")
        self.addCleanup(rpc.clear_extra_exmods)
        self.addCleanup(rpc.cleanup)

        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
        self.messaging_conf.transport_driver = 'fake'
        self.messaging_conf.response_timeout = 15
        self.useFixture(self.messaging_conf)
        rpc.init(CONF)

        # NOTE(geguileo): This is required because _determine_obj_version_cap
        # and _determine_rpc_version_cap functions in cinder.rpc.RPCAPI cache
        # versions in LAST_RPC_VERSIONS and LAST_OBJ_VERSIONS so we may have
        # weird interactions between tests if we don't clear them before each
        # test.
        rpc.LAST_OBJ_VERSIONS = {}
        rpc.LAST_RPC_VERSIONS = {}

        conf_fixture.set_defaults(CONF)
        CONF([], default_config_files=[])

        # NOTE(vish): We need a better method for creating fixtures for tests
        #             now that we have some required db setup for the system
        #             to work properly.
        self.start = timeutils.utcnow()

        CONF.set_default('connection', 'sqlite://', 'database')
        CONF.set_default('sqlite_synchronous', False, 'database')

        global _DB_CACHE
        if not _DB_CACHE:
            _DB_CACHE = Database(sqla_api, migration,
                                 sql_connection=CONF.database.connection,
                                 sqlite_db=CONF.database.sqlite_db,
                                 sqlite_clean_db='clean.sqlite')
        self.useFixture(_DB_CACHE)

        # NOTE(danms): Make sure to reset us back to non-remote objects
        # for each test to avoid interactions. Also, backup the object
        # registry.
        objects_base.CinderObject.indirection_api = None
        self._base_test_obj_backup = copy.copy(
            objects_base.CinderObjectRegistry._registry._obj_classes)
        self.addCleanup(self._restore_obj_registry)

        # emulate some of the mox stuff, we can't use the metaclass
        # because it screws with our generators
        mox_fixture = self.useFixture(moxstubout.MoxStubout())
        self.mox = mox_fixture.mox
        self.stubs = mox_fixture.stubs
        self.addCleanup(CONF.reset)
        self.addCleanup(self._common_cleanup)
        self.injected = []
        self._services = []

        fake_notifier.stub_notifier(self.stubs)

        self.override_config('fatal_exception_format_errors', True)
        # This will be cleaned up by the NestedTempfile fixture
        lock_path = self.useFixture(fixtures.TempDir()).path
        self.fixture = self.useFixture(
            config_fixture.Config(lockutils.CONF))
        self.fixture.config(lock_path=lock_path,
                            group='oslo_concurrency')
        lockutils.set_defaults(lock_path)
        self.override_config('policy_file',
                             os.path.join(
                                 os.path.abspath(
                                     os.path.join(
                                         os.path.dirname(__file__),
                                         '..',
                                     )
                                 ),
                                 'cinder/tests/unit/policy.json'),
                             group='oslo_policy')

        self._disable_osprofiler()

        # NOTE(geguileo): This is required because common get_by_id method in
        # cinder.db.sqlalchemy.api caches get methods and if we use a mocked
        # get method in one test it would carry on to the next test.  So we
        # clear out the cache.
        sqla_api._GET_METHODS = {}
 def test_qos_specs_delete(self, mock_qos_delete, mock_qos_get_specs):
     req = fakes.HTTPRequest.blank('/v2/fake/qos-specs/1')
     notifier = fake_notifier.get_fake_notifier()
     with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
         self.controller.delete(req, 1)
         self.assertEqual(1, notifier.get_notification_count())