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

DBG - break line that coverage says is not executed #2006

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/components/vm/consoles/consoles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,25 @@ class Consoles extends React.Component {
onDesktopConsoleDownload (type) {
const { vm } = this.props;
// fire download of the .vv file
domainDesktopConsole({ name: vm.name, id: vm.id, connectionName: vm.connectionName, consoleDetail: vm.displays.find(display => display.type == type) });
const consoleDetail = vm.displays.find(display => display.type == type);

let address;
if (cockpit.transport.host == "localhost") {
const app = cockpit.transport.application();
if (app.startsWith("cockpit+=")) {
address = "wrong:" + app.substr(9);
Comment on lines +96 to +97
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 added lines are not executed by any test.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test failure shows the wrong value that is computed here. Hmm. Maybe the coverage collection goes wrong across logouts?

} else {
address = window.location.hostname;
}
} else {
address = cockpit.transport.host;
const pos = address.indexOf("@");
if (pos >= 0) {
address = address.substr(pos + 1);
Comment on lines +102 to +105
Copy link
Contributor

Choose a reason for hiding this comment

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

These 4 added lines are not executed by any test.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is expected, the test aborts before reaching the part that executes this code.

}
}

domainDesktopConsole({ name: vm.name, consoleDetail: { ...consoleDetail, address } });
}

render () {
Expand Down
119 changes: 95 additions & 24 deletions test/check-machines-consoles
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import testlib
class TestMachinesConsoles(machineslib.VirtualMachinesCase):

def waitDownloadFile(self, filename: str, expected_size: int | None = None, content: str | None = None) -> None:
b = self.browser
filepath = b.driver.download_dir / filename
filepath = self.browser.driver.download_dir / filename

# Big downloads can take a while
testlib.wait(filepath.exists, tries=120)
Expand All @@ -39,6 +38,30 @@ class TestMachinesConsoles(machineslib.VirtualMachinesCase):
if content is not None:
self.assertEqual(filepath.read_text(), content)

def waitViewerDownload(self, kind, host, port=5900):
self.browser.allow_download()
self.browser.click(".pf-v5-c-console__remote-viewer-launch-vv") # "Launch Remote Viewer" button
content = f"""[virt-viewer]
type={kind}
host={host}
port={port}
delete-this-file=1
fullscreen=0

[...............................GraphicsConsole]
"""
# HACK: Due to a bug in cockpit-machines, Firefox downloads the desktop
# viewer file as a randomly generated file while chromium as
# "download". As we want to download this as "$vmName.vv" in the end
# work around the issue for now.
if self.browser.browser == "chromium":
fname = "download"
else:
testlib.wait(lambda: len(os.listdir(self.browser.driver.download_dir)) == 1)
fname = os.listdir(self.browser.driver.download_dir)[0]

self.waitDownloadFile(fname, content=content)

@testlib.skipImage('SPICE not supported on RHEL', "rhel-*", "centos-*")
def testExternalConsole(self):
b = self.browser
Expand All @@ -56,28 +79,7 @@ class TestMachinesConsoles(machineslib.VirtualMachinesCase):
b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:first-child dd", "127.0.0.1")
b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:nth-child(2) dd", "5900")

b.allow_download()
b.click(".pf-v5-c-console__remote-viewer-launch-vv") # "Launch Remote Viewer" button
content = """[virt-viewer]
type=spice
host=127.0.0.1
port=5900
delete-this-file=1
fullscreen=0

[...............................GraphicsConsole]
"""
# HACK: Due to a bug in cockpit-machines, Firefox downloads the desktop
# viewer file as a randomly generated file while chromium as
# "download". As we want to download this as "$vmName.vv" in the end
# work around the issue for now.
if b.browser == "chromium":
fname = "download"
else:
testlib.wait(lambda: len(os.listdir(b.driver.download_dir)) == 1)
fname = os.listdir(b.driver.download_dir)[0]

self.waitDownloadFile(fname, expected_size=len(content), content=content)
self.waitViewerDownload("spice", b.address)

# Go to the expanded console view
b.click("button:contains(Expand)")
Expand Down Expand Up @@ -253,6 +255,75 @@ fullscreen=0
self.allow_browser_errors("Disconnection timed out.",
"Failed when connecting: Connection closed")

def testExternalConsoleMultiHost(self):
b = self.browser

my_ip = "172.27.0.15"
name = "subVmTest1"

self.setup_ssh_auth()
self.machine.execute(f"ssh-keyscan {my_ip} > /etc/ssh/ssh_known_hosts")
self.enable_multihost(self.machine)
self.machine.write("/etc/cockpit/cockpit.conf", "[Session]\nWarnBeforeConnecting=false\n", append=True)

self.createVm(name, graphics="vnc")

self.machine.start_cockpit()

# Direct login via SSH

b.open(f"/={my_ip}/machines")
b.set_val('#login-user-input', "admin")
b.set_val('#login-password-input', "foobar")
b.click("#login-button")

self.waitPageInit()
b.become_superuser()
b.enter_page("/machines")
self.waitVmRow(name)

self.goToVmPage(name)
b.wait_in_text(f"#vm-{name}-system-state", "Running")

b.click("#pf-v5-c-console__type-selector")
b.wait_visible("#pf-v5-c-console__type-selector + .pf-v5-c-select__menu")
b.click("#DesktopViewer button")
b.wait_not_present("#pf-v5-c-console__type-selector + .pf-v5-c-select__menu")

b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:first-child dd", "127.0.0.1")
b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:nth-child(2) dd", "5900")

self.waitViewerDownload("vnc", my_ip)

# Login from Shell via SSH

b.logout()
b.login_and_go("/system")

host = f"admin@{my_ip}"

b.add_machine(host, password=None, known_host=True, expect_warning=False)

b.go(f"/@{host}/machines")
b.enter_page("/machines", host=host)
self.waitPageInit()
b.become_superuser()
b.enter_page("/machines", host=host)
self.waitVmRow(name)

self.goToVmPage(name)
b.wait_in_text(f"#vm-{name}-system-state", "Running")

b.click("#pf-v5-c-console__type-selector")
b.wait_visible("#pf-v5-c-console__type-selector + .pf-v5-c-select__menu")
b.click("#DesktopViewer button")
b.wait_not_present("#pf-v5-c-console__type-selector + .pf-v5-c-select__menu")

b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:first-child dd", "127.0.0.1")
b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:nth-child(2) dd", "5900")

self.waitViewerDownload("vnc", my_ip)


if __name__ == '__main__':
testlib.test_main()
101 changes: 0 additions & 101 deletions test/check-machines-multi-host-consoles

This file was deleted.