class Horizon(SimpleBase): def __init__(self, data=None): self.data_key = 'horizon' self.data = { 'auth_strategy': 'keystone', 'allowed_hosts': "['*']", } self.services = ['httpd'] self.packages = ['httpd', 'mod_wsgi'] def init_before(self): self.package = env['cluster']['os_package_map']['horizon'] self.prefix = self.package.get('prefix', '/usr') self.python = Python(self.prefix) def init_after(self): self.data.update({ 'keystone': env.cluster['keystone'], 'prefix': self.prefix, }) def setup(self): data = self.init() if self.is_tag('package'): self.install_packages() self.python.setup() self.python.setup_package(**self.package) sudo('sh -c "cd {0}/lib/horizon/ && {1} manage.py collectstatic --noinput"'.format( self.prefix, self.python.get_cmd())) sudo('sh -c "cd {0}/lib/horizon/ && {1} manage.py compress --force"'.format( self.prefix, self.python.get_cmd())) sudo('chown -R apache:apache {0}/lib/horizon'.format(self.prefix)) if self.is_tag('conf'): is_updated = filer.template( self.prefix + '/lib/horizon/openstack_dashboard/local/local_settings.py', src='{0}/local_settings.py.j2'.format(data['version']), data=data, ) is_updated = filer.template( '/etc/httpd/conf.d/horizon_httpd.conf', src='{0}/horizon_httpd.conf.j2'.format(data['version']), data=data, ) or is_updated if self.is_tag('service'): self.enable_services().start_services(pty=False) if is_updated: self.restart_services(pty=False)
def setup(): prefix = '/opt/test-python' python = Python(prefix) python.setup() python.install('flake8') assert python.get_prefix() == prefix assert python.get_cmd() == '{0}/bin/python'.format(prefix)