Esempio n. 1
0
 def _scp_file(self, url):
     file_name = url.split('/')[-1]
     logs.debug_3("scp file %s from RackHD" % url)
     if not os.path.exists(file_name):
         path = url[6:]
         rackhd_hostname = fit_common.fitargs()['rackhd_host']
         scp_file = fit_common.fitcreds(
         )['rackhd_host'][0]['username'] + '@{0}:{1}'.format(
             rackhd_hostname, path)
         cmd = 'scp -o StrictHostKeyChecking=no {0} .'.format(scp_file)
         logs.debug_3("scp command : '{0}'".format(cmd))
         logfile_redirect = None
         if fit_common.VERBOSITY >= 9:
             logfile_redirect = sys.stdout
         (command_output, ecode) = pexpect.run(
             cmd,
             withexitstatus=1,
             events={
                 '(?i)assword: ':
                 fit_common.fitcreds()['rackhd_host'][0]['password'] + '\n'
             },
             logfile=logfile_redirect)
         assert ecode == 0, 'failed "{0}" because {1}. Output={2}'.format(
             cmd, ecode, command_output)
     return file_name
Esempio n. 2
0
 def test01_set_auth_user(self):
     fit_common.remote_shell('rm auth.json')
     auth_json = open('auth.json', 'w')
     auth_json.write('{"username":"******"api"][0]["admin_user"] + '", "password":"******"api"][0]["admin_pass"] + '", "role":"Administrator"}')
     auth_json.close()
     fit_common.scp_file_to_ora('auth.json')
     rc = fit_common.remote_shell("curl -ks -X POST -H 'Content-Type:application/json' https://localhost:" +
                                  str(fit_common.fitports()['https']) + "/api/2.0/users -d @auth.json")
     if rc['exitcode'] != 0:
         log.info_5("ALERT: Auth admin user not set! Please manually set the admin user account if required.")
    def test04_setup_rackhd_docker_services(self):
        # add the .env variables for HOST IP into the ".env" file
        envfile = open("envfile", 'w')
        envfile.write("TAG=latest\n")
        envfile.write("REGISTRY_IP=172.31.128.1\n")
        host_ip = "HOST_IP=" + socket.gethostbyname(fit_common.fitcfg()['rackhd_host']) + "\n"
        envfile.write(host_ip)
        envfile.close()
        fit_common.scp_file_to_ora("envfile")
        self.assertEqual(fit_common.remote_shell('cp envfile /home/onrack/.env'
                                                 )['exitcode'], 0, "copy of env file failed.")
        os.remove('envfile')

        # Get the username and password from config-mn/credentials.json
        username = fit_common.fitcreds()['docker_hub'][0]['username']
        password = fit_common.fitcreds()['docker_hub'][0]['password']
        command = 'cd rackhd/docker/dell; sudo docker login --username='******' --password='******'exitcode'], 0, "Docker login failed.")

        # Docker up consul
        command = "cd rackhd/docker/dell; sudo docker-compose up -d consul"
        self.assertEqual(fit_common.remote_shell(command)['exitcode'], 0, "Docker up consul failed.")
        time.sleep(30)

        command = "cd rackhd/docker/dell; sudo chmod +x set_config.sh; sudo ./set_config.sh"
        self.assertEqual(fit_common.remote_shell(command)['exitcode'], 0, "set_config.sh failed.")

        # Docker up the rest of micro service containers
        command = "cd rackhd/docker/dell; sudo docker-compose up -d"
        self.assertEqual(fit_common.remote_shell(command)['exitcode'], 0, "docker-compose up failed.")
        time.sleep(180)

        # Set port to 8080 in smi config file
        port_var = fit_common.fitports()['http']
        command = "cd rackhd/docker/dell; sudo sed -i 's/9090/" + str(port_var) + "/g' set_rackhd_smi_config.sh"
        self.assertEqual(fit_common.remote_shell(command)['exitcode'], 0, "set_rackhd_smi_config.sh failed.")

        # Populates smi config file
        command = "cd rackhd/docker/dell; sudo ./set_rackhd_smi_config.sh"
        self.assertEqual(fit_common.remote_shell(command)['exitcode'], 0, "set_rackhd_smi_config.sh failed.")

        # Replace  callback Uri port from 9988 to 9080 in smi config file
        command = "cd /opt/monorail; sudo sed -i 's/9988/9080/g' smiConfig.json"
        self.assertEqual(fit_common.remote_shell(command)['exitcode'], 0, "Change port from 9988 to 9080 in smiConfig failed.")

        # Restart on-http service
        command = "sudo service on-http restart"
        self.assertEqual(fit_common.remote_shell(command)['exitcode'], 0, "failed to start on-http service.")
