Exemple #1
0
 def test_check_2(self, mock_path, mock_snapid, mock_logerror,
                  mock_compreply, mock_sqpath):
     mock_snapid.return_value = 'mock_pre', 'text'
     mock_sqpath.return_value = os.path.join(os.path.dirname(__file__),
                                             'configs')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_rpc_test.yml')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     self.db['check_from_sqlite'] = True
     self.db['first_snap_id'] = 0
     self.db['second_snap_id'] = 1
     comp = Comparator()
     comp.generate_test_files(main_file,
                              self.hostname,
                              self.chk,
                              self.diff,
                              self.db,
                              self.snap_del,
                              "mock_pre",
                              action="check")
     mock_logerror.assert_called()
     mock_compreply.assert_called()
Exemple #2
0
 def test_incorrect_test_format(self, mock_path, mock_info, mock_sys):
     def fun():
         raise BaseException
     mock_sys.return_value = fun
     self.chk = True
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_incorrect_4.yml')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     self.db['check_from_sqlite'] = True
     with patch('logging.Logger.error') as mock_log:
         try:
             comp.generate_test_files(
                 main_file,
                 self.hostname,
                 self.chk,
                 self.diff,
                 self.db,
                 self.snap_del,
                 "snap_no-diff_pre",
                 self.action,
                 "snap_no-diff_post1")
         except BaseException:
             err = "ERROR!! Data stored in database is not in %s format"
             c_list = mock_log.call_args_list[0]
             self.assertNotEqual(c_list[0][0].find(err), -1)
Exemple #3
0
 def compare_tests(self,
                   hostname,
                   config_data,
                   pre_snap=None,
                   post_snap=None,
                   action=None):
     """
     called by check and snapcheck argument, to compare snap files
     calls the function to compare snapshots based on arguments given
     (--check, --snapcheck, --diff)
     :param hostname: device name
     :return: return object of Operator containing test details
     """
     comp = Comparator()
     chk = self.args.check
     diff = self.args.diff
     pre_snap_file = self.args.pre_snapfile if pre_snap is None else pre_snap
     if (chk or diff or action in ["check", "diff"]):
         post_snap_file = self.args.post_snapfile if post_snap is None else post_snap
         test_obj = comp.generate_test_files(config_data, hostname, chk,
                                             diff, self.db, self.snap_del,
                                             pre_snap_file, action,
                                             post_snap_file)
     else:
         test_obj = comp.generate_test_files(config_data, hostname, chk,
                                             diff, self.db, self.snap_del,
                                             pre_snap_file, action)
     return test_obj
Exemple #4
0
 def test_no_test_file(self, mock_info):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_incorrect_1.yml')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     with patch('logging.Logger.error') as mock_error:
         comp.generate_test_files(main_file, self.hostname, self.chk,
                                  self.diff, self.db, self.snap_del,
                                  "snap_is-equal_pre")
         err = "ERROR!! No test file found, Please mention test files !!"
         c_list = mock_error.call_args_list[0]
         self.assertNotEqual(c_list[0][0].find(err), -1)
Exemple #5
0
 def test_compare_diff(self, mock_path, mock_info):
     self.diff = True
     comp = Comparator()
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_empty_test.yml')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     with patch('jnpr.jsnapy.check.diff') as mock_compare:
         comp.generate_test_files(main_file, self.hostname, self.chk,
                                  self.diff, self.db, self.snap_del,
                                  "snap_no-diff_pre", self.action,
                                  "snap_no-diff_post")
         self.assertTrue(mock_compare.called)
Exemple #6
0
 def test_incorrect_test_file(self, mock_info):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_incorrect_2.yml')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     filename = os.path.join('/etc', 'jsnapy', 'testfiles', "dummy.yml")
     with patch('logging.Logger.error') as mock_error:
         comp.generate_test_files(main_file, self.hostname, self.chk,
                                  self.diff, self.db, self.snap_del,
                                  "snap_is-equal_pre")
         err = "ERROR!! File %s not found" % filename
         c_list = mock_error.call_args_list[0]
         self.assertNotEqual(c_list[0][0].find(err), -1)
Exemple #7
0
 def test_incorrect_test_command(self, mock_path, mock_info):
     self.chk = False
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_incorrect_3.yml')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     with patch('logging.Logger.error') as mock_log:
         comp.generate_test_files(main_file, self.hostname, self.chk,
                                  self.diff, self.db, self.snap_del,
                                  "snap_is-equal_pre")
         err = "ERROR occurred, test keys 'command' or 'rpc' not defined properly"
         c_list = mock_log.call_args_list[0]
         self.assertNotEqual(c_list[0][0].find(err), -1)
