Ejemplo n.º 1
0
 def wait_for_ping(self, instance, user=None):
     """
     To obtain the SSH client, we must wait for the instance to boot,
     even the EC2 instance status is available.
     :param instance: created ec2 instance to wait for
     :param user: SSH user to use with the created key
     :return: SSHClient or None on error
     """
     ping_arg = '-n'
     if os.name == 'posix':
         ping_arg = '-c'
     if not instance.public_dns_name:
         log.error(
             "Spawned instance was not allocated a public IP. Please try again."
         )
         raise Exception(
             "Spawned instance was not allocated a public IP. Please try again."
         )
     ping_cmd = 'ping {} 1 {}'.format(ping_arg, instance.ip_address)
     try:
         timeout = 0
         while os.system(ping_cmd) != 0 and timeout < 60:
             time.sleep(10)
             timeout += 10
         # artificial wait for ssh service up status
         time.sleep(60)
         client = SSHClient(server=instance.ip_address,
                            host_key_file=self.host_key_file,
                            user=user or self.user,
                            ssh_key_file=os.path.join(
                                self.localpath, self.key_name + '.pem'))
     except Exception as e:
         log.exception(e)
         raise
     return client
Ejemplo n.º 2
0
 def get_instance_details(self):
     """
     Create ssh client and get vm IPs
     :return: ssh_client, vm_ips
     """
     ssh_client = {}
     vm_ips = {}
     for i in xrange(1, self.vm_count + 1):
         if self.provider == constants.AWS:
             ssh_client[i] = self.connector.wait_for_ping(self.vms[i])
             # SRIOV is enabled by default on AWS for the tested platforms
             # if sriov == constants.ENABLED:
             #     ssh_client[i] = connector.enable_sr_iov(vms[i], ssh_client[i])
             self.vms[i].update()
             vm_ips[i] = self.vms[i].private_ip_address
         elif self.provider == constants.AZURE:
             ssh_client[i] = SSHClient(
                 server=self.vms[i].name + self.connector.dns_suffix,
                 host_key_file=self.connector.host_key_file,
                 user=self.connector.user,
                 ssh_key_file=os.path.join(self.connector.localpath,
                                           self.connector.key_name +
                                           '.pem'))
             ip = ssh_client[i].run(
                 'ifconfig eth0 | grep "inet" | cut -d: -f2 | awk -F " " \'{print $2}\' | head -n 1'
             )
             log.info('vm ip {}'.format(ip))
             vm_ips[i] = ip[1].strip()
             log.info('--vm ips i {} {}'.format(i, vm_ips[i]))
         elif self.provider == constants.GCE:
             ssh_client[i] = self.connector.wait_for_ping(self.vms[i])
             vm_ips[i] = self.vms[i]['networkInterfaces'][0]['networkIP']
     return ssh_client, vm_ips
Ejemplo n.º 3
0
 def perf_tuning(self):
     current_path = os.path.dirname(sys.modules['__main__'].__file__)
     for i in range(1, self.vm_count + 1):
         log.info('Running perf tuning on {}'.format(self.vm_ips[i]))
         self.ssh_client[i].connect()
         self.ssh_client[i].put_file(os.path.join(current_path, 'tests', 'perf_tuning.sh'),
                                     '/tmp/perf_tuning.sh')
         self.ssh_client[i].run('chmod +x /tmp/perf_tuning.sh')
         self.ssh_client[i].run("sed -i 's/\r//' /tmp/perf_tuning.sh")
         params = [self.provider]
         if '.deb' in self.kernel:
             log.info('Uploading kernel {} on {}'.format(self.kernel, self.vm_ips[i]))
             self.ssh_client[i].put_file(os.path.join(self.localpath, self.kernel),
                                         '/tmp/{}'.format(self.kernel))
             params.append('/tmp/{}'.format(self.kernel))
         log.info('Run perf_tuning.sh {}'.format(' '.join(params)))
         self.ssh_client[i].run('/tmp/perf_tuning.sh {}'.format(' '.join(params)))
         if self.provider in [constants.AWS, constants.GCE]:
             self.ssh_client[i] = self.connector.restart_vm(self.vms[i])
         elif self.provider == constants.AZURE:
             self.vms[i] = self.connector.restart_vm(self.vms[i].name)
             # TODO add custom kernel support for all providers - only azure support
             self.ssh_client[i] = SSHClient(server=self.vms[i].name + self.connector.dns_suffix,
                                            host_key_file=self.connector.host_key_file,
                                            user=self.connector.user,
                                            ssh_key_file=os.path.join(
                                                    self.connector.localpath,
                                                    self.connector.key_name + '.pem'))
             ip = self.ssh_client[i].run(
                     'ifconfig eth0 | grep "inet" | cut -d: -f2 | awk -F " " \'{print $2}\' | head -n 1')
             self.vm_ips[i] = ip[1].strip()
Ejemplo n.º 4
0
 def wait_for_ping(self, instance):
     """
     To obtain the SSH client, we must wait for the instance to boot, even the GCE instance
     status is available.
     :param instance: instance to wait for sshd start
     :return: SSHClient or None on error
     """
     ping_arg = '-n'
     if os.name == 'posix':
         ping_arg = '-c'
     nat_ip = instance['networkInterfaces'][0]['accessConfigs'][0].get(
         'natIP', None)
     if not nat_ip:
         log.error(
             "Spawned instance was not allocated a NAT IP. Please try again."
         )
         raise Exception(
             "Spawned instance was not allocated a public IP. Please try again."
         )
     ping_cmd = 'ping {} 1 {}'.format(ping_arg, nat_ip)
     try:
         timeout = 0
         while os.system(ping_cmd) != 0 and timeout < 60:
             time.sleep(10)
             timeout += 10
         # artificial wait for ssh service up status
         time.sleep(60)
         client = SSHClient(server=nat_ip,
                            host_key_file=self.host_key_file,
                            user=self.user,
                            ssh_key_file=os.path.join(
                                self.localpath, self.key_name + '.pem'))
     except Exception as e:
         log.exception(e)
         raise
     return client