Re: [virt-bootstrap] [PATCH v4 14/26] Drop unused functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Should be merged with the commit adding the Build_QCOW2_Image class

--
cedric

On Thu, 2017-08-03 at 14:13 +0100, Radostin Stoyanov wrote:
> Remove the functions create_qcow2() and extract_layers_in_qcow2()
> as they were replaced with the class Build_QCOW2_Image.
> 
> Remove the unit tests as well.
> ---
>  src/virtBootstrap/utils.py  | 61 ----------------------------
>  tests/test_docker_source.py | 38 +++++------------
>  tests/test_file_source.py   | 35 ----------------
>  tests/test_utils.py         | 99 ---------------------------------------------
>  4 files changed, 9 insertions(+), 224 deletions(-)
> 
> diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
> index 19aaa17..965dcad 100644
> --- a/src/virtBootstrap/utils.py
> +++ b/src/virtBootstrap/utils.py
> @@ -302,67 +302,6 @@ def get_mime_type(path):
>      )
>  
>  
> -def create_qcow2(tar_file, layer_file, backing_file=None, size=DEF_QCOW2_SIZE):
> -    """
> -    Create qcow2 image from tarball.
> -    """
> -    qemu_img_cmd = ["qemu-img", "create", "-f", "qcow2", layer_file, size]
> -
> -    if not backing_file:
> -        logger.info("Creating base qcow2 image")
> -        execute(qemu_img_cmd)
> -
> -        logger.info("Formatting qcow2 image")
> -        execute(['virt-format',
> -                 '--format=qcow2',
> -                 '--partition=none',
> -                 '--filesystem=ext3',
> -                 '-a', layer_file])
> -    else:
> -        # Add backing chain
> -        qemu_img_cmd.insert(2, "-b")
> -        qemu_img_cmd.insert(3, backing_file)
> -
> -        logger.info("Creating qcow2 image with backing chain")
> -        execute(qemu_img_cmd)
> -
> -    # Extract tarball using "tar-in" command from libguestfs
> -    tar_in_cmd = ["guestfish",
> -                  "-a", layer_file,
> -                  '-m', '/dev/sda',
> -                  'tar-in', tar_file, "/"]
> -
> -    # Check if tarball is compressed
> -    compression = get_compression_type(tar_file)
> -    if compression is not None:
> -        tar_in_cmd.append('compress:' + compression)
> -
> -    # Execute virt-tar-in command
> -    execute(tar_in_cmd)
> -
> -
> -def extract_layers_in_qcow2(layers_list, dest_dir, progress):
> -    """
> -    Extract docker layers in qcow2 images with backing chains.
> -    """
> -    qcow2_backing_file = None
> -
> -    nlayers = len(layers_list)
> -    for index, layer in enumerate(layers_list):
> -        log_layer_extract(layer, index + 1, nlayers, progress)
> -        tar_file = layer[2]
> -
> -        # Name format for the qcow2 image
> -        qcow2_layer_file = "{}/layer-{}.qcow2".format(dest_dir, index)
> -        # Create the image layer
> -        create_qcow2(tar_file, qcow2_layer_file, qcow2_backing_file)
> -        # Keep the file path for the next layer
> -        qcow2_backing_file = qcow2_layer_file
> -
> -        # Update progress value
> -        progress(value=(float(index + 1) / nlayers * 50) + 50)
> -
> -
>  def get_image_dir(no_cache=False):
>      """
>      Get the directory where image layers are stored.
> diff --git a/tests/test_docker_source.py b/tests/test_docker_source.py
> index 4859e1b..3865be6 100644
> --- a/tests/test_docker_source.py
> +++ b/tests/test_docker_source.py
> @@ -525,14 +525,6 @@ class TestDockerSource(unittest.TestCase):
>          """
>          self._unpack_test_fmt('dir', 'virtBootstrap.utils.untar_layers')
>  
> -    def test_unpack_qcow2_format(self):
> -        """
> -        Ensures that unpack() calls extract_layers_in_qcow2() when the
> -        output format is set to 'qcow2'.
> -        """
> -        self._unpack_test_fmt('qcow2',
> -                              'virtBootstrap.utils.extract_layers_in_qcow2')
> -
>      def unpack_raise_error_test(self,
>                                  output_format,
>                                  patch_method,
> @@ -566,32 +558,20 @@ class TestDockerSource(unittest.TestCase):
>          patch_method = 'virtBootstrap.utils.untar_layers'
>          self.unpack_raise_error_test('dir', patch_method, side_effect, msg)
>  
> -    def test_unpack_raise_error_if_extract_in_qcow2_fail(self):
> -        """
> -        Ensures that unpack() throws an Exception when
> -        extract_layers_in_qcow2() fails.
> -        """
> -        msg = 'Caught extract_layers_in_qcow2 failure'
> -        side_effect = Exception(msg)
> -        patch_method = 'virtBootstrap.utils.extract_layers_in_qcow2'
> -        self.unpack_raise_error_test('qcow2', patch_method, side_effect, msg)
> -
>      def test_unpack_no_cache_clean_up(self):
>          """
>          Ensures that unpack() removes the folder which stores tar archives
>          of image layers when no_cache is set to True.
>          """
> -        output_formats = ['dir', 'qcow2']
> -        patch_methods = [
> -            'virtBootstrap.utils.untar_layers',
> -            'virtBootstrap.utils.extract_layers_in_qcow2'
> -        ]
> -        for fmt, patch_mthd in zip(output_formats, patch_methods):
> -            m_self = self._mock_docker_source()
> -            m_self.no_cache = True
> -            with mock.patch('shutil.rmtree') as m_shutil:
> -                self._unpack_test_fmt(fmt, patch_mthd, m_self=m_self)
> -            m_shutil.assert_called_once_with(m_self.images_dir)
> +        m_self = self._mock_docker_source()
> +        m_self.no_cache = True
> +        with mock.patch('shutil.rmtree') as m_shutil:
> +            self._unpack_test_fmt(
> +                'dir',
> +                'virtBootstrap.utils.untar_layers',
> +                m_self=m_self
> +            )
> +        m_shutil.assert_called_once_with(m_self.images_dir)
>  
>      def test_unpack_no_cache_clean_up_on_failure(self):
>          """
> diff --git a/tests/test_file_source.py b/tests/test_file_source.py
> index 6e89aa2..a55ae4e 100644
> --- a/tests/test_file_source.py
> +++ b/tests/test_file_source.py
> @@ -87,29 +87,6 @@ class TestFileSource(unittest.TestCase):
>  
>          m_untar.assert_called_once_with(m_self.path, dest)
>  
> -    def test_unpack_to_qcow2(self):
> -        """
> -        Ensures that unpack() calls create_qcow2() when the output
> -        format is set to 'qcow2'.
> -        """
> -        m_self = mock.Mock(spec=sources.FileSource)
> -        m_self.progress = mock.Mock()
> -        m_self.path = 'foo'
> -        m_self.output_format = 'qcow2'
> -        dest = 'bar'
> -        qcow2_file_path = 'foobar'
> -
> -        with mock.patch.multiple('os.path',
> -                                 isfile=mock.DEFAULT,
> -                                 realpath=mock.DEFAULT) as mocked:
> -
> -            mocked['isfile'].return_value = True
> -            mocked['realpath'].return_value = qcow2_file_path
> -            with mock.patch('virtBootstrap.utils.create_qcow2') as m_qcow2:
> -                sources.FileSource.unpack(m_self, dest)
> -
> -        m_qcow2.assert_called_once_with(m_self.path, qcow2_file_path)
> -
>      def _unpack_raise_error_test(self,
>                                   output_format,
>                                   side_effect=None,
> @@ -157,15 +134,3 @@ class TestFileSource(unittest.TestCase):
>                                        side_effect=Exception(msg),
>                                        patch_method=patch_method,
>                                        msg=msg)
> -
> -    def test_unpack_raise_error_if_extract_in_qcow2_fail(self):
> -        """
> -        Ensures that unpack() throws an Exception when create_qcow2()
> -        fails.
> -        """
> -        msg = 'Caught extract_layers_in_qcow2 failure'
> -        patch_method = 'virtBootstrap.utils.create_qcow2'
> -        self._unpack_raise_error_test(output_format='qcow2',
> -                                      side_effect=Exception(msg),
> -                                      patch_method=patch_method,
> -                                      msg=msg)
> diff --git a/tests/test_utils.py b/tests/test_utils.py
> index 0b6ccc0..e45a2c9 100644
> --- a/tests/test_utils.py
> +++ b/tests/test_utils.py
> @@ -226,105 +226,6 @@ class TestUtils(unittest.TestCase):
>          mocked['safe_untar'].assert_has_calls(expected_calls)
>  
>      ###################################
> -    # Tests for: create_qcow2()
> -    ###################################
> -    def _apply_test_to_create_qcow2(self, expected_calls, *args):
> -        """
> -        This method contains common test pattern used in the next two
> -        test cases.
> -        """
> -        with mock.patch.multiple(utils,
> -                                 execute=mock.DEFAULT,
> -                                 logger=mock.DEFAULT,
> -                                 get_mime_type=mock.DEFAULT) as mocked:
> -            mocked['get_mime_type'].return_value = 'application/x-gzip'
> -            utils.create_qcow2(*args)
> -        mocked['execute'].assert_has_calls(expected_calls)
> -
> -    def test_utils_create_qcow2_base_layer(self):
> -        """
> -        Ensures that create_qcow2() creates base layer when
> -        backing_file = None.
> -        """
> -        tar_file = 'foo'
> -        layer_file = 'bar'
> -        size = '5G'
> -        backing_file = None
> -
> -        expected_calls = [
> -            mock.call(["qemu-img", "create", "-f", "qcow2", layer_file, size]),
> -
> -            mock.call(['virt-format',
> -                       '--format=qcow2',
> -                       '--partition=none',
> -                       '--filesystem=ext3',
> -                       '-a', layer_file]),
> -
> -            mock.call(['guestfish',
> -                       '-a', layer_file,
> -                       '-m', '/dev/sda',
> -                       'tar-in', tar_file, '/', 'compress:gzip'])
> -        ]
> -
> -        self._apply_test_to_create_qcow2(expected_calls, tar_file, layer_file,
> -                                         backing_file, size)
> -
> -    def test_utils_create_qcow2_layer_with_backing_chain(self):
> -        """
> -        Ensures that create_qcow2() creates new layer with backing chains
> -        when backing_file is specified.
> -        """
> -        tar_file = 'foo'
> -        layer_file = 'bar'
> -        backing_file = 'base'
> -        size = '5G'
> -
> -        expected_calls = [
> -            mock.call(['qemu-img', 'create',
> -                       '-b', backing_file,
> -                       '-f', 'qcow2',
> -                       layer_file, size]),
> -
> -            mock.call(['guestfish',
> -                       '-a', layer_file,
> -                       '-m', '/dev/sda',
> -                       'tar-in', tar_file, '/', 'compress:gzip'])
> -        ]
> -
> -        self._apply_test_to_create_qcow2(expected_calls, tar_file, layer_file,
> -                                         backing_file, size)
> -
> -    ###################################
> -    # Tests for: extract_layers_in_qcow2()
> -    ###################################
> -    def test_utils_if_all_layers_extracted_in_order_in_qcow2(self):
> -        """
> -        Ensures that extract_layers_in_qcow2() iterates through all
> -        layers in order.
> -        """
> -        layers = ['l1', 'l2', 'l3']
> -        layers_list = [['', '', layer] for layer in layers]
> -        dest_dir = '/foo'
> -
> -        # Generate expected calls
> -        expected_calls = []
> -        qcow2_backing_file = None
> -        for index, layer in enumerate(layers):
> -            qcow2_layer_file = dest_dir + "/layer-%s.qcow2" % index
> -            expected_calls.append(
> -                mock.call(layer, qcow2_layer_file, qcow2_backing_file))
> -            qcow2_backing_file = qcow2_layer_file
> -
> -        # Mocking out and execute
> -        with mock.patch.multiple(utils,
> -                                 create_qcow2=mock.DEFAULT,
> -                                 log_layer_extract=mock.DEFAULT) as mocked:
> -            utils.extract_layers_in_qcow2(layers_list, dest_dir, mock.Mock())
> -
> -        # Check actual calls
> -        mocked['create_qcow2'].assert_has_calls(expected_calls)
> -
> -    ###################################
>      # Tests for: get_image_dir()
>      ###################################
>      def test_utils_getimage_dir(self):

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list




[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux