def tool_deploy(self, message):
        """
        Deploy the named tool for the specified user
        Expects a message with `tool_name`, `version` and `user_id` values
        """

        tool, user = self.get_tool_and_user(message)
        id_token = message["id_token"]
        old_chart_name = message.get("old_chart_name", None)
        tool_deployment = ToolDeployment(tool, user, old_chart_name)

        update_tool_status(tool_deployment, id_token, TOOL_DEPLOYING)
        try:
            tool_deployment.save()
        except ToolDeployment.Error as err:
            update_tool_status(tool_deployment, id_token, TOOL_DEPLOY_FAILED)
            log.error(err)
            return

        status = wait_for_deployment(tool_deployment, id_token)

        if status == TOOL_DEPLOY_FAILED:
            log.warning(f"Failed deploying {tool.name} for {user}")
        else:
            log.debug(f"Deployed {tool.name} for {user}")
def test_deploy_for_generic(helm, token_hex, tool, users):
    cookie_secret_proxy = "cookie secret proxy"
    cookie_secret_tool = "cookie secret tool"
    token_hex.side_effect = [cookie_secret_proxy, cookie_secret_tool]
    user = users["normal_user"]

    # simulate release with old naming scheme installed
    old_release_name = f"{user.username}-{tool.chart_name}"
    helm.list_releases.return_value = [old_release_name]

    tool_deployment = ToolDeployment(tool, user)
    tool_deployment.save()

    # uninstall tool with old naming scheme
    helm.delete.assert_called_with(True, old_release_name)

    # install new release
    helm.upgrade_release.assert_called_with(
        f"{tool.chart_name}-{user.slug}",
        f"mojanalytics/{tool.chart_name}",
        "--version",
        tool.version,
        "--namespace",
        user.k8s_namespace,
        "--set",
        f"username={user.username}",
        "--set",
        f"Username={user.username}",
        "--set",
        f"aws.iamRole={user.iam_role_name}",
        "--set",
        f"toolsDomain={settings.TOOLS_DOMAIN}",
    )
コード例 #3
0
 def create(self, request):
     try:
         tool = Tool.objects.get(chart_name=request.data["name"])
     except Tool.DoesNotExist:
         return Response({}, status=status.HTTP_400_BAD_REQUEST)
     tool_deployment = ToolDeployment(tool, request.user)
     tool_deployment.save()
     return Response({}, status=status.HTTP_201_CREATED)