Example #1
0
def test_binary():
    with shell.tempdir():
        with open('1.txt', 'w') as f:
            f.write('123')
        run('cat 1.txt | lz4 -1 |', preamble, 'cp - s3://bucket/binary/1.txt')
        assert '123' == run(preamble,
                            'cp s3://bucket/binary/1.txt - | lz4 -d -c')
Example #2
0
def clone_source():
    with shell.climb_git_root():
        orig = os.getcwd()
        with shell.tempdir(cleanup=False):
            shell.run(f"rsync -avhc {orig}/ . --exclude '.git' --exclude '.tox' --exclude '.backups' --exclude '__pycache__'")
            shell.run('mkdir .git')
            return os.getcwd()
Example #3
0
def apply(doc):
    output_dir = config.output_dir()
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    log = planet.logger

    planet_filters = config.filters('Planet')

    # Go-go-gadget-template
    for template_file in config.template_files():
        output_file = shell.run(template_file, doc)

        # run any template specific filters
        if config.filters(template_file) != planet_filters:
            output = open(output_file).read()
            for filter in config.filters(template_file):
                if filter in planet_filters: continue
                if filter.find('>') > 0:
                    # tee'd output
                    filter, dest = filter.split('>', 1)
                    tee = shell.run(filter.strip(), output, mode="filter")
                    if tee:
                        output_dir = planet.config.output_dir()
                        dest_file = os.path.join(output_dir, dest.strip())
                        dest_file = open(dest_file, 'w')
                        dest_file.write(tee)
                        dest_file.close()
                else:
                    # pipe'd output
                    output = shell.run(filter, output, mode="filter")
                    if not output:
                        os.unlink(output_file)
                        break
            else:
                handle = open(output_file, 'w')
                handle.write(output)
                handle.close()

    # Process bill of materials
    for copy_file in config.bill_of_materials():
        dest = os.path.join(output_dir, copy_file)
        for template_dir in config.template_directories():
            source = os.path.join(template_dir, copy_file)
            if os.path.exists(source): break
        else:
            log.error('Unable to locate %s', copy_file)
            log.info("Template search path:")
            for template_dir in config.template_directories():
                log.info("    %s", os.path.realpath(template_dir))
            continue

        mtime = os.stat(source).st_mtime
        if not os.path.exists(dest) or os.stat(dest).st_mtime < mtime:
            dest_dir = os.path.split(dest)[0]
            if not os.path.exists(dest_dir): os.makedirs(dest_dir)

            log.info("Copying %s to %s", source, dest)
            if os.path.exists(dest): os.chmod(dest, 0644)
            shutil.copyfile(source, dest)
            shutil.copystat(source, dest)
Example #4
0
def apply(doc):
    output_dir = config.output_dir()
    if not os.path.exists(output_dir): os.makedirs(output_dir)
    log = planet.getLogger(config.log_level(),config.log_format())

    # Go-go-gadget-template
    for template_file in config.template_files():
        shell.run(template_file, doc)

    # Process bill of materials
    for copy_file in config.bill_of_materials():
        dest = os.path.join(output_dir, copy_file)
        for template_dir in config.template_directories():
            source = os.path.join(template_dir, copy_file)
            if os.path.exists(source): break
        else:
            log.error('Unable to locate %s', copy_file)
            continue

        mtime = os.stat(source).st_mtime
        if not os.path.exists(dest) or os.stat(dest).st_mtime < mtime:
            dest_dir = os.path.split(dest)[0]
            if not os.path.exists(dest_dir): os.makedirs(dest_dir)

            log.info("Copying %s to %s", source, dest)
            shutil.copyfile(source, dest)
            shutil.copystat(source, dest)
Example #5
0
 def __rebaseFile( self , file , base ):
     """__rebaseFile(f,b)
     
     Execute the command to rebase file f to base address b.
     """
     cmd = '%s -v -b 0x%x %s' % ( self.__rebaseTool , base , file )
     shell.run( cmd )
