How to use attach_volume method in localstack

Best Python code snippet using localstack_python

test_ebs.py

Source: test_ebs.py Github

copy

Full Screen

...24 'InstanceId': INSTANCE_ID,25 'Device': DEVICE26 }]27 }]}28 volume_item = self.ebs_attachment.attach_volume(self.volume,29 self.volume_item)30 self.assertEqual({'S': DEVICE}, volume_item['device'])31 self.ec2.create_snapshot.assert_not_called()32 self.ec2.create_volume.assert_not_called()33 self.ec2.attach_volume.assert_not_called()34 self.ec2.get_waiter.assert_not_called()35 def test_attach_existing_same_az(self):36 self.volume_item['volume_id'] = {'S': VOLUME_ID}37 self.ec2.describe_volumes.return_value = {'Volumes': [{38 'AvailabilityZone': AVAILABILITY_ZONE,39 'Attachments': [{40 'InstanceId': 'i-654321',41 'Device': DEVICE42 }]43 }]}44 self.ebs_attachment._next_volume = MagicMock(return_value=DEVICE)45 self.ebs_attachment._attach_volume = MagicMock()46 self.ebs_attachment.attach_volume(self.volume, self.volume_item)47 self.ec2.create_snapshot.assert_not_called()48 self.ec2.create_volume.assert_not_called()49 self.ec2.attach_volume.assert_not_called()50 self.ec2.get_waiter.assert_called_with('volume_available')51 def test_attach_existing_different_az(self):52 self.volume_item['volume_id'] = {'S': VOLUME_ID}53 self.ec2.describe_volumes.return_value = {'Volumes': [{54 'AvailabilityZone': 'us-west-2a',55 'Attachments': [{56 'InstanceId': 'i-654321',57 'Device': '/​dev/​xvdb'58 }]59 }]}60 self.ec2.create_snapshot.return_value = {'SnapshotId': SNAPSHOT_ID}61 self.ebs_attachment._next_volume = MagicMock(return_value=DEVICE)62 self.ebs_attachment._attach_volume = MagicMock()63 self.ebs_attachment.attach_volume(self.volume, self.volume_item)64 self.ec2.create_snapshot.assert_called_with(VolumeId=VOLUME_ID)65 self.ec2.create_volume.assert_called_with(66 AvailabilityZone=AVAILABILITY_ZONE,67 Size=4,68 VolumeType='gp2',69 SnapshotId=SNAPSHOT_ID70 )71 self.ec2.attach_volume.assert_not_called()72 self.ec2.delete_volume.assert_called_with(VolumeId=VOLUME_ID)73 def test_attach_create_volume(self):74 self.volume.iops = 40075 self.volume.encrypted = True76 self.volume_item['snapshot_id'] = {'S': SNAPSHOT_ID}77 self.ebs_attachment._next_volume = MagicMock(return_value=DEVICE)78 self.ebs_attachment._attach_volume = MagicMock()79 self.ebs_attachment.attach_volume(self.volume, self.volume_item)80 self.ec2.describe_volumes.assert_not_called()81 self.ec2.create_snapshot.assert_not_called()82 self.ec2.create_volume.assert_called_with(83 Size=4, VolumeType='gp2', AvailabilityZone=AVAILABILITY_ZONE,84 Iops=400, Encrypted=True, SnapshotId=SNAPSHOT_ID)85 def test_describe_volume_error(self):86 client_error = ClientError({'Error': {'Code': 0}}, 'DescribeVolumes')87 self.ec2.describe_volumes.side_effect = client_error88 self.assertRaises(ClientError, self.ebs_attachment._describe_volume,89 VOLUME_ID)90 def test_describe_volume_not_found(self):91 client_error = ClientError({'Error': {92 'Code': 'InvalidVolume.NotFound'}}, 'DescribeVolumes')93 self.ec2.describe_volumes.side_effect = client_error94 volume = self.ebs_attachment._describe_volume(VOLUME_ID)95 self.assertIsNone(volume)96 @patch('spacel.volumes.ebs.check_output')97 def test_next_volume(self, mock_lsblk):98 mock_lsblk.return_value = '''NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT99/​dev/​xvda 8:0 0 8.0G 0 disk100/​dev/​xvdb 8:1 0 16.0G 0 disk101'''102 next_device = self.ebs_attachment._next_volume()103 self.assertEqual('/​dev/​xvdc', next_device)104 @patch('spacel.volumes.ebs.check_output')105 def test_next_volume_none_available(self, mock_lsblk):106 devices = ['/​dev/​xvd%s' % chr(ord('a') + dev) for dev in range(26)]107 mock_lsblk.return_value = '\n'.join(devices)108 next_device = self.ebs_attachment._next_volume()109 self.assertIsNone(next_device)110 @patch('spacel.volumes.ebs.check_output')111 def test_attach_volume(self, _):112 volume_item = {'volume_id': {'S': VOLUME_ID}}...

