def setup_method(self,method):

        self.remove_files = []

        # get user account info
        self.username,self.userpass = self.testdata.find_account_for('registeredworkspace')
        hubname = self.testdata.find_url_for('https')

        # access a tool session container
        cm = ContainerManager()
        self.ws = cm.access(host=hubname,
                            username=self.username,
                            password=self.userpass)

        # copy the executable to the session directory
        self.sftp = SFTPClient(
            host=hubname, username=self.username, password=self.userpass)

        local_exe_path = os.path.join(hubcheck.conf.settings.data_dir,
                                 'capacitor_voltage','sim1.py')

        self.ws.execute('cd $SESSIONDIR')
        sessiondir,es = self.ws.execute('pwd')

        self.exe_fn = 'sim1.py'
        self.exe_path = os.path.join(sessiondir,self.exe_fn)
        self.remove_files.append(self.exe_path)

        self.sftp.chdir(sessiondir)
        self.sftp.put(local_exe_path,self.exe_fn)
        self.sftp.chmod(self.exe_path,0700)

        # shouldn't take more than 60 seconds
        # to run submit --local commands
        self.ws.timeout = 60
    def setup_method(self,method):

        # get into a tool session container
        hubname = self.testdata.find_url_for('https')
        self.username,self.userpass = \
            self.testdata.find_account_for('purdueworkspace')

        cm = ContainerManager()
        self.ws = cm.access(host=hubname,
                            username=self.username,
                            password=self.userpass)

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

        self.utils.account.login_as(self.username,self.userpass)

        # setup file paths
        fxf_fn = 'hcfxf.txt'
        self.ws.execute('cd $SESSIONDIR')
        sessiondir,es = self.ws.execute('pwd')
        self.fxf_path = os.path.join(sessiondir,fxf_fn)
        self.localfn = os.path.join(os.getcwd(),'hcfxf.tmp')

        self.expected = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    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 setUp(self):

        self.remove_files = []

        # get user account info
        self.username,self.userpass = self.testdata.find_account_for('registeredworkspace')
        hubname = self.testdata.find_url_for('https')

        cm = ContainerManager()

        self.ws = cm.access(host=hubname,
                            username=self.username,
                            password=self.userpass)

        # cd into the session directory
        self.sftp = SFTPClient(
            host=hubname, username=self.username, password=self.userpass)

        self.ws.execute('cd $SESSIONDIR')
        self.sessiondir,es = self.ws.execute('pwd')
        self.sftp.chdir(self.sessiondir)


        # write data and script files to disk in the container.
        for fname,fprop in FILES.items():
            with self.sftp.open(fname,mode='w') as f:
                f.write(fprop['contents'])
            self.remove_files.append(os.path.join(self.sessiondir,fname))
            self.sftp.chmod(fname,fprop['mode'])
    def setUp(self):

        self.remove_files = []
        self.ws = None

        # get user account info
        self.hubname = self.testdata.find_url_for('https')
        self.username,self.userpass = \
            self.testdata.find_account_for('purdueworkspace')

        cm = ContainerManager()
        self.ws = cm.access(host=self.hubname,
                            username=self.username,
                            password=self.userpass)

        # copy the checknet executable to the session directory
        self.ws.execute('cd $SESSIONDIR')
        sessiondir,es = self.ws.execute('pwd')

        self.exe_fn = 'checknet.py'
        local_exe_path = os.path.join(hubcheck.conf.settings.data_dir,self.exe_fn)
        self.exe_path = os.path.join(sessiondir,self.exe_fn)
        self.remove_files.append(self.exe_path)

        self.ws.importfile(local_exe_path,self.exe_path,mode=0o700)
    def setUp(self):

        # get user account info
        hubname = self.testdata.find_url_for('https')
        self.username,self.userpass = \
            self.testdata.find_account_for('registeredworkspace')

        cm = ContainerManager()
        self.ws = cm.access(host=hubname,
                            username=self.username,
                            password=self.userpass)
    def setup_method(self,method):

        # get user account info
        self.username,self.userpass = \
            self.testdata.find_account_for('appsworkspace')
        hubname = self.testdata.find_url_for('https')

        # access a tool session container
        cm = ContainerManager()
        self.ws = cm.access(host=hubname,
                            username=self.username,
                            password=self.userpass)

        self.sessiondir = self.ws.execute('echo $SESSIONDIR')
    def setup_method(self,method):

        # get user account info
        self.hubname = self.testdata.find_url_for('https')

        # access a tool session container
        self.cm = ContainerManager()
    def setUp(self):

        # start up a tool session container
        self.hubname = self.testdata.find_url_for('https')
        self.username,self.userpass = \
            self.testdata.find_account_for('purdueworkspace')

        self.cm = ContainerManager()
        self.ws = self.cm.create(host=self.hubname,
                                 username=self.username,
                                 password=self.userpass)

        self.session_number,es = self.ws.execute('echo $SESSION')
        self.session_number = int(self.session_number)

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

        self.utils.account.login_as(self.username,self.userpass)

        self.po = self.catalog.load_pageobject('GenericPage')
        self.po.header.goto_myaccount()

        self.po = self.catalog.load_pageobject('MembersDashboardPage')

        self.my_sessions_module = self.po.modules.my_sessions
    def setup_method(self,method):

        self.remove_files = []

        # get user account info
        self.username,self.userpass = self.testdata.find_account_for('registeredworkspace')
        hubname = self.testdata.find_url_for('https')

        # access a tool session container
        cm = ContainerManager()
        self.ws = cm.access(host=hubname,
                            username=self.username,
                            password=self.userpass)

        self.ws.execute('cd $SESSIONDIR')
        self.sessiondir,es = self.ws.execute('pwd')
    def setup_method(self,method):

        # get user account info
        self.username,self.userpass = self.testdata.find_account_for('submituser')
        hubname = self.testdata.find_url_for('https')

        cm = ContainerManager()

        self.ws = cm.access(host=hubname,
                            username=self.username,
                            password=self.userpass)

        self.ws.execute('cd $SESSIONDIR')
        sessiondir,es = self.ws.execute('pwd')
        self.exe_path = os.path.join(sessiondir,sayhi_py_fn)
        self.ws.importfile(sayhi_py_data,self.exe_path,mode=0o600,is_data=True)

        self.ws.timeout = 30
    def setUp(self):

        self.ws = None

        if self.data is None:
            # only get the package list once

            # get user account info
            hubname = self.testdata.find_url_for('https')
            self.username,self.userpass = \
                self.testdata.find_account_for('registeredworkspace')

            cm = ContainerManager()
            self.ws = cm.access(host=hubname,
                                username=self.username,
                                password=self.userpass)

            self.data = self.ws.read_file('/var/tmp/installed_pkgs')
Ejemplo n.º 13
0
    def checkout_repository(self, toolname, username, userpass):
        """
        checkout the repository to see if it exists and is accessible.
        """

        self.logger.info("checking out repository for the tool '%s'" % (toolname))

        repo_url = self.repo_url_template % {"hubname": self.hubname, "toolname": toolname}

        # ssh into a tool session container
        cm = ContainerManager()
        ws = cm.access(host=self.hubname, username=username, password=userpass)

        svn = Subversion(ws, username, userpass)

        session_number = -1
        repo_home = None
        try:
            session_number, es = ws.execute("echo $SESSION")
            if session_number <= 0:
                raise RuntimeError("invalid session number: %s" % (session_number))

            # create a temp directory to hold the repo
            repo_home, es = ws.execute("mktemp -d --tmpdir=`pwd` -t tmp.XXXXXXXX")
            ws.execute("cd %s" % (repo_home))

            # do the checkout
            svn.checkout(repo_url, toolname)

            # cd into the repo
            ws.execute("cd %s" % (toolname))
            tool_repo, es = ws.execute("pwd")

        finally:
            # FIXME: remove the temp directory
            ws.send_raw("")
            ws.send_raw("")
            time.sleep(5)
            if repo_home is not None:
                ws.execute("rm -rf %s" % (repo_home))

            # shut down the ssh connection
            ws.close()
    def setup_method(self,method):

        # get user account info
        self.username,self.userpass = \
            self.testdata.find_account_for('registeredworkspace')
        self.hubname = self.testdata.find_url_for('https')

        # get into a workspace
        self.cm = ContainerManager()
        self.ws = self.cm.access(host=self.hubname,
                                 username=self.username,
                                 password=self.userpass)
    def _time_groups_for(self,usertype):

        # get user account info
        hubname = self.testdata.find_url_for('https')
        username,userpass = \
            self.testdata.find_account_for(usertype)


        cm = ContainerManager()
        self.ws = cm.access(host=hubname,
                            username=username,
                            password=userpass)

        command = '/usr/bin/time -f "{0}" groups {1}'.format('%e',username)
        output,es = self.ws.execute(command)

        time_re = re.compile('%s : ([^\n]+)\r\n([^\n]+)(\r\n)?' % (username))
        match = time_re.search(output)
        self.assertTrue(match is not None, output)

        (grouplist,timecount,junk) = match.groups()

        self.assertTrue(float(timecount) < 1.0,
            "groups command took longer than 1 second: %s" % (timecount))

        self.assertTrue(grouplist != "",
            "groups list is empty: %s" % (output))

        fail_groups = []
        for group in grouplist.split():
            try:
                float(group)
                fail_groups.append(group)
            except ValueError:
                pass

        self.assertTrue(len(fail_groups) == 0,
            "groups with no name: %s" % (fail_groups))
