Пример #1
0
    def test_stop_without_remove(self):
        container1 = FakeContainer(name='service1-testing-1234',
                                   network='the-network',
                                   status='running')
        container2 = FakeContainer(name='service2-testing-5678',
                                   network='the-network',
                                   status='exited')
        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.stop_all(DEFAULT_OPTIONS)
        assert container1.stopped
        assert container1.timeout == 1
        assert container1.removed_at is None
        assert not container2.stopped
        assert self.docker._networks_removed == []
Пример #2
0
    def test_stop_with_remove_and_order(self):
        container1 = FakeContainer(name='service1-testing-1234',
                                   network='the-network',
                                   status='running')
        container2 = FakeContainer(name='service2-testing-5678',
                                   network='the-network',
                                   status='running')
        container3 = FakeContainer(name='service3-testing-5678',
                                   network='the-network',
                                   status='running')
        self.docker._existing_containers = [container1, container2, container3]
        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"
            dependencies = ['service1']

        class ServiceThree(NewServiceBase):
            name = "service3"
            image = "howareyou/image"
            dependencies = ['service2']

        collection._base_class = NewServiceBase
        collection.load_definitions()
        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
        assert container2.stopped
        assert container2.removed_at is not None
        assert container3.stopped
        assert container3.removed_at is not None
        assert container1.removed_at > container2.removed_at > container3.removed_at
        assert self.docker._networks_removed == ['the-network']
Пример #3
0
    def test_update_for_base_service(self):
        container1 = FakeContainer(name='service1-testing-1234',
                                   network='the-network',
                                   status='running')
        container2 = FakeContainer(name='service2-testing-5678',
                                   network='the-network',
                                   status='running')
        container3 = FakeContainer(name='service3-testing-5678',
                                   network='the-network',
                                   status='running')
        self.docker._existing_containers = [container1, container2, container3]
        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"
            dependencies = ['service1']

        class ServiceThree(NewServiceBase):
            name = 'service3'
            image = 'howareyou/image'
            dependencies = ['service1', 'service2']

        collection._base_class = NewServiceBase
        collection.load_definitions()
        collection.update_for_base_service('service2')
        assert collection.all_by_name == {
            'service2': ServiceTwo(),
            'service3': ServiceThree()
        }
        collection.stop_all(DEFAULT_OPTIONS)
        assert not container1.stopped
        assert container2.stopped
        assert container3.stopped
Пример #4
0
    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 == []