Ejemplo n.º 1
0
    def test_dump_resize_fail_btrfs(self):
        '''Test images.dump function when resize fails (btrfs)'''
        salt_mock = {
            'cmd.run_stdout':
            MagicMock(return_value='btrfs'),
            'cmd.run_all':
            MagicMock(side_effect=[{
                'retcode': 0,
                'stdout': 'checksum',
            }, {
                'retcode': 1,
                'stderr': 'error',
            }]),
        }

        with patch.dict(images.__salt__, salt_mock):
            with self.assertRaises(CommandExecutionError):
                images.dump('http://example.org/image.btrfs',
                            '/dev/sda1',
                            checksum_type='md5',
                            checksum='checksum')
            salt_mock['cmd.run_all'].assert_called_with(
                'mount /dev/sda1 /mnt; btrfs filesystem resize max /mnt; '
                'umount /mnt',
                python_shell=True)
Ejemplo n.º 2
0
    def test_dump_resize_fail_xfs(self):
        """Test images.dump function when resize fails (xfs)"""
        salt_mock = {
            "cmd.run_stdout":
            MagicMock(return_value="xfs"),
            "cmd.run_all":
            MagicMock(side_effect=[
                {
                    "retcode": 0,
                    "stdout": "checksum"
                },
                {
                    "retcode": 1,
                    "stderr": "error"
                },
            ]),
        }

        with patch.dict(images.__salt__, salt_mock):
            with self.assertRaises(CommandExecutionError):
                images.dump(
                    "http://example.org/image.xfs",
                    "/dev/sda1",
                    checksum_type="md5",
                    checksum="checksum",
                )
            salt_mock["cmd.run_all"].assert_called_with(
                "mount /dev/sda1 /mnt; xfs_growfs /mnt; umount /mnt",
                python_shell=True)
Ejemplo n.º 3
0
    def test_dump_download_checksum_fail(self):
        '''Test images.dump function when checksum fails'''
        salt_mock = {
            'cmd.run_all':
            MagicMock(return_value={
                'retcode': 0,
                'stdout': 'badchecksum',
            }),
        }

        with patch.dict(images.__salt__, salt_mock):
            with self.assertRaises(CommandExecutionError):
                images.dump('http://example.org/image.ext4',
                            '/dev/sda1',
                            checksum_type='md5',
                            checksum='checksum')
Ejemplo n.º 4
0
    def test_dump_resize(self):
        """Test images.dump function"""
        salt_mock = {
            "cmd.run_stdout":
            MagicMock(return_value="ext4"),
            "cmd.run_all":
            MagicMock(side_effect=[{
                "retcode": 0,
                "stdout": "checksum"
            }, {
                "retcode": 0
            }]),
            "cmd.run":
            MagicMock(return_value=""),
        }

        with patch.dict(images.__salt__, salt_mock):
            self.assertEqual(
                images.dump(
                    "http://example.org/image.ext4",
                    "/dev/sda1",
                    checksum_type="md5",
                    checksum="checksum",
                ),
                "checksum",
            )
            salt_mock["cmd.run"].assert_called_with("sync")
Ejemplo n.º 5
0
    def test_dump_download_checksum_fail_fetch(self):
        """Test images.dump function when checksum fails"""
        salt_mock = {
            "cmd.run_stdout":
            MagicMock(return_value="checksum -"),
            "cmd.run_all":
            MagicMock(return_value={
                "retcode": 0,
                "stdout": "badchecksum"
            }),
        }

        with patch.dict(images.__salt__, salt_mock):
            with self.assertRaises(CommandExecutionError):
                images.dump("http://example.org/image.ext4",
                            "/dev/sda1",
                            checksum_type="md5")
Ejemplo n.º 6
0
    def test_dump_download_fail_xz(self):
        '''Test images.dump function when download fails (xz)'''
        salt_mock = {
            'cmd.run_all':
            MagicMock(return_value={
                'retcode': 1,
                'stderr': 'error',
            }),
        }

        with patch.dict(images.__salt__, salt_mock):
            with self.assertRaises(CommandExecutionError):
                images.dump('http://example.org/image.xz', '/dev/sda1')
            salt_mock['cmd.run_all'].assert_called_with(
                'set -eo pipefail ; curl --fail --location --silent '
                'http://example.org/image.xz | xz -d | tee /dev/sda1 '
                '| md5sum',
                python_shell=True)
