~ubuntu-branches/debian/stretch/waagent/stretch

« back to all changes in this revision

Viewing changes to tests/distro/test_resourceDisk.py

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2016-08-24 16:48:22 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20160824164822-vdf8m5xy5gycm1cz
Tags: 2.1.6-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Microsoft Corporation
 
2
#
 
3
# Licensed under the Apache License, Version 2.0 (the "License");
 
4
# you may not use this file except in compliance with the License.
 
5
# You may obtain a copy of the License at
 
6
#
 
7
#     http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
# Unless required by applicable law or agreed to in writing, software
 
10
# distributed under the License is distributed on an "AS IS" BASIS,
 
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
12
# See the License for the specific language governing permissions and
 
13
# limitations under the License.
 
14
#
 
15
# Requires Python 2.4+ and Openssl 1.0+
 
16
#
 
17
# Implements parts of RFC 2131, 1541, 1497 and
 
18
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
 
19
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
 
20
 
 
21
from azurelinuxagent.common.utils import shellutil
 
22
from azurelinuxagent.daemon.resourcedisk import get_resourcedisk_handler
 
23
from tests.tools import *
 
24
 
 
25
 
 
26
class TestResourceDisk(AgentTestCase):
 
27
    def test_mkfile(self):
 
28
        # setup
 
29
        test_file = os.path.join(self.tmp_dir, 'test_file')
 
30
        file_size = 1024 * 128
 
31
        if os.path.exists(test_file):
 
32
            os.remove(test_file)
 
33
 
 
34
        # execute
 
35
        get_resourcedisk_handler().mkfile(test_file, file_size)
 
36
 
 
37
        # assert
 
38
        assert os.path.exists(test_file)
 
39
 
 
40
        # cleanup
 
41
        os.remove(test_file)
 
42
 
 
43
    def test_mkfile_dd_fallback(self):
 
44
        with patch.object(shellutil, "run") as run_patch:
 
45
            # setup
 
46
            run_patch.return_value = 1
 
47
            test_file = os.path.join(self.tmp_dir, 'test_file')
 
48
            file_size = 1024 * 128
 
49
 
 
50
            # execute
 
51
            if sys.version_info >= (3,3):
 
52
                with patch("os.posix_fallocate",
 
53
                           side_effect=Exception('failure')):
 
54
                    get_resourcedisk_handler().mkfile(test_file, file_size)
 
55
            else:
 
56
                get_resourcedisk_handler().mkfile(test_file, file_size)
 
57
 
 
58
            # assert
 
59
            assert run_patch.call_count > 1
 
60
            assert "fallocate" in run_patch.call_args_list[0][0][0]
 
61
            assert "dd if" in run_patch.call_args_list[-1][0][0]
 
62
 
 
63
 
 
64
if __name__ == '__main__':
 
65
    unittest.main()