1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012, Red Hat, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
18
Unit Tests for nova.cert.rpcapi
21
from nova.cert import rpcapi as cert_rpcapi
22
from nova import context
23
from nova import flags
31
class CertRpcAPITestCase(test.TestCase):
34
super(CertRpcAPITestCase, self).setUp()
37
super(CertRpcAPITestCase, self).tearDown()
39
def _test_cert_api(self, method, **kwargs):
40
ctxt = context.RequestContext('fake_user', 'fake_project')
41
rpcapi = cert_rpcapi.CertAPI()
42
expected_retval = 'foo'
43
expected_msg = rpcapi.make_msg(method, **kwargs)
44
expected_msg['version'] = rpcapi.RPC_API_VERSION
47
self.call_topic = None
49
self.call_timeout = None
51
def _fake_call(_ctxt, _topic, _msg, _timeout):
52
self.call_ctxt = _ctxt
53
self.call_topic = _topic
55
self.call_timeout = _timeout
56
return expected_retval
58
self.stubs.Set(rpc, 'call', _fake_call)
60
retval = getattr(rpcapi, method)(ctxt, **kwargs)
62
self.assertEqual(retval, expected_retval)
63
self.assertEqual(self.call_ctxt, ctxt)
64
self.assertEqual(self.call_topic, FLAGS.cert_topic)
65
self.assertEqual(self.call_msg, expected_msg)
66
self.assertEqual(self.call_timeout, None)
68
def test_revoke_certs_by_user(self):
69
self._test_cert_api('revoke_certs_by_user', user_id='fake_user_id')
71
def test_revoke_certs_by_project(self):
72
self._test_cert_api('revoke_certs_by_project',
73
project_id='fake_project_id')
75
def test_revoke_certs_by_user_and_project(self):
76
self._test_cert_api('revoke_certs_by_user_and_project',
77
user_id='fake_user_id',
78
project_id='fake_project_id')
80
def test_generate_x509_cert(self):
81
self._test_cert_api('generate_x509_cert',
82
user_id='fake_user_id',
83
project_id='fake_project_id')
85
def test_fetch_ca(self):
86
self._test_cert_api('fetch_ca', project_id='fake_project_id')
88
def test_fetch_crl(self):
89
self._test_cert_api('fetch_crl', project_id='fake_project_id')
91
def test_decrypt_text(self):
92
self._test_cert_api('decrypt_text',
93
project_id='fake_project_id', text='blah')