- (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')
+ (ret_code, _, _) = ssh.exec_command(
+ 'cd {0} && rm -rf env && '
+ 'virtualenv --system-site-packages --never-download env && '
+ '. env/bin/activate && '
+ 'pip install -r requirements.txt'
+ .format(con.REMOTE_FW_DIR), timeout=100)
+ if ret_code != 0:
+ raise RuntimeError('Virtualenv setup including requirements.txt on {0}'
+ .format(node['host']))
+
+ logger.console('Virtualenv on {0} created'.format(node['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
+ """
+ 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.error("Node {0} setup failed, error:'{1}'"
+ .format(node['host'], exc.message))
+ result = False