Exemple #8
0
 def test_incorrect_test_format_2(self, mock_path, mock_info):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_incorrect_4.yml')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     with patch('logging.Logger.error') as mock_log:
         comp.generate_test_files(main_file, self.hostname, self.chk,
                                  self.diff, self.db, self.snap_del,
                                  "snap_no-diff_pre", self.action,
                                  "snap_no-diff_post1")
         err = "ERROR!! for checking snapshots in text format use '--diff' option"
         c_list = mock_log.call_args_list[0]
         self.assertNotEqual(c_list[0][0].find(err), -1)
Exemple #9
0
 def test_check_1(self, mock_path, mock_loginfo, mock_sqpath, mock_snapname,
                  mock_logerror, mock_compreply):
     self.chk = False
     mock_snapname.return_value = 'mock_pre', 'text'
     mock_sqpath.return_value = os.path.join(os.path.dirname(__file__),
                                             'configs')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_rpc_test.yml')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     self.db['check_from_sqlite'] = True
     comp = Comparator()
     comp.generate_test_files(main_file, self.hostname, self.chk, self.diff,
                              self.db, self.snap_del,
                              "mock_pre")  #,action= "check")
     mock_loginfo.assert_called()
     mock_logerror.assert_called()
     mock_compreply.assert_called()
 def test_exists_fail(self, mock_path, mock_debug, mock_info):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_exists.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_exists_fail_pre")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 1)
Exemple #11
0
 def test_all_same_ignore_null_2(self, mock_path, mock_debug, mock_info):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_all-same-ignore-null_2.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_all-same-success_pre")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 0)
Exemple #12
0
 def test_in_range_ignore_null_skip(self, mock_path):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_in-range_ignore-null_skip.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_in-range_pre")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 0)
 def test_regex_errors(self, mock_path):
     with self.assertRaises(IndexError):
         self.chk = True
         comp = Comparator()  # created changes in the test file
         conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                                  'main_regex.yml')
         mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                               'configs')
         config_file = open(conf_file, 'r')
         main_file = yaml.load(config_file)
         oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                         self.diff, self.db, self.snap_del,
                                         "pre_regex", self.action,
                                         "post_regex_empty")
 def test_is_gt(self, mock_path):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_is-gt.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_is-gt_pre")
     self.assertEqual(oper.no_passed, 1)
     self.assertEqual(oper.no_failed, 0)
 def test_xml_comparator(self, mock_path):
     self.chk = True
     comp = Comparator()  # created changes in the test file
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_xml_comparator.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "pre_xml_compare", self.action,
                                     "post_xml_compare")
     self.assertEqual(oper.no_failed, 1)
Exemple #16
0
 def test_not_equal_ignore_null_5(self, mock_path, mock_debug, mock_info):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_not-equal_ignore-null_5.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_is-equal_pre_special")
     self.assertEqual(oper.no_passed, 1)
     self.assertEqual(oper.no_failed, 0)
Exemple #17
0
 def test_conditional_operator_error_1(self, mock_path):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_conditional_op_error_1.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_all-same-success_pre")
     self.assertEqual(oper.no_passed, 4)  #one not run due to short-cutting
     self.assertEqual(oper.no_failed, 0)
     self.assertEqual(oper.result, "Failed")
 def test_delta_Index_error(self, mock_path, mock_error):
     with self.assertRaises(Exception):
         self.chk = True
         comp = Comparator()  #created changes in the test file
         conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                                  'main_test_delta_index_error.yml')
         mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                               'configs')
         config_file = open(conf_file, 'r')
         main_file = yaml.load(config_file)
         oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                         self.diff, self.db, self.snap_del,
                                         "pre_list_not_more_no_node",
                                         self.action,
                                         "post_list_not_more_no_node")
Exemple #19
0
 def test_conditional_operator_pass(self, mock_path):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_conditional_op_pass.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_all-same-success_pre")
     self.assertEqual(oper.no_passed, 4)
     self.assertEqual(oper.no_failed, 0)
     self.assertEqual(oper.result, 'Passed')
 def test_list_not_less_ignore_null_fail_1(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_list-not-less_ignore-null_fail_1.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_no-diff_pre", self.action,
                                     "snap_no-diff_post")
     self.assertEqual(oper.no_passed, 1)  #null case will pass
     self.assertEqual(oper.no_failed, 1)
 def test_no_diff_2(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_dot-dot.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_no-diff_pre", self.action,
                                     "snap_no-diff_post")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 6)
 def test_list_not_more_pass(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_list-not-more.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_no-diff_pre", self.action,
                                     "snap_3")
     self.assertEqual(oper.no_passed, 2)
     self.assertEqual(oper.no_failed, 0)
