예제 #1
0
 def test_plugin_config_with_default_url(self):
     renderer = supplier.TemplateRenderer(version="5.5.0")
     repo = supplier.DistributionRepository(name="release", distribution_config={
         "runtime.jdk.bundled": "false",
         "plugin_example_release_url": "https://artifacts.example.org/downloads/plugins/example-{{VERSION}}.zip"
     }, template_renderer=renderer)
     self.assertEqual("https://artifacts.example.org/downloads/plugins/example-5.5.0.zip", repo.plugin_download_url("example"))
예제 #2
0
    def test_does_not_cache_when_no_revision(self, es, copy, ensure_dir):
        def add_es_artifact(binaries):
            binaries["elasticsearch"] = "/path/to/artifact.tar.gz"

        es.fetch.return_value = None
        es.add.side_effect = add_es_artifact

        renderer = supplier.TemplateRenderer(version=None,
                                             os_name="linux",
                                             arch="x86_64")

        cached_supplier = supplier.CachedSourceSupplier(
            distributions_root="/tmp",
            source_supplier=es,
            file_resolver=supplier.ElasticsearchFileNameResolver(
                distribution_config={}, template_renderer=renderer))

        cached_supplier.fetch()
        cached_supplier.prepare()

        binaries = {}

        cached_supplier.add(binaries)

        self.assertEqual(0, copy.call_count)
        self.assertFalse(cached_supplier.cached)
        self.assertIn("elasticsearch", binaries)
예제 #3
0
    def test_uses_already_cached_artifact(self, es, path_exists):
        # assume that the artifact is already cached
        path_exists.return_value = True
        renderer = supplier.TemplateRenderer(version="abc123",
                                             os_name="linux",
                                             arch="x86_64")

        dist_cfg = {
            "runtime.jdk.bundled":
            "true",
            "jdk.bundled.release_url":
            "https://elstc.co/elasticsearch-{{VERSION}}-{{OSNAME}}-{{ARCH}}.tar.gz"
        }
        file_resolver = supplier.ElasticsearchFileNameResolver(
            distribution_config=dist_cfg, template_renderer=renderer)
        cached_supplier = supplier.CachedSourceSupplier(
            distributions_root="/tmp",
            source_supplier=es,
            file_resolver=file_resolver)

        cached_supplier.fetch()
        cached_supplier.prepare()

        binaries = {}

        cached_supplier.add(binaries)

        self.assertEqual(0, es.fetch.call_count)
        self.assertEqual(0, es.prepare.call_count)
        self.assertEqual(0, es.add.call_count)
        self.assertTrue(cached_supplier.cached)
        self.assertIn("elasticsearch", binaries)
        self.assertEqual("/tmp/elasticsearch-abc123-linux-x86_64.tar.gz",
                         binaries["elasticsearch"])
예제 #4
0
 def test_uses_provided_values(self):
     renderer = supplier.TemplateRenderer(version="1.2.3",
                                          os_name="Windows",
                                          arch="arm7")
     assert (renderer.render(
         "This is version {{VERSION}} on {{OSNAME}} with a {{ARCH}} CPU.")
             == "This is version 1.2.3 on Windows with a arm7 CPU.")
예제 #5
0
    def test_does_not_cache_when_no_revision(self, es, copy, ensure_dir):
        def add_es_artifact(binaries):
            binaries["elasticsearch"] = "/path/to/artifact.tar.gz"

        es.fetch.return_value = None
        es.add.side_effect = add_es_artifact

        # no version / revision provided
        renderer = supplier.TemplateRenderer(version=None,
                                             os_name="linux",
                                             arch="x86_64")

        dist_cfg = {
            "runtime.jdk.bundled":
            "true",
            "jdk.bundled.release_url":
            "https://elstc.co/elasticsearch-{{VERSION}}-{{OSNAME}}-{{ARCH}}.tar.gz",
        }
        file_resolver = supplier.ElasticsearchFileNameResolver(
            distribution_config=dist_cfg, template_renderer=renderer)
        cached_supplier = supplier.CachedSourceSupplier(
            distributions_root="/tmp",
            source_supplier=es,
            file_resolver=file_resolver)

        cached_supplier.fetch()
        cached_supplier.prepare()

        binaries = {}

        cached_supplier.add(binaries)

        assert copy.call_count == 0
        assert not cached_supplier.cached
        assert binaries["elasticsearch"] == "/path/to/artifact.tar.gz"
