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

Hmusum/test uploading binary file #4153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
66 changes: 35 additions & 31 deletions tests/cloudconfig/deploy/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
require 'assertions'
require 'cloudconfig_test'
require 'json'
require 'application_v2_api'
Expand All @@ -8,7 +9,6 @@ class DeployV2 < CloudConfigTest

include ApplicationV2Api

# TODO: @@vespa_home needs to be changed when running the test manually
@@vespa_home = Environment.instance.vespa_home
@@config_server_config_file = "#{@@vespa_home}/conf/configserver-app/configserver-config.xml"

Expand All @@ -20,7 +20,6 @@ def setup
@httpport = 19071
@session_id = nil
@original_config_server_config = write_default_config_server_config
puts "original config server config: #{@original_config_server_config}"

appdir = "#{CLOUDCONFIG_DEPLOY_APPS}/base"
deploy(appdir, nil) # to initialize nodeproxies etc.
Expand All @@ -34,6 +33,21 @@ def setup
@region = "default"
@instance = "default"
@urischeme = https_client.scheme # TODO Inline as 'https' once TLS is enforced
@sessions_path = "#{@@vespa_home}/var/db/vespa/config_server/serverdb/tenants/#{@tenant_name}/sessions"
end

# TODO: Add to list in test below when working, want a separate test method while WIP
def test_binary_content
session_id = @session_id
file = "components/test.jar"
assert_put_application_file(session_id, "#{CLOUDCONFIG_DEPLOY_APPS}app_b/components/test.jar", file)

output = read_application_file(session_id, file)
file = File.open("#{CLOUDCONFIG_DEPLOY_APPS}/app_b/#{file}", "rb")
data = file.read
file.close
assert_equal(output, data, "not equal")
next_session(session_id)
end

def test_deploy_v2
Expand All @@ -44,8 +58,8 @@ def test_deploy_v2
@session_id = run_multiple_create_sessions(@session_id)
@session_id = run_multiple_prepare_sessions(@session_id)
@session_id = run_outdated_session_activation(@session_id)
@session_id = run_activate_without_prepare(@session_id, @tenant_name)
@session_id = run_serverdb_reuse_session_id(@session_id, @tenant_name)
@session_id = run_activate_without_prepare(@session_id)
@session_id = run_serverdb_reuse_session_id(@session_id)
@session_id = run_configserver_restart(@session_id)
@session_id = run_content_edit(@session_id)
@session_id = run_content_status(@session_id)
Expand Down Expand Up @@ -81,7 +95,7 @@ def run_invalid_app(session_id=@session_id)
end

def run_multiple_create_sessions(session_id=@session_id)
set_description("Tests creating multiple sessions in parallel and then preparing and activating one of them")
set_description("Tests creating multiple sessions, then preparing and activating one of them")
session_a = session_id
session_b = next_session(session_a)
result_a = create_session("#{CLOUDCONFIG_DEPLOY_APPS}/app_a", session_a)
Expand All @@ -95,7 +109,7 @@ def run_multiple_create_sessions(session_id=@session_id)
end

def run_multiple_prepare_sessions(session_id=@session_id)
set_description("Tests creating and preparing multiple sessions in parallel and then activate one of them")
set_description("Tests creating and preparing multiple sessions, then activating one of them")
session_a = session_id
session_b = next_session(session_a)
result_a = create_session("#{CLOUDCONFIG_DEPLOY_APPS}/app_a", session_a)
Expand All @@ -109,31 +123,28 @@ def run_multiple_prepare_sessions(session_id=@session_id)
next_session(session_b)
end

def run_activate_without_prepare(session_id=@session_id, tenant="default")
def run_activate_without_prepare(session_id=@session_id)
set_description("Tests activating a session that has not been prepared")
result = create_session("#{CLOUDCONFIG_DEPLOY_APPS}/app_b", session_id)
result["activate"] = url_base_activate(session_id) + "?timeout=5.0"
result = activate_session_fail(result, 400, /.*Session #{session_id} is not prepared/)
next_session(session_id)
end

# Check that
# #{Environment.instance.vespa_home}/var/db/vespa/config_server/serverdb/tenants/default/sessions/ is cleaned
# when creating a session with the same session id that was used once in the past
def run_serverdb_reuse_session_id(session_id=@session_id, tenant_name="default")
# Check that @sessions_path is cleaned when creating a session with the same session id that
# was used once in the past
def run_serverdb_reuse_session_id(session_id=@session_id)
# base app deployed in setup contains 'extra_file'
deploy_and_activate_session("#{CLOUDCONFIG_DEPLOY_APPS}/base", session_id, 19080)
assert_file_exists("#{@@vespa_home}/var/db/vespa/config_server/serverdb/tenants/#{tenant_name}/sessions/#{session_id}/extra_file")
assert_file_exists("#{@sessions_path}/#{session_id}/extra_file")
# Restart config server and delete zookeeper data so the next deploy
# also will have session id 2
restart_config_server(@node)
# Zookeeper will be cleaned, so next deploy will get session id 2
session_id = 2
if (tenant_name != "default")
create_tenant_and_wait(tenant_name, @node.hostname)
end
create_tenant_and_wait(@tenant_name, @node.hostname)
next_session_id = deploy_and_activate_session("#{CLOUDCONFIG_DEPLOY_APPS}/app_a", session_id, 1337)
assert_file_does_not_exist("#{@@vespa_home}/var/db/vespa/config_server/serverdb/tenants/#{tenant_name}/sessions/#{session_id}/extra_file")
assert_file_does_not_exist("#{@sessions_path}/#{session_id}/extra_file")
next_session_id
end

Expand Down Expand Up @@ -181,15 +192,12 @@ def run_content_edit(session_id=@session_id)
# Create a directory
result = create_application_dir(session_id, "files/")
assert_not_error(result)
# assert(!result.has_key?("error"))

# Put a file in the directory
assert_put_application_file(session_id, "#{CLOUDCONFIG_DEPLOY_APPS}/extra/test1.txt", "files/test1.txt")

# Check directory listing
result = list_application_dir(session_id, "files/")
# assert_not_error(result)
# assert(!result.has_key?("error"))
assert_equal(result.size, 1)
assert_equal(result[0], url_base_content(session_id) + "files/test1.txt")

Expand All @@ -198,10 +206,8 @@ def run_content_edit(session_id=@session_id)
assert(result.has_key?("message"))
result = delete_application_file(session_id, "files/test1.txt")
assert_not_error(result)
# assert(!result.has_key?("error"))
result = delete_application_file(session_id, "files/")
assert_not_error(result)
# assert(!result.has_key?("error"))

assert_active_application(create_result, services, session_id)
end
Expand Down Expand Up @@ -251,8 +257,8 @@ def run_content_status(session_id=@session_id)
assert_status(session_id, test_file, create_status_response("deleted", "", test_file))

# File that does not exist
assert_not_error(get_content_status(session_id, "non-existing-file"))

result = get_content_status(session_id, "non-existing-file")
assert_equal('BAD_REQUEST', result['error-code']) # TODO: Should be NOT_FOUND

prepare_result = prepare_session(create_result, session_id)
activate_result = activate_session(prepare_result, session_id)
Expand Down Expand Up @@ -292,7 +298,7 @@ def run_outdated_session_activation(session_id=@session_id)

# try to activate b, which should give a conflict (status code 409)
result = activate_session_fail(result_b, 409, /.*Cannot activate session #{session_b} because the currently active session \(#{session_c}\) has changed since session #{session_b} was created \(was #{session_a} at creation time\)/)
assert_logd_config_v2(1339, @hostname, tenant_name, @application_name)
assert_logd_config_v2(1339, @hostname, @tenant_name, @application_name)

# Deploying again should work
session_d = next_session(session_c)
Expand Down Expand Up @@ -345,7 +351,6 @@ def run_create_from_application_url(session_id=@session_id)
session_id = deploy_and_activate_session_v2("#{CLOUDCONFIG_DEPLOY_APPS}/app_a", session_id, 1337)
result = create_session_url(application_url(@node.hostname, @tenant_name, @application_name), session_id)
# so that we can prepare the new session with the same host as the previous one
# todo: change later to test with another host
delete_application_v2(@hostname, @tenant_name, @application_name)
result = prepare_session(result, session_id)
result = activate_session(result, session_id)
Expand Down Expand Up @@ -383,7 +388,7 @@ def run_old_sessions_are_deleted(session_id=@session_id)
wait_until_local_session_deleted(session_id_b)
assert_exists(session_id_c)

set_config_server_config({ })
set_config_server_config()
restart_config_server(@node, :keep_everything => true)
session_id
end
Expand Down Expand Up @@ -508,7 +513,7 @@ def list_application_dir(session_id, dirname, recursive = false)
end

def assert_not_error(json)
assert(json.instance_of? Hash)
assert(!json.has_key?('error-code'), json)
end

def assert_exists(session_id)
Expand All @@ -520,7 +525,7 @@ def assert_not_exists(session_id)
end

def local_session_exists(session_id)
exitcode, out = @node.execute("ls #{@@vespa_home}/var/db/vespa/config_server/serverdb/tenants/#{@tenant_name}/sessions/#{session_id}", { :exitcode => true, :noecho => true})
exitcode, out = @node.execute("ls #{@sessions_path}/#{session_id}", { :exitcode => true, :noecho => true})
exitcode == "0"
end

Expand Down Expand Up @@ -592,11 +597,11 @@ def assert_logd_config(expected_port)

def write_default_config_server_config
original_content = @node.readfile(@@config_server_config_file)
set_config_server_config({})
set_config_server_config()
original_content
end

def set_config_server_config(fields_and_values)
def set_config_server_config(fields_and_values = {})
default_for_this_test = {
"maintainerIntervalMinutes" => 1,
"canReturnEmptySentinelConfig" => true,
Expand Down Expand Up @@ -627,7 +632,6 @@ def assert_file_does_not_exist(file)
def teardown
stop
@node.stop_base if @node
puts "Stopping configserver"
@node.stop_configserver if @node
replace_config_server_config(@original_config_server_config)
@dirty_environment_settings = true
Expand Down