Exemple #1
0
def parameterizeOne(image_name, logger):
    labutils.logger = logger
    start_config, comp_name, labname, lab_path = getStartConfig(
        image_name, logger)
    running = labutils.GetContainerId(image_name)
    logger.debug('running is %s  ' % running)
    email_addr = labutils.getLastEmail()
    if email_addr is None:
        logger.error('Missing labtainer email address')
        ''' TBD dialog?  Tell user how to add it '''
        return

    cwd = os.getcwd()
    logger.debug('parameterizeOne in %s need to be in %s' % (cwd, student_dir))
    os.chdir(student_dir)
    for name, container in start_config.containers.items():
        if name == comp_name:
            logger.debug('found match container name %s' % name)
            labutils.ParamForStudent(start_config.lab_master_seed,
                                     container.full_name,
                                     container.user,
                                     container.password,
                                     labname,
                                     email_addr,
                                     lab_path,
                                     name,
                                     None,
                                     running_container=running)
            os.chdir(cwd)
            return
    os.chdir(cwd)
Exemple #2
0
def parameterizeOne(image_name, logger):
    labutils.logger = logger
    start_config, comp_name, labname, lab_path = getStartConfig(
        image_name, logger)
    running = labutils.GetContainerId(image_name)
    logger.debug('running is %s  ' % running)
    email_addr = labutils.getLastEmail()
    if email_addr is None:
        logger.error('Missing labtainer email address')
        ''' TBD dialog?  Tell user how to add it '''
        return

    cwd = os.getcwd()
    logger.debug('parameterizeOne in %s need to be in %s' % (cwd, student_dir))
    os.chdir(student_dir)
    for name, container in start_config.containers.items():
        if name == comp_name:
            logger.debug('found match container name %s' % name)
            labutils.ParamForStudent(start_config.lab_master_seed,
                                     container.full_name,
                                     container.image_name,
                                     container.user,
                                     container.password,
                                     labname,
                                     email_addr,
                                     lab_path,
                                     name,
                                     None,
                                     running_container=running)
            os.chdir(cwd)
            if container.kick_me is not None:
                ''' gns3 cloud interfaces that share NICs get hung up after the first container shutdown.
                        For magical reasons, pinging the container from the VM wakes it up. '''
                for subnet in container.container_nets:
                    if container.kick_me in container.container_nets:
                        ip = container.container_nets[container.kick_me]
                        cmd = 'ping -c 1 %s' % ip
                        os.system(cmd)
                        logger.info('kicked with %s' % cmd)
                    else:
                        logger.debug('kickme %s not found for %s' %
                                     (container.kick_me, name))
            break
    os.chdir(cwd)
 def checkLab(self, lab, test_registry, remove_lab):
     FAILURE=1
     retval = True
     xfer_dir = os.path.join(os.getenv('HOME'), self.labtainer_config.host_home_xfer, lab)
     self.logger.debug('checkLab xfer is %s' % xfer_dir)
     shutil.rmtree(xfer_dir, ignore_errors=True)
     os.mkdir(xfer_dir)
     test_flag = ''
     if test_registry:
         test_flag = '-t'
     cmd = 'labtainer %s -q -r %s' % (lab, test_flag)
     result = subprocess.call(cmd, shell=True, stderr=self.outfile, stdout=self.outfile)
     self.logger.debug('result is %d' % result)
     self.simlab = None
     if result == FAILURE:
         retval = False
     else:
         self.simlab = SimLab.SimLab(lab, verbose_level=self.verbose_level, logger=self.logger)
         if self.simlab.hasSim():
             self.logger.debug('now call simLab')
             self.simlab.simThis()
     cmd = 'stoplab %s' % lab
     ps = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
     output = ps.communicate()
     self.logger.debug('stoplab output %s' % output[0].decode('utf-8'))
     email = labutils.getLastEmail()
     if email is not None:
         email = email.replace("@","_at_")
     if len(output[1]) > 0:
         print('%s' % output[0].decode('utf-8'))
         print('%s' % output[1].decode('utf-8'))
         retval = False
     if retval and self.simlab.hasSim():
         here = os.getcwd() 
         os.chdir('../labtainer-instructor')
         cmd = 'gradelab %s -r' % lab
         result = subprocess.call(cmd, shell=True, stderr=self.outfile, stdout=self.outfile)
         if result == FAILURE:
             retval = False
         self.logger.debug('instructor start result is %d' % result)
         '''
         self.simlab.searchWindows('GOAL_RESULTS')
         cmd = 'stoplab %s' % lab
         result = subprocess.call(cmd, shell=True, stderr=self.outfile, stdout=self.outfile)
         if result == FAILURE:
             retval = False
         self.logger.debug('instructor stop result is %d' % result)
         '''
         if retval:
             expected = self.simlab.getExpectedPath()
             if os.path.isdir(expected):
                 fname = '%s.grades.txt' % lab
                 new = os.path.join(xfer_dir, fname)
                 old = os.path.join(expected, fname)
                 if os.path.isfile(old):
                     if self.cmpStudent(new, old, email):
                         print('%s matches %s' % (new, old))        
                     else:
                         print('%s DOES NOT MATCH %s' % (new, old))        
                         retval = False
                 else:
                     print('no expected results for %s' % lab)
         os.chdir(here)
     if retval and remove_lab:
         cmd = 'removelab.py %s' % lab
         result = subprocess.call(cmd, shell=True, stderr=self.outfile, stdout=self.outfile)
         self.logger.debug('removelab %s result %d' % (lab, result))
         
     print('do check_nets')       
     if not check_nets.checkNets():
         retval = False
         self.logger.error('check_net error')
    
     return retval
