def set_value(self, app, value, together_config_settings, part): if part == 'outside': return self._write_file_content(self.filename, value) else: if not app_is_running(app): settings_logger.error( 'Cannot write %s while %s is not running' % (self.name, app)) return from univention.appcenter.docker import Docker docker = Docker(app) return self._write_file_content(docker.path(self.filename), value)
def test_file_setting_docker(installed_apache_docker_app): content = '''[test/setting4] Type = File Filename = /tmp/settingdir/setting4.test Description = My Description 4 ''' app, settings = fresh_settings(content, installed_apache_docker_app, 1) setting, = settings assert repr(setting) == "FileSetting(name='test/setting4')" docker_file = Docker(app).path(setting.filename) try: with Configuring(app, revert='configure') as config: assert not os.path.exists(docker_file) assert setting.get_value(app) is None config.set({setting.name: 'Docker file content'}) assert os.path.exists(docker_file) assert open(docker_file, 'rb').read() == 'Docker file content' assert setting.get_value(app) == 'Docker file content' config.set({setting.name: None}) assert not os.path.exists(docker_file) assert setting.get_value(app) is None finally: try: os.unlink(setting.filename) except EnvironmentError: pass
def _get_docker(cls, app): if not app.docker: return if app.plugin_of: app = Apps().find(app.plugin_of) return cls._get_docker(app) return Docker(app, cls.logger)
def get_value(self, app, phase='Settings'): if self.is_outside(app): value = self._read_file_content(self.filename) else: if app_is_running(app): from univention.appcenter.docker import Docker docker = Docker(app) value = self._read_file_content(docker.path(self.filename)) else: settings_logger.info('Cannot read %s while %s is not running' % (self.name, app)) value = None if value is None and phase == 'Install': settings_logger.info('Falling back to initial value for %s' % self.name) value = self.get_initial_value(app) return value
def app_is_running(app): from univention.appcenter.app_cache import Apps if isinstance(app, basestring): app = Apps().find(app) if app: if not app.docker: return False if not app.is_installed(): return False try: from univention.appcenter.docker import Docker except ImportError: return None else: docker = Docker(app) return docker.is_running() else: return None
def test_password_setting_docker(installed_apache_docker_app): content = '''[test/setting5] Type = Password [test/setting6] Type = PasswordFile Filename = /tmp/settingdir/setting6.password ''' app, settings = fresh_settings(content, installed_apache_docker_app, 2) password_setting, password_file_setting = settings assert repr(password_setting) == "PasswordSetting(name='test/setting5')" assert repr( password_file_setting) == "PasswordFileSetting(name='test/setting6')" assert password_setting.should_go_into_image_configuration(app) is False assert password_file_setting.should_go_into_image_configuration( app) is False password_file = Docker(app).path(password_file_setting.filename) assert password_setting.is_inside(app) is True assert password_file_setting.is_inside(app) is True assert not os.path.exists(password_file) with Configuring(app, revert='ucr') as config: config.set({ password_setting.name: 'MyPassword', password_file_setting.name: 'FilePassword' }) assert password_setting.get_value(app) == 'MyPassword' assert os.path.exists(password_file) assert open(password_file, 'rb').read() == 'FilePassword' assert stat.S_IMODE(os.stat(password_file).st_mode) == 0600 stop = get_action('stop') stop.call(app=app) config.set({ password_setting.name: 'MyNewPassword2', password_file_setting.name: 'NewFilePassword2' }) assert password_setting.get_value(app) is None assert password_file_setting.get_value(app) is None start = get_action('start') start.call(app=app) assert password_setting.get_value(app) == 'MyPassword' assert open(password_file, 'rb').read() == 'FilePassword'
def _update_apps(self, args): self.log( 'Updating all installed Apps to use the new App Center server') logfile_logger = get_logfile_logger('dev-use-test-appcenter') for app in Apps().get_all_locally_installed_apps(): self.log('Updating %s' % app) register = get_action('register') # we should only use ['component'] in container_mode() # and None otherwise, because it is more correct. however, # this would require credentials (for potential schema updates etc) register.call(apps=[app], register_task=['component']) if app.docker and not container_mode(): try: from univention.appcenter.docker import Docker except ImportError: # should not happen self.log('univention-appcenter-docker is not installed') continue start = get_action('start') start.call(app=app) docker = Docker(app, self.logger) self.log('Updating container... (checking for appbox)') if docker.execute('which', 'univention-app').returncode == 0: self.log( '... setting the new App Center inside the container') returncode = docker.execute( 'univention-install', '-y', 'univention-appcenter-dev', _logger=logfile_logger).returncode if returncode != 0: self.warn( 'univention-install univention-appcenter-dev failed!' ) if args.revert: returncode = docker.execute( 'univention-app', 'dev-use-test-appcenter', '--revert', _logger=logfile_logger).returncode else: returncode = docker.execute( 'univention-app', 'dev-use-test-appcenter', '--appcenter-host', args.appcenter_host, _logger=logfile_logger).returncode if returncode != 0: self.fatal( 'univention-app dev-use-test-appcenter failed!') else: self.log('... nothing to do here')
def _get_docker(cls, app): if not app.docker: return if app.uses_docker_compose(): return MultiDocker(app, cls.logger) return Docker(app, cls.logger)