Beispiel #1
0
    def test_up(self):
        web = self.create_service('web')
        db = self.create_service('db')
        other = self.create_service('other')
        project = Project('test', [web, db, other], self.client)

        web.create_container()

        self.assertEqual(len(web.containers()), 0)
        self.assertEqual(len(db.containers()), 0)
        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 0)

        unstarted = project.create_containers(service_names=['web', 'db'])
        self.assertEqual(len(unstarted), 2)
        self.assertEqual(unstarted[0][0], web)
        self.assertEqual(unstarted[1][0], db)

        self.assertEqual(len(web.containers()), 0)
        self.assertEqual(len(db.containers()), 0)
        self.assertEqual(len(web.containers(stopped=True)), 2)
        self.assertEqual(len(db.containers(stopped=True)), 1)

        project.kill_and_remove(unstarted)

        self.assertEqual(len(web.containers()), 0)
        self.assertEqual(len(db.containers()), 0)
        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 0)
Beispiel #2
0
 def test_get_service(self):
     web = Service(
         project='figtest',
         name='web',
         client=None,
         image="busybox:latest",
     )
     project = Project('test', [web], None)
     self.assertEqual(project.get_service('web'), web)
Beispiel #3
0
 def test_get_services_removes_duplicates_following_links(self):
     db = Service(
         project='figtest',
         name='db',
     )
     web = Service(project='figtest', name='web', links=[(db, 'database')])
     project = Project('test', [web, db], None)
     self.assertEqual(
         project.get_services(['web', 'db'], include_links=True), [db, web])
Beispiel #4
0
 def test_get_service(self):
     web = Service(
         project='figtest',
         name='web',
         client=None,
         image="busybox:latest",
     )
     project = Project('test', [web], None)
     self.assertEqual(project.get_service('web'), web)
Beispiel #5
0
 def test_get_services_returns_listed_services_with_args(self):
     web = Service(
         project='figtest',
         name='web',
     )
     console = Service(
         project='figtest',
         name='console',
     )
     project = Project('test', [web, console], None)
     self.assertEqual(project.get_services(['console']), [console])
Beispiel #6
0
 def test_get_services_returns_listed_services_with_args(self):
     web = Service(
         project='figtest',
         name='web',
     )
     console = Service(
         project='figtest',
         name='console',
     )
     project = Project('test', [web, console], None)
     self.assertEqual(project.get_services(['console']), [console])
Beispiel #7
0
    def test_create_containers(self):
        web = self.create_service('web')
        db = self.create_service('db')
        project = Project('test', [web, db], self.client)

        project.create_containers(service_names=['web'])
        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 0)

        project.create_containers()
        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 1)
Beispiel #8
0
 def test_get_services_with_include_links(self):
     db = Service(
         project='figtest',
         name='db',
     )
     web = Service(project='figtest', name='web', links=[(db, 'database')])
     cache = Service(project='figtest', name='cache')
     console = Service(project='figtest',
                       name='console',
                       links=[(web, 'web')])
     project = Project('test', [web, db, cache, console], None)
     self.assertEqual(project.get_services(['console'], include_links=True),
                      [db, web, console])
Beispiel #9
0
 def test_get_services_removes_duplicates_following_links(self):
     db = Service(
         project='figtest',
         name='db',
     )
     web = Service(
         project='figtest',
         name='web',
         links=[(db, 'database')]
     )
     project = Project('test', [web, db], None)
     self.assertEqual(
         project.get_services(['web', 'db'], include_links=True),
         [db, web]
     )
Beispiel #10
0
 def test_from_config(self):
     project = Project.from_config("figtest", {"web": {"image": "ubuntu"}, "db": {"image": "ubuntu"}}, self.client)
     self.assertEqual(len(project.services), 2)
     self.assertEqual(project.get_service("web").name, "web")
     self.assertEqual(project.get_service("web").options["image"], "ubuntu")
     self.assertEqual(project.get_service("db").name, "db")
     self.assertEqual(project.get_service("db").options["image"], "ubuntu")
Beispiel #11
0
    def test_recreate_containers(self):
        web = self.create_service('web')
        db = self.create_service('db')
        project = Project('test', [web, db], self.client)

        old_web_container = web.create_container()
        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 0)

        (old, new) = project.recreate_containers()
        self.assertEqual(len(old), 1)
        self.assertEqual(old[0][0], web)
        self.assertEqual(len(new), 2)
        self.assertEqual(new[0][0], web)
        self.assertEqual(new[1][0], db)

        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 1)