class TestWorkspaceUser(TestCase2):

    def setup_method(self,method):

        # get user account info
        self.hubname = self.testdata.find_url_for('https')

        # access a tool session container
        self.cm = ContainerManager()


    def teardown_method(self,method):

        pass


    def test_workspace_access(self):
        """
        the hc accounts specified as being in the mw-login group
        should be able to ssh into a workspace using virtual ssh
        """

        failed_logins = []

        for username in self.testdata.get_usernames():
            userdata = self.testdata.get_userdata_for(username)

            if 'mw-login' not in userdata.admin_properties.groups:
                continue

            ws = None

            try:
                ws = self.cm.access(host=self.hubname,
                                    username=userdata.username,
                                    password=userdata.password)

                sessiondir = ws.execute('echo $SESSIONDIR')

            except:
                failed_logins.append(userdata.username)

            finally:
                if ws is not None:
                    ws.close()
                    ws = None


        assert len(failed_logins) == 0, \
            'login failed for the following accounts: %s' % (failed_logins)
    def test_tty_recycle(self):
        """
        check if ttys are being released after ssh connections are closed.

        ssh'ing into a workspace, opening a shell, and closing the ssh
        connection should release the pty. tool session containers get 15 ptys.
        we are checking to see if ptys are being released after the user exits
        the pty.

        the failue occurs in the call to cm.access().
        """

        session_number = 0
        cm = ContainerManager()

        for i in range(31):

            try:
                # access a tool session container
                ws = cm.access(host=self.hubname,
                               username=self.username,
                               password=self.userpass)

                session_number,es = ws.execute('echo $SESSION')

                # start up a new bash shell manually
                ws.send('/bin/bash')

                # exit the workspace
                ws.close()
            except (ConnectionClosedError,socket.timeout) as e:
                if session_number > 0:
                    # container is hosed, shut it down.
                    cm.stop(self.hubname,self.username,int(session_number))
                assert False, "After connecting %s time(s): %s" \
                    % (i,sys.exc_info()[0])
Ejemplo n.º 18
0
    def setUp(self):

        self.cm = ContainerManager()

        self.host1 = ''
        self.user11 = ''
        self.pass11 = ''
        self.user12 = ''
        self.pass12 = ''

        self.host2 = ''
        self.user21 = ''
        self.pass21 = ''
        self.user22 = ''
        self.pass22 = ''
    def setup_method(self,method):

        # start up a tool session container
        self.hubname = self.testdata.find_url_for('https')
        self.username,self.userpass = \
            self.testdata.find_account_for('registeredworkspace')

        self.cm = ContainerManager()
        self.ws = self.cm.access(host=self.hubname,
                                 username=self.username,
                                 password=self.userpass)

        self.session_number,es = self.ws.execute('echo $SESSION')
        self.ws.close()

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

        self.utils.account.login_as(self.username,self.userpass)

        self.po = self.catalog.load_pageobject('ToolSessionPage',
                    'workspace',int(self.session_number))
        self.po.goto_page()
class TestToolSessionShare(TestCase2):

    def setup_method(self,method):

        # start up a tool session container
        self.hubname = self.testdata.find_url_for('https')
        self.username,self.userpass = \
            self.testdata.find_account_for('registeredworkspace')

        self.cm = ContainerManager()
        self.ws = self.cm.access(host=self.hubname,
                                 username=self.username,
                                 password=self.userpass)

        self.session_number,es = self.ws.execute('echo $SESSION')
        self.ws.close()

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

        self.utils.account.login_as(self.username,self.userpass)

        self.po = self.catalog.load_pageobject('ToolSessionPage',
                    'workspace',int(self.session_number))
        self.po.goto_page()


    def teardown_method(self,method):

        # disconnect all users from workspace

        self.po.goto_page()
        self.po.share.disconnect_all()


    def test_share_session_with_1(self):
        """
        test sharing the session with nobody
        """

        shared_with_1 = self.po.share.get_shared_with()

        self.po.share.share.click()
        self.po.share.wait_for_overlay()

        shared_with_2 = self.po.share.get_shared_with()

        assert len(shared_with_1) == len(shared_with_2), \
            "after pressing the share button, shared list changed: " \
            + "before: %s, after: %s" % (shared_with_1,shared_with_2)

        s1 = set(shared_with_1)
        s2 = set(shared_with_2)
        s_union = s1 | s2

        assert len(s_union) == len(shared_with_1), \
            "after pressing the share button, shared list changed: " \
            + "before: %s, after: %s" % (shared_with_1,shared_with_2)


    def test_share_session_with_2(self):
        """
        test sharing the session with another user
        """

        shared_with_1 = self.po.share.get_shared_with()

        username2,junk = \
            self.testdata.find_account_for('purdueworkspace')
        user2_data = self.testdata.get_userdata_for(username2)
        user2_name = '{0} {1}'.format(user2_data.firstname,user2_data.lastname)

        self.po.share.share_session_with(username2)

        shared_with_2 = self.po.share.get_shared_with()

        assert len(shared_with_1)+1 == len(shared_with_2), \
            "after sharing the session, wrong # users listed: " \
            + "before: %s, after: %s" % (shared_with_1,shared_with_2)

        assert user2_name in shared_with_2, \
            "after sharing session with %s, user %s" % (username2,user2_name) \
            + " does not show up in shared with list: %s" % (shared_with_2)


    def test_share_session_with_3(self):
        """
        test sharing the session with a fake user
        """

        shared_with_1 = self.po.share.get_shared_with()

        self.po.share.share_session_with('fakeuserthatshouldnotexist')

        shared_with_2 = self.po.share.get_shared_with()

        assert len(shared_with_1) == len(shared_with_2), \
            "after sharing the session with a fake user, shared list changed: " \
            + "before: %s, after: %s" % (shared_with_1,shared_with_2)

        s1 = set(shared_with_1)
        s2 = set(shared_with_2)
        s_union = s1 | s2

        assert len(s_union) == len(shared_with_1), \
            "after sharing the session with a fake user, shared list changed: " \
            + "before: %s, after: %s" % (shared_with_1,shared_with_2)