Ejemplo n.º 7
0
    def test_dump_download_fail_xz(self):
        """Test images.dump function when download fails (xz)"""
        salt_mock = {
            "cmd.run_all":
            MagicMock(return_value={
                "retcode": 1,
                "stderr": "error"
            }),
        }

        with patch.dict(images.__salt__, salt_mock):
            with self.assertRaises(CommandExecutionError):
                images.dump("http://example.org/image.xz", "/dev/sda1")
            salt_mock["cmd.run_all"].assert_called_with(
                "set -eo pipefail ; curl --fail --location --silent "
                "http://example.org/image.xz | xz -d | tee /dev/sda1 "
                "| md5sum",
                python_shell=True,
            )
Ejemplo n.º 8
0
    def test_dump_resize_fail_extx(self):
        '''Test images.dump function when resize fails (extx)'''
        salt_mock = {
            'cmd.run_stdout':
            MagicMock(return_value='ext4'),
            'cmd.run_all':
            MagicMock(side_effect=[{
                'retcode': 0,
                'stdout': 'checksum',
            }, {
                'retcode': 1,
                'stderr': 'error',
            }]),
        }

        with patch.dict(images.__salt__, salt_mock):
            with self.assertRaises(CommandExecutionError):
                images.dump('http://example.org/image.ext4',
                            '/dev/sda1',
                            checksum_type='md5',
                            checksum='checksum')
            salt_mock['cmd.run_all'].assert_called_with(
                'e2fsck -f -y /dev/sda1; resize2fs /dev/sda1',
                python_shell=True)
Ejemplo n.º 9
0
    def test_dump_resize(self):
        '''Test images.dump function'''
        salt_mock = {
            'cmd.run_stdout':
            MagicMock(return_value='ext4'),
            'cmd.run_all':
            MagicMock(side_effect=[{
                'retcode': 0,
                'stdout': 'checksum',
            }, {
                'retcode': 0,
            }]),
            'cmd.run':
            MagicMock(return_value=''),
        }

        with patch.dict(images.__salt__, salt_mock):
            self.assertEqual(
                images.dump('http://example.org/image.ext4',
                            '/dev/sda1',
                            checksum_type='md5',
                            checksum='checksum'), 'checksum')
            salt_mock['cmd.run'].assert_called_with('sync')
Ejemplo n.º 10
0
 def test_dump_missing_checksum_type(self):
     '''Test images.dump function with a missing checksum type'''
     with self.assertRaises(SaltInvocationError):
         images.dump('http://example.org/image.xz',
                     '/dev/sda1',
                     checksum='mychecksum')
Ejemplo n.º 11
0
 def test_dump_invalid_checksum_type(self):
     '''Test images.dump function with an invalid checksum type'''
     with self.assertRaises(SaltInvocationError):
         images.dump('http://example.org/image.xz',
                     '/dev/sda1',
                     checksum_type='crc')
Ejemplo n.º 12
0
 def test_dump_invalid_url(self):
     '''Test images.dump function with an invalid URL'''
     with self.assertRaises(SaltInvocationError):
         images.dump('random://example.org', '/dev/sda1')
Ejemplo n.º 13
0
 def test_dump_missing_checksum_type(self):
     """Test images.dump function with a missing checksum type"""
     with self.assertRaises(SaltInvocationError):
         images.dump("http://example.org/image.xz",
                     "/dev/sda1",
                     checksum="mychecksum")
Ejemplo n.º 14
0
 def test_dump_invalid_checksum_type(self):
     """Test images.dump function with an invalid checksum type"""
     with self.assertRaises(SaltInvocationError):
         images.dump("http://example.org/image.xz",
                     "/dev/sda1",
                     checksum_type="crc")
Ejemplo n.º 15
0
 def test_dump_invalid_url(self):
     """Test images.dump function with an invalid URL"""
     with self.assertRaises(SaltInvocationError):
         images.dump("random://example.org", "/dev/sda1")