Best Python code snippet using localstack_python
test_aws.py
Source:test_aws.py
...183 image = MagicMock()184 self.svc.share_image(image, accounts=accounts, groups=groups)185 image.modify_attribute.assert_not_called()186 @patch('cloudimg.aws.AWSService.wait_for_import_snapshot_task')187 def test_import_snapshot(self, mock_wait):188 snapshot = mock_wait.return_value = MagicMock()189 obj = MagicMock()190 result = self.svc.import_snapshot(obj, self.md.snapshot_name)191 self.assertEqual(snapshot, result)192 self.assertEqual(self.mock_import_snapshot.call_count, 1)193 self.assertEqual(snapshot.create_tags.call_count, 1)194 self.assertFalse('RoleName' in self.mock_import_snapshot.call_args[1])195 @patch('cloudimg.aws.AWSService.wait_for_import_snapshot_task')196 def test_import_snapshot_role(self, mock_wait):197 self.init_service(import_role='fake-role')198 snapshot = mock_wait.return_value = MagicMock()199 obj = MagicMock()200 result = self.svc.import_snapshot(obj, self.md.snapshot_name)201 self.assertEqual(snapshot, result)202 self.assertEqual(self.mock_import_snapshot.call_count, 1)203 self.assertEqual(snapshot.create_tags.call_count, 1)204 kwargs = self.mock_import_snapshot.call_args[1]205 self.assertTrue('RoleName' in kwargs)206 self.assertEqual(kwargs['RoleName'], 'fake-role')207 def test_wait_for_import_snapshot_task(self):208 task = {209 'ImportTaskId': 'task-abc123',210 'SnapshotTaskDetail': {211 'Status': 'active'212 }213 }214 task_rsp = deepcopy(task)...
containerfsinstalltarget.py
Source:containerfsinstalltarget.py
1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""Container-as-basic-filesystem installation target4@author: Tobias Hunger <tobias.hunger@gmail.com>5"""6from cleanroom.firestarter.installtarget import InstallTarget7import cleanroom.firestarter.tools as tool8from cleanroom.helper.btrfs import BtrfsHelper9import os10import typing11def _extract_into_snapshot(_, rootfs: str, *, import_snapshot: str) -> int:12 # Extract data13 return tool.run(14 "/usr/bin/bash",15 "-c",16 f'( cd "{rootfs}" ; tar -cf - . ) | ( cd "{import_snapshot}" ; tar -xf - )',17 ).returncode18class ContainerFilesystemInstallTarget(InstallTarget):19 def __init__(self) -> None:20 super().__init__("container_fs", "Install a container filesystem.")21 def __call__(22 self, *, parse_result: typing.Any, tmp_dir: str, image_file: str23 ) -> int:24 container_name = parse_result.override_system_name25 if not container_name:26 container_name = parse_result.system_name27 if container_name.startswith("system-"):28 container_name = container_name[7:]29 read_write = parse_result.read_write30 container_dir = os.path.join(parse_result.machines_dir, container_name)31 import_dir = container_dir + "_import"32 try:33 btrfs = BtrfsHelper("/usr/bin/btrfs")34 btrfs.create_subvolume(import_dir)35 # Mount filessystems and copy the rootfs into import_dir:36 result = tool.execute_with_system_mounted(37 lambda e, r: _extract_into_snapshot(e, r, import_snapshot=import_dir),38 image_file=image_file,39 tmp_dir=tmp_dir,40 )41 # Delete *old* container-name:42 if btrfs.is_subvolume(container_dir):43 btrfs.delete_subvolume(container_dir)44 # Copy over container filesystem:45 btrfs.create_snapshot(import_dir, container_dir, read_only=not read_write)46 finally:47 btrfs.delete_subvolume(import_dir)48 return result49 def setup_subparser(self, subparser: typing.Any) -> None:50 subparser.add_argument(51 "--container-name",52 dest="override_system_name",53 action="store",54 nargs="?",55 default="",56 help="Container name to use "57 '[default: system-name without "system-" prefix]',58 )59 subparser.add_argument(60 "--machines-dir",61 dest="machines_dir",62 action="store",63 default="/var/lib/machines",64 help="Machines directory [default: /var/lib/machines]",65 )66 subparser.add_argument(67 "--read-write",68 dest="read_write",69 action="store_true",70 default=False,71 help="Make final snapshot read/write [default is read-only].",...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!