Esempio n. 4
0
 def _apply_obmsetting_to_node(self, nodeid):
     # usr = ''
     # pwd = ''
     response = fit_common.rackhdapi('/api/2.0/nodes/' + nodeid +
                                     '/catalogs/bmc')
     bmcip = response['json']['data']['IP Address']
     # Try credential record in config file
     for creds in fit_common.fitcreds()['bmc']:
         if fit_common.remote_shell('ipmitool -I lanplus -H ' + bmcip +
                                    ' -U ' + creds['username'] + ' -P ' +
                                    creds['password'] +
                                    ' fru')['exitcode'] == 0:
             usr = creds['username']
             pwd = creds['password']
             break
     # Put the credential to OBM settings
     if usr != "":
         payload = {
             "service": "ipmi-obm-service",
             "config": {
                 "host": bmcip,
                 "user": usr,
                 "password": pwd
             },
             "nodeId": nodeid
         }
         api_data = fit_common.rackhdapi("/api/2.0/obms",
                                         action='put',
                                         payload=payload)
         if api_data['status'] == 201:
             return True
     return False
 def __apply_obmsetting_to_node(self, nodeid):
     usr = None
     # pwd = ''
     response = fit_common.rackhdapi(
         '/api/2.0/nodes/' + nodeid + '/catalogs/bmc')
     bmcip = response['json']['data']['IP Address']
     # Try credential record in config file
     for creds in fit_common.fitcreds()['bmc']:
         if fit_common.remote_shell(
             'ipmitool -I lanplus -H ' + bmcip + ' -U ' + creds['username'] + ' -P ' +
                 creds['password'] + ' fru')['exitcode'] == 0:
             usr = creds['username']
             pwd = creds['password']
             break
     # Put the credential to OBM settings
     if usr is not None:
         payload = {
             "service": "ipmi-obm-service",
             "config": {
                 "host": bmcip,
                 "user": usr,
                 "password": pwd},
             "nodeId": nodeid}
         api_data = fit_common.rackhdapi("/api/2.0/obms", action='put', payload=payload)
         if api_data['status'] == 201:
             return True
     return False
Esempio n. 6
0
 def test11_add_management_server(self):
     log.info_5("**** Creating management server.")
     usr = ""
     pwd = ""
     # find correct BMC passwords from credentials list
     for creds in fit_common.fitcreds()['bmc']:
         if fit_common.remote_shell('ipmitool -I lanplus -H ' + fit_common.fitcfg()['bmc'] +
                                    ' -U ' + creds['username'] + ' -P ' +
                                    creds['password'] + ' fru')['exitcode'] == 0:
             usr = creds['username']
             pwd = creds['password']
     # create management node using these creds
     if usr != "" and pwd != "":
         payload = {"name": "Management Server " + str(time.time()),
                    "type": "mgmt",
                    "autoDiscover": True,
                    "obms": [{"service": "ipmi-obm-service",
                              "config": {"host": fit_common.fitcfg()['bmc'],
                                         "user": usr,
                                         "password": pwd}}]}
         api_data = fit_common.rackhdapi("/api/2.0/nodes", action='post', payload=payload)
         self.assertEqual(api_data['status'], 201,
                          'Incorrect HTTP return code, expecting 201, got ' + str(api_data['status']))
     else:
         self.fail("Unable to contact management server BMC, skipping MGMT node create")
 def _scp_file(self, url):
     file_name = url.split('/')[-1]
     logs.debug_3("scp file %s from RackHD" % url)
     if os.path.exists(file_name) is False:
         path = url[6:]
         rackhd_hostname = fit_common.fitargs()['rackhd_host']
         scp_file = fit_common.fitcreds()['rackhd_host'][0]['username'] + '@{0}:{1}'.format(rackhd_hostname, path)
         cmd = 'scp -o StrictHostKeyChecking=no {0} .'.format(scp_file)
         logs.debug_3("scp command : '{0}'".format(cmd))
         if fit_common.VERBOSITY >= 9:
             logfile_redirect = sys.stdout
         (command_output, ecode) = pexpect.run(
             cmd, withexitstatus=1,
             events={'(?i)assword: ': fit_common.fitcreds()['rackhd_host'][0]['password'] + '\n'},
             logfile=logfile_redirect)
         assert ecode == 0, 'failed "{0}" because {1}. Output={2}'.format(cmd, ecode, command_output)
     return file_name
Esempio n. 8
0
    def test01_install_ova_template(self):
        ovafile = fit_common.fitargs()['template']
        numvms = int(fit_common.fitargs()['numvms'])
        # Check for ovftool
        self.assertEqual(
            fit_common.subprocess.call('which ovftool', shell=True), 0,
            "FAILURE: 'ovftool' not installed.")
        # Ping for valid ESXi host
        self.assertEqual(
            fit_common.subprocess.call('ping -c 1 ' +
                                       fit_common.fitargs()['hyper'],
                                       shell=True), 0,
            "FAILURE: ESXi hypervisor not found.")

        # Run probe to check for valid OVA file
        rc = fit_common.subprocess.call("ovftool " + ovafile, shell=True)
        self.assertEqual(rc, 0, 'Invalid or missing OVA file: ' + ovafile)

        # check for number of virtual machine
        self.assertTrue(numvms < 100,
                        "Number of vms should not be greater than 99")

        # Shutdown previous ORA
        if fit_common.subprocess.call('ping -c 1 ' +
                                      fit_common.fitargs()['rackhd_host'],
                                      shell=True) == 0:
            fit_common.remote_shell('shutdown -h now')
            fit_common.time.sleep(5)

        # this clears the hypervisor ssh key from ~/.ssh/known_hosts
        subprocess.call([
            "touch ~/.ssh/known_hosts;ssh-keygen -R " +
            fit_common.fitargs()['hyper'] +
            " -f ~/.ssh/known_hosts >/dev/null 2>&1"
        ],
                        shell=True)

        # Find correct hypervisor credentials by testing each entry in the list
        cred_list = fit_common.fitcreds()['hyper']
        for entry in cred_list:
            uname = entry['username']
            passwd = entry['password']
            (command_output, exitstatus) = \
                fit_common.pexpect.run(
                                "ssh -q -o StrictHostKeyChecking=no -t " + uname + "@"
                                + fit_common.fitargs()['hyper'] + " pwd",
                                withexitstatus=1,
                                events={"assword": passwd + "\n"},
                                timeout=20, logfile=None)
            if exitstatus == 0:
                break
        # Run OVA installer
        for vm in range(0, numvms):
            self.deploy_ova(vm, uname, passwd, numvms, ovafile)
Esempio n. 9
0
 def test07_discover_pdu_node(self):
     log.info_5("**** Creating PDU node.")
     payload = {"type": "pdu",
                "name": "PDU",
                "autoDiscover": True,
                "obms": [{"service": "snmp",
                          "config": {"host": fit_common.fitcfg()['pdu'],
                                     "community": fit_common.fitcreds()['snmp'][0]['community']}}]}
     api_data = fit_common.rackhdapi("/api/2.0/nodes/", action='post', payload=payload)
     self.assertEqual(api_data['status'], 201, 'Incorrect HTTP return code, expecting 201, got ' +
                      str(api_data['status']))
