Beispiel #1
0
#               /*/common/messageBodyEncryptionEnabled:[false]
#               /*/mss/compressionEnabled: [true]   # need mss restart
# (2) create 6 accounts:[email protected] [email protected]
# (3) clear current popserv.stat file

import basic_function
import basic_class
import imap_operations
import smtp_operations
import global_variables
import remote_operations
from sendmails import send_mail
import time

basic_class.mylogger_record.debug('Preparing... get some variables needed for tests')

mx1_search_cassandraBlobPort,mx1_cassblob_ip,mx1_mxos_host2_eureka_port,mx1_mxos_host2_ip,mx1_mss_host2_ip,mx1_mss_host1_ip,mx1_popserv_host1,mx1_popserv_host1_pop3Port,mx_account,mx1_host1_ip,root_account,root_passwd,test_account_base,mx1_default_domain = \
global_variables.get_values('mx1_search_cassandraBlobPort','mx1_cassblob_ip','mx1_mxos_host2_eureka_port','mx1_mxos_host2_ip','mx1_mss_host2_ip','mx1_mss_host1_ip','mx1_popserv_host1','mx1_popserv_host1_pop3Port','mx_account','mx1_host1_ip','root_account','root_passwd','test_account_base','mx1_default_domain')



basic_class.mylogger_record.info('step1:delete 2 accounts')
remote_operations.remote_operation(mx1_host1_ip,'su - {0} -c \'for ((i=1;i<=2;i++));do account-delete {1}$i@{2};done\''.format(mx_account,test_account_base,mx1_default_domain),root_account,root_passwd,1,'Mailbox Deleted Successfully',2)


basic_class.mylogger_record.info('step2:restore keys and restart services')
remote_operations.remote_operation(mx1_host1_ip,'su - {0} -c \'imconfcontrol -install -key \"/*/common/hostInfo=blobtier=Cassandra:blobcluster:9162\";imconfcontrol -install -key \"/*/mss/compressionEnabled=true\"\''.format(mx_account),root_account,root_passwd,0)
remote_operations.remote_operation(mx1_mss_host1_ip,'su - {0} -c \'~/lib/imservctrl killStart mss\''.format(mx_account),root_account,root_passwd,0)
remote_operations.remote_operation(mx1_mss_host2_ip,'su - {0} -c \'~/lib/imservctrl killStart mss\''.format(mx_account),root_account,root_passwd,0)

Beispiel #2
0
import basic_function
import basic_class
import imap_operations
import global_variables
import remote_operations
import time

#print (global_variables.get_value('initialpath'))

#basic_class.mylogger_record.info('Runing setup testcase:mx-12534-pop_login_10_accounts_half_pass_half_fail')
basic_class.mylogger_record.debug(
    'Preparing... get some variables needed for tests')

mx1_mxos_host1_ip,mx1_mxos_host2_ip,mx2_imapserv_host1_ip,mx2_mss_host1_ip,mx2_mta_host1_SMTPPort,mx2_mta_host1_ip,mx2_host1_ip,mx2_popserv_host1_pop3Port,mx2_popserv_host1,mx2_imapserv_host1_imap4Port,mx2_imapserv_host1,mx1_mss_host1_ip,mx1_mss_host2_ip,mx1_imapserv_host1_ip,mx1_imapserv_host1_imap4Port,mx1_mta_host1_ip,mx1_mta_host1_SMTPPort,mx1_popserv_host1_ip,mx1_popserv_host1_pop3Port,mx_account,mx1_host1_ip,root_account,root_passwd,test_account_base,mx1_default_domain,mx2_default_domain = \
global_variables.get_values('mx1_mxos_host1_ip','mx1_mxos_host2_ip','mx2_imapserv_host1_ip','mx2_mss_host1_ip','mx2_mta_host1_SMTPPort','mx2_mta_host1_ip','mx2_host1_ip','mx2_popserv_host1_pop3Port','mx2_popserv_host1','mx2_imapserv_host1_imap4Port','mx2_imapserv_host1','mx1_mss_host1_ip','mx1_mss_host2_ip','mx1_imapserv_host1_ip','mx1_imapserv_host1_imap4Port','mx1_mta_host1_ip','mx1_mta_host1_SMTPPort','mx1_popserv_host1_ip','mx1_popserv_host1_pop3Port','mx_account','mx1_host1_ip','root_account','root_passwd','test_account_base','mx1_default_domain',mx2_default_domain)

