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

« back to all changes in this revision

Viewing changes to nova/tests/virt/hyperv/test_vhdutils.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman
  • Date: 2013-10-17 13:54:08 UTC
  • mfrom: (1.1.75)
  • Revision ID: package-import@ubuntu.com-20131017135408-n6jbddbictu9uazl
Tags: 1:2013.1.4-0ubuntu1
* Resynchronize with stable/grizzly (0409a09) (LP: #1241202):
  - [2ab1b6a] sql error when launching an instance from a volume LP: 1171190
  - [b5fa9f0] nova should check the is_public of flavor when creating an
    instance LP: 1212179
  - [f651317] nova boot --num-instances=50 times out  LP: 1199433
  - [ee9d1f6] Not prompt relevant message when stop a stoped vm LP: 1181934
  - [fc4d1f9] vmware driver should work without requiring patched wsdl
    LP: 1171215
  - [65b122f] launch index is not right if boot some VMs in one request
    LP: 1212648
  - [90fa239] VMware: Unable to spawn a instance when using Quantum and
    VMware drivers LP: 1202042
  - [474b8a4] Spawning multiple instances can cause race conditions with nbd
    LP: 1207422
  - [c704897]  Some sequence of characters in console-log can DoS nova-
    compute LP: 1215091
  - [43f2a4c] libvirt driver: Failed to attach new interface to VM
    LP: 1212565
  - [067fb93] Multi datastore support for provisioning of instances on ESX
    LP: 1104994
  - [fc9af8f] Compute nodes changing hostnames should log an error
    LP: 1224982
  - [cc1b72a] Security groups with source groups no longer work LP: 1216720
  - [faabb91] instance consoleauth  expired tokens need to be removed from
    the cache LP: 1209134
  - [5c55985] VHD snapshot from Hyper-V driver is bigger than original
    instance LP: 1177927
  - [d9ce5a4] normal user can show all the networks LP: 1186867
  - [6697489] hard reboot fails when using force_raw_images=False and
    use_cow_images=False and  LP: 1200249
  - [a59957c] Snapshot failure with VMwareVCDriver LP: 1184807
  - [542191d] VMWAREAPI: Problem with starting Windows instances on ESXi 5.1
    LP: 1187853
  - [62f2218] Exceptions during soft reboot should result in a hard reboot
    LP: 1202974
  - [f306875] Incorrect host stats reported by VMWare VCDriver LP: 1190515
  - [8e6b79f] Windows instances need timezone to be localtime LP: 1231254
  - [570e8c7] boto version breaks gating LP: 1237944
  - [6193176] hard reboot fails with preallocate_images=performance
    LP: 1200113
  - [a48f9df] mount_options: mount: /boot: No such file or directory
    LP: 1210371
  - [516ec3e] one port_id can add to two instance LP: 1204850
  - [f89e624] VMware: no VM connectivity when opaque network does not match
    bridge id LP: 1225002
  - [ba7ad53] Add boto special casing for param changes in 2.13
  - [7b2b673] Cannot live block migrate an instance without shared storage
    LP: 1193359
  - [0409a09] boto version checking in test cases is not backwards compatible
    LP: 1239220

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
#  Copyright 2013 Cloudbase Solutions Srl
 
4
#
 
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
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
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
 
15
#    under the License.
 
16
 
 
17
import mock
 
18
 
 
19
from nova import test
 
20
 
 
21
from nova.virt.hyperv import constants
 
22
from nova.virt.hyperv import vhdutils
 
23
from nova.virt.hyperv import vmutils
 
24
 
 
25
 
 
26
class VHDUtilsTestCase(test.TestCase):
 
27
    """Unit tests for the Hyper-V VHDUtils class."""
 
28
 
 
29
    _FAKE_VHD_PATH = "C:\\fake_path.vhdx"
 
30
    _FAKE_FORMAT = 3
 
31
    _FAKE_MAK_INTERNAL_SIZE = 1000
 
32
    _FAKE_JOB_PATH = 'fake_job_path'
 
33
    _FAKE_RET_VAL = 0
 
34
 
 
35
    def setUp(self):
 
36
        self._vhdutils = vhdutils.VHDUtils()
 
37
        self._vhdutils._conn = mock.MagicMock()
 
38
        self._vhdutils._vmutils = mock.MagicMock()
 
39
        super(VHDUtilsTestCase, self).setUp()
 
40
 
 
41
    def test_create_dynamic_vhd(self):
 
42
        self._vhdutils.get_vhd_info = mock.MagicMock(
 
43
            return_value={'Format': self._FAKE_FORMAT})
 
44
 
 
45
        mock_img_svc = self._vhdutils._conn.Msvm_ImageManagementService()[0]
 
46
        mock_img_svc.CreateDynamicVirtualHardDisk.return_value = (
 
47
            self._FAKE_JOB_PATH, self._FAKE_RET_VAL)
 
48
 
 
49
        self._vhdutils.create_dynamic_vhd(self._FAKE_VHD_PATH,
 
50
                                          self._FAKE_MAK_INTERNAL_SIZE,
 
51
                                          constants.DISK_FORMAT_VHD)
 
52
 
 
53
        mock_img_svc.CreateDynamicVirtualHardDisk.assert_called_once_with(
 
54
            Path=self._FAKE_VHD_PATH,
 
55
            MaxInternalSize=self._FAKE_MAK_INTERNAL_SIZE)
 
56
 
 
57
    def test_get_internal_vhd_size_by_file_size_fixed(self):
 
58
        vhdutil = vhdutils.VHDUtils()
 
59
        root_vhd_size = 1 * 1024 ** 3
 
60
        vhdutil.get_vhd_info = mock.MagicMock()
 
61
        vhdutil.get_vhd_info.return_value = {'Type': constants.VHD_TYPE_FIXED}
 
62
 
 
63
        real_size = vhdutil._get_internal_vhd_size_by_file_size(None,
 
64
                                                                root_vhd_size)
 
65
        expected_vhd_size = 1 * 1024 ** 3 - 512
 
66
        self.assertEqual(expected_vhd_size, real_size)
 
67
 
 
68
    def test_get_internal_vhd_size_by_file_size_dynamic(self):
 
69
        vhdutil = vhdutils.VHDUtils()
 
70
        root_vhd_size = 20 * 1024 ** 3
 
71
        vhdutil.get_vhd_info = mock.MagicMock()
 
72
        vhdutil.get_vhd_info.return_value = {'Type':
 
73
                                             constants.VHD_TYPE_DYNAMIC}
 
74
        vhdutil._get_vhd_dynamic_blk_size = mock.MagicMock()
 
75
        vhdutil._get_vhd_dynamic_blk_size.return_value = 2097152
 
76
 
 
77
        real_size = vhdutil._get_internal_vhd_size_by_file_size(None,
 
78
                                                                root_vhd_size)
 
79
        expected_vhd_size = 20 * 1024 ** 3 - 43008
 
80
        self.assertEqual(expected_vhd_size, real_size)
 
81
 
 
82
    def test_get_internal_vhd_size_by_file_size_unsupported(self):
 
83
        vhdutil = vhdutils.VHDUtils()
 
84
        root_vhd_size = 20 * 1024 ** 3
 
85
        vhdutil.get_vhd_info = mock.MagicMock()
 
86
        vhdutil.get_vhd_info.return_value = {'Type': 5}
 
87
 
 
88
        self.assertRaises(vmutils.HyperVException,
 
89
                          vhdutil._get_internal_vhd_size_by_file_size,
 
90
                          None, root_vhd_size)