def pre(self): self.group_name = self.make_uuid('group_name') self.group_desc = self.make_uuid('group_desc') self.group = ec2_conn.create_security_group( self.group_name, self.group_desc ) groups = util.retry( lambda: ec2_conn.get_all_security_groups( groupnames=[self.group_name]) ) assert len(groups)
def post(self): self.reservation.instances[0].terminate() #ec2_conn.terminate_instances([self.reservation.instances[0].id]) util.wait( lambda: self.reservation.instances[0].update() == 'terminated', timeout=60 * 2 ) assert util.retry( lambda: not self.testSSH( self.key_pairs.keypair.material.encode('ascii'), config['ec2']['test_username'], self.reservation.instances[0].public_dns_name ), wait_exp=2 )
def pre(self, key_pairs=None, security_group=None): image_id = config['ec2']['test_image_id'] instance_config = config['ec2']['test_instance'] self.image = ec2_conn.get_all_images(image_ids=[image_id])[0] self.security_group = security_group self.key_pairs = key_pairs self.security_group.group.authorize('tcp', 22, 22, '0.0.0.0/0') self.reservation = self.image.run( security_groups=[self.security_group.group_name], key_name=self.key_pairs.key_name, **instance_config ) util.wait( lambda: self.reservation.instances[0].update() == 'running', timeout=60 * 3 ) util.wait( lambda: self.testTelnet( self.reservation.instances[0].public_dns_name, 22 ), timeout = 60 * 5 ) assert util.retry( lambda: self.testSSH( self.key_pairs.keypair.material.encode('ascii'), config['ec2']['test_username'], self.reservation.instances[0].public_dns_name ), wait_exp=2 )
def test_invoke(self): mock = functools.partial(self.mock, succeed_on_try=2) ret = util.retry(mock, max_tries=5) self.assertTrue(self.mock.testValue(ret)) self.assertTrue(self.mock.testCalled(2))