本文整理汇总了Python中fuelweb_test.helpers.ssh_manager.SSHManager.execute方法的典型用法代码示例。如果您正苦于以下问题:Python SSHManager.execute方法的具体用法?Python SSHManager.execute怎么用?Python SSHManager.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fuelweb_test.helpers.ssh_manager.SSHManager
的用法示例。
在下文中一共展示了SSHManager.execute方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: install_pkg_2
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
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']
示例2: DockerActions
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
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)
)
示例3: rebalance_swift_ring
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
def rebalance_swift_ring(controller_ip, retry_count=5, sleep=600):
"""Check Swift ring and rebalance it if needed.
Replication should be performed on primary controller node.
Retry check several times. Wait for replication due to LP1498368.
"""
ssh = SSHManager()
cmd = "/usr/local/bin/swift-rings-rebalance.sh"
logger.debug('Check swift ring and rebalance it.')
for _ in xrange(retry_count):
try:
checkers.check_swift_ring(controller_ip)
break
except AssertionError:
result = ssh.execute(controller_ip, cmd)
logger.debug("command execution result is {0}".format(result))
else:
checkers.check_swift_ring(controller_ip)
示例4: check_ping
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
def check_ping(ip, host, deadline=10, size=56, timeout=1, interval=1):
"""Check network connectivity from remote to host using ICMP (ping)
:param ip: remote ip
:param host: string IP address or host/domain name
:param deadline: time in seconds before ping exits
:param size: size of data to be sent
:param timeout: time to wait for a response, in seconds
:param interval: wait interval seconds between sending each packet
:return: bool: True if ping command
"""
ssh_manager = SSHManager()
cmd = ("ping -W {timeout} -i {interval} -s {size} -c 1 -w {deadline} "
"{host}".format(host=host,
size=size,
timeout=timeout,
interval=interval,
deadline=deadline))
res = ssh_manager.execute(ip, cmd)
return int(res['exit_code']) == 0
示例5: EnvironmentModel
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
#.........这里部分代码省略.........
"Node {0} does not become online".format(node.name))
return True
def revert_snapshot(self, name, skip_timesync=False,
skip_slaves_check=False):
if not self.d_env.has_snapshot(name):
return False
logger.info('We have snapshot with such name: {:s}'.format(name))
logger.info("Reverting the snapshot '{0}' ....".format(name))
self.d_env.revert(name)
logger.info("Resuming the snapshot '{0}' ....".format(name))
self.resume_environment()
if not skip_timesync:
self.sync_time()
try:
_wait(self.fuel_web.client.get_releases,
expected=EnvironmentError, timeout=300)
except exceptions.Unauthorized:
self.set_admin_keystone_password()
self.fuel_web.get_nailgun_version()
if not skip_slaves_check:
_wait(lambda: self.check_slaves_are_ready(), timeout=60 * 6)
return True
def set_admin_ssh_password(self):
new_login = settings.SSH_FUEL_CREDENTIALS['login']
new_password = settings.SSH_FUEL_CREDENTIALS['password']
try:
self.ssh_manager.execute_on_remote(
ip=self.ssh_manager.admin_ip,
cmd='date'
)
logger.debug('Accessing admin node using SSH: SUCCESS')
except Exception:
logger.debug('Accessing admin node using SSH credentials:'
' FAIL, trying to change password from default')
self.ssh_manager.initialize(
admin_ip=self.ssh_manager.admin_ip,
admin_login='root',
admin_password='r00tme',
slave_login=settings.SSH_SLAVE_CREDENTIALS['login'],
slave_password=settings.SSH_SLAVE_CREDENTIALS['password']
)
self.ssh_manager.execute_on_remote(
ip=self.ssh_manager.admin_ip,
cmd='echo -e "{1}\\n{1}" | passwd {0}'.format(new_login,
new_password)
)
self.ssh_manager.initialize(
admin_ip=self.ssh_manager.admin_ip,
admin_login=new_login,
admin_password=new_password,
slave_login=settings.SSH_SLAVE_CREDENTIALS['login'],
slave_password=settings.SSH_SLAVE_CREDENTIALS['password']
)
self.ssh_manager.update_connection(
ip=self.ssh_manager.admin_ip,
login=new_login,
password=new_password
)
logger.debug("Admin node password has changed.")
示例6: BaseActions
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
class BaseActions(object):
"""BaseActions.""" # TODO documentation
def __init__(self):
self.ssh_manager = SSHManager()
self.admin_ip = self.ssh_manager.admin_ip
def __repr__(self):
klass, obj_id = type(self), hex(id(self))
return "[{klass}({obj_id})]".format(
klass=klass,
obj_id=obj_id)
# TODO(kozhukalov): This method seems not needed and
# can easily be replaced by using execute_on_remote
# available in SSHManager (up to the type of return value)
def execute(self, cmd, exit_code=None, stdin=None):
if stdin is not None:
cmd = 'echo "{0}" | {1}'.format(stdin, cmd)
result = self.ssh_manager.execute(
ip=self.admin_ip,
cmd=cmd
)
if exit_code is not None:
assert_equal(exit_code,
result['exit_code'],
('Command {cmd} returned exit code "{e}", but '
'expected "{c}". Output: {out}; {err} ').format(
cmd=cmd,
e=result['exit_code'],
c=exit_code,
out=result['stdout'],
err=result['stderr']
))
return ''.join(result['stdout']).strip()
def restart_service(self, service):
result = self.ssh_manager(
ip=self.admin_ip,
cmd="systemctl restart {0}".format(service))
return result['exit_code'] == 0
def put_value_to_local_yaml(self, old_file, new_file, element, value):
"""Changes content in old_file at element is given to the new value
and creates new file with changed content
:param old_file: a path to the file content from to be changed
:param new_file: a path to the new file to ve created with new content
:param element: tuple with path to element to be changed
for example: ['root_elem', 'first_elem', 'target_elem']
if there are a few elements with equal names use integer
to identify which element should be used
:return: nothing
"""
with open(old_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
origin_yaml = yaml_dict
for k in element[:-1]:
yaml_dict = yaml_dict[k]
yaml_dict[element[-1]] = value
with open(new_file, 'w') as f_new:
yaml.dump(origin_yaml, f_new, default_flow_style=False,
default_style='"')
def get_value_from_local_yaml(self, yaml_file, element):
"""Get a value of the element from the local yaml file
:param str yaml_file: a path to the yaml file
:param list element:
list with path to element to be read
for example: ['root_elem', 'first_elem', 'target_elem']
if there are a few elements with equal names use integer
to identify which element should be used
:return obj: value
"""
with open(yaml_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
for i, k in enumerate(element):
try:
yaml_dict = yaml_dict[k]
except IndexError:
raise IndexError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
except KeyError:
raise KeyError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
return yaml_dict
def change_remote_yaml(self, path_to_file, element, value):
"""Changes values in the yaml file stored
There is no need to copy file manually
:param path_to_file: absolute path to the file
:param element: list with path to the element be changed
:param value: new value for element
:return: Nothing
"""
#.........这里部分代码省略.........
示例7: CustomRepo
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
#.........这里部分代码省略.........
'filename:': flist_file}
# TODO: add dependencies list to cpkg
self.pkgs_list.append(cpkg)
# Download packages (local_folder)
def download_pkgs(self, pkgs_local_path):
# Process the packages list:
total_pkgs = len(self.pkgs_list)
logger.info('Found {0} custom package(s)'.format(total_pkgs))
for npkg, pkg in enumerate(self.pkgs_list):
# TODO: Previous versions of the updating packages must be removed
# to avoid unwanted packet manager dependencies resolution
# (when some package still depends on other package which
# is not going to be installed)
logger.info('({0}/{1}) Downloading package: {2}/{3}'
.format(npkg + 1, total_pkgs,
self.custom_pkgs_mirror,
pkg["filename:"]))
pkg_ext = pkg["filename:"].split('.')[-1]
if pkg_ext == 'deb':
path_suff = 'main/'
elif pkg_ext == 'udeb':
path_suff = 'debian-installer/'
else:
path_suff = ''
wget_cmd = "wget --no-verbose --directory-prefix {0} {1}/{2}"\
.format(pkgs_local_path + path_suff,
self.custom_pkgs_mirror,
pkg["filename:"])
wget_result = self.ssh_manager.execute(
ip=self.ip,
cmd=wget_cmd
)
assert_equal(0, wget_result['exit_code'],
self.assert_msg(wget_cmd, wget_result['stderr']))
# Upload regenerate* script to masternode (script name)
def regenerate_repo(self, regenerate_script, local_mirror_path):
# Uploading scripts that prepare local repositories:
# 'regenerate_centos_repo' and 'regenerate_ubuntu_repo'
try:
self.ssh_manager.upload_to_remote(
ip=self.ip,
source='{0}/{1}'.format(self.path_scripts, regenerate_script),
target=self.remote_path_scripts
)
self.ssh_manager.execute_on_remote(
ip=self.ip,
cmd='chmod 755 {0}/{1}'.format(self.remote_path_scripts,
regenerate_script)
)
except Exception:
logger.error('Could not upload scripts for updating repositories.'
'\n{0}'.format(traceback.format_exc()))
raise
# Update the local repository using previously uploaded script.
script_cmd = '{0}/{1} {2} {3}'.format(self.remote_path_scripts,
regenerate_script,
local_mirror_path,
self.ubuntu_release)
script_result = self.ssh_manager.execute(
示例8: EnvironmentModel
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
#.........这里部分代码省略.........
try:
wait(lambda: self.fuel_web.get_nailgun_node_by_devops_node(node)["online"], timeout=60 * 6)
except TimeoutError:
raise TimeoutError("Node {0} does not become online".format(node.name))
return True
def revert_snapshot(self, name, skip_timesync=False):
if not self.d_env.has_snapshot(name):
return False
logger.info("We have snapshot with such name: %s" % name)
logger.info("Reverting the snapshot '{0}' ....".format(name))
self.d_env.revert(name)
logger.info("Resuming the snapshot '{0}' ....".format(name))
self.resume_environment()
if not skip_timesync:
self.sync_time()
try:
_wait(self.fuel_web.client.get_releases, expected=EnvironmentError, timeout=300)
except exceptions.Unauthorized:
self.set_admin_keystone_password()
self.fuel_web.get_nailgun_version()
_wait(lambda: self.check_slaves_are_ready(), timeout=60 * 6)
return True
def set_admin_ssh_password(self):
new_login = settings.SSH_CREDENTIALS["login"]
new_password = settings.SSH_CREDENTIALS["password"]
try:
self.ssh_manager.execute_on_remote(ip=self.ssh_manager.admin_ip, cmd="date")
logger.debug("Accessing admin node using SSH: SUCCESS")
except Exception:
logger.debug("Accessing admin node using SSH credentials:" " FAIL, trying to change password from default")
self.ssh_manager.initialize(admin_ip=self.ssh_manager.admin_ip, login="root", password="r00tme")
self.ssh_manager.execute_on_remote(
ip=self.ssh_manager.admin_ip, cmd='echo -e "{1}\\n{1}" | passwd {0}'.format(new_login, new_password)
)
self.ssh_manager.initialize(admin_ip=self.ssh_manager.admin_ip, login=new_login, password=new_password)
self.ssh_manager.update_connection(ip=self.ssh_manager.admin_ip, login=new_login, password=new_password)
logger.debug("Admin node password has changed.")
logger.info("Admin node login name: '{0}' , password: '{1}'".format(new_login, new_password))
def set_admin_keystone_password(self):
try:
self.fuel_web.client.get_releases()
# TODO(akostrikov) CENTOS7 except exceptions.Unauthorized:
except:
self.ssh_manager.execute_on_remote(
ip=self.ssh_manager.admin_ip,
cmd="fuel user --newpass {0} --change-password".format(settings.KEYSTONE_CREDS["password"]),
)
logger.info(
'New Fuel UI (keystone) username: "{0}", password: "{1}"'.format(
settings.KEYSTONE_CREDS["username"], settings.KEYSTONE_CREDS["password"]
)
)
def insert_cdrom_tray(self):
# This is very rude implementation and it SHOULD be changes after
# implementation this feature in fuel-devops
name = "{}_{}".format(settings.ENV_NAME, self.d_env.nodes().admin.name)
NAME_SIZE = 80
示例9: BaseActions
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
class BaseActions(object):
"""BaseActions.""" # TODO documentation
def __init__(self):
self.ssh_manager = SSHManager()
self.admin_ip = self.ssh_manager.admin_ip
self.container = None
def __repr__(self):
klass, obj_id = type(self), hex(id(self))
container = getattr(self, 'container', None)
return "[{klass}({obj_id}), container:{container}]".format(
klass=klass,
obj_id=obj_id,
container=container)
def execute_in_container(self, command, container=None, exit_code=None,
stdin=None):
if not container:
container = self.container
cmd = 'dockerctl shell {0} {1}'.format(container, command)
if stdin is not None:
cmd = 'echo "{0}" | {1}'.format(stdin, cmd)
result = self.ssh_manager.execute(
ip=self.admin_ip,
cmd=cmd
)
if exit_code is not None:
assert_equal(exit_code,
result['exit_code'],
('Command {cmd} returned exit code "{e}", but '
'expected "{c}". Output: {out}; {err} ').format(
cmd=cmd,
e=result['exit_code'],
c=exit_code,
out=result['stdout'],
err=result['stderr']
))
return ''.join(result['stdout']).strip()
def copy_between_node_and_container(self, copy_from, copy_to):
""" Copy files from/to container.
:param copy_from: path to copy file from
:param copy_to: path to copy file to
For ex.:
- to copy from container to master node use:
copy_from = container:path_from
copy_to = path_to
- to copy from master node to container use:
copy_from = path_from
copy_to = container:path_to
:return:
Standard output from console
"""
cmd = 'dockerctl copy {0} {1}'.format(copy_from, copy_to)
result = self.ssh_manager.execute(
ip=self.admin_ip,
cmd=cmd
)
assert_equal(0, result['exit_code'],
('Command copy returned exit code "{e}", but '
'expected "0". Output: {out}; {err} ').format(
cmd=cmd,
e=result['exit_code'],
out=result['stdout'],
err=result['stderr']))
return ''.join(result['stdout']).strip()
@property
def is_container_ready(self):
result = self.ssh_manager.execute(
ip=self.admin_ip,
cmd="timeout 5 dockerctl check {0}".format(self.container)
)
return result['exit_code'] == 0
def wait_for_ready_container(self, timeout=300):
wait(lambda: self.is_container_ready, timeout=timeout)
def put_value_to_local_yaml(self, old_file, new_file, element, value):
"""Changes content in old_file at element is given to the new value
and creates new file with changed content
:param old_file: a path to the file content from to be changed
:param new_file: a path to the new file to ve created with new content
:param element: tuple with path to element to be changed
for example: ['root_elem', 'first_elem', 'target_elem']
if there are a few elements with equal names use integer
to identify which element should be used
:return: nothing
"""
with open(old_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
origin_yaml = yaml_dict
for k in element[:-1]:
yaml_dict = yaml_dict[k]
#.........这里部分代码省略.........
示例10: BaseActions
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
class BaseActions(object):
"""BaseActions.""" # TODO documentation
def __init__(self):
self.ssh_manager = SSHManager()
self.admin_ip = self.ssh_manager.admin_ip
def __repr__(self):
klass, obj_id = type(self), hex(id(self))
return "[{klass}({obj_id})]".format(
klass=klass,
obj_id=obj_id)
def restart_service(self, service):
result = self.ssh_manager.execute(
ip=self.admin_ip,
cmd="systemctl restart {0}".format(service))
return result['exit_code'] == 0
@staticmethod
def put_value_to_local_yaml(old_file, new_file, element, value):
"""Changes content in old_file at element is given to the new value
and creates new file with changed content
:param old_file: a path to the file content from to be changed
:param new_file: a path to the new file to ve created with new content
:param element: tuple with path to element to be changed
for example: ['root_elem', 'first_elem', 'target_elem']
if there are a few elements with equal names use integer
to identify which element should be used
:return: nothing
"""
with open(old_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
origin_yaml = yaml_dict
for k in element[:-1]:
yaml_dict = yaml_dict[k]
yaml_dict[element[-1]] = value
with open(new_file, 'w') as f_new:
yaml.dump(origin_yaml, f_new, default_flow_style=False,
default_style='"')
@staticmethod
def get_value_from_local_yaml(yaml_file, element):
"""Get a value of the element from the local yaml file
:param str yaml_file: a path to the yaml file
:param list element:
list with path to element to be read
for example: ['root_elem', 'first_elem', 'target_elem']
if there are a few elements with equal names use integer
to identify which element should be used
:return obj: value
"""
with open(yaml_file, 'r') as f_old:
yaml_dict = yaml.load(f_old)
for i, k in enumerate(element):
try:
yaml_dict = yaml_dict[k]
except IndexError:
raise IndexError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
except KeyError:
raise KeyError("Element {0} not found in the file {1}"
.format(element[: i + 1], f_old))
return yaml_dict
def change_remote_yaml(self, path_to_file, element, value):
"""Changes values in the yaml file stored
There is no need to copy file manually
:param path_to_file: absolute path to the file
:param element: list with path to the element be changed
:param value: new value for element
:return: Nothing
"""
old_file = '/tmp/temp_file_{0}.old.yaml'.format(str(os.getpid()))
new_file = '/tmp/temp_file_{0}.new.yaml'.format(str(os.getpid()))
self.ssh_manager.download_from_remote(
ip=self.admin_ip,
destination=path_to_file,
target=old_file
)
self.put_value_to_local_yaml(old_file, new_file, element, value)
self.ssh_manager.upload_to_remote(
ip=self.admin_ip,
source=new_file,
target=path_to_file
)
os.remove(old_file)
os.remove(new_file)
def get_value_from_remote_yaml(self, path_to_file, element):
"""Get a value from the yaml file stored
on the master node
:param str path_to_file: absolute path to the file
#.........这里部分代码省略.........
示例11: EnvironmentModel
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
#.........这里部分代码省略.........
def revert_snapshot(self, name, skip_timesync=False):
if not self.d_env.has_snapshot(name):
return False
logger.info('We have snapshot with such name: %s' % name)
logger.info("Reverting the snapshot '{0}' ....".format(name))
self.d_env.revert(name)
logger.info("Resuming the snapshot '{0}' ....".format(name))
self.resume_environment()
if not skip_timesync:
nailgun_nodes = [self.fuel_web.get_nailgun_node_by_name(node.name)
for node in self.d_env.nodes().slaves
if node.driver.node_active(node)]
self.sync_time(nailgun_nodes)
try:
_wait(self.fuel_web.client.get_releases,
expected=EnvironmentError, timeout=300)
except exceptions.Unauthorized:
self.set_admin_keystone_password()
self.fuel_web.get_nailgun_version()
_wait(lambda: self.check_slaves_are_ready(), timeout=60 * 6)
return True
def set_admin_ssh_password(self):
new_login = settings.SSH_CREDENTIALS['login']
new_password = settings.SSH_CREDENTIALS['password']
try:
self.ssh_manager.execute_on_remote(
ip=self.ssh_manager.admin_ip,
cmd='date'
)
logger.debug('Accessing admin node using SSH: SUCCESS')
except Exception:
logger.debug('Accessing admin node using SSH credentials:'
' FAIL, trying to change password from default')
self.ssh_manager.update_connection(
ip=self.ssh_manager.admin_ip,
login='root',
password='r00tme'
)
self.ssh_manager.execute_on_remote(
ip=self.ssh_manager.admin_ip,
cmd='echo -e "{1}\\n{1}" | passwd {0}'.format(new_login,
new_password)
)
self.ssh_manager.update_connection(
ip=self.ssh_manager.admin_ip,
login=new_login,
password=new_password
)
logger.debug("Admin node password has changed.")
logger.info("Admin node login name: '{0}' , password: '{1}'".
format(new_login, new_password))
def set_admin_keystone_password(self):
try:
self.fuel_web.client.get_releases()
# TODO(akostrikov) CENTOS7 except exceptions.Unauthorized:
except:
self.ssh_manager.execute_on_remote(
示例12: EnvironmentModel
# 需要导入模块: from fuelweb_test.helpers.ssh_manager import SSHManager [as 别名]
# 或者: from fuelweb_test.helpers.ssh_manager.SSHManager import execute [as 别名]
#.........这里部分代码省略.........
logger.info("We have snapshot with such name: {:s}".format(name))
logger.info("Reverting the snapshot '{0}' ....".format(name))
self.d_env.revert(name)
logger.info("Resuming the snapshot '{0}' ....".format(name))
self.resume_environment()
if not skip_timesync:
self.sync_time()
else:
self.sync_time(["admin"])
try:
with QuietLogger(upper_log_level=logging.CRITICAL):
# TODO(astudenov): add timeout_msg
wait_pass(
self.fuel_web.client.get_releases,
expected=(exceptions.RetriableConnectionFailure, exceptions.UnknownConnectionError),
timeout=300,
)
except exceptions.Unauthorized:
self.set_admin_keystone_password()
self.fuel_web.get_nailgun_version()
if not skip_slaves_check:
# TODO(astudenov): add timeout_msg
wait_pass(lambda: self.check_slaves_are_ready(), timeout=60 * 6)
return True
def set_admin_ssh_password(self):
new_login = settings.SSH_FUEL_CREDENTIALS["login"]
new_password = settings.SSH_FUEL_CREDENTIALS["password"]
try:
self.ssh_manager.execute_on_remote(ip=self.ssh_manager.admin_ip, cmd="date")
logger.debug("Accessing admin node using SSH: SUCCESS")
except Exception:
logger.debug("Accessing admin node using SSH credentials:" " FAIL, trying to change password from default")
self.ssh_manager.initialize(
admin_ip=self.ssh_manager.admin_ip,
admin_login="root",
admin_password="r00tme",
slave_login=settings.SSH_SLAVE_CREDENTIALS["login"],
slave_password=settings.SSH_SLAVE_CREDENTIALS["password"],
)
self.ssh_manager.execute_on_remote(
ip=self.ssh_manager.admin_ip, cmd='echo -e "{1}\\n{1}" | passwd {0}'.format(new_login, new_password)
)
self.ssh_manager.initialize(
admin_ip=self.ssh_manager.admin_ip,
admin_login=new_login,
admin_password=new_password,
slave_login=settings.SSH_SLAVE_CREDENTIALS["login"],
slave_password=settings.SSH_SLAVE_CREDENTIALS["password"],
)
self.ssh_manager.update_connection(ip=self.ssh_manager.admin_ip, login=new_login, password=new_password)
logger.debug("Admin node password has changed.")
logger.info("Admin node login name: '{0}' , password: '{1}'".format(new_login, new_password))
def set_admin_keystone_password(self):
try:
self.fuel_web.client.get_releases()
# TODO(akostrikov) CENTOS7 except exceptions.Unauthorized:
except:
self.ssh_manager.execute_on_remote(
ip=self.ssh_manager.admin_ip,
cmd="fuel user --newpass {0} --change-password".format(settings.KEYSTONE_CREDS["password"]),