basic_class.mylogger_record.info('step1:set keys')
remote_operations.remote_operation(
    mx1_host1_ip,
    'su - {0} -c \'imconfcontrol -install -key \"/*/common/loginAliases=true\";imconfcontrol -install -key \"/*/common/perfStatThresholds=StatPopPassCommand 200\";imconfcontrol -install -key \"/*/common/reportParamsInterval=30\";imconfcontrol -install -key \"/*/common/badPasswordDelay=0\";imconfcontrol -install -key \"/*/common/maxBadPasswordDelay=0\";imconfcontrol -install -key \"/*/popserv/popProxyHost=pop://{1}:{2}\";imconfcontrol -install -key \"/*/popserv/popProxyPort={2}\";imconfcontrol -install -key \"/*/popserv/allowAPOP=true\";imconfcontrol -install -key \"/*/mxos/defaultPasswordStoreType=clear\";imconfcontrol -install -key \"/*/mxos/trustedClient=true\"\''
    .format(mx_account, mx2_popserv_host1,
            mx2_popserv_host1_pop3Port), root_account, root_passwd, 0)
remote_operations.remote_operation(
    mx2_host1_ip,
    'su - {0} -c \'imconfcontrol -install -key \"/*/common/loginAliases=true\";imconfcontrol -install -key \"/*/common/perfStatThresholds=StatPopPassCommand 200\";imconfcontrol -install -key \"/*/common/reportParamsInterval=30\";imconfcontrol -install -key \"/*/common/badPasswordDelay=0\";imconfcontrol -install -key \"/*/common/maxBadPasswordDelay=0\";imconfcontrol -install -key \"/*/popserv/allowAPOP=true\";imconfcontrol -install -key \"/*/mxos/defaultPasswordStoreType=clear\";imconfcontrol -install -key \"/*/mxos/trustedClient=true\"\''
    .format(mx_account), root_account, root_passwd, 0)