#    def test_share_session_with_4(self):
#        """
#        test sharing the session with a group
#        """
#
#        self.po.share.share_session_with(group=0)


#    def test_share_session_with_5(self):
#        """
#        test sharing the session with another user, read only
#        """
#
#        shared_with_1 = self.po.share.get_shared_with()
#
#        username2,junk = \
#            self.testdata.find_account_for('purdueworkspace')
#        user2_data = self.testdata.get_userdata_for(username2)
#        user2_name = '{0} {1}'.format(user2_data.firstname,user2_data.lastname)

#        self.po.share.share_session_with(username2,readonly=True)
#
#        shared_with_2 = self.po.share.get_shared_with()
#
#        assert len(shared_with_1)+1 == len(shared_with_2), \
#            "after sharing the session, wrong # users listed: " \
#            + "before: %s, after: %s" % (shared_with_1,shared_with_2)
#
#        assert user2_name in shared_with_2, \
#            "after sharing session with %s, user %s" % (username2,user2_name) \
#            + " does not show up in shared with list: %s" % (shared_with_2)
#
#        # check if the user was added to the list with the "read only" property


    def test_share_session_with_6(self):
        """
        test sharing the session with another user twice

        user should only show up once in list
        """

        shared_with_1 = self.po.share.get_shared_with()

        username2,junk = \
            self.testdata.find_account_for('purdueworkspace')
        user2_data = self.testdata.get_userdata_for(username2)
        user2_name = '{0} {1}'.format(user2_data.firstname,user2_data.lastname)

        self.po.share.share_session_with(username2)
        self.po.share.share_session_with(username2)

        shared_with_2 = self.po.share.get_shared_with()

        assert len(shared_with_1)+1 == len(shared_with_2), \
            "after sharing the session, wrong # users listed: " \
            + "before: %s, after: %s" % (shared_with_1,shared_with_2)

        assert user2_name in shared_with_2, \
            "after sharing session with %s, user %s" % (username2,user2_name) \
            + " does not show up in shared with list: %s" % (shared_with_2)


    def test_share_session_with_7(self):
        """
        test sharing the session with multiple users
        """

        shared_with_1 = self.po.share.get_shared_with()

        username2,junk = \
            self.testdata.find_account_for('purdueworkspace')
        user2_data = self.testdata.get_userdata_for(username2)
        user2_name = '{0} {1}'.format(user2_data.firstname,user2_data.lastname)

        username3,junk = \
            self.testdata.find_account_for('networkworkspace')
        user3_data = self.testdata.get_userdata_for(username3)
        user3_name = '{0} {1}'.format(user3_data.firstname,user3_data.lastname)

        self.po.share.share_session_with([username2,username3])

        shared_with_2 = self.po.share.get_shared_with()

        assert len(shared_with_1)+2 == len(shared_with_2), \
            "after sharing the session, wrong # users listed: " \
            + "before: %s, after: %s" % (shared_with_1,shared_with_2)

        assert user2_name in shared_with_2, \
            "after sharing session with %s, user %s" % (username2,user2_name) \
            + " does not show up in shared with list: %s" % (shared_with_2)

        assert user3_name in shared_with_2, \
            "after sharing session with %s, user %s" % (username3,user3_name) \
            + " does not show up in shared with list: %s" % (shared_with_2)


    def test_share_session_with_8(self):
        """
        test sharing the session with multiple users, one at a time
        """

        shared_with_1 = self.po.share.get_shared_with()

        username2,junk = \
            self.testdata.find_account_for('purdueworkspace')
        user2_data = self.testdata.get_userdata_for(username2)
        user2_name = '{0} {1}'.format(user2_data.firstname,user2_data.lastname)

        username3,junk = \
            self.testdata.find_account_for('networkworkspace')
        user3_data = self.testdata.get_userdata_for(username3)
        user3_name = '{0} {1}'.format(user3_data.firstname,user3_data.lastname)

        self.po.share.share_session_with([username2])
        self.po.share.share_session_with([username3])

        shared_with_2 = self.po.share.get_shared_with()

        assert len(shared_with_1)+2 == len(shared_with_2), \
            "after sharing the session, wrong # users listed: " \
            + "before: %s, after: %s" % (shared_with_1,shared_with_2)

        assert user2_name in shared_with_2, \
            "after sharing session with %s, user %s" % (username2,user2_name) \
            + " does not show up in shared with list: %s" % (shared_with_2)

        assert user3_name in shared_with_2, \
            "after sharing session with %s, user %s" % (username3,user3_name) \
            + " does not show up in shared with list: %s" % (shared_with_2)


    def test_disconnect_1(self):
        """
        test disconnecting a connected user from a tool session container
        """

        shared_with_1 = self.po.share.get_shared_with()

        username2,junk = \
            self.testdata.find_account_for('purdueworkspace')
        user2_data = self.testdata.get_userdata_for(username2)
        user2_name = '{0} {1}'.format(user2_data.firstname,user2_data.lastname)

        # share the session with someone
        self.po.share.share_session_with(username2)

        shared_with_2 = self.po.share.get_shared_with()

        assert user2_name in shared_with_2, \
            "after sharing session with %s, user does" % (username2) \
            + " not show up in shared with list %s" % (shared_with_2)

        # disconnect user from session
        self.po.share.disconnect(username2)

        # check that user was disconnected
        shared_with_3 = self.po.share.get_shared_with()

        assert user2_name not in shared_with_3, \
            "after unsharing session with %s, user %s" \
            % (username2, user2_name) \
            + " still shows up in shared with list: %s" \
            % (shared_with_3)
