Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ExternalPluginSourceDownloader, refactor repo url lookup in PluginDistributionRepositoryProvider #181

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from osbenchmark.builder.downloaders.downloader import Downloader


class ExternalPluginSourceDownloader(Downloader):
def __init__(self, plugin_config_instance, executor, source_repository_provider, binary_builder, plugin_source_directory):
super().__init__(executor)
self.plugin_config_instance = plugin_config_instance
self.source_repository_provider = source_repository_provider
self.binary_builder = binary_builder
self.plugin_source_directory = plugin_source_directory

def download(self, host):
self._fetch(host)
self._prepare(host)

return {self.plugin_config_instance.name: self._get_zip_path()}

def _fetch(self, host):
plugin_remote_url = self.plugin_config_instance.variables["source"]["remote"]["repo"]["url"]
plugin_revision = self.plugin_config_instance.variables["source"]["revision"]
self.source_repository_provider.fetch_repository(host, plugin_remote_url, plugin_revision, self.plugin_source_directory)

def _prepare(self, host):
if self.binary_builder:
build_command = self.plugin_config_instance.variables["source"]["build"]["command"]
self.binary_builder.build(host, [build_command], override_source_directory=self.plugin_source_directory)

def _get_zip_path(self):
artifact_path = self.plugin_config_instance.variables["source"]["build"]["artifact"]["subdir"]
return f"file://{self.plugin_source_directory}/{artifact_path}/*.zip"
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def __init__(self, plugin, executor):
def get_download_url(self, host):
distribution_repository = self.plugin.variables["distribution"]["repository"]

default_key = f"plugin.{self.plugin.name}.{distribution_repository}.url"
default_key = f"distribution.{distribution_repository}.remote.repo.url"
return self.repository_url_provider.render_url_for_key(host, self.plugin.variables, default_key, mandatory=False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from unittest import TestCase, mock
from unittest.mock import Mock

from osbenchmark.builder.downloaders.external_plugin_source_downloader import ExternalPluginSourceDownloader
from osbenchmark.builder.provision_config import PluginDescriptor


class ExternalPluginSourceDownloaderTest(TestCase):
def setUp(self):
self.executor = Mock()
self.source_repo_provider = Mock()
self.binary_builder = Mock()

self.host = None
self.plugin_config_instance = PluginDescriptor(name="my-plugin", variables={
"source": {
"remote": {
"repo": {
"url": "https//fake.url.com"
}
},
"revision": "current",
"build": {
"command": "gradle build",
"artifact": {
"subdir": "plugin/subdir"
}
},
}
})
self.plugin_src_dir = "/fake/dir/for/plugin"

self.external_plugin_source_downloader = ExternalPluginSourceDownloader(self.plugin_config_instance, self.executor,
self.source_repo_provider, self.binary_builder,
self.plugin_src_dir)

def test_download_with_build(self):
plugin_binary = self.external_plugin_source_downloader.download(self.host)
self.assertEqual(plugin_binary, {"my-plugin": "file:///fake/dir/for/plugin/plugin/subdir/*.zip"})
self.source_repo_provider.fetch_repository.assert_has_calls([
mock.call(self.host, "https//fake.url.com", "current", self.plugin_src_dir)
])
self.binary_builder.build.assert_has_calls([
mock.call(self.host, ["gradle build"], override_source_directory=self.plugin_src_dir)
])

def test_download_without_build(self):
self.binary_builder = None

plugin_binary = self.external_plugin_source_downloader.download(self.host)
self.assertEqual(plugin_binary, {"my-plugin": "file:///fake/dir/for/plugin/plugin/subdir/*.zip"})
self.source_repo_provider.fetch_repository.assert_has_calls([
mock.call(self.host, "https//fake.url.com", "current", self.plugin_src_dir)
])
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def setUp(self):
def test_get_plugin_url(self):
self.plugin_distro_repo_provider.get_download_url(self.host)
self.plugin_distro_repo_provider.repository_url_provider.render_url_for_key.assert_has_calls([
mock.call(None, {"distribution": {"repository": "release"}}, "plugin.my-plugin.release.url", mandatory=False)
mock.call(None, {"distribution": {"repository": "release"}}, "distribution.release.remote.repo.url", mandatory=False)
])