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

[cli] Toggle Primary Instance (petenv) #2102

Merged
merged 97 commits into from
Aug 5, 2021
Merged

[cli] Toggle Primary Instance (petenv) #2102

merged 97 commits into from
Aug 5, 2021

Conversation

surahman
Copy link
Contributor

Issue #1138:
I have added support to handle the client.primary-name= command. I am not sure about the mock tests I have set up and they would require some review. When stepping through the tests with a debugger I was unable to hit breakpoints on set and set_aux within the utils/settings.cpp file - which is typically an indicator of an issue. Manual argument passing tests work on the cmdl.

@surahman surahman changed the title [utils] Set "client.primary_name=" [utils] Setting "client.primary_name=" May 12, 2021
Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Hi @surahman, thanks for the PR. I am afraid it doesn't cut it yet though.

The logic for disabling primary would need to go in the commands that deal with it (along with the "if" condition below).

tests/test_mock_settings.cpp Outdated Show resolved Hide resolved
src/utils/settings.cpp Outdated Show resolved Hide resolved
src/client/cli/cmd/set.cpp Outdated Show resolved Hide resolved
@surahman
Copy link
Contributor Author

surahman commented May 12, 2021

The logic for disabling primary would need to go in the commands that deal with it (along with the "if" condition below).

I will correct the issue with the error being thrown about the missing settings key parameter.
The positional arg client.primary-name= is to being handled with and without the instance name. Are you referring to handling further downstream once the command line param is parsed and clears checks?

@ricab
Copy link
Collaborator

ricab commented May 13, 2021

Hey @surahman, yeah I mean the places where the primary instance gets special treatment:

$ grep -r petenv_key src/client/ include/
src/client/gui/gui_cmd.cpp:    auto petenv_name = MP_SETTINGS.get(petenv_key).toStdString();
src/client/cli/cmd/restart.cpp:    const auto petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/stop.cpp:    const auto petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/suspend.cpp:    const auto petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/launch.cpp:    petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/shell.cpp:    petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/start.cpp:    petenv_name = MP_SETTINGS.get(petenv_key);
include/multipass/constants.h:constexpr auto petenv_key = "client.primary-name";     // This will eventually be moved to some dynamic settings schema
include/multipass/cli/format_utils.h:    const auto petenv_name = MP_SETTINGS.get(petenv_key).toStdString();

They would have to be modified to have the primary instance disabled. Otherwise this just sets the name to the empty string.

(Note that, for historic reasons, the code often uses the term petenv, short for "pet environment", to designate the primary instance.)

[tests] mock tests need to be double checked.
[utils] handling <"client.primary-name=">.
[utils] refactoring.
[tests] relocated mock tests to <settings> fixtures.
[tests] resetting file.
[utils] cleaning up code.
[utils] typo with empty string check.
[utils] reverting.
@surahman
Copy link
Contributor Author

surahman commented May 15, 2021

$ grep -r petenv_key src/client/ include/
src/client/gui/gui_cmd.cpp:    auto petenv_name = MP_SETTINGS.get(petenv_key).toStdString();
src/client/cli/cmd/restart.cpp:    const auto petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/stop.cpp:    const auto petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/suspend.cpp:    const auto petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/launch.cpp:    petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/shell.cpp:    petenv_name = MP_SETTINGS.get(petenv_key);
src/client/cli/cmd/start.cpp:    petenv_name = MP_SETTINGS.get(petenv_key);
include/multipass/constants.h:constexpr auto petenv_key = "client.primary-name";     // This will eventually be moved to some dynamic settings schema
include/multipass/cli/format_utils.h:    const auto petenv_name = MP_SETTINGS.get(petenv_key).toStdString();

@ricab thanks for the information. How would you like to have the primary is disabled situation dealt with? Is the correct of dealing with this to just return from the function with a success (potentially a silent error) or a failure (input command/request invalid) code?

For now, I have set a check for disabled primary instances and returned a CommandFailed status where applicable. I will add a check to ensure key is set to client.primary-name, but it currently only checks for name set to empty. petenv_key is a constant, as pointed out earlier.