Exemple #23
0
 def test_xpath_with_functions(self, mock_path):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_xpath_functions.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "post")
     self.assertEqual(oper.no_passed, 1)
     self.assertEqual(oper.no_failed, 0)
     self.assertEqual(oper.result, 'Passed')
Exemple #24
0
 def compare_tests(
         self, hostname, config_data, pre_snap=None, post_snap=None, action=None):
     """
     called by check and snapcheck argument, to compare snap files
     calls the function to compare snapshots based on arguments given
     (--check, --snapcheck, --diff)
     :param hostname: device name
     :return: return object of Operator containing test details
     """
     comp = Comparator()
     chk = self.args.check
     diff = self.args.diff
     pre_snap_file = self.args.pre_snapfile if pre_snap is None else pre_snap
     if (chk or diff or action in ["check", "diff"]):
         post_snap_file = self.args.post_snapfile if post_snap is None else post_snap
         test_obj = comp.generate_test_files(
             config_data,
             hostname,
             chk,
             diff,
             self.db,
             self.snap_del,
             pre_snap_file,
             action,
             post_snap_file)
     else:
         test_obj = comp.generate_test_files(
             config_data,
             hostname,
             chk,
             diff,
             self.db,
             self.snap_del,
             pre_snap_file,
             action)
     return test_obj
 def test_list_not_more_ignore_null_skip_2(self, mock_path):
     #Test to check if xml element present in second snapshot but not present in second snapshot and if ignore-NULL
     #flag is set, it should return failure.
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_list-not-more_ignore-null_skip_2.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_exists_pre", self.action,
                                     "snap_exists_post")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 1)
 def test_list_not_more_ignore_null_fail_1(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                              'main_list-not-more_ignore-null_fail_1.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                           'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                     self.diff, self.db, self.snap_del,
                                     "snap_no-diff_pre", self.action,
                                     "snap_3")
     self.assertEqual(
         oper.no_passed,
         2)  #the name is kinda misleading but in line with the convention
     self.assertEqual(oper.no_failed, 0)
Exemple #27
0
 def test_is_equal_success_ignore_null_2(self, mock_path, mock_debug, mock_info):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_is-equal_ignore-null_6.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "snap_is-equal_pre_special")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 1)
Exemple #28
0
 def test_all_same_ignore_null_3(self, mock_path, mock_debug, mock_info):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_all-same-ignore-null_3.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "snap_all-same-success_pre")
     self.assertEqual(oper.no_passed, 0) #comparison between None values. All values are None.   
     self.assertEqual(oper.no_failed, 1)
Exemple #29
0
 def test_exists_fail(self, mock_path, mock_debug, mock_info):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_exists.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "snap_exists_fail_pre")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 1)
Exemple #30
0
 def test_contains_ignore_null_fail_1(self, mock_path):
     self.chk = False
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_contains_ignore-null_fail_1.yml')
     config_file = open(conf_file, 'r')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "snap_contains_pre")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 1)
Exemple #31
0
 def test_xml_comparator(self, mock_path):
     self.chk = True
     comp = Comparator()  # created changes in the test file
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_xml_comparator.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "pre_xml_compare",
         self.action,
         "post_xml_compare")
     self.assertEqual(oper.no_failed,1)
    def test_no_diff_pass(self, sqlite_mock_path, mock_path):
        self.chk = True
        self.db['check_from_sqlite'] = True
        comp = Comparator()
        conf_file = os.path.join(os.path.dirname(__file__), 'configs',
                                 'main_no-diff_sql.yml')
        mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                              'configs')
        sqlite_mock_path.return_value = os.path.join(os.path.dirname(__file__),
                                                     'configs')

        config_file = open(conf_file, 'r')
        main_file = yaml.load(config_file)
        oper = comp.generate_test_files(main_file, self.hostname, self.chk,
                                        self.diff, self.db, self.snap_del,
                                        "snap_no-diff_pre", self.action,
                                        "snap_no-diff_post1")
        self.assertEqual(oper.no_passed, 6)
        self.assertEqual(oper.no_failed, 0)
