Exemple #1
0
    def test_save_variable_append_in_existing_list(self):

        save_variable(self.blitz_obj,
                      self.section,
                      'list_item',
                      9000,
                      append_in_list=True)
        self.assertEqual(
            self.blitz_obj.parameters['save_variable_name']['list_item'],
            [177, 24, 13, 45, 9000])
Exemple #2
0
    def test_save_variable_append_in_empty_list(self):

        save_variable(self.blitz_obj,
                      self.section,
                      'new_item',
                      'VRF1',
                      append_in_list=True)
        self.assertEqual(
            self.blitz_obj.parameters['save_variable_name']['new_item'],
            ['VRF1'])
Exemple #3
0
    def test_save_variable_append(self):

        save_variable(self.blitz_obj,
                      self.section,
                      'sub_command',
                      'vrf',
                      append=True)
        self.assertEqual(
            self.blitz_obj.parameters['save_variable_name']['sub_command'],
            'interface\nvrf')
    def test_save_and_load_variable_empty(self):

        saved_variable = 'var2'
        saved_value = ''
        save_variable(self.blitz_obj, self.section, saved_variable,
                      saved_value)
        self.assertEqual(
            self.blitz_obj.parameters['save_variable_name'][saved_variable],
            saved_value)

        _, val = _load_saved_variable(self.blitz_obj,
                                      self.section,
                                      val=saved_value,
                                      key=saved_variable)
        self.assertEqual(val, saved_value)
    def test_save_variable(self):

        save_variable(self.blitz_obj, self.section, 'var1', 'aa')
        self.assertEqual(
            self.blitz_obj.parameters['save_variable_name']['var1'], 'aa')
    def health_dispatcher(self,
                          steps,
                          section,
                          data,
                          testbed,
                          processor,
                          reconnect,
                          name='',
                          **kwargs):
        """
        excute health yaml based on Blitz logic. This will be calling Blitz's
        `dispacher` to execute all the actions in health yaml
        
        `data` contains all the items under a section in health yaml
        
        example of `data`:
        [
          {
            'parallel': [
              {
                'api': {
                  'device': 'uut',
                  'function': 'get_platform_cpu_load',
                  'arguments': {
                    'command': 'show processes cpu',
                    'processes': ['BGP I/O']
                  },
                  'save': [
                    {
                      'variable_name': 'cpu'
                    }
                  ]
                }
              },
              {
                'api': {
                  'device': 'uut',
                  (snip)
        
        `data` is List, so store the `data` as dict to `data_dict` for Dq

        Arguments:
            steps (`obj`) : Aetest Steps object
            section (`obj`) : Aetest Section object
            data (`list`) : data of section
            testbed (`obj`) : testbed object
            processor (`obj`) : Aetest processor object
            name (`str`) : name of section in health yaml
                           Default to ``
            reconnect (`dict` or None) : parameters for reconnect
                                         ex.)
                                         {
                                             'max_time': 900, # maximum time to reconnect
                                             'interval': 60,  # sleep before retry
                                         }
        Returns:
            None
        """

        if 'genie' not in testbed.__module__:
            # convert testbed from pyATS to Genie
            testbed = Converter.convert_tb(runtime.testbed)

        if 'genie' not in testbed.__module__:
            # convert testbed from pyATS to Genie
            testbed = Converter.convert_tb(runtime.testbed)

        if 'health_settings' in kwargs:
            health_settings = kwargs['health_settings']
        else:
            health_settings = {}

        # save `health_settings` as testscript variable
        save_variable(self, section, 'testscript.health_settings',
                      health_settings)
        # handling for `health_settings.devices`. TODO; AttrDict support
        if 'devices' in health_settings:
            save_variable(self, section, 'testscript.health_settings.devices',
                          health_settings['devices'])

        # ---------------------
        # pre-context processor
        # ---------------------

        # set result Passed at beginning of section in pre processor
        # because section sometimes doesn't have any item like commonCleanup
        # if the section doesn't have any, section.result is None and rolled-up
        # only with pyATS Health Check result. But section should have Passed
        # at first place
        if section.__result__ is None:
            section.result = Passed

        # execute pre-processor and received result in self.pre_processor_result
        self.pre_processor_run, self.pre_processor_result = self._pre_post_processors(
            testbed,
            processor,
            section,
            data,
            name,
            reconnect,
            processor_targets=['pre', 'both'],
            processor_type='pre',
            health_settings=health_settings)

        try:
            yield
        except Exception as e:
            # make section Errored when exception happens
            section.result = Errored.clone('Caught exception in %s' %
                                           str(section),
                                           data={'traceback': e})

        # ----------------------
        # post-context processor
        # ----------------------
        post_if_pre_execute_flag = not any(
            Dq(each_data).get_values('processor', 0) == 'post_if_pre_execute'
            and not self.pre_processor_run
            for each_data in self._get_actions(data))

        if not post_if_pre_execute_flag:
            log.info(
                "Post-processor pyATS Health '{name}' was skipped because required Pre-processor was not executed."
                .format(name=name))

        else:
            if 'genie' not in testbed.__module__:
                # convert testbed from pyATS to Genie
                # need to convert to bring latest status from runtime again
                # for the case devices are connected after pre-processor
                testbed = Converter.convert_tb(runtime.testbed)

            # execute post-processor
            _, post_processor_result = self._pre_post_processors(
                testbed,
                processor,
                section,
                data,
                name,
                reconnect,
                processor_targets=['post', 'post_if_pre_execute', 'both'],
                processor_type='post',
                pre_processor_result=self.pre_processor_result,
                health_settings=health_settings)

            # raise result
            getattr(processor, post_processor_result.name)()