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

[#119] Change misleading message in das-cli faas update-version #121

Merged
merged 6 commits into from
Oct 7, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[#105] Add working directory option to jupyter-notebook start command. (PR: #120)
[#119] Correct misleading message in das-cli faas update-version to accurately reflect the latest version. (PR: #121)
59 changes: 39 additions & 20 deletions src/commands/faas/faas_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
from .openfaas_container_manager import OpenFaaSContainerManager


def get_function_version(settings: Settings) -> tuple:
function_name = settings.get("openfaas.function")
function_version = settings.get("openfaas.version")

return function_name, function_version


def pull_function_version(
image_manager: ImageManager,
repository: str,
Expand Down Expand Up @@ -70,7 +63,9 @@ def run(self):
openfaas_container_name = self._settings.get("openfaas.container_name")

try:
openfaas_container_service = OpenFaaSContainerManager(openfaas_container_name)
openfaas_container_service = OpenFaaSContainerManager(
openfaas_container_name
)
openfaas_container_service.stop()

self.stdout("OpenFaaS service stopped", severity=StdoutSeverity.SUCCESS)
Expand Down Expand Up @@ -174,7 +169,9 @@ def run(self):
[
{
"name": "MongoDB",
"container_manager": MongodbContainerManager(mongodb_container_name),
"container_manager": MongodbContainerManager(
mongodb_container_name
),
"port": mongodb_port,
},
{
Expand All @@ -187,7 +184,8 @@ def run(self):

self.stdout("Starting OpenFaaS...")

function, version = get_function_version(self._settings)
function = self._settings.get("openfaas.function")
version = self._settings.get("openfaas.version")

pull_function_version(
self._image_manager,
Expand Down Expand Up @@ -278,19 +276,29 @@ def __init__(
self._settings = settings
self._image_manager = image_manager

def run(self):
self._settings.raise_on_missing_file()

version = self._settings.get("openfaas.version", "latest")
def get_current_function_version(self) -> tuple:
self._settings.rewind() # Ensure we are getting the latest setting content
function = self._settings.get("openfaas.function", "query-engine")

label = self._image_manager.get_label(
image_tag = self._image_manager.get_label(
repository=OPENFAAS_IMAGE_NAME,
tag=self._image_manager.format_function_tag(function, version),
tag=self._image_manager.format_function_tag(
function,
version=self._settings.get("openfaas.version", "latest"),
),
label="fn.version",
)

self.stdout(f"{function} {label}", severity=StdoutSeverity.SUCCESS)
version = image_tag.split("-").pop()

return function, version

def run(self):
self._settings.raise_on_missing_file()

function, version = self.get_current_function_version()

self.stdout(f"{function} {version}", severity=StdoutSeverity.SUCCESS)


class FaaSUpdateVersion(Command):
Expand Down Expand Up @@ -341,15 +349,22 @@ class FaaSUpdateVersion(Command):
]

@inject
def __init__(self, settings: Settings, image_manager: ImageManager) -> None:
def __init__(
self,
settings: Settings,
image_manager: ImageManager,
faas_version: FaaSVersion,
) -> None:
super().__init__()
self._settings = settings
self._image_manager = image_manager
self._faas_version = faas_version

def _set_version(self, function: str, version: str) -> None:
self._settings.set("openfaas.version", version)
self._settings.set("openfaas.function", function)
self._settings.save()
self._settings.rewind()

def run(
self,
Expand All @@ -358,7 +373,9 @@ def run(
) -> None:
self._settings.raise_on_missing_file()

current_function_name, current_function_version = get_function_version(self._settings)
current_function_name, current_function_version = (
self._faas_version.get_current_function_version()
)

self.stdout(f"Downloading the {function} function, version {version}...")

Expand All @@ -371,7 +388,9 @@ def run(

self._set_version(function, version)

newer_function_name, newer_function_version = get_function_version(self._settings)
newer_function_name, newer_function_version = (
self._faas_version.get_current_function_version()
)

if (
current_function_name != newer_function_name
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_faas.bats
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,12 @@ Function version successfully updated $old_function $old_version --> $new_functi
@test "Update FaaS to the latest available version" {
local old_version="$(get_config .openfaas.version)"
local function="$(get_config .openfaas.function)"
local latest_version="$(get_latest_image_tag $openfaas_repository)"

run das-cli faas update-version

assert_output "Downloading the $function function, version latest...
Function version successfully updated $function $old_version --> $function latest. You need to call 'faas restart' to start using the new version."
Function version successfully updated $function $old_version --> $function $latest_version. You need to call 'faas restart' to start using the new version."

local image_version_digest="$(get_disgest_local_image "$openfaas_repository:query-engine-latest")"

Expand Down