1
# Copyright 2014 Cisco Systems, Inc.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
18
from ironic.common import exception
19
from ironic.drivers import base as driver_base
20
from ironic.tests import base
23
class FakeVendorInterface(driver_base.VendorInterface):
24
def get_properties(self):
27
@driver_base.passthru(['POST'])
28
def noexception(self):
31
@driver_base.passthru(['POST'])
32
def ironicexception(self):
33
raise exception.IronicException("Fake!")
35
@driver_base.passthru(['POST'])
36
def normalexception(self):
37
raise Exception("Fake!")
39
def validate(self, task, **kwargs):
42
def driver_validate(self, **kwargs):
46
class PassthruDecoratorTestCase(base.TestCase):
49
super(PassthruDecoratorTestCase, self).setUp()
50
self.fvi = FakeVendorInterface()
51
driver_base.LOG = mock.Mock()
53
def test_passthru_noexception(self):
54
result = self.fvi.noexception()
55
self.assertEqual("Fake", result)
57
def test_passthru_ironicexception(self):
58
self.assertRaises(exception.IronicException,
59
self.fvi.ironicexception, mock.ANY)
60
driver_base.LOG.exception.assert_called_with(
61
mock.ANY, 'ironicexception')
63
def test_passthru_nonironicexception(self):
64
self.assertRaises(exception.VendorPassthruException,
65
self.fvi.normalexception, mock.ANY)
66
driver_base.LOG.exception.assert_called_with(
67
mock.ANY, 'normalexception')