def _run_mkvterm_cmd(lpar_uuid, force): cmd = ['mkvterm', '--id', str(lpar_id), '--vnc', '--local'] ret_code, std_out, std_err = _run_proc(cmd) # If the vterm was already started, the mkvterm command will always # return an error message with a return code of 3. However, there # are 2 scenarios here, one where it was started with the VNC option # previously, which we will get a valid port number back (which is # the good path scenario), and one where it was started out-of-band # where we will get no port. If it is the out-of-band scenario and # they asked us to force the connection, then we will attempt to # terminate the old vterm session so we can start up one with VNC. if force and ret_code == 3 and not _parse_vnc_port(std_out): LOG.warning(_("Invalid output on vterm open. Trying to reset the " "vterm. Error was %s"), std_err) close_vterm(adapter, lpar_uuid) ret_code, std_out, std_err = _run_proc(cmd) # The only error message that is fine is a return code of 3 that a # session is already started, where we got back the port back meaning # that it was started as VNC. Else, raise up the error message. if ret_code != 0 and not (ret_code == 3 and _parse_vnc_port(std_out)): raise pvm_exc.VNCBasedTerminalFailedToOpen(err=std_err) # Parse the VNC Port out of the stdout returned from mkvterm return _parse_vnc_port(std_out)
def test_get_vnc_console(self, mock_vterm): # Success mock_vterm.return_value = '10' resp = self.drv.get_vnc_console(mock.ANY, self.inst) self.assertEqual('127.0.0.1', resp.host) self.assertEqual('10', resp.port) self.assertEqual('uuid', resp.internal_access_path) mock_vterm.assert_called_once_with( mock.ANY, 'uuid', mock.ANY, vnc_path='uuid') # VNC failure - exception is raised directly mock_vterm.side_effect = pvm_exc.VNCBasedTerminalFailedToOpen(err='xx') self.assertRaises(pvm_exc.VNCBasedTerminalFailedToOpen, self.drv.get_vnc_console, mock.ANY, self.inst) # 404 mock_vterm.side_effect = pvm_exc.HttpError(mock.Mock(status=404)) self.assertRaises(exception.InstanceNotFound, self.drv.get_vnc_console, mock.ANY, self.inst)