예제 #6
0
    def test_raises_error_on_missing_car_variable(self):
        car = team.Car(
            "default",
            root_path=None,
            config_paths=[],
            variables={
                "clean_command": "./gradlew clean",
                # system.build_command is not defined
            },
        )
        renderer = supplier.TemplateRenderer(version="abc")
        builder = mock.create_autospec(supplier.Builder)
        es = supplier.ElasticsearchSourceSupplier(revision="abc",
                                                  es_src_dir="/src",
                                                  remote_url="",
                                                  car=car,
                                                  builder=builder,
                                                  template_renderer=renderer)
        with pytest.raises(
                exceptions.SystemSetupError,
                match='Car "default" requires config key "system.build_command"'
        ):
            es.prepare()

        assert builder.build.call_count == 0
예제 #7
0
 def test_uses_derived_values(self, os_name, cpu_arch):
     renderer = supplier.TemplateRenderer(version="1.2.3")
     self.assertEqual(
         "This is version 1.2.3 on linux with a x86_64 CPU.",
         renderer.render(
             "This is version {{VERSION}} on {{OSNAME}} with a {{ARCH}} CPU."
         ))
예제 #8
0
 def test_missing_plugin_config(self):
     renderer = supplier.TemplateRenderer(version="5.5.0")
     repo = supplier.DistributionRepository(name="release",
                                            distribution_config={
                                                "runtime.jdk.bundled":
                                                "false",
                                            },
                                            template_renderer=renderer)
     self.assertIsNone(repo.plugin_download_url("not existing"))
예제 #9
0
 def test_resolve_plugin_url(self):
     v = {"plugin_custom-analyzer_release_url": "http://example.org/elasticearch/custom-analyzer-{{VERSION}}.zip"}
     renderer = supplier.TemplateRenderer(version="6.3.0")
     s = supplier.PluginDistributionSupplier(repo=supplier.DistributionRepository(name="release",
                                                                                  distribution_config=v,
                                                                                  template_renderer=renderer),
                                             plugin=team.PluginDescriptor("custom-analyzer"))
     binaries = {}
     s.add(binaries)
     self.assertDictEqual(binaries, {"custom-analyzer": "http://example.org/elasticearch/custom-analyzer-6.3.0.zip"})
예제 #10
0
 def test_missing_cache(self):
     renderer = supplier.TemplateRenderer(version="2.4.3")
     repo = supplier.DistributionRepository(name="release", distribution_config={
         "jdk.unbundled.release.url": "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{VERSION}}.tar.gz",
         "runtime.jdk.bundled": "false"
     }, template_renderer=renderer)
     with self.assertRaises(exceptions.SystemSetupError) as ctx:
         # noinspection PyStatementEffect
         repo.cache
     self.assertEqual("Mandatory config key [release.cache] is undefined.", ctx.exception.args[0])
예제 #11
0
 def test_release_repo_config_with_default_url(self, os_name, cpu_arch):
     renderer = supplier.TemplateRenderer(version="7.3.2")
     repo = supplier.DistributionRepository(name="release", distribution_config={
         "runtime.jdk.bundled": "true",
         "jdk.bundled.release_url": "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{VERSION}}-{{OSNAME}}-{{ARCH}}.tar.gz",
         "release.cache": "true"
     }, template_renderer=renderer)
     self.assertEqual("https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz", repo.download_url)
     self.assertEqual("elasticsearch-7.3.2-linux-x86_64.tar.gz", repo.file_name)
     self.assertTrue(repo.cache)
예제 #12
0
 def test_invalid_cache_value(self):
     renderer = supplier.TemplateRenderer(version="2.4.3")
     repo = supplier.DistributionRepository(name="release", distribution_config={
         "jdk.unbundled.release.url": "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{VERSION}}.tar.gz",
         "runtime.jdk.bundled": "false",
         "release.cache": "Invalid"
     }, template_renderer=renderer)
     with self.assertRaises(exceptions.SystemSetupError) as ctx:
         # pylint: disable=pointless-statement
         # noinspection PyStatementEffect
         repo.cache
     self.assertEqual("Value [Invalid] for config key [release.cache] is not a valid boolean value.", ctx.exception.args[0])
