def test_file_creation_existence_and_deletion(connection): path = '/tmp/usinetestfile' run(f'rm {path} || exit 0') assert not exists(path) run(f'touch {path}') assert exists(path) run(f'rm {path}') assert not exists(path)
def test_dry_run(connection): path = '/tmp/usinetestfile' run(f'rm {path} || exit 0') assert not exists(path) usine.client.dry_run = True run(f'touch {path}') usine.client.dry_run = False assert not exists(path)
def test_folder_creation_existence_and_deletion(connection): path = '/tmp/usinetestfolder' run(f'rmdir {path} || exit 0') assert not exists(path) mkdir(path) assert exists(path) run(f'rmdir {path}') assert not exists(path)
def test_folder_mv(connection): path = '/tmp/usinetestfolder' newpath = '/tmp/usinenewtestfolder' run(f'rmdir {newpath} || exit 0') mkdir(path) mv(path, newpath) assert exists(newpath) assert not exists(path) run(f'rmdir {newpath}') assert not exists(newpath)
def test_file_mv(connection): path = '/tmp/usinetestfile' newpath = '/tmp/usinenewtestfile' run(f'rm {newpath} || exit 0') run(f'touch {path}') mv(path, newpath) assert exists(newpath) assert not exists(path) run(f'rm {newpath}') assert not exists(newpath)
def test_folder_cp(connection): path = '/tmp/usinetestfolder' targetpath = '/tmp/usinetargettestfolder' run(f'rmdir {targetpath} || exit 0') mkdir(path) cp(path, targetpath) assert exists(targetpath) assert exists(path) run(f'rmdir {targetpath}') assert not exists(targetpath) run(f'rmdir {path}') assert not exists(path)
def test_file_cp(connection): path = '/tmp/usinetestfile' targetpath = '/tmp/usinetargettestfile' run(f'rm {targetpath} || exit 0') run(f'touch {path}') cp(path, targetpath) assert exists(targetpath) assert exists(path) run(f'rm {targetpath}') assert not exists(targetpath) run(f'rm {path}') assert not exists(path)
def test_folder_creation_existence_and_deletion_with_subfolder(connection): path = '/tmp/usinetestfolder' subpath = f'{path}/subfolder' run(f'rmdir {subpath} || exit 0') run(f'rmdir {path} || exit 0') assert not exists(path) with pytest.raises(SystemExit): mkdir(subpath, parents=False) mkdir(subpath) assert exists(subpath) run(f'rmdir {subpath}') run(f'rmdir {path}') assert not exists(path)
def create_bar(): with sudo(user='******'), cd('/srv/'): if exists('/tmp/foo'): mkdir('/tmp/foo/bar') else: print('/tmp/foo does not exist') ls('tamer')
def venv(): """Setup the python virtualenv.""" path = '/srv/addok/venv/' if not exists(path): with sudo(user='******'): run(f'python3 -m venv {path}') pip('install pip -U')
def db(): """Create the database and the needed extensions.""" dest = '/ssd/postgresql' if not exists(dest): src = '/var/lib/postgresql' mv(src, dest) run(f'ln --symbolic --force {dest} {src}') chown('postgres:postgres', src) with sudo(user='******'): conf = template('remote/postgresql.conf', **config) put(conf, f'/etc/postgresql/{config.psql_version}/main/postgresql.conf') run('createuser tilery || exit 0') run('createdb tilery -O tilery || exit 0') run('psql tilery -c "CREATE EXTENSION IF NOT EXISTS postgis"')
def install_imposm(force=False, release='0.6.0-alpha.4'): """Install imposm from binary. :force: install even if the binary already exists. :release: optionnal release to install """ if exists('/usr/bin/imposm') and not force: print('imposm already installed') return # Cf https://github.com/omniscale/imposm3/issues/165#issuecomment-395993259 wget(f'https://github.com/omniscale/imposm3/releases/download/v{release}/imposm-{release}-linux-x86-64.tar.gz', # noqa '/tmp/imposm.tar.gz') run('tar -xzf /tmp/imposm.tar.gz --directory /srv/tilery/src') with sudo(): run(f'ln --symbolic --force ' f'/srv/tilery/src/imposm-{release}-linux-x86-64/imposm ' f'/usr/bin/imposm') with sudo(user='******'): mkdir('/srv/tilery/tmp/imposm')
def http(): """Configure Nginx and letsencrypt.""" # When we'll have a domain. put('remote/piano.conf', '/etc/nginx/snippets/piano.conf') put('remote/forte.conf', '/etc/nginx/snippets/forte.conf') put('remote/letsencrypt.conf', '/etc/nginx/snippets/letsencrypt.conf') put('remote/ssl.conf', '/etc/nginx/snippets/ssl.conf') domain = config.piano_domains[0] pempath = f'/etc/letsencrypt/live/{domain}/fullchain.pem' if exists(pempath): print(f'{pempath} found, using https configuration') conf = template('remote/nginx-https.conf', piano_domains=' '.join(config.piano_domains), forte_domains=' '.join(config.forte_domains), domain=domain) else: print(f'{pempath} not found, using http configuration') # Before letsencrypt. conf = template('remote/nginx-http.conf', piano_domains=' '.join(config.piano_domains), forte_domains=' '.join(config.forte_domains), domain=domain) put(conf, '/etc/nginx/sites-enabled/pianoforte.conf') restart(services='nginx')
def install_mod_tile(force=False): if not exists('/usr/bin/renderd') or force: with sudo(): run('add-apt-repository --yes ppa:osmadmins/ppa') run('apt-get update') run('apt install --yes libapache2-mod-tile')
def download_shapefile(name, url, force): datapath = '/srv/tilery/data/' if not exists(datapath + name) or force: with sudo(user='******'): wget(url, '/tmp/data.zip') run(f'unzip -n /tmp/data.zip -d {datapath}')
def test_dry_run(connection): remote = '/tmp/usinetestdryrun' usine.client.dry_run = True put(Path(__file__).parent / 'test.txt', remote) usine.client.dry_run = False assert not exists(remote)