class TestToolSessionApp(TestCase2):

    def setup_method(self,method):

        # start up a tool session container
        self.hubname = self.testdata.find_url_for('https')
        self.username,self.userpass = \
            self.testdata.find_account_for('registeredworkspace')

        self.cm = ContainerManager()
        self.ws = self.cm.access(host=self.hubname,
                                 username=self.username,
                                 password=self.userpass)

        self.session_number,es = self.ws.execute('echo $SESSION')
        self.ws.close()

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

        self.utils.account.login_as(self.username,self.userpass)

        self.po = self.catalog.load_pageobject('ToolSessionPage',
                    'workspace',int(self.session_number))
        self.po.goto_page()


    def teardown_method(self,method):

        # get out of the workspace
        # shut down the ssh connection
        self.cm.sync_open_sessions(self.hubname,self.username)


    def test_terminate_container(self):
        """
        test pressing the terminate button on the app
        """

        # press the terminate button
        self.po.app.do_terminate()

        # check that the container terminated
        po = self.catalog.load_pageobject('MembersDashboardPage')
        po.goto_page()
        open_sessions = po.modules.my_sessions.get_session_numbers()

        assert int(self.session_number) not in open_sessions,\
            "after terminating session %s," % (self.session_number) \
            + " session still listed as open in my_sessions module"


    def test_keep_container(self):
        """
        test pressing the keep button on the app
        """

        # press the keep button
        self.po.app.do_keep()

        # check that the container is still open
        po = self.catalog.load_pageobject('MembersDashboardPage')
        po.goto_page()
        open_sessions = po.modules.my_sessions.get_session_numbers()

        assert int(self.session_number) in open_sessions,\
            "after keeping session %s," % (self.session_number) \
            + " session not listed as open in my_sessions module"


#    def test_popout_container(self):
#        """
#        test pressing the popout button on the app to popout the app
#        """
#
#        browser = self.browser._browser
#
#        # get current window info
#        url1 = browser.current_url
#        current_window = browser.current_window_handle
#
#        # press the popout button
#        self.po.app.do_popout()
#
#        # find the popup window
#        other_window = None
#        for w in browser.window_handles:
#            if w != current_window:
#                other_window = w
#
#        assert other_window is not None, \
#            "after pressing the popout button, no window popped out"
#
#
#    def test_popout_container_close(self):
#        """
#        test closing the popped out app does not end the session
#        """
#
#        browser = self.browser._browser
#
#        # get current window info
#        url1 = browser.current_url
#        current_window = browser.current_window_handle
#
#        # press the popout button
#        self.po.app.do_popout()
#
#        # find the popup window
#        other_window = None
#        for w in browser.window_handles:
#            if w != current_window:
#                other_window = w
#
#        assert other_window is not None, \
#            "after pressing the popout button, no window popped out"
#
#        # switch to the popup window
#        browser.switch_to_window(other_window)
#
#        # close the popup window
#        browser.close()
#        browser.switch_to_window(current_window)
#
#        # check that the container is still open
#        po = self.catalog.load_pageobject('MembersDashboardPage')
#        po.goto_page()
#        open_sessions = po.modules.my_sessions.get_session_numbers()
#
#        assert int(self.session_number) in open_sessions,\
#            "after closing popped out app," \
#            + " session %s not listed as open in my_sessions module" \
#            % (self.session_number)
#
#
#    def test_popout_container_popin(self):
#        """
#        test popping-in a popped out app
#        """
#
#        browser = self.browser._browser
#
#        # get current window info
#        url1 = browser.current_url
#        current_window = browser.current_window_handle
#
#        # press the popout button
#        self.po.app.do_popout()
#
#        # find the popup window
#        other_window = None
#        for w in browser.window_handles:
#            if w != current_window:
#                other_window = w
#
#        assert other_window is not None, \
#            "after pressing the popout button, no window popped out"
#
#        # pop the container back in the browser
#        self.po.app.do_popout()
#
#        # make sure the popped-out window closes
#        other_window = None
#        for w in browser.window_handles:
#            if w != current_window:
#                other_window = w
#
#        assert other_window is None, \
#            "after pressing the 'pop in' button," \
#            + " the popped out window still exists"
#
#        # check that the container is still open
#        po = self.catalog.load_pageobject('MembersDashboardPage')
#        po.goto_page()
#        open_sessions = po.modules.my_sessions.get_session_numbers()
#
#        assert int(self.session_number) in open_sessions,\
#            "after popping in the tool session container app," \
#            + " session %s not listed as open in my_sessions module" \
#            % (self.session_number)


    @hubcheck.utils.hub_version(min_version='1.1.2')
    @pytest.mark.user_storage
    def test_storage_meter(self):
        """
        retrieve the free storage amount
        """

        storage_amount = self.po.app.storage.storage_meter()

        assert storage_amount != '', \
            "invalid storage amount returned: %s" % (storage_amount)

        assert storage_amount != '0% of 0GB', \
            "user quotas not activated: storage_amount = %s" % (storage_amount)