예제 #13
0
 def test_release_repo_config_with_user_url(self):
     renderer = supplier.TemplateRenderer(version="2.4.3")
     repo = supplier.DistributionRepository(name="release", distribution_config={
         "jdk.unbundled.release_url": "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{VERSION}}.tar.gz",
         "runtime.jdk.bundled": "false",
         # user override
         "release.url": "https://es-mirror.example.org/downloads/elasticsearch/elasticsearch-{{VERSION}}.tar.gz",
         "release.cache": "false"
     }, template_renderer=renderer)
     self.assertEqual("https://es-mirror.example.org/downloads/elasticsearch/elasticsearch-2.4.3.tar.gz", repo.download_url)
     self.assertEqual("elasticsearch-2.4.3.tar.gz", repo.file_name)
     self.assertFalse(repo.cache)
예제 #14
0
    def test_caches_artifact(self, es, copy, path_exists, ensure_dir):
        def add_es_artifact(binaries):
            binaries["elasticsearch"] = "/path/to/artifact.tar.gz"

        path_exists.return_value = False

        es.fetch.return_value = "abc123"
        es.add.side_effect = add_es_artifact

        renderer = supplier.TemplateRenderer(version="abc123",
                                             os_name="linux",
                                             arch="x86_64")

        dist_cfg = {
            "runtime.jdk.bundled":
            "true",
            "jdk.bundled.release_url":
            "https://elstc.co/elasticsearch-{{VERSION}}-{{OSNAME}}-{{ARCH}}.tar.gz"
        }

        cached_supplier = supplier.CachedSourceSupplier(
            distributions_root="/tmp",
            source_supplier=es,
            file_resolver=supplier.ElasticsearchFileNameResolver(
                distribution_config=dist_cfg, template_renderer=renderer))
        cached_supplier.fetch()
        cached_supplier.prepare()

        binaries = {}

        cached_supplier.add(binaries)
        # path is cached now
        path_exists.return_value = True

        self.assertEqual(1, copy.call_count, "artifact has been copied")
        self.assertEqual(1, es.add.call_count,
                         "artifact has been added by internal supplier")
        self.assertTrue(cached_supplier.cached)
        self.assertIn("elasticsearch", binaries)

        # simulate a second attempt
        cached_supplier.fetch()
        cached_supplier.prepare()

        binaries = {}
        cached_supplier.add(binaries)

        self.assertEqual(1, copy.call_count,
                         "artifact has not been copied twice")
        # the internal supplier did not get called again as we reuse the cached artifact
        self.assertEqual(1, es.add.call_count,
                         "internal supplier is not called again")
        self.assertTrue(cached_supplier.cached)
예제 #15
0
 def test_missing_url(self):
     renderer = supplier.TemplateRenderer(version="2.4.3")
     repo = supplier.DistributionRepository(name="miss", distribution_config={
         "jdk.unbundled.release_url": "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{VERSION}}.tar.gz",
         "runtime.jdk.bundled": "false",
         "release.cache": "true"
     }, template_renderer=renderer)
     with self.assertRaises(exceptions.SystemSetupError) as ctx:
         # pylint: disable=pointless-statement
         # noinspection PyStatementEffect
         repo.download_url
     self.assertEqual("Neither config key [miss.url] nor [jdk.unbundled.miss_url] is defined.", ctx.exception.args[0])
예제 #16
0
 def test_no_build(self):
     car = team.Car("default", root_path=None, config_paths=[], variables={
         "clean_command": "./gradlew clean",
         "system.build_command": "./gradlew assemble"
     })
     renderer = supplier.TemplateRenderer(version=None)
     es = supplier.ElasticsearchSourceSupplier(revision="abc",
                                               es_src_dir="/src",
                                               remote_url="",
                                               car=car,
                                               builder=None,
                                               template_renderer=renderer)
     es.prepare()
예제 #17
0
    def setUp(self):
        super().setUp()
        renderer = supplier.TemplateRenderer(version="8.0.0-SNAPSHOT", os_name="linux", arch="x86_64")

        dist_cfg = {
            "runtime.jdk.bundled": "true",
            "jdk.bundled.release_url": "https://elstc.co/elasticsearch-{{VERSION}}-{{OSNAME}}-{{ARCH}}.tar.gz"
        }

        self.resolver = supplier.ElasticsearchFileNameResolver(
            distribution_config=dist_cfg,
            template_renderer=renderer
        )
