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

Enforce single release install in progress #34

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 13 additions & 14 deletions lib/peridiod/release/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,12 @@ defmodule Peridiod.Release.Server do
def handle_call(
{:install_release, %Release{} = release_metadata},
{from, _ref},
%{installing_release: nil} = state
state
) do
{reply, state} = do_install_release(release_metadata, from, state)
{:reply, reply, state}
end

def handle_call({:install_release, %Release{}}, _from, state) do
{:reply, {:error, {:installing_release, state.installing_release}}, state}
end

def handle_call(
{:cache_binary, %Binary{prn: prn}},
_from,
Expand Down Expand Up @@ -441,18 +437,17 @@ defmodule Peridiod.Release.Server do
MapSet.new(keys)
end

defp do_install_release(release_metadata, callback, state) do
defp do_install_release(release_metadata, callback, %{installing_release: nil} = state) do
binaries_metadata =
release_metadata
|> Release.filter_binaries_by_targets(state.targets)
|> Enum.reject(&Binary.kv_installed?(state.kv_pid, &1, :current))
|> Enum.reject(&Binary.installed?(state.cache_pid, &1))

trusted? = binaries_trusted?(binaries_metadata, state)
installed? = Release.installed?(state.cache_pid, release_metadata)

case {trusted?, installed?} do
{true, false} ->
case trusted? do
true ->
Logger.debug("Install Release: ok")
Release.kv_progress(state.kv_pid, release_metadata)

Expand All @@ -468,16 +463,20 @@ defmodule Peridiod.Release.Server do
{:ok, state}
end

{false, _} ->
false ->
Logger.debug("Install Release: untrusted signatures")
{{:error, :untrusted_signatures}, state}

{_, true} ->
Logger.debug("Install Release: already installed")
{{:error, :already_installed}, state}
end
end

defp do_install_release(
release_metadata,
_callback,
%{installing_release: {release_metadata, _, _}} = state
) do
{{:error, {:installing_release, release_metadata}}, state}
end

defp do_cache_release(release_metadata, callback, state) do
binaries_metadata =
release_metadata
Expand Down
15 changes: 0 additions & 15 deletions test/peridiod/release/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,6 @@ defmodule Peridiod.Release.ServerTest do
assert {:error, :already_cached} =
Release.Server.cache_release(release_server_pid, release_metadata)
end

test "already installed", %{
cache_pid: cache_pid,
release_server_pid: release_server_pid,
release_metadata: %Release{binaries: binaries} = release_metadata
} do
binary_metadata = List.first(binaries)
:ok = Binary.metadata_to_cache(cache_pid, binary_metadata)
signing_key = List.first(binary_metadata.signatures).signing_key
{:ok, _signatures} = Release.Server.add_trusted_signing_key(release_server_pid, signing_key)
assert :ok = Release.stamp_installed(cache_pid, release_metadata)

assert {:error, :already_installed} =
Release.Server.install_release(release_server_pid, release_metadata)
end
end

describe "binary install cache" do
Expand Down