本文整理汇总了Python中fuelweb_test.helpers.ssh_manager.SSHManager类的典型用法代码示例。如果您正苦于以下问题:Python SSHManager类的具体用法?Python SSHManager怎么用?Python SSHManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SSHManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_nodes_tasks
def get_nodes_tasks(node_id):
"""
:param node_id: an integer number of node id
:return: a set of deployment tasks for corresponding node
"""
tasks = set()
ssh = SSHManager()
result = ssh.execute_on_remote(ssh.admin_ip, "ls /var/log/astute")
filenames = [filename.strip() for filename in result['stdout']]
for filename in filenames:
ssh.download_from_remote(
ssh.admin_ip,
destination="/var/log/astute/{0}".format(filename),
target="/tmp/{0}".format(filename))
data = fileinput.FileInput(
files=["/tmp/{0}".format(filename) for filename in filenames],
openhook=fileinput.hook_compressed)
for line in data:
if "Task time summary" in line \
and "node {}".format(node_id) in line:
# FIXME: define an exact search of task
task_name = line.split("Task time summary: ")[1].split()[0]
check = any([excluded_task in task_name
for excluded_task in TASKS_BLACKLIST])
if check:
continue
tasks.add(task_name)
return tasks
示例2: store_astute_yaml_for_one_node
def store_astute_yaml_for_one_node(nailgun_node):
ssh_manager = SSHManager()
if 'roles' not in nailgun_node:
return None
errmsg = 'Downloading "{0}.yaml" from the {1} failed'
msg = 'File "{0}.yaml" was downloaded from the {1}'
nodename = nailgun_node['name']
ip = nailgun_node['ip']
for role in nailgun_node['roles']:
filename = '{0}/{1}-{2}-{3}.yaml'.format(settings.LOGS_DIR,
func_name,
nodename,
role)
if not ssh_manager.isfile_on_remote(ip,
'/etc/{0}.yaml'.format(role)):
role = 'primary-' + role
if ssh_manager.download_from_remote(ip,
'/etc/{0}.yaml'.format(role),
filename):
logger.info(msg.format(role, nodename))
else:
logger.error(errmsg.format(role, nodename))
if settings.DOWNLOAD_FACTS:
fact_filename = re.sub(r'-\w*\.', '-facts.', filename)
generate_facts(ip)
if ssh_manager.download_from_remote(ip,
'/tmp/facts.yaml',
fact_filename):
logger.info(msg.format('facts', nodename))
else:
logger.error(errmsg.format('facts', nodename))
示例3: replace_rpm_package
def replace_rpm_package(package):
"""Replaced rpm package.rpm on master node with package.rpm
from review
"""
ssh = SSHManager()
logger.info("Patching {}".format(package))
if not settings.UPDATE_FUEL:
raise exceptions.FuelQAVariableNotSet('UPDATE_FUEL', 'True')
try:
# Upload package
target_path = '/var/www/nailgun/{}/'.format(package)
ssh.upload_to_remote(
ip=ssh.admin_ip,
source=settings.UPDATE_FUEL_PATH.rstrip('/'),
target=target_path)
package_name = package
package_ext = '*.noarch.rpm'
pkg_path = os.path.join(target_path,
'{}{}'.format(package_name, package_ext))
full_package_name = get_full_filename(wildcard_name=pkg_path)
logger.debug('Package name is {0}'.format(full_package_name))
full_package_path = os.path.join(os.path.dirname(pkg_path),
full_package_name)
# Update package on master node
if not does_new_pkg_equal_to_installed_pkg(
installed_package=package_name,
new_package=full_package_path):
update_rpm(path=full_package_path)
except Exception:
logger.error("Could not upload package")
raise
示例4: install_pkg_2
def install_pkg_2(ip, pkg_name, port=22):
"""Install a package <pkg_name> on node
:param ip: ip of node
:param pkg_name: name of a package
:param port: ssh port
:return: exit code of installation
"""
ssh_manager = SSHManager()
remote_status = ssh_manager.execute(
ip=ip,
port=port,
cmd="rpm -q '{0}'".format(pkg_name)
)
if remote_status['exit_code'] == 0:
logger.info("Package '{0}' already installed.".format(pkg_name))
else:
logger.info("Installing package '{0}' ...".format(pkg_name))
remote_status = ssh_manager.execute(
ip=ip,
port=port,
cmd="yum -y install {0}".format(pkg_name)
)
logger.info("Installation of the package '{0}' has been"
" completed with exit code {1}"
.format(pkg_name, remote_status['exit_code']))
return remote_status['exit_code']
示例5: get_oswl_services_names
def get_oswl_services_names():
cmd = "systemctl list-units| grep oswl_ | awk '{print $1}'"
result = SSHManager().execute_on_remote(
SSHManager().admin_ip, cmd)['stdout_str'].strip()
logger.info('list of statistic services {0}'.format(
result.split('\n')))
return result.split('\n')
示例6: _turnon_executable_ruby
def _turnon_executable_ruby(node):
"""Set mode +x for /usr/bin/ruby
:param node: dict, node attributes
"""
ssh = SSHManager()
cmd = "chmod +x /usr/bin/ruby"
ssh.execute_on_remote(node["ip"], cmd)
示例7: _turnoff_executable_ruby
def _turnoff_executable_ruby(node):
"""Set mode -x for /usr/bin/ruby
:param node: dict, node attributes
"""
ssh = SSHManager()
cmd = 'chmod -x /usr/bin/ruby'
ssh.execute_on_remote(node['ip'], cmd)
示例8: get_os_packages
def get_os_packages(ip, packages_pattern=None):
"""Pick names of some OS packages from node"""
if not packages_pattern:
packages_pattern = "neutron|nova|cinder|keystone|" "ceilometer|ironic|glance"
packages = SSHManager().execute_on_remote(
ip, "dpkg-query -W -f '${{package}}\\n' | grep -E '{}'".format(packages_pattern)
)["stdout_str"]
return packages.split("\n")
示例9: delete_astute_log
def delete_astute_log():
"""Delete astute.log file(s) on master node.
This is to ensure that no unwanted tasks are used by tests (e.g. from
previous deployments).
:return: None
"""
ssh = SSHManager()
ssh.execute_on_remote(ssh.admin_ip, "rm /var/log/astute/astute*")
ssh.execute_on_remote(ssh.admin_ip, "systemctl restart astute.service")
示例10: install_plugin_check_code
def install_plugin_check_code(ip, plugin, exit_code=0):
# Moved from checkers.py for improvement of code
cmd = "cd /var && fuel plugins --install {0} ".format(plugin)
chan, _, stderr, _ = SSHManager().execute_async_on_remote(
ip=ip,
cmd=cmd
)
logger.debug('Try to read status code from chain...')
assert_equal(
chan.recv_exit_status(), exit_code,
'Install script fails with next message {0}'.format(''.join(stderr)))
示例11: hiera_json_out
def hiera_json_out(node_ip, parameter):
hiera_cmd = "ruby -rhiera -rjson -e \"h = Hiera.new(); " \
"Hiera.logger = 'noop'; " \
"puts JSON.dump(h.lookup(\'{0}\', " \
"[], {{}}, nil, nil))\"".format(parameter)
ssh_manager = SSHManager()
config = ssh_manager.execute_on_remote(
ip=node_ip,
cmd=hiera_cmd,
jsonify=True,
err_msg='Cannot get floating ranges')['stdout_json']
return config
示例12: DockerActions
class DockerActions(object):
"""DockerActions.""" # TODO documentation
def __init__(self):
self.ssh_manager = SSHManager()
def list_containers(self):
result = self.ssh_manager.execute(
ip=self.ssh_manager.admin_ip,
cmd='dockerctl list'
)
return result['stdout']
def wait_for_ready_containers(self, timeout=300):
if MASTER_IS_CENTOS7:
return
cont_actions = []
for container in self.list_containers():
cont_action = BaseActions()
cont_action.container = container
cont_actions.append(cont_action)
try:
wait(lambda: all([cont_action.is_container_ready
for cont_action in cont_actions]),
timeout=timeout)
except TimeoutError:
failed_containers = [x.container for x in cont_actions
if not x.is_container_ready]
raise TimeoutError(
"Container(s) {0} failed to start in {1} seconds."
.format(failed_containers, timeout))
def restart_container(self, container):
self.ssh_manager.execute(
ip=self.ssh_manager.admin_ip,
cmd='dockerctl restart {0}'.format(container)
)
cont_action = BaseActions()
cont_action.container = container
cont_action.wait_for_ready_container()
def restart_containers(self):
for container in self.list_containers():
self.restart_container(container)
def execute_in_containers(self, cmd):
for container in self.list_containers():
self.ssh_manager.execute(
ip=self.ssh_manager.admin_ip,
cmd="dockerctl shell {0} bash -c '{1}'".format(container, cmd)
)
示例13: check_service
def check_service(ip, commands):
"""Check that required nova services are running on controller.
:param ip: ip address of node
:param commands: type list, nova commands to execute on controller,
example of commands:
['nova-manage service list | grep vcenter-vmcluster1']
"""
ssh_manager = SSHManager()
ssh_manager.check_call(ip=ip, command='source openrc')
for cmd in commands:
wait(lambda:
':-)' in ssh_manager.check_call(ip=ip, command=cmd).stdout[-1],
timeout=200)
示例14: upload_nailgun_agent_rpm
def upload_nailgun_agent_rpm():
"""Upload nailgun_agent.rpm on master node
"""
ssh = SSHManager()
logger.info("Upload nailgun-agent")
if not settings.UPDATE_FUEL:
raise exceptions.FuelQAVariableNotSet('UPDATE_FUEL', 'True')
pack_path = '/var/www/nailgun/nailgun-agent-review/'
ssh.upload_to_remote(
ip=ssh.admin_ip,
source=settings.UPDATE_FUEL_PATH.rstrip('/'),
target=pack_path)
# Extract rpm context
cmd = 'cd {0}; rpm2cpio {1} | cpio -idmv'.format(
pack_path, 'nailgun-agent-*.noarch.rpm ')
ssh.execute_on_remote(ssh.admin_ip, cmd)
示例15: __init__
def __init__(self):
self.ssh_manager = SSHManager()
self.ip = self.ssh_manager.admin_ip
self.path_scripts = ('{0}/fuelweb_test/helpers/'
.format(os.environ.get("WORKSPACE", "./")))
self.remote_path_scripts = '/tmp/'
self.ubuntu_script = 'regenerate_ubuntu_repo'
self.centos_script = 'regenerate_centos_repo'
self.local_mirror_ubuntu = settings.LOCAL_MIRROR_UBUNTU
self.local_mirror_centos = settings.LOCAL_MIRROR_CENTOS
self.ubuntu_release = settings.UBUNTU_RELEASE
self.centos_supported_archs = ['noarch', 'x86_64']
self.pkgs_list = []
self.custom_pkgs_mirror_path = ''
if settings.OPENSTACK_RELEASE_UBUNTU in settings.OPENSTACK_RELEASE:
# Trying to determine the root of Ubuntu repository
pkgs_path = settings.CUSTOM_PKGS_MIRROR.split('/dists/')
if len(pkgs_path) == 2:
self.custom_pkgs_mirror = pkgs_path[0]
self.custom_pkgs_mirror_path = '/dists/{}'.format(pkgs_path[1])
else:
self.custom_pkgs_mirror = settings.CUSTOM_PKGS_MIRROR
else:
self.custom_pkgs_mirror = settings.CUSTOM_PKGS_MIRROR