Example #1
0
 def test_subvolume_created_exists_unset_cow(self, mount, umount, is_cow,
                                             unset_cow):
     '''
     Test creating a subvolume.
     '''
     mount.return_value = '/tmp/xxx'
     is_cow.return_value = True
     unset_cow.return_value = True
     salt_mock = {
         'btrfs.subvolume_exists': MagicMock(return_value=True),
     }
     opts_mock = {
         'test': False,
     }
     with patch.dict(btrfs.__salt__, salt_mock), \
             patch.dict(btrfs.__opts__, opts_mock):
         assert btrfs.subvolume_created(
             name='@/var', device='/dev/sda1', copy_on_write=False) == {
                 'name': '@/var',
                 'result': True,
                 'changes': {
                     '@/var_no_cow': True
                 },
                 'comment': ['Subvolume @/var already present'],
             }
         salt_mock['btrfs.subvolume_exists'].assert_called_with(
             '/tmp/xxx/@/var')
         mount.assert_called_once()
         umount.assert_called_once()
Example #2
0
 def test_subvolume_created_fails(self, mount, umount):
     '''
     Test creating a subvolume.
     '''
     mount.return_value = '/tmp/xxx'
     salt_mock = {
         'btrfs.subvolume_exists': MagicMock(return_value=False),
         'btrfs.subvolume_create':
         MagicMock(side_effect=CommandExecutionError),
     }
     states_mock = {
         'file.directory': MagicMock(return_value={'result': True}),
     }
     opts_mock = {
         'test': False,
     }
     with patch.dict(btrfs.__salt__, salt_mock), \
             patch.dict(btrfs.__states__, states_mock), \
             patch.dict(btrfs.__opts__, opts_mock):
         assert btrfs.subvolume_created(
             name='@/var', device='/dev/sda1') == {
                 'name': '@/var',
                 'result': False,
                 'changes': {},
                 'comment': ['Error creating subvolume @/var'],
             }
         salt_mock['btrfs.subvolume_exists'].assert_called_with(
             '/tmp/xxx/@/var')
         salt_mock['btrfs.subvolume_create'].assert_called_once()
         mount.assert_called_once()
         umount.assert_called_once()
Example #3
0
 def test_subvolume_created_fails(self, mount, umount):
     """
     Test creating a subvolume.
     """
     mount.return_value = "/tmp/xxx"
     salt_mock = {
         "btrfs.subvolume_exists": MagicMock(return_value=False),
         "btrfs.subvolume_create":
         MagicMock(side_effect=CommandExecutionError),
     }
     states_mock = {
         "file.directory": MagicMock(return_value={"result": True}),
     }
     opts_mock = {
         "test": False,
     }
     with patch.dict(btrfs.__salt__, salt_mock), patch.dict(
             btrfs.__states__,
             states_mock), patch.dict(btrfs.__opts__, opts_mock):
         assert btrfs.subvolume_created(
             name="@/var", device="/dev/sda1") == {
                 "name": "@/var",
                 "result": False,
                 "changes": {},
                 "comment": ["Error creating subvolume @/var"],
             }
         salt_mock["btrfs.subvolume_exists"].assert_called_with(
             "/tmp/xxx/@/var")
         salt_mock["btrfs.subvolume_create"].assert_called_once()
         mount.assert_called_once()
         umount.assert_called_once()
Example #4
0
 def test_subvolume_created_exists_unset_cow(self, mount, umount, is_cow,
                                             unset_cow):
     """
     Test creating a subvolume.
     """
     mount.return_value = "/tmp/xxx"
     is_cow.return_value = True
     unset_cow.return_value = True
     salt_mock = {
         "btrfs.subvolume_exists": MagicMock(return_value=True),
     }
     opts_mock = {
         "test": False,
     }
     with patch.dict(btrfs.__salt__,
                     salt_mock), patch.dict(btrfs.__opts__, opts_mock):
         assert btrfs.subvolume_created(
             name="@/var", device="/dev/sda1", copy_on_write=False) == {
                 "name": "@/var",
                 "result": True,
                 "changes": {
                     "@/var_no_cow": True
                 },
                 "comment": ["Subvolume @/var already present"],
             }
         salt_mock["btrfs.subvolume_exists"].assert_called_with(
             "/tmp/xxx/@/var")
         mount.assert_called_once()
         umount.assert_called_once()
Example #5
0
def test_subvolume_created_exists_set_default_no_force(mount, umount,
                                                       is_default,
                                                       set_default):
    """
    Test creating a subvolume.
    """
    mount.return_value = "/tmp/xxx"
    is_default.return_value = False
    set_default.return_value = True
    salt_mock = {
        "btrfs.subvolume_exists": MagicMock(return_value=True),
    }
    opts_mock = {
        "test": False,
    }
    with patch.dict(btrfs.__salt__,
                    salt_mock), patch.dict(btrfs.__opts__, opts_mock):
        assert btrfs.subvolume_created(
            name="@/var",
            device="/dev/sda1",
            set_default=True,
            force_set_default=False,
        ) == {
            "name": "@/var",
            "result": True,
            "changes": {},
            "comment": ["Subvolume @/var already present"],
        }
        salt_mock["btrfs.subvolume_exists"].assert_called_with(
            "/tmp/xxx/@/var")
        mount.assert_called_once()
        umount.assert_called_once()
Example #6
0
 def test_subvolume_created_exists_test(self, mount, umount):
     '''
     Test creating a subvolume.
     '''
     mount.return_value = '/tmp/xxx'
     salt_mock = {
         'btrfs.subvolume_exists': MagicMock(return_value=True),
     }
     opts_mock = {
         'test': True,
     }
     with patch.dict(btrfs.__salt__, salt_mock), \
             patch.dict(btrfs.__opts__, opts_mock):
         assert btrfs.subvolume_created(name='@/var',
                                        device='/dev/sda1') == {
             'name': '@/var',
             'result': None,
             'changes': {},
             'comment': ['Subvolume @/var already present'],
         }
         salt_mock['btrfs.subvolume_exists'].assert_called_with('/tmp/xxx/@/var')
         mount.assert_called_once()
         umount.assert_called_once()
Example #7
0
 def test_subvolume_created_exists_decorator(self, mount, umount):
     """
     Test creating a subvolume using a non-kwargs call
     """
     mount.return_value = "/tmp/xxx"
     salt_mock = {
         "btrfs.subvolume_exists": MagicMock(return_value=True),
     }
     opts_mock = {
         "test": False,
     }
     with patch.dict(btrfs.__salt__, salt_mock), patch.dict(
         btrfs.__opts__, opts_mock
     ):
         assert btrfs.subvolume_created("@/var", "/dev/sda1") == {
             "name": "@/var",
             "result": True,
             "changes": {},
             "comment": ["Subvolume @/var already present"],
         }
         salt_mock["btrfs.subvolume_exists"].assert_called_with("/tmp/xxx/@/var")
         mount.assert_called_once()
         umount.assert_called_once()