Skip to content

Commit

Permalink
Merge pull request #3 from trianglesis/development_test
Browse files Browse the repository at this point in the history
Some refactoring and tests
  • Loading branch information
trianglesis authored Oct 2, 2017
2 parents f6514b9 + 5f20887 commit bbd32b6
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 556 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ bmc_tplpre/check/__pycache__/
bmc_tplpre/tplint/
bmc_tplpre/taxonomy/
bmc_tplpre/DEV_TEST/
bmc_tplpre/.idea/
bmc_tplpre/.idea/
*.pyc
390 changes: 190 additions & 200 deletions bmc_tplpre/check.py

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import logging
log = logging.getLogger("check.logger")
log = logging.getLogger("check_ide.logger")

"""
Collecting data after Discovery run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
"""

import os
from check.parse_args import ArgsParse
from check.preproc import Preproc
from check.imports import TPLimports
from check.test_queries import TestRead
from check.upload import AddmOperations
from check.syntax_checker import SyntaxCheck
from check.local_logic import LocalLogic
from check.scan import AddmScan
from check_ide.parse_args import ArgsParse
from check_ide.preproc import Preproc
from check_ide.imports import TPLimports
from check_ide.test_queries import TestRead
from check_ide.upload import AddmOperations
from check_ide.syntax_checker import SyntaxCheck
from check_ide.local_logic import LocalLogic
from check_ide.scan import AddmScan
# import json
# from pprint import pformat

import logging
log = logging.getLogger("check.logger")
log = logging.getLogger("check_ide.logger")


class GlobalLogic:
Expand All @@ -27,8 +27,12 @@ def __init__(self, extra_args, known_args):
"""
Initialize with options for logical operations.
Check arg sets and output messages for different option scenarios.
:return: func
"""
# print(extra_args)
# print(type(known_args))
# print(known_args)

# FULL PATH ARGS:
self.tku_patterns_t = ''
Expand Down Expand Up @@ -228,7 +232,7 @@ def __init__(self, extra_args, known_args):
if self.oper_args['imports']:
'''
Set of args dedicated for imports logic.
WIll check mode here and compose boolean logic.
WIll check_ide mode here and compose boolean logic.
'''
imports = self.oper_args['imports']

Expand All @@ -250,7 +254,7 @@ def __init__(self, extra_args, known_args):
if self.oper_args['tests']:
'''
Set of args dedicated for test execution logic.
WIll check mode here and compose boolean logic.
WIll check_ide mode here and compose boolean logic.
'''
tests = self.oper_args['tests']

Expand All @@ -271,7 +275,7 @@ def __init__(self, extra_args, known_args):
if self.oper_args['tku_oper']:
'''
Set of args dedicated for ADDM management execution logic.
WIll check mode here and compose boolean logic.
WIll check_ide mode here and compose boolean logic.
'''
tku_oper = self.oper_args['tku_oper']

Expand All @@ -288,7 +292,7 @@ def __init__(self, extra_args, known_args):
@staticmethod
def check_args_set(**args_from_cmd):
"""
This will check args set in input.
This will check_ide args set in input.
Based on set of args - it will compose another set of functions.
The set of functions will consist of all needed functions on order to execute.
Expand All @@ -297,26 +301,26 @@ def check_args_set(**args_from_cmd):
-- 1. Imports_(for all from current pattern + all recursive patterns),
2. TPLPreproc_(for all in imports folder),
3. SyntaxCheck_(for all in imports folder), -- This probably will be removed later with AST
4. AskADDM_(ADDM SSH connection - check supported tpl, working folder, save SSH session)
4. AskADDM_(ADDM SSH connection - check_ide supported tpl, working folder, save SSH session)
5. UploadPatterns_ (zip patterns for correspond tpl ver from ADDM - upload-activate)
6. StartScan_(start Discovery with options)
7. CheckScan_(Check when scan is finished and successful)
8. RunQuery_(Run Search SoftwareInstance or so and output result)
9. SaveResults_(save model file for SI and Query file for queries with results)
10. ...
- for tpl usage (without Preproc or Syntax):
-- 1. AskADDM_(ADDM SSH connection - check supported tpl, working folder, save SSH session)
-- 1. AskADDM_(ADDM SSH connection - check_ide supported tpl, working folder, save SSH session)
2. UploadPatterns_ (zip patterns for correspond tpl ver from ADDM - upload-activate)
3. StartScan_(start Discovery with options)
4. CheckScan_(Check when scan is finished and successful)
5. RunQuery_(Run Search SoftwareInstance or so and output result)
6. SaveResults_(save model file for SI and Query file for queries with results)
7. ...
- for test.py (or something like that) if will be added:
-- 1. AskADDM_(ADDM SSH connection - check supported tpl, working folder, save SSH session)
-- 1. AskADDM_(ADDM SSH connection - check_ide supported tpl, working folder, save SSH session)
2. StartTH_(start TestHarness in tku_patterns folder and output results)
3. ExecuteTest_(run test with set of options you send)
4. ValidateTests_(check something you need to)
4. ValidateTests_(check_ide something you need to)
5. This section not even planned yet, can be changed.
:param args_from_cmd: set
Expand All @@ -327,7 +331,7 @@ def check_args_set(**args_from_cmd):
return parse_args.gather_args(known_args=args_from_cmd['known_args'],
extra_args=args_from_cmd['extra_args'])

def make_function_set(self) -> object:
def make_function_set(self):
"""
Output:
conditional_functions =
Expand Down Expand Up @@ -463,7 +467,7 @@ def cond_args(self):
- Import patterns if needed on mode set in import_cond
- Run preproc on patterns based on conditional arguments:
- Run syntax check based on cond args:
- Run syntax check_ide based on cond args:
- Generate addm working dir based on DEV condition:
- Zipping files in working dir and compose possible path to this zip in ADDM to upload or activate.
- If you want to wipe all TKU before:
Expand Down Expand Up @@ -495,11 +499,11 @@ def cond_args(self):
elif local_proceed_for_addm:
"""
When there is an active SSH connection to ADDM but no scan and host list options -
Make version check and zip patterns for current ADDM version.
Make version check_ide and zip patterns for current ADDM version.
- Import patterns if needed on mode set in import_cond
- Run preproc on patterns based on conditional arguments:
- Run syntax check based on cond args:
- Run syntax check_ide based on cond args:
- Zipping files in working dir and compose possible path to this zip in ADDM to upload or activate.
- tpl_vers addm_prod addm_ver
Expand All @@ -523,7 +527,7 @@ def cond_args(self):
- Import patterns if needed on mode set in import_cond
- Run preproc on patterns based on conditional arguments:
- Run syntax check based on cond args:
- Run syntax check_ide based on cond args:
- Generate addm working dir based on DEV condition:
- Zipping files in working dir and compose possible path to this zip in ADDM to upload or activate.
- If you want to wipe all TKU before:
Expand Down Expand Up @@ -555,12 +559,12 @@ def cond_args(self):
elif import_preproc_syntax_local:
"""
I have no active connection to ADDM so I don't know about tpl version to generate and zip
- SO I will just import, Preproc and check syntax
- SO I will just import, Preproc and check_ide syntax
- Import patterns if needed on mode set in import_cond
- Run preproc on patterns based on conditional arguments:
- Run syntax check based on cond args:
- Run syntax check_ide based on cond args:
- Maybe I can add tpl_version for offline checks but what for?
"""
log.info("Local processing, no ADDM connection.")
Expand Down Expand Up @@ -779,11 +783,11 @@ def preproc_cond(self):
else:
log.debug("This 'self.env_cond' is not operable: "+str(self.env_cond))

def syntax_cond(self, **logical_conditions):
def syntax_cond(self, tpl_version):
"""
Run syntax with options based on conditional arguments.
If ADDM did not return any version - syntax check will run for all available versions.
If ADDM did not return any version - syntax check_ide will run for all available versions.
Optional: arg set of tpl version can be used here.
By default - results printed in raw mode. Further execution continues.
Expand All @@ -793,7 +797,6 @@ def syntax_cond(self, **logical_conditions):
"""

# Set examples in __init__ docstrings:
tpl_version = logical_conditions['tpl_version']
import_cond = self.import_cond

syntax_check_cond_f = False
Expand All @@ -804,21 +807,21 @@ def syntax_cond(self, **logical_conditions):
if self.usual_imports:
"""
- If no addm version -
it will use empty string as arg and run syntax check for all supported versions.
it will use empty string as arg and run syntax check_ide for all supported versions.
"""
log.info("Syntax check TPLPreprocessor result.")
log.debug("Syntax check will run on tpl folders after usual TPLPreproc output. (usual_imports)")
log.info("Syntax check_ide TPLPreprocessor result.")
log.debug("Syntax check_ide will run on tpl folders after usual TPLPreproc output. (usual_imports)")
syntax_check_cond_f = self.make_syntax_check(self.working_dir, disco_ver=tpl_version)

# Preproc will run on all files from folder 'imports'
elif self.recursive_imports or self.read_test:
"""
- After TPLPreprocessor finished its work - run Syntax Check on folder imports
- If no addm version -
it will use empty string as arg and run syntax check for all supported versions.
it will use empty string as arg and run syntax check_ide for all supported versions.
"""
log.info("Syntax check on imports.")
log.debug("Syntax check will run on imports folder after my importing logic. "
log.info("Syntax check_ide on imports.")
log.debug("Syntax check_ide will run on imports folder after my importing logic. "
"(recursive_imports or read_test)")
syntax_check_cond_f = self.make_syntax_check(self.working_dir+os.sep+"imports", disco_ver=tpl_version)

Expand All @@ -828,21 +831,21 @@ def syntax_cond(self, **logical_conditions):
# SOLO RUNS:
else:
"""
- If no addm version - it will use empty string as arg and run syntax check for all versions.
- In this condition syntax check will hope that imports are already in folder after previous runs.
- If no addm version - it will use empty string as arg and run syntax check_ide for all versions.
- In this condition syntax check_ide will hope that imports are already in folder after previous runs.
"""
if self.env_cond == 'developer_tplpre' or self.env_cond == 'developer_tpl':
log.info("1/1 Syntax check solo file.")
log.info("1/1 Syntax check_ide solo file.")
log.debug("1/2 Imports was already created just checking syntax for active pattern. "
"(not read_test not recursive_imports not usual_imports)")
syntax_check_cond_f = self.make_syntax_check(self.working_dir, disco_ver=tpl_version)

elif self.env_cond == 'customer_tku':

log.warning("TPLint cannot check syntax for single tpl file!"
"On other way it will check syntax for whole CORE "
log.warning("TPLint cannot check_ide syntax for single tpl file!"
"On other way it will check_ide syntax for whole CORE "
"folder and this can take too much time."
"To check syntax please choose usual imports option, "
"To check_ide syntax please choose usual imports option, "
"so TPLint will run it only for 'imports' folder!")

else:
Expand Down Expand Up @@ -924,7 +927,7 @@ def pattern_path_cond(self, addm_working_dir):
addm_zip_f = ''
path_to_file = ''

# Make addm dev vm check to false for condition when this is customer mode.
# Make addm dev vm check_ide to false for condition when this is customer mode.
if self.env_cond == 'customer_tku':
addm_vm = False
else:
Expand Down Expand Up @@ -1154,7 +1157,7 @@ def zip_activ_cond(self, **zipping_conditions):

def test_run_cond(self):
"""
This function gets self.tst_cond and check if this is dict.
This function gets self.tst_cond and check_ide if this is dict.
Then it run different scenarios.
[{
Expand Down Expand Up @@ -1278,15 +1281,15 @@ def pre_processing():
@staticmethod
def make_syntax_check(working_dir, disco_ver):
"""
Closure for syntax check function.
Closure for syntax check_ide function.
Run LOCAL syntax check procedure in selected folders or files.
Run LOCAL syntax check_ide procedure in selected folders or files.
Can run ONLY when imports from patter are also in the same folder.
Should be ignored in SOLO MODE.
:param working_dir: str - input dir where run syntax check
:param disco_ver: str - version of discover engine to use for check, if empty - run all.
:return: func - syntax check with args in it.
:param working_dir: str - input dir where run syntax check_ide
:param disco_ver: str - version of discover engine to use for check_ide, if empty - run all.
:return: func - syntax check_ide with args in it.
"""

def syntax_check():
Expand Down
Loading

0 comments on commit bbd32b6

Please sign in to comment.