Exemplo n.º 1
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")
Exemplo n.º 2
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')
Exemplo n.º 3
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')
Exemplo n.º 4
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')
Exemplo n.º 5
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
Exemplo n.º 6
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)
Exemplo n.º 7
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')
Exemplo n.º 8
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])
Exemplo n.º 9
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])
Exemplo n.º 10
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
Exemplo n.º 11
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])
Exemplo n.º 12
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])
Exemplo n.º 13
0
 def test_from_config_throws_error_when_not_dict(self):
     with self.assertRaises(ConfigurationError):
         project = Project.from_config('figtest', {
             'web': 'busybox:latest',
         }, None)
Exemplo n.º 14
0
 def test_from_config_throws_error_when_not_dict(self):
     with self.assertRaises(ConfigurationError):
         project = Project.from_config('figtest', {
             'web': 'ubuntu',
         }, self.client)
Exemplo n.º 15
0
 def test_from_config_throws_error_when_not_dict(self):
     with self.assertRaises(ConfigurationError):
         project = Project.from_config('figtest', {
             'web': 'busybox:latest',
         }, None)
Exemplo n.º 16
0
 def test_from_config_throws_error_when_not_dict(self):
     with self.assertRaises(ConfigurationError):
         project = Project.from_config("figtest", {"web": "ubuntu"}, self.client)
Exemplo n.º 17
0
 def test_from_config_throws_error_when_not_dict(self):
     with self.assertRaises(ConfigurationError):
         project = Project.from_config('figtest', {
             'web': 'ubuntu',
         }, self.client)
Exemplo n.º 18
0
 def rm(self):
     config = self.get_fig_config('')
     project = FigProject.from_config(self.image_name, config, self.client)
     project.remove_stopped(v=True)