summaryrefslogtreecommitdiff
path: root/nova/tests/unit/virt/vmwareapi/stubs.py
blob: a0406bdac5ec9b270c9c211397c994d29f2e7525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright (c) 2011 Citrix Systems, Inc.
# Copyright 2011 OpenStack Foundation
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Stubouts for the test suite
"""

from oslo_vmware import exceptions as vexc

import nova.conf
from nova.tests.unit.virt.vmwareapi import fake

CONF = nova.conf.CONF


def fake_get_vim_object(arg):
    """Stubs out the VMwareAPISession's get_vim_object method."""
    return fake.FakeVim()


@property
def fake_vim_prop(arg):
    """Stubs out the VMwareAPISession's vim property access method."""
    return fake.get_fake_vim_object(arg)


def fake_is_vim_object(module):
    """Stubs out the VMwareAPISession's is_vim_object method."""
    return isinstance(module, fake.FakeVim)


def fake_temp_method_exception():
    raise vexc.VimFaultException(
            [vexc.NOT_AUTHENTICATED],
            "Session Empty/Not Authenticated")


def fake_temp_session_exception():
    raise vexc.VimConnectionException("it's a fake!",
            "Session Exception")


def fake_session_file_exception():
    fault_list = [vexc.FILE_ALREADY_EXISTS]
    raise vexc.VimFaultException(fault_list,
                                 Exception('fake'))


def fake_session_permission_exception():
    fault_list = [vexc.NO_PERMISSION]
    fault_string = 'Permission to perform this operation was denied.'
    details = {'privilegeId': 'Resource.AssignVMToPool', 'object': 'domain-c7'}
    raise vexc.VimFaultException(fault_list, fault_string, details=details)


def set_stubs(test):
    """Set the stubs."""

    test.stub_out('nova.virt.vmwareapi.network_util.get_network_with_the_name',
                  fake.fake_get_network)
    test.stub_out('nova.virt.vmwareapi.images.upload_image_stream_optimized',
                  fake.fake_upload_image)
    test.stub_out('nova.virt.vmwareapi.images.fetch_image',
                  fake.fake_fetch_image)
    test.stub_out('nova.virt.vmwareapi.session.VMwareAPISession.vim',
                  fake_vim_prop)
    test.stub_out('nova.virt.vmwareapi.session.VMwareAPISession.'
                  '_is_vim_object',
                  fake_is_vim_object)
    test.stub_out('nova.network.neutron.API.update_instance_vnic_index',
                  lambda *args, **kwargs: None)