Ejemplo n.º 22
0
class TestHCUnitContainerManager(object):

    def test_get_buffer_3(self,ssh_shell):
        """check for empty buffer after retrieving prompt
        """

        p = ssh_shell.get_prompt()
        buf = ssh_shell.get_buffer()
        assert buf == '', "buf = '%s', expected ''" % (buf)



    def setUp(self):

        self.cm = ContainerManager()

        self.host1 = ''
        self.user11 = ''
        self.pass11 = ''
        self.user12 = ''
        self.pass12 = ''

        self.host2 = ''
        self.user21 = ''
        self.pass21 = ''
        self.user22 = ''
        self.pass22 = ''

    def tearDown(self):

        self.cm.stop_all()
        self.cm.clear()


    def test_access_new_session(self,cm):
        """
        """

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


    def test_access_previously_opened_session(self):
        """
        """

        # open the first tool session container
        ws1 = self.cm.access(self.host1,self.user11,self.pass11)
        session_number1,es = ws1.execute('echo $SESSION')
        # exit the container
        ws1.close()

        # make sure we got into the container
        self.assertTrue(int(session_number1) > 0,
            "session_number = %s, i don't think we are in a workspace" \
            % session_number1)

        # open the second tool session container
        ws2 = self.cm.access(self.host1,self.user11,self.pass11)
        session_number2,es = ws2.execute('echo $SESSION')
        ws2.close()

        # make sure we got into the second container
        self.assertTrue(int(session_number2) > 0,
            "session_number = %s, i don't think we are in a workspace" \
            % session_number2)

        # check that the first and second containers were the same
        # by comparing the session number

        self.assertTrue(int(session_number1) == int(session_number2),
            "connecting twice to the same session failed: session_number1 = %s, session_number2 = %s" \
            % (session_number1,session_number2))


    def test_access_sessions_for_different_users_same_host(self):
        """
        """

        # open tool session container for user1
        ws1 = self.cm.access(self.host1,self.user11,self.pass11)
        session_number1,es = ws1.execute('echo $SESSION')
        # exit the container
        ws1.close()

        # make sure we got into the container
        self.assertTrue(int(session_number1) > 0,
            "session_number = %s, i don't think we are in a workspace" \
            % session_number1)

        # open tool session container for user2
        ws2 = self.cm.access(self.host1,self.user12,self.pass12)
        session_number2,es = ws2.execute('echo $SESSION')
        ws2.close()

        # make sure we got into the second container
        self.assertTrue(int(session_number2) > 0,
            "session_number = %s, i don't think we are in a workspace" \
            % session_number2)

        # check that the first and second containers are different
        # by comparing the session number

        self.assertTrue(int(session_number1) != int(session_number2),
            "trying to connect to two different containers, as different users failed: session_number1 = %s, session_number2 = %s" \
            % (session_number1,session_number2))


    def test_access_sessions_for_different_users_different_host(self):
        """
        """

        # open tool session container for user1
        ws1 = self.cm.access(self.host1,self.user11,self.pass11)
        session_number1,es = ws1.execute('echo $SESSION')
        # exit the container
        ws1.close()

        # make sure we got into the container
        self.assertTrue(int(session_number1) > 0,
            "session_number = %s, i don't think we are in a workspace" \
            % session_number1)

        # open tool session container for user2
        ws2 = self.cm.access(self.host2,self.user21,self.pass21)
        session_number2,es = ws2.execute('echo $SESSION')
        ws2.close()

        # make sure we got into the second container
        self.assertTrue(int(session_number2) > 0,
            "session_number = %s, i don't think we are in a workspace" \
            % session_number2)

        # check that the first and second containers are different
        # by comparing the session number

        self.assertTrue(int(session_number1) != int(session_number2),
            "trying to connect to two different containers, as different users failed: session_number1 = %s, session_number2 = %s" \
            % (session_number1,session_number2))


    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))


    def test_stop_session_2(self):
        """
        try to close a session that is not open
        """

        # open a temporary session
        # so we can get a session in the stop() method
        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()


        try:
            # stop the tool session container
            session_number2 = 1234
            self.cm.stop(self.host1,self.user11,session_number2)
        finally:
            # close the temporary session
            self.cm.stop(self.host1,self.user11,session_number1)