@ricab
Copy link
Collaborator

ricab commented May 17, 2021

Hi @surahman, this is quite tricky. if the primary instance is disabled, multipass needs to disable any special treatment for it and error out in commands that need an instance but get none. So, if the user said for instance multipass start, without an instance name, multipass would indeed need to error out. Commands like start, stop, shell... would require at least one instance argument. Pretty much like a multipass delete would, but perhaps mentioning that the primary instance is disabled in the error message. The help messages would also need to be updated, where they mention primary today.

@ricab
Copy link
Collaborator

ricab commented May 17, 2021

BTW, I haven't looked at your new code yet. Please let me know when you feel it's ready for another review pass.

@codecov
Copy link

codecov bot commented May 20, 2021

Codecov Report

Merging #2102 (4cb066e) into main (2126b95) will increase coverage by 0.06%.
The diff coverage is 98.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2102      +/-   ##
==========================================
+ Coverage   82.91%   82.98%   +0.06%     
==========================================
  Files         186      186              
  Lines        9695     9730      +35     
==========================================
+ Hits         8039     8074      +35     
  Misses       1656     1656              
Impacted Files Coverage Δ
src/utils/settings.cpp 22.09% <0.00%> (ø)
src/client/cli/cmd/launch.cpp 78.22% <100.00%> (+0.08%) ⬆️
src/client/cli/cmd/restart.cpp 92.00% <100.00%> (+1.30%) ⬆️
src/client/cli/cmd/shell.cpp 84.41% <100.00%> (+1.55%) ⬆️
src/client/cli/cmd/start.cpp 97.56% <100.00%> (+0.19%) ⬆️
src/client/cli/cmd/stop.cpp 94.44% <100.00%> (+0.82%) ⬆️
src/client/cli/cmd/suspend.cpp 92.50% <100.00%> (+1.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2126b95...4cb066e. Read the comment docs.

@surahman
Copy link
Contributor Author

surahman commented May 20, 2021

@ricab I have gone ahead and updated the tests to include parameters. ATM start errors out if a command is passed without a parameter.

The other commands are also set to error out if the petenv is disabled. I gather that you would like a message to be sent to cerr and the command to return ok instead? Are there any example tests on how to capture the messages sent to the streams? Found it.

I will look through the help messages to locate instances of primary.

@ricab
Copy link
Collaborator

ricab commented May 20, 2021

Hmm, I don't quite follow, but primary is an instance that is automatically launched, started, stoped, etc. when you use the corresponding commands without arguments. And its name can change, so that after multipass set client.primary_name=heyo, multipass start # no args launches an instance named heyo, multipass stop would stop it, etc. BTW, have you seen https://multipass.run/docs/primary-instance ?

So, to disable it, stop, start, etc. should now error out, since they don't know what instance to work with. So that's what the tests should check, for instance:

    EXPECT_CALL(mock_settings, get(Eq(mp::petenv_key))).WillRepeatedly(Return(""));
    EXPECT_THAT(send_command({"start" /* no further args */ }), Eq(mp::ReturnCode::CommandFail));

while

    EXPECT_CALL(mock_settings, get(Eq(mp::petenv_key))).WillRepeatedly(Return("something"));
    EXPECT_THAT(send_command({"start" /* no further args */ }), Eq(mp::ReturnCode::CommandSuccess));

The launch command is different, because it expects an image name rather than an instance name. So multipass launch # no args is unrelated to primary.

BTW, the help messages are dynamically generated, so you should look for petenv_key rather than primary.

@surahman
Copy link
Contributor Author

surahman commented May 20, 2021

My adjustments to start seem to be up to spec, all the other tests for start are passing including start_cmd_considers_configured_petenv (Jarjar Binks is happy):

    const auto custom_petenv = "";
    EXPECT_CALL(mock_settings, get(Eq(mp::petenv_key))).WillRepeatedly(Return(custom_petenv));
    EXPECT_THAT(send_command({"start"}), Eq(mp::ReturnCode::CommandFail));

For the others, I will need to handle the disabled primary in the parse_args to check for additional passed parameter counts when necessary. Still drop an error message on cerr?

I will update the descriptions to include behavior for a disabled primary.

@surahman surahman requested a review from ricab May 20, 2021 19:12
@ricab
Copy link
Collaborator

ricab commented Aug 4, 2021

bors try

@bors
Copy link
Contributor

bors bot commented Aug 4, 2021

try

Already running a review

@Saviq
Copy link
Collaborator

Saviq commented Aug 4, 2021

bors try-

@Saviq
Copy link
Collaborator

Saviq commented Aug 4, 2021

bors try

bors bot added a commit that referenced this pull request Aug 4, 2021
@ricab ricab closed this Aug 4, 2021
@ricab ricab reopened this Aug 4, 2021
@ricab
Copy link
Collaborator

ricab commented Aug 4, 2021

bors cancel

@ricab
Copy link
Collaborator

ricab commented Aug 4, 2021

bors try-

@ricab
Copy link
Collaborator

ricab commented Aug 4, 2021

bors try

bors bot added a commit that referenced this pull request Aug 4, 2021
@ricab ricab closed this Aug 4, 2021
@ricab ricab reopened this Aug 4, 2021
@bors
Copy link
Contributor

bors bot commented Aug 4, 2021

try

Build failed:

@ricab
Copy link
Collaborator

ricab commented Aug 4, 2021

@surahman I believe you have dropped some test code when fixing the conflicts. I didn't want to force-push into your repo (probably couldn't anyway) so I have pushed a fixed merge in the branch primary-null-proposed.

