예제 #1
0
    def setUp(self):
        self.revision = FlotillaServiceRevision(units=[
            FlotillaDockerService(
                'redis.service', 'redis:latest', environment={'FOO': 'bar'})
        ])
        self.rev_hash = self.revision.revision_hash

        self.assignments = MagicMock(spec=Table)
        self.regions = MagicMock(spec=Table)
        self.revisions = MagicMock(spec=Table)
        self.services = MagicMock(spec=Table)
        self.units = MagicMock(spec=Table)
        self.users = MagicMock(spec=Table)
        self.revision_item = MagicMock(spec=Item)
        self.revisions.has_item.return_value = False
        self.revisions.get_item.return_value = self.revision_item

        self.service_item = MagicMock(spec=Item)
        self.service_data = {self.rev_hash: 1}
        self.service_item.__getitem__.side_effect = \
            self.service_data.__getitem__
        self.service_item.__contains__.side_effect = \
            self.service_data.__contains__
        self.service_item.get.side_effect = \
            self.service_data.get
        self.service_item.keys.side_effect = self.service_data.keys
        self.services.get_item.return_value = self.service_item
        self.kms = MagicMock(spec=KMSConnection)
        self.db = FlotillaClientDynamo(self.assignments, self.regions,
                                       self.revisions, self.services,
                                       self.units, self.users, self.kms)
예제 #2
0
    def test_constructor_logdriver(self):
        self.unit = FlotillaDockerService(DOCKER_NAME,
                                          DOCKER_IMAGE,
                                          logdriver='journald')

        logging_flag = ' --log-driver=journald '
        self.assertTrue(logging_flag in self.unit.unit_file)
예제 #3
0
def get_units(services, environments):
    units = []
    for name, service in services.items():
        env = environments.get(name, {})
        unit = FlotillaUnit('%s.service' % name, service, env)
        units.append(unit)
    for name, env in environments.items():
        if name in services:
            continue

        image = env.get('DOCKER_IMAGE')
        if not image:
            continue
        del env['DOCKER_IMAGE']

        ports = {}
        for key, value in env.items():
            try:
                if key.startswith('DOCKER_PORT_'):
                    ports[int(key[12:])] = int(value)
                    del env[key]
            except:
                continue

        logdriver = env.get('DOCKER_LOG_DRIVER')
        if logdriver:
            del env['DOCKER_LOG_DRIVER']

        unit = FlotillaDockerService('%s.service' % name, image, ports=ports,
                                     environment=env, logdriver=logdriver)
        units.append(unit)
    return units
예제 #4
0
    def test_set_units_environment(self):
        flotilla_unit = FlotillaDockerService('redis.service',
                                              'redis:latest',
                                              environment={'FOO': 'bar'})

        self.systemd.set_units([flotilla_unit])

        env_path = '%s/%s' % (self.env_dir, flotilla_unit.full_name)
        self.assertTrue(os.path.isfile(env_path))
예제 #5
0
    def test_constructor_ports(self):
        self.unit = FlotillaDockerService(DOCKER_NAME,
                                          DOCKER_IMAGE,
                                          ports={
                                              80: 8080,
                                              443: 8443
                                          })

        docker_ports = ' -p 80:8080 -p 443:8443 '
        self.assertTrue(docker_ports in self.unit.unit_file)
예제 #6
0
def get_units(files):
    services = {}
    environments = {}

    for path, contents in files.items():
        filename = os.path.basename(path)
        name, extension = os.path.splitext(filename)

        if extension == '.service' and contents:
            services[name] = contents
        elif extension == '.env':
            environments[name] = parse_env(contents)

    units = []
    for name, service in services.items():
        env = environments.get(name, {})
        unit = FlotillaUnit('%s.service' % name, service, env)
        units.append(unit)

    for name, env in environments.items():
        if name in services:
            continue

        image = env.get('DOCKER_IMAGE')
        if not image:
            continue
        del env['DOCKER_IMAGE']

        ports = {}
        for key, value in env.items():
            try:
                if key.startswith('DOCKER_PORT_'):
                    ports[int(key[12:])] = int(value)
                    del env[key]
            except:
                continue

        logdriver = env.get('DOCKER_LOG_DRIVER')
        if logdriver:
            del env['DOCKER_LOG_DRIVER']

        unit = FlotillaDockerService('%s.service' % name,
                                     image,
                                     ports=ports,
                                     environment=env,
                                     logdriver=logdriver)
        units.append(unit)

    return units
예제 #7
0
    def setUp(self):
        self.unit = MagicMock()
        self.unit.properties.Id = UNIT_NAME
        self.unit.properties.LoadState = LOAD_STATE
        self.unit.properties.ActiveState = ACTIVE_STATE
        self.unit.properties.SubState = SUB_STATE
        self.unit.properties.ActiveEnterTimestamp = ACTIVE_TIMESTAMP
        self.unit.properties.ActiveExitTimestamp = ACTIVE_TIMESTAMP

        self.loaded_unit = MagicMock()
        self.loaded_unit.properties.ActiveState = ACTIVE_STATE

        self.manager = MagicMock()
        self.manager.list_units.return_value = [self.unit]
        self.manager.load_unit.return_value = self.loaded_unit

        self.flotilla_unit = FlotillaDockerService('redis.service',
                                                   'redis:latest')

        self.unit_dir = tempfile.mkdtemp('flotilla-systemd-unit')
        self.env_dir = tempfile.mkdtemp('flotilla-systemd-env')
        self.systemd = SystemdUnits(self.manager,
                                    unit_dir=self.unit_dir,
                                    env_dir=self.env_dir)
예제 #8
0
 def test_constructor_environment(self):
     self.unit = FlotillaDockerService(DOCKER_NAME,
                                       DOCKER_IMAGE,
                                       environment={'foo': 'bar'})
     docker_env = ' --env-file '
     self.assertTrue(docker_env in self.unit.unit_file)
예제 #9
0
 def setUp(self):
     self.unit = FlotillaDockerService(DOCKER_NAME, DOCKER_IMAGE)