View | Details | Raw Unified | Return to bug 34819 | Differences between
and this patch

Collapse All | Expand All

(-)lib.py (-15 / +43 lines)
 Lines 126-132    Link Here 
126
		# Create the logfile
126
		# Create the logfile
127
		if self.logfile:
127
		if self.logfile:
128
			log = open(self.logfile, 'a+')
128
			log = open(self.logfile, 'a+')
129
			log.write('Created instance %s at %s\n' % (section, time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())))
129
			log.write('Creating instance %s at %s\n' % (section, time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())))
130
			log.close()
130
			log.close()
131
		self.logfile_fd = None
131
		self.logfile_fd = None
132
132
 Lines 144-150    Link Here 
144
		self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
144
		self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
145
		start = now = time.time()
145
		start = now = time.time()
146
		# TODO: make the timeout configurable
146
		# TODO: make the timeout configurable
147
		timeout = 1200
147
		timeout = 600
148
		while now - start < timeout:
148
		while now - start < timeout:
149
			try:
149
			try:
150
				self._connect_vm()
150
				self._connect_vm()
 Lines 552-561    Link Here 
552
				'ec2_ami',
552
				'ec2_ami',
553
				'ec2_security_group',
553
				'ec2_security_group',
554
				'ec2_instance_type',
554
				'ec2_instance_type',
555
				'ec2_instance_ebsOptimized',
555
				'ec2_keypair',
556
				'ec2_keypair',
556
				'ec2_region',
557
				'ec2_region',
557
				'ec2_subnet_id',
558
				'ec2_subnet_id',
558
				'ec2_partition_size',
559
				'ec2_partition_size',
560
				'ec2_volume_type',
561
				'ec2_volume_iops',
559
				]
562
				]
560
		for key in params:
563
		for key in params:
561
			if not config.has_option(section, key):
564
			if not config.has_option(section, key):
 Lines 576-585    Link Here 
576
		"""
579
		"""
577
		bdm = None
580
		bdm = None
578
		if self.aws_cfg.get('ec2_partition_size'):
581
		if self.aws_cfg.get('ec2_partition_size'):
582
			opt_volume_type = 'standard'
583
			opt_oips = None
584
			if self.aws_cfg.get('ec2_volume_type'):
585
				#TODO: make sure ebsOptimized is also active
586
				opt_volume_type = self.aws_cfg.get('ec2_volume_type')
587
				# IOPS - up to partition_size * 30 (See AWS docs)
588
				opt_iops = self.aws_cfg.get('ec2_volume_iops')
579
			dev_sda1 = blockdevicemapping.EBSBlockDeviceType(
589
			dev_sda1 = blockdevicemapping.EBSBlockDeviceType(
580
					size = self.aws_cfg.get('ec2_partition_size'),
590
					size = self.aws_cfg.get('ec2_partition_size'),
581
					delete_on_termination=True,
591
					volume_type = opt_volume_type,
582
					)
592
					iops = opt_iops,
593
					delete_on_termination = True,
594
					)	
583
			bdm = blockdevicemapping.BlockDeviceMapping()
595
			bdm = blockdevicemapping.BlockDeviceMapping()
584
			bdm['/dev/sda1'] = dev_sda1
596
			bdm['/dev/sda1'] = dev_sda1
585
		return bdm
597
		return bdm
 Lines 605-610    Link Here 
605
		user_data = '\n'.join(['%s=%s' % (v, os.getenv(v, '')) for v in env_vars])
617
		user_data = '\n'.join(['%s=%s' % (v, os.getenv(v, '')) for v in env_vars])
606
618
607
		self.ec2 = boto.connect_ec2(**aws_cfg)
619
		self.ec2 = boto.connect_ec2(**aws_cfg)
620
608
		reuse = self.aws_cfg.get('ec2_reuse')
621
		reuse = self.aws_cfg.get('ec2_reuse')
609
		if reuse:
622
		if reuse:
610
			reservation = self.ec2.get_all_instances(instance_ids=[reuse])[0]
623
			reservation = self.ec2.get_all_instances(instance_ids=[reuse])[0]
 Lines 617-623    Link Here 
617
				user_data=user_data,
630
				user_data=user_data,
618
				security_group_ids=[self.aws_cfg['ec2_security_group']],
631
				security_group_ids=[self.aws_cfg['ec2_security_group']],
619
				instance_type=self.aws_cfg['ec2_instance_type'],
632
				instance_type=self.aws_cfg['ec2_instance_type'],
