Best Python code snippet using localstack_python
docker_utils.py
Source: docker_utils.py
...44 return container_id45def inspect_current_container_mounts() -> List[VolumeInfo]:46 return DOCKER_CLIENT.inspect_container_volumes(get_current_container_id())47@functools.lru_cache()48def get_default_volume_dir_mount() -> Optional[VolumeInfo]:49 """50 Returns the volume information of LocalStack's DEFAULT_VOLUME_DIR (/var/lib/localstack), if mounted,51 else it returns None. If we're not currently in docker a VauleError is raised. in a container, a ValueError is52 raised.53 :return: the volume info of the default volume dir or None54 """55 for volume in inspect_current_container_mounts():56 if volume.destination.rstrip("/") == DEFAULT_VOLUME_DIR:57 return volume58 return None59def get_host_path_for_path_in_docker(path):60 """61 Returns the calculated host location for a given subpath of DEFAULT_VOLUME_DIR inside the localstack container.62 The path **has** to be a subdirectory of DEFAULT_VOLUME_DIR (the dir itself *will not* work).63 :param path: Path to be replaced (subpath of DEFAULT_VOLUME_DIR)64 :return: Path on the host65 """66 if config.LEGACY_DIRECTORIES:67 return re.sub(r"^%s/(.*)$" % config.dirs.tmp, r"%s/\1" % config.dirs.functions, path)68 if config.is_in_docker:69 volume = get_default_volume_dir_mount()70 if volume:71 if volume.type != "bind":72 raise ValueError(73 f"Mount to {DEFAULT_VOLUME_DIR} needs to be a bind mount for mounting to work"74 )75 if not path.startswith(f"{DEFAULT_VOLUME_DIR}/") and path != DEFAULT_VOLUME_DIR:76 # We should be able to replace something here.77 # if this warning is printed, the usage of this function is probably wrong.78 # Please check if the target path is indeed prefixed by /var/lib/localstack79 # if this happens, mounts may fail80 LOG.warning(81 "Error while performing automatic host path replacement for path '%s' to source '%s'",82 path,83 volume.source,...
test_docker_utils.py
Source: test_docker_utils.py
1from unittest import mock2from localstack.utils.container_utils.container_client import VolumeInfo3from localstack.utils.docker_utils import get_host_path_for_path_in_docker4class TestDockerUtils:5 def test_host_path_for_path_in_docker_windows(self):6 with mock.patch(7 "localstack.utils.docker_utils.get_default_volume_dir_mount"8 ) as get_volume, mock.patch("localstack.config.is_in_docker", True):9 get_volume.return_value = VolumeInfo(10 type="bind",11 source=r"C:\Users\localstack\volume\mount",12 destination="/var/lib/localstack",13 mode="rw",14 rw=True,15 propagation="rprivate",16 )17 result = get_host_path_for_path_in_docker("/var/lib/localstack/some/test/file")18 get_volume.assert_called_once()19 # this path style is kinda weird, but windows will accept it - no need for manual conversion of / to \20 assert result == r"C:\Users\localstack\volume\mount/some/test/file"21 def test_host_path_for_path_in_docker_linux(self):22 with mock.patch(23 "localstack.utils.docker_utils.get_default_volume_dir_mount"24 ) as get_volume, mock.patch("localstack.config.is_in_docker", True):25 get_volume.return_value = VolumeInfo(26 type="bind",27 source="/home/some-user/.cache/localstack/volume",28 destination="/var/lib/localstack",29 mode="rw",30 rw=True,31 propagation="rprivate",32 )33 result = get_host_path_for_path_in_docker("/var/lib/localstack/some/test/file")34 get_volume.assert_called_once()35 assert result == "/home/some-user/.cache/localstack/volume/some/test/file"36 def test_host_path_for_path_in_docker_linux_volume_dir(self):37 with mock.patch(38 "localstack.utils.docker_utils.get_default_volume_dir_mount"39 ) as get_volume, mock.patch("localstack.config.is_in_docker", True):40 get_volume.return_value = VolumeInfo(41 type="bind",42 source="/home/some-user/.cache/localstack/volume",43 destination="/var/lib/localstack",44 mode="rw",45 rw=True,46 propagation="rprivate",47 )48 result = get_host_path_for_path_in_docker("/var/lib/localstack")49 get_volume.assert_called_once()50 assert result == "/home/some-user/.cache/localstack/volume"51 def test_host_path_for_path_in_docker_linux_wrong_path(self):52 with mock.patch(53 "localstack.utils.docker_utils.get_default_volume_dir_mount"54 ) as get_volume, mock.patch("localstack.config.is_in_docker", True):55 get_volume.return_value = VolumeInfo(56 type="bind",57 source="/home/some-user/.cache/localstack/volume",58 destination="/var/lib/localstack",59 mode="rw",60 rw=True,61 propagation="rprivate",62 )63 result = get_host_path_for_path_in_docker("/var/lib/localstacktest")64 get_volume.assert_called_once()65 assert result == "/var/lib/localstacktest"66 result = get_host_path_for_path_in_docker("/etc/some/path")...
Check out the latest blogs from LambdaTest on this topic:
Agile has unquestionable benefits. The mainstream method has assisted numerous businesses in increasing organizational flexibility as a result, developing better, more intuitive software. Distributed development is also an important strategy for software companies. It gives access to global talent, the use of offshore outsourcing to reduce operating costs, and round-the-clock development.
Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
In today’s tech world, where speed is the key to modern software development, we should aim to get quick feedback on the impact of any change, and that is where CI/CD comes in place.
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
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!!