Skip to content

Commit c670360

Browse files
authoredJul 31, 2024··
Create instances during login if not created (#4253)
Completes #2469.
1 parent 63c895e commit c670360

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed
 

‎src/molecule/command/login.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: AN
4545
"""Execute the actions necessary to perform a `molecule login` and returns None."""
4646
c = self._config
4747
if (not c.state.created) and c.driver.managed:
48-
msg = "Instances not created. Please create instances first."
49-
util.sysexit_with_message(msg)
48+
base.execute_subcommand(c, "create")
5049

5150
hosts = [d["name"] for d in self._config.platforms.instances]
5251
hostname = self._get_hostname(hosts) # type: ignore[no-untyped-call]

‎tests/unit/command/test_login.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ def test_login_execute(mocker: MockerFixture, _instance): # type: ignore[no-unt
4242
m.assert_called_once_with("instance-1")
4343

4444

45-
@pytest.mark.skip(reason="needs rewrite after switch to delegated")
4645
@pytest.mark.parametrize(
4746
"config_instance",
4847
["command_driver_delegated_managed_section_data"], # noqa: PT007
4948
indirect=True,
5049
)
51-
def test_execute_raises_when_not_created(caplog, _instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103
50+
def test_login_execute_instance_creation(mocker: MockerFixture, _instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103
51+
_instance._config.command_args = {"host": "instance-1"}
5252
_instance._config.state.change_state("created", False) # noqa: FBT003
5353

54-
with pytest.raises(SystemExit) as e:
55-
_instance.execute()
56-
57-
assert e.value.code == 1
54+
mocker.patch("molecule.command.login.Login._get_login")
55+
patched_execute_subcommand = mocker.patch("molecule.command.base.execute_subcommand")
56+
patched_execute_subcommand.side_effect = lambda _config, _: _config.state.change_state(
57+
key="created",
58+
value=True,
59+
)
60+
_instance.execute()
5861

59-
msg = "Instances not created. Please create instances first."
60-
assert msg in caplog.text
62+
patched_execute_subcommand.assert_called_once_with(_instance._config, "create")
63+
assert _instance._config.state.created
6164

6265

6366
def test_get_hostname_does_not_match(caplog, _instance): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, PT019, D103

0 commit comments

Comments
 (0)
Please sign in to comment.