Esempio n. 10
0
def guess_the_password(str_username):
    """
    Guess the password according to the username
    :param str_username: string based username
    :return: string based password on success, 1 on unable to guess
    """
    dict_cheat_sheet = {}
    for entry in fit_common.fitcreds()['bmc']:
        dict_cheat_sheet[entry['username']] = entry['password']
    if (str_username in dict_cheat_sheet) \
            and (dict_cheat_sheet[str_username] != ""):
        return dict_cheat_sheet[str_username]
    else:
        return 1
Esempio n. 11
0
 def test07_discover_pdu_node(self):
     print "**** Creating PDU node."
     payload = {
                 "type": "pdu",
                 "name": "PDU",
                 "autoDiscover": "true",
                 "snmpSettings":{
                     "host": fit_common.fitcfg()['pdu'],
                     "community": fit_common.fitcreds()['snmp'][0]['community'],
                 }
                 }
     api_data = fit_common.rackhdapi("/api/2.0/nodes/", action='post', payload=payload)
     self.assertEqual(api_data['status'], 201, 'Incorrect HTTP return code, expecting 201, got '
                      + str(api_data['status']))
Esempio n. 12
0
 def test01_set_auth_user(self):
     auth_json = open('auth.json', 'w')
     auth_json.write('{"username":"******"api"][0]["admin_user"] + '", "password":"******"api"][0]["admin_pass"] + '", "role":"Administrator"}')
     auth_json.close()
     try:
         # add first user to remote rackhd directly
         return_code = ""
         rackhd_hostname = fit_common.fitargs()['rackhd_host']
         set_auth_url = "https://" + rackhd_hostname + ":" + str(fit_common.fitports()['https']) + "/api/2.0/users"
         rc = fit_common.restful(url_command=set_auth_url, rest_action="post", rest_payload=json.load(open('auth.json')))
         return_code = str(rc['status'])
     except Exception as e:
         log.info_5("ALERT: RackHD is not in localhost, will set first user through ssh{0}".format(e))
     if return_code != '201':
         log.info_5("ALERT: Can't set first user to RackHD https port directly, will set it through ssh")
         # ssh login to rackhd and add first user to localhost rackhd
         fit_common.remote_shell('rm auth.json')
         fit_common.scp_file_to_ora('auth.json')
         rc = fit_common.remote_shell("curl -ks -X POST -H 'Content-Type:application/json' https://localhost:" +
                                      str(fit_common.fitports()['https']) + "/api/2.0/users -d @auth.json")
         if rc['exitcode'] != 0:
             log.info_5("ALERT: Auth admin user not set! Please manually set the admin user account if required.")
Esempio n. 13
0
def guess_the_password(str_username):
    """
    Guess the password according to the username
    :param str_username: string based username
    :return: string based password on success, 1 on unable to guess
    """
    dict_cheat_sheet = {}
    for entry in fit_common.fitcreds()['bmc']:
        dict_cheat_sheet[entry['username']] = entry['password']
    if (str_username in dict_cheat_sheet) \
            and (dict_cheat_sheet[str_username] != ""):
        return dict_cheat_sheet[str_username]
    else:
        return None
