From 45c57dbab3e6a22efeff11296d723c93bdef5a6c Mon Sep 17 00:00:00 2001 From: Felix Satyaputra Date: Mon, 10 Apr 2017 10:41:24 +1000 Subject: [PATCH] Download sandbox image from Lightbend generic repo if Bintray credentials is not available --- conductr_cli/resolvers/bintray_resolver.py | 3 +- conductr_cli/sandbox_run_jvm.py | 12 +- conductr_cli/test/test_sandbox_run_jvm.py | 213 ++++++++++++++++++--- 3 files changed, 201 insertions(+), 27 deletions(-) diff --git a/conductr_cli/resolvers/bintray_resolver.py b/conductr_cli/resolvers/bintray_resolver.py index b6fc839..130ca1a 100644 --- a/conductr_cli/resolvers/bintray_resolver.py +++ b/conductr_cli/resolvers/bintray_resolver.py @@ -16,7 +16,8 @@ BINTRAY_CREDENTIAL_FILE_PATH = '{}/.lightbend/commercial.credentials'.format(os.path.expanduser('~')) BINTRAY_PROPERTIES_RE = re.compile('^(\S+)\s*=\s*([\S]+)$') BINTRAY_LIGHTBEND_ORG = 'lightbend' -BINTRAY_CONDUCTR_REPO = 'commercial-releases' +BINTRAY_CONDUCTR_COMMERCIAL_REPO = 'commercial-releases' +BINTRAY_CONDUCTR_GENERIC_REPO = 'generic' BINTRAY_CONDUCTR_CORE_PACKAGE_NAME = 'ConductR-Universal' BINTRAY_CONDUCTR_AGENT_PACKAGE_NAME = 'ConductR-Agent-Universal' diff --git a/conductr_cli/sandbox_run_jvm.py b/conductr_cli/sandbox_run_jvm.py index bdc3e6c..e1e382a 100644 --- a/conductr_cli/sandbox_run_jvm.py +++ b/conductr_cli/sandbox_run_jvm.py @@ -1,4 +1,4 @@ -from conductr_cli import conduct_main, host, license_validation, sandbox_stop, sandbox_common +from conductr_cli import conduct_main, host, license_validation, sandbox_stop, sandbox_common, sandbox_version from conductr_cli.constants import DEFAULT_SCHEME, DEFAULT_PORT, DEFAULT_BASE_PATH, DEFAULT_API_VERSION, \ DEFAULT_LICENSE_FILE, DEFAULT_SERVICE_LOCATOR_PORT, FEATURE_PROVIDE_PROXYING, DEFAULT_SANDBOX_IMAGE_DIR from conductr_cli.exceptions import BindAddressNotFound, BintrayUnreachableError, InstanceCountError, \ @@ -6,7 +6,8 @@ SandboxUnsupportedOsError, JavaCallError, JavaUnsupportedVendorError, JavaUnsupportedVersionError, \ JavaVersionParseError, HostnameLookupError, LicenseValidationError from conductr_cli.resolvers import bintray_resolver -from conductr_cli.resolvers.bintray_resolver import BINTRAY_LIGHTBEND_ORG, BINTRAY_CONDUCTR_REPO +from conductr_cli.resolvers.bintray_resolver import BINTRAY_LIGHTBEND_ORG, BINTRAY_CONDUCTR_COMMERCIAL_REPO, \ + BINTRAY_CONDUCTR_GENERIC_REPO from conductr_cli.sandbox_common import flatten from conductr_cli.sandbox_version import is_conductr_on_private_bintray from conductr_cli.screen_utils import h1, h2 @@ -473,6 +474,11 @@ def download_sandbox_image(image_dir, package_name, artefact_type, image_version try: bintray_auth = bintray_resolver.load_bintray_credentials(raise_error=False) + if sandbox_version.is_conductr_on_private_bintray(image_version): + bintray_repo = BINTRAY_CONDUCTR_COMMERCIAL_REPO + else: + bintray_repo = BINTRAY_CONDUCTR_COMMERCIAL_REPO if bintray_auth[0] else BINTRAY_CONDUCTR_GENERIC_REPO + if artefact_type == 'core': file_prefix = 'conductr-{}-{}'.format(image_version, artefact_os_name()) else: @@ -486,7 +492,7 @@ def is_matching_artefact(download_url): artefact for artefact in bintray_resolver.bintray_artefacts_by_version(bintray_auth, BINTRAY_LIGHTBEND_ORG, - BINTRAY_CONDUCTR_REPO, + bintray_repo, package_name, image_version) if is_matching_artefact(artefact['download_url']) diff --git a/conductr_cli/test/test_sandbox_run_jvm.py b/conductr_cli/test/test_sandbox_run_jvm.py index e5e2f89..df80b43 100644 --- a/conductr_cli/test/test_sandbox_run_jvm.py +++ b/conductr_cli/test/test_sandbox_run_jvm.py @@ -1738,22 +1738,22 @@ class TestDownloadSandboxImage(CliTestCase): image_dir = '~/.conductr/images' - image_version = '2.0.0-rc.2' + image_version = '2.1.0-alpha.1' core_package_name = 'ConductR-Universal' core_artefact_type = 'core' - core_artefact_file_name = 'conductr-2.0.0-rc.2-Mac_OS_X-x86_64.tgz' + core_artefact_file_name = 'conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz' core_artefact_mac_os = { 'package_name': 'ConductR-Universal', 'resolver': 'conductr_cli.resolvers.bintray_resolver', 'org': 'lightbend', 'repo': 'commercial-releases', - 'version': '2.0.0-rc.2', - 'path': 'conductr-2.0.0-rc.2-Mac_OS_X-x86_64.tgz', - 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-2.0.0-rc.2-Mac_OS_X-x86_64.tgz' + 'version': '2.1.0-alpha.1', + 'path': 'conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', + 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz' } core_artefact_linux = { @@ -1761,25 +1761,25 @@ class TestDownloadSandboxImage(CliTestCase): 'resolver': 'conductr_cli.resolvers.bintray_resolver', 'org': 'lightbend', 'repo': 'commercial-releases', - 'version': '2.0.0-rc.2', - 'path': 'conductr-2.0.0-rc.2-Linux-x86_64.tgz', - 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-2.0.0-rc.2-Linux-x86_64.tgz' + 'version': '2.1.0-alpha.1', + 'path': 'conductr-2.1.0-alpha.1-Linux-x86_64.tgz', + 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-2.1.0-alpha.1-Linux-x86_64.tgz' } agent_package_name = 'ConductR-Agent-Universal' agent_artefact_type = 'agent' - agent_artefact_file_name = 'conductr-agent-2.0.0-rc.2-Mac_OS_X-x86_64.tgz' + agent_artefact_file_name = 'conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz' agent_artefact_mac_os = { 'package_name': 'ConductR-Agent-Universal', 'resolver': 'conductr_cli.resolvers.bintray_resolver', 'org': 'lightbend', 'repo': 'commercial-releases', - 'version': '2.0.0-rc.2', - 'path': 'conductr-agent-2.0.0-rc.2-Mac_OS_X-x86_64.tgz', - 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-agent-2.0.0-rc.2-Mac_OS_X-x86_64.tgz' + 'version': '2.1.0-alpha.1', + 'path': 'conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', + 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz' } agent_artefact_linux = { @@ -1787,12 +1787,12 @@ class TestDownloadSandboxImage(CliTestCase): 'resolver': 'conductr_cli.resolvers.bintray_resolver', 'org': 'lightbend', 'repo': 'commercial-releases', - 'version': '2.0.0-rc.2', - 'path': 'conductr-agent-2.0.0-rc.2-Linux-x86_64.tgz', - 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-agent-2.0.0-rc.2-Linux-x86_64.tgz' + 'version': '2.1.0-alpha.1', + 'path': 'conductr-agent-2.1.0-alpha.1-Linux-x86_64.tgz', + 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-agent-2.1.0-alpha.1-Linux-x86_64.tgz' } - def test_download_core(self): + def test_download_core_from_commercial_releases(self): mock_artefact_os_name = MagicMock(return_value='Mac_OS_X') mock_load_bintray_credentials = MagicMock(return_value=self.bintray_auth) @@ -1800,8 +1800,8 @@ def test_download_core(self): mock_bintray_artefacts_by_version = MagicMock(return_value=artefacts) mock_bintray_download_artefact = MagicMock(return_value=(True, - 'conductr-2.0.0-rc.2-Mac_OS_X-x86_64.tgz', - '~/.conductr/images/conductr-2.0.0-rc.2-Mac_OS_X-x86_64.tgz')) + 'conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', + '~/.conductr/images/conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz')) with patch('conductr_cli.sandbox_run_jvm.artefact_os_name', mock_artefact_os_name), \ patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', @@ -1810,7 +1810,7 @@ def test_download_core(self): mock_bintray_artefacts_by_version), \ patch('conductr_cli.resolvers.bintray_resolver.bintray_download_artefact', mock_bintray_download_artefact): - self.assertEqual('~/.conductr/images/conductr-2.0.0-rc.2-Mac_OS_X-x86_64.tgz', + self.assertEqual('~/.conductr/images/conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', sandbox_run_jvm.download_sandbox_image(self.image_dir, self.core_package_name, self.core_artefact_type, @@ -1826,7 +1826,90 @@ def test_download_core(self): self.core_artefact_mac_os, self.bintray_auth) - def test_download_agent(self): + def test_download_core_from_generic(self): + mock_artefact_os_name = MagicMock(return_value='Mac_OS_X') + bintray_auth = (None, None, None) + mock_load_bintray_credentials = MagicMock(return_value=bintray_auth) + + artefacts = [self.core_artefact_mac_os, self.core_artefact_linux] + mock_bintray_artefacts_by_version = MagicMock(return_value=artefacts) + + mock_bintray_download_artefact = MagicMock(return_value=(True, + 'conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', + '~/.conductr/images/conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz')) + + with patch('conductr_cli.sandbox_run_jvm.artefact_os_name', mock_artefact_os_name), \ + patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', + mock_load_bintray_credentials), \ + patch('conductr_cli.resolvers.bintray_resolver.bintray_artefacts_by_version', + mock_bintray_artefacts_by_version), \ + patch('conductr_cli.resolvers.bintray_resolver.bintray_download_artefact', + mock_bintray_download_artefact): + self.assertEqual('~/.conductr/images/conductr-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', + sandbox_run_jvm.download_sandbox_image(self.image_dir, + self.core_package_name, + self.core_artefact_type, + self.image_version)) + + mock_load_bintray_credentials.assert_called_once_with(raise_error=False) + mock_bintray_artefacts_by_version.assert_called_once_with(bintray_auth, + 'lightbend', + 'generic', + self.core_package_name, + self.image_version) + mock_bintray_download_artefact.assert_called_once_with(self.image_dir, + self.core_artefact_mac_os, + bintray_auth) + + def test_download_core_older_version(self): + image_version = '2.0.5' + + mock_artefact_os_name = MagicMock(return_value='Mac_OS_X') + mock_load_bintray_credentials = MagicMock(return_value=self.bintray_auth) + + core_artefact_mac_os = self.core_artefact_mac_os.copy() + core_artefact_mac_os.update({ + 'version': '2.0.5', + 'path': 'conductr-2.0.5-Mac_OS_X-x86_64.tgz', + 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-2.0.5-Mac_OS_X-x86_64.tgz' + }) + core_artefact_linux = self.core_artefact_linux.copy() + core_artefact_linux.update({ + 'version': '2.0.5', + 'path': 'conductr-2.0.5-Linux-x86_64.tgz', + 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-2.0.5-Linux-x86_64.tgz' + }) + artefacts = [core_artefact_mac_os, core_artefact_linux] + mock_bintray_artefacts_by_version = MagicMock(return_value=artefacts) + + mock_bintray_download_artefact = MagicMock(return_value=(True, + 'conductr-2.0.5-Mac_OS_X-x86_64.tgz', + '~/.conductr/images/conductr-2.0.5-Mac_OS_X-x86_64.tgz')) + + with patch('conductr_cli.sandbox_run_jvm.artefact_os_name', mock_artefact_os_name), \ + patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', + mock_load_bintray_credentials), \ + patch('conductr_cli.resolvers.bintray_resolver.bintray_artefacts_by_version', + mock_bintray_artefacts_by_version), \ + patch('conductr_cli.resolvers.bintray_resolver.bintray_download_artefact', + mock_bintray_download_artefact): + self.assertEqual('~/.conductr/images/conductr-2.0.5-Mac_OS_X-x86_64.tgz', + sandbox_run_jvm.download_sandbox_image(self.image_dir, + self.core_package_name, + self.core_artefact_type, + image_version)) + + mock_load_bintray_credentials.assert_called_once_with(raise_error=False) + mock_bintray_artefacts_by_version.assert_called_once_with(self.bintray_auth, + 'lightbend', + 'commercial-releases', + self.core_package_name, + image_version) + mock_bintray_download_artefact.assert_called_once_with(self.image_dir, + core_artefact_mac_os, + self.bintray_auth) + + def test_download_agent_from_commercial_releases(self): mock_artefact_os_name = MagicMock(return_value='Mac_OS_X') mock_load_bintray_credentials = MagicMock(return_value=self.bintray_auth) @@ -1834,8 +1917,8 @@ def test_download_agent(self): mock_bintray_artefacts_by_version = MagicMock(return_value=artefacts) mock_bintray_download_artefact = MagicMock(return_value=(True, - 'conductr-agent-2.0.0-rc.2-Mac_OS_X-x86_64.tgz', - '~/.conductr/images/conductr-agent-2.0.0-rc.2-Mac_OS_X-x86_64.tgz')) + 'conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', + '~/.conductr/images/conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz')) with patch('conductr_cli.sandbox_run_jvm.artefact_os_name', mock_artefact_os_name), \ patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', @@ -1844,7 +1927,7 @@ def test_download_agent(self): mock_bintray_artefacts_by_version), \ patch('conductr_cli.resolvers.bintray_resolver.bintray_download_artefact', mock_bintray_download_artefact): - self.assertEqual('~/.conductr/images/conductr-agent-2.0.0-rc.2-Mac_OS_X-x86_64.tgz', + self.assertEqual('~/.conductr/images/conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', sandbox_run_jvm.download_sandbox_image(self.image_dir, self.agent_package_name, self.agent_artefact_type, @@ -1860,6 +1943,90 @@ def test_download_agent(self): self.agent_artefact_mac_os, self.bintray_auth) + def test_download_agent_from_generic(self): + mock_artefact_os_name = MagicMock(return_value='Mac_OS_X') + bintray_auth = (None, None, None) + mock_load_bintray_credentials = MagicMock(return_value=bintray_auth) + + artefacts = [self.agent_artefact_mac_os, self.agent_artefact_linux] + mock_bintray_artefacts_by_version = MagicMock(return_value=artefacts) + + mock_bintray_download_artefact = MagicMock(return_value=(True, + 'conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', + '~/.conductr/images/conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz')) + + with patch('conductr_cli.sandbox_run_jvm.artefact_os_name', mock_artefact_os_name), \ + patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', + mock_load_bintray_credentials), \ + patch('conductr_cli.resolvers.bintray_resolver.bintray_artefacts_by_version', + mock_bintray_artefacts_by_version), \ + patch('conductr_cli.resolvers.bintray_resolver.bintray_download_artefact', + mock_bintray_download_artefact): + self.assertEqual('~/.conductr/images/conductr-agent-2.1.0-alpha.1-Mac_OS_X-x86_64.tgz', + sandbox_run_jvm.download_sandbox_image(self.image_dir, + self.agent_package_name, + self.agent_artefact_type, + self.image_version)) + + mock_load_bintray_credentials.assert_called_once_with(raise_error=False) + mock_bintray_artefacts_by_version.assert_called_once_with(bintray_auth, + 'lightbend', + 'generic', + self.agent_package_name, + self.image_version) + mock_bintray_download_artefact.assert_called_once_with(self.image_dir, + self.agent_artefact_mac_os, + bintray_auth) + + def test_download_agent_older_version(self): + image_version = '2.0.5' + + mock_artefact_os_name = MagicMock(return_value='Mac_OS_X') + bintray_auth = (None, None, None) + mock_load_bintray_credentials = MagicMock(return_value=bintray_auth) + + agent_artefact_mac_os = self.agent_artefact_mac_os.copy() + agent_artefact_mac_os.update({ + 'version': '2.0.5', + 'path': 'conductr-agent-2.0.5-Mac_OS_X-x86_64.tgz', + 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-agent-2.0.5-Mac_OS_X-x86_64.tgz' + }) + agent_artefact_linux = self.agent_artefact_linux.copy() + agent_artefact_linux.update({ + 'version': '2.0.5', + 'path': 'conductr-agent-2.0.5-Linux-x86_64.tgz', + 'download_url': 'https://dl.bintray.com/lightbend/commercial-releases/conductr-agent-2.0.5-Linux-x86_64.tgz' + }) + artefacts = [agent_artefact_mac_os, agent_artefact_linux] + mock_bintray_artefacts_by_version = MagicMock(return_value=artefacts) + + mock_bintray_download_artefact = MagicMock(return_value=(True, + 'conductr-agent-2.0.5-Mac_OS_X-x86_64.tgz', + '~/.conductr/images/conductr-agent-2.0.5-Mac_OS_X-x86_64.tgz')) + + with patch('conductr_cli.sandbox_run_jvm.artefact_os_name', mock_artefact_os_name), \ + patch('conductr_cli.resolvers.bintray_resolver.load_bintray_credentials', + mock_load_bintray_credentials), \ + patch('conductr_cli.resolvers.bintray_resolver.bintray_artefacts_by_version', + mock_bintray_artefacts_by_version), \ + patch('conductr_cli.resolvers.bintray_resolver.bintray_download_artefact', + mock_bintray_download_artefact): + self.assertEqual('~/.conductr/images/conductr-agent-2.0.5-Mac_OS_X-x86_64.tgz', + sandbox_run_jvm.download_sandbox_image(self.image_dir, + self.agent_package_name, + self.agent_artefact_type, + image_version)) + + mock_load_bintray_credentials.assert_called_once_with(raise_error=False) + mock_bintray_artefacts_by_version.assert_called_once_with(bintray_auth, + 'lightbend', + 'commercial-releases', + self.agent_package_name, + image_version) + mock_bintray_download_artefact.assert_called_once_with(self.image_dir, + agent_artefact_mac_os, + bintray_auth) + def test_bintray_unreachable(self): mock_load_bintray_credentials = MagicMock(return_value=self.bintray_auth)