Ejemplo n.º 23
0
    def upload_code(self, toolname, data, username, userpass, msg):
        """
        upload source code into the source code repository

        data is a dictionary that links files on the local file system
        to a path relative to the checked out svn repository.

        example:
        data = {
            '/home/hubzero/testuser/main.c'      : 'src/main.c',
            '/home/hubzero/testuser/Makefile'    : 'src/Makefile',
            '/home/hubzero/testuser/tool.xml'    : 'rappture/tool.xml',
        }
        """

        self.logger.info("uploading source code for the tool '%s'" % (toolname))

        repo_url = self.repo_url_template % {"hubname": self.hubname, "toolname": toolname}

        # ssh into a tool session container
        cm = ContainerManager()
        ws = cm.access(host=self.hubname, username=username, password=userpass)

        svn = Subversion(ws, username, userpass)

        session_number = -1
        repo_home = None
        try:
            session_number, es = ws.execute("echo $SESSION")
            if session_number <= 0:
                raise RuntimeError("invalid session number: %s" % (session_number))

            # create a temp directory to hold the repo
            repo_home, es = ws.execute("mktemp -d --tmpdir=`pwd` -t tmp.XXXXXXXX")
            ws.execute("cd %s" % (repo_home))

            # do the checkout
            svn.checkout(repo_url, toolname)

            # cd into the repo
            ws.execute("cd %s" % (toolname))
            tool_repo, es = ws.execute("pwd")

            # add some code
            commit_files = []
            for localpath, remotepath in data.items():
                commit_files.append(remotepath)
                remotepath = os.path.join(tool_repo, remotepath)
                ws.importfile(localpath, remotepath)

            # commit the source code repository
            svn.add(commit_files)
            revision = svn.commit("initial upload of source code")
            if revision is None:
                raise RuntimeError("commit failure, revision is None")

        finally:
            # FIXME: remove the temp directory
            ws.send_raw("")
            ws.send_raw("")
            time.sleep(5)
            if repo_home is not None:
                ws.execute("rm -rf %s" % (repo_home))

            # shut down the ssh connection
            ws.close()
Ejemplo n.º 24
0
    def update(self, toolname, username, userpass):
        """
        update the svn repository with a change so the tool can be installed

        in this case we update the invoke script because all
        tools should have one. we change a predetermined line
        starting with '# hc contribtool update: DATE'
        Where the term DATE is replaced with a date time stamp
        """

        self.logger.info("updating svn repository for the tool '%s'" % (toolname))

        repo_url = self.repo_url_template % {"hubname": self.hubname, "toolname": toolname}

        # ssh into a tool session container
        cm = ContainerManager()
        ws = cm.access(host=self.hubname, username=username, password=userpass)

        svn = Subversion(ws, username, userpass)

        session_number = -1
        repo_home = None
        try:
            session_number, es = ws.execute("echo $SESSION")
            if session_number <= 0:
                raise RuntimeError("invalid session number: %s" % (session_number))

            # create a temp directory to hold the repo
            repo_home, es = ws.execute("mktemp -d --tmpdir=`pwd` -t tmp.XXXXXXXX")
            ws.execute("cd %s" % (repo_home))

            # do the checkout
            svn.checkout(repo_url, toolname)

            # cd into the repo
            ws.execute("cd %s" % (toolname))
            tool_repo, es = ws.execute("pwd")

            # add the marker to the invoke script if it does not exist
            script_path = "middleware/invoke"
            script_data = ws.read_file(script_path)
            if re.search(self.update_marker, script_data) is None:
                # file doesn't have the marker, add it
                script_data += "\n%sDATE" % (self.update_marker)

            # update the marker with the current date time stamp
            dts = datetime.datetime.today().strftime("%Y%m%d%H%M%S")
            pattern = self.update_marker + ".*"
            replace = self.update_marker + dts
            script_data = re.sub(pattern, replace, script_data)

            # write the change back to the disk
            ws.write_file(script_path, script_data)

            # commit the changed file back to the source code repository
            revision = svn.commit("updating the invoke script")
            if revision is None:
                raise RuntimeError("commit failure, revision is None")

        finally:
            # FIXME: remove the temp directory
            ws.send_raw("")
            ws.send_raw("")
            time.sleep(5)
            if repo_home is not None:
                ws.execute("rm -rf %s" % (repo_home))

            # shut down the ssh connection
            ws.close()

        # navigate to the tool status page
        po = self.catalog.load_pageobject("ToolsStatusInstalledPage", toolname)
        po.goto_page()

        # on web page, mark project as updated
        po.flip_status_to_updated()

        self.__wait_for_tool_state(po, "Updated")
Ejemplo n.º 25
0
    def compile_code(self, toolname, adminuser, adminpass):
        """
        ssh into a tool session container as a tool manager,
        compile a tool's source code, and install the binaries
        """

        # ssh into a tool session container as the tools manager
        # compile and install the code

        # get into a tool session container.
        cm = ContainerManager()
        ws = cm.access(host=self.hubname, username=adminuser, password=adminpass)

        session_number, es = ws.execute("echo $SESSION")

        # catch errors that happen in the shell
        # so we can properly exit and close the workspace
        try:
            # become the apps user
            ws.send("sudo su - apps")
            ws.start_bash_shell()
            output, es = ws.execute("whoami")
            exit_apps = True
            if output != "apps":
                exit_apps = False
                msg = "doesn't look like we were able to become the apps user"
                self.logger.error(msg)
                raise Exception(msg)

            # catch compile and install errors
            # so we can report them back to the developer

            # navigate to the tool directory
            cmd = "cd /apps/%(toolname)s/dev/src" % {"toolname": toolname}
            ws.execute(cmd)

            # if there is a makefile available
            # run:
            # make clean
            # make all
            # make install
            # don't fail if there is no clean or all targets
            if ws.bash_test("-e Makefile"):
                # allow 30 minutes for the code to compile
                ws.timeout = 1800
                output, es = ws.execute("make clean", False)
                output, es = ws.execute("make all", False)
                no_make_all_text = "make: *** No rule to make target `all'.  Stop."
                if es > 0:
                    if es == 2 and output == no_make_all_text:
                        output, es = ws.execute("make")
                    else:
                        self.logger.exception(output)
                        raise ExitCodeError(output)
                output, es = ws.execute("make install")
                ws.timeout = 10
            else:
                msg = "No Makefile found"
                print msg
                self.logger.info(msg)

        finally:
            # exit sudo
            ws.stop_bash_shell()
            if exit_apps:
                ws.send("exit")

            # shut down the ssh connection
            ws.close()
