• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2
3import unittest, StringIO
4import common
5from autotest_lib.client.bin import fsinfo
6from autotest_lib.client.common_lib.test_utils import mock
7
8class fsionfo_test(unittest.TestCase):
9
10    def setUp(self):
11        self.god = mock.mock_god()
12        self.god.stub_function(fsinfo, 'open')
13
14
15    def tearDown(self):
16        self.god.unstub_all()
17
18
19    def create_test_file(self, filename, contents):
20        test_file = StringIO.StringIO(contents)
21        fsinfo.open.expect_call(filename, 'r').and_return(test_file)
22
23
24    def test_ext_mkfs_options(self):
25        tune2fs_dict = {'Filesystem volume name': '<none>',
26                        'Last mounted on': '<not available>',
27                        'Filesystem revision #': '1 (dynamic)',
28                        'Block size': 4096,
29                        'Block count': 263056,
30                        'Fragment size': 4096,
31                        'Blocks per group': 32768,
32                        'Journal inode': 8,
33                        'Reserved block count': 2630,
34                        'Inode count': 131616,
35                        'Filesystem features': 'filetype sparse_super',
36                        'Filesystem OS type': 'Linux'}
37        expected_option = {'-b': 4096,
38                           '-f': 4096,
39                           '-g': 32768,
40                           '-j': None,
41                           '-m': 1,
42                           '-O': 'filetype,sparse_super',
43                           '-o': 'Linux',
44                           '-r': '1'}
45
46        mkfs_option = {}
47        fsinfo.ext_mkfs_options(tune2fs_dict, mkfs_option)
48
49        for option, value in expected_option.iteritems():
50            self.assertEqual(value, mkfs_option[option])
51
52
53    def test_xfs_mkfs_options(self):
54        tune2fs_dict = {'meta-data: isize': 256,
55                        'meta-data: agcount': 8,
56                        'meta-data: agsize': 32882,
57                        'meta-data: sectsz': 512,
58                        'meta-data: attr': 0,
59                        'data: bsize': 4096,
60                        'data: imaxpct': 25,
61                        'data: sunit': 0,
62                        'data: swidth': 0,
63                        'data: unwritten': 1,
64                        'naming: version': 2,
65                        'naming: bsize': 4096,
66                        'log: version': 1,
67                        'log: sectsz': 512,
68                        'log: sunit': 0,
69                        'log: lazy-count': 0,
70                        'log: bsize': 4096,
71                        'log: blocks': 2560,
72                        'realtime: extsz': 4096,
73                        'realtime: blocks': 0,
74                        'realtime: rtextents': 0}
75
76        expected_option = {'-i size': 256,
77                           '-d agcount': 8,
78                           '-s size': 512,
79                           '-b size': 4096,
80                           '-i attr': 0,
81                           '-i maxpct': 25,
82                           '-d sunit': 0,
83                           '-d swidth': 0,
84                           '-d unwritten': 1,
85                           '-n version': 2,
86                           '-n size': 4096,
87                           '-l version': 1,
88                           '-l sectsize': 512,
89                           '-l sunit': 0,
90                           '-l lazy-count': 0,
91                           '-r extsize': 4096,
92                           '-r size': 0,
93                           '-r rtdev': 0,
94                           '-l size': 10485760}
95        mkfs_option = {}
96        fsinfo.xfs_mkfs_options(tune2fs_dict, mkfs_option)
97        for option, value in expected_option.iteritems():
98            self.assertEqual(value, mkfs_option[option])
99
100
101    def test_opt_string2dict(self):
102        test_string = '-q -b 1234   -O fdasfa,fdasfdas -l adfas -k -L'
103        result = fsinfo.opt_string2dict(test_string)
104        expected_result = {'-q': None,
105                           '-b': 1234,
106                           '-O': 'fdasfa,fdasfdas',
107                           '-l': 'adfas',
108                           '-k': None,
109                           '-L': None}
110        self.assertEqual(expected_result, result)
111
112
113    def test_merge_ext_features(self):
114        conf = 'a,b,d,d,d,d,d,e,e,a,f'.split(',')
115        user = '^e,a,^f,g,h,i'
116        expected_result = ['a', 'b', 'd', 'g', 'h', 'i']
117        result = fsinfo.merge_ext_features(conf, user)
118        self.assertEqual(expected_result, result)
119
120
121    def test_compare_features(self):
122        f1 = ['sparse_super', 'filetype', 'resize_inode', 'dir_index']
123        f2 = ['filetype', 'resize_inode', 'dir_index', 'large_file']
124        self.assertTrue(fsinfo.compare_features(f1, f1))
125        self.assertFalse(fsinfo.compare_features(f1, f2))
126
127
128    def test_mke2fs_conf(self):
129        content = ('[defaults]\n'
130                   'base_features = sparse_super,filetype,resize_inode\n'
131                   '       blocksize = 4096 \n'
132                   '       inode_ratio = 8192  \n'
133                   '\n [fs_types]\n'
134                   '       small = {\n'
135                   '                         blocksize = 1024\n'
136                   '               inode_ratio = 4096 \n'
137                   '                                                 }\n'
138                   '       floppy = {\n'
139                   '                         blocksize = 4096\n'
140                   '                                }\n')
141        self.create_test_file('/etc/mke2fs.conf', content)
142
143        conf_opt = fsinfo.parse_mke2fs_conf('small')
144        mkfs_opt = fsinfo.convert_conf_opt(conf_opt)
145        expected_conf = {'blocksize': 1024,
146                         'inode_ratio': 4096,
147                         'base_features': 'sparse_super,filetype,resize_inode'}
148        expected_mkfs = {'-O': ['sparse_super', 'filetype', 'resize_inode'],
149                         '-i': 4096,
150                         '-b': 1024}
151        self.assertEqual(conf_opt, expected_conf)
152        self.assertEqual(mkfs_opt, expected_mkfs)
153
154
155if __name__ == '__main__':
156    unittest.main()
157