Example #6
0
def test_props(args):
    num_buckets, csv = args
    result = expected(num_buckets, csv)
    with shell.tempdir():
        stdout = '\n'.join(sorted({l.split(':')[0] for l in result.splitlines()}))
        assert stdout == shell.run(f'bsv | bpartition {num_buckets} prefix', stdin=csv, echo=True)
        assert result == shell.run(f'bcat --prefix prefix*')
Example #7
0
def test_appends():
    with shell.tempdir():
        stdin = """
        0,b,c,d
        1,e,f,g
        2,h,i,j
        """
        stdout = """
        prefix00
        prefix01
        prefix02
        """
        assert rm_whitespace(unindent(stdout)) == shell.run(f'bsv | bpartition 10 prefix', stdin=unindent(stdin))
        assert rm_whitespace(unindent(stdout)) == shell.run(f'bsv | bpartition 10 prefix', stdin=unindent(stdin))
        stdout = """
        prefix00:b,c,d
        prefix00:b,c,d
        prefix01:e,f,g
        prefix01:e,f,g
        prefix02:h,i,j
        prefix02:h,i,j
        """
        assert unindent(stdout).strip() == shell.run(f'bcat --prefix prefix*')
        stdout = """
        prefix00
        prefix01
        prefix02
        """
        assert unindent(stdout).strip() == shell.run('ls prefix*')
Example #8
0
def sketch_data(datas, alpha, bins, minval, quantiles):
    quantiles = ','.join(map(str, quantiles))
    with shell.tempdir():
        for data in datas:
            shell.run(f'bsv | bschema a:f64 | bquantile-sketch f64 -b {bins} -a {alpha} >> sketches', stdin='\n'.join(map(str, data)) + '\n')
        csv = shell.run(f'cat sketches | bquantile-merge {quantiles} | bschema f64:a,f64:a | csv')
        return [float(v) for line in csv.splitlines() for [q, v] in [line.split(',')]]
Example #9
0
def test_fails_when_non_positive_buckets():
    with shell.climb_git_root():
        stdin = 'a'
        print(shell.run('pwd'))
        res = shell.run('bsv | bbucket 0', stdin=stdin, warn=True)
        assert 'NUM_BUCKETS must be positive, got: 0' == res['stderr']
        assert res['exitcode'] == 1
 def _set_env(self):
     os.environ['http_proxy'] = 'http://proxy-chain.intel.com:911'
     os.environ['https_proxy'] = 'http://proxy-chain.intel.com:911'
     os.environ[
         'no_proxy'] = 'intel.com,.intel.com,localhost,127.0.0.1,10.0.0.0/8'  # ,192.168.0.0/16,172.16.0.0/12'
     command = f'{self.path_kubectl} config set-context --current --namespace={self._namespace}'
     run(command, capture_outputs=True)
Example #11
0
def test_basic():
    with shell.tempdir():
        stdin = """
        b,c,d
        e,f,g
        h,i,j
        """
        stdout = """
        prefix_02
        prefix_04
        prefix_05
        """
        assert rm_whitespace(unindent(stdout)) == shell.run(
            'bsv | bpartition -l 10 prefix', stdin=unindent(stdin))
        stdout = """
        prefix_02:h,i,j
        prefix_04:e,f,g
        prefix_05:b,c,d
        """
        assert unindent(stdout).strip() == shell.run('bcat -l -p prefix*')
        stdout = """
        prefix_02
        prefix_04
        prefix_05
        """
        assert unindent(stdout).strip() == shell.run('ls prefix*')
Example #12
0
File: cvs.py Project: mikjo/bigitr
 def addDirectories(self, dirNames):
     for dirName in dirNames:
         parent = os.path.dirname(dirName)
         if parent and parent != "/" and not os.path.exists(parent + "/CVS"):
             self.addDirectories((parent,))
         if not os.path.exists(dirName + "/CVS"):
             shell.run(self.log, "cvs", "add", dirName)