Esempio n. 14
0
    def test01_install_ova_template(self):
        ovafile = fit_common.fitargs()['template']
        numvms = int(fit_common.fitargs()['numvms'])
        # Check for ovftool
        self.assertEqual(fit_common.subprocess.call('which ovftool', shell=True), 0, "FAILURE: 'ovftool' not installed.")
        # Ping for valid ESXi host
        self.assertEqual(fit_common.subprocess.call('ping -c 1 ' + fit_common.fitargs()['hyper'], shell=True), 0, "FAILURE: ESXi hypervisor not found.")

        # Run probe to check for valid OVA file
        rc = fit_common.subprocess.call("ovftool " + ovafile, shell=True)
        self.assertEqual(rc, 0,'Invalid or missing OVA file: ' + ovafile)

        # check for number of virtual machine
        self.assertTrue(numvms < 100, "Number of vms should not be greater than 99")

        # Shutdown previous ORA
        if fit_common.subprocess.call('ping -c 1 ' + fit_common.fitargs()['rackhd_host'], shell=True) == 0:
            fit_common.remote_shell('shutdown -h now')
            fit_common.time.sleep(5)

        # this clears the hypervisor ssh key from ~/.ssh/known_hosts
        subprocess.call(["touch ~/.ssh/known_hosts;ssh-keygen -R "
                         + fit_common.fitargs()['hyper']  + " -f ~/.ssh/known_hosts >/dev/null 2>&1"], shell=True)

        # Find correct hypervisor credentials by testing each entry in the list
        cred_list = fit_common.fitcreds()['hyper']
        for entry in cred_list:
            uname = entry['username']
            passwd = entry['password']
            (command_output, exitstatus) = \
                fit_common.pexpect.run(
                                "ssh -q -o StrictHostKeyChecking=no -t " + uname + "@"
                                + fit_common.fitargs()['hyper'] + " pwd",
                                withexitstatus=1,
                                events={"assword": passwd + "\n"},
                                timeout=20, logfile=None)
            if exitstatus == 0:
                break
        # Run OVA installer
        for vm in range(0, numvms):
            self.deploy_ova(vm,uname,passwd,numvms,ovafile)
Esempio n. 15
0
import ConfigParser

# Check for fit-based configuration
CONFIG = os.environ.get('FIT_CONFIG', None)
if CONFIG:
    # Load FIT configuration (.json format)
    import fit_common

    defaults = fit_common.fitcfg()['cit-config']
    defaults['RACKHD_HOST'] = fit_common.fitcfg()['rackhd_host']
    defaults['RACKHD_PORT'] = fit_common.fitports()['http']
    defaults['RACKHD_PORT_AUTH'] = fit_common.fitports()['https']
    defaults['RACKHD_USER_AUTH_PORT'] = fit_common.fitports()['https']
    defaults['RACKHD_HTTPD_PORT'] = fit_common.fitports()['httpd']
    defaults['RACKHD_SSH_PORT'] = fit_common.fitports()['ssh']
    defaults['RACKHD_SSH_USER'] = fit_common.fitcreds()['rackhd_ssh'][0]['username']
    defaults['RACKHD_SSH_PASSWORD'] = fit_common.fitcreds()['rackhd_ssh'][0]['password']
    defaults['RACKHD_SMB_USER'] = fit_common.fitcreds()['rackhd_smb'][0]['username']
    defaults['RACKHD_SMB_PASSWORD'] = fit_common.fitcreds()['rackhd_smb'][0]['password']
    defaults['RACKHD_AMQP_URL'] = fit_common.fitrackhd()['amqp']

    # map from original cit repo path name to httpProxies in rackhd configuration
    mappings = {
        'RACKHD_CENTOS_REPO_PATH': '/CentOS/6.5',
        'RACKHD_ESXI_REPO_PATH': '/ESXi/6.0',
        'RACKHD_UBUNTU_REPO_PATH': '/Ubuntu/14'
    }
    for cit_path, local_path in mappings.items():
        server_path = None
        for proxy in fit_common.fitrackhd()['httpProxies']:
            if local_path == proxy['localPath']:
    def test04_setup_rackhd_docker_services(self):
        # add the .env variables for HOST IP into the ".env" file
        envfile = open("envfile", 'w')
        envfile.write("TAG=latest\n")
        envfile.write("REGISTRY_IP=172.31.128.1\n")
        host_ip = "HOST_IP=" + socket.gethostbyname(
            fit_common.fitcfg()['rackhd_host']) + "\n"
        envfile.write(host_ip)
        envfile.close()
        fit_common.scp_file_to_ora("envfile")
        self.assertEqual(
            fit_common.remote_shell('cp envfile /home/onrack/.env')
            ['exitcode'], 0, "copy of env file failed.")
        os.remove('envfile')

        # Get the username and password from config-mn/credentials.json
        username = fit_common.fitcreds()['docker_hub'][0]['username']
        password = fit_common.fitcreds()['docker_hub'][0]['password']
        command = 'cd rackhd/docker/dell; sudo docker login --username='******' --password='******'exitcode'], 0,
            "Docker login failed.")

        # Docker up consul
        command = "cd rackhd/docker/dell; sudo docker-compose up -d consul"
        self.assertEqual(
            fit_common.remote_shell(command)['exitcode'], 0,
            "Docker up consul failed.")
        time.sleep(30)

        command = "cd rackhd/docker/dell; sudo chmod +x set_config.sh; sudo ./set_config.sh"
        self.assertEqual(
            fit_common.remote_shell(command)['exitcode'], 0,
            "set_config.sh failed.")

        # Docker up the rest of micro service containers
        command = "cd rackhd/docker/dell; sudo docker-compose up -d"
        self.assertEqual(
            fit_common.remote_shell(command)['exitcode'], 0,
            "docker-compose up failed.")
        time.sleep(180)

        # Set port to 8080 in smi config file
        port_var = fit_common.fitports()['http']
        command = "cd rackhd/docker/dell; sudo sed -i 's/9090/" + str(
            port_var) + "/g' set_rackhd_smi_config.sh"
        self.assertEqual(
            fit_common.remote_shell(command)['exitcode'], 0,
            "set_rackhd_smi_config.sh failed.")

        # Populates smi config file
        command = "cd rackhd/docker/dell; sudo ./set_rackhd_smi_config.sh"
        self.assertEqual(
            fit_common.remote_shell(command)['exitcode'], 0,
            "set_rackhd_smi_config.sh failed.")

        # Replace  callback Uri port from 9988 to 9080 in smi config file
        command = "cd /opt/monorail; sudo sed -i 's/9988/9080/g' smiConfig.json"
        self.assertEqual(
            fit_common.remote_shell(command)['exitcode'], 0,
            "Change port from 9988 to 9080 in smiConfig failed.")

        # Restart on-http service
        command = "sudo service on-http restart"
        self.assertEqual(
            fit_common.remote_shell(command)['exitcode'], 0,
            "failed to start on-http service.")
