- """Create fresh virtualenv to a directory, install pip requirements."""
- logger.console('Extracting virtualenv, installing requirements.txt '
- 'on {0}'.format(node['host']))
- ssh = SSH()
- ssh.connect(node)
- (ret_code, stdout, stderr) = ssh.exec_command(
- 'cd {0} && rm -rf env && virtualenv env && . env/bin/activate && '
- 'pip install -r requirements.txt'
- .format(con.REMOTE_FW_DIR), timeout=100)
- if 0 != ret_code:
- logger.error('Virtualenv creation error: {0}'.format(stdout + stderr))
- raise Exception('Virtualenv setup failed')
+ """Create fresh virtualenv to a directory, install pip requirements.
+
+ :param node: Node to create virtualenv on.
+ :type node: dict
+ :returns: nothing
+ :raises RuntimeError: When failed to setup virtualenv.
+ """
+ host = node['host']
+ logger.console('Virtualenv setup including requirements.txt on {0} starts.'
+ .format(host))
+ exec_cmd_no_error(
+ node, 'cd {0} && rm -rf env'
+ ' && virtualenv --system-site-packages --never-download env'
+ ' && source env/bin/activate && pip install -r requirements.txt'
+ .format(con.REMOTE_FW_DIR), timeout=100, include_reason=True,
+ message="Failed install at node {host}".format(host=host))
+ logger.console('Virtualenv setup on {0} done.'.format(host))
+
+
+def setup_node(node, tarball, remote_tarball, results=None):
+ """Copy a tarball to a node and extract it.
+
+ :param node: A node where the tarball will be copied and extracted.
+ :param tarball: Local path of tarball to be copied.
+ :param remote_tarball: Remote path of the tarball.
+ :param results: A list where to store the result of node setup, optional.
+ :type node: dict
+ :type tarball: str
+ :type remote_tarball: str
+ :type results: list
+ :returns: True - success, False - error
+ :rtype: bool
+ """
+ host = node['host']
+ try:
+ copy_tarball_to_node(tarball, node)
+ extract_tarball_at_node(remote_tarball, node)
+ if node['type'] == NodeType.TG:
+ create_env_directory_at_node(node)
+ except RuntimeError as exc:
+ logger.console("Node {node} setup failed, error: {err!r}".format(
+ node=host, err=exc))
+ result = False