Example #13
0
def test_map_from_n_without_numeric_prefixes():
    # builds on map and map_to_n test
    with servers(1_000_000):
        step1 = 's4://bucket/step1'  # input data
        step2 = 's4://bucket/step2'  # bucketed
        step3 = 's4://bucket/step3'  # partitioned
        step4 = 's4://bucket/step4'  # merged buckets

        def fn(arg):
            i, chunk = arg
            run(f's4 cp - {step1}/{uuid.uuid4()}',
                stdin="\n".join(chunk) + "\n")

        list(pool.thread.map(fn, enumerate(util.iter.chunk(words, 180))))
        run(f's4 map {step1}/ {step2}/ "python3 /tmp/bucket.py 3"')
        run(f's4 map-to-n {step2}/ {step3}/ "python3 /tmp/partition.py 3"')
        run(f"s4 map-from-n {step3}/ {step4}/ 'xargs cat'")
        assert run(
            f"s4 ls -r {step4}/ | awk '{{print $NF}}'").splitlines() == [
                'step4/00000',
                'step4/00001',
                'step4/00002',
            ]
        run(f's4 cp -r {step4}/ step4/')
        result = []
        num_buckets = 3
        for word in words:
            hash_bytes = hashlib.md5(word.encode()).digest()
            hash_int = int.from_bytes(hash_bytes, 'big')
            bucket = hash_int % num_buckets
            if bucket == 0:
                result.append(word)
        assert sorted(result) == sorted(
            run('cat step4/00000', stream=False).splitlines())
Example #14
0
    def test_run_command_with_root(self):
        spawn_mock = mock_pexpect_and_return(return_value=get_mock_process(
            password_prompt=False))

        cmd = 'touch baz'
        shell.run(cmd, root=True)
        spawn_mock.assert_called_once_with(f'sudo {cmd}', encoding='utf-8')
Example #15
0
def setup_module(m):
    m.tempdir = clone_source()
    m.orig = os.getcwd()
    m.path = os.environ['PATH']
    os.chdir(m.tempdir)
    os.environ['PATH'] = f'{os.getcwd()}/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin'
    shell.run('make clean && make bsv csv btake', stream=True)
Example #16
0
def test_data_modifications_not_allowed():
    with servers():
        run('echo | s4 cp - s4://bucket/data.txt')
        path = run('find . -type f -name data.txt')
        assert path.endswith('/data.txt')
        with pytest.raises(Exception):
            run('echo >>', path)
    def delete_session(self, session_type=None, session_name=None, user=None):
        if user is not None:
            self._user = user
            print(f'Delete Session setting user to {self._user}')

        if not self._is_valid_session(session_name, session_type):
            raise DeleteSessionError(f'No such session {session_name}')

        for kind in ['service', 'deployment']:
            cmd = f"{self.path_kubectl} get {kind} {session_name} -o yaml"
            returncode, stdout, _ = run(cmd, None, capture_outputs=True)
            if returncode:
                raise DeleteSessionError(
                    f'Failed to delete session {session_name}. Please contact [email protected]'
                )

            tempyaml = tempfile.NamedTemporaryFile(
                mode="w",
                prefix=f'{session_name}.{kind}_',
                suffix=".yaml",
                delete=False)
            tempyaml.write(stdout)
            tempyaml.close()
            cmd = f'{self.path_kubectl} delete -f {tempyaml.name}'
            returncode, stdout, _ = run(cmd, None, capture_outputs=True)
            if returncode:
                raise DeleteSessionError(
                    f'Failed to delete session {session_name}. Please contact [email protected]'
                )
            tempyaml.delete
            logging.debug(f"Deleted {kind} for {session_name}")
Example #18
0
def apply(doc):
    output_dir = config.output_dir()
    if not os.path.exists(output_dir): os.makedirs(output_dir)
    log = planet.logger

    planet_filters = config.filters('Planet')

    # Go-go-gadget-template
    for template_file in config.template_files():
        output_file = shell.run(template_file, doc)

        # run any template specific filters
        if config.filters(template_file) != planet_filters:
            output = open(output_file).read()
            for filter in config.filters(template_file):
                if filter in planet_filters: continue
                if filter.find('>')>0:
                    # tee'd output
                    filter,dest = filter.split('>',1)
                    tee = shell.run(filter.strip(), output, mode="filter")
                    if tee:
                        output_dir = planet.config.output_dir()
                        dest_file = os.path.join(output_dir, dest.strip())
                        dest_file = open(dest_file,'w')
                        dest_file.write(tee)
                        dest_file.close()
                else:
                    # pipe'd output
                    output = shell.run(filter, output, mode="filter")
                    if not output:
                        os.unlink(output_file)
                        break
            else:
                handle = open(output_file,'w')
                handle.write(output)
                handle.close()

    # Process bill of materials
    for copy_file in config.bill_of_materials():
        dest = os.path.join(output_dir, copy_file)
        for template_dir in config.template_directories():
            source = os.path.join(template_dir, copy_file)
            if os.path.exists(source): break
        else:
            log.error('Unable to locate %s', copy_file)
            log.info("Template search path:")
            for template_dir in config.template_directories():
                log.info("    %s", os.path.realpath(template_dir))
            continue

        mtime = os.stat(source).st_mtime
        if not os.path.exists(dest) or os.stat(dest).st_mtime < mtime:
            dest_dir = os.path.split(dest)[0]
            if not os.path.exists(dest_dir): os.makedirs(dest_dir)

            log.info("Copying %s to %s", source, dest)
            if os.path.exists(dest): os.chmod(dest, 0644)
            shutil.copyfile(source, dest)
            shutil.copystat(source, dest)
Example #19
0
def on_press(key):
    global current

    if key in COMBINATION:
        current.add(key)
        if all(k in current for k in COMBINATION):
            current = set()
            shell.run()
Example #20
0
 def infoDiff(self, since=None, until='HEAD'):
     if since:
         shell.run(self.log, 'git', 'diff', '--stat=200', '--patch',
                   '--minimal', '--irreversible-delete',
                   '%s..%s' % (since, until))
     else:
         shell.run(self.log, 'git', 'diff', '--stat=200', '--patch',
                   '--minimal', '--irreversible-delete')
Example #21
0
def add_script(cluster_id, schema_file, script_file):
    schema_path = 's3://shareablee-hive/tmp/scripts/%s' % uuid.uuid4()
    script_path = 's3://shareablee-hive/tmp/scripts/%s' % uuid.uuid4()
    shell.run('aws s3 cp', schema_file, schema_path)
    shell.run('aws s3 cp', script_file, script_path)
    add_step(cluster_id, 'copy schema', 'aws', 's3', 'cp', schema_path, '/tmp/schema.hql')
    add_step(cluster_id, 'copy script', 'aws', 's3', 'cp', script_path, '/tmp/script.hql')
    add_step(cluster_id, 'run script', 'hive', '-i', '/tmp/schema.hql', '-f', '/tmp/script.hql')
Example #22
0
 def addDirectories(self, dirNames):
     for dirName in dirNames:
         parent = os.path.dirname(dirName)
         if parent and parent != '/' and not os.path.exists(parent +
                                                            '/CVS'):
             self.addDirectories((parent, ))
         if not os.path.exists(dirName + '/CVS'):
             shell.run(self.log, 'cvs', 'add', dirName)
Example #23
0
def run(stdin, *args):
    with shell.climb_git_root():
        stdinpath = 'stdin'
        stdoutpath = 'stdout'
        with open(stdinpath, 'w') as f:
            f.write(stdin)
        shell.run(*(('set -o pipefail; cat', stdinpath, '|') + args + ('>', stdoutpath)), stream=True)
        with open(stdoutpath) as f:
            return f.read()
Example #24
0
def setenforce(mode):
    """ Sets enforcing mode of SElinux

    :param mode: Enforcing mode from [Permissive, Enforcing]
    :param type: ``str``
    :raises: AssertionError
    """
    assert mode in ["Permissive", "Enforcing"]
    shell.run("/usr/sbin/setenforce %s" % mode)
Example #25
0
def exportDYSM(archivePath):
    workspace = os.path.dirname(archivePath)
    project_name = os.path.splitext(os.path.basename(archivePath))[0]

    dysmZipPath = workspace + "/" + project_name + ".app.dSYM.zip"
    dysmPath = workspace + "/" + project_name + ".app.dSYM"
    shell.run("cp -r %s/dSYMs/%s.app.dSYM %s" %
              (archivePath, project_name, workspace))
    shell.run("zip -r -o %s %s" % (dysmZipPath, dysmPath))
Example #26
0
def test_filtering():
    assert '1,1\n2,2' == shell.run(
        'echo -e "1,1\n2,2\n3\n" | bsv | bschema 1,1 --filter | csv')
    assert '22\n33' == shell.run(
        'echo -e "1\n22\n33\n" | bsv | bschema 2 --filter | csv')
    assert '12850\n13107' == shell.run(
        'echo -e "1\n22\n33\n" | bsv | bschema u16:a --filter | csv')
    assert 'as\n12' == shell.run(
        'echo -e "asdf\nq\n123\n" | bsv | bschema "2*" --filter | csv')
Example #27
0
def exportSymbol(archivePath):
    workspace = os.path.dirname(archivePath)
    project_name = os.path.splitext(os.path.basename(archivePath))[0]

    symbolZipPath = workspace + "/" + project_name + ".app.dSYM.zip"
    symbolPath = workspace + "/" + "BCSymbolMaps"

    shell.run("cp -r %s/BCSymbolMaps %s" % (archivePath, workspace))
    shell.run("zip -r -o %s %s" % (symbolZipPath, symbolPath))
Example #28
0
def setenforce(mode):
    """ Sets enforcing mode of SElinux

    :param mode: Enforcing mode from [Permissive, Enforcing]
    :param type: ``str``
    :raises: AssertionError
    """
    assert mode in ["Permissive", "Enforcing"]
    shell.run("/usr/sbin/setenforce %s" % mode)
Example #29
0
def update_zip(path, *includes):
    stderr('\nupdate zip:')
    _zip_file = zip_file(path)
    tempdir = os.path.dirname(_zip_file)
    [site_packages] = glob.glob(f'{tempdir}/env/lib/python3*/site-packages')
    with sh.cd(site_packages):
        sh.run(f'cp {path} .')
        sh.run(f'zip {_zip_file} {os.path.basename(path)}')
    stderr('', _zip_file)
Example #30
0
def run(l):
    print("Hello Jammer! I am ISLA (Intelligent Spacedog Lighting Assistant")
    print("Please select a foreground color")
    s = raw_input(">")
    color1 = getattr(colors, s)
    print(
        "Ok thanks. You're doing great. Now please select a background color")
    s = raw_input(">")
    color2 = getattr(colors, s)
    print("Now just select an effects color and we are ready to go!")
    s = raw_input(">")
    color3 = getattr(colors, s)

    print("Ok thanks! Those are great choices")

    walk = fourstepmover(4, color1, color2)
    chill = fourstepmover(8, color2, colors.dim(color2, .1), 1.1)
    chill.loop = True
    walk.loop = True

    default = walk
    default.loop = True
    l.run(default)
    print("What would you like to do?")
    print("1. Cool fill 2. Freakout 3. Pulse 4. Walk")

    def handle_input(input):
        strippedInput = input.lstrip("i")
        immediate = False
        if strippedInput != input:
            immediate = True
        input = strippedInput

        def run(f):
            if immediate == True:
                l.runImmediately(f)
            else:
                l.run(f)

        if input == "1":
            print("Ok! Hold on dropping some dope beats in 4, 3, 2...")
            f = fourbarmover(color1, color2)
            run(f)
            l.run(chill)
        if input == "2":
            print("HOLD ON BUDDY")
            run(strobe(PartyBar().all(color3), 1 / 4.0, 4))
            l.run(chill)
        if input == "3":
            print("Nice and smooth")
            run(chill)
        if input == "4":
            print("To the dog park we go!")
            run(walk)

    shell.run(l, handle_input)
Example #31
0
def setup_module(m):
    m.tempdir = clone_source()
    m.orig = os.getcwd()
    m.path = os.environ['PATH']
    os.chdir(m.tempdir)
    os.environ[
        'PATH'] = f'{os.getcwd()}/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/bin'
    shell.run('make clean', stream=True)
    compile_buffer_sizes('_csv', buffers)
    shell.run('make _csv')
Example #32
0
 def infoDiff(self, since=None, until='HEAD'):
     if since:
         shell.run(self.log, 'git', 'diff',
                   '--stat=200',
                   '--patch', '--minimal', '--irreversible-delete',
                   '%s..%s' %(since, until))
     else:
         shell.run(self.log, 'git', 'diff',
                   '--stat=200',
                   '--patch', '--minimal', '--irreversible-delete')
Example #33
0
def test_map():
    with servers(1_000_000):
        src = 's4://bucket/data_in'
        dst = 's4://bucket/data_out'

        def fn(arg):
            i, chunk = arg
            run(f's4 cp - {src}/{i:05}', stdin="\n".join(chunk) + "\n")

        list(pool.thread.map(fn, enumerate(util.iter.chunk(words, 180))))
        assert run(f"s4 ls {src}/ | awk '{{print $NF}}' ").splitlines() == [
            '00000', '00001', '00002', '00003', '00004', '00005'
        ]
        assert run(f's4 cp {src}/00000 - | head -n5').splitlines() == [
            'Abelson', 'Aberdeen', 'Allison', 'Amsterdam', 'Apollos'
        ]
        run(f's4 map {src}/ {dst}/ "tr A-Z a-z"')
        assert run(f"s4 ls {dst}/ | awk '{{print $NF}}'").splitlines() == [
            '00000', '00001', '00002', '00003', '00004', '00005'
        ]
        assert run(f's4 cp {dst}/00000 - | head -n5').splitlines() == [
            'abelson', 'aberdeen', 'allison', 'amsterdam', 'apollos'
        ]
        run(f's4 cp -r {dst}/ result')
        assert run('cat result/*', stream=False) == '\n'.join(words).lower()
Example #34
0
def test_props(csvs):
    result = expected(csvs)
    if result.strip():
        with shell.tempdir():
            paths = []
            for i, csv in enumerate(csvs):
                path = f'file{i}.bsv'
                shell.run(f'bsv > {path}', stdin=csv)
                paths.append(path)
            assert result.strip() == shell.run(f'brmerge', *paths, ' | bcut 1 | csv', echo=True)
            assert shell.run('cat', *paths, '| brsort | bcut 1 | csv') == shell.run(f'brmerge', *paths, ' | bcut 1 | csv')
Example #35
0
def start(port, conf, extra=''):
    with shell.cd(f'_{port}'):
        for i in range(5):
            try:
                shell.run(
                    f'timeout 60 s4-server -port {port} -conf {conf} {extra}',
                    stream=True)
            except:
                logging.exception('')
                continue
        assert False, f'failed to start server on ports from: {port}'
Example #36
0
def add_script(cluster_id, schema_file, script_file):
    schema_path = 's3://shareablee-hive/tmp/scripts/%s' % uuid.uuid4()
    script_path = 's3://shareablee-hive/tmp/scripts/%s' % uuid.uuid4()
    shell.run('aws s3 cp', schema_file, schema_path)
    shell.run('aws s3 cp', script_file, script_path)
    add_step(cluster_id, 'copy schema', 'aws', 's3', 'cp', schema_path,
             '/tmp/schema.hql')
    add_step(cluster_id, 'copy script', 'aws', 's3', 'cp', script_path,
             '/tmp/script.hql')
    add_step(cluster_id, 'run script', 'hive', '-i', '/tmp/schema.hql', '-f',
             '/tmp/script.hql')
Example #37
0
def is_elf(filename):
    """ Checks whether file is ELF executable

    :param filename: file name to check
    :type filename: ``str``

    :returns: Whether file is ELF executable
    """
    try:
        shell.run("readelf -h %s" % filename)
        return True
    except AssertionError:
        return False
Example #38
0
def install(package_name):
    """ Does the 'yum install <package>' command.

    :param package_name: Name of the package to install (eg. katello-all)
    :type package_name: str

    :raises: AssertionError
    """
    # Install it
    text = shell.run("yum -y install %s" % (package_name))
    # Verify it
    shell.run("rpm -q %s" % (package_name))
    return rpm.check_for_errors(text)
Example #39
0
File: cvs.py Project: mikjo/bigitr
 def commit(self, message):
     fd, name = tempfile.mkstemp(".bigitr")
     os.write(fd, message)
     # flat list: ['-s', 'A=a', '-s', 'B=b']
     cvsvars = sum([["-s", x] for x in self.ctx.getCVSVariables(self.repo)], [])
     if self.mapped_branch is not None:
         commitargs = ["commit", "-r", self.branch, "-R", "-F", name]
     else:
         commitargs = ["commit", "-R", "-F", name]
     try:
         shell.run(self.log, "cvs", *(cvsvars + commitargs))
     finally:
         os.remove(name)
         os.close(fd)
Example #40
0
def package_installed(package):
    """ Returns whether is package installed or not

    :param package: Package name
    :type package: ``str``

    :returns: ``True`` when package is installed, otherwise ``False``
    :rtype: ``bool``
    """
    try:
        shell.run("rpm -q %s" % package)
        return True
    except AssertionError:
        return False
Example #41
0
def remove(package_name):
    """ Does the 'yum remove <package>' command.

    :param package_name: Name of the package to be removed (eg. katello-all)
    :type package_name: str

    :raises: AssertionError
    """
    # Remove it
    text = shell.run("yum -y remove %s" % (package_name))
    # Verify it
    shell.run("rpm -q %s" % (package_name), errorcode=1)

    return text
Example #42
0
def getenforce():
    """ Returns enforcing mode of SElinux

    :returns: Enforcing mode of SELinux
    :rtype: ``str``
    """
    return shell.run("/usr/sbin/getenforce")
Example #43
0
def ql(package):
    """ Performs a 'rpm -ql' command

    :param package: Package to be listed
    :type package: ``str``
    """
    return shell.run("rpm -ql %s" % package)
Example #44
0
def e(package):
    """ Performs a 'rpm -e' command

    :param package: Package to be removed
    :type package: ``str``
    """
    return shell.run("rpm -e %s" % package)
Example #45
0
def status(launch,
           bucket: 's3 bucket to upload logs to' = shell.conf.get_or_prompt_pref('launch_logs_bucket',  __file__, message='bucket for launch_logs')):
    """
    show all instances, and their state, ie running|done|failed|missing.
    """
    launch = launch.replace('launch=', '')
    data = json.loads(params(launch))
    results = shell.run("aws s3 ls %(bucket)s/launch_logs/launch=%(launch)s/ --recursive|awk '{print $NF}'| grep exited=" % locals()).splitlines()
    results = [(x.split('/')[-2], x.split('exited=')[-1]) for x in results]
    fail_labels = [label.split('label=', 1)[-1] for label, exit in results if exit != '0']
    done_labels = [label.split('label=', 1)[-1] for label, exit in results if exit == '0']
    running_labels = [aws.ec2._tags(i)['label'] for i in aws.ec2._ls(['launch=%s' % launch], state='running')]
    vals = []
    for label in sorted(data['labels']):
        if label in fail_labels:
            vals.append('failed label=%s' % label)
        elif label in done_labels:
            vals.append('done label=%s' % label)
        elif label in running_labels:
            vals.append('running label=%s' % label)
        else:
            vals.append('missing label=%s' % label)
    for k, v in util.iter.groupby(vals, key=lambda x: x.split()[0]):
        logging.info('num %s: %s', k, len(v))
    return sorted(vals, key=lambda x: x.split()[0], reverse=True)
Example #46
0
    def process_module(self, imodule):

        if imodule.type in ["cvs", "distribution"]:
            tmpdir="branch_tmp_"+str(distributions.my_get_thread_ident())
            shell.rm(tmpdir)

            try:

                if imodule.type == "cvs":
                    imodule.checkout(
                        date = self.source_date,
                        tag = self.source_tag,
                        as = tmpdir)
                else:
                    cvs.Checkout(self.source_tag or imodule.cvs_tag,
                                 "distribution",
                                 imodule.cvs_root,
                                 tmpdir,
                                 self.source_date or imodule.cvs_date)

                cmd='cvs tag %s %s "%s"' %( self.cvs_flags,self.dash_b,  self.tag )
                print "Running: %s (in %s + %s)" % (cmd, os.getcwd(), tmpdir)
                status, output = shell.run(cmd, dir = tmpdir)
                print output
                if status:
                    print "Tagging module %s failed\n" % imodule.id

            except cvs.cvs_error:
                print "Tagging module %s failed\n" % imodule.id
            
            shell.rm(tmpdir)