Full Screen

Full Screen

createVolumesforMongo.py

Source: createVolumesforMongo.py Github

copy

Full Screen

1#!/​usr/​bin/​env python2# the script will create snapshots of volumes and delete volumes which are older than 2 weeks3__author__ = "ID017437"4__date__ = "$Dec 16, 2015 8:48:52 AM$"5import boto6import os7import time8from boto import ec29region = os.environ.get('AWS_DEFAULT_REGION')10aws_access_key = os.environ.get('AWS_ACCESS_KEY_ID')11aws_secret_key = os.environ.get('AWS_SECRET_KEY')12aws_instance_id = os.environ.get('SCALR_CLOUD_SERVER_ID')13aws_instance_name = os.environ.get('SCALR_SERVER_HOSTNAME')14aws_zone = os.environ.get('AWS_ZONE')15aws_vol_type= os.environ.get('MONGODB_VOLUME_TYPE')16aws_vol_size= os.environ.get('MONGODB_VOLUME_SIZE')17aws_vol_iops= os.environ.get('MONGODB_VOLUME_IOPS')18def createMongoVolsGP2(conn_eu):19 # Create Data Volume20 vol=conn_eu.create_volume(aws_vol_size,aws_zone,None,aws_vol_type) 21 # Add a Name tag to the new volume so we can find it. 22 conn_eu.create_tags([vol.id], {"Name":"Data Volume for:"+aws_instance_name}) 23 #Attach Data volume to instance24 time.sleep(20)25 result = conn_eu.attach_volume (vol.id,aws_instance_id, "/​dev/​xvdh")26 print 'Attach Volume Result: ', result27 28 # Create Log Volume29 vol=conn_eu.create_volume(aws_vol_size,aws_zone,None,aws_vol_type) 30 # Add a Name tag to the new volume so we can find it. 31 conn_eu.create_tags([vol.id], {"Name":"Log Volume for:"+aws_instance_name})32 #Attach Log volume to instance33 time.sleep(20)34 result = conn_eu.attach_volume (vol.id,aws_instance_id, "/​dev/​xvdi")35 print 'Attach Volume Result: ', result36 37 # Create Journal Volume38 vol=conn_eu.create_volume(aws_vol_size,aws_zone,None,aws_vol_type) 39 # Add a Name tag to the new volume so we can find it. 40 conn_eu.create_tags([vol.id], {"Name":"Journal Volume for:"+aws_instance_name})41 #Attach Journal volume to instance42 time.sleep(20)43 result = conn_eu.attach_volume (vol.id,aws_instance_id, "/​dev/​xvdj")44 print 'Attach Volume Result: ', result45 46 47 return48def createMongoVolsIO1(conn_eu,aws_vol_iops):49 50 51 # Create Data Volume52 vol=conn_eu.create_volume(aws_vol_size,aws_zone,None,aws_vol_type,aws_vol_iops) 53 # Add a Name tag to the new volume so we can find it. 54 conn_eu.create_tags([vol.id], {"Name":"Data Volume for:"+aws_instance_name}) 55 #Attach Data volume to instance56 time.sleep(20)57 result = conn_eu.attach_volume (vol.id,aws_instance_id, "/​dev/​xvdh")58 print 'Attach Volume Result: ', result59 60 # Create Log Volume61 vol=conn_eu.create_volume(aws_vol_size,aws_zone,None,aws_vol_type,aws_vol_iops) 62 # Add a Name tag to the new volume so we can find it. 63 conn_eu.create_tags([vol.id], {"Name":"Log Volume for:"+aws_instance_name})64 #Attach Log volume to instance65 time.sleep(20)66 result = conn_eu.attach_volume (vol.id,aws_instance_id, "/​dev/​xvdi")67 print 'Attach Volume Result: ', result68 69 # Create Journal Volume70 vol=conn_eu.create_volume(aws_vol_size,aws_zone,None,aws_vol_type,aws_vol_iops) 71 # Add a Name tag to the new volume so we can find it. 72 conn_eu.create_tags([vol.id], {"Name":"Journal Volume for:"+aws_instance_name})73 #Attach Journal volume to instance74 time.sleep(20)75 result = conn_eu.attach_volume (vol.id,aws_instance_id, "/​dev/​xvdj")76 print 'Attach Volume Result: ', result77 return78def main():79 #conn_eu = ec2.connect_to_region(region,aws_access_key,aws_secret_key)80 conn_eu = ec2.connect_to_region(region) 81 82 if aws_vol_iops is None :83 createMongoVolsGP2(conn_eu)84 else:85 createMongoVolsIO1(conn_eu,aws_vol_iops)86 87if __name__ == "__main__":...

