def test_start_shellinabox_console_nopid(self, mock_stop, mock_dir_exists, mock_pid_exists, mock_popen, mock_path_exists, mock_fcntl): # no existing PID file before starting mock_stop.side_effect = exception.NoConsolePid('/tmp/blah') mock_popen.return_value.poll.return_value = 0 self.mock_stdout.write(b'0') self.mock_stdout.seek(0) mock_popen.return_value.stdout = self.mock_stdout self.mock_stderr.write(b'1') self.mock_stderr.seek(0) mock_popen.return_value.stderr = self.mock_stderr mock_pid_exists.return_value = True mock_path_exists.return_value = True console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_stop.assert_called_once_with(self.info['uuid']) mock_dir_exists.assert_called_once_with() mock_pid_exists.assert_called_once_with(12345) mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def test_start_shellinabox_console(self, mock_stop, mock_dir_exists, mock_pid_exists, mock_popen, mock_path_exists, mock_fcntl): mock_popen.return_value.poll.return_value = 0 self.mock_stdout.write(b'0') self.mock_stdout.seek(0) mock_popen.return_value.stdout = self.mock_stdout self.mock_stderr.write(b'1') self.mock_stderr.seek(0) mock_popen.return_value.stderr = self.mock_stderr mock_pid_exists.return_value = True mock_path_exists.return_value = True console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_stop.assert_called_once_with(self.info['uuid']) mock_dir_exists.assert_called_once_with() mock_pid_exists.assert_called_once_with(12345) mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def start_console(self, task): """Start a remote console for the node. :param task: a TaskManager instance containing the node to act on. :raises: MissingParameterValue when required ipmi credentials are missing. :raises: InvalidParameterValue when the IPMI terminal port is not an integer. :raises: ConsoleError if unable to start the console process. """ driver_info = _parse_driver_info(task.node) path = _console_pwfile_path(driver_info['uuid']) pw_file = console_utils.make_persistent_password_file( path, driver_info['password']) console_cmd = ("/:%(uid)s:%(gid)s:HOME:pyghmicons %(bmc)s" " %(user)s" " %(passwd_file)s" % {'uid': os.getuid(), 'gid': os.getgid(), 'bmc': driver_info['address'], 'user': driver_info['username'], 'passwd_file': pw_file}) try: console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['port'], console_cmd) except exception.ConsoleError: with excutils.save_and_reraise_exception(): utils.unlink_without_raise(path)
def start_console(self, task): """Start a remote console for the node. :param task: a task from TaskManager :raises: MissingParameterValue if required ssh parameters are missing :raises: ConsoleError if the directory for the PID file cannot be created :raises: ConsoleSubprocessFailed when invoking the subprocess failed :raises: InvalidParameterValue if required parameters are invalid. """ driver_info = _parse_driver_info(task.node) driver_info['macs'] = driver_utils.get_node_mac_addresses(task) ssh_obj = _get_connection(task.node) node_name = _get_hosts_name_for_node(ssh_obj, driver_info) ssh_cmd = ("/:%(uid)s:%(gid)s:HOME:virsh console %(node)s" % {'uid': os.getuid(), 'gid': os.getgid(), 'node': node_name}) console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['terminal_port'], ssh_cmd)
def start_console(self, task): """Start a remote console for the node. :param task: a task from TaskManager :raises: MissingParameterValue if required seamicro parameters are missing :raises: ConsoleError if the directory for the PID file cannot be created :raises: ConsoleSubprocessFailed when invoking the subprocess failed :raises: InvalidParameterValue if required parameter are invalid. """ driver_info = _parse_driver_info(task.node) telnet_port = get_telnet_port(driver_info) chassis_ip = urlparse.urlparse(driver_info['api_endpoint']).netloc seamicro_cmd = ("/:%(uid)s:%(gid)s:HOME:telnet %(chassis)s %(port)s" % {'uid': os.getuid(), 'gid': os.getgid(), 'chassis': chassis_ip, 'port': telnet_port}) console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['port'], seamicro_cmd)
def start_console(self, task): """Start a remote console for the node. :param task: a task from TaskManager :raises: MissingParameterValue if required seamicro parameters are missing :raises: ConsoleError if the directory for the PID file cannot be created :raises: ConsoleSubprocessFailed when invoking the subprocess failed :raises: InvalidParameterValue if required parameter are invalid. """ driver_info = _parse_driver_info(task.node) telnet_port = get_telnet_port(driver_info) chassis_ip = urlparse.urlparse(driver_info['api_endpoint']).netloc seamicro_cmd = ("/:%(uid)s:%(gid)s:HOME:telnet %(chassis)s %(port)s" % { 'uid': os.getuid(), 'gid': os.getgid(), 'chassis': chassis_ip, 'port': telnet_port }) console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['port'], seamicro_cmd)
def start_console(self, task): """Start a remote console for the node. :param task: a task from TaskManager :raises: MissingParameterValue if required ssh parameters are missing :raises: ConsoleError if the directory for the PID file cannot be created :raises: ConsoleSubprocessFailed when invoking the subprocess failed :raises: InvalidParameterValue if required parameters are invalid. """ driver_info = _parse_driver_info(task.node) driver_info['macs'] = driver_utils.get_node_mac_addresses(task) ssh_obj = _get_connection(task.node) node_name = _get_hosts_name_for_node(ssh_obj, driver_info) ssh_cmd = ("/:%(uid)s:%(gid)s:HOME:virsh console %(node)s" % {'uid': os.getuid(), 'gid': os.getgid(), 'node': node_name}) console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['terminal_port'], ssh_cmd)
def start_console(self, task): """Start a remote console for the node. :param task: a TaskManager instance containing the node to act on. :raises: MissingParameterValue when required ipmi credentials are missing. :raises: InvalidParameterValue when the IPMI terminal port is not an integer. :raises: ConsoleError if unable to start the console process. """ driver_info = _parse_driver_info(task.node) path = _console_pwfile_path(driver_info['uuid']) pw_file = console_utils.make_persistent_password_file( path, driver_info['password']) console_cmd = ("/:%(uid)s:%(gid)s:HOME:pyghmicons %(bmc)s" " %(user)s" " %(passwd_file)s" % {'uid': os.getuid(), 'gid': os.getgid(), 'bmc': driver_info['address'], 'user': driver_info['username'], 'passwd_file': pw_file}) try: console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['port'], console_cmd) except exception.ConsoleError: with excutils.save_and_reraise_exception(): utils.unlink_without_raise(path)
def test_start_shellinabox_console_nopid(self, mock_stop, mock_dir_exists, mock_pid_exists, mock_pid, mock_popen): # no existing PID file before starting mock_stop.side_effect = iter([exception.NoConsolePid('/tmp/blah')]) mock_popen.return_value.poll.return_value = 0 mock_pid.return_value = 12345 mock_pid_exists.return_value = True # touch the pid file pid_file = console_utils._get_console_pid_file(self.info['uuid']) open(pid_file, 'a').close() self.addCleanup(os.remove, pid_file) self.assertTrue(os.path.exists(pid_file)) console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_stop.assert_called_once_with(self.info['uuid']) mock_dir_exists.assert_called_once_with() mock_pid.assert_called_once_with(self.info['uuid']) mock_pid_exists.assert_called_once_with(12345) mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def test_start_shellinabox_console_nopid(self, mock_stop, mock_dir_exists, mock_pid_exists, mock_pid, mock_popen): # no existing PID file before starting mock_stop.side_effect = iter([exception.NoConsolePid('/tmp/blah')]) mock_popen.return_value.poll.return_value = 0 mock_pid.return_value = 12345 mock_pid_exists.return_value = True # touch the pid file pid_file = console_utils._get_console_pid_file(self.info['uuid']) open(pid_file, 'a').close() self.addCleanup(os.remove, pid_file) self.assertTrue(os.path.exists(pid_file)) console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_stop.assert_called_once_with(self.info['uuid']) mock_dir_exists.assert_called_once_with() mock_pid.assert_called_once_with(self.info['uuid']) mock_pid_exists.assert_called_once_with(12345) mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def test_start_shellinabox_console(self, mock_stop, mock_dir_exists, mock_pid_exists, mock_pid, mock_popen): mock_popen.return_value.poll.return_value = 0 mock_pid.return_value = 12345 mock_pid_exists.return_value = True # touch the pid file pid_file = console_utils._get_console_pid_file(self.info['uuid']) open(pid_file, 'a').close() self.addCleanup(os.remove, pid_file) self.assertTrue(os.path.exists(pid_file)) console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_stop.assert_called_once_with(self.info['uuid']) mock_dir_exists.assert_called_once_with() mock_pid.assert_called_once_with(self.info['uuid']) mock_pid_exists.assert_called_once_with(12345) mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def test_start_shellinabox_console(self, mock_popen): mock_popen.return_value.poll.return_value = 0 # touch the pid file pid_file = console_utils._get_console_pid_file(self.info['uuid']) open(pid_file, 'a').close() self.assertTrue(os.path.exists(pid_file)) console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def test_start_shellinabox_console(self, mock_popen): mock_popen.return_value.poll.return_value = 0 # touch the pid file pid_file = console_utils._get_console_pid_file(self.info['uuid']) open(pid_file, 'a').close() self.assertTrue(os.path.exists(pid_file)) console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def test_start_shellinabox_console(self, mock_stop, mock_dir_exists, mock_pid_exists, mock_popen, mock_path_exists): mock_popen.return_value.poll.return_value = 0 mock_pid_exists.return_value = True mock_path_exists.return_value = True console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_stop.assert_called_once_with(self.info['uuid']) mock_dir_exists.assert_called_once_with() mock_pid_exists.assert_called_once_with(12345) mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def start_console(self, task): """Start a remote console for the node.""" driver_info = _parse_driver_info(task.node) path = _console_pwfile_path(driver_info['uuid']) pw_file = console_utils.make_persistent_password_file( path, driver_info['password']) ipmi_cmd = "/:%(uid)s:%(gid)s:HOME:ipmitool -H %(address)s" \ " -I lanplus -U %(user)s -f %(pwfile)s" \ % {'uid': os.getuid(), 'gid': os.getgid(), 'address': driver_info['address'], 'user': driver_info['username'], 'pwfile': pw_file} if CONF.debug: ipmi_cmd += " -v" ipmi_cmd += " sol activate" console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['port'], ipmi_cmd)
def start_console(self, task): """Start a remote console for the node.""" driver_info = _parse_driver_info(task.node) path = _console_pwfile_path(driver_info['uuid']) pw_file = console_utils.make_persistent_password_file( path, driver_info['password']) ipmi_cmd = "/:%(uid)s:%(gid)s:HOME:ipmitool -H %(address)s" \ " -I lanplus -U %(user)s -f %(pwfile)s" \ % {'uid': os.getuid(), 'gid': os.getgid(), 'address': driver_info['address'], 'user': driver_info['username'], 'pwfile': pw_file} if CONF.debug: ipmi_cmd += " -v" ipmi_cmd += " sol activate" console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['port'], ipmi_cmd)
def start_console(self, task): """Start a remote console for the node. :param task: a task from TaskManager :raises: InvalidParameterValue if required ipmi parameters are missing :raises: PasswordFileFailedToCreate if unable to create a file containing the password :raises: ConsoleError if the directory for the PID file cannot be created :raises: ConsoleSubprocessFailed when invoking the subprocess failed """ driver_info = _parse_driver_info(task.node) path = _console_pwfile_path(driver_info['uuid']) pw_file = console_utils.make_persistent_password_file( path, driver_info['password'] or '\0') ipmi_cmd = ("/:%(uid)s:%(gid)s:HOME:ipmitool -H %(address)s" " -I lanplus -U %(user)s -f %(pwfile)s" % {'uid': os.getuid(), 'gid': os.getgid(), 'address': driver_info['address'], 'user': driver_info['username'], 'pwfile': pw_file}) for name, option in BRIDGING_OPTIONS: if driver_info[name] is not None: ipmi_cmd = " ".join([ipmi_cmd, option, driver_info[name]]) if CONF.debug: ipmi_cmd += " -v" ipmi_cmd += " sol activate" try: console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['port'], ipmi_cmd) except (exception.ConsoleError, exception.ConsoleSubprocessFailed): with excutils.save_and_reraise_exception(): ironic_utils.unlink_without_raise(path)
def start_console(self, task): """Start a remote console for the node. :param task: a task from TaskManager :raises: InvalidParameterValue if required ipmi parameters are missing :raises: PasswordFileFailedToCreate if unable to create a file containing the password :raises: ConsoleError if the directory for the PID file cannot be created :raises: ConsoleSubprocessFailed when invoking the subprocess failed """ driver_info = _parse_driver_info(task.node) path = _console_pwfile_path(driver_info['uuid']) pw_file = console_utils.make_persistent_password_file( path, driver_info['password']) ipmi_cmd = ("/:%(uid)s:%(gid)s:HOME:ipmitool -H %(address)s" " -I lanplus -U %(user)s -f %(pwfile)s" % {'uid': os.getuid(), 'gid': os.getgid(), 'address': driver_info['address'], 'user': driver_info['username'], 'pwfile': pw_file}) for name, option in BRIDGING_OPTIONS: if driver_info[name] is not None: ipmi_cmd = " ".join([ipmi_cmd, option, driver_info[name]]) if CONF.debug: ipmi_cmd += " -v" ipmi_cmd += " sol activate" try: console_utils.start_shellinabox_console(driver_info['uuid'], driver_info['port'], ipmi_cmd) except (exception.ConsoleError, exception.ConsoleSubprocessFailed): with excutils.save_and_reraise_exception(): utils.unlink_without_raise(path)
def test_start_shellinabox_console_nopid(self, mock_stop, mock_dir_exists, mock_pid_exists, mock_popen, mock_path_exists): # no existing PID file before starting mock_stop.side_effect = exception.NoConsolePid('/tmp/blah') mock_popen.return_value.poll.return_value = 0 mock_pid_exists.return_value = True mock_path_exists.return_value = True console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_stop.assert_called_once_with(self.info['uuid']) mock_dir_exists.assert_called_once_with() mock_pid_exists.assert_called_once_with(12345) mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()
def test_start_shellinabox_console(self, mock_stop, mock_dir_exists, mock_pid_exists, mock_pid, mock_popen): mock_popen.return_value.poll.return_value = 0 mock_pid.return_value = 12345 mock_pid_exists.return_value = True # touch the pid file pid_file = console_utils._get_console_pid_file(self.info['uuid']) open(pid_file, 'a').close() self.addCleanup(os.remove, pid_file) self.assertTrue(os.path.exists(pid_file)) console_utils.start_shellinabox_console(self.info['uuid'], self.info['port'], 'ls&') mock_stop.assert_called_once_with(self.info['uuid']) mock_dir_exists.assert_called_once_with() mock_pid.assert_called_once_with(self.info['uuid']) mock_pid_exists.assert_called_once_with(12345) mock_popen.assert_called_once_with(mock.ANY, stdout=subprocess.PIPE, stderr=subprocess.PIPE) mock_popen.return_value.poll.assert_called_once_with()