Example #47
0
def update():
    """ Does the 'yum update' command.

    :raises: AssertionError
    """
    # Update
    return rpm.check_for_errors(shell.run("yum -y update"))
Example #48
0
def grouplist():
    """ Does the 'yum grouplist' command.

    :raises: AssertionError
    """
    # Check for update
    return shell.run("yum grouplist")
Example #49
0
    def run(self, cmd, nowarn=0):
        print "Running '%s' in %s" % (cmd, tmpdir())
        status, output=shell.run(cmd, self.lcb, 1800, tmpdir())
        if status and not nowarn:
            print "WARNING WARNING WARNING"
            print "Command failed: %s" % cmd

        return output
Example #50
0
 def __sign( self , file ):
     """__sign(f)
     
     Execute the command to sign dll f.
     """
     cmd = '%s %s' % ( self.__signTool , file )
     (ret, output) = shell.run( cmd )
     if ret:
         log.error("Failed to sign %s: %s" % ( file , output ) )
Example #51
0
 def run_cmd(self, cmd):
     outmsg.verbose(cmd)
     t = time.time()
     try:
         ret=shell.run(cmd, self.lcb)
     except shell.error, se:
         e = err.Error()
         e.Set(str(se))
         raise err.error, e
Example #52
0
def package_build_host(package):
    """ Returns build host of the package.

    :param package: Package to check
    :type package: ``str``
    :returns: Build host of the package
    :rtype: ``str``
    """
    return shell.run("rpm -q --qf \"%%{BUILDHOST}\" %s" % package).strip()
Example #53
0
def package_problems(package):
    """ This functions returns reported problems with package

    :param package: Package to check
    :type package: ``str``
    :returns: ``STDOUT`` of rpm -V
    :rtype: ``str``
    """
    return shell.run("rpm -Vvv %s" % package, None)
Example #54
0
def run1(cmd, no_prefix=False):
    if not no_prefix:
        cmd = "%s%s" % (platform_prefix, cmd)
    debug("rlink, running: %s" % cmd)
    (e, out) = shell.run(cmd)
    if string.strip(out) != "":
        print out
    if e:
        print "Cmd '%s' failed with error code %d" % (cmd, e)
        sys.exit(1)
Example #55
0
def run_noexit(cmd):
    cmd = "%s%s" % (platform_prefix, cmd)
    debug("rlink, running: %s" % cmd)
    (e, out) = shell.run(cmd)
    if string.strip(out) != "":
        print out
    if e:
        ## Only print verbose message if debug is enabled, since
        ## it typically isn't an error
        debug("Cmd '%s' failed with error code %d" % (cmd, e))
Example #56
0
    def Cmd(self, cmd, path, dir = None):
        log.trace( 'entry' , [ cmd ] )
        cmd='cvs -d "%s" %s "%s"' % (self.root, cmd, path)
        log.info("running %s in %s + %s" % (repr(cmd), repr(os.getcwd()), repr(dir)))
        results = shell.run(cmd, dir = dir, timeout_seconds = 1800)
        resList = []
	for item in results:
	    resList.append(item)
        log.trace( 'exit' , [ resList ]  )
        return results
Example #57
0
def search(package_name):
    """ Does the 'yum search <package>' command.

    :param package_name: Name of the package to install (eg. katello-all)
    :type package_name: str

    :raises: AssertionError
    """
    # Install it
    return shell.run("yum search %s" % (package_name))
Example #58
0
def readelf(filename):
    """ Returns content of the ``readelf --all`` call.

    :param filename: File to check
    :type filename: ``str``

    :returns: Content of the ELF analysis
    :rtype: ``str``
    """
    return shell.run("readelf --all %s" % filename)
Example #59
0
def groupinstall(group):
    """ Does the 'yum groupinstall <package>' command.

    :param package_name: Name of the group to install (eg. katello-all)
    :type package_name: str

    :raises: AssertionError
    """
    # Install it
    text = shell.run("yum -y groupinstall %s" % (group))
    return rpm.check_for_errors(text)