Skip to content

Commit

Permalink
Enable creating VM without user password if using SSH keys
Browse files Browse the repository at this point in the history
Fixes #1314
  • Loading branch information
yunmingyang authored Dec 6, 2023
1 parent 041cf97 commit 2102e41
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/create-vm-dialog/createVmDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function validateParams(vmParams) {
);
}

if (!vmParams.userPassword && vmParams.userLogin) {
if (vmParams.userLogin && !((!!vmParams.userPassword) || vmParams.sshKeys.length > 0)) {
validationFailed.userPassword = _("User password must not be empty when user login is set");
}
if (vmParams.userPassword && !vmParams.userLogin) {
Expand Down
34 changes: 32 additions & 2 deletions test/check-machines-create
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ class TestMachinesCreate(VirtualMachinesCase):
create_and_run=True),
{"create-vm-dialog-user-login": "User login must not be empty when SSH keys are set"})

# Without the root password and "Create and edit"
runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
location=config.VALID_DISK_IMAGE_PATH,
user_login="",
ssh_keys=[rsakey]),
{"create-vm-dialog-user-login": "User login must not be empty when SSH keys are set"})

def testCreateNameGeneration(self):
config = TestMachinesCreate.TestCreateConfig
runner = TestMachinesCreate.CreateVmRunner(self)
Expand Down Expand Up @@ -307,6 +315,27 @@ class TestMachinesCreate(VirtualMachinesCase):
ssh_keys=[rsakey],
create_and_run=True))

# Try to create VM with a SSH key and without the root and user password
runner.createCloudBaseImageTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
location=config.VALID_DISK_IMAGE_PATH,
os_name=config.FEDORA_28,
os_short_id=config.FEDORA_28_SHORTID,
user_login="foo",
ssh_keys=[rsakey],
create_and_run=True))

# Try to create VM with a SSH key and root password, also without the user password
runner.createCloudBaseImageTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
location=config.VALID_DISK_IMAGE_PATH,
os_name=config.FEDORA_28,
os_short_id=config.FEDORA_28_SHORTID,
root_password="dogsaremybestfr13nds",
user_login="foo",
ssh_keys=[rsakey],
create_and_run=True))

# try to create VM with multiple SSH keys
runner.createCloudBaseImageTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
Expand Down Expand Up @@ -1149,7 +1178,8 @@ vnc_password= "{vnc_passwd}"
user_data_path = virt_install_cmd_out.split("user-data=", 1)[1].split()[0]
user_data = self.machine.execute("cat " + user_data_path)

self.assertIn("\nssh_pwauth: true", user_data)
if self.user_password:
self.assertIn("\nssh_pwauth: true", user_data)

ssh_keys = self.expected_ssh_keys or self.ssh_keys
if ssh_keys is not None:
Expand Down Expand Up @@ -1306,7 +1336,7 @@ vnc_password= "{vnc_passwd}"
b.set_checked(f"#connectionName-{self.connection}", True)

if self.is_unattended or self.sourceType == "cloud":
if self.is_unattended or self.user_password or self.user_login or self.root_password:
if self.is_unattended or self.user_password or self.user_login or self.root_password or self.ssh_keys:
b.click("#pf-tab-1-automation")

if self.profile:
Expand Down

0 comments on commit 2102e41

Please sign in to comment.