示例#1
0
    def test_net_from_container(self):
        net_container = Container.create(
            self.client,
            image='busybox:latest',
            name='composetest_net_container',
            command='top'
        )
        net_container.start()

        project = Project.from_dicts(
            name='composetest',
            service_dicts=config.from_dictionary({
                'web': {
                    'image': 'busybox:latest',
                    'net': 'container:composetest_net_container'
                },
            }),
            client=self.client,
        )

        project.up()

        web = project.get_service('web')
        self.assertEqual(web._get_net(), 'container:' + net_container.id)

        project.kill()
        project.remove_stopped()
示例#2
0
    def test_from_dictionary(self):
        service_dicts = config.from_dictionary({"foo": {"image": "busybox"}, "bar": {"environment": ["FOO=1"]}})

        self.assertEqual(
            sorted(service_dicts, key=lambda d: d["name"]),
            sorted([{"name": "bar", "environment": {"FOO": "1"}}, {"name": "foo", "image": "busybox"}]),
        )
示例#3
0
    def test_net_from_service(self):
        project = Project.from_dicts(
            name='composetest',
            service_dicts=config.from_dictionary({
                'net': {
                    'image': 'busybox:latest',
                    'command': ["top"]
                },
                'web': {
                    'image': 'busybox:latest',
                    'net': 'container:net',
                    'command': ["top"]
                },
            }),
            client=self.client,
        )

        project.up()

        web = project.get_service('web')
        net = project.get_service('net')
        self.assertEqual(web._get_net(), 'container:' + net.containers()[0].id)

        project.kill()
        project.remove_stopped()
示例#4
0
    def test_project_up_with_no_deps(self):
        project = Project.from_dicts(
            name='composetest',
            service_dicts=config.from_dictionary({
                'console': {
                    'image': 'busybox:latest',
                    'command': ["top"],
                },
                'data': {
                    'image': 'busybox:latest',
                    'command': ["top"]
                },
                'db': {
                    'image': 'busybox:latest',
                    'command': ["top"],
                    'volumes_from': ['data'],
                },
                'web': {
                    'image': 'busybox:latest',
                    'command': ["top"],
                    'links': ['db'],
                },
            }),
            client=self.client,
        )
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up(['db'], start_deps=False)
        self.assertEqual(len(project.containers(stopped=True)), 2)
        self.assertEqual(len(project.get_service('web').containers()), 0)
        self.assertEqual(len(project.get_service('db').containers()), 1)
        self.assertEqual(len(project.get_service('data').containers()), 0)
        self.assertEqual(len(project.get_service('data').containers(stopped=True)), 1)
        self.assertEqual(len(project.get_service('console').containers()), 0)
示例#5
0
 def test_nonexistent_path(self):
     options = {'build': 'nonexistent.path'}
     self.assertRaises(
         config.ConfigurationError, lambda: config.from_dictionary(
             {
                 'foo': options,
                 'working_dir': 'tests/fixtures/build-path'
             }))
示例#6
0
 def test_nonexistent_path(self):
     options = {'build': 'nonexistent.path'}
     self.assertRaises(
         config.ConfigurationError,
         lambda: config.from_dictionary({
             'foo': options,
             'working_dir': 'tests/fixtures/build-path'
         })
     )
示例#7
0
    def setUpClass(self):
        surveil_dir = os.path.realpath(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "../../../../"
            )
        )

        compose_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            'integration.yml'
        )

        project_config = compose_config.from_dictionary(
            compose_config.load_yaml(compose_file),
            working_dir=surveil_dir,
            filename=compose_file
        )

        self.project = compose_project.Project.from_dicts(
            "surveilintegrationtest",
            project_config,
            docker_client.docker_client()
        )

        self.project.kill()
        self.project.remove_stopped()
        self.project.build()
        self.project.up()

        self.surveil_client = sclient.Client(
            'http://localhost:8999/v2',
            auth_url='http://localhost:8999/v2/auth',
            version='2_0'
        )

        #  Wait until Surveil is available
        now = time.time()
        while True:
            print("Waiting for surveil... %s" % int(time.time() - now))
            if time.time() < (now + 380):
                try:
                    #  If 'ws-arbiter' is found, Surveil is ready!
                    configured_hosts = self.surveil_client.status.hosts.list()
                    host_found = False
                    for host in configured_hosts:
                        if host['host_name'].decode() == 'ws-arbiter':
                            host_found = True
                            break
                    if host_found:
                        break
                except Exception:
                    pass
                time.sleep(10)
            else:
                raise Exception("Surveil could not start")
示例#8
0
def _fetch_project(name, config):
    """
    Wrap the call to Project.from_config as it has side effects
    :param name: name for the project
    :type name: str
    :param config: dictionary configuration
    :type config: dict
    :return: the docker-compose Project
    :rtype: Project
    """
    # get the Project Ready dictionary list. No Working Dir for us
    config_dicts = from_dictionary(config, working_dir='')
    return Project.from_dicts(name, config_dicts, docker_client())
 def test_from_config(self):
     dicts = config.from_dictionary({
         'web': {
             'image': 'busybox:latest',
         },
         'db': {
             'image': 'busybox:latest',
         },
     })
     project = Project.from_dicts('composetest', dicts, None)
     self.assertEqual(len(project.services), 2)
     self.assertEqual(project.get_service('web').name, 'web')
     self.assertEqual(project.get_service('web').options['image'], 'busybox:latest')
     self.assertEqual(project.get_service('db').name, 'db')
     self.assertEqual(project.get_service('db').options['image'], 'busybox:latest')
