~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/tests/drivers/test_base.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-05 12:21:37 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20150105122137-171bqrdpcxqipunk
Tags: 2015.1~b1-0ubuntu1
* New upstream beta release:
  - d/control: Align version requirements with upstream release.
* d/watch: Update uversionmangle to deal with kilo beta versioning
  changes.
* d/control: Bumped Standards-Version to 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Cisco Systems, Inc.
 
2
# All Rights Reserved.
 
3
#
 
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
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
#    under the License.
 
15
 
 
16
import mock
 
17
 
 
18
from ironic.common import exception
 
19
from ironic.drivers import base as driver_base
 
20
from ironic.tests import base
 
21
 
 
22
 
 
23
class FakeVendorInterface(driver_base.VendorInterface):
 
24
    def get_properties(self):
 
25
        pass
 
26
 
 
27
    @driver_base.passthru(['POST'])
 
28
    def noexception(self):
 
29
        return "Fake"
 
30
 
 
31
    @driver_base.passthru(['POST'])
 
32
    def ironicexception(self):
 
33
        raise exception.IronicException("Fake!")
 
34
 
 
35
    @driver_base.passthru(['POST'])
 
36
    def normalexception(self):
 
37
        raise Exception("Fake!")
 
38
 
 
39
    def validate(self, task, **kwargs):
 
40
        pass
 
41
 
 
42
    def driver_validate(self, **kwargs):
 
43
        pass
 
44
 
 
45
 
 
46
class PassthruDecoratorTestCase(base.TestCase):
 
47
 
 
48
    def setUp(self):
 
49
        super(PassthruDecoratorTestCase, self).setUp()
 
50
        self.fvi = FakeVendorInterface()
 
51
        driver_base.LOG = mock.Mock()
 
52
 
 
53
    def test_passthru_noexception(self):
 
54
        result = self.fvi.noexception()
 
55
        self.assertEqual("Fake", result)
 
56
 
 
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')
 
62
 
 
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')