Esempio n. 17
0
import os, sys
import ConfigParser

# Check for fit-based configuration
CONFIG = os.environ.get('FIT_CONFIG', None)
if CONFIG:
    # Load FIT configuration (.json format)
    import fit_common

    defaults = fit_common.fitcfg()['cit-config']
    defaults['RACKHD_HOST'] = fit_common.fitcfg()['rackhd_host']
    defaults['RACKHD_PORT'] = fit_common.fitports()['http']
    defaults['RACKHD_PORT_AUTH'] = fit_common.fitports()['https']
    defaults['RACKHD_HTTPD_PORT'] = fit_common.fitports()['httpd']
    defaults['RACKHD_SSH_PORT'] = fit_common.fitports()['ssh']
    defaults['RACKHD_SSH_USER'] = fit_common.fitcreds(
    )['rackhd_ssh'][0]['username']
    defaults['RACKHD_SSH_PASSWORD'] = fit_common.fitcreds(
    )['rackhd_ssh'][0]['password']
    defaults['RACKHD_SMB_USER'] = fit_common.fitcreds(
    )['rackhd_smb'][0]['username']
    defaults['RACKHD_SMB_PASSWORD'] = fit_common.fitcreds(
    )['rackhd_smb'][0]['password']
    defaults['RACKHD_AMQP_URL'] = fit_common.fitrackhd()['amqp']

    # map from original cit repo path name to httpProxies in rackhd configuration
    mappings = {
        'RACKHD_CENTOS_REPO_PATH': '/CentOS/6.5',
        'RACKHD_ESXI_REPO_PATH': '/ESXi/6.0',
        'RACKHD_UBUNTU_REPO_PATH': '/Ubuntu/14'
    }
    for cit_path, local_path in mappings.items():