Example #1
0
    def test_profile_create_with_bad_type(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'create', True)
        type_name = 'unknown_type'
        body = {
            'profile': {
                'name': 'test_profile',
                'spec': {
                    'type': type_name,
                    'version': '1.0',
                    'properties': {
                        'param': 'value'
                    },
                },
                'metadata': {},
            }
        }
        req = self._post('/profiles', jsonutils.dumps(body))

        error = senlin_exc.ProfileTypeNotFound(profile_type=type_name)
        mock_call = self.patchobject(rpc_client.EngineClient,
                                     'call',
                                     side_effect=error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.create,
                                              req,
                                              body=body)

        mock_call.assert_called_once_with(req.context,
                                          ('profile_create', body['profile']))
        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileTypeNotFound', resp.json['error']['type'])
Example #2
0
    def test_profile_type_get_nonexist(self, mock_env):
        x_env = mock.Mock()
        err = exc.ProfileTypeNotFound(profile_type='FAKE_TYPE')
        x_env.get_profile.side_effect = err
        mock_env.return_value = x_env

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.profile_type_get, self.ctx,
                               'FAKE_TYPE')

        self.assertEqual(exc.ProfileTypeNotFound, ex.exc_info[0])
        self.assertEqual('Profile type (FAKE_TYPE) is not found.',
                         six.text_type(ex.exc_info[1]))
        mock_env.assert_called_once_with()
        x_env.get_profile.assert_called_once_with('FAKE_TYPE')
Example #3
0
    def test_profile_type_get_not_found(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'get', True)
        type_name = 'BogusProfileType'
        req = self._get('/profile_types/%(type)s' % {'type': type_name})

        error = senlin_exc.ProfileTypeNotFound(profile_type=type_name)
        mock_call = self.patchobject(rpc_client.EngineClient, 'call')
        mock_call.side_effect = shared.to_remote_error(error)

        resp = shared.request_with_middleware(fault.FaultWrapper,
                                              self.controller.get,
                                              req, type_name=type_name)

        mock_call.assert_called_once_with(
            req.context,
            ('profile_type_get', {'type_name': type_name}))

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('ProfileTypeNotFound', resp.json['error']['type'])
Example #4
0
 def get_profile(self, name):
     self._check_plugin_name('Profile', name)
     plugin = self.profile_registry.get_plugin(name)
     if plugin is None:
         raise exception.ProfileTypeNotFound(profile_type=name)
     return plugin