Exemple #4
0
    def checkLab(self, lab, test_registry, remove_lab):
        FAILURE = 1
        now = datetime.datetime.now()
        dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
        print('smoketest start lab %s at %s' % (lab, dt_string))
        retval = True
        xfer_dir = os.path.join(os.getenv('HOME'),
                                self.labtainer_config.host_home_xfer, lab)
        self.logger.debug('checkLab xfer is %s' % xfer_dir)
        shutil.rmtree(xfer_dir, ignore_errors=True)
        os.mkdir(xfer_dir)
        test_flag = ''
        if test_registry:
            test_flag = '-t'
        ''' synch to know when labtainers is running and ready '''
        syncdir = os.path.join(os.getenv('LABTAINER_DIR'), 'scripts',
                               'labtainer-student', '.tmp', lab, 'sync')
        try:
            os.rmdir(syncdir)
        except:
            pass
        cmd = 'labtainer %s -q -r %s' % (lab, test_flag)
        result = subprocess.call(cmd,
                                 shell=True,
                                 stderr=self.outfile,
                                 stdout=self.outfile)
        self.logger.debug('result is %d' % result)
        while not os.path.isdir(syncdir):
            self.logger.debug(
                'synch not found, wait for labtainers to be ready.')
            print('synch %s not found, wait for labtainers to be ready.' %
                  syncdir)
            time.sleep(1)
        self.simlab = None
        if result == FAILURE:
            retval = False
        else:
            self.simlab = SimLab.SimLab(lab,
                                        verbose_level=self.verbose_level,
                                        logger=self.logger)
            if self.simlab.hasSim():
                self.logger.debug('now call simLab')
                self.simlab.simThis()
        cmd = 'stoplab %s' % lab
        ps = subprocess.Popen(cmd,
                              shell=True,
                              stderr=subprocess.PIPE,
                              stdout=subprocess.PIPE)
        output = ps.communicate()
        self.logger.debug('stoplab output %s' % output[0].decode('utf-8'))
        email = labutils.getLastEmail()
        if email is not None:
            email = email.replace("@", "_at_")
        if len(output[1]) > 0:
            print('%s' % output[0].decode('utf-8'))
            print('%s' % output[1].decode('utf-8'))
            retval = False
        if retval and self.simlab.hasSim():
            here = os.getcwd()
            os.chdir('../labtainer-instructor')
            cmd = 'gradelab %s -r' % lab
            result = subprocess.call(cmd,
                                     shell=True,
                                     stderr=self.outfile,
                                     stdout=self.outfile)
            if result == FAILURE:
                retval = False
            self.logger.debug('instructor start result is %d' % result)
            '''
            self.simlab.searchWindows('GOAL_RESULTS')
            cmd = 'stoplab %s' % lab
            result = subprocess.call(cmd, shell=True, stderr=self.outfile, stdout=self.outfile)
            if result == FAILURE:
                retval = False
            self.logger.debug('instructor stop result is %d' % result)
            '''
            if retval:
                expected = self.simlab.getExpectedPath()
                if os.path.isdir(expected):
                    fname = '%s.grades.txt' % lab
                    new = os.path.join(xfer_dir, fname)
                    old = os.path.join(expected, fname)
                    if os.path.isfile(old):
                        if self.cmpStudent(new, old, email):
                            print('%s matches %s' % (new, old))
                        else:
                            print('%s DOES NOT MATCH %s' % (new, old))
                            retval = False
                    else:
                        print('no expected results for %s' % lab)
            os.chdir(here)
        if retval and remove_lab:
            cmd = 'removelab.py %s' % lab
            result = subprocess.call(cmd,
                                     shell=True,
                                     stderr=self.outfile,
                                     stdout=self.outfile)
            self.logger.debug('removelab %s result %d' % (lab, result))

        print('do check_nets')
        if not check_nets.checkNets(True):
            if not check_nets.checkNets(False):
                retval = False
                self.logger.error('check_net error')
            else:
                self.logger.debug('check_net fixed docker errors')

        return retval