Exemplo n.º 1
0
    def test_subvolume_list_fails_parameters(self):
        '''
        Test btrfs subvolume list
        '''
        # Fails when sort is not a list
        with pytest.raises(CommandExecutionError):
            btrfs.subvolume_list('/mnt', sort='-rootid')

        # Fails when sort is not recognized
        with pytest.raises(CommandExecutionError):
            btrfs.subvolume_list('/mnt', sort=['-root'])
Exemplo n.º 2
0
    def test_subvolume_list_fails_parameters(self):
        """
        Test btrfs subvolume list
        """
        # Fails when sort is not a list
        with pytest.raises(CommandExecutionError):
            btrfs.subvolume_list("/mnt", sort="-rootid")

        # Fails when sort is not recognized
        with pytest.raises(CommandExecutionError):
            btrfs.subvolume_list("/mnt", sort=["-root"])
Exemplo n.º 3
0
    def test_subvolume_list_simple(self):
        '''
        Test btrfs subvolume list
        '''
        salt_mock = {
            'cmd.run_all':
            MagicMock(
                return_value={
                    'recode':
                    0,
                    'stdout':
                    '''ID 257 gen 8 top level 5 path one
ID 258 gen 10 top level 5 path another one
''',
                }),
        }
        with patch.dict(btrfs.__salt__, salt_mock):
            assert btrfs.subvolume_list('/mnt') == [
                {
                    'id': '257',
                    'gen': '8',
                    'top level': '5',
                    'path': 'one',
                },
                {
                    'id': '258',
                    'gen': '10',
                    'top level': '5',
                    'path': 'another one',
                },
            ]
            salt_mock['cmd.run_all'].assert_called_once()
            salt_mock['cmd.run_all'].assert_called_with(
                ['btrfs', 'subvolume', 'list', '/mnt'])
Exemplo n.º 4
0
    def test_subvolume_list_simple(self):
        """
        Test btrfs subvolume list
        """
        salt_mock = {
            "cmd.run_all":
            MagicMock(
                return_value={
                    "recode":
                    0,
                    "stdout":
                    """ID 257 gen 8 top level 5 path one
ID 258 gen 10 top level 5 path another one
""",
                }),
        }
        with patch.dict(btrfs.__salt__, salt_mock):
            assert btrfs.subvolume_list("/mnt") == [
                {
                    "id": "257",
                    "gen": "8",
                    "top level": "5",
                    "path": "one"
                },
                {
                    "id": "258",
                    "gen": "10",
                    "top level": "5",
                    "path": "another one"
                },
            ]
            salt_mock["cmd.run_all"].assert_called_once()
            salt_mock["cmd.run_all"].assert_called_with(
                ["btrfs", "subvolume", "list", "/mnt"])
Exemplo n.º 5
0
    def test_subvolume_list(self):
        '''
        Test btrfs subvolume list
        '''
        salt_mock = {
            'cmd.run_all':
            MagicMock(
                return_value={
                    'recode':
                    0,
                    'stdout':
                    '''\
ID 257 gen 8 cgen 8 parent 5 top level 5 parent_uuid -     received_uuid - \
             uuid 777...-..05 path one
ID 258 gen 10 cgen 10 parent 5 top level 5 parent_uuid -     received_uuid - \
             uuid a90...-..01 path another one
''',
                }),
        }
        with patch.dict(btrfs.__salt__, salt_mock):
            assert btrfs.subvolume_list('/mnt',
                                        parent_id=True,
                                        absolute=True,
                                        ogeneration=True,
                                        generation=True,
                                        subvolumes=True,
                                        uuid=True,
                                        parent_uuid=True,
                                        sent_subvolume_uuid=True,
                                        generation_cmp='-100',
                                        ogeneration_cmp='+5',
                                        sort=['-rootid', 'gen']) == [
                                            {
                                                'id': '257',
                                                'gen': '8',
                                                'cgen': '8',
                                                'parent': '5',
                                                'top level': '5',
                                                'parent_uuid': '-',
                                                'received_uuid': '-',
                                                'uuid': '777...-..05',
                                                'path': 'one',
                                            },
                                            {
                                                'id': '258',
                                                'gen': '10',
                                                'cgen': '10',
                                                'parent': '5',
                                                'top level': '5',
                                                'parent_uuid': '-',
                                                'received_uuid': '-',
                                                'uuid': 'a90...-..01',
                                                'path': 'another one',
                                            },
                                        ]
            salt_mock['cmd.run_all'].assert_called_once()
            salt_mock['cmd.run_all'].assert_called_with([
                'btrfs', 'subvolume', 'list', '-p', '-a', '-c', '-g', '-o',
                '-u', '-q', '-R', '-G', '-100', '-C', '+5',
                '--sort=-rootid,gen', '/mnt'
            ])
Exemplo n.º 6
0
    def test_subvolume_list(self):
        """
        Test btrfs subvolume list
        """
        salt_mock = {
            "cmd.run_all":
            MagicMock(
                return_value={
                    "recode":
                    0,
                    "stdout":
                    """\
ID 257 gen 8 cgen 8 parent 5 top level 5 parent_uuid -     received_uuid - \
             uuid 777...-..05 path one
ID 258 gen 10 cgen 10 parent 5 top level 5 parent_uuid -     received_uuid - \
             uuid a90...-..01 path another one
""",
                }),
        }
        with patch.dict(btrfs.__salt__, salt_mock):
            assert btrfs.subvolume_list(
                "/mnt",
                parent_id=True,
                absolute=True,
                ogeneration=True,
                generation=True,
                subvolumes=True,
                uuid=True,
                parent_uuid=True,
                sent_subvolume_uuid=True,
                generation_cmp="-100",
                ogeneration_cmp="+5",
                sort=["-rootid", "gen"],
            ) == [
                {
                    "id": "257",
                    "gen": "8",
                    "cgen": "8",
                    "parent": "5",
                    "top level": "5",
                    "parent_uuid": "-",
                    "received_uuid": "-",
                    "uuid": "777...-..05",
                    "path": "one",
                },
                {
                    "id": "258",
                    "gen": "10",
                    "cgen": "10",
                    "parent": "5",
                    "top level": "5",
                    "parent_uuid": "-",
                    "received_uuid": "-",
                    "uuid": "a90...-..01",
                    "path": "another one",
                },
            ]
            salt_mock["cmd.run_all"].assert_called_once()
            salt_mock["cmd.run_all"].assert_called_with([
                "btrfs",
                "subvolume",
                "list",
                "-p",
                "-a",
                "-c",
                "-g",
                "-o",
                "-u",
                "-q",
                "-R",
                "-G",
                "-100",
                "-C",
                "+5",
                "--sort=-rootid,gen",
                "/mnt",
            ])