def test_properties_test(self, exists, mount, umount): """ Test setting a property in test mode. """ exists.return_value = True mount.return_value = "/tmp/xxx" salt_mock = { "btrfs.properties": MagicMock(side_effect=[ { "ro": { "description": "Set/get read-only flag or subvolume", "value": "N/A", }, }, ]), } opts_mock = { "test": True, } with patch.dict(btrfs.__salt__, salt_mock), patch.dict(btrfs.__opts__, opts_mock): assert btrfs.properties(name="@/var", device="/dev/sda1", ro=True) == { "name": "@/var", "result": None, "changes": { "ro": "true" }, "comment": [], } salt_mock["btrfs.properties"].assert_called_with("/tmp/xxx/@/var") mount.assert_called_once() umount.assert_called_once()
def test_properties_subvolume_fail(self, exists, mount, umount): ''' Test setting a wrong property in a subvolume ''' exists.return_value = True mount.return_value = '/tmp/xxx' salt_mock = { 'btrfs.properties': MagicMock(side_effect=[ { 'ro': { 'description': 'Set/get read-only flag or subvolume', 'value': 'N/A', }, } ]), } opts_mock = { 'test': False, } with patch.dict(btrfs.__salt__, salt_mock), \ patch.dict(btrfs.__opts__, opts_mock): assert btrfs.properties(name='@/var', device='/dev/sda1', wrond_property=True) == { 'name': '@/var', 'result': False, 'changes': {}, 'comment': ['Some property not found in @/var'], } salt_mock['btrfs.properties'].assert_called_with('/tmp/xxx/@/var') mount.assert_called_once() umount.assert_called_once()
def test_properties_subvolume_fail(self, exists, mount, umount): """ Test setting a wrong property in a subvolume """ exists.return_value = True mount.return_value = "/tmp/xxx" salt_mock = { "btrfs.properties": MagicMock(side_effect=[{ "ro": { "description": "Set/get read-only flag or subvolume", "value": "N/A", }, }]), } opts_mock = { "test": False, } with patch.dict(btrfs.__salt__, salt_mock), patch.dict(btrfs.__opts__, opts_mock): assert btrfs.properties(name="@/var", device="/dev/sda1", wrond_property=True) == { "name": "@/var", "result": False, "changes": {}, "comment": ["Some property not found in @/var"], } salt_mock["btrfs.properties"].assert_called_with("/tmp/xxx/@/var") mount.assert_called_once() umount.assert_called_once()
def test_properties_device_fail(self, exists): """ Test when we try to set a device that is not pressent """ exists.return_value = False assert btrfs.properties(name="/dev/sda1", device=None) == { "name": "/dev/sda1", "result": False, "changes": {}, "comment": ["Object /dev/sda1 not found"], }
def test_properties_device_fail(self, exists): ''' Test when we try to set a device that is not pressent ''' exists.return_value = False assert btrfs.properties(name='/dev/sda1', device=None) == { 'name': '/dev/sda1', 'result': False, 'changes': {}, 'comment': ['Object /dev/sda1 not found'], }
def test_properties_default_root_subvolume(self, exists, mount, umount): """ Test when root subvolume resolves to another subvolume """ exists.return_value = False mount.return_value = "/tmp/xxx" assert btrfs.properties(name="/", device="/dev/sda1") == { "name": "/", "result": False, "changes": {}, "comment": ["Object / not found"], } exists.assert_called_with("/tmp/xxx/.")
def test_properties_default_root_subvolume(self, exists, mount, umount): ''' Test when root subvolume resolves to another subvolume ''' exists.return_value = False mount.return_value = '/tmp/xxx' assert btrfs.properties(name='/', device='/dev/sda1') == { 'name': '/', 'result': False, 'changes': {}, 'comment': ['Object / not found'], } exists.assert_called_with('/tmp/xxx/.')
def test_properties_subvolume_not_exists(self, exists, mount, umount): """ Test when subvolume is not present """ exists.return_value = False mount.return_value = "/tmp/xxx" assert btrfs.properties(name="@/var", device="/dev/sda1") == { "name": "@/var", "result": False, "changes": {}, "comment": ["Object @/var not found"], } mount.assert_called_once() umount.assert_called_once()
def test_properties_subvolume_not_exists(self, exists, mount, umount): ''' Test when subvolume is not present ''' exists.return_value = False mount.return_value = '/tmp/xxx' assert btrfs.properties(name='@/var', device='/dev/sda1') == { 'name': '@/var', 'result': False, 'changes': {}, 'comment': ['Object @/var not found'], } mount.assert_called_once() umount.assert_called_once()
def test_properties_enable_ro_subvolume(self, exists, mount, umount): ''' Test setting a ro property in a subvolume ''' exists.return_value = True mount.return_value = '/tmp/xxx' salt_mock = { 'btrfs.properties': MagicMock(side_effect=[ { 'ro': { 'description': 'Set/get read-only flag or subvolume', 'value': 'N/A', }, }, None, { 'ro': { 'description': 'Set/get read-only flag or subvolume', 'value': 'true', }, } ]), } opts_mock = { 'test': False, } with patch.dict(btrfs.__salt__, salt_mock), \ patch.dict(btrfs.__opts__, opts_mock): assert btrfs.properties(name='@/var', device='/dev/sda1', ro=True) == { 'name': '@/var', 'result': True, 'changes': {'ro': 'true'}, 'comment': ['Properties changed in @/var'], } salt_mock['btrfs.properties'].assert_any_call('/tmp/xxx/@/var') salt_mock['btrfs.properties'].assert_any_call('/tmp/xxx/@/var', set='ro=true') mount.assert_called_once() umount.assert_called_once()