How to use sh - 10 common examples

To help you get started, we’ve selected a few sh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / molecule / test / unit / lint / test_yamllint.py View on Github external
def test_execute_bakes(_patched_get_files, patched_run_command, _instance):
    _instance.execute()

    assert _instance._yamllint_command is not None

    x = [str(sh.Command('yamllint')), '-s', '--foo=bar', 'foo.yml', 'bar.yaml']
    result = str(patched_run_command.mock_calls[0][1][0]).split()

    assert sorted(x) == sorted(result)
github projectcalico / calicoctl / tests / fv / __init__.py View on Github external
Sets up docker images and host containers for running the STs.
    """
    containers = docker.ps("-qa").split()
    for container in containers:
        DockerHost.delete_container(container)
    print "Host containers removed."

    # Pull and save each image, so we can use them inside the host containers.
    print sh.bash("./build_node.sh").stdout
    docker.save("--output", "calico-node.tar", "calico/node")
    if not os.path.isfile("busybox.tar"):
        docker.pull("busybox:latest")
        docker.save("--output", "busybox.tar", "busybox:latest")
    if not os.path.isfile("nsenter.tar"):
        docker.pull("jpetazzo/nsenter:latest")
        docker.save("--output", "nsenter.tar", "jpetazzo/nsenter:latest")
    if not os.path.isfile("etcd.tar"):
        docker.pull("quay.io/coreos/etcd:v2.0.10")
        docker.save("--output", "etcd.tar", "quay.io/coreos/etcd:v2.0.10")

    # Create the calicoctl binary here so it will be in the volume mounted on the hosts.
    print sh.bash("./create_binary.sh")
    print "Calicoctl binary created."

    host1 = DockerHost('host1')
    DockerHost('host2')
    host1.start_etcd()
github projectcalico / calicoctl / tests / fv / __init__.py View on Github external
def setup_package():
    """
    Sets up docker images and host containers for running the STs.
    """
    containers = docker.ps("-qa").split()
    for container in containers:
        DockerHost.delete_container(container)
    print "Host containers removed."

    # Pull and save each image, so we can use them inside the host containers.
    print sh.bash("./build_node.sh").stdout
    docker.save("--output", "calico-node.tar", "calico/node")
    if not os.path.isfile("busybox.tar"):
        docker.pull("busybox:latest")
        docker.save("--output", "busybox.tar", "busybox:latest")
    if not os.path.isfile("nsenter.tar"):
        docker.pull("jpetazzo/nsenter:latest")
        docker.save("--output", "nsenter.tar", "jpetazzo/nsenter:latest")
    if not os.path.isfile("etcd.tar"):
        docker.pull("quay.io/coreos/etcd:v2.0.10")
        docker.save("--output", "etcd.tar", "quay.io/coreos/etcd:v2.0.10")

    # Create the calicoctl binary here so it will be in the volume mounted on the hosts.
    print sh.bash("./create_binary.sh")
    print "Calicoctl binary created."

    host1 = DockerHost('host1')
github projectcalico / libcalico / tests / fv / __init__.py View on Github external
def setup_package():
    """
    Sets up docker images and host containers for running the STs.
    """
    containers = docker.ps("-qa").split()
    for container in containers:
        DockerHost.delete_container(container)
    print "Host containers removed."

    # Pull and save each image, so we can use them inside the host containers.
    print sh.bash("./build_node.sh").stdout
    docker.save("--output", "calico-node.tar", "calico/node")
    if not os.path.isfile("busybox.tar"):
        docker.pull("busybox:latest")
        docker.save("--output", "busybox.tar", "busybox:latest")
    if not os.path.isfile("nsenter.tar"):
        docker.pull("jpetazzo/nsenter:latest")
        docker.save("--output", "nsenter.tar", "jpetazzo/nsenter:latest")
    if not os.path.isfile("etcd.tar"):
        docker.pull("quay.io/coreos/etcd:v2.0.10")
        docker.save("--output", "etcd.tar", "quay.io/coreos/etcd:v2.0.10")

    # Create the calicoctl binary here so it will be in the volume mounted on the hosts.
    print sh.bash("./create_binary.sh")
    print "Calicoctl binary created."

    host1 = DockerHost('host1')
github ansible / molecule / test / functional / docker / test_scenarios.py View on Github external
def test_command_verify_testinfra_precommit(
    scenario_to_test, with_scenario, scenario_name
):
    options = {'scenario_name': scenario_name}
    cmd = sh.molecule.bake('create', **options)
    pytest.helpers.run_command(cmd)

    options = {'scenario_name': scenario_name}
    cmd = sh.molecule.bake('converge', **options)
    pytest.helpers.run_command(cmd)

    options = {'scenario_name': scenario_name}
    cmd = sh.molecule.bake('verify', **options)
    pytest.helpers.run_command(cmd)
github zmap / zmap / test / test_sharding.py View on Github external
def _runTest(self, shards, max_threads):
        for threads in range(1, max_threads + 1):
            for shard in range(0, shards):
                with sh.sudo:
                    outfile = output_file_name(shards, shard, threads)
                    zmap(p=80, T=threads, shards=shards, shard=shard, _out="tempfile")
                    parse("tempfile", _out=outfile)
                    dup_lines = int(wc(uniq(cat(outfile), "-d"), "-l"))
                    self.assertEqual(dup_lines, 0)
                    shard_file = shard_file_name(shards, threads)
                    if shard == 0:
                        cat(outfile, _out=shard_file)
                    else:
                        cat(shard_file, outfile, _out="tempfile")
                        mv("tempfile", shard_file)

        for threads in range(1, max_threads + 1):
            shard_file = shard_file_name(shards, threads)
            num_lines = int(wc(cat(shard_file), "-l"))
            self.assertEqual(num_lines, TestSharding.NUM_IPS)
            dup_lines = int(wc(uniq(sh.sort(cat(shard_file), "-n"), "-d"), "-l"))
            self.assertEqual(dup_lines, 0)
github chrisdev / wagtail-cookiecutter-foundation / tests / test_cookiecutter_generation.py View on Github external
def test_flake8_compliance(cookies):
    """generated project should pass flake8"""
    result = cookies.bake()
    try:
        sh.flake8(str(result.project))
    except sh.ErrorReturnCode as e:
        pytest.fail(e)
github wildfish / wildfish-django-starter / tests / base.py View on Github external
def clean(self):
        if exists(self.destpath):
            shutil.rmtree(self.destpath)
        sh.cd(self.root_dir)
github lab11 / M-ulator / ci_tests.py View on Github external
BUILD_DIR = 'builds'
PRISTINE = os.path.join(BUILD_DIR, 'simulator')


# Start from scratch
rm('-r', '-f', BUILD_DIR)
mkdir(BUILD_DIR)


# No fuse in the CI environment means we need a unique directory for each
# variant. We first grab a copy of the simulator folder and wipe out all things
# tup to use as a template so that the same script will work locally and in CI
cp('-r', 'simulator', PRISTINE)
with sh.pushd(PRISTINE):
	rm('-r', '-f', '.tup')
	rm('-r', '-f', sh.glob('build-*'))

variants = {}

log.info(sh.cc('--version'))

for variant_file in os.listdir('simulator/configs'):
	log.info("Building {}".format(variant_file))

	variant = os.path.basename(variant_file)

	build_variant_dir = os.path.join(BUILD_DIR, variant)
	mkdir(build_variant_dir)
	cp('-r', PRISTINE, build_variant_dir)

	with sh.pushd(os.path.join(build_variant_dir, 'simulator')):
		tup('init')
github Azure / azure-cli / scripts / smoke_test_install / _common.py View on Github external
def verify_tab_complete(vm):
    # TODO: Also check completion by running 'complete' and using grep to verify the output
    try:
        vm(['grep', '-q', "\"source '/usr/local/az/az.completion'\"", '~/.bashrc'])
    except sh.ErrorReturnCode_1 as e:
        raise Exception("Tab completion should be enabled but source command not found in rc file")