You should be able to move this PR to it with the following steps:

  1. git checkout set_client.primary-name=null
  2. git fetch <canonicals_multipass_remote>
  3. git reset --hard <canonicals_multipass_remote>/primary-null-proposed
  4. git push --force (after confirming it's pointing at the new merge commit)

@surahman
Copy link
Contributor Author

surahman commented Aug 4, 2021

@ricab sorry about that, thanks for the fix 👍🏽.

@ricab
Copy link
Collaborator

ricab commented Aug 4, 2021

Alright, let's try again.

bors try

bors bot added a commit that referenced this pull request Aug 4, 2021
@bors
Copy link
Contributor

bors bot commented Aug 4, 2021

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Alright, let's merge this. Yeyyy 🥳 Thanks again for your effort getting this done @surahman

bors merge

bors bot added a commit that referenced this pull request Aug 4, 2021
2102: [cli] Toggle Primary Instance (petenv) r=ricab a=surahman

**_Issue #1138:_**
I have added support to handle the `client.primary-name=` command. I am not sure about the mock tests I have set up and they would require some review. When stepping through the tests with a debugger I was unable to hit breakpoints on `set` and `set_aux` within the `utils/settings.cpp` file - which is typically an indicator of an issue. Manual argument passing tests work on the `cmdl`.

Co-authored-by: Saad Ur Rahman <[email protected]>
@surahman
Copy link
Contributor Author

surahman commented Aug 4, 2021

@ricab you are most welcome! Thanks for all your patience, guidance, and assistance with this.

@bors
Copy link
Contributor

bors bot commented Aug 4, 2021

Build failed:

@ricab
Copy link
Collaborator

ricab commented Aug 4, 2021

bors retry

bors bot added a commit that referenced this pull request Aug 4, 2021
2102: [cli] Toggle Primary Instance (petenv) r=ricab a=surahman

**_Issue #1138:_**
I have added support to handle the `client.primary-name=` command. I am not sure about the mock tests I have set up and they would require some review. When stepping through the tests with a debugger I was unable to hit breakpoints on `set` and `set_aux` within the `utils/settings.cpp` file - which is typically an indicator of an issue. Manual argument passing tests work on the `cmdl`.

Co-authored-by: Saad Ur Rahman <[email protected]>
@bors
Copy link
Contributor

bors bot commented Aug 4, 2021

Build failed:

@ricab
Copy link
Collaborator

ricab commented Aug 5, 2021

bors retry

@bors
Copy link
Contributor

bors bot commented Aug 5, 2021

@bors bors bot merged commit a130207 into canonical:main Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow disabling primary instance handling
4 participants