def test_helm_repository_update_when_cache_old(helm_repository_index): yesterday = datetime.utcnow() - timedelta(days=1) HelmRepository._updated_at = yesterday with patch("controlpanel.api.helm.Helm") as helm: HelmRepository.update(force=False) helm.execute.assert_called_once()
def test_helm_repository_get_chart_app_version(helm_repository_index, chart_name, version, expected_app_version): # See tests/api/fixtures/helm_mojanalytics_index.py with patch("controlpanel.api.helm.open", helm_repository_index): app_version = HelmRepository.get_chart_app_version(chart_name, version) assert app_version == expected_app_version
def get_installed_app_version(self, id_token): """ Returns the version of the deployed tool NOTE: This is the version coming from the helm chart `appVersion` field, **not** the version of the chart released in the user namespace. e.g. if user has `rstudio-2.2.5` (chart version) installed in his namespace, this would return "RStudio: 1.2.1335+conda, R: 3.5.1, Python: 3.7.1, patch: 10" **not** "2.2.5". Also bear in mind that Helm added this `appVersion` field only "recently" so if a user has an old version of a tool chart installed this would return `None` as we can't determine the tool version as this information is simply not available in the helm repository index. """ chart_version = self.get_installed_chart_version(id_token) if chart_version: return HelmRepository.get_chart_app_version( self.tool.chart_name, chart_version ) return None
def app_version(self): """ Returns the "appVersion" for this tool. This is metadata in the helm chart which we use to maintain details of the actual tool version (e.g. "RStudio: 1.2.1335+conda, R: 3.5.1, ...") as opposed to the chart version. Returns None if this information is not available for this tool and chart version (e.g. the chart was released before the `appVersion` was introduced) or because the chart doesn't exist in the helm reporitory. """ return HelmRepository.get_chart_app_version(self.chart_name, self.version)
def test_helm_repository_chart_info_when_chart_found(helm_repository_index): with patch("controlpanel.api.helm.open", helm_repository_index): # See tests/api/fixtures/helm_mojanalytics_index.py rstudio_info = HelmRepository.get_chart_info("rstudio") rstudio_2_2_5_app_version = "RStudio: 1.2.1335+conda, R: 3.5.1, Python: 3.7.1, patch: 10" assert len(rstudio_info) == 2 assert "2.2.5" in rstudio_info assert "1.0.0" in rstudio_info assert rstudio_info["2.2.5"].app_version == rstudio_2_2_5_app_version # Helm added `appVersion` field in metadata only # "recently" so for testing that for old chart # version this returns `None` assert rstudio_info["1.0.0"].app_version == None
def test_helm_repository_chart_info_when_chart_not_found( helm_repository_index): with patch("controlpanel.api.helm.open", helm_repository_index): info = HelmRepository.get_chart_info("notfound") assert info == {}
def test_helm_repository_update_when_recently_updated(helm_repository_index): HelmRepository._updated_at = datetime.utcnow() with patch("controlpanel.api.helm.Helm") as helm: HelmRepository.update(force=False) helm.execute.assert_not_called()