Beispiel #12
0
    def test_from_dict_sorts_in_dependency_order(self):
        project = Project.from_dicts(
            "figtest",
            [{"name": "web", "image": "ubuntu", "links": ["db"]}, {"name": "db", "image": "ubuntu"}],
            self.client,
        )

        self.assertEqual(project.services[0].name, "db")
        self.assertEqual(project.services[1].name, "web")
Beispiel #13
0
 def test_from_dict(self):
     project = Project.from_dicts(
         "figtest", [{"name": "web", "image": "ubuntu"}, {"name": "db", "image": "ubuntu"}], self.client
     )
     self.assertEqual(len(project.services), 2)
     self.assertEqual(project.get_service("web").name, "web")
     self.assertEqual(project.get_service("web").options["image"], "ubuntu")
     self.assertEqual(project.get_service("db").name, "db")
     self.assertEqual(project.get_service("db").options["image"], "ubuntu")
Beispiel #14
0
    def test_from_dict_sorts_in_dependency_order(self):
        project = Project.from_dicts('figtest', [{
            'name': 'web',
            'image': 'ubuntu',
            'links': ['db'],
        }, {
            'name': 'db',
            'image': 'ubuntu'
        }], self.client)

        self.assertEqual(project.services[0].name, 'db')
        self.assertEqual(project.services[1].name, 'web')
Beispiel #15
0
 def test_from_dict(self):
     project = Project.from_dicts('figtest', [{
         'name': 'web',
         'image': 'ubuntu'
     }, {
         'name': 'db',
         'image': 'ubuntu'
     }], self.client)
     self.assertEqual(len(project.services), 2)
     self.assertEqual(project.get_service('web').name, 'web')
     self.assertEqual(project.get_service('web').options['image'], 'ubuntu')
     self.assertEqual(project.get_service('db').name, 'db')
     self.assertEqual(project.get_service('db').options['image'], 'ubuntu')
Beispiel #16
0
    def test_recreate_containers(self):
        web = self.create_service('web')
        db = self.create_service('db')
        project = Project('test', [web, db], self.client)

        old_web_container = web.create_container()
        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 0)

        (old, new) = project.recreate_containers()
        self.assertEqual(len(old), 1)
        self.assertEqual(old[0][0], web)
        self.assertEqual(len(new), 2)
        self.assertEqual(new[0][0], web)
        self.assertEqual(new[1][0], db)

        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 1)

        # remove intermediate containers
        for (service, container) in old:
            container.remove()
Beispiel #17
0
    def test_recreate_containers(self):
        web = self.create_service("web")
        db = self.create_service("db")
        project = Project("test", [web, db], self.client)

        old_web_container = web.create_container()
        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 0)

        (old, new) = project.recreate_containers()
        self.assertEqual(len(old), 1)
        self.assertEqual(old[0][0], web)
        self.assertEqual(len(new), 2)
        self.assertEqual(new[0][0], web)
        self.assertEqual(new[1][0], db)

        self.assertEqual(len(web.containers(stopped=True)), 1)
        self.assertEqual(len(db.containers(stopped=True)), 1)

        # remove intermediate containers
        for (service, container) in old:
            container.remove()
Beispiel #18
0
 def test_from_config(self):
     project = Project.from_config('figtest', {
         'web': {
             'image': 'ubuntu',
         },
         'db': {
             'image': 'ubuntu',
         },
     }, self.client)
     self.assertEqual(len(project.services), 2)
     self.assertEqual(project.get_service('web').name, 'web')
     self.assertEqual(project.get_service('web').options['image'], 'ubuntu')
     self.assertEqual(project.get_service('db').name, 'db')
     self.assertEqual(project.get_service('db').options['image'], 'ubuntu')
Beispiel #19
0
 def test_from_config(self):
     project = Project.from_config('figtest', {
         'web': {
             'image': 'ubuntu',
         },
         'db': {
             'image': 'ubuntu',
         },
     }, self.client)
     self.assertEqual(len(project.services), 2)
     self.assertEqual(project.get_service('web').name, 'web')
     self.assertEqual(project.get_service('web').options['image'], 'ubuntu')
     self.assertEqual(project.get_service('db').name, 'db')
     self.assertEqual(project.get_service('db').options['image'], 'ubuntu')
