~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/tests/hyperv/mockproxy.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
 
20
20
import inspect
 
21
import pickle
21
22
 
22
23
 
23
24
def serialize_obj(obj):
39
40
            l1 = l1 + (serialize_obj(i1),)
40
41
        val = str(l1)
41
42
    else:
42
 
        val = str(obj)
 
43
        if isinstance(obj, str) or isinstance(obj, unicode):
 
44
            val = obj
 
45
        elif hasattr(obj, '__str__') and inspect.ismethod(obj.__str__):
 
46
            val = str(obj)
 
47
        else:
 
48
            val = str(type(obj))
43
49
    return val
44
50
 
45
51
 
48
54
    return serialize_obj((args, kwargs))
49
55
 
50
56
 
 
57
class MockException(Exception):
 
58
    def __init__(self, message):
 
59
        super(MockException, self).__init__(message)
 
60
 
 
61
 
51
62
class Mock(object):
52
63
    def _get_next_value(self, name):
53
64
        c = self._access_count.get(name)
56
67
        else:
57
68
            c = c + 1
58
69
        self._access_count[name] = c
59
 
        return self._values[name][c]
 
70
 
 
71
        try:
 
72
            value = self._values[name][c]
 
73
        except IndexError as ex:
 
74
            raise MockException(_('Couldn\'t find invocation num. %(c)d '
 
75
                'of attribute "%(name)s"') % locals())
 
76
        return value
60
77
 
61
78
    def _get_next_ret_value(self, name, params):
62
79
        d = self._access_count.get(name)
69
86
        else:
70
87
            c = c + 1
71
88
        d[params] = c
72
 
        return self._values[name][params][c]
 
89
 
 
90
        try:
 
91
            m = self._values[name]
 
92
        except KeyError as ex:
 
93
            raise MockException(_('Couldn\'t find attribute "%s"') % (name))
 
94
 
 
95
        try:
 
96
            value = m[params][c]
 
97
        except KeyError as ex:
 
98
            raise MockException(_('Couldn\'t find attribute "%(name)s" '
 
99
                'with arguments "%(params)s"') % locals())
 
100
        except IndexError as ex:
 
101
            raise MockException(_('Couldn\'t find invocation num. %(c)d '
 
102
                'of attribute "%(name)s" with arguments "%(params)s"')
 
103
                    % locals())
 
104
 
 
105
        return value
73
106
 
74
107
    def __init__(self, values):
75
108
        self._values = values
82
115
        if name.startswith('__') and name.endswith('__'):
83
116
            return object.__getattribute__(self, name)
84
117
        else:
85
 
            if isinstance(self._values[name], dict):
 
118
            try:
 
119
                isdict = isinstance(self._values[name], dict)
 
120
            except KeyError as ex:
 
121
                raise MockException(_('Couldn\'t find attribute "%s"')
 
122
                    % (name))
 
123
 
 
124
            if isdict:
86
125
                def newfunc(*args, **kwargs):
87
126
                    params = serialize_args(args, kwargs)
88
127
                    return self._get_next_ret_value(name, params)