Exemplo n.º 1
0
 def test_exit_if_no_output_path_provided_and_loading_is_disabled_too(self):
     squash = Squash(self.log,
                     'image',
                     self.docker_client,
                     load_image=False,
                     output_path=None)
     squash.run()
     self.log.warn.assert_called_with(
         "No output path specified and loading into Docker is not selected either; squashed image would not accessible, proceeding with squashing doesn't make sense"
     )
        def __enter__(self):
            from_layer = self.docker.history(
                self.image.tag)[self.number_of_layers]['Id']

            squash = Squash(
                self.log, self.image.tag, self.docker, tag=self.tag, from_layer=from_layer)
            squash.run()
            self.squashed_layer = self._squashed_layer()
            self.layers = [o['Id'] for o in self.docker.history(self.tag)]
            return self
        def __enter__(self):
            from_layer = self.number_of_layers

            if self.number_of_layers and not self.numeric:
                from_layer = self.docker.history(
                    self.image.tag)[self.number_of_layers]['Id']

            squash = Squash(
                self.log, self.image.tag, self.docker, tag=self.tag, from_layer=from_layer,
                output_path=self.output_path, load_image=self.load_image, tmp_dir=self.tmp_dir, development=self.development)

            self.image_id = squash.run()

            if not self.output_path:
                self.history = self.docker.history(self.tag)

                self.tar = self._save_image()

                with tarfile.open(fileobj=self.tar, mode='r') as tar:
                    self.tarnames = tar.getnames()

                self.squashed_layer = self._squashed_layer()
                self.layers = [o['Id'] for o in self.docker.history(self.tag)]
                self.metadata = self.docker.inspect_image(self.tag)

            return self
Exemplo n.º 4
0
        def __enter__(self):
            from_layer = self.docker.history(
                self.image.tag)[self.number_of_layers]['Id']

            squash = Squash(
                self.log, self.image.tag, self.docker, tag=self.tag, from_layer=from_layer, output_path=self.output_path)
            self.image_id = squash.run()

            if not self.output_path:
                self.squashed_layer = self._squashed_layer()
                self.layers = [o['Id'] for o in self.docker.history(self.tag)]
                self.metadata = self.docker.inspect_image(self.tag)

            return self
Exemplo n.º 5
0
        def __enter__(self):
            from_layer = self.docker.history(
                self.image.tag)[self.number_of_layers]['Id']

            squash = Squash(self.log,
                            self.image.tag,
                            self.docker,
                            tag=self.tag,
                            from_layer=from_layer,
                            output_path=self.output_path)
            self.image_id = squash.run()

            if not self.output_path:
                self.squashed_layer = self._squashed_layer()
                self.layers = [o['Id'] for o in self.docker.history(self.tag)]
                self.metadata = self.docker.inspect_image(self.tag)

            return self
Exemplo n.º 6
0
 def test_handle_case_when_no_image_is_provided(self):
     squash = Squash(self.log, None, self.docker_client)
     with self.assertRaises(SquashError) as cm:
         squash.run()
     self.assertEquals(str(cm.exception), "Image is not provided")
Exemplo n.º 7
0
 def test_exit_if_no_output_path_provided_and_loading_is_disabled_too(self):
     squash = Squash(self.log, 'image', self.docker_client, load_image=False, output_path=None)
     squash.run()
     self.log.warn.assert_called_with("No output path specified and loading into Docker is not selected either; squashed image would not accessible, proceeding with squashing doesn't make sense")
Exemplo n.º 8
0
 def test_handle_case_when_no_image_is_provided(self):
     squash = Squash(self.log, None, self.docker_client)
     with self.assertRaises(SquashError) as cm:
         squash.run()
     self.assertEquals(
         str(cm.exception), "Image is not provided")
Exemplo n.º 9
0
 def test_handle_case_when_no_image_is_provided(self):
     squash = Squash(self.log, None, self.docker_client)
     with self.assertRaises(SystemExit) as cm:
         squash.run()
     self.assertEqual(cm.exception.code, 1)
     self.log.error.assert_called_with("Image is not provided, exiting")