Beispiel #20
0
 def test_from_config(self):
     project = Project.from_config('figtest', {
         'web': {
             'image': 'busybox:latest',
         },
         'db': {
             'image': 'busybox:latest',
         },
     }, 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')
Beispiel #21
0
    def test_from_dict_sorts_in_dependency_order(self):
        project = Project.from_dicts('figtest', [
            {
                'name': 'web',
                'image': 'ubuntu',
                'links': ['db'],
            },
            {
                'name': 'db',
                'image': 'ubuntu'
            }
        ], self.client)

        self.assertEqual(project.services[0].name, 'db')
        self.assertEqual(project.services[1].name, 'web')
Beispiel #22
0
 def test_get_services_with_include_links(self):
     db = Service(
         project='figtest',
         name='db',
     )
     web = Service(
         project='figtest',
         name='web',
         links=[(db, 'database')]
     )
     cache = Service(
         project='figtest',
         name='cache'
     )
     console = Service(
         project='figtest',
         name='console',
         links=[(web, 'web')]
     )
     project = Project('test', [web, db, cache, console], None)
     self.assertEqual(
         project.get_services(['console'], include_links=True),
         [db, web, console]
     )
Beispiel #23
0
 def test_from_dict(self):
     project = Project.from_dicts('figtest', [
         {
             'name': 'web',
             'image': 'busybox:latest'
         },
         {
             'name': 'db',
             'image': 'busybox:latest'
         },
     ], 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')
Beispiel #24
0
    def project(self):
        try:
            yaml_path = self.check_yaml_filename()
            config = yaml.load(open(yaml_path))

            config = transform_config(config, env=self.env_name)

            return Project.from_config(self.custom_project_name or self.project_name, config, self.client)

        except IOError as e:
            if e.errno == errno.ENOENT:
                log.error("Can't find %s. Are you in the right directory?", os.path.basename(e.filename))
            else:
                log.error(e)

            exit(1)
Beispiel #25
0
 def test_from_dict(self):
     project = Project.from_dicts('figtest', [
         {
             'name': 'web',
             'image': 'ubuntu'
         },
         {
             'name': 'db',
             'image': 'ubuntu'
         }
     ], self.client)
     self.assertEqual(len(project.services), 2)
     self.assertEqual(project.get_service('web').name, 'web')
     self.assertEqual(project.get_service('web').options['image'], 'ubuntu')
     self.assertEqual(project.get_service('db').name, 'db')
     self.assertEqual(project.get_service('db').options['image'], 'ubuntu')
Beispiel #26
0
 def do(self, task, args):
     config = self.get_fig_config(task)
     if args:
         config['main']['command'] += ' {0}'.format(' '.join(args))
     project = FigProject.from_config(self.image_name, config, self.client)
     for container in project.up():
         if container.name == '{0}_main_1'.format(self.image_name):
             for chunk in container.attach(stderr=True, stdout=True, stream=True):
                 sys.stdout.write(chunk)
             inspect = container.inspect()
             code = inspect['State']['ExitCode']
             break
     config.pop('main', None)
     if config:
         project.stop(service_names=config.keys())
     return code
Beispiel #27
0
 def test_from_config(self):
     project = Project.from_config(
         'figtest', {
             'web': {
                 'image': 'busybox:latest',
             },
             'db': {
                 'image': 'busybox:latest',
             },
         }, 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')
Beispiel #28
0
 def test_volumes_from_service(self):
     project = Project.from_config(
         name='figtest',
         config={
             'data': {
                 'image': 'busybox:latest',
                 'volumes': ['/var/data'],
             },
             'db': {
                 'image': 'busybox:latest',
                 'volumes_from': ['data'],
             },
         },
         client=self.client,
     )
     db = project.get_service('db')
     data = project.get_service('data')
     self.assertEqual(db.volumes_from, [data])
Beispiel #29
0
    def test_from_dict_sorts_in_dependency_order(self):
        project = Project.from_dicts('figtest', [{
            'name': 'web',
            'image': 'busybox:latest',
            'links': ['db'],
        }, {
            'name': 'db',
            'image': 'busybox:latest',
            'volumes_from': ['volume']
        }, {
            'name': 'volume',
            'image': 'busybox:latest',
            'volumes': ['/tmp'],
        }], None)

        self.assertEqual(project.services[0].name, 'volume')
        self.assertEqual(project.services[1].name, 'db')
        self.assertEqual(project.services[2].name, 'web')
Beispiel #30
0
    def _get_fig_project(self):

        if not self.env_name:
            raise ValueError('env is not specified!')

        if not self.project_dir:
            raise ValueError('project_dir is not specified!')

        if not self.project_name:
            raise ValueError('project_name is not specified!')

        os.chdir(self.project_dir)
        with open('ficloud.yml') as f:
            config = yaml.load(f)

        config = transform_config(config['services'], env=self.env_name)
        project = Project.from_config(self.project_name, config, self.client)
        return project
Beispiel #31
0
 def test_from_dict(self):
     project = Project.from_dicts('figtest', [
         {
             'name': 'web',
             'image': 'busybox:latest'
         },
         {
             'name': 'db',
             'image': 'busybox:latest'
         },
     ], 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')
Beispiel #32
0
 def test_volumes_from_service(self):
     project = Project.from_config(
         name='figtest',
         config={
             'data': {
                 'image': 'busybox:latest',
                 'volumes': ['/var/data'],
             },
             'db': {
                 'image': 'busybox:latest',
                 'volumes_from': ['data'],
             },
         },
         client=self.client,
     )
     db = project.get_service('db')
     data = project.get_service('data')
     self.assertEqual(db.volumes_from, [data])
Beispiel #33
0
 def test_volumes_from_container(self):
     data_container = Container.create(
         self.client,
         image='busybox:latest',
         volumes=['/var/data'],
         name='figtest_data_container',
     )
     project = Project.from_config(
         name='figtest',
         config={
             'db': {
                 'image': 'busybox:latest',
                 'volumes_from': ['figtest_data_container'],
             },
         },
         client=self.client,
     )
     db = project.get_service('db')
     self.assertEqual(db.volumes_from, [data_container])
Beispiel #34
0
 def test_volumes_from_container(self):
     data_container = Container.create(
         self.client,
         image='busybox:latest',
         volumes=['/var/data'],
         name='figtest_data_container',
     )
     project = Project.from_config(
         name='figtest',
         config={
             'db': {
                 'image': 'busybox:latest',
                 'volumes_from': ['figtest_data_container'],
             },
         },
         client=self.client,
     )
     db = project.get_service('db')
     self.assertEqual(db.volumes_from, [data_container])
Beispiel #35
0
    def test_from_dict_sorts_in_dependency_order(self):
        project = Project.from_dicts('figtest', [
            {
                'name': 'web',
                'image': 'busybox:latest',
                'links': ['db'],
            },
            {
                'name': 'db',
                'image': 'busybox:latest',
                'volumes_from': ['volume']
            },
            {
                'name': 'volume',
                'image': 'busybox:latest',
                'volumes': ['/tmp'],
            }
        ], None)

        self.assertEqual(project.services[0].name, 'volume')
        self.assertEqual(project.services[1].name, 'db')
        self.assertEqual(project.services[2].name, 'web')
Beispiel #36
0
    def test_unscale_after_restart(self):
        web = self.create_service('web')
        project = Project('figtest', [web], self.client)

        project.start()

        service = project.get_service('web')
        service.scale(1)
        self.assertEqual(len(service.containers()), 1)
        service.scale(3)
        self.assertEqual(len(service.containers()), 3)
        project.up()
        service = project.get_service('web')
        self.assertEqual(len(service.containers()), 3)
        service.scale(1)
        self.assertEqual(len(service.containers()), 1)
        project.up()
        service = project.get_service('web')
        self.assertEqual(len(service.containers()), 1)
        # does scale=0 ,makes any sense? after recreating at least 1 container is running
        service.scale(0)
        project.up()
        service = project.get_service('web')
        self.assertEqual(len(service.containers()), 1)
        project.kill()
        project.remove_stopped()
Beispiel #37
0
    def test_project_up_with_no_deps(self):
        console = self.create_service('console')
        db = self.create_service('db', volumes=['/var/db'])
        web = self.create_service('web', links=[(db, 'db')])

        project = Project('figtest', [web, db, console], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up(['web'], start_links=False)
        self.assertEqual(len(project.containers()), 1)
        self.assertEqual(len(web.containers()), 1)
        self.assertEqual(len(db.containers()), 0)
        self.assertEqual(len(console.containers()), 0)

        project.kill()
        project.remove_stopped()
Beispiel #38
0
    def test_project_up_without_all_services(self):
        console = self.create_service('console')
        db = self.create_service('db')
        project = Project('figtest', [console, db], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up()
        self.assertEqual(len(project.containers()), 2)
        self.assertEqual(len(db.containers()), 1)
        self.assertEqual(len(console.containers()), 1)

        project.kill()
        project.remove_stopped()
Beispiel #39
0
    def test_unscale_after_restart(self):
        web = self.create_service('web')
        project = Project('figtest', [web], self.client)

        project.start()

        service = project.get_service('web')
        service.scale(1)
        self.assertEqual(len(service.containers()), 1)
        service.scale(3)
        self.assertEqual(len(service.containers()), 3)
        project.up()
        service = project.get_service('web')
        self.assertEqual(len(service.containers()), 3)
        service.scale(1)
        self.assertEqual(len(service.containers()), 1)
        project.up()
        service = project.get_service('web')
        self.assertEqual(len(service.containers()), 1)
        # does scale=0 ,makes any sense? after recreating at least 1 container is running
        service.scale(0)
        project.up()
        service = project.get_service('web')
        self.assertEqual(len(service.containers()), 1)
        project.kill()
        project.remove_stopped()
Beispiel #40
0
 def test_from_config_throws_error_when_not_dict(self):
     with self.assertRaises(ConfigurationError):
         project = Project.from_config('figtest', {
             'web': 'busybox:latest',
         }, None)
Beispiel #41
0
    def test_start_stop_kill_remove(self):
        web = self.create_service('web')
        db = self.create_service('db')
        project = Project('figtest', [web, db], self.client)

        project.start()

        self.assertEqual(len(web.containers()), 0)
        self.assertEqual(len(db.containers()), 0)

        web_container_1 = web.create_container()
        web_container_2 = web.create_container()
        db_container = db.create_container()

        project.start(service_names=['web'])
        self.assertEqual(set(c.name for c in project.containers()),
                         set([web_container_1.name, web_container_2.name]))

        project.start()
        self.assertEqual(
            set(c.name for c in project.containers()),
            set([
                web_container_1.name, web_container_2.name, db_container.name
            ]))

        project.stop(service_names=['web'], timeout=1)
        self.assertEqual(set(c.name for c in project.containers()),
                         set([db_container.name]))

        project.kill(service_names=['db'])
        self.assertEqual(len(project.containers()), 0)
        self.assertEqual(len(project.containers(stopped=True)), 3)

        project.remove_stopped(service_names=['web'])
        self.assertEqual(len(project.containers(stopped=True)), 1)

        project.remove_stopped()
        self.assertEqual(len(project.containers(stopped=True)), 0)
Beispiel #42
0
    def test_project_up_with_no_recreate_stopped(self):
        web = self.create_service('web')
        db = self.create_service('db', volumes=['/var/db'])
        project = Project('figtest', [web, db], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up(['db'])
        project.stop()

        old_containers = project.containers(stopped=True)

        self.assertEqual(len(old_containers), 1)
        old_db_id = old_containers[0].id
        db_volume_path = old_containers[0].inspect()['Volumes']['/var/db']

        project.up(recreate=False)

        new_containers = project.containers(stopped=True)
        self.assertEqual(len(new_containers), 2)

        db_container = [c for c in new_containers if 'db' in c.name][0]
        self.assertEqual(c.id, old_db_id)
        self.assertEqual(c.inspect()['Volumes']['/var/db'], db_volume_path)

        project.kill()
        project.remove_stopped()
Beispiel #43
0
    def test_project_up_without_all_services(self):
        console = self.create_service('console')
        db = self.create_service('db')
        project = Project('figtest', [console, db], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up()
        self.assertEqual(len(project.containers()), 2)
        self.assertEqual(len(db.containers()), 1)
        self.assertEqual(len(console.containers()), 1)

        project.kill()
        project.remove_stopped()
Beispiel #44
0
    def test_project_up_with_no_recreate_stopped(self):
        web = self.create_service('web')
        db = self.create_service('db', volumes=['/var/db'])
        project = Project('figtest', [web, db], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up(['db'])
        project.stop()

        old_containers = project.containers(stopped=True)

        self.assertEqual(len(old_containers), 1)
        old_db_id = old_containers[0].id
        db_volume_path = old_containers[0].inspect()['Volumes']['/var/db']

        project.up(recreate=False)

        new_containers = project.containers(stopped=True)
        self.assertEqual(len(new_containers), 2)

        db_container = [c for c in new_containers if 'db' in c.name][0]
        self.assertEqual(db_container.id, old_db_id)
        self.assertEqual(db_container.inspect()['Volumes']['/var/db'],
                         db_volume_path)

        project.kill()
        project.remove_stopped()
Beispiel #45
0
 def test_get_service(self):
     web = self.create_service('web')
     project = Project('test', [web], self.client)
     self.assertEqual(project.get_service('web'), web)
Beispiel #46
0
 def test_from_config_throws_error_when_not_dict(self):
     with self.assertRaises(ConfigurationError):
         project = Project.from_config('figtest', {
             'web': 'ubuntu',
         }, self.client)
Beispiel #47
0
    def test_project_up_with_no_deps(self):
        console = self.create_service('console')
        db = self.create_service('db', volumes=['/var/db'])
        web = self.create_service('web', links=[(db, 'db')])

        project = Project('figtest', [web, db, console], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up(['web'], start_links=False)
        self.assertEqual(len(project.containers()), 1)
        self.assertEqual(len(web.containers()), 1)
        self.assertEqual(len(db.containers()), 0)
        self.assertEqual(len(console.containers()), 0)

        project.kill()
        project.remove_stopped()
Beispiel #48
0
    def test_project_up(self):
        web = self.create_service('web')
        db = self.create_service('db', volumes=['/var/db'])
        project = Project('figtest', [web, db], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

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

        project.kill()
        project.remove_stopped()
Beispiel #49
0
    def test_project_up_recreates_containers(self):
        web = self.create_service('web')
        db = self.create_service('db', volumes=['/var/db'])
        project = Project('figtest', [web, db], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

        project.up(['db'])
        self.assertEqual(len(project.containers()), 1)
        old_db_id = project.containers()[0].id
        db_volume_path = project.containers()[0].inspect(
        )['Volumes']['/var/db']

        project.up()
        self.assertEqual(len(project.containers()), 2)

        db_container = [c for c in project.containers() if 'db' in c.name][0]
        self.assertNotEqual(c.id, old_db_id)
        self.assertEqual(c.inspect()['Volumes']['/var/db'], db_volume_path)

        project.kill()
        project.remove_stopped()
Beispiel #50
0
    def test_start_stop_kill_remove(self):
        web = self.create_service('web')
        db = self.create_service('db')
        project = Project('figtest', [web, db], self.client)

        project.start()

        self.assertEqual(len(web.containers()), 0)
        self.assertEqual(len(db.containers()), 0)

        web_container_1 = web.create_container()
        web_container_2 = web.create_container()
        db_container = db.create_container()

        project.start(service_names=['web'])
        self.assertEqual(set(c.name for c in project.containers()), set([web_container_1.name, web_container_2.name]))

        project.start()
        self.assertEqual(set(c.name for c in project.containers()), set([web_container_1.name, web_container_2.name, db_container.name]))

        project.stop(service_names=['web'], timeout=1)
        self.assertEqual(set(c.name for c in project.containers()), set([db_container.name]))

        project.kill(service_names=['db'])
        self.assertEqual(len(project.containers()), 0)
        self.assertEqual(len(project.containers(stopped=True)), 3)

        project.remove_stopped(service_names=['web'])
        self.assertEqual(len(project.containers(stopped=True)), 1)

        project.remove_stopped()
        self.assertEqual(len(project.containers(stopped=True)), 0)
Beispiel #51
0
 def test_get_service(self):
     web = self.create_service('web')
     project = Project('test', [web], self.client)
     self.assertEqual(project.get_service('web'), web)
Beispiel #52
0
 def to_fig_project(self, client):
     return Project.from_dicts(self.plan.name, self.to_service_dicts, client)
Beispiel #53
0
    def test_project_up(self):
        web = self.create_service('web')
        db = self.create_service('db', volumes=['/var/db'])
        project = Project('figtest', [web, db], self.client)
        project.start()
        self.assertEqual(len(project.containers()), 0)

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

        project.kill()
        project.remove_stopped()