예제 #18
0
    def test_build(self):
        car = team.Car("default", root_path=None, config_paths=[], variables={
            "clean_command": "./gradlew clean",
            "system.build_command": "./gradlew assemble"
        })
        builder = mock.create_autospec(supplier.Builder)
        renderer = supplier.TemplateRenderer(version="abc")
        es = supplier.ElasticsearchSourceSupplier(revision="abc",
                                                  es_src_dir="/src",
                                                  remote_url="",
                                                  car=car,
                                                  builder=builder,
                                                  template_renderer=renderer)
        es.prepare()

        builder.build.assert_called_once_with(["./gradlew clean", "./gradlew assemble"])
예제 #19
0
 def test_add_elasticsearch_binary(self):
     car = team.Car("default", root_path=None, config_paths=[], variables={
         "clean_command": "./gradlew clean",
         "system.build_command": "./gradlew assemble",
         "system.artifact_path_pattern": "distribution/archives/tar/build/distributions/*.tar.gz"
     })
     renderer = supplier.TemplateRenderer(version="abc")
     es = supplier.ElasticsearchSourceSupplier(revision="abc",
                                               es_src_dir="/src",
                                               remote_url="",
                                               car=car,
                                               builder=None,
                                               template_renderer=renderer)
     binaries = {}
     es.add(binaries=binaries)
     self.assertEqual(binaries, {"elasticsearch": "elasticsearch.tar.gz"})
예제 #20
0
 def test_missing_cache(self):
     renderer = supplier.TemplateRenderer(version="2.4.3")
     repo = supplier.DistributionRepository(
         name="release",
         distribution_config={
             "jdk.unbundled.release.url":
             "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-{{VERSION}}.tar.gz",
             "runtime.jdk.bundled": "false",
         },
         template_renderer=renderer,
     )
     with pytest.raises(exceptions.SystemSetupError) as exc:
         # pylint: disable=pointless-statement
         # noinspection PyStatementEffect
         repo.cache
     assert exc.value.args[
         0] == "Mandatory config key [release.cache] is undefined."
예제 #21
0
 def test_plugin_config_with_user_url(self):
     renderer = supplier.TemplateRenderer(version="5.5.0")
     repo = supplier.DistributionRepository(
         name="release",
         distribution_config={
             "runtime.jdk.bundled":
             "false",
             "plugin_example_release_url":
             "https://artifacts.example.org/downloads/plugins/example-{{VERSION}}.zip",
             # user override
             "plugin.example.release.url":
             "https://mirror.example.org/downloads/plugins/example-{{VERSION}}.zip",
         },
         template_renderer=renderer,
     )
     assert repo.plugin_download_url(
         "example"
     ) == "https://mirror.example.org/downloads/plugins/example-5.5.0.zip"
예제 #22
0
    def test_does_not_cache_on_copy_error(self, es, copy, path_exists,
                                          ensure_dir):
        def add_es_artifact(binaries):
            binaries["elasticsearch"] = "/path/to/artifact.tar.gz"

        path_exists.return_value = False

        es.fetch.return_value = "abc123"
        es.add.side_effect = add_es_artifact
        copy.side_effect = OSError("no space left on device")

        renderer = supplier.TemplateRenderer(version="abc123",
                                             os_name="linux",
                                             arch="x86_64")

        dist_cfg = {
            "runtime.jdk.bundled":
            "true",
            "jdk.bundled.release_url":
            "https://elstc.co/elasticsearch-{{VERSION}}-{{OSNAME}}-{{ARCH}}.tar.gz"
        }

        cached_supplier = supplier.CachedSourceSupplier(
            distributions_root="/tmp",
            source_supplier=es,
            file_resolver=supplier.ElasticsearchFileNameResolver(
                distribution_config=dist_cfg, template_renderer=renderer))
        cached_supplier.fetch()
        cached_supplier.prepare()

        binaries = {}

        cached_supplier.add(binaries)

        self.assertEqual(1, copy.call_count, "artifact has been copied")
        self.assertEqual(1, es.add.call_count,
                         "artifact has been added by internal supplier")
        self.assertFalse(cached_supplier.cached)
        self.assertIn("elasticsearch", binaries)
        # still the uncached artifact
        self.assertEqual("/path/to/artifact.tar.gz", binaries["elasticsearch"])
예제 #23
0
 def test_converts_arm_architecture(self, os_name, cpu_arch):
     renderer = supplier.TemplateRenderer(version="7.16.0")
     assert (renderer.render(
         "This is version {{VERSION}} on {{OSNAME}} with a {{ARCH}} CPU.")
             == "This is version 7.16.0 on darwin with a aarch64 CPU.")