def test_stop_dependency_and_dependant_excluded(self): collection = ServiceCollection() class NewServiceBase(Service): name = "not used" image = "not used" collection._base_class = NewServiceBase class ServiceOne(NewServiceBase): name = "hello" image = "hello" dependencies = ["howareyou"] class ServiceTwo(NewServiceBase): name = "goodbye" image = "hello" dependencies = ["hello"] class ServiceThree(NewServiceBase): name = "howareyou" image = "hello" collection.load_definitions() collection.exclude_for_stop(['howareyou', 'hello'])
def test_error_on_stop_dependency_excluded(self): collection = ServiceCollection() class NewServiceBase(Service): name = "not used" image = "not used" collection._base_class = NewServiceBase class ServiceOne(NewServiceBase): name = "hello" image = "hello" dependencies = ["howareyou"] class ServiceTwo(NewServiceBase): name = "goodbye" image = "hello" dependencies = ["hello"] class ServiceThree(NewServiceBase): name = "howareyou" image = "hello" collection.load_definitions() with pytest.raises(ServiceLoadError): collection.exclude_for_stop(['goodbye'])
def test_stop_with_remove_and_exclude(self): container1 = FakeContainer(name='service1-testing-1234', network='the-network', status='running') container2 = FakeContainer(name='service2-testing-5678', network='the-network', status='running') self.docker._existing_containers = [container1, container2] collection = ServiceCollection() class NewServiceBase(Service): name = "not used" image = "not used" class ServiceOne(NewServiceBase): name = "service1" image = "howareyou/image" class ServiceTwo(NewServiceBase): name = "service2" image = "howareyou/image" collection._base_class = NewServiceBase collection.load_definitions() collection.exclude_for_stop(['service2']) options = Options(network=Network(name='the-network', id='the-network-id'), timeout=50, remove=True, run_dir='/etc', build=[]) collection.stop_all(options) assert container1.stopped assert container1.removed_at is not None # service2 was excluded assert not container2.stopped assert container2.removed_at is None # If excluded is not empty, network should not be removed assert self.docker._networks_removed == []