620
				instance_initiated_shutdown_behavior='terminate',  # 'save'
633
				instance_initiated_shutdown_behavior='terminate',
621
				block_device_map=self._get_blockdevicemapping()
634
				block_device_map=self._get_blockdevicemapping()
622
				)
635
				)
623
		else:
636
		else:
 Lines 628-656    Link Here 
628
				user_data=user_data,
641
				user_data=user_data,
629
				security_groups=[self.aws_cfg['ec2_security_group']],
642
				security_groups=[self.aws_cfg['ec2_security_group']],
630
				instance_type=self.aws_cfg['ec2_instance_type'],
643
				instance_type=self.aws_cfg['ec2_instance_type'],
631
				instance_initiated_shutdown_behavior='terminate',  # 'save'
644
				instance_initiated_shutdown_behavior='terminate',
632
				block_device_map=self._get_blockdevicemapping()
645
				block_device_map=self._get_blockdevicemapping()
633
				)
646
				)
647
		
648
		self.instance = reservation.instances[0]		
649
		self._log('Instance %s reserved. ->%s' % (self.instance.id, self.instance.state))
634
650
635
		self.instance = reservation.instances[0]
636
637
		self._wait_instance()
651
		self._wait_instance()
638
652
		
639
		self.instance.add_tag('Name', 'Test-%s-%s' % (os.getenv('USER'), self.section))
653
		self.instance.add_tag('Name', 'Test-%s-%s' % (os.getenv('USER'), self.section))
640
		self.instance.add_tag('class', 'ucs-test')
654
		self.instance.add_tag('class', 'ucs-test')
641
		for var in env_vars:
655
		for var in env_vars:
642
			self.instance.add_tag(var.lower(), os.getenv(var, ''))
656
			self.instance.add_tag(var.lower(), os.getenv(var, ''))
657
		#Need ebsOptimized if volume_type is io1
658
		#NOTE:launching an instance with image.run does not support ebsOptimized
659
		#modifying instance attribute:
660
		#self._log('EBS status: %s' % (self.instance.ebs_optimized))
661
		if self.aws_cfg.get('ec2_instance_ebsOptimized') == 'True':
662
			self._log('Changing EBS status: stopping instance first.')
663
			# stop VM (make sure it will only be stoped, not terminated)
664
			self.instance.modify_attribute('instanceInitiatedShutdownBehavior', 'stop')
665
			self.instance.stop()
666
			self._wait_instance(desiredState='stopped')
667
			self.instance.modify_attribute('ebsOptimized', True)
668
			self.instance.modify_attribute('instanceInitiatedShutdownBehavior', 'terminate')
669
			self.instance.start()
670
		self._wait_instance()
643
671
644
	def _wait_instance(self, timeout=600):
672
	def _wait_instance(self, timeout=600, desiredState='running'):
645
		"""
673
		"""
646
		Wait until instance is created.
674
		Wait until instance is created.
647
		"""
675
		"""
648
		start = now = time.time()
676
		start = now = time.time()
649
		while now - start < timeout:
677
		while now - start < timeout:
650
			if self.instance.state == 'running':
678
			if self.instance.state == desiredState:
651
				break
679
				break
652
			if self.instance.state == 'pending':
680
			if self.instance.state != desiredState:
653
				self._log('Pending %d...' % (timeout - now + start))
681
				self._log('State: %s, waiting %d...' % (self.instance.state, timeout - now + start))
654
			time.sleep(10)
682
			time.sleep(10)
655
683
656
			try:
684
			try:
 Lines 661-674    Link Here 
661
					if error.error_code == 'InvalidInstanceID.NotFound':
689
					if error.error_code == 'InvalidInstanceID.NotFound':
662
						break
690
						break
663
				else:
691
				else:
664
					self._log('Unexcpected error waiting for instance: %s', ex)
692
					self._log('Unexpected error waiting for instance: %s', ex)
665
					raise
693
					raise
666
			now = time.time()
694
			now = time.time()
667
		else:
695
		else:
668
			self._log('Timeout waiting for instance')
696
			self._log('Timeout waiting for instance')
669
			raise
697
			raise
698
		self._log('OK ->%s' % (self.instance.state))
670
699
671
672
def _print_process(msg):
700
def _print_process(msg):
673
	'''	Print s status line '''
701
	'''	Print s status line '''
674
	if len(msg) > 64:
702
	if len(msg) > 64:

Return to bug 34819