Best Python code snippet using lisa_python
test_tasks.py
Source:test_tasks.py
1"""Test kioscadmin tasks."""2from datetime import timedelta3from unittest import mock4from unittest.mock import patch, call5import docker.errors6from django.conf import settings7from django.utils import timezone8from containers.models import (9 ACTION_STOP,10 STATE_EXITED,11 STATE_RUNNING,12 ContainerLogEntry,13 STATE_INITIAL,14 PROCESS_DOCKER,15 ACTION_RESTART,16 ACTION_PAUSE,17 STATE_PAUSED,18 ACTION_UNPAUSE,19 ACTION_START,20 PROCESS_PROXY,21 ContainerBackgroundJob,22)23from kioscadmin.tasks import (24 connect_docker,25 poll_docker_status_and_logs,26 sync_container_state_with_last_user_action,27 DEFAULT_GRACE_PERIOD_CONTAINER_STATUS,28 stop_inactive_containers,29)30from containers.tests.factories import (31 ContainerBackgroundJobFactory,32 ContainerLogEntryFactory,33)34from containers.tests.helpers import (35 TestBase,36 DockerMock,37 log_entry1,38 log_entry2,39 log_entry3,40 log_entry1_no_date,41)42class TestPollDockerStatusAndLogsTask(TestBase):43 """Tests for ``poll_docker_status_and_logs`` task."""44 def setUp(self):45 super().setUp()46 self.cli = connect_docker()47 self.create_one_container()48 self.container1.container_id = DockerMock.create_container.get("Id")49 self.container1.image_id = DockerMock.inspect_image.get("Id")50 self.container1.save()51 self.bg_job = ContainerBackgroundJobFactory(52 project=self.project, user=self.superuser, container=self.container153 )54 @patch("docker.api.client.APIClient.logs")55 @patch("docker.api.client.APIClient.inspect_container")56 def test_all_new_entries(self, inspect_container, _logs):57 self.assertEqual(self.container1.state, STATE_INITIAL)58 # Prepare59 inspect_container.side_effect = [DockerMock.inspect_container_started]60 _logs.side_effect = [DockerMock.logs]61 # Run62 poll_docker_status_and_logs()63 # Assert objects64 self.container1.refresh_from_db()65 self.assertEqual(self.container1.state, STATE_RUNNING)66 self.assertEqual(67 ContainerLogEntry.objects.filter(container=self.container1).count(),68 3,69 )70 logs = [71 entry.text72 for entry in ContainerLogEntry.objects.filter(73 container=self.container174 )75 ]76 self.assertEqual(77 logs,78 [log_entry1()[1][31:], log_entry2()[1][31:], log_entry3()[1][31:]],79 )80 # Assert mocks81 inspect_container.assert_called_once_with(self.container1.container_id)82 _logs.assert_called_once_with(83 self.container1.container_id, timestamps=True84 )85 @patch("docker.api.client.APIClient.logs")86 @patch("docker.api.client.APIClient.inspect_container")87 def test_all_new_entries_no_date(self, inspect_container, _logs):88 self.assertEqual(self.container1.state, STATE_INITIAL)89 # Prepare90 inspect_container.side_effect = [DockerMock.inspect_container_started]91 _logs.side_effect = [DockerMock.logs_no_date]92 # Run93 poll_docker_status_and_logs()94 # Assert objects95 self.container1.refresh_from_db()96 self.assertEqual(self.container1.state, STATE_RUNNING)97 self.assertEqual(98 ContainerLogEntry.objects.filter(container=self.container1).count(),99 1,100 )101 logs = [102 entry.text103 for entry in ContainerLogEntry.objects.filter(104 container=self.container1105 )106 ]107 self.assertEqual(108 logs,109 ["Docker log has no timestamp! ({})".format(log_entry1_no_date())],110 )111 # Assert mocks112 inspect_container.assert_called_once_with(self.container1.container_id)113 _logs.assert_called_once_with(114 self.container1.container_id, timestamps=True115 )116 @patch("docker.api.client.APIClient.logs")117 @patch("docker.api.client.APIClient.inspect_container")118 def test_add_entries_since_date(self, inspect_container, _logs):119 self.assertEqual(self.container1.state, STATE_INITIAL)120 # Prepare121 dt1, entry1 = log_entry1()122 dt2, entry2 = log_entry2()123 ContainerLogEntryFactory(124 text=entry1[31:],125 container=self.container1,126 process=PROCESS_DOCKER,127 date_docker_log=dt1,128 user=None,129 )130 last_log = ContainerLogEntryFactory(131 text=entry2[31:],132 container=self.container1,133 process=PROCESS_DOCKER,134 date_docker_log=dt2,135 user=None,136 )137 inspect_container.side_effect = [DockerMock.inspect_container_started]138 _logs.side_effect = [DockerMock.logs_since]139 # Run140 poll_docker_status_and_logs()141 # Assert objects142 self.container1.refresh_from_db()143 self.assertEqual(self.container1.state, STATE_RUNNING)144 self.assertEqual(145 ContainerLogEntry.objects.filter(container=self.container1).count(),146 3,147 )148 logs = [149 entry.text150 for entry in ContainerLogEntry.objects.filter(151 container=self.container1152 )153 ]154 self.assertEqual(155 logs,156 [log_entry1()[1][31:], log_entry2()[1][31:], log_entry3()[1][31:]],157 )158 # Assert mocks159 inspect_container.assert_called_once_with(self.container1.container_id)160 _logs.assert_called_once_with(161 self.container1.container_id,162 timestamps=True,163 since=last_log.date_docker_log.replace(tzinfo=None),164 )165class TestSyncContainerStateWithLastUserActionTask(TestBase):166 """Tests for ``sync_container_state_with_last_user_action`` task."""167 def setUp(self):168 super().setUp()169 self.cli = connect_docker()170 self.create_one_container()171 self.container1.container_id = DockerMock.create_container.get("Id")172 self.container1.image_id = DockerMock.inspect_image.get("Id")173 self.container1.save()174 self.bg_job = ContainerBackgroundJobFactory(175 project=self.project, user=self.superuser, container=self.container1176 )177 @patch("docker.api.client.APIClient.remove_container")178 @patch("docker.api.client.APIClient.unpause")179 @patch("docker.api.client.APIClient.pause")180 @patch("docker.api.client.APIClient.stop")181 @patch("docker.api.client.APIClient.start")182 @patch("docker.api.client.APIClient.pull")183 @patch("docker.api.client.APIClient.inspect_container")184 @patch("docker.api.client.APIClient.inspect_image")185 @patch("docker.api.client.APIClient.create_host_config")186 @patch("docker.api.client.APIClient.create_container")187 def test_no_last_status_update(188 self,189 create_container,190 create_host_config,191 inspect_image,192 inspect_container,193 pull,194 start,195 stop,196 pause,197 unpause,198 remove_container,199 ):200 self.assertEqual(self.container1.state, STATE_INITIAL)201 inspect_container.side_effect = [DockerMock.inspect_container_started]202 # Run203 sync_container_state_with_last_user_action()204 # Assert mocks205 create_container.assert_not_called()206 create_host_config.assert_not_called()207 inspect_image.assert_not_called()208 inspect_container.assert_called_once_with(self.container1.container_id)209 pull.assert_not_called()210 start.assert_not_called()211 stop.assert_not_called()212 pause.assert_not_called()213 unpause.assert_not_called()214 remove_container.assert_not_called()215 # Assert objects216 self.bg_job.refresh_from_db()217 self.assertEqual(self.bg_job.retries, 0)218 @patch("docker.api.client.APIClient.remove_container")219 @patch("docker.api.client.APIClient.unpause")220 @patch("docker.api.client.APIClient.pause")221 @patch("docker.api.client.APIClient.stop")222 @patch("docker.api.client.APIClient.start")223 @patch("docker.api.client.APIClient.pull")224 @patch("docker.api.client.APIClient.inspect_container")225 @patch("docker.api.client.APIClient.inspect_image")226 @patch("docker.api.client.APIClient.create_host_config")227 @patch("docker.api.client.APIClient.create_container")228 def test_no_job(229 self,230 create_container,231 create_host_config,232 inspect_image,233 inspect_container,234 pull,235 start,236 stop,237 pause,238 unpause,239 remove_container,240 ):241 # Prepare242 self.bg_job.delete()243 self.container1.date_last_status_update = timezone.now()244 self.container1.save()245 inspect_container.side_effect = [DockerMock.inspect_container_started]246 # Run247 sync_container_state_with_last_user_action()248 # Assert mocks249 create_container.assert_not_called()250 create_host_config.assert_not_called()251 inspect_image.assert_not_called()252 inspect_container.assert_called_once_with(self.container1.container_id)253 pull.assert_not_called()254 start.assert_not_called()255 stop.assert_not_called()256 pause.assert_not_called()257 unpause.assert_not_called()258 remove_container.assert_not_called()259 @patch("docker.api.client.APIClient.remove_container")260 @patch("docker.api.client.APIClient.unpause")261 @patch("docker.api.client.APIClient.pause")262 @patch("docker.api.client.APIClient.stop")263 @patch("docker.api.client.APIClient.start")264 @patch("docker.api.client.APIClient.pull")265 @patch("docker.api.client.APIClient.inspect_container")266 @patch("docker.api.client.APIClient.inspect_image")267 @patch("docker.api.client.APIClient.create_host_config")268 @patch("docker.api.client.APIClient.create_container")269 def test_no_state(270 self,271 create_container,272 create_host_config,273 inspect_image,274 inspect_container,275 pull,276 start,277 stop,278 pause,279 unpause,280 remove_container,281 ):282 # Prepare283 self.container1.date_last_status_update = timezone.now()284 self.container1.save()285 inspect_container.side_effect = [DockerMock.inspect_container_no_info]286 # Run287 sync_container_state_with_last_user_action()288 # Assert mocks289 create_container.assert_not_called()290 create_host_config.assert_not_called()291 inspect_image.assert_not_called()292 inspect_container.assert_called_once_with(self.container1.container_id)293 pull.assert_not_called()294 start.assert_not_called()295 stop.assert_not_called()296 pause.assert_not_called()297 unpause.assert_not_called()298 remove_container.assert_not_called()299 # Assert objects300 self.bg_job.refresh_from_db()301 self.assertEqual(self.bg_job.retries, 0)302 @patch("docker.api.client.APIClient.remove_container")303 @patch("docker.api.client.APIClient.unpause")304 @patch("docker.api.client.APIClient.pause")305 @patch("docker.api.client.APIClient.stop")306 @patch("docker.api.client.APIClient.start")307 @patch("docker.api.client.APIClient.pull")308 @patch("docker.api.client.APIClient.inspect_container")309 @patch("docker.api.client.APIClient.inspect_image")310 @patch("docker.api.client.APIClient.create_host_config")311 @patch("docker.api.client.APIClient.create_container")312 def test_state_as_expected_start(313 self,314 create_container,315 create_host_config,316 inspect_image,317 inspect_container,318 pull,319 start,320 stop,321 pause,322 unpause,323 remove_container,324 ):325 # Prepare326 self.container1.date_last_status_update = timezone.now()327 self.container1.state = STATE_RUNNING328 self.container1.save()329 self.bg_job.action = ACTION_START330 self.bg_job.save()331 inspect_container.side_effect = [DockerMock.inspect_container_started]332 # Run333 sync_container_state_with_last_user_action()334 # Assert mocks335 create_container.assert_not_called()336 create_host_config.assert_not_called()337 inspect_image.assert_not_called()338 inspect_container.assert_called_once_with(self.container1.container_id)339 pull.assert_not_called()340 start.assert_not_called()341 stop.assert_not_called()342 pause.assert_not_called()343 unpause.assert_not_called()344 remove_container.assert_not_called()345 # Assert objects346 self.bg_job.refresh_from_db()347 self.assertEqual(self.bg_job.retries, 0)348 @patch("docker.api.client.APIClient.remove_container")349 @patch("docker.api.client.APIClient.unpause")350 @patch("docker.api.client.APIClient.pause")351 @patch("docker.api.client.APIClient.stop")352 @patch("docker.api.client.APIClient.start")353 @patch("docker.api.client.APIClient.pull")354 @patch("docker.api.client.APIClient.inspect_container")355 @patch("docker.api.client.APIClient.inspect_image")356 @patch("docker.api.client.APIClient.create_host_config")357 @patch("docker.api.client.APIClient.create_container")358 def test_as_expected_restart(359 self,360 create_container,361 create_host_config,362 inspect_image,363 inspect_container,364 pull,365 start,366 stop,367 pause,368 unpause,369 remove_container,370 ):371 # Prepare372 self.container1.date_last_status_update = timezone.now()373 self.container1.state = STATE_RUNNING374 self.container1.save()375 self.bg_job.action = ACTION_RESTART376 self.bg_job.save()377 inspect_container.side_effect = [DockerMock.inspect_container_restarted]378 # Run379 sync_container_state_with_last_user_action()380 # Assert mocks381 create_container.assert_not_called()382 create_host_config.assert_not_called()383 inspect_image.assert_not_called()384 inspect_container.assert_called_once_with(self.container1.container_id)385 pull.assert_not_called()386 start.assert_not_called()387 stop.assert_not_called()388 pause.assert_not_called()389 unpause.assert_not_called()390 remove_container.assert_not_called()391 # Assert objects392 self.bg_job.refresh_from_db()393 self.assertEqual(self.bg_job.retries, 0)394 @patch("docker.api.client.APIClient.remove_container")395 @patch("docker.api.client.APIClient.unpause")396 @patch("docker.api.client.APIClient.pause")397 @patch("docker.api.client.APIClient.stop")398 @patch("docker.api.client.APIClient.start")399 @patch("docker.api.client.APIClient.pull")400 @patch("docker.api.client.APIClient.inspect_container")401 @patch("docker.api.client.APIClient.inspect_image")402 @patch("docker.api.client.APIClient.create_host_config")403 @patch("docker.api.client.APIClient.create_container")404 def test_as_expected_stop(405 self,406 create_container,407 create_host_config,408 inspect_image,409 inspect_container,410 pull,411 start,412 stop,413 pause,414 unpause,415 remove_container,416 ):417 # Prepare418 self.container1.date_last_status_update = timezone.now()419 self.container1.state = STATE_EXITED420 self.container1.save()421 self.bg_job.action = ACTION_STOP422 self.bg_job.save()423 inspect_container.side_effect = [DockerMock.inspect_container_stopped]424 # Run425 sync_container_state_with_last_user_action()426 # Assert mocks427 create_container.assert_not_called()428 create_host_config.assert_not_called()429 inspect_image.assert_not_called()430 inspect_container.assert_called_once_with(self.container1.container_id)431 pull.assert_not_called()432 start.assert_not_called()433 stop.assert_not_called()434 pause.assert_not_called()435 unpause.assert_not_called()436 remove_container.assert_not_called()437 # Assert objects438 self.bg_job.refresh_from_db()439 self.assertEqual(self.bg_job.retries, 0)440 @patch("docker.api.client.APIClient.remove_container")441 @patch("docker.api.client.APIClient.unpause")442 @patch("docker.api.client.APIClient.pause")443 @patch("docker.api.client.APIClient.stop")444 @patch("docker.api.client.APIClient.start")445 @patch("docker.api.client.APIClient.pull")446 @patch("docker.api.client.APIClient.inspect_container")447 @patch("docker.api.client.APIClient.inspect_image")448 @patch("docker.api.client.APIClient.create_host_config")449 @patch("docker.api.client.APIClient.create_container")450 def test_state_as_expected_pause(451 self,452 create_container,453 create_host_config,454 inspect_image,455 inspect_container,456 pull,457 start,458 stop,459 pause,460 unpause,461 remove_container,462 ):463 # Prepare464 self.container1.date_last_status_update = timezone.now()465 self.container1.state = STATE_PAUSED466 self.container1.save()467 self.bg_job.action = ACTION_PAUSE468 self.bg_job.save()469 inspect_container.side_effect = [DockerMock.inspect_container_paused]470 # Run471 sync_container_state_with_last_user_action()472 # Assert mocks473 create_container.assert_not_called()474 create_host_config.assert_not_called()475 inspect_image.assert_not_called()476 inspect_container.assert_called_once_with(self.container1.container_id)477 pull.assert_not_called()478 start.assert_not_called()479 stop.assert_not_called()480 pause.assert_not_called()481 unpause.assert_not_called()482 remove_container.assert_not_called()483 # Assert objects484 self.bg_job.refresh_from_db()485 self.assertEqual(self.bg_job.retries, 0)486 @patch("docker.api.client.APIClient.remove_container")487 @patch("docker.api.client.APIClient.unpause")488 @patch("docker.api.client.APIClient.pause")489 @patch("docker.api.client.APIClient.stop")490 @patch("docker.api.client.APIClient.start")491 @patch("docker.api.client.APIClient.pull")492 @patch("docker.api.client.APIClient.inspect_container")493 @patch("docker.api.client.APIClient.inspect_image")494 @patch("docker.api.client.APIClient.create_host_config")495 @patch("docker.api.client.APIClient.create_container")496 def test_state_as_expected_unpause(497 self,498 create_container,499 create_host_config,500 inspect_image,501 inspect_container,502 pull,503 start,504 stop,505 pause,506 unpause,507 remove_container,508 ):509 # Prepare510 self.container1.date_last_status_update = timezone.now()511 self.container1.state = STATE_RUNNING512 self.container1.save()513 self.bg_job.action = ACTION_UNPAUSE514 self.bg_job.save()515 inspect_container.side_effect = [DockerMock.inspect_container_unpaused]516 # Run517 sync_container_state_with_last_user_action()518 # Assert mocks519 create_container.assert_not_called()520 create_host_config.assert_not_called()521 inspect_image.assert_not_called()522 inspect_container.assert_called_once_with(self.container1.container_id)523 pull.assert_not_called()524 start.assert_not_called()525 stop.assert_not_called()526 pause.assert_not_called()527 unpause.assert_not_called()528 remove_container.assert_not_called()529 # Assert objects530 self.bg_job.refresh_from_db()531 self.assertEqual(self.bg_job.retries, 0)532 @patch("docker.api.client.APIClient.remove_container")533 @patch("docker.api.client.APIClient.unpause")534 @patch("docker.api.client.APIClient.pause")535 @patch("docker.api.client.APIClient.stop")536 @patch("docker.api.client.APIClient.start")537 @patch("docker.api.client.APIClient.pull")538 @patch("docker.api.client.APIClient.inspect_container")539 @patch("docker.api.client.APIClient.inspect_image")540 @patch("docker.api.client.APIClient.create_host_config")541 @patch("docker.api.client.APIClient.create_container")542 def test_timeout_not_yet_passed(543 self,544 create_container,545 create_host_config,546 inspect_image,547 inspect_container,548 pull,549 start,550 stop,551 pause,552 unpause,553 remove_container,554 ):555 # Prepare556 self.container1.date_last_status_update = timezone.now()557 self.container1.state = STATE_RUNNING558 self.container1.save()559 self.bg_job.action = ACTION_STOP560 self.bg_job.save()561 inspect_container.side_effect = [DockerMock.inspect_container_started]562 # Run563 sync_container_state_with_last_user_action()564 # Assert mocks565 create_container.assert_not_called()566 create_host_config.assert_not_called()567 inspect_image.assert_not_called()568 inspect_container.assert_called_once_with(self.container1.container_id)569 pull.assert_not_called()570 start.assert_not_called()571 stop.assert_not_called()572 pause.assert_not_called()573 unpause.assert_not_called()574 remove_container.assert_not_called()575 # Assert objects576 self.bg_job.refresh_from_db()577 self.assertEqual(self.bg_job.retries, 0)578 @patch("docker.api.client.APIClient.remove_container")579 @patch("docker.api.client.APIClient.unpause")580 @patch("docker.api.client.APIClient.pause")581 @patch("docker.api.client.APIClient.stop")582 @patch("docker.api.client.APIClient.start")583 @patch("docker.api.client.APIClient.pull")584 @patch("docker.api.client.APIClient.inspect_container")585 @patch("docker.api.client.APIClient.inspect_image")586 @patch("docker.api.client.APIClient.create_host_config")587 @patch("docker.api.client.APIClient.create_container")588 def test_max_retries_hit(589 self,590 create_container,591 create_host_config,592 inspect_image,593 inspect_container,594 pull,595 start,596 stop,597 pause,598 unpause,599 remove_container,600 ):601 # Prepare602 self.container1.date_last_status_update = timezone.now() - timedelta(603 seconds=DEFAULT_GRACE_PERIOD_CONTAINER_STATUS + 20604 )605 self.container1.state = STATE_RUNNING606 self.container1.save()607 self.bg_job.action = ACTION_STOP608 self.bg_job.retries = self.container1.max_retries609 self.bg_job.save()610 inspect_container.side_effect = [DockerMock.inspect_container_started]611 # Run612 sync_container_state_with_last_user_action()613 # Assert mocks614 create_container.assert_not_called()615 create_host_config.assert_not_called()616 inspect_image.assert_not_called()617 inspect_container.assert_called_once_with(self.container1.container_id)618 pull.assert_not_called()619 start.assert_not_called()620 stop.assert_not_called()621 pause.assert_not_called()622 unpause.assert_not_called()623 remove_container.assert_not_called()624 # Assert objects625 self.bg_job.refresh_from_db()626 self.assertEqual(self.bg_job.retries, self.container1.max_retries)627 @patch("docker.api.client.APIClient.remove_container")628 @patch("docker.api.client.APIClient.unpause")629 @patch("docker.api.client.APIClient.pause")630 @patch("docker.api.client.APIClient.stop")631 @patch("docker.api.client.APIClient.start")632 @patch("docker.api.client.APIClient.pull")633 @patch("docker.api.client.APIClient.inspect_container")634 @patch("docker.api.client.APIClient.inspect_image")635 @patch("docker.api.client.APIClient.create_host_config")636 @patch("docker.api.client.APIClient.create_container")637 def test_stopping(638 self,639 create_container,640 create_host_config,641 inspect_image,642 inspect_container,643 pull,644 start,645 stop,646 pause,647 unpause,648 remove_container,649 ):650 # Prepare651 self.container1.date_last_status_update = timezone.now() - timedelta(652 seconds=DEFAULT_GRACE_PERIOD_CONTAINER_STATUS + 20653 )654 self.container1.state = STATE_RUNNING655 self.container1.save()656 self.bg_job.action = ACTION_STOP657 self.bg_job.save()658 inspect_container.side_effect = [659 DockerMock.inspect_container_started,660 DockerMock.inspect_container_stopped,661 ]662 # Run663 sync_container_state_with_last_user_action()664 # Assert mocks665 create_container.assert_not_called()666 create_host_config.assert_not_called()667 inspect_image.assert_not_called()668 inspect_container.assert_has_calls(669 [call(self.container1.container_id)] * 2670 )671 pull.assert_not_called()672 start.assert_not_called()673 stop.assert_called_once_with(self.container1.container_id)674 pause.assert_not_called()675 unpause.assert_not_called()676 remove_container.assert_not_called()677 # Assert objects678 self.container1.refresh_from_db()679 self.bg_job.refresh_from_db()680 self.assertEqual(self.bg_job.retries, 1)681 self.assertEqual(self.container1.state, STATE_EXITED)682 @patch("docker.api.client.APIClient.remove_container")683 @patch("docker.api.client.APIClient.unpause")684 @patch("docker.api.client.APIClient.pause")685 @patch("docker.api.client.APIClient.stop")686 @patch("docker.api.client.APIClient.start")687 @patch("docker.api.client.APIClient.pull")688 @patch("docker.api.client.APIClient.inspect_container")689 @patch("docker.api.client.APIClient.inspect_image")690 @patch("docker.api.client.APIClient.create_host_config")691 @patch("docker.api.client.APIClient.create_networking_config")692 @patch("docker.api.client.APIClient.create_endpoint_config")693 @patch("docker.api.client.APIClient.create_container")694 def test_starting(695 self,696 create_container,697 create_endpoint_config,698 create_networking_config,699 create_host_config,700 inspect_image,701 inspect_container,702 pull,703 start,704 stop,705 pause,706 unpause,707 remove_container,708 ):709 # Prepare710 self.container1.date_last_status_update = timezone.now() - timedelta(711 seconds=DEFAULT_GRACE_PERIOD_CONTAINER_STATUS + 20712 )713 self.container1.state = STATE_EXITED714 self.container1.save()715 self.bg_job.action = ACTION_START716 self.bg_job.save()717 create_container.side_effect = [DockerMock.create_container]718 create_host_config.side_effect = [DockerMock.create_host_config]719 inspect_container.side_effect = [720 DockerMock.inspect_container_stopped,721 DockerMock.inspect_container_started,722 ]723 inspect_image.side_effect = [DockerMock.inspect_image]724 environment = dict(self.container1.environment)725 environment.update(726 {727 "CONTAINER_PORT": self.container1.container_port,728 "TITLE": self.container1.title,729 "DESCRIPTION": self.container1.description,730 }731 )732 # Run733 sync_container_state_with_last_user_action()734 # Assert mocks735 create_container.assert_called_once_with(736 detach=True,737 image=self.container1.image_id,738 environment=environment,739 command=self.container1.command or None,740 ports=[self.container1.container_port],741 host_config=None,742 )743 create_host_config.assert_called_once_with(744 ulimits=[745 {746 "Name": "nofile",747 "Soft": settings.KIOSC_DOCKER_MAX_ULIMIT_NOFILE_SOFT,748 "Hard": settings.KIOSC_DOCKER_MAX_ULIMIT_NOFILE_HARD,749 }750 ],751 port_bindings={752 self.container1.container_port: self.container1.host_port753 },754 )755 create_endpoint_config.assert_not_called(),756 create_networking_config.assert_not_called(),757 inspect_image.assert_called_once_with(self.container1.get_repos_full())758 inspect_container.assert_has_calls(759 [call(self.container1.container_id)] * 2760 )761 pull.assert_called_once_with(762 repository=self.container1.repository,763 tag=self.container1.tag,764 stream=True,765 decode=True,766 )767 start.assert_called_once_with(self.container1.container_id)768 stop.assert_not_called()769 pause.assert_not_called()770 unpause.assert_not_called()771 remove_container.assert_called_once_with(self.container1.container_id)772 # Assert objects773 self.container1.refresh_from_db()774 self.bg_job.refresh_from_db()775 self.assertEqual(self.bg_job.retries, 1)776 self.assertEqual(self.container1.state, STATE_RUNNING)777 @patch("docker.api.client.APIClient.remove_container")778 @patch("docker.api.client.APIClient.unpause")779 @patch("docker.api.client.APIClient.pause")780 @patch("docker.api.client.APIClient.stop")781 @patch("docker.api.client.APIClient.start")782 @patch("docker.api.client.APIClient.pull")783 @patch("docker.api.client.APIClient.inspect_container")784 @patch("docker.api.client.APIClient.inspect_image")785 @patch("docker.api.client.APIClient.create_host_config")786 @patch("docker.api.client.APIClient.create_container")787 def test_pausing(788 self,789 create_container,790 create_host_config,791 inspect_image,792 inspect_container,793 pull,794 start,795 stop,796 pause,797 unpause,798 remove_container,799 ):800 # Prepare801 self.container1.date_last_status_update = timezone.now() - timedelta(802 seconds=DEFAULT_GRACE_PERIOD_CONTAINER_STATUS + 20803 )804 self.container1.state = STATE_RUNNING805 self.container1.save()806 self.bg_job.action = ACTION_PAUSE807 self.bg_job.save()808 inspect_container.side_effect = [809 DockerMock.inspect_container_started,810 DockerMock.inspect_container_paused,811 ]812 # Run813 sync_container_state_with_last_user_action()814 # Assert mocks815 create_container.assert_not_called()816 create_host_config.assert_not_called()817 inspect_image.assert_not_called()818 inspect_container.assert_has_calls(819 [call(self.container1.container_id)] * 2820 )821 pull.assert_not_called()822 start.assert_not_called()823 stop.assert_not_called()824 pause.assert_called_once_with(self.container1.container_id)825 unpause.assert_not_called()826 remove_container.assert_not_called()827 # Assert objects828 self.container1.refresh_from_db()829 self.bg_job.refresh_from_db()830 self.assertEqual(self.bg_job.retries, 1)831 self.assertEqual(self.container1.state, STATE_PAUSED)832 @patch("docker.api.client.APIClient.remove_container")833 @patch("docker.api.client.APIClient.unpause")834 @patch("docker.api.client.APIClient.pause")835 @patch("docker.api.client.APIClient.stop")836 @patch("docker.api.client.APIClient.start")837 @patch("docker.api.client.APIClient.pull")838 @patch("docker.api.client.APIClient.inspect_container")839 @patch("docker.api.client.APIClient.inspect_image")840 @patch("docker.api.client.APIClient.create_host_config")841 @patch("docker.api.client.APIClient.create_container")842 def test_unpausing(843 self,844 create_container,845 create_host_config,846 inspect_image,847 inspect_container,848 pull,849 start,850 stop,851 pause,852 unpause,853 remove_container,854 ):855 # Prepare856 self.container1.date_last_status_update = timezone.now() - timedelta(857 seconds=DEFAULT_GRACE_PERIOD_CONTAINER_STATUS + 20858 )859 self.container1.state = STATE_PAUSED860 self.container1.save()861 self.bg_job.action = ACTION_UNPAUSE862 self.bg_job.save()863 inspect_container.side_effect = [864 DockerMock.inspect_container_paused,865 DockerMock.inspect_container_unpaused,866 ]867 # Run868 sync_container_state_with_last_user_action()869 # Assert mocks870 create_container.assert_not_called()871 create_host_config.assert_not_called()872 inspect_image.assert_not_called()873 inspect_container.assert_has_calls(874 [call(self.container1.container_id)] * 2875 )876 pull.assert_not_called()877 start.assert_not_called()878 stop.assert_not_called()879 pause.assert_not_called()880 unpause.assert_called_once_with(self.container1.container_id)881 remove_container.assert_not_called()882 # Assert objects883 self.container1.refresh_from_db()884 self.bg_job.refresh_from_db()885 self.assertEqual(self.bg_job.retries, 1)886 self.assertEqual(self.container1.state, STATE_RUNNING)887class TestStopInactiveContainers(TestBase):888 """Tests for ``stop_inactive_containers`` task."""889 def setUp(self):890 super().setUp()891 self.cli = connect_docker()892 self.create_one_container()893 self.container1.container_id = DockerMock.create_container.get("Id")894 self.container1.image_id = DockerMock.inspect_image.get("Id")895 self.container1.save()896 @patch("docker.api.client.APIClient.remove_container")897 @patch("docker.api.client.APIClient.unpause")898 @patch("docker.api.client.APIClient.pause")899 @patch("docker.api.client.APIClient.stop")900 @patch("docker.api.client.APIClient.start")901 @patch("docker.api.client.APIClient.pull")902 @patch("docker.api.client.APIClient.inspect_container")903 @patch("docker.api.client.APIClient.inspect_image")904 @patch("docker.api.client.APIClient.create_host_config")905 @patch("docker.api.client.APIClient.create_container")906 def test_no_container_id(907 self,908 create_container,909 create_host_config,910 inspect_image,911 inspect_container,912 pull,913 start,914 stop,915 pause,916 unpause,917 remove_container,918 ):919 self.assertEqual(self.container1.state, STATE_INITIAL)920 inspect_container.side_effect = docker.errors.NotFound("x")921 # Run922 stop_inactive_containers()923 # Assert mocks924 create_container.assert_not_called()925 create_host_config.assert_not_called()926 inspect_image.assert_not_called()927 inspect_container.assert_called_once_with(self.container1.container_id)928 pull.assert_not_called()929 start.assert_not_called()930 stop.assert_not_called()931 pause.assert_not_called()932 unpause.assert_not_called()933 remove_container.assert_not_called()934 # Assert objects935 self.assertEqual(ContainerBackgroundJob.objects.count(), 0)936 @patch("docker.api.client.APIClient.remove_container")937 @patch("docker.api.client.APIClient.unpause")938 @patch("docker.api.client.APIClient.pause")939 @patch("docker.api.client.APIClient.stop")940 @patch("docker.api.client.APIClient.start")941 @patch("docker.api.client.APIClient.pull")942 @patch("docker.api.client.APIClient.inspect_container")943 @patch("docker.api.client.APIClient.inspect_image")944 @patch("docker.api.client.APIClient.create_host_config")945 @patch("docker.api.client.APIClient.create_container")946 def test_no_state(947 self,948 create_container,949 create_host_config,950 inspect_image,951 inspect_container,952 pull,953 start,954 stop,955 pause,956 unpause,957 remove_container,958 ):959 self.assertEqual(self.container1.state, STATE_INITIAL)960 inspect_container.side_effect = [DockerMock.inspect_container_no_info]961 # Run962 stop_inactive_containers()963 # Assert mocks964 create_container.assert_not_called()965 create_host_config.assert_not_called()966 inspect_image.assert_not_called()967 inspect_container.assert_called_once_with(self.container1.container_id)968 pull.assert_not_called()969 start.assert_not_called()970 stop.assert_not_called()971 pause.assert_not_called()972 unpause.assert_not_called()973 remove_container.assert_not_called()974 # Assert objects975 self.assertEqual(ContainerBackgroundJob.objects.count(), 0)976 @patch("docker.api.client.APIClient.remove_container")977 @patch("docker.api.client.APIClient.unpause")978 @patch("docker.api.client.APIClient.pause")979 @patch("docker.api.client.APIClient.stop")980 @patch("docker.api.client.APIClient.start")981 @patch("docker.api.client.APIClient.pull")982 @patch("docker.api.client.APIClient.inspect_container")983 @patch("docker.api.client.APIClient.inspect_image")984 @patch("docker.api.client.APIClient.create_host_config")985 @patch("docker.api.client.APIClient.create_container")986 def test_state_exited(987 self,988 create_container,989 create_host_config,990 inspect_image,991 inspect_container,992 pull,993 start,994 stop,995 pause,996 unpause,997 remove_container,998 ):999 self.container1.state = STATE_EXITED1000 self.container1.save()1001 inspect_container.side_effect = [DockerMock.inspect_container_stopped]1002 # Run1003 stop_inactive_containers()1004 # Assert mocks1005 create_container.assert_not_called()1006 create_host_config.assert_not_called()1007 inspect_image.assert_not_called()1008 inspect_container.assert_called_once_with(self.container1.container_id)1009 pull.assert_not_called()1010 start.assert_not_called()1011 stop.assert_not_called()1012 pause.assert_not_called()1013 unpause.assert_not_called()1014 remove_container.assert_not_called()1015 # Assert objects1016 self.assertEqual(ContainerBackgroundJob.objects.count(), 0)1017 @patch("docker.api.client.APIClient.remove_container")1018 @patch("docker.api.client.APIClient.unpause")1019 @patch("docker.api.client.APIClient.pause")1020 @patch("docker.api.client.APIClient.stop")1021 @patch("docker.api.client.APIClient.start")1022 @patch("docker.api.client.APIClient.pull")1023 @patch("docker.api.client.APIClient.inspect_container")1024 @patch("docker.api.client.APIClient.inspect_image")1025 @patch("docker.api.client.APIClient.create_host_config")1026 @patch("docker.api.client.APIClient.create_container")1027 def test_no_last_access(1028 self,1029 create_container,1030 create_host_config,1031 inspect_image,1032 inspect_container,1033 pull,1034 start,1035 stop,1036 pause,1037 unpause,1038 remove_container,1039 ):1040 # Prepare1041 inspect_container.side_effect = [DockerMock.inspect_container_started]1042 # Run1043 stop_inactive_containers()1044 # Assert mocks1045 create_container.assert_not_called()1046 create_host_config.assert_not_called()1047 inspect_image.assert_not_called()1048 inspect_container.assert_called_once_with(self.container1.container_id)1049 pull.assert_not_called()1050 start.assert_not_called()1051 stop.assert_not_called()1052 pause.assert_not_called()1053 unpause.assert_not_called()1054 remove_container.assert_not_called()1055 # Assert objects1056 self.assertEqual(ContainerBackgroundJob.objects.count(), 0)1057 @patch("docker.api.client.APIClient.remove_container")1058 @patch("docker.api.client.APIClient.unpause")1059 @patch("docker.api.client.APIClient.pause")1060 @patch("docker.api.client.APIClient.stop")1061 @patch("docker.api.client.APIClient.start")1062 @patch("docker.api.client.APIClient.pull")1063 @patch("docker.api.client.APIClient.inspect_container")1064 @patch("docker.api.client.APIClient.inspect_image")1065 @patch("docker.api.client.APIClient.create_host_config")1066 @patch("docker.api.client.APIClient.create_container")1067 def test_last_access_below_threshold(1068 self,1069 create_container,1070 create_host_config,1071 inspect_image,1072 inspect_container,1073 pull,1074 start,1075 stop,1076 pause,1077 unpause,1078 remove_container,1079 ):1080 # Prepare1081 self.container1.log_entries.create(1082 text="Accessing", process=PROCESS_PROXY, user=self.superuser1083 )1084 self.container1.inactivity_threshold = 11085 self.container1.save()1086 inspect_container.side_effect = [DockerMock.inspect_container_started]1087 # Run1088 stop_inactive_containers()1089 # Assert mocks1090 create_container.assert_not_called()1091 create_host_config.assert_not_called()1092 inspect_image.assert_not_called()1093 inspect_container.assert_called_once_with(self.container1.container_id)1094 pull.assert_not_called()1095 start.assert_not_called()1096 stop.assert_not_called()1097 pause.assert_not_called()1098 unpause.assert_not_called()1099 remove_container.assert_not_called()1100 # Assert objects1101 self.assertEqual(ContainerBackgroundJob.objects.count(), 0)1102 @patch("docker.api.client.APIClient.remove_container")1103 @patch("docker.api.client.APIClient.unpause")1104 @patch("docker.api.client.APIClient.pause")1105 @patch("docker.api.client.APIClient.stop")1106 @patch("docker.api.client.APIClient.start")1107 @patch("docker.api.client.APIClient.pull")1108 @patch("docker.api.client.APIClient.inspect_container")1109 @patch("docker.api.client.APIClient.inspect_image")1110 @patch("docker.api.client.APIClient.create_host_config")1111 @patch("docker.api.client.APIClient.create_container")1112 def test_last_access_above_threshold(1113 self,1114 create_container,1115 create_host_config,1116 inspect_image,1117 inspect_container,1118 pull,1119 start,1120 stop,1121 pause,1122 unpause,1123 remove_container,1124 ):1125 # Prepare1126 mock_now = timezone.now() - timedelta(days=2)1127 with mock.patch(1128 "django.utils.timezone.now", mock.Mock(return_value=mock_now)1129 ):1130 self.container1.log_entries.create(1131 text="Accessing",1132 process=PROCESS_PROXY,1133 user=self.superuser,1134 )1135 self.container1.state = STATE_RUNNING1136 self.container1.inactivity_threshold = 11137 self.container1.save()1138 inspect_container.side_effect = [1139 DockerMock.inspect_container_started,1140 DockerMock.inspect_container_stopped,1141 ]1142 # Run1143 stop_inactive_containers()1144 # Assert mocks1145 create_container.assert_not_called()1146 create_host_config.assert_not_called()1147 inspect_image.assert_not_called()1148 inspect_container.assert_has_calls(1149 [call(self.container1.container_id)] * 21150 )1151 pull.assert_not_called()1152 start.assert_not_called()1153 stop.assert_called_once_with(self.container1.container_id)1154 pause.assert_not_called()1155 unpause.assert_not_called()1156 remove_container.assert_not_called()1157 # Assert objects...
common_environment.py
Source:common_environment.py
...12 context.build_or_pull_image(skip_pull=True, skip_build=True)13def sample_after_scenario(context, scenario):14 if context.config.userdata['KEEP_CONTAINER_AFTER_TEST']:15 return16 context.remove_container()17def sample_after_all(context):18 if hasattr(context, 'temp_dir'):19 shutil.rmtree(context.temp_dir) # FIXME catch exception20def docker_setup(context):21 # Set a remote dir for commands22 context.remote_dir = '/tmp/'23 # Read ansible inventory from config24 ansible_cfg = None25 logging.info("Reading ansible config")26 try:27 ansible_cfg = context.config.userdata['ANSIBLE']28 except KeyError:29 raise Exception("-D ANSIBLE missing")30 def open_file(path):31 context.temp_dir = tempfile.mkdtemp()32 ret = Runner(33 module_name='fetch',34 inventory_file=ansible_cfg,35 module_args='src={0} dest={1}'.format(36 path, context.temp_dir)).run()37 for _, value in ret['contacted'].iteritems():38 try:39 ret_file = open(value['dest'])40 return ret_file41 except KeyError:42 print("ansible output: {0}".format(ret))43 raise Exception(value['msg'])44 context.open_file = open_file45 def run(command):46 if '{{' in command:47 command = command.replace("{{", "{{ '{{").replace("}}", "}}' }}")48 if '=' in command:49 command = command.replace('=', '\=')50 logging.info("Running '%s'", command)51 context.result = Runner(52 module_name="shell",53 inventory_file=ansible_cfg,54 module_args="{0} chdir={1}".format(command, context.remote_dir)55 ).run()56 # dark means not responding57 if 'dark' in context.result:58 print(context.result)59 for host, values in context.result['contacted'].iteritems():60 retvalue = values.get('rc')61 logging.info("On {0} returned {1}".format(host, retvalue))62 if 'cmd' in values:63 logging.info("cmd: {0}".format(values['cmd']))64 if 'stderr' in values:65 logging.info('stderr:%s', values['stderr'])66 result = ''67 if 'msg' in values:68 logging.info('msg:%s', values['msg'])69 result = values['msg']70 if 'stdout' in values:71 logging.info('stdout:%s', values['stdout'])72 result = values['stdout']73 if 'failed' in values:74 assert False75 return result76 context.run = run77 def copy_dockerfile():78 try:79 # copy dockerfile80 dockerfile = context.config.userdata['DOCKERFILE']81 dockerfile_dir = os.path.dirname(dockerfile)82 # create remote directory83 Runner(84 inventory_file=ansible_cfg,85 module_name='file',86 module_args='dest={0} state=directory'.format(context.remote_dir)87 ).run()88 # copy dockerfile89 Runner(90 inventory_file=ansible_cfg,91 module_name='copy',92 module_args='src={0} dest={1}'.format(dockerfile, context.remote_dir)93 ).run()94 # copy files from dockerfile95 f_in = open(dockerfile)96 for path in re.findall('(?:ADD|COPY) ([^ ]+) ', f_in.read()):97 for glob_path in glob.glob(os.path.join(dockerfile_dir, path)):98 # TODO Is there a nicer way to keep permissions?99 Runner(100 inventory_file=ansible_cfg,101 module_name='copy',102 module_args='src={0} dest={1} directory_mode mode={2}'.format(103 glob_path, context.remote_dir,104 oct(stat.S_IMODE(os.stat(glob_path).st_mode)))105 ).run()106 except Exception as e:107 logging.warning("copy_dockerfile:%s", e)108 context.copy_dockerfile_to_remote_machine = copy_dockerfile109 def build_or_pull_image(skip_build=False, skip_pull=False):110 # build image if not exist111 try:112 context.image = context.config.userdata['IMAGE']113 if not skip_pull:114 run('docker pull {0}'.format(context.image))115 except AssertionError:116 pass117 except KeyError:118 context.image = 'ctf'119 if not skip_build:120 try:121 run('docker build -t {0} .'.format(context.image))122 except AssertionError:123 pass124 context.cid_file = "/tmp/%s.cid" % re.sub(r'\W+', '', context.image)125 context.build_or_pull_image = build_or_pull_image126 def get_current_cid():127 try:128 return context.run('cat %s' % context.cid_file)129 except AssertionError as e:130 logging.info("remove_container: %s", str(e))131 return132 context.get_current_cid = get_current_cid133 def remove_container(show_logs=True, kill=True, rm=True):134 cid = context.get_current_cid()135 if cid:136 if show_logs:137 context.run("docker logs %s" % cid)138 try:139 context.run("docker stop %s" % cid)140 except AssertionError:141 if kill:142 context.run("docker kill %s" % cid)143 finally:144 if rm:145 context.run("docker rm -f %s" % cid)146 if hasattr(context, 'cid'):147 del context.cid...
analyze.py
Source:analyze.py
1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4Created on Mon Oct 25 16:00:22 20215@author: grahamseasons6"""7from nipype import Workflow, Node, MapNode, Function, IdentityInterface8from nipype.interfaces.fsl import MultipleRegressDesign, FLAMEO, Merge9import os10 11class level3:12 def __init__(self, task, pipeline, base_dir):13 self.task = task14 self.pipeline = pipeline15 self.base_dir = base_dir16 17 def construct(self):18 from l3_analysis.functions import get_sink, remove_container, mniMask19 level3 = Workflow('level3')20 level3.base_dir = os.getcwd()21 #remove container from outputs22 inputnode = Node(IdentityInterface(fields=['copes', 'varcopes', 'mask', 'covariates', 'subjects']), name='inputnode')23 24 intermediates = ['copes', 'varcopes', 'flameo_stats']25 files = []#stats/file26 27 self.l3(level3)28 29 level3.connect([(inputnode, level3.get_node('group'), [('covariates', 'covariate'),30 ('subjects', 'subjects')]),31 (inputnode, level3.get_node('groupcontrast'), [('copes', 'copes'),32 ('varcopes', 'varcopes')]),33 (inputnode, level3.get_node('flameo'), [(('mask', mniMask), 'mask_file')]),34 ])35 36 outnode = Node(IdentityInterface(fields=['copes', 'varcopes', 'dof', 'zstats', 'flameo_stats', 'mask']), name='outnode')37 38 level3.connect([(level3.get_node('flameo'), outnode, [(('copes', remove_container), 'copes'),39 (('var_copes', remove_container), 'varcopes'),40 (('tdof', remove_container), 'dof'),41 (('zstats', remove_container), 'zstats'),42 (('stats_dir', remove_container), 'flameo_stats')]),43 (inputnode, outnode, [(('mask', mniMask), 'mask')]),44 ])45 46 write = Node(Function(input_names=['base_dir', 'pipeline_st', 'task']+intermediates), name='write')47 write.inputs.function_str = get_sink(intermediates, files)48 write.inputs.base_dir = self.base_dir49 write.inputs.pipeline_st = self.pipeline50 write.inputs.task = self.task51 52 level3.connect([(level3.get_node('flameo'), write, [(('copes', remove_container), 'copes'),53 (('var_copes', remove_container), 'varcopes'),54 (('zstats', remove_container), 'zstats'),55 (('stats_dir', remove_container), 'flameo_stats')]),56 ])57 58 return level359 60 61 def l3(self, flow):62 from l3_analysis.functions import group_contrast63 self.setup(flow)64 65 l3model = Node(MultipleRegressDesign(), name='l3model')66 67 groupcontrast = Node(Function(input_names=['copes', 'varcopes'],68 output_names=['copes', 'varcopes'], 69 function=group_contrast), name='groupcontrast')70 71 mergecopes = MapNode(Merge(dimension='t'), iterfield='in_files', name='mergecopes')72 mergevarcopes = MapNode(Merge(dimension='t'), iterfield='in_files', name='mergevarcopes')73 74 flameo = MapNode(FLAMEO(), iterfield=['cope_file', 'var_cope_file'], name='flameo', n_procs=2, mem_gb=0.3)75 76 flow.connect([(flow.get_node('group'), l3model, [('EVs', 'regressors'),77 ('contrasts', 'contrasts'),78 ('group_ids', 'groups')]),79 (groupcontrast, mergecopes, [('copes', 'in_files')]),80 (groupcontrast, mergevarcopes, [('varcopes', 'in_files')]),81 (mergecopes, flameo, [('merged_file', 'cope_file')]),82 (mergevarcopes, flameo, [('merged_file', 'var_cope_file')]),83 (l3model, flameo, [('design_con', 't_con_file'),84 ('design_grp', 'cov_split_file'),85 ('design_fts', 'f_con_file'),86 ('design_mat', 'design_file')]),87 ])88 89 90 def setup(self, flow):91 from l3_analysis.functions import t_test92 93 group = Node(Function(input_names=['covariate', 'subjects', 'demean'],94 output_names=['EVs', 'contrasts', 'group_ids'], function=t_test), name='group')95 96 flow.add_nodes([group])97 98 99 100 101 102 103 104 105 ...
dockerSetMonitor.py
Source:dockerSetMonitor.py
...4from config import *5def make_new_influxdb(domain, port):6 remote = get_docker_manager(domain, port)7 try:8 remote.remove_container('influxdb')9 except Exception as e:10 print(e)11 remote.run(image='tutum/influxdb:latest', name='influxdb', ports=INFLUXDB_PORTS, detach=True, environment=INFLUXDB_ENV, volumes=INFLUXDB_VOLUMES, restart_policy=RESTART)12 remote.list()13def make_new_grafana(domain, port):14 remote = get_docker_manager(domain, port)15 try:16 remote.remove_container('grafana')17 except Exception as e:18 print(e)19 remote.run(image='grafana/grafana:latest', name='grafana', ports=GRAFANA_PORTS, detach=True, environment=GRAFANA_ENV, volumes=GRAFANA_VOLUMES, restart_policy=RESTART)20 remote.list()21def make_new_cadvisor(domain, port, instance):22 remote = get_docker_manager(domain, port)23 try:24 remote.remove_container('cadvisor')25 except Exception as e:26 print(e)27 temp_command = CADVISOR_COMMAND28 temp_command[3] = instance29 remote.run(image='google/cadvisor:latest', name='cadvisor', ports=CADVISOR_PORTS, detach=True, volumes=CADVISOR_VOLUMES, command=temp_command)30 remote.list()31def make_new_smtp(domain, port):32 remote = get_docker_manager(domain, port)33 try:34 remote.remove_container('smtp')35 except Exception as e:36 print(e)37 # remote.run(image='namshi/smtp:latest', name='smtp', ports=SMTP_PORTS, detach=True, environment=SMTP_ENV)...
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!!