Skip to content

Commit

Permalink
Merge #1491
Browse files Browse the repository at this point in the history
1491: Added check for cloud-init file existence r=Saviq a=ianbtr

This should help with #1486.

Co-authored-by: Ian Alexander Bertram <[email protected]>
Co-authored-by: Ian Bertram <[email protected]>
Co-authored-by: Michał Sawicz <[email protected]>
  • Loading branch information
3 people authored Apr 17, 2020
2 parents f68e4d0 + f9b5bde commit c80b31f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/client/cli/cmd/launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <yaml-cpp/yaml.h>

#include <QDir>
#include <QFileInfo>
#include <QTimeZone>

#include <regex>
Expand Down Expand Up @@ -200,6 +201,14 @@ mp::ParseCode cmd::Launch::parse_args(mp::ArgParser* parser)
}
else
{
QFileInfo check_file(cloudInitFile);

if (!check_file.exists() || !check_file.isFile())
{
cerr << "error: No such file: " << cloudInitFile.toStdString() << "\n";
return ParseCode::CommandLineError;
}

node = YAML::LoadFile(cloudInitFile.toStdString());
}
request.set_cloud_init_user_data(YAML::Dump(node));
Expand Down
7 changes: 6 additions & 1 deletion tests/test_cli_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,13 @@ TEST_F(Client, launch_cmd_cloudinit_option_with_valid_file_is_ok)

TEST_F(Client, launch_cmd_cloudinit_option_fails_with_missing_file)
{
EXPECT_THAT(send_command({"launch", "--cloud-init", "/definitely/missing-file"}),
std::stringstream cerr_stream;
auto missing_file{"/definitely/missing-file"};

EXPECT_THAT(send_command({"launch", "--cloud-init", missing_file}, trash_stream, cerr_stream),
Eq(mp::ReturnCode::CommandLineError));
EXPECT_NE(std::string::npos, cerr_stream.str().find("No such file")) << "cerr has: " << cerr_stream.str();
EXPECT_NE(std::string::npos, cerr_stream.str().find(missing_file)) << "cerr has: " << cerr_stream.str();
}

TEST_F(Client, launch_cmd_cloudinit_option_fails_no_value)
Expand Down

2 comments on commit c80b31f

@multipass-ci-bot

This comment was marked as outdated.

@Saviq
Copy link
Collaborator

@Saviq Saviq commented on c80b31f Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS build available: multipass-1.2.1+mac-Darwin.pkg
Windows build available: multipass-1.2.1+win-win64.exe

Please sign in to comment.