Full Screen

Full Screen

core.py

Source: core.py Github

copy

Full Screen

...36 wait_running(dc.id)37 ip = ec2.allocate_address(domain='vpc')38 ec2.associate_address( dc.id, allocation_id=ip.allocation_id )39 v = ec2.get_all_volumes( ['vol-1fb7d673'] )[0]40 ec2.attach_volume( v.id, dc.id, 'xvdf' )41 set_name( dc.id, 'velaskec-dc' )42 log( 'velaskec-dc started at %s' % ip.public_ip )43price = {"t1.micro":"0.020","m1.small": "0.115", "m1.medium" : "0.230", "m1.large": "0.46"}44def start_spot( image_id, instance_type, **kwargs ):45 return ec2.request_spot_instances( price[instance_type], image_id, count = 1,46 key_name = 'webserver',47 instance_type = instance_type,48 monitoring_enabled = True,49 **kwargs50 )[0]51 52def start_vpc_spot( image_id ):53 return start_spot( image_id, 'm1.medium', subnet_id = 'subnet-b58921dd')54spots = []55def start_spots(): 56 [spots.append(start_vpc_spot(x)) for x 57 in [ 'ami-7fe23216','ami-4be23222']]58 log( 'spot requests have been created' )59def get_instance(spot_id):60 spot = lambda: ec2.get_all_spot_instance_requests([spot_id.id])[0]61 while spot().state != 'active': time.sleep(1)62 return spot().instance_id63def allocate_ip(id):64 ip = ec2.allocate_address(domain='vpc')65 ec2.associate_address( id, allocation_id=ip.allocation_id )66 return ip67def attach_volume(v_name, instance_id):68 v = ec2.get_all_volumes( [v_name] )[0]69 ec2.attach_volume( v.id, instance_id, 'xvdf' )70def tune_sql():71 instance_id = get_instance(spots[0])72 wait_running( instance_id )73 v = ec2.get_all_volumes( ['vol-3df85651'] )[0]74 ec2.attach_volume( v.id, instance_id, 'xvdf' )75 ip = allocate_ip(instance_id)76 set_name( instance_id, 'sql1' )77 log( 'sql1 started at %s' % ip.public_ip )78def tune_wss():79 instance_id = get_instance(spots[1])80 wait_running( instance_id )81 ip = allocate_ip(instance_id)82 set_name( instance_id, 'wss4fe' )...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful