def test_stop_session_1(self):
        """
        close a session that is open
        """

        # open a session
        ws1 = self.cm.access(self.host1,self.user11,self.pass11)
        session_number1,es = ws1.execute('echo $SESSION')
        self.assertTrue(int(session_number1) > 0,
            "session_number = %s, i don't think we are in a workspace" \
            % session_number1)
        ws1.close()

        # stop the tool session container
        self.cm.stop(self.host1,self.user11,session_number1)

        session = ToolSession(host=self.host1,
                              username=self.user11,
                              password=self.pass11)

        data = session.get_open_session_detail()
        for k,v in data.items():
            if v['session_number'] == session_number1:
                self.assertTrue(v['session_number'] == session_number1,
                    "session %s still open, after calling stop()" \
                    % (session_number1))
Example #2
0
    def launch(self, toolname, username, userpass):
        """
        test launching the tool as the tool submitter
        """

        self.logger.info("test launching the tool '%s'" % (toolname))

        # try launching the tool
        po = self.catalog.load_pageobject("ToolsStatusInstalledPage", toolname)
        po.goto_page()
        po.goto_launch_tool()

        # check if a new tool session was started
        self.logger.info("checking if new tool session was started")

        po = self.catalog.load_pageobject("ToolSessionPage")
        session_number = po.get_session_number()

        session = ToolSession(host=self.hubname, username=username, password=userpass)
        session_data = session.get_open_session_detail()

        has_session = False
        for session_info in session_data.values():
            if int(session_info["session_number"]) == int(session_number):
                has_session = True
                self.logger.info("Found session %s in user's session list" % session_number)
                break

        if not has_session:
            raise Exception("session #%s does not appear to be open" % (session_number))

        ws = session.access(session_number)
        snum, es = ws.execute("echo $SESSION")
        if session_number != int(snum):
            # we are not in the correct session
            raise Exception("ssh'ing into session #%s failed: %s" % (session_number, snum))

        # look for the tool to be running
        output = ""
        cmd = "ps aux | grep /apps/%s/.*/middleware/invoke | grep -v grep" % (toolname)

        output, es = ws.execute(cmd, fail_on_exit_code=False)
        ws.close()

        # close the tool
        session.stop(session_number)

        if es != 0:
            self.logger.error(output)
            raise Exception(output)
    def setup_method(self,method):

        self.remove_files = []

        # get user account info
        self.reguser,self.regpass = self.testdata.find_account_for('registeredworkspace')
        self.appsuser,self.appspass = self.testdata.find_account_for('appsworkspace')
        self.hubname = self.testdata.find_url_for('https')

        # setup a web browser
        self.browser.get(self.https_authority)

        # setup access to tool session containers
        cm = ContainerManager()

        self.reg_ws = cm.access(host=self.hubname,
                                username=self.reguser,
                                password=self.regpass)

        self.session = ToolSession(
            host=self.hubname, username=self.reguser, password=self.regpass)

        # get a list of session open before the test was run
        # incase the test fails unexpectedly, we can cleanup
        self.existing_sessions = self.session.get_open_session_detail()
        self.close_sessions = []
class TestParameterPassingUrl(TestCase2):

    def setup_method(self,method):

        self.remove_files = []

        # get user account info
        self.reguser,self.regpass = self.testdata.find_account_for('registeredworkspace')
        self.appsuser,self.appspass = self.testdata.find_account_for('appsworkspace')
        self.hubname = self.testdata.find_url_for('https')

        # setup a web browser
        self.browser.get(self.https_authority)

        # setup access to tool session containers
        cm = ContainerManager()

        self.reg_ws = cm.access(host=self.hubname,
                                username=self.reguser,
                                password=self.regpass)

        self.session = ToolSession(
            host=self.hubname, username=self.reguser, password=self.regpass)

        # get a list of session open before the test was run
        # incase the test fails unexpectedly, we can cleanup
        self.existing_sessions = self.session.get_open_session_detail()
        self.close_sessions = []

    def teardown_method(self,method):

        # exit the workspace
        # shut down the ssh connection
        self.reg_ws.close()

        # see if we can find any sessions accidentally left open.
        open_sessions = self.session.get_open_session_detail()
        open_sessions_numbers = []

        for row in open_sessions.values():
            open_sessions_numbers.append(row['session_number'])
            if re.search(TOOL_NAME,row['name']) is not None:
                # we found an open session that matches the name of our test tool
                # check if it was open before we started the test.
                old_session = False
                for existing_row in self.existing_sessions.values():
                    if existing_row['session_number'] == row['session_number']:
                        old_session = True
                        break
                if old_session is False:
                    # we found a session that was not open when the test started
                    # but is open now. there is a small chance it was opened by
                    # someone else.
                    # check if it is already in the list of sessions to be closed,
                    # if not, add the session to the list
                    if row['session_number'] not in self.close_sessions:
                        self.close_sessions.append(row['session_number'])

        # close the parampass tool's container
        for session_number in self.close_sessions:
            # check if the session is still open before closing it
            if session_number in open_sessions_numbers:
                self.session.stop(session_number)

        del self.session


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_no_parameters_file(self):
        """
        launch a tool with no parameters argument in url.
        """

        parameters_text = ''

        sessnum = launch_tool(self.https_authority,self.reguser,self.regpass,
                    self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @pytest.mark.skipif(True, reason="we no longer do file validation")
    @hubcheck.utils.hub_version(min_version='1.1.4')
    def dnr_test_launch_tool_invalid_path_1(self):
        """
        launch a tool with a parameter file with an invalid filename.

        file(datafile1):/home/hubname/testuser/file_does_not_exist
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')

        parameters_text = 'file(datafile1):%s/file_does_not_exist' % (home_dir)

        try:
            sessnum = launch_tool(self.https_authority,self.reguser,
                        self.regpass,self.browser,self.catalog,self.utils,
                        TOOL_NAME,TOOL_REVISION,parameters_text)

            self.close_sessions.append(sessnum)

            assert False, "while passing tool parameters, cms failed to" \
                + " catch invalid path: %s" % (repr(parameters_text))

        except BadParameterError as e:
            pass


    @pytest.mark.skipif(True, reason="we no longer do file validation")
    @hubcheck.utils.hub_version(min_version='1.1.4')
    def dnr_test_launch_tool_invalid_path_2(self):
        """
        launch a tool with a parameter file with an invalid user.

        file(datafile1):/home/hubname/non_existent_fake_user/file_does_not_exist
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')
        home_base = os.path.dirname(home_dir)
        home_dir = os.path.join(home_base,'non_existent_fake_user')

        parameters_text = 'file(datafile1):%s/file_does_not_exist' % (home_dir)

        try:
            sessnum = launch_tool(self.https_authority,self.reguser,
                        self.regpass,self.browser,self.catalog,self.utils,
                        TOOL_NAME,TOOL_REVISION,parameters_text)

            self.close_sessions.append(sessnum)

            assert False, "while passing tool parameters, cms failed to" \
                + " catch invalid path: %s" % (repr(parameters_text))

        except BadParameterError as e:
            pass


    @pytest.mark.skipif(True, reason="we no longer do file validation")
    @hubcheck.utils.hub_version(min_version='1.1.4')
    def dnr_test_launch_tool_invalid_path_3(self):
        """
        launch a tool with a parameter file with an invalid hubname.

        file(datafile1):/home/bad_hubname/fake_user/file_does_not_exist
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')
        home_base = os.path.dirname(os.path.dirname(home_dir))
        home_dir = os.path.join(home_base,'bad_hubname','fake_user')

        parameters_text = 'file(datafile1):%s/file_does_not_exist' % (home_dir)

        try:
            sessnum = launch_tool(self.https_authority,self.reguser,
                        self.regpass,self.browser,self.catalog,self.utils,
                        TOOL_NAME,TOOL_REVISION,parameters_text)

            self.close_sessions.append(sessnum)

            assert False, "while passing tool parameters, cms failed to" \
                + " catch invalid path: %s" % (repr(parameters_text))

        except BadParameterError as e:
            pass


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_invalid_path_4(self):
        """
        launch a tool with a parameter file with an invalid hubname.

        file(datafile1):/bad_home/bad_hubname/fake_user/file_does_not_exist
        """

        home_dir = os.path.join('/','bad_home','bad_hubname','fake_user')

        parameters_text = 'file(datafile1):%s/file_does_not_exist' % (home_dir)

        try:
            sessnum = launch_tool(self.https_authority,self.reguser,
                        self.regpass,self.browser,self.catalog,self.utils,
                        TOOL_NAME,TOOL_REVISION,parameters_text)

            self.close_sessions.append(sessnum)

            assert False, "while passing tool parameters, cms failed to" \
                + " catch invalid path: %s" % (repr(parameters_text))

        except BadParameterError as e:
            pass


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_blacklisted_path_1(self):
        """
        launch a tool with a parameter file with an blacklisted path.

        file(datafile1):/etc/environ
        """

        parameters_text = 'file(datafile1):/etc/environ'

        try:
            sessnum = launch_tool(self.https_authority,self.reguser,
                        self.regpass,self.browser,self.catalog,self.utils,
                        TOOL_NAME,TOOL_REVISION,parameters_text)

            self.close_sessions.append(sessnum)

            assert False, "while passing tool parameters, cms failed to" \
                + " catch blacklisted path: %s" % (repr(parameters_text))

        except BadParameterError as e:
            pass


    @pytest.mark.skipif(
        not hubcheck.utils.check_hub_hostname(['nees.org']),
        reason="nees.org specific test")
    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_whitelisted_path_1(self):
        """
        launch a tool with a parameter file with a whitelisted path.

        directory:/nees
        """

        parameters_text = 'directory:/nees'

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @pytest.mark.skipif(
        not hubcheck.utils.check_hub_hostname(['nees.org']),
        reason="nees.org specific test")
    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_whitelisted_path_2(self):
        """
        launch a tool with a parameter file with a whitelisted path.

        file:/nees/home/Public.groups/thumb_1235445883_Model-18EP-a.jpg
        """

        parameters_text = 'file:/nees/home/Public.groups/thumb_1235445883_Model-18EP-a.jpg'

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_whitelisted_path_3(self):
        """
        launch a tool with a parameter file with a whitelisted path.

        directory:/home/blahh
        """

        parameters_text = 'directory:/home/blahh'

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_home_expansion_1(self):
        """
        launch a tool with a parameter file with a ~ in the path.

        file(datafile1):~/.icewm/menu
        """

        parameters_text = 'file(datafile1):~/.icewm/menu'

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_named_file_1(self):
        """
        launch a tool with a single named file parameter in url.
        """

        session_dir,es = self.reg_ws.execute('echo ${SESSIONDIR}')

        parameters_text = 'file(datafile1):%s/resources' % (session_dir)

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_named_file_2(self):
        """
        launch a tool with multiple named file parameter in url.
        files are located in home directory
        """

        session_dir,es = self.reg_ws.execute('echo ${SESSIONDIR}')
        home_dir,es = self.reg_ws.execute('echo ${HOME}')

        parameters_text = '\n'.join([
            'file(datafile1):%s/resources' % (session_dir),
            'file(datafile2):%s/.icewm/menu' % (home_dir),
        ])

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_file_format_1(self):
        """
        launch a tool with single named file parameter and an
        extra newline at the end of the file.
        https://nees.org/groups/parampass/wiki/MainPage step 1 (b)
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')

        parameters_text = '\n'.join([
            'file(datafile2):%s/.icewm/menu' % (home_dir),
            '',
        ])

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        parameters_text = shrink_space(parameters_text)

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_file_format_2(self):
        """
        launch a tool with single named file parameter and
        multiple extra newlines at the end of the file.
        https://nees.org/groups/parampass/wiki/MainPage step 1 (b)
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')

        parameters_text = '\n'.join([
            'file(datafile2):%s/.icewm/menu' % (home_dir),
            '',
            '',
        ])

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        parameters_text = shrink_space(parameters_text)

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_file_format_3(self):
        """
        launch a tool with single named file parameter and
        surrounded by multiple extra newlines.
        https://nees.org/groups/parampass/wiki/MainPage step 1 (b)
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')

        parameters_text = '\n'.join([
            '',
            '',
            'file(datafile2):%s/.icewm/menu' % (home_dir),
            '',
            '',
        ])

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        parameters_text = shrink_space(parameters_text)

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_file_format_4(self):
        """
        launch a tool with single named file parameter and
        preceeded by multiple extra newlines.
        https://nees.org/groups/parampass/wiki/MainPage step 1 (b)
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')

        parameters_text = '\n'.join([
            '',
            '',
            'file(datafile2):%s/.icewm/menu' % (home_dir),
        ])

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        parameters_text = shrink_space(parameters_text)

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_file_format_5(self):
        """
        launch a tool with multiple named file parameter and
        a single extra newlines between the parameters.
        https://nees.org/groups/parampass/wiki/MainPage step 1 (b)
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')

        parameters_text = '\n'.join([
            'file(datafile2):%s/.icewm/menu' % (home_dir),
            '',
            'file(datafile2):%s/.icewm/preferences' % (home_dir),
        ])

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_launch_tool_file_format_6(self):
        """
        launch a tool with multiple named file parameter and
        multiple extra newlines between the parameters.
        https://nees.org/groups/parampass/wiki/MainPage step 1 (b)
        """

        home_dir,es = self.reg_ws.execute('echo ${HOME}')

        parameters_text = '\n'.join([
            'file(datafile2):%s/.icewm/menu' % (home_dir),
            '',
            '',
            'file(datafile2):%s/.icewm/preferences' % (home_dir),
        ])

        sessnum = launch_tool(self.https_authority,self.reguser,
                    self.regpass,self.browser,self.catalog,self.utils,
                    TOOL_NAME,TOOL_REVISION,parameters_text)

        self.close_sessions.append(sessnum)

        ws = self.session.access(session_number=sessnum)
        ws.execute('cd $SESSIONDIR')

        ws_params_text = retrieve_container_parameters(ws)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))
class TestParameterPassingInvokeApp(TestCase2):

    def setup_method(self,method):

        self.remove_files = []

        # get user account info
        self.reguser,self.regpass = self.testdata.find_account_for('registeredworkspace')
        self.appsuser,self.appspass = self.testdata.find_account_for('appsworkspace')
        hubname = self.testdata.find_url_for('https')

        # setup a web browser
        self.browser.get(self.https_authority)

        # setup access to tool session containers
        cm = ContainerManager()

        self.reg_ws = cm.access(host=hubname,
                                username=self.reguser,
                                password=self.regpass)

        self.apps_ws = cm.access(host=hubname,
                                 username=self.appsuser,
                                 password=self.appspass,
                                 toolname=hubcheck.conf.settings.apps_workspace_toolname)

        self.session = ToolSession(
            host=hubname, username=self.reguser, password=self.regpass)

        self.reg_ws.execute('cd $SESSIONDIR')

        # get a list of session open before the test was run
        # incase the test fails unexpectedly, we can cleanup
        self.existing_sessions = self.session.get_open_session_detail()
        self.close_sessions = []

    def teardown_method(self,method):

        # exit the workspace
        # shut down the ssh connection
        self.reg_ws.close()
        self.apps_ws.close()

        # see if we can find any sessions accidentally left open.
        open_sessions = self.session.get_open_session_detail()
        open_sessions_numbers = []

        for row in open_sessions.values():
            open_sessions_numbers.append(row['session_number'])
            if re.search(TOOL_NAME,row['name']) is not None:
                # we found an open session that matches the name of our test tool
                # check if it was open before we started the test.
                old_session = False
                for existing_row in self.existing_sessions.values():
                    if existing_row['session_number'] == row['session_number']:
                        old_session = True
                        break
                if old_session is False:
                    # we found a session that was not open when the test started
                    # but is open now. there is a small chance it was opened by
                    # someone else.
                    # check if it is already in the list of sessions to be closed,
                    # if not, add the session to the list
                    if row['session_number'] not in self.close_sessions:
                        self.close_sessions.append(row['session_number'])

        # close the parampass tool's container
        for session_number in self.close_sessions:
            # check if the session is still open before closing it
            if session_number in open_sessions_numbers:
                self.session.stop(session_number)

        del self.session


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_1_command_no_templates_no_parameters_file(self):
        """
        launch a tool with an invoke script with one -C option that is not
        templated. do not create a parameters file.
        """

        invoke_script = """#!/bin/sh
        %(invoke_app_path)s -C %(test_program)s
        """ % {'invoke_app_path' : INVOKE_APP_PATH,
               'test_program' : TEST_PROGRAM_NAME}

        params_info = {
        }

        expected_parameters = ''

        sessnum,parameters_text = pass_parameters(self.apps_ws, self.reg_ws,
                                      invoke_script, params_info,
                                      self.https_authority, self.reguser,
                                      self.regpass, self.browser,
                                      self.catalog, self.utils)

        self.close_sessions.append(sessnum)

        # log into the tool session container to get the list of parameters
        # passed into the test program. we check that the paramaters were
        # all found in our original parameters file we generated earlier.

        ws = self.session.access(session_number=sessnum)
        ws.execute('echo $SESSION')

        ws_params_text = retrieve_container_parameters(ws)
        ws_params_out = retrieve_program_output(ws,TEST_PROGRAM_PARAMS_FNAME)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))

        # check that toolparams started the correct tool based on
        # parameters passed into the container.
        assert expected_parameters == ws_params_out, \
            "expected parameters: %s\nreceived parameters: %s" \
            % (repr(expected_parameters),repr(ws_params_out))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_1_command_no_templates_with_parameters_file(self):
        """
        launch a tool with an invoke script with one -C option that is not
        templated. create a parameters file. no parameters should be passed
        to the test program.
        """

        homedir,es = self.reg_ws.execute('echo ${HOME}')

        invoke_script = """#!/bin/sh
        %(invoke_app_path)s -C %(test_program)s
        """ % {'invoke_app_path' : INVOKE_APP_PATH,
               'test_program' : TEST_PROGRAM_NAME}

        params_info = {
            'datafile1' : {
                'text' : 'this is datafile1',
                'type' : 'file(datafile1)',
                'path' : "%s/datafile1" % (homedir),
            },
        }

        expected_parameters = ''

        sessnum,parameters_text = pass_parameters(self.apps_ws, self.reg_ws,
                                      invoke_script, params_info,
                                      self.https_authority, self.reguser,
                                      self.regpass, self.browser,
                                      self.catalog, self.utils)

        self.close_sessions.append(sessnum)

        # log into the tool session container to get the list of parameters
        # passed into the test program. we check that the paramaters were
        # all found in our original parameters file we generated earlier.

        ws = self.session.access(session_number=sessnum)
        ws.execute('echo $SESSION')

        ws_params_text = retrieve_container_parameters(ws)
        ws_params_out = retrieve_program_output(ws,TEST_PROGRAM_PARAMS_FNAME)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))

        # check that toolparams started the correct tool based on
        # parameters passed into the container.
        assert expected_parameters == ws_params_out, \
            "expected parameters: %s\nreceived parameters: %s" \
            % (repr(expected_parameters),repr(ws_params_out))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_1_template_1_default_run_default(self):
        """
        launch a tool with an invoke script with two -C options. the first
        -C option is templated and accepts a named file. the second -C option
        is not templated. invoke_app should make the non-templated command the
        default option for toolparams. toolparams should run the default option
        because there is no TOOL_PARAMETERS file and no templates will match.
        no TOOL_PARAMETERS file will be created. no parameters should be passed
        to the test program.
        """

        invoke_script = """#!/bin/sh
        %(invoke_app_path)s -C "%(test_program)s @@file(datafile1)" -C %(test_program)s
        """ % {'invoke_app_path' : INVOKE_APP_PATH,
               'test_program' : TEST_PROGRAM_NAME}

        params_info = {
        }

        expected_parameters = ''

        sessnum,parameters_text = pass_parameters(self.apps_ws, self.reg_ws,
                                      invoke_script, params_info,
                                      self.https_authority, self.reguser,
                                      self.regpass, self.browser,
                                      self.catalog, self.utils)

        self.close_sessions.append(sessnum)

        # log into the tool session container to get the list of parameters
        # passed into the test program. we check that the paramaters were
        # all found in our original parameters file we generated earlier.

        ws = self.session.access(session_number=sessnum)
        ws.execute('echo $SESSION')

        ws_params_text = retrieve_container_parameters(ws)
        ws_params_out = retrieve_program_output(ws,TEST_PROGRAM_PARAMS_FNAME)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))

        # check that toolparams started the correct tool based on
        # parameters passed into the container.
        assert expected_parameters == ws_params_out, \
            "expected parameters: %s\nreceived parameters: %s" \
            % (repr(expected_parameters),repr(ws_params_out))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_1_template_1_default_run_template(self):
        """
        launch a tool with an invoke script with two -C options. the first
        -C option is templated and accepts a named file. the second -C option
        is not templated. invoke_app should make the non-templated command the
        default option for toolparams. toolparams should run the templated option
        because it will match a value in the TOOL_PARAMETERS file.
        one parameter should be passed to the test program.
        """

        homedir,es = self.reg_ws.execute('echo ${HOME}')

        invoke_script = """#!/bin/sh
        %(invoke_app_path)s -C "%(test_program)s @@file(datafile1)" -C %(test_program)s
        """ % {'invoke_app_path' : INVOKE_APP_PATH,
               'test_program' : TEST_PROGRAM_NAME}

        params_info = {
            'datafile1' : {
                'text' : 'this is datafile1',
                'type' : 'file(datafile1)',
                'path' : "%s/datafile1" % (homedir),
            },
        }

        expected_parameters = params_info['datafile1']['path']

        sessnum,parameters_text = pass_parameters(self.apps_ws, self.reg_ws,
                                      invoke_script, params_info,
                                      self.https_authority, self.reguser,
                                      self.regpass, self.browser,
                                      self.catalog, self.utils)

        self.close_sessions.append(sessnum)

        # log into the tool session container to get the list of parameters
        # passed into the test program. we check that the paramaters were
        # all found in our original parameters file we generated earlier.

        ws = self.session.access(session_number=sessnum)
        ws.execute('echo $SESSION')

        ws_params_text = retrieve_container_parameters(ws)
        ws_params_out = retrieve_program_output(ws,TEST_PROGRAM_PARAMS_FNAME)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))

        # check that toolparams started the correct tool based on
        # parameters passed into the container.
        assert expected_parameters == ws_params_out, \
            "expected parameters: %s\nreceived parameters: %s" \
            % (repr(expected_parameters),repr(ws_params_out))


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_1_template_0_default_run_template_1(self):
        """
        launching a tool with an invoke script with one -C template command
        should launch toolparams to run the command. toolparams
        should launch the tool with the templated argument.
        """

        homedir,es = self.reg_ws.execute('echo ${HOME}')

        invoke_script = """#!/bin/sh
        %(invoke_app_path)s -C "%(test_program)s @@file(datafile1)"
        """ % {'invoke_app_path' : INVOKE_APP_PATH,
               'test_program' : TEST_PROGRAM_NAME}

        params_info = {
            'datafile1' : {
                'text' : 'this is datafile1',
                'type' : 'file(datafile1)',
                'path' : "%s/datafile1" % (homedir),
            },
        }

        expected_parameters = params_info['datafile1']['path']

        sessnum,parameters_text = pass_parameters(self.apps_ws, self.reg_ws,
                                      invoke_script, params_info,
                                      self.https_authority, self.reguser,
                                      self.regpass, self.browser,
                                      self.catalog, self.utils)

        self.close_sessions.append(sessnum)

        # log into the tool session container to get the list of parameters
        # passed into the test program. we check that the paramaters were
        # all found in our original parameters file we generated earlier.

        ws = self.session.access(session_number=sessnum)
        ws.execute('echo $SESSION')

        ws_params_text = retrieve_container_parameters(ws)
        ws_params_out = retrieve_program_output(ws,TEST_PROGRAM_PARAMS_FNAME)

        ws.close()

        # check that the TOOL_PARAMETERS file has the same info
        # as out parameters_text variable it was created from
        assert parameters_text == ws_params_text, \
            "TOOL_PARAMETERS file in container does not match data" \
            + " sent through url.\nexpected:\n%s\nreceived:\n%s\n" \
            % (repr(parameters_text),repr(ws_params_text))

        # check that toolparams started the correct tool based on
        # parameters passed into the container.
        assert expected_parameters == ws_params_out, \
            "expected parameters: %s\nreceived parameters: %s" \
            % (repr(expected_parameters),repr(ws_params_out))