@@ -545,6 +545,80 @@ public void getConsoleConnectionDetailsReturnsDetailsForKVMHypervisor() {
545545 Assert .assertEquals (port , result .getPort ());
546546 }
547547
548+ @ Test
549+ public void getConsoleConnectionDetailsRequiresNewViewerForKVMUserVmWhenMultipleViewersEnabled () {
550+ VirtualMachine vm = Mockito .mock (VirtualMachine .class );
551+ HostVO host = Mockito .mock (HostVO .class );
552+ String hostAddress = "192.168.1.100" ;
553+ int port = 5900 ;
554+ Pair <String , Integer > hostPortInfo = new Pair <>(hostAddress , port );
555+
556+ Mockito .when (vm .getUuid ()).thenReturn ("vm-uuid" );
557+ Mockito .when (vm .getHostName ()).thenReturn ("vm-hostname" );
558+ Mockito .when (vm .getVncPassword ()).thenReturn ("vnc-password" );
559+ Mockito .when (vm .getType ()).thenReturn (VirtualMachine .Type .User );
560+ Mockito .when (host .getHypervisorType ()).thenReturn (Hypervisor .HypervisorType .KVM );
561+ Mockito .when (vmInstanceDetailsDao .listDetailsKeyPairs (Mockito .anyLong (), Mockito .anyList ())).thenReturn (Map .of ());
562+ Mockito .when (managementServer .getVncPort (vm )).thenReturn (hostPortInfo );
563+ Mockito .doReturn (new Ternary <>(hostAddress , null , null ))
564+ .when (consoleAccessManager ).parseHostInfo (Mockito .anyString ());
565+ Mockito .doReturn (true ).when (consoleAccessManager ).isKvmMultipleConsoleViewersEnabled ();
566+
567+ ConsoleConnectionDetails result = consoleAccessManager .getConsoleConnectionDetails (vm , host );
568+
569+ Assert .assertNotNull (result );
570+ Assert .assertTrue (result .isSessionRequiresNewViewer ());
571+ }
572+
573+ @ Test
574+ public void getConsoleConnectionDetailsDoesNotRequireNewViewerForKVMUserVmWhenMultipleViewersDisabled () {
575+ VirtualMachine vm = Mockito .mock (VirtualMachine .class );
576+ HostVO host = Mockito .mock (HostVO .class );
577+ String hostAddress = "192.168.1.100" ;
578+ int port = 5900 ;
579+ Pair <String , Integer > hostPortInfo = new Pair <>(hostAddress , port );
580+
581+ Mockito .when (vm .getUuid ()).thenReturn ("vm-uuid" );
582+ Mockito .when (vm .getHostName ()).thenReturn ("vm-hostname" );
583+ Mockito .when (vm .getVncPassword ()).thenReturn ("vnc-password" );
584+ Mockito .when (vm .getType ()).thenReturn (VirtualMachine .Type .User );
585+ Mockito .when (host .getHypervisorType ()).thenReturn (Hypervisor .HypervisorType .KVM );
586+ Mockito .when (vmInstanceDetailsDao .listDetailsKeyPairs (Mockito .anyLong (), Mockito .anyList ())).thenReturn (Map .of ());
587+ Mockito .when (managementServer .getVncPort (vm )).thenReturn (hostPortInfo );
588+ Mockito .doReturn (new Ternary <>(hostAddress , null , null ))
589+ .when (consoleAccessManager ).parseHostInfo (Mockito .anyString ());
590+ Mockito .doReturn (false ).when (consoleAccessManager ).isKvmMultipleConsoleViewersEnabled ();
591+
592+ ConsoleConnectionDetails result = consoleAccessManager .getConsoleConnectionDetails (vm , host );
593+
594+ Assert .assertNotNull (result );
595+ Assert .assertFalse (result .isSessionRequiresNewViewer ());
596+ }
597+
598+ @ Test
599+ public void getConsoleConnectionDetailsDoesNotRequireNewViewerForKVMSystemVmWhenMultipleViewersEnabled () {
600+ VirtualMachine vm = Mockito .mock (VirtualMachine .class );
601+ HostVO host = Mockito .mock (HostVO .class );
602+ String hostAddress = "192.168.1.100" ;
603+ int port = 5900 ;
604+ Pair <String , Integer > hostPortInfo = new Pair <>(hostAddress , port );
605+
606+ Mockito .when (vm .getUuid ()).thenReturn ("vm-uuid" );
607+ Mockito .when (vm .getHostName ()).thenReturn ("vm-hostname" );
608+ Mockito .when (vm .getVncPassword ()).thenReturn ("vnc-password" );
609+ Mockito .when (vm .getType ()).thenReturn (VirtualMachine .Type .DomainRouter );
610+ Mockito .when (host .getHypervisorType ()).thenReturn (Hypervisor .HypervisorType .KVM );
611+ Mockito .when (vmInstanceDetailsDao .listDetailsKeyPairs (Mockito .anyLong (), Mockito .anyList ())).thenReturn (Map .of ());
612+ Mockito .when (managementServer .getVncPort (vm )).thenReturn (hostPortInfo );
613+ Mockito .doReturn (new Ternary <>(hostAddress , null , null ))
614+ .when (consoleAccessManager ).parseHostInfo (Mockito .anyString ());
615+
616+ ConsoleConnectionDetails result = consoleAccessManager .getConsoleConnectionDetails (vm , host );
617+
618+ Assert .assertNotNull (result );
619+ Assert .assertFalse (result .isSessionRequiresNewViewer ());
620+ }
621+
548622 @ Test
549623 public void getConsoleConnectionDetailsReturnsDetailsWithRDPForHyperV () {
550624 VirtualMachine vm = Mockito .mock (VirtualMachine .class );
0 commit comments