def remove_dir(path, use_sudo='false'): """Remove the source directory.""" cmd = ['rm', '-r', path] if use_sudo == 'true': fmeth = sudo elif use_sudo == 'false': fmeth = run else: raise NotImplementedError(use_sudo) fcmd(fmeth, cmd)
def list_storage(): """List storage size of connected devices.""" fcmd(run, ['lsblk'])
def ebs_mkfs(): """Make a file system on a newly attached device.""" cmd = ['mkfs', '-t', 'ext4', parser.get('aws', 'ebs_mount_name')] fcmd(sudo, cmd)
def _run_tests_(self, should_email=False): aws_src = os.getenv('OCGIS_SIMPLEAWS_SRC') aws_conf = os.getenv('OCGIS_CONF_PATH') aws_testing_section = 'aws-testing' ebs_volumesize = int(parser.get(aws_testing_section, 'ebs_volumesize')) ebs_snapshot = parser.get(aws_testing_section, 'ebs_snapshot') ebs_mount_name = parser.get(aws_testing_section, 'ebs_mount_name') ebs_placement = parser.get(aws_testing_section, 'ebs_placement') test_results_path = parser.get(aws_testing_section, 'test_results_path') test_instance_name = parser.get(aws_testing_section, 'test_instance_name') test_instance_type = parser.get(aws_testing_section, 'test_instance_type') test_image_id = parser.get(aws_testing_section, 'test_image_id') dest_email = parser.get(aws_testing_section, 'dest_email') dir_clone = parser.get('server', 'dir_clone') key_name = parser.get('simple-aws', 'key_name') import sys sys.path.append(aws_src) import saws import ipdb am = saws.AwsManager(aws_conf) self.log.info('launching instance') instance = am.launch_new_instance(test_instance_name, image_id=test_image_id, instance_type=test_instance_type, placement=ebs_placement) with settings(host_string=instance.ip_address, disable_known_hosts=True, connection_attempts=10): try: self.log.info('creating volume') volume = am.conn.create_volume(ebs_volumesize, ebs_placement, snapshot=ebs_snapshot) am.wait_for_status(volume, 'available') try: self.log.info('attaching volume') am.conn.attach_volume(volume.id, instance.id, ebs_mount_name, dry_run=False) am.wait_for_status(volume, 'in-use') ebs_mount() if self.launch_pause == 'true': self.log.info('pausing. continue to terminate instance...') msg = 'ssh -i ~/.ssh/{0}.pem ubuntu@{1}'.format(key_name, instance.public_dns_name) self.log.info(msg) ipdb.set_trace() else: path = os.path.join(dir_clone, parser.get('git', 'name')) test_target = os.path.join(path, 'src', 'ocgis', 'test') # test_target = os.path.join(path, 'src', 'ocgis', 'test', 'test_simple') nose_runner = os.path.join(path, 'fabfile', 'nose_runner.py') path_src = os.path.join(path, 'src') with cd(path): fcmd(run, ['git', 'pull']) fcmd(run, ['git', 'checkout', self.branch]) fcmd(run, ['git', 'pull']) with cd(path_src): with shell_env(OCGIS_TEST_TARGET=test_target): fcmd(run, ['python', nose_runner]) if self.path_local_log is not None: get(test_results_path, local_path=self.path_local_log) ebs_umount() finally: self.log.info('detaching volume') volume.detach(force=True) am.wait_for_status(volume, 'available') self.log.info('deleting volume') volume.delete() finally: self.log.info('terminating instance') instance.terminate() if should_email and self.launch_pause == 'false' and self.path_local_log is not None: self.log.info('sending email') with open(self.path_local_log, 'r') as f: content = f.read() am.send_email(dest_email, dest_email, 'OCGIS_AWS', content) self.log.info('success')
def _run_tests_(self, should_email=False): aws_src = os.getenv('OCGIS_SIMPLEAWS_SRC') aws_conf = os.getenv('OCGIS_CONF_PATH') aws_testing_section = 'aws-testing' ebs_volumesize = int(parser.get(aws_testing_section, 'ebs_volumesize')) ebs_snapshot = parser.get(aws_testing_section, 'ebs_snapshot') ebs_mount_name = parser.get(aws_testing_section, 'ebs_mount_name') ebs_placement = parser.get(aws_testing_section, 'ebs_placement') test_results_path = parser.get(aws_testing_section, 'test_results_path') test_instance_name = parser.get(aws_testing_section, 'test_instance_name') test_instance_type = parser.get(aws_testing_section, 'test_instance_type') test_image_id = parser.get(aws_testing_section, 'test_image_id') dest_email = parser.get(aws_testing_section, 'dest_email') dir_clone = parser.get('server', 'dir_clone') key_name = parser.get('simple-aws', 'key_name') import sys sys.path.append(aws_src) import saws import ipdb am = saws.AwsManager(aws_conf) self.log.info('launching instance') instance = am.launch_new_instance(test_instance_name, image_id=test_image_id, instance_type=test_instance_type, placement=ebs_placement) with settings(host_string=instance.ip_address, disable_known_hosts=True, connection_attempts=10): try: self.log.info('creating volume') volume = am.conn.create_volume(ebs_volumesize, ebs_placement, snapshot=ebs_snapshot) am.wait_for_status(volume, 'available') try: self.log.info('attaching volume') am.conn.attach_volume(volume.id, instance.id, ebs_mount_name, dry_run=False) am.wait_for_status(volume, 'in-use') ebs_mount() if self.launch_pause == 'true': self.log.info( 'pausing. continue to terminate instance...') msg = 'ssh -i ~/.ssh/{0}.pem ubuntu@{1}'.format( key_name, instance.public_dns_name) self.log.info(msg) ipdb.set_trace() else: path = os.path.join(dir_clone, parser.get('git', 'name')) test_target = os.path.join(path, 'src', 'ocgis', 'test') # test_target = os.path.join(path, 'src', 'ocgis', 'test', 'test_simple') nose_runner = os.path.join(path, 'fabfile', 'nose_runner.py') path_src = os.path.join(path, 'src') with cd(path): fcmd(run, ['git', 'pull']) fcmd(run, ['git', 'checkout', self.branch]) fcmd(run, ['git', 'pull']) with cd(path_src): with shell_env(OCGIS_TEST_TARGET=test_target): fcmd(run, ['python', nose_runner]) if self.path_local_log is not None: get(test_results_path, local_path=self.path_local_log) ebs_umount() finally: self.log.info('detaching volume') volume.detach(force=True) am.wait_for_status(volume, 'available') self.log.info('deleting volume') volume.delete() finally: self.log.info('terminating instance') instance.terminate() if should_email and self.launch_pause == 'false' and self.path_local_log is not None: self.log.info('sending email') with open(self.path_local_log, 'r') as f: content = f.read() am.send_email(dest_email, dest_email, 'OCGIS_AWS', content) self.log.info('success')