예제 #1
0
 def mock_get_yaml(yaml_file):
     if 'main' in yaml_file:
         return base.get_main_yaml()
     elif 'test_keystone' in yaml_file:
         return base.get_test_keystone_soochi()
     elif 'test_glance' in yaml_file:
         return base.get_test_glance_soochi()
예제 #2
0
    def test_soochis_with_group(self, get_yaml):
        get_yaml.side_effect = self.mock_get_yaml
        soochis = input_file.get_soochis(soochis=[],
                                         groups=['deployment'])

        for _, soochi in soochis:
            self.assertIn(soochi, [base.get_test_keystone_soochi(),
                                   base.get_test_glance_soochi()])
예제 #3
0
 def ttest_output(self):
     inp = {}
     t_soochis = base.get_test_keystone_soochi()['jaanches']['port_5000']
     inp['port_5000'] = t_soochis
     inp['port_5000']['formatted_output'] = 'test_output'
     with mock.patch.object(builtin, 'print') as mock_print:
         console.ConsoleFormatOutput().output(**inp)
         # fixme(thenakliman): mock print
         mock_print.assert_called()
예제 #4
0
    def test_get_soochis_both(self, get_yaml):
        get_yaml.side_effect = self.mock_get_yaml
        soochis = input_file.get_soochis(
            soochis=['test_glance', 'test_keystone'],
            groups=[])

        exp_output = [base.get_test_keystone_soochi(),
                      base.get_test_glance_soochi()]
        expected_output = self.match_soochi_format(exp_output)
        for exp in expected_output:
            self.assertIn(exp, soochis)
예제 #5
0
    def test_soochis_two_group(self, get_yaml):
        get_yaml.side_effect = self.mock_get_yaml
        soochis = input_file.get_soochis(soochis=[],
                                         groups=['monitor', 'deployment'])

        exp_soochis = [base.get_test_keystone_soochi(),
                       base.get_test_glance_soochi()]

        for _, soochi in soochis:
            self.assertIn(soochi, exp_soochis)

        self.assertEqual(len(soochis), len(exp_soochis))
        self.assertEqual(get_yaml.call_count, 3)
예제 #6
0
    def test_soochis_invalid_jaanch(self, get_yaml):
        get_yaml.side_effect = self.mock_get_yaml
        soochis = input_file.get_soochis(soochis=[],
                                         groups=['monitor', 'deployment'])

        exp_soochis = [base.get_test_keystone_soochi()]
        tmp = base.get_test_glance_soochi()
        del tmp['jaanches']['port_9292']
        exp_soochis.append(tmp)

        for _, soochi in soochis:
            if soochi['jaanches'].get('port_9292'):
                del soochi['jaanches']['port_9292']

            self.assertIn(soochi, exp_soochis)
예제 #7
0
 def test_conf_with_section(self, mock_output_yaml, mock_output_file):
     nirikshak.CONF['output_yaml'] = {'output_dir':
                                      '/var/nirikshak/result.yaml'}
     f_name = nirikshak.CONF['output_yaml']['output_dir']
     soochis = base_test.get_test_keystone_soochi()['jaanches']
     soochis['port_35357']['output']['result'] = 'test'
     soochis['port_35357']['input']['result'] = 'test'
     mock_output_file.return_value = {}
     exp = {'port_35357': soochis['port_35357']}
     dump_yaml.YAMLFormatOutput().output(**exp)
     result = {
         'port_35357': {
             'input': soochis['port_35357']['input']['args'],
             'output': {'actual_output': 'test', 'expected_output': 'test'}
         }
     }
     mock_output_file.assert_called_with(f_name)
     mock_output_yaml.assert_called_with(result, f_name)
예제 #8
0
    def test_with_invalid_soochi(self, get_yaml):
        def get_yaml_file(location):
            if 'main' in location:
                t_soochis = base.get_main_yaml()
                t_soochis['monitor']['soochis']['test_soochi'] = {
                    'soochi': 'test_soochi'}

                return t_soochis

            return self.mock_get_yaml(location)

        get_yaml.side_effect = get_yaml_file
        soochis = input_file.get_soochis(soochis=[],
                                         groups=['monitor'])
        exp_soochis = [base.get_test_keystone_soochi(),
                       base.get_test_glance_soochi()]

        for soochi in exp_soochis:
            self.assertIn(({}, soochi), soochis)
예제 #9
0
    def test_with_all_soochi_groups(self, get_yaml):
        def get_yaml_file(location):
            if 'main' in location:
                t_soochis = base.get_main_yaml()
                del t_soochis['monitor']['soochis']['test_keystone']
                del t_soochis['deployment']['soochis']['test_glance']
                return t_soochis

            return self.mock_get_yaml(location)

        get_yaml.side_effect = get_yaml_file
        soochis = input_file.get_soochis(soochis=[],
                                         groups=['monitor'])
        exp_soochis = [base.get_test_keystone_soochi(),
                       base.get_test_glance_soochi()]

        expected_output = self.match_soochi_format(exp_soochis)
        for soochi in expected_output:
            self.assertIn(soochi, soochis)
예제 #10
0
    def test_soochis_soochi_group(self, get_yaml):
        def get_yaml_file(location):
            if 'main' in location:
                t_soochis = base.get_main_yaml()
                del t_soochis['monitor']['soochis']['test_keystone']
                del t_soochis['monitor']['groups']
                return t_soochis

            return self.mock_get_yaml(location)

        get_yaml.side_effect = get_yaml_file
        soochis = input_file.get_soochis(soochis=['test_keystone'],
                                         groups=['monitor'])
        exp_soochis = [base.get_test_keystone_soochi(),
                       base.get_test_glance_soochi()]

        for _, soochi in soochis:
            self.assertIn(soochi, exp_soochis)

        self.assertEqual(len(soochis), len(exp_soochis))
예제 #11
0
    def test_conf_without_section(self, mock_output_json, mock_output_file):
        try:
            del nirikshak.CONF['output_json']
        except KeyError:
            pass

        f_name = '/var/lib/nirikshak/result.json'
        soochis = base_test.get_test_keystone_soochi()['jaanches']
        mock_output_file.return_value = {'port_5000': soochis['port_5000']}
        exp = {'port_35357': soochis['port_35357']}
        dump_json.JSONFormatOutput().output(**exp)
        result = {
            'port_35357': {
                'input': soochis['port_35357']['input']['args'],
                'output': None
            }
        }
        result.update({'port_5000': soochis['port_5000']})
        mock_output_file.assert_called_with(f_name)
        mock_output_json.assert_called_with(result, f_name)
예제 #12
0
 def test_get_soochis_keystone(self, get_yaml):
     get_yaml.side_effect = self.mock_get_yaml
     soochis = input_file.get_soochis(soochis=['test_keystone'], groups=[])
     exp_output = [base.get_test_keystone_soochi()]
     expected_output = self.match_soochi_format(exp_output)
     self.assertEqual(soochis, expected_output)
예제 #13
0
 def test_format_soochi(self):
     dct = base.get_test_keystone_soochi()
     self.assertEqual(dct, dummy.FormatOutputConsole().format_output(**dct))
예제 #14
0
 def setUp(self):
     sample_jaanch = {}
     sample_jaanch = base.get_test_keystone_soochi()
     sample_jaanch = sample_jaanch['jaanches']['port_5000']
     self.sample_jaanch = sample_jaanch
     super(WorkerTest, self).setUp()