1
# Copyright 2014 Microsoft Corporation
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
7
# http://www.apache.org/licenses/LICENSE-2.0
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.
15
# Requires Python 2.4+ and Openssl 1.0+
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
21
from azurelinuxagent.common.utils import shellutil
22
from azurelinuxagent.daemon.resourcedisk import get_resourcedisk_handler
23
from tests.tools import *
26
class TestResourceDisk(AgentTestCase):
27
def test_mkfile(self):
29
test_file = os.path.join(self.tmp_dir, 'test_file')
30
file_size = 1024 * 128
31
if os.path.exists(test_file):
35
get_resourcedisk_handler().mkfile(test_file, file_size)
38
assert os.path.exists(test_file)
43
def test_mkfile_dd_fallback(self):
44
with patch.object(shellutil, "run") as run_patch:
46
run_patch.return_value = 1
47
test_file = os.path.join(self.tmp_dir, 'test_file')
48
file_size = 1024 * 128
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)
56
get_resourcedisk_handler().mkfile(test_file, file_size)
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]
64
if __name__ == '__main__':