class members_dashboard_my_session_item_2(TestCase):

    def setUp(self):

        # start up a tool session container
        self.hubname = self.testdata.find_url_for('https')
        self.username,self.userpass = \
            self.testdata.find_account_for('purdueworkspace')

        self.cm = ContainerManager()
        self.ws = self.cm.create(host=self.hubname,
                                 username=self.username,
                                 password=self.userpass)

        self.session_number,es = self.ws.execute('echo $SESSION')
        self.session_number = int(self.session_number)

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

        self.utils.account.login_as(self.username,self.userpass)

        self.po = self.catalog.load_pageobject('GenericPage')
        self.po.header.goto_myaccount()

        self.po = self.catalog.load_pageobject('MembersDashboardPage')

        self.my_sessions_module = self.po.modules.my_sessions


    def tearDown(self):

        # get out of the workspace
        # shut down the ssh connection
        self.ws.close()
        # resync our session data because in the test,
        # we attempted to close a session being tracked by cm
        self.cm.sync_open_sessions(self.hubname,self.username)


    @hubcheck.utils.hub_version(min_version='1.1.4')
    def test_terminate_click_accept(self):
        """
        click the terminate session link and accept the confirmation
        """

        pageurl1 = self.po.current_url()
        num_sessions_1 = self.my_sessions_module.count_sessions()

        session_item = self.my_sessions_module.get_session_by_session_number(
                        self.session_number)

        self.assertTrue(session_item is not None,
            'No session exists for session numbered: %s'
            % (self.session_number))

        # open the slide down window
        if not session_item.is_slide_open():
            session_item.toggle_slide()

        session_item.terminate_session(confirm=True)

        self.my_sessions_module = self.po.modules.my_sessions
        session_numbers = self.my_sessions_module.get_session_numbers()

        self.assertTrue(self.session_number not in session_numbers,
            "after confirming the termination of a session"
            + " the session %d still appears in the list of open sessions"
            % (self.session_number))
class TestIcewmUserConfig(TestCase2):

    def setup_method(self,method):

        # get user account info
        self.username,self.userpass = \
            self.testdata.find_account_for('registeredworkspace')
        self.hubname = self.testdata.find_url_for('https')

        # get into a workspace
        self.cm = ContainerManager()
        self.ws = self.cm.access(host=self.hubname,
                                 username=self.username,
                                 password=self.userpass)


    def teardown_method(self,method):
        pass


    def _check_icewm_config_file(self,fname,points_to):

        # check the file is a link
        assert self.ws.bash_test('-L {0}'.format(fname)), \
            '"{0}" not a link'.format(fname)

        # check the file points to default config
        command = 'readlink -e {0}'.format(fname)
        output,es = self.ws.execute(command)
        assert output == points_to, \
            '"{0}" points to "{1}", expected "{2}"'.format(fname,output,points_to)

        # check the default config is readable
        assert self.ws.bash_test('-r {0}'.format(points_to)), \
            '"{0}" not a readable'.format(points_to)


    def test_icewm_config(self):
        """
        check icewm config files point to hubzero config
        """

        # check if the icewm directory was created.
        msg = "User's IceWM config directory (~/.icewm) was not recreated" + \
              " by new workspace after being deleted"
        assert self.ws.bash_test('-d {0}'.format(ICEWM_CONF_DIR)), msg

        msg = "User's IceWM config directory (~/.icewm) is not readable" + \
              " by new workspace after being deleted"
        assert self.ws.bash_test('-r {0}'.format(ICEWM_CONF_DIR)), msg


        # check if the user has the default icewm user config for hubzero

        for (fname,points_to) in ICEWM_CONF_FILE_SPEC:
            self._check_icewm_config_file(fname,points_to)


    def test_updated_icewm_config(self):
        """
        check if starting a workspace created a new icewm config directory
        after the user deleted their original one.
        """

        # remove the user's icewm config dir
        self.ws.execute('rm -rf ~/.icewm')

        session_number = 0

        # create a new workspace
        ws2 = self.cm.create(host=self.hubname,
                             username=self.username,
                             password=self.userpass)

        session_number,es = ws2.execute('echo $SESSION')

        # exit the new workspace
        ws2.close()

        # stop the new container
        self.cm.stop(self.hubname,self.username,int(session_number))


        # check if the icewm directory was created.
        msg = "User's IceWM config directory (~/.icewm) was not recreated" + \
              " by new workspace after being deleted"
        assert self.ws.bash_test('-d {0}'.format(ICEWM_CONF_DIR)), msg

        msg = "User's IceWM config directory (~/.icewm) is not readable" + \
              " by new workspace after being deleted"
        assert self.ws.bash_test('-r {0}'.format(ICEWM_CONF_DIR)), msg


        # check if the user has the default icewm user config for hubzero

        for (fname,points_to) in ICEWM_CONF_FILE_SPEC:
            self._check_icewm_config_file(fname,points_to)