Ejemplo n.º 1
0
def database_connection():
    cfg = utils.get_config()
    cfg.epepin_api_endpoint = os.environ.get('REQ_DB_ENDPOINT')
    if (cfg.epepin_api_endpoint is None):
        cfg.epepin_db_endpoint = cfg.epepin_db_endpoint
    db = database.Database(cfg.epepin_db_endpoint, cfg.epepin_db_port)
    current_app.logger.info('routes.database_connection database: ' + str(db))
    return db
Ejemplo n.º 2
0
    def syncro_MongoDB(self, authorization):
        cfg = utils.get_config()
        indir = os.getcwd() + os.sep + 'files'
        indir = indir.replace('epepin_api' + os.sep, '')
        try:
            os.stat(indir + os.sep + 'logs')
        except:
            os.mkdir(indir + os.sep + 'logs')
        try:
            mongo_db = self.database_connection()
            db_connection = mongo_db.connection()
            current_app.logger.info('Its connected to database.')
            current_app.logger.info('Directory files:' + str(indir))
        except Exception as ex:
            current_app.logger.error('Dont connected to database.')
            current_app.logger.error('Error:' + ex.message)
            pass

        try:
            self.syncro_users(mongo_db, db_connection, cfg, authorization)
        except Exception as ex:
            current_app.logger.error('Dont connected to openalm:' +
                                     str(cfg.epepin_users_openalm_url))
            current_app.logger.error('Error:' + ex.message)
            pass

        try:
            Jenkins.getInstance(mongo_db).jenkins_syncro()
        except Exception as ex:
            current_app.logger.error('Dont connected to jenkins:' +
                                     str(cfg.epepin_jenkins_url))
            current_app.logger.error('Error:' + ex.message)
            pass

        #Delete all requirements in Database
        mongo_db.delete_requirement_all(db_connection)
        numFiles = 0
        requirements_all = []
        logging.debug('dir files:' + str(indir))
        for root, dirs, filenames in os.walk(indir):
            for f in filenames:
                if f.endswith('.adoc'):
                    requirements_all.extend(
                        self.parse_adoc_file(mongo_db, db_connection, indir,
                                             indir + os.sep + f))
                    numFiles += 1
                elif f.endswith('.yaml'):
                    requirements_all.extend(
                        self.parse_adoc_file(mongo_db, db_connection, indir,
                                             indir + os.sep + f))
                    numFiles += 1

        current_app.logger.info(
            "Synchronization successfully. Files:" + str(numFiles) +
            " Requeriments:" +
            str(mongo_db.get_requirements(db_connection).count()))
Ejemplo n.º 3
0
def validate(data_json, schema_json):
    try:
        cfg = utils.get_config()
        schemas_folder = cfg.epepin_schemas_folder
        if type(data_json) is dict:
            data_json = json.dumps(data_json)
        jsonschema.validate(
            json.loads(data_json),
            json.loads(
                utils.get_file_content(schemas_folder + '/%s' % schema_json)))
    except jsonschema.ValidationError as e:
        raise ValidatorException(e.message)
    except jsonschema.SchemaError as e:
        raise ValidatorException(e.message)
    except Exception as e:
        raise ValidatorException(e.message)
Ejemplo n.º 4
0
    def database_connection(self):
        cfg = utils.get_config()
        epepin_db_endpoint = os.environ.get('REQ_DB_ENDPOINT')
        current_app.logger.info('REQ_DB_ENDPOINT:' + str(epepin_db_endpoint))
        if (epepin_db_endpoint is None):
            epepin_db_endpoint = cfg.epepin_db_endpoint

        db = None
        try:
            db = database.Database(epepin_db_endpoint, cfg.epepin_db_port)
            current_app.logger.info('Database:' + str(epepin_db_endpoint) +
                                    ':' + str(cfg.epepin_db_port))
        except Exception as ex:
            current_app.logger.error('Dont exist database:' +
                                     str(epepin_db_endpoint) + ':' +
                                     str(cfg.epepin_db_port))
            current_app.logger.error('Error:' + ex.message)
            pass
        return db
Ejemplo n.º 5
0
    def jenkins_syncro(self):
        current_app.logger.info('jenkins_syncro init b_execute:' + str(self.b_execute))
        if (not self.b_execute):
            self.b_execute=True
            cfg = utils.get_config()
            try:
                try:
                    self.db.delete_jenkins_tc_all(self.db_connection)
                except Exception as ex:
                    current_app.logger.error('Exception e:' + ex.message)
                    pass

                for value in cfg.epepin_jenkins_jobs:
                    try:
                        data = json.loads(urllib2.urlopen(urllib2.Request(cfg.epepin_jenkins_url.replace('$$JOB$$',value))).read())                 
                        #data = json.loads(urllib2.urlopen(urllib2.Request('https://147.214.113.90/job/JNB7__CDE-CBA__RegressionTest__OSC/api/json')).read())                    
                        for builds in data['builds']:
                            data2=json.loads(urllib2.urlopen(urllib2.Request(builds['url'] + 'testReport/api/json')).read())
                            for suites in data2['suites']:
                                for cases in suites['cases']:
                                    test_case = TestCase()
                                    test_case.setID(cases['className'] + '#' + cases['name'])
                                    test_case.set_test_suite(cases['className'])
                                    test_case.setName(cases['name'])
                                    test_case.setStatus(cases['status'])
                                    test_case.setTimestamp(datetime.datetime.now())
                                    self.jenkins_tc[test_case.getID()]= test_case
                                    self.db.insert_jenkins_tc(self.db_connection,test_case.toJSON())
                            break
                    except Exception as ex:
                        current_app.logger.error('Jenkins Exception e:' + ex.message)
                        pass
            except Exception as ex:
                current_app.logger.error('Jenkins Syncro Exception e:' + ex.message)
                self.b_execute=False
                pass
            self.last_execution=datetime.datetime.now()
            self.b_execute=False
        return
Ejemplo n.º 6
0
def login():
    status_code = CODE_POST_OK
    message = MSG_POST_OK
    token = None
    content = request.get_json()
    cfg = utils.get_config()
    try:
        data = {
            'username': content['username'],
            'password': content['password']
        }
        reqdata = urlencode(data)
        req = urllib2.Request(cfg.epepin_auth_url, reqdata)
        #response = urllib2.urlopen(req)
        token = jwt.encode(
            {
                'exp': datetime.utcnow() + timedelta(seconds=1800),
                'username':
                content['username'] + str(datetime.now().microsecond)
            },
            Authetication.get_key(),
            algorithm=Authetication.get_algorithm())

        #token = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
        Authetication.put_token(str(token))
        current_app.logger.info('%s logged in successfully',
                                content['username'])
    except jwt.ExpiredSignatureError as ex:
        status_code = '401'
        message = 'HTTP 401 Unauthorized. Expired Time.'
    except jwt.PyJWTError as exx:
        current_app.logger.info("\n User not logged in: " +
                                content['username'] + "\n. Exception:" +
                                exx.message)
    except EpepinException as ex:
        status_code = ex.get_status_code()
        message = ex.get_error_message()
    return Response.json_token(status_code, message, str(token))