basic_class.mylogger_record.info('step2:create 10 accounts')
remote_operations.remote_operation(
    mx1_host1_ip,
Beispiel #3
0
# (2) check and analyze imapserv.stat file .make sure the total attempts are 20 ,and half passed ,half failed

import basic_function
import basic_class
import imap_operations
import global_variables
import time
import remote_operations
import stat_statistics


#step 1
basic_class.mylogger_record.info('step1:imap auth_crammd5:10 account with correct passwd, the other 5 use wrong pssswd')

mx1_imapserv_host1_ip,mx1_imapserv_host1_imap4Port,mx_account,mx1_host1_ip,root_account,root_passwd,test_account_base,mx1_default_domain = \
global_variables.get_values('mx1_imapserv_host1_ip','mx1_imapserv_host1_imap4Port','mx_account','mx1_host1_ip','root_account','root_passwd','test_account_base','mx1_default_domain')


for i in range(1,6): 
    mximap1 = imap_operations.IMAP_Ops(mx1_imapserv_host1_ip,mx1_imapserv_host1_imap4Port)
    try:
        mximap1.imap_auth_crammd5(test_account_base+str(i),test_account_base+str(i)) # using correct passwd
        basic_class.mylogger_record.info('auth_cram-md5 success')
    except:
        basic_class.mylogger_record.error('auth_cram-md5 fail')
    mximap1.imap_select()
    mximap1.imap_logout()

for i in range(6,11): 
    mximap2 = imap_operations.IMAP_Ops(mx1_imapserv_host1_ip,mx1_imapserv_host1_imap4Port)
    try:
Beispiel #4
0
import basic_function
import basic_class
import imap_operations
import global_variables
import time
import remote_operations
import stat_statistics

#step 1
basic_class.mylogger_record.info(
    'step1:imap login:5 account with correct passwd, the other 5 use wrong pssswd'
)

mx2_imap1_host_ip,mx2_mss1_host_ip,mx2_mta1_port,mx2_mta1_host_ip,mx2_host1_ip,mx2_pop1_port,mx2_pop1_host,mx2_imap1_port,mx2_imap1_host,mx1_mss1_host_ip,mx1_mss2_host_ip,mx1_imap1_host_ip,mx1_imap1_port,mx1_mta1_host_ip,mx1_mta1_port,mx1_pop1_host_ip,mx1_pop1_port,mx_account,mx1_host1_ip,root_account,root_passwd,test_account_base,default_domain = \
global_variables.get_values('mx2_imap1_host_ip','mx2_mss1_host_ip','mx2_mta1_port','mx2_mta1_host_ip','mx2_host1_ip','mx2_pop1_port','mx2_pop1_host','mx2_imap1_port','mx2_imap1_host','mx1_mss1_host_ip','mx1_mss2_host_ip','mx1_imap1_host_ip','mx1_imap1_port','mx1_mta1_host_ip','mx1_mta1_port','mx1_pop1_host_ip','mx1_pop1_port','mx_account','mx1_host1_ip','root_account','root_passwd','test_account_base','default_domain')

for i in range(1, 6):
    mximap1 = imap_operations.IMAP_Ops(mx1_imap1_host_ip, mx1_imap1_port)
    try:
        mximap1.imap_authenticate('u' + str(i) + '@' + default_domain,
                                  test_account_base +
                                  str(i))  # using correct passwd
        basic_class.mylogger_record.info('imap alias auth_plain success')
    except:
        basic_class.mylogger_record.error('imap alias auth_plain fail')
    mximap1.imap_select()
    mximap1.imap_logout()

for i in range(6, 11):
    mximap2 = imap_operations.IMAP_Ops(mx1_imap1_host_ip, mx1_imap1_port)
Beispiel #5
0
import imap_operations
import smtp_operations
import global_variables
import remote_operations
import mxos_operations_MessageBodyEncryption
import time
import requests
import cassandra_operations

result_lists = []

basic_class.mylogger_record.debug(
    'Preparing... get some variables needed for tests')

mx1_imapserv_host1_imap4Port,mx1_imapserv_host1_ip,AES_mode1,mx1_mxos_host1_eureka_port,mx1_search_cassandraBlobPort,mx1_cassblob_ip,mx1_mxos_host2_ip,ASE_key128,AES_mode1,mx1_mta_host1_SMTPPort,mx1_mta_host1_ip,mx1_mxos_host1_eureka_port,mx1_mxos_host1_ip,mx1_mss_host2_ip,mx1_mss_host1_ip,mx1_popserv_host1,mx1_popserv_host1_pop3Port,mx_account,mx1_host1_ip,root_account,root_passwd,test_account_base,mx1_default_domain = \
global_variables.get_values('mx1_imapserv_host1_imap4Port','mx1_imapserv_host1_ip','AES_mode1','mx1_mxos_host1_eureka_port','mx1_search_cassandraBlobPort','mx1_cassblob_ip','mx1_mxos_host2_ip','ASE_key128','AES_mode1','mx1_mta_host1_SMTPPort','mx1_mta_host1_ip','mx1_mxos_host1_eureka_port','mx1_mxos_host1_ip','mx1_mss_host2_ip','mx1_mss_host1_ip','mx1_popserv_host1','mx1_popserv_host1_pop3Port','mx_account','mx1_host1_ip','root_account','root_passwd','test_account_base','mx1_default_domain')

basic_class.mylogger_record.debug('step1:fetching the latest message uuid')
uuid = mxos_operations_MessageBodyEncryption.fetch_latest_message_uuid(
    mx1_mxos_host1_ip, mx1_mxos_host1_eureka_port, '*****@*****.**')

basic_class.mylogger_record.debug(
    'step2:fetch message body from cassandrablob directly')

encrypted_flag, messagebody1 = cassandra_operations.cassandra_cqlsh_fetch_messagebody(
    mx1_cassblob_ip, mx1_search_cassandraBlobPort, uuid, AES_mode1)

body_check_flag1 = messagebody1.count(
    'attachement,haha,are you OK? we love world')
basic_class.mylogger_record.debug('body_check_flag1= ' + str(body_check_flag1))
Beispiel #6
0
# (3) clear current popserv.stat file

import basic_function
import basic_class
import imap_operations
import smtp_operations
import global_variables
import remote_operations
import mxos_operations_MessageBodyEncryption
import time


basic_class.mylogger_record.debug('Preparing... get some variables needed for tests')

mx1_mxos_host2_ip,ASE_key256,AES_mode3,mx1_mta_host1_SMTPPort,mx1_mta_host1_ip,mx1_mxos_host1_eureka_port,mx1_mxos_host1_ip,mx1_mss_host2_ip,mx1_mss_host1_ip,mx1_popserv_host1,mx1_popserv_host1_pop3Port,mx_account,mx1_host1_ip,root_account,root_passwd,test_account_base,mx1_default_domain = \
global_variables.get_values('mx1_mxos_host2_ip','ASE_key256','AES_mode3','mx1_mta_host1_SMTPPort','mx1_mta_host1_ip','mx1_mxos_host1_eureka_port','mx1_mxos_host1_ip','mx1_mss_host2_ip','mx1_mss_host1_ip','mx1_popserv_host1','mx1_popserv_host1_pop3Port','mx_account','mx1_host1_ip','root_account','root_passwd','test_account_base','mx1_default_domain')

basic_class.mylogger_record.info('step1:set keys and restart services')
remote_operations.remote_operation(mx1_host1_ip,'su - {0} -c \'imconfcontrol -install -key \"/*/common/blobStoreAmazonS3Key=blobtier otosankey\";imconfcontrol -install -key \"/*/common/blobStoreAmazonS3KeyId=blobtier otosan\";imconfcontrol -install -key \"/*/common/hostInfo=blobtier=S3:scality.otosan.opwv:80\";imconfcontrol -install -key \"/*/common/messageBodyEncryptionEnabled=true\";imconfcontrol -install -key \"/*/mss/compressionEnabled=true\";imconfcontrol -install -key \"/*/mxos/ldapEncryptionDn=cn=encryption,cn=config\";imconfcontrol -install -key \"/*/mxos/ldapReadEncryptionFilter=(&(objectclass=messageBodyEncryption)(cn=encryption))\";imconfcontrol -install -key \"/*/mxos/loadRulesOrder=domain\nmailbox\ncos\nmessage\ncustom\nadminrealm\nlogging\naddressbook\nnotify\nsaml\ntasks\ndatastore\nmailinglist\nencryption\"\''.format(mx_account),root_account,root_passwd,0)
remote_operations.remote_operation(mx1_mss_host1_ip,'su - {0} -c \'~/lib/imservctrl killStart mss\''.format(mx_account),root_account,root_passwd,0)
remote_operations.remote_operation(mx1_mss_host2_ip,'su - {0} -c \'~/lib/imservctrl killStart mss mxos\''.format(mx_account),root_account,root_passwd,0)
remote_operations.remote_operation(mx1_mxos_host2_ip,'su - {0} -c \'~/lib/imservctrl killStart mxos\''.format(mx_account),root_account,root_passwd,0)

basic_class.mylogger_record.info('Sleeping 50 seconds ...')
time.sleep(50)

basic_class.mylogger_record.info('set passphrase')
cuid,cpassphrase = mxos_operations_MessageBodyEncryption.fetch_current_uid_passphrase(mx1_mxos_host1_ip,mx1_mxos_host1_eureka_port)
basic_class.mylogger_record.info('cuid,cpassphrase: '+str(cuid)+','+cpassphrase)

if int(cuid) == -1:
Beispiel #7
0
import basic_class
import imap_operations
import smtp_operations
import global_variables
import remote_operations
import mxos_operations_MessageBodyEncryption
import time
import requests
import cassandra_operations

result_lists = []

basic_class.mylogger_record.debug('Preparing... get some variables needed for tests')

mx1_imap1_port,mx1_imap1_host_ip,AES_mode5,mx1_mxos1_port,mx1_blobstore_port,mx1_blobstore_host_ip,mx1_mxos2_host_ip,ASE_key128,AES_mode1,mx1_mta1_port,mx1_mta1_host_ip,mx1_mxos1_port,mx1_mxos1_host_ip,mx1_mss2_host_ip,mx1_mss1_host_ip,mx1_pop1_host,mx1_pop1_port,mx_account,mx1_host1_ip,root_account,root_passwd,test_account_base,default_domain = \
global_variables.get_values('mx1_imap1_port','mx1_imap1_host_ip','AES_mode5','mx1_mxos1_port','mx1_blobstore_port','mx1_blobstore_host_ip','mx1_mxos2_host_ip','ASE_key128','AES_mode1','mx1_mta1_port','mx1_mta1_host_ip','mx1_mxos1_port','mx1_mxos1_host_ip','mx1_mss2_host_ip','mx1_mss1_host_ip','mx1_pop1_host','mx1_pop1_port','mx_account','mx1_host1_ip','root_account','root_passwd','test_account_base','default_domain')

basic_class.mylogger_record.debug('step1:fetching the latest message uuid')
uuid = mxos_operations_MessageBodyEncryption.fetch_latest_message_uuid(mx1_mxos1_host_ip,mx1_mxos1_port,'*****@*****.**')

basic_class.mylogger_record.debug('step2:fetch message body from cassandrablob directly')
messagebody1 = cassandra_operations.cassandra_cqlsh_fetch_messagebody(mx1_blobstore_host_ip,mx1_blobstore_port,uuid,AES_mode5)

body_check_flag1 = messagebody1.count(' we love world !!!!!!ucucucucucuc')
basic_class.mylogger_record.debug('body_check_flag1= '+str(body_check_flag1))

if body_check_flag1 >=1:
    result_lists.append('fetch messagebody from cassandra success')
else:
    result_lists.append('fetch messagebody from cassandra fail')    
Beispiel #8
0
def construct_mx_topology(root_user='', root_pass='', mx_user=''):
    """ this function used to construct topology of MX environemnt,will create auto_user.vars file """

    import os
    import paramiko
    import global_variables
    import basic_class
    import remote_operations

    if root_user:
        root_account = root_user
    else:
        root_account = global_variables.get_value('root_account')

    if root_pass:
        root_passwd = root_pass
    else:
        root_passwd = global_variables.get_value('root_passwd')

    if mx_user:
        mx_account = mx_user
    else:
        mx_account = global_variables.get_value('mx_account')

    sshport = global_variables.get_value('sshport')
    basic_class.mylogger_record.debug('root_account = ' + str(root_account))
    basic_class.mylogger_record.debug('root_passwd = ' + str(root_passwd))
    basic_class.mylogger_record.debug('mx_account = ' + str(mx_account))

    # Check if auto-user.vars file exist
    initialpath, mx_seed_host_nums = global_variables.get_values(
        'initialpath', 'mx_seed_host_nums')
    basic_class.mylogger_record.debug('target path = ' +
                                      str(initialpath + '/etc/auto-user.vars'))
    exist_flag_auto_vars = os.path.exists(initialpath + '/etc/auto-user.vars')
    basic_class.mylogger_record.debug('exist_flag_auto_vars = ' +
                                      str(exist_flag_auto_vars))
    # Determine if need create a new file
    if exist_flag_auto_vars:
        ctime_auto_vars = os.path.getctime(
            initialpath +
            '/etc/auto-user.vars')  # create time of auto-user.vars
        mtime_manu_vars = os.path.getmtime(
            initialpath +
            '/etc/manu-user.vars')  # last modify time of manu-user.vars
        basic_class.mylogger_record.debug('ctime_auto_vars = ' +
                                          str(ctime_auto_vars))
        basic_class.mylogger_record.debug('mtime_manu_vars = ' +
                                          str(mtime_manu_vars))

        if mtime_manu_vars >= ctime_auto_vars:  # mesans manu-user.vars have been modified
            regenerate_flag = 1  # create auto-user.vars again
            basic_class.mylogger_record.debug('regenerate_flag = ' +
                                              str(regenerate_flag))
            basic_class.mylogger_record.info(
                'Regenerating auto-user.vars again ...')
        else:  # skip to create auto-user.vars
            regenerate_flag = 0
            basic_class.mylogger_record.debug('regenerate_flag = ' +
                                              str(regenerate_flag))
            basic_class.mylogger_record.info(
                'Skip Regenerating auto-user.vars ...')
    else:  # create auto-user.vars if not exist
        regenerate_flag = 1
        basic_class.mylogger_record.debug('regenerate_flag = ' +
                                          str(regenerate_flag))
        basic_class.mylogger_record.info(
            'Regenerating auto-user.vars again ...')

    if regenerate_flag == 1:  # need recreate auto-user.vars
        total = []  # used to store all fetched variabled
        host_dict, port_dict, addr_dict, cass_dict = {}, {}, {}, {}
        host_sshnonpass_list = [
        ]  # to store the flag that if this host can be sshed from testmachne without password

        for xyz in range(int(mx_seed_host_nums)):
            seed_host = global_variables.get_value(
                'mx_seed_host{}_ip'.format(xyz + 1))
            basic_class.mylogger_record.debug('seed_host = ' + str(seed_host))

            # establish sh conenction with seed_host
            keyfile = os.environ['HOME'] + '/.ssh/id_rsa'
            ssh_try = paramiko.SSHClient()
            ssh_try.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            if os.path.exists(
                    keyfile):  # keyfile exist, will try to ssh withot password
                basic_class.mylogger_record.debug(
                    'Establishing ssh connection with pubkey ...')
                private_key = paramiko.RSAKey.from_private_key_file(keyfile)
                try:
                    ssh_try.connect(hostname=seed_host,
                                    port=sshport,
                                    username=root_account,
                                    pkey=private_key)
                except:
                    basic_class.mylogger_record.debug(
                        'Establishing ssh connection with pubkey failed! Will continue try with password ...'
                    )
                    basic_class.mylogger_record.debug(
                        'Establishing ssh connection with password ...')
                    try:
                        ssh_try.connect(hostname=seed_host,
                                        port=sshport,
                                        username=root_account,
                                        password=root_passwd)
                    except:
                        basic_class.mylogger_record.warning(
                            'Establishing ssh connection with password failed! Please check manually! '
                        )
                        exit(1)
                    else:
                        basic_class.mylogger_record.debug(
                            'Established ssh connection with password success!'
                        )
                else:
                    basic_class.mylogger_record.debug(
                        'Established ssh connection with pubkey success!')
            else:  # keyfile not exist, will try to ssh with password
                basic_class.mylogger_record.debug(
                    'Establishing ssh connection with password ...')
                try:
                    ssh_try.connect(hostname=seed_host,
                                    port=sshport,
                                    username=root_account,
                                    password=root_passwd)
                except:
                    basic_class.mylogger_record.warning(
                        'Establishing ssh connection with password failed! Please check manually! '
                    )
                    exit(1)
                else:
                    basic_class.mylogger_record.debug(
                        'Established ssh connection with password success!')

            #get hosts and hosts, ip, addrs
            tmp_cmd1 = 'imconfget  -hosts | grep -v cluster'
            basic_class.mylogger_record.debug('tmp_cmd1 = ' + str(tmp_cmd1))
            stdin, stdout1, stderr = ssh_try.exec_command(
                'su - {0} -c "{1}"'.format(mx_account, tmp_cmd1))
            h_lists = str(stdout1.read(), 'utf-8').split('\n')[0:-2]
            basic_class.mylogger_record.debug('h_lists = ' + str(h_lists))
            i = 0
            for h_list in h_lists:
                h_list = h_list.split()[0]
                key = 'mx' + str(xyz + 1) + '_host' + str(i + 1)
                value = str(h_list)
                addr_dict[key] = value

                tmp_cmd2 = "grep " + str(
                    h_list) + " /etc/hosts|awk \'{print $1}\' | head -1"
                basic_class.mylogger_record.debug('tmp_cmd2 = ' +
                                                  str(tmp_cmd2))
                stdin, stdout2, stderr = ssh_try.exec_command(tmp_cmd2)
                tmpip = str(stdout2.read(), 'utf-8').split('\n')[0:-1]
                basic_class.mylogger_record.debug('tmpip = ' + str(tmpip))
                key = 'mx' + str(xyz + 1) + '_host' + str(i + 1) + "_ip"
                value = ''.join(tmpip[0].split())
                addr_dict[key] = value

                # check ssh_non_password_flag
                ssh_authtype_flag = remote_operations.check_host_sshnonpassword_flag(
                    value, root_account, root_passwd)
                if ssh_authtype_flag == 1:  # auth with pubkey success
                    host_sshnonpass_list.append('sshnonpassauth_flag_' + key +
                                                ' = ' + str(ssh_authtype_flag))
                    host_sshnonpass_list.append('sshnonpassauth_flag_' +
                                                value + ' = ' +
                                                str(ssh_authtype_flag))
                elif ssh_authtype_flag == 0:  # auth with password success
                    host_sshnonpass_list.append('sshnonpassauth_flag_' + key +
                                                ' = ' + str(ssh_authtype_flag))
                    host_sshnonpass_list.append('sshnonpassauth_flag_' +
                                                value + ' = ' +
                                                str(ssh_authtype_flag))
                else:  # buth auth types failed
                    basic_class.mylogger_record.error(
                        'Establishing ssh connection with or without password failed, please check manually !'
                    )
                    host_sshnonpass_list.append('sshnonpassauth_flag_' + key +
                                                ' = ' + str(-1))
                    host_sshnonpass_list.append('sshnonpassauth_flag_' +
                                                value + ' = ' + str(-1))
                    exit(1)
                i += 1

            tmp_cmd3 = 'imconfcontrol -ports'
            basic_class.mylogger_record.debug('tmp_cmd3 = ' + str(tmp_cmd3))
            stdin, stdout3, stderr = ssh_try.exec_command(
                'su - {0} -c "{1}"'.format(mx_account, tmp_cmd3))
            tmp_list = str(stdout3.read(), 'utf-8').split('\n')[0:-1]
            basic_class.mylogger_record.debug('tmp_list = ')
            [basic_class.mylogger_recordnf.debug(tmp) for tmp in tmp_list]
            for hostports in tmp_list:
                tmp_a = hostports.split()
                if tmp_a[0].isdigit():
                    tmp_cmd4 = 'imconfget -server ' + tmp_a[2]
                    basic_class.mylogger_record.debug('tmp_cmd4 = ' +
                                                      str(tmp_cmd4))
                    stdin, stdout4, stderr = ssh_try.exec_command(
                        'su - {0} -c "{1}"'.format(mx_account, tmp_cmd4))
                    s_list = str(stdout4.read(), 'utf-8').split('\n')[0:-1]
                    basic_class.mylogger_record.debug('s_list = ' +
                                                      str(s_list))
                    for serverhosts in s_list:
                        server_tmp = serverhosts.split()
                        if len(server_tmp) > 0:
                            for i in range(len(server_tmp)):
                                key = 'mx' + str(
                                    xyz +
                                    1) + '_' + tmp_a[2] + '_host' + str(i + 1)
                                value = server_tmp[i]
                                host_dict[key] = value
                                key = 'mx' + str(xyz + 1) + '_' + tmp_a[
                                    2] + '_host' + str(i + 1) + '_ip'
                                value = [
                                    addr_dict.get(k + '_ip')
                                    for k, v in addr_dict.items()
                                    if v == server_tmp[i]
                                ]
                                host_dict[key] = value[0]
                                #print(host_list)
                                key = 'mx' + str(
                                    xyz + 1) + '_' + tmp_a[2] + '_host' + str(
                                        i + 1) + '_' + tmp_a[3].replace(
                                            '.', '_')
                                value = tmp_a[0]
                                port_dict[key] = value
                                #print(port_list)
                        else:
                            key = 'mx' + str(xyz + 1) + '_' + tmp_a[
                                2] + '_' + tmp_a[3].replace('.', '_')
                            value = tmp_a[0]
                            port_dict[key] = value
                else:  #skip the titles
                    pass

            #get cassandra info
            tmp_cmd5 = 'grep hostInfo config/config.db | cut -d \':\' -f 3'
            basic_class.mylogger_record.debug('tmp_cmd5 = ' + str(tmp_cmd5))
            stdin, stdout5, stderr = ssh_try.exec_command(
                'su - {0} -c "{1}"'.format(mx_account, tmp_cmd5))
            b_n = str(stdout5.read(), 'utf-8').split('\n')[0:-1]
            basic_class.mylogger_record.debug('b_n = ' + str(b_n))
            blobtier = b_n[0].split()[0]

            tmp_cmd6 = "grep " + str(
                blobtier) + " /etc/hosts|awk \'{print $1}\' | head -1"
            basic_class.mylogger_record.debug('tmp_cmd6 = ' + str(tmp_cmd6))
            stdin, stdout6, stderr = ssh_try.exec_command(tmp_cmd6)
            tmp_ip = str(stdout6.read(), 'utf-8').split('\n')[0:-1]
            basic_class.mylogger_record.debug('tmp_ip = ' + str(tmp_ip))
            blob_ip = tmp_ip[0].split()[0]
            cass_dict['mx' + str(xyz + 1) + '_cassblob_hosts'] = str(blobtier)
            cass_dict['mx' + str(xyz + 1) + '_cassblob_ip'] = str(blob_ip)

            tmp_cmd7 = 'grep cassandraMDCluster config/config.db | cut -d \'[\' -f 2| cut -d \']\' -f1 '
            basic_class.mylogger_record.debug('tmp_cmd7 = ' + str(tmp_cmd7))
            stdin, stdout7, stderr = ssh_try.exec_command(
                'su - {0} -c "{1}"'.format(mx_account, tmp_cmd7))
            m_n = str(stdout7.read(), 'utf-8').split('\n')[0:-1]
            basic_class.mylogger_record.debug('m_n = ' + str(m_n))
            metadata = m_n[0].split()[0]

            tmp_cmd8 = "grep " + str(
                metadata) + " /etc/hosts|awk \'{print $1}\' | head -1"
            stdin, stdout8, stderr = ssh_try.exec_command(tmp_cmd8)
            tmp_ip = str(stdout8.read(), 'utf-8').split('\n')[0:-1]
            basic_class.mylogger_record.debug('tmp_ip = ' + str(tmp_ip))
            meta_ip = tmp_ip[0].split()[0]
            cass_dict['mx' + str(xyz + 1) + '_cassmeta_hosts'] = str(metadata)
            cass_dict['mx' + str(xyz + 1) + '_cassmeta_ip'] = str(meta_ip)

            # get default domain
            tmp_cmd9 = "imconfget -fullpath '/*/common/domainName'"
            stdin, stdout9, stderr = ssh_try.exec_command(
                'su - {0} -c "{1}"'.format(mx_account, tmp_cmd9))
            default_domain = str(stdout9.read(), 'utf-8').split('\n')[0:-1]
            default_domain = default_domain[0].split()[0]
            basic_class.mylogger_record.debug('default_domain = ' +
                                              str(default_domain))
            host_dict['mx' + str(xyz + 1) +
                      '_default_domain'] = str(default_domain)

            ssh_try.close()

        user_var_file = open('etc/auto-user.vars', "w")
        #tmp_list=list(set(host_list+port_list+addr_list+cass_list))
        for tck, tcv in sorted(addr_dict.items(),
                               key=lambda addr_dict: addr_dict[0]):
            total.append(tck + ' = ' + tcv)
        for tck, tcv in sorted(host_dict.items(),
                               key=lambda host_dict: host_dict[0]):
            total.append(tck + ' = ' + tcv)
        for tck, tcv in sorted(port_dict.items(),
                               key=lambda port_dict: port_dict[0]):
            total.append(tck + ' = ' + tcv)
        for tck, tcv in sorted(cass_dict.items(),
                               key=lambda cass_dict: cass_dict[0]):
            total.append(tck + ' = ' + tcv)
        total.extend(host_sshnonpass_list)
        basic_class.mylogger_record.debug('total = ' + str(total))

        for item in sorted(total):
            user_var_file.write(item + "\n")
        user_var_file.close()
    else:
        pass

    basic_class.mylogger_record.debug('Importing auto-user.vars ...')
    global_variables.import_variables_from_file([
        initialpath + '/etc/auto-user.vars'
    ])  # read auto generated users.vars