fixed pep8 errors

This commit is contained in:
Borne Mace 2015-09-08 19:54:46 -07:00
parent b10138b4b7
commit c6d15274d8
6 changed files with 63 additions and 71 deletions

View File

@ -23,8 +23,8 @@ from tempfile import mkstemp
from kollacli import exceptions
from kollacli import utils
from kollacli.sshutils import ssh_setup_host
from kollacli.exceptions import CommandError
from kollacli.sshutils import ssh_setup_host
ANSIBLE_SSH_USER = 'ansible_ssh_user'
ANSIBLE_CONNECTION = 'ansible_connection'
@ -110,38 +110,35 @@ class Host(object):
def upgrade(self):
pass
#TODO(bmace) needs to be updated to use ansible
# def check(self):
# sshKeysExist = ssh_check_keys()
# if not sshKeysExist:
# try:
# ssh_keygen()
# except Exception as e:
# raise exceptions.CommandError(
# 'ERROR: ssh key generation failed on local host : %s'
# % str(e))
#
# try:
# self.log.info('Starting check of host (%s)' % self.name)
# ssh_check_host(self.name)
# self.log.info('Host (%s), check succeeded' % self.name)
#
# except CommandError as e:
# raise e
# except Exception as e:
# raise Exception(
# 'ERROR: Host (%s), check failed. Reason : %s'
# % (self.name, str(e)))
# return True
# TODO(bmace) needs to be updated to use ansible
# def check(self):
# sshKeysExist = ssh_check_keys()
# if not sshKeysExist:
# try:
# ssh_keygen()
# except Exception as e:
# raise exceptions.CommandError(
# 'ERROR: ssh key generation failed on local host : %s'
# % str(e))
# try:
# self.log.info('Starting check of host (%s)' % self.name)
# ssh_check_host(self.name)
# self.log.info('Host (%s), check succeeded' % self.name)
# except CommandError as e:
# raise e
# except Exception as e:
# raise Exception(
# 'ERROR: Host (%s), check failed. Reason : %s'
# % (self.name, str(e)))
# return True
def setup(self, password):
# self._setup_keys()
# self._setup_keys()
# check if already setup
# if self._is_setup():
# self.log.info('Setup skipped for host (%s), ' % self.name +
# 'kolla already setup')
# return True
# if self._is_setup():
# self.log.info('Setup skipped for host (%s), ' % self.name +
# 'kolla already setup')
# return True
# not setup- we need to set up the user / remote ssh keys
# using root and the available password
@ -156,17 +153,16 @@ class Host(object):
% (self.name, str(e)))
return True
#TODO(bmace) change to use ansible for check
# def _is_setup(self):
# is_setup = False
# try:
# ssh_check_host(self.name)
# is_setup = True
#
# except Exception as e:
# self.log.debug('%s' % str(e))
# pass
# return is_setup
# TODO(bmace) change to use ansible for check
# def _is_setup(self):
# is_setup = False
# try:
# ssh_check_host(self.name)
# is_setup = True
# except Exception as e:
# self.log.debug('%s' % str(e))
# pass
# return is_setup
class HostGroup(object):

View File

@ -13,8 +13,6 @@
# under the License.
import logging
import os
from shutil import move
from tempfile import mkstemp
import yaml
from kollacli.utils import get_kolla_etc
@ -106,7 +104,6 @@ class AnsibleProperties(object):
for key, value in self.unique_properties.items():
unique_list.append(value)
return sorted(unique_list, key=lambda x: x.name)
def filter_jinja2(self, contents):
for key, value in contents.items():
@ -177,6 +174,7 @@ class AnsibleProperties(object):
except Exception as e:
raise e
class AnsibleProperty(object):
def __init__(self, name, value, file_name):

View File

@ -131,9 +131,8 @@ class HostCheck(Command):
def take_action(self, parsed_args):
try:
hostname = parsed_args.hostname.strip()
self.log.info('check currently disabled, in work')
# hostname = parsed_args.hostname.strip()
# inventory = Inventory.load()
# host = inventory.get_host(hostname)
# if not host:

View File

@ -40,7 +40,7 @@ class PropertySet(Command):
ansible_properties = properties.AnsibleProperties()
ansible_properties.set_property(property_name, property_value)
except Exception as e:
except Exception:
raise Exception(traceback.format_exc())
@ -61,7 +61,7 @@ class PropertyClear(Command):
ansible_properties = properties.AnsibleProperties()
ansible_properties.clear_property(property_name)
except Exception as e:
except Exception:
raise Exception(traceback.format_exc())

View File

@ -22,42 +22,41 @@ from kollacli.exceptions import CommandError
from kollacli.utils import get_admin_user
from kollacli.utils import get_kollacli_etc
from kollacli.utils import get_setup_user
from kollacli.utils import get_pk_bits
from kollacli.utils import get_pk_password
# from kollacli.utils import get_pk_bits
# from kollacli.utils import get_pk_password
MIN_DOCKER_VERSION = '1.8.1'
def ssh_connect(net_addr, username, password):
log = logging.getLogger(__name__)
try:
logging.getLogger('paramiko').setLevel(logging.WARNING)
ssh_client = paramiko.SSHClient()
# private_key = ssh_get_private_key()
# private_key = ssh_get_private_key()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# if useKeys:
# ssh_client.connect(hostname=net_addr, username=username,
# password=password, pkey=private_key)
# else:
# if useKeys:
# ssh_client.connect(hostname=net_addr, username=username,
# password=password, pkey=private_key)
# else:
ssh_client.connect(hostname=net_addr, username=username,
password=password)
return ssh_client
except Exception as e:
except Exception:
_close_ssh_client(ssh_client)
raise Exception(traceback.format_exc())
#TODO(bmace) check host should be done with ansible
#def ssh_check_host(net_addr):
# log = logging.getLogger(__name__)
# ssh_client = None
# try:
# ssh_client = ssh_connect(net_addr, get_admin_user(), '', True)
# _pre_setup_checks(ssh_client, log)
# _post_setup_checks(net_addr, log)
# TODO(bmace) check host should be done with ansible
# def ssh_check_host(net_addr):
# log = logging.getLogger(__name__)
# ssh_client = None
# try:
# ssh_client = ssh_connect(net_addr, get_admin_user(), '', True)
# _pre_setup_checks(ssh_client, log)
# _post_setup_checks(net_addr, log)
#
# finally:
# _close_ssh_client(ssh_client)
# finally:
# _close_ssh_client(ssh_client)
def ssh_setup_host(net_addr, password):
@ -71,8 +70,8 @@ def ssh_setup_host(net_addr, password):
ssh_client = ssh_connect(net_addr, setup_user, password)
# before modifying the host, check that it meets requirements
#_pre_setup_checks(ssh_client, log)
#TODO(bmace) pre / post checks should be done with ansible
# _pre_setup_checks(ssh_client, log)
# TODO(bmace) pre / post checks should be done with ansible
# populate authorized keys file w/ public key
cmd = ('sudo su - %s -c "echo \'%s\' >> %s/.ssh/authorized_keys"'
@ -80,7 +79,7 @@ def ssh_setup_host(net_addr, password):
_exec_ssh_cmd(cmd, ssh_client, log)
# verify ssh connection to the new account
#_post_setup_checks(net_addr, log)
# _post_setup_checks(net_addr, log)
except Exception as e:
raise e

View File

@ -109,7 +109,7 @@ class KollaCliTest(testtools.TestCase):
def _init_file(self, filepath):
if os.path.exists(filepath):
os.remove(filepath)
with open(filepath, 'w') as _:
with open(filepath, 'w'):
pass
def _init_dir(self, path):