示例#10
0
    def setUpClass(self):
        surveil_dir = os.path.realpath(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "../../../../"))

        compose_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'integration.yml')

        project_config = compose_config.from_dictionary(
            compose_config.load_yaml(compose_file),
            working_dir=surveil_dir,
            filename=compose_file)

        self.project = compose_project.Project.from_dicts(
            "surveilintegrationtest", project_config,
            docker_client.docker_client())

        self.project.kill()
        self.project.remove_stopped()
        self.project.build()
        self.project.up()

        self.surveil_client = sclient.Client(
            'http://localhost:8999/v2',
            auth_url='http://localhost:8999/v2/auth',
            version='2_0')

        #  Wait until Surveil is available
        now = time.time()
        while True:
            print("Waiting for surveil... %s" % int(time.time() - now))
            if time.time() < (now + 380):
                try:
                    #  If 'ws-arbiter' is found, Surveil is ready!
                    configured_hosts = self.surveil_client.status.hosts.list()
                    host_found = False
                    for host in configured_hosts:
                        if host['host_name'].decode() == 'ws-arbiter':
                            host_found = True
                            break
                    if host_found:
                        break
                except Exception:
                    pass
                time.sleep(10)
            else:
                raise Exception("Surveil could not start")
示例#11
0
 def test_volumes_from_service(self):
     service_dicts = config.from_dictionary({
         'data': {
             'image': 'busybox:latest',
             'volumes': ['/var/data'],
         },
         'db': {
             'image': 'busybox:latest',
             'volumes_from': ['data'],
         },
     }, working_dir='.')
     project = Project.from_dicts(
         name='composetest',
         service_dicts=service_dicts,
         client=self.client,
     )
     db = project.get_service('db')
     data = project.get_service('data')
     self.assertEqual(db.volumes_from, [data])
示例#12
0
    def test_from_dictionary(self):
        service_dicts = config.from_dictionary({
            'foo': {'image': 'busybox'},
            'bar': {'environment': ['FOO=1']},
        })

        self.assertEqual(
            sorted(service_dicts, key=lambda d: d['name']),
            sorted([
                {
                    'name': 'bar',
                    'environment': {'FOO': '1'},
                },
                {
                    'name': 'foo',
                    'image': 'busybox',
                }
            ])
        )
示例#13
0
 def test_volumes_from_container(self):
     data_container = Container.create(
         self.client,
         image='busybox:latest',
         volumes=['/var/data'],
         name='composetest_data_container',
         labels={LABEL_PROJECT: 'composetest'},
     )
     project = Project.from_dicts(
         name='composetest',
         service_dicts=config.from_dictionary({
             'db': {
                 'image': 'busybox:latest',
                 'volumes_from': ['composetest_data_container'],
             },
         }),
         client=self.client,
     )
     db = project.get_service('db')
     self.assertEqual(db.volumes_from, [data_container])
示例#14
0
    def test_from_dictionary(self):
        service_dicts = config.from_dictionary({
            'foo': {
                'image': 'busybox'
            },
            'bar': {
                'environment': ['FOO=1']
            },
        })

        self.assertEqual(
            sorted(service_dicts, key=lambda d: d['name']),
            sorted([{
                'name': 'bar',
                'environment': {
                    'FOO': '1'
                },
            }, {
                'name': 'foo',
                'image': 'busybox',
            }]))
示例#15
0
    def test_project_up_starts_depends(self):
        project = Project.from_dicts(
            name='composetest',
            service_dicts=config.from_dictionary({
                'console': {
                    'image': 'busybox:latest',
                    'command': ["top"],
                },
                'data': {
                    'image': 'busybox:latest',
                    'command': ["top"]
                },
                'db': {
                    'image': 'busybox:latest',
                    'command': ["top"],
                    'volumes_from': ['data'],
                },
                'web': {
                    'image': 'busybox:latest',
                    'command': ["top"],
                    'links': ['db'],
                },
            }),
            client=self.client,
        )
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up(['web'])
        self.assertEqual(len(project.containers()), 3)
        self.assertEqual(len(project.get_service('web').containers()), 1)
        self.assertEqual(len(project.get_service('db').containers()), 1)
        self.assertEqual(len(project.get_service('data').containers()), 1)
        self.assertEqual(len(project.get_service('console').containers()), 0)

        project.kill()
        project.remove_stopped()
示例#16
0
 def test_from_dictionary_throws_error_when_not_dict(self):
     with self.assertRaises(config.ConfigurationError):
         config.from_dictionary({
             'web': 'busybox:latest',
         })
示例#17
0
 def test_nonexistent_path(self):
     options = {"build": "nonexistent.path"}
     self.assertRaises(
         config.ConfigurationError,
         lambda: config.from_dictionary({"foo": options, "working_dir": "tests/fixtures/build-path"}),
     )
示例#18
0
 def make_project(self, cfg):
     return Project.from_dicts(
         name='composetest',
         client=self.client,
         service_dicts=config.from_dictionary(cfg),
     )
示例#19
0
 def test_from_dictionary_throws_error_when_not_dict(self):
     with self.assertRaises(config.ConfigurationError):
         config.from_dictionary({
             'web': 'busybox:latest',
         })