示例#1
0
    def test_fstab_present_aix_present(self):
        """
        Test fstab_present
        """
        ret = {
            "name": "/dev/sda1",
            "result": True,
            "changes": {},
            "comment": ["/home entry was already in /etc/filesystems."],
        }

        grains_mock = {"os": "AIX"}
        opts_mock = {"test": False}
        salt_mock = {"mount.set_filesystems": MagicMock(return_value="present")}
        with patch.dict(mount.__grains__, grains_mock), patch.dict(
            mount.__opts__, opts_mock
        ), patch.dict(mount.__salt__, salt_mock):
            assert mount.fstab_present("/dev/sda1", "/home", "ext2") == ret
            salt_mock["mount.set_filesystems"].assert_called_with(
                name="/home",
                device="/dev/sda1",
                fstype="ext2",
                mount=True,
                opts="",
                config="/etc/filesystems",
                match_on="auto",
                not_change=False,
            )
示例#2
0
    def test_fstab_present_new(self):
        """
        Test fstab_present
        """
        ret = {
            "name": "/dev/sda1",
            "result": True,
            "changes": {"persist": "new"},
            "comment": ["/home entry added in /etc/fstab."],
        }

        grains_mock = {"os": "Linux"}
        opts_mock = {"test": False}
        salt_mock = {"mount.set_fstab": MagicMock(return_value="new")}
        with patch.dict(mount.__grains__, grains_mock), patch.dict(
            mount.__opts__, opts_mock
        ), patch.dict(mount.__salt__, salt_mock):
            assert mount.fstab_present("/dev/sda1", "/home", "ext2") == ret
            salt_mock["mount.set_fstab"].assert_called_with(
                name="/home",
                device="/dev/sda1",
                fstype="ext2",
                opts="defaults",
                dump=0,
                pass_num=0,
                config="/etc/fstab",
                match_on="auto",
                not_change=False,
            )
示例#3
0
    def test_fstab_present_macos_present(self):
        """
        Test fstab_present
        """
        ret = {
            "name": "/dev/sda1",
            "result": True,
            "changes": {},
            "comment": ["/home entry was already in /etc/auto_salt."],
        }

        grains_mock = {"os": "MacOS"}
        opts_mock = {"test": False}
        salt_mock = {"mount.set_automaster": MagicMock(return_value="present")}
        with patch.dict(mount.__grains__, grains_mock), patch.dict(
            mount.__opts__, opts_mock
        ), patch.dict(mount.__salt__, salt_mock):
            assert mount.fstab_present("/dev/sda1", "/home", "ext2") == ret
            salt_mock["mount.set_automaster"].assert_called_with(
                name="/home",
                device="/dev/sda1",
                fstype="ext2",
                opts="noowners",
                config="/etc/auto_salt",
                not_change=False,
            )
示例#4
0
    def test_fstab_present_fail(self):
        '''
        Test fstab_present
        '''
        ret = {
            'name': '/dev/sda1',
            'result': False,
            'changes': {},
            'comment': ['/home entry cannot be changed in /etc/fstab: error.'],
        }

        grains_mock = {'os': 'Linux'}
        opts_mock = {'test': False}
        salt_mock = {
            'mount.set_fstab': MagicMock(return_value='error')
        }
        with patch.dict(mount.__grains__, grains_mock), \
                patch.dict(mount.__opts__, opts_mock), \
                patch.dict(mount.__salt__, salt_mock):
            assert mount.fstab_present('/dev/sda1', '/home', 'ext2') == ret
            salt_mock['mount.set_fstab'].assert_called_with(name='/home',
                                                            device='/dev/sda1',
                                                            fstype='ext2',
                                                            opts='defaults',
                                                            dump=0,
                                                            pass_num=0,
                                                            config='/etc/fstab',
                                                            match_on='auto')
示例#5
0
    def test_fstab_present_aix_present(self):
        '''
        Test fstab_present
        '''
        ret = {
            'name': '/dev/sda1',
            'result': True,
            'changes': {},
            'comment': ['/home entry was already in /etc/filesystems.'],
        }

        grains_mock = {'os': 'AIX'}
        opts_mock = {'test': False}
        salt_mock = {
            'mount.set_filesystems': MagicMock(return_value='present')
        }
        with patch.dict(mount.__grains__, grains_mock), \
                patch.dict(mount.__opts__, opts_mock), \
                patch.dict(mount.__salt__, salt_mock):
            assert mount.fstab_present('/dev/sda1', '/home', 'ext2') == ret
            salt_mock['mount.set_filesystems'].assert_called_with(name='/home',
                                                                  device='/dev/sda1',
                                                                  fstype='ext2',
                                                                  mount=True,
                                                                  opts='',
                                                                  config='/etc/filesystems',
                                                                  match_on='auto')
示例#6
0
    def test_fstab_present_macos_present(self):
        '''
        Test fstab_present
        '''
        ret = {
            'name': '/dev/sda1',
            'result': True,
            'changes': {},
            'comment': ['/home entry was already in /etc/auto_salt.'],
        }

        grains_mock = {'os': 'MacOS'}
        opts_mock = {'test': False}
        salt_mock = {
            'mount.set_automaster': MagicMock(return_value='present')
        }
        with patch.dict(mount.__grains__, grains_mock), \
                patch.dict(mount.__opts__, opts_mock), \
                patch.dict(mount.__salt__, salt_mock):
            assert mount.fstab_present('/dev/sda1', '/home', 'ext2') == ret
            salt_mock['mount.set_automaster'].assert_called_with(name='/home',
                                                                 device='/dev/sda1',
                                                                 fstype='ext2',
                                                                 opts='noowners',
                                                                 config='/etc/auto_salt')
示例#7
0
    def test_fstab_present_test_new(self):
        '''
        Test fstab_present
        '''
        ret = {
            'name': '/dev/sda1',
            'result': None,
            'changes': {},
            'comment': ['/home entry will be written in /etc/fstab.'],
        }

        grains_mock = {'os': 'Linux'}
        opts_mock = {'test': True}
        salt_mock = {'mount.set_fstab': MagicMock(return_value='new')}
        with patch.dict(mount.__grains__, grains_mock), \
                patch.dict(mount.__opts__, opts_mock), \
                patch.dict(mount.__salt__, salt_mock):
            assert mount.fstab_present('/dev/sda1', '/home', 'ext2') == ret
            salt_mock['mount.set_fstab'].assert_called_with(
                name='/home',
                device='/dev/sda1',
                fstype='ext2',
                opts='defaults',
                dump=0,
                pass_num=0,
                config='/etc/fstab',
                test=True,
                match_on='auto',
                not_change=False)