Exemplo n.º 1
0
def test_private_space_cat():
    with Session() as session:
        session.login('cnc:7130')
        m = velstor.pcapi.mount.Mount(session,
                                      '/tmp/pytest/joebob',
                                      pathname='/joebob',
                                      writeback='never')
        #
        #  Ensure it mounted
        subprocess.check_output(
            ['bash', '-c', 'mount | fgrep {}'.format(m.mount_point)])
        #
        #  Create a file and cat it to another file
        #
        large_file_path = os.path.join(m.mount_point, 'large_file')
        cat_file_path = os.path.join(m.mount_point, 'large_file_copy')
        libtest.command('dd', 'if=/dev/urandom',
                        'of={}'.format(large_file_path), 'bs={}'.format(1024),
                        'count={}'.format(1024))
        assert (os.path.exists(large_file_path))
        libtest.command('bash', '-c',
                        'cat {} > {}'.format(large_file_path, cat_file_path))
        libtest.command('cmp', large_file_path, cat_file_path)
        libtest.command('rm', large_file_path, cat_file_path)
        #
        #  Clean up
        m.dispose()
Exemplo n.º 2
0
def test_get_default():
    with Session() as session:
        session.login('cnc:7130')
        try:
            Workspace(session).get()
            assert False
        except ValueError:
            pass
Exemplo n.º 3
0
def test_get_well_known_workspace():
    with Session() as session:
        session.login('cnc:7130')
        w = Workspace(session).get('/root/local')
        assert (w.pathname == '/root/local')
        assert (w.vtrq_id == 0)
        assert (w.vtrq_path == '/')
        assert (w.writeback == 'always')
Exemplo n.º 4
0
def test_delete_enoent():
    with Session() as session:
        session.login('cnc:7130')
        try:
            Workspace(session, pathname='/not/even').delete()
            assert False
        except RESTException as e:
            assert (e.error_sym == 'ENOENT')
            assert (e.http_code == 404)
Exemplo n.º 5
0
def test_set_no_pathname():
    with Session() as session:
        session.login('cnc:7130')
        w = Workspace(session)
        try:
            w.set()
            assert False
        except ValueError:
            assert True
Exemplo n.º 6
0
def main(args=None):
    """The main routine."""
    if args is None:
        args = sys.argv[1:]

    with Session() as session:
        #
        try:
            return worker(session, vsh_parser().parse_args())
        except requests.exceptions.RequestException as e:
            #
            #  Requests raised an exception.  Probably couldn't reach the vCNC
            #  server There is no HTTP code for this error, so we adopt 504,
            #  which is similar.
            #
            #  Yes, it would have been cooler to have done this with a single
            #  RE.
            #
            details = str(e)
            match_host = re.search("host='(\S+)'", details)
            match_port = re.search("port=(\d+)", details)
            match_error = re.search('NewConnectionError', details)
            suffix = '.'
            #
            #  If the server happens to match the vCNC server's default value,
            #  then add the additional suggestion to check configuration.
            #
            if match_host and match_port and match_error:
                host = match_host.group(1)
                port = match_port.group(1)
                if host == 'vcnc' and port == "6130":
                    suffix = ''.join([
                        '. Did you mean to set a command line switch'
                        , ' or environment variable?'])
               
                return error_response(
                    'Could not reach vCNC server at {}:{}{}'.format(
                        host, port, suffix)
                    , http_status=504
                    , error_sym='EHOSTDOWN')
            else:
                #
                #  We don't really know what happened.  Just dump the raw data
                #  as the message.
                #
                return error_response(details)
            #
            #
        except SystemExit:
            raise
        except KeyboardInterrupt:
            sys.exit(errno.EINVAL)
        except BaseException as e:
            print(e)
            raise
Exemplo n.º 7
0
def test_lifecycle_success():
    with Session() as session:
        session.login('cnc:7130')
        w = Workspace(session, pathname='/bubba', writeback='never')
        #
        #  Prepare by deleting any existing workspace.
        #
        try:
            w.delete()
        except RESTException:
            pass
        #
        #  Create/Get/Delete
        #  We expect these methods to raise a RESTException if they fail
        #
        w.set()
        assert (w.get() == w)
        w.delete()
Exemplo n.º 8
0
def test_lifecycle_success():
    with Session() as session:
        session.login('cnc:7130')
        #
        #  Put a workspace on the vtrq
        w = Workspace(session, pathname='/bubba', writeback='never')
        w.set(hard=True)
        #
        #  Mount a volume with that workspace
        v = Volume(session, '/tmp/pytest/bubba', w)
        v.mount(hard=True)
        #
        #  Ensure it mounted
        subprocess.check_output(
            ['bash', '-c', 'mount | fgrep {}'.format(v.mount_point)])
        #
        #  Clean up
        v.unmount()
        w.delete()
Exemplo n.º 9
0
def main(args=None):
    """The main routine."""
    if args is None:
        args = sys.argv[1:]

    with Session() as session:
        handler = Handler(session)
        parser = vclc_parser(handler)
        #
        try:
            global quiet
            results = parser.parse_args(args, handler)
            quiet = results.quiet
            return results.action()
        except requests.exceptions.RequestException as e:
            #
            #  Requests raised an exception.  Probably couldn't reach the vCNC
            #  server There is no HTTP code for this error, so we adopt 504,
            #  which is similar.
            #
            #  Yes, it would have been cooler to have done this with a single
            #  RE.
            #
            details = str(e)
            match_host = re.search("host='(\S+)'", details)
            match_port = re.search("port=(\d+)", details)
            match_error = re.search('NewConnectionError', details)
            suffix = '.'
            #
            #  If the server happens to match the vCNC server's default value,
            #  then add the additional suggestion to check configuration.
            #
            if match_host and match_port and match_error:
                host = match_host.group(1)
                port = match_port.group(1)
                if host == 'vcnc' and port == "6130":
                    suffix = ''.join([
                        ' Did you mean to set a command line switch',
                        ' or environment variable?'])
                return error_response('Could not reach vCNC server at '
                                      + match_host.group(1)
                                      + ':'
                                      + match_port.group(1)
                                      + suffix,
                                      http_status=504,
                                      error_sym='EHOSTDOWN')
            else:
                #
                #  We don't really know what happened.  Just dump the raw data
                #  as the message.
                #
                return error_response(details)
            #
            #
        except vClcException:
            #
            #  Calling 'vclc' with no arguments isn't trapped as an error by
            #  argparse.
            #
            m = parser.format_usage()
            m = re.sub('\n[ ]+', ' ', m)
            return error_response(m, http_status=400, error_sym='EINVAL')
        except SystemExit:
            raise
        except KeyboardInterrupt:
            sys.exit(errno.EINVAL)
        except BaseException:
            raise