Exemple #33
0
 def test_delta_Index_error(self, mock_path, mock_error):
     with self.assertRaises(Exception):
         self.chk = True
         comp = Comparator()                 #created changes in the test file
         conf_file = os.path.join(os.path.dirname(__file__),
                                  'configs', 'main_test_delta_index_error.yml')
         mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
         config_file = open(conf_file, 'r')
         main_file = yaml.load(config_file)
         oper = comp.generate_test_files(
             main_file,
             self.hostname,
             self.chk,
             self.diff,
             self.db,
             self.snap_del,
             "pre_list_not_more_no_node",
             self.action,
             "post_list_not_more_no_node")
Exemple #34
0
 def test_regex_errors(self, mock_path):
     with self.assertRaises(IndexError):
         self.chk = True
         comp = Comparator()  # created changes in the test file
         conf_file = os.path.join(os.path.dirname(__file__),
                                  'configs', 'main_regex.yml')
         mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
         config_file = open(conf_file, 'r')
         main_file = yaml.load(config_file)
         oper = comp.generate_test_files(
             main_file,
             self.hostname,
             self.chk,
             self.diff,
             self.db,
             self.snap_del,
             "pre_regex",
             self.action,
             "post_regex_empty")
Exemple #35
0
 def test_regex_ignore_null_true(self, mock_path):
     self.chk = True
     comp = Comparator()  # created changes in the test file
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_regex_1.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "pre_regex",
         self.action,
         "post_regex_empty")
     self.assertEqual(oper.no_failed, 1)
Exemple #36
0
 def test_delta_percentage(self, mock_path, mock_error):
     self.chk = True
     comp = Comparator()  # created changes in the test file
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_delta_percentage.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "pre_delta_percentage",
         self.action,
         "post_delta_percentage")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 6)   
Exemple #37
0
 def test_list_not_more_missing_node(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_list_not_more_node_missing.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file, Loader=yaml.FullLoader)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "pre_list_not_more_node_missing",
         self.action,
         "post_list_not_more_node_missing")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 1)
Exemple #38
0
 def test_list_not_more_missing_node(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_list_not_more_node_missing.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "pre_list_not_more_node_missing",
         self.action,
         "post_list_not_more_node_missing")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 1)
Exemple #39
0
 def test_delta_ignore_null_id_skip(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_delta_ignore-null_id_skip.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "snap_delta_pre",
         self.action,
         "snap_delta_post")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 0)
Exemple #40
0
 def test_list_not_less_ignore_null_skip(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_list-not-less_ignore-null_skip.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "snap_no-diff_pre",
         self.action,
         "snap_no-diff_post")
     self.assertEqual(oper.no_passed, 0)
     self.assertEqual(oper.no_failed, 1)
Exemple #41
0
 def test_list_not_more_ignore_null_fail_1(self, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_list-not-more_ignore-null_fail_1.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "snap_no-diff_pre",
         self.action,
         "snap_3")
     self.assertEqual(oper.no_passed, 2)#the name is kinda misleading but in line with the convention    
     self.assertEqual(oper.no_failed, 0)
Exemple #42
0
 def test_no_diff_2_pass(self, mock_sqlite_path, mock_path):
     self.chk = True
     comp = Comparator()
     conf_file = os.path.join(os.path.dirname(__file__),
                              'configs', 'main_dot-dot.yml')
     mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     mock_sqlite_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
     config_file = open(conf_file, 'r')
     main_file = yaml.load(config_file)
     oper = comp.generate_test_files(
         main_file,
         self.hostname,
         self.chk,
         self.diff,
         self.db,
         self.snap_del,
         "snap_no-diff_pre",
         self.action,
         "snap_3")
     self.assertEqual(oper.no_passed, 6)
     self.assertEqual(oper.no_failed, 0)
Exemple #43
0
    def test_no_diff_pass(self, sqlite_mock_path, mock_path):
        self.hostname = '10.216.193.114'
        self.chk = True
        self.db['check_from_sqlite'] = True
        comp = Comparator()
        conf_file = os.path.join(os.path.dirname(__file__),
                                 'configs', 'main_no-diff_sql.yml')
        mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')
        sqlite_mock_path.return_value = os.path.join(os.path.dirname(__file__), 'configs')

        config_file = open(conf_file, 'r')
        main_file = yaml.load(config_file)
        oper = comp.generate_test_files(
            main_file,
            self.hostname,
            self.chk,
            self.diff,
            self.db,
            self.snap_del,
            "snap_no-diff_pre",
            self.action,
            "snap_no-diff_post1")
        self.assertEqual(oper.no_passed, 6)
        self.assertEqual(oper.no_failed, 0)