Skip to content

Commit 01830e7

Browse files
bors[bot]Chris Townsendricab
authored andcommitted
Merge #2171
2171: [daemon] Fix regression in Workflows-based launches r=ricab a=townsend2010 Fixes #2170 Co-authored-by: Chris Townsend <[email protected]> Co-authored-by: Ricardo Abreu <[email protected]>
1 parent 38dcd72 commit 01830e7

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/daemon/daemon.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,28 @@ std::vector<mp::NetworkInterface> validate_extra_interfaces(const mp::LaunchRequ
451451
return interfaces;
452452
}
453453

454-
auto validate_create_arguments(const mp::LaunchRequest* request, const mp::VirtualMachineFactory& factory)
454+
void validate_image(const mp::LaunchRequest* request, const mp::VMImageVault& vault,
455+
mp::VMWorkflowProvider& workflow_provider)
455456
{
457+
// TODO: Refactor this in such a way that we can use info returned here instead of ignoring it to avoid calls
458+
// later that accomplish the same thing.
459+
try
460+
{
461+
workflow_provider.info_for(request->image());
462+
}
463+
catch (const std::out_of_range&)
464+
{
465+
auto image_query = query_from(request, "");
466+
if (image_query.query_type == mp::Query::Type::Alias)
467+
vault.all_info_for(image_query);
468+
}
469+
}
470+
471+
auto validate_create_arguments(const mp::LaunchRequest* request, const mp::DaemonConfig* config)
472+
{
473+
assert(config && config->factory && config->workflow_provider && config->vault && "null ptr somewhere...");
474+
validate_image(request, *config->vault, *config->workflow_provider);
475+
456476
static const auto min_mem = try_mem_size(mp::min_memory_size);
457477
static const auto min_disk = try_mem_size(mp::min_disk_size);
458478
assert(min_mem && min_disk);
@@ -490,7 +510,7 @@ auto validate_create_arguments(const mp::LaunchRequest* request, const mp::Virtu
490510
option_errors.add_error_codes(mp::LaunchError::INVALID_HOSTNAME);
491511

492512
std::vector<std::string> nets_need_bridging;
493-
auto extra_interfaces = validate_extra_interfaces(request, factory, nets_need_bridging, option_errors);
513+
auto extra_interfaces = validate_extra_interfaces(request, *config->factory, nets_need_bridging, option_errors);
494514

495515
struct CheckedArguments
496516
{
@@ -2159,13 +2179,7 @@ std::string mp::Daemon::check_instance_exists(const std::string& instance_name)
21592179
void mp::Daemon::create_vm(const CreateRequest* request, grpc::ServerWriter<CreateReply>* server,
21602180
std::promise<grpc::Status>* status_promise, bool start)
21612181
{
2162-
// Try to get info for the requested image. This will throw out if the requested image is not found. This check
2163-
// needs to be done before the other checks.
2164-
auto image_query = query_from(request, "");
2165-
if (image_query.query_type == Query::Type::Alias)
2166-
config->vault->all_info_for(image_query);
2167-
2168-
auto checked_args = validate_create_arguments(request, *config->factory);
2182+
auto checked_args = validate_create_arguments(request, config.get());
21692183

21702184
if (!checked_args.option_errors.error_codes().empty())
21712185
{

tests/test_daemon.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,12 @@ TEST_F(Daemon, fails_with_image_not_found_also_if_image_is_also_non_bridgeable)
10991099
return default_vault.all_info_for(query);
11001100
});
11011101

1102+
auto mock_workflow_provider = std::make_unique<NiceMock<mpt::MockVMWorkflowProvider>>();
1103+
EXPECT_CALL(*mock_workflow_provider, info_for(_)).WillOnce(Throw(std::out_of_range("")));
1104+
11021105
config_builder.vault = std::move(mock_image_vault);
1106+
config_builder.workflow_provider = std::move(mock_workflow_provider);
1107+
11031108
mp::Daemon daemon{config_builder.build()};
11041109

11051110
std::stringstream err_stream;

0 commit comments

Comments
 (0)