Пример #1
0
    def test_matcher_package_bad_command(self):

      steps = Steps()
      with steps.start("Starting action", continue_=True) as step:

        self.kwargs.update({'steps': step,
                            'device': self.dev,
                            'maple_plugin_input': self.plugin_input3})
        maple(**self.kwargs)
        self.assertEqual(step.result, Failed)
Пример #2
0
    def test_matcher_package_without_output(self):

      steps = Steps()
      self.dev.execute = Mock(side_effect=Exception)
      with steps.start("Starting action", continue_=True) as step:

        self.kwargs.update({'steps': step,
                            'device': self.dev,
                            'maple_plugin_input': self.plugin_input2})
        maple(**self.kwargs)
        self.assertEqual(step.result, Failed)
Пример #3
0
    def test_pass(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()

        images = {
            'kickstart': ['slot0:/n7000-s2-kickstart.8.3.0.CV.0.658.gbin'],
            'system': ['slot0:/n7000-s2-dk10.34.3.0.CV.0.658.gbin']
        }

        data = {
            'show boot': '''
                Current Boot Variables:

                sup-1
                kickstart variable = slot0:/n7000-s2-kickstart.8.3.0.CV.0.658.gbin
                system variable = slot0:/n7000-s2-dk10.34.3.0.CV.0.658.gbin
                Boot POAP Disabled
                sup-2
                kickstart variable = slot0:/n7000-s2-kickstart.8.3.0.CV.0.658.gbin
                system variable = slot0:/n7000-s2-dk10.34.3.0.CV.0.658.gbin
                Boot POAP Disabled
                No module boot variable set

                Boot Variables on next reload:

                sup-1
                kickstart variable = slot0:/n7000-s2-kickstart.8.3.0.CV.0.658.gbin
                system variable = slot0:/n7000-s2-dk10.34.3.0.CV.0.658.gbin
                Boot POAP Disabled
                sup-2
                kickstart variable = slot0:/n7000-s2-kickstart.8.3.0.CV.0.658.gbin
                system variable = slot0:/n7000-s2-dk10.34.3.0.CV.0.658.gbin
                Boot POAP Disabled
                No module boot variable set
                '''
        }

        steps = Steps()

        # And we want the execute method to be mocked with device console output.
        self.device.execute = Mock(side_effect=lambda x: data[x])

        # Call the method to be tested (clean step inside class)
        self.cls.verify_boot_variable(
            steps=steps, device=self.device, images=images
        )

        # Check the overall result is as expected
        self.assertEqual(Passed, steps.details[0].result)
Пример #4
0
    def test_dispatcher_1(self):

      blitz_discoverer = self.blitz_cls()._discover()
      for section in blitz_discoverer:

        new_section = section.__testcls__(section)
        steps = Steps()
        blitz_obj = self.blitz_cls()
        self.uid = blitz_obj.uid
        blitz_obj.parent = self
        blitz_obj.parent.parameters = mock.Mock()

        output = blitz_obj.dispatcher(steps,
                                             self.testbed,
                                             new_section,
                                             section.parameters['data'])

        self.assertEqual(output, { 'action': 'execute',
                                             'alias': None,
                                             'continue_': True,
                                             'description': '',
                                             'device': 'PE1',
                                             'saved_vars': {'host': 'host'},
                                             'filters': '(?P<host>host).*',
                                             'step_result': Passed})

        self.assertEqual(new_section.description, "section description")
Пример #5
0
    def test_loop_range(self):

        steps = Steps()
        data = yaml.safe_load(self.loop_range)
        self.kwargs.update({'steps': steps, 'action_item': data})
        out = loop(**self.kwargs)
        self.assertEqual(steps.result, Passed)
Пример #6
0
    def test_loop_with_parallel_errored(self):

        steps = Steps()
        data = yaml.safe_load(self.loop_parallel_error)
        self.kwargs.update({'steps': steps, 'action_item': data})
        out = loop(**self.kwargs)
        self.assertEqual(steps.result, Errored)
    def test_pass(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()

        data = {
            'show install active summary':
            '''
                Default Profile:
                SDRs:
                    Owner
                Active Packages:
                    disk0:asr9k-mini-px-6.1.21.15I
                    disk0:asr9k-mpls-px-6.1.21.15I
                    disk0:asr9k-mcast-px-6.1.21.15I
                    disk0:asr9k-mgbl-px-6.1.21.15I
               ''',
        }

        self.device.execute = Mock(side_effect=lambda x: data[x])
        self.cls.installed_packages = [
            'asr9k-mini-px-6.1.21.15I', 'asr9k-mpls-px-6.1.21.15I',
            'asr9k-mcast-px-6.1.21.15I', 'asr9k-mgbl-px-6.1.21.15I'
        ]

        # And we want the verify_installed_pies method to be mocked.
        # This simulates the pass case.
        self.device.api.verify_installed_pies(self.cls.installed_packages, 0,
                                              0)

        # Call the method to be tested (clean step inside class)
        self.cls.verify_pies_installed(steps=steps, device=self.device)

        # Check that the result is expected
        self.assertEqual(Passed, steps.details[0].result)
Пример #8
0
    def test_fail_to_set_boot_variables(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()
        data = {
            'dir bootflash:/':
            '''
                   Directory of bootflash:/
                        11  drwx            16384  Nov 25 2016 19:32:53 -07:00  lost+found
                        12  -rw-                0  Dec 13 2016 11:36:36 -07:00  ds_stats.txt
                        104417  drwx             4096  Apr 10 2017 09:09:11 -07:00  .prst_sync
                        80321  drwx             4096  Nov 25 2016 19:40:38 -07:00  .rollback_timer
                        64257  drwx             4096  Nov 25 2016 19:41:02 -07:00  .installer
                        48193  drwx             4096  Nov 25 2016 19:41:14 -07:00  virtual-instance-stby-sync
                        8033  drwx             4096  Nov 25 2016 18:42:07 -07:00  test.bin
                        1940303872 bytes total (1036210176 bytes free)
                '''
        }

        # And we want the execute method to be mocked with device console output.
        self.device.execute = Mock(return_value=data['dir bootflash:/'])

        # And we want the execute_set_boot_variable api to raise an exception when called.
        # This simulates the fail case.
        self.device.api.execute_set_boot_variable = Mock(side_effect=Exception)

        # We expect this step to fail so make sure it raises the signal
        with self.assertRaises(TerminateStepSignal):
            self.cls.set_boot_variable(steps=steps, device=self.device)

        # Check the overall result is as expected
        self.assertEqual(Failed, steps.details[0].result)
Пример #9
0
    def test_pass(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()

        data = {
            'dir bootflash:/':
            '''
                   Directory of bootflash:/
                        11  drwx            16384  Nov 25 2016 19:32:53 -07:00  lost+found
                        12  -rw-                0  Dec 13 2016 11:36:36 -07:00  ds_stats.txt
                        104417  drwx             4096  Apr 10 2017 09:09:11 -07:00  .prst_sync
                        80321  drwx             4096  Nov 25 2016 19:40:38 -07:00  .rollback_timer
                        64257  drwx             4096  Nov 25 2016 19:41:02 -07:00  .installer
                        48193  drwx             4096  Nov 25 2016 19:41:14 -07:00  virtual-instance-stby-sync
                        8033  drwx             4096  Nov 25 2016 18:42:07 -07:00  test.bin
                        1940303872 bytes total (1036210176 bytes free)
                '''
        }

        # And we want the execute method to be mocked with device console output.
        self.device.execute = Mock(return_value=data['dir bootflash:/'])

        # And we want the execute_set_boot_variable api to be mocked.
        # This simulates the pass case.
        self.device.api.execute_set_boot_variable = Mock()

        # Call the method to be tested (clean step inside class)
        self.cls.set_boot_variable(steps=steps, device=self.device)
        # Check that the result is expected
        self.assertEqual(Passed, steps.details[0].result)
Пример #10
0
    def test_fail_to_verify_boot_variables(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()
        self.cls.new_boot_var = 'flash:cat9k_iosxe.BLD_V173_999.SSA.bin'

        data1 = {
            'show boot':
            '''
            starfleet-1#show boot
            BOOT variable = bootflash:cat9k_iosxe.BLD_V173_THROTTLE_LATEST_20200421_032634.SSA.bin;
            Configuration Register is 0x102
            MANUAL_BOOT variable = no
            BAUD variable = 9600
            ENABLE_BREAK variable does not exist
            BOOTMODE variable does not exist
            IPXE_TIMEOUT variable does not exist
            CONFIG_FILE variable =
        '''
        }

        # And we want the verify_boot_variable api to be mocked.
        # This simulates the fail case.
        self.device.execute = Mock(return_value=data1['show boot'])

        # And we want the execute_copy_run_to_start api to raise an exception when called.
        # This simulates the fail case.
        self.device.api.execute_copy_run_to_start = Mock(side_effect=Exception)

        # We expect this step to fail so make sure it raises the signal
        with self.assertRaises(TerminateStepSignal):
            self.cls.save_running_config(steps=steps, device=self.device)

        # Check the overall result is as expected
        self.assertEqual(Failed, steps.details[0].result)
Пример #11
0
    def test_pass(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()
        self.cls.new_boot_var = 'bootflash:cat9k_iosxe.BLD_V173_THROTTLE_LATEST_20200421_032634.SSA.bin'

        data1 = {
            'show boot':
            '''
            starfleet-1#show boot
            BOOT variable = bootflash:cat9k_iosxe.BLD_V173_THROTTLE_LATEST_20200421_032634.SSA.bin;
            Configuration Register is 0x102
            MANUAL_BOOT variable = no
            BAUD variable = 9600
            ENABLE_BREAK variable does not exist
            BOOTMODE variable does not exist
            IPXE_TIMEOUT variable does not exist
            CONFIG_FILE variable =
        '''
        }

        # And we want the verify_boot_variable api to be mocked.
        # This simulates the pass case.
        self.device.execute = Mock(return_value=data1['show boot'])

        # Call the method to be tested (clean step inside class)
        self.cls.verify_boot_variable(steps=steps, device=self.device)
        # Check that the result is expected
        self.assertEqual(Passed, steps.details[0].result)
Пример #12
0
    def test_save_findall(self):
      self._initiate_blitz_cls(self.yaml5)
      blitz_discoverer = self.blitz_cls()._discover()
      for section in blitz_discoverer:

        new_section = section.__testcls__(section)
        steps = Steps()
        blitz_obj = self.blitz_cls()
        self.uid = blitz_obj.uid
        blitz_obj.parent = self
        blitz_obj.parent.parameters = mock.Mock()

        output = blitz_obj.dispatcher(steps,
                                      self.testbed,
                                      new_section,
                                      section.parameters['data'])

        self.assertEqual(output, {
                          'action': 'execute',
                          'device': 'PE1',
                          'alias': None,
                          'continue_': True,
                          'description': '',
                          'saved_vars': {
                            'execute_output': [
                              'host', 'execute', 'output'
                            ]
                          },
                          'step_result': Passed
                        })
Пример #13
0
    def test_pass(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()
        self.cls.history = OrderedDict()
        self.cls.mock_value = OrderedDict()
        setattr(self.cls.mock_value, 'parameters', {})
        self.cls.history.update({'ExpandImage': self.cls.mock_value})
        self.cls.history['ExpandImage'].parameters = OrderedDict()

        data = '''
        Sample Outputs:
            WARNING: bootflash:asr1000-universalk9.17.06.01a.SPA.18.conf
            WARNING: packages.conf will replace the identical file that already exists in bootflash:
        '''

        # And we want the execute method to be mocked.
        # This simulates the pass case.
        self.device.execute = Mock(return_value=data)

        # Call the method to be tested (clean step inside class)
        self.cls.expand_image(steps=steps,
                              device=self.device,
                              image=['bootflash:stay-isr-image.bin'])

        # Check that the result is expected
        self.assertEqual(Passed, steps.details[0].result)
    def test_fail_to_execute_copy_run_start(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()
        configuration = '''
            configuration: |
            interface ethernet2/1
            no shutdown
        '''

        # And we want the configure method to be mocked.
        self.device.configure = Mock()

        # And we want the execute_copy_run_api_to_start to be mocked to raise exception.
        # This simulates the fail case.
        self.device.api.execute_copy_run_to_start = Mock(side_effect=Exception)

        # Call the method to be tested (clean step inside class)
        # We expect this step to fail so make sure it raises the signal
        with self.assertRaises(TerminateStepSignal):
            self.cls.apply_configuration(
                    steps=steps, device=self.device, config_stable_time=0,\
                    configuration=configuration, file="test.cfg", copy_vdc_all=True
                )

        # Check that the result is expected
        self.assertEqual(Failed, steps.details[1].result)
Пример #15
0
def configure_bgp_neighbor_activate(device,
                                    address_family,
                                    bgp_as,
                                    neighbor_address,
                                    steps=Steps()):
    """ Activate bgp neighbor on bgp router 

        Args:
            device ('obj')             : Device to be configured
            bgp_as ('str')             : Bgp Id to be added to configuration
            neighbor_address ('str')   : Address of neighbor to be added to configuration
            address_family ('str')     : Address family to be configured
            steps('obj')               : Context manager steps
        Returns:
            N/A
        Raises:
            SubCommandFailure: Failed executing configure commands
            
    """
    with steps.start("Configure device {dev}".format(dev=device.name),
                     continue_=True) as step:

        try:
            device.configure([
                "router bgp {bgp_as}".format(bgp_as=bgp_as),
                "address-family {address_family}".format(
                    address_family=address_family),
                "neighbor {device_address} activate".format(
                    device_address=neighbor_address),
            ])
        except SubCommandFailure as e:
            raise SubCommandFailure("Could not ativate bgp neighbor on bgp "
                                    "router {bgp_as}".format(bgp_as=bgp_as))
Пример #16
0
    def test_parallel_loops(self):

        steps = Steps()
        data = yaml.safe_load(self.yaml3)
        self.blitz_obj.parameters['save_variable_name'] = {}
        self.blitz_obj.parameters['save_variable_name'][
            'execute_id'] = 'passed'
        self.kwargs.update({
            'self': self.blitz_obj,
            'data': data,
            'steps': steps
        })

        # TODO alias and saved_vars wont get stored when under loop/run_condition
        # self.assertIn('exec_1', self.blitz_obj.parameters['save_variable_name'])
        parallel(**self.kwargs)
        self.assertIn('parse_id',
                      self.blitz_obj.parameters['save_variable_name'])
        self.assertEqual(steps.result, Failed)
        self.assertEqual(steps.details[0].name,
                         'Executing actions in parallel')
        self.assertEqual(
            steps.details[1].name,
            'Condition %VARIABLES{execute_id} == passed is met and '
            'the step result is failed')
        self.assertEqual(steps.details[1].result, Failed)
    def test_pass(self):
        steps = Steps()
        self.device.execute = Mock(return_value='[OK]')

        self.cls.write_memory(steps=steps, device=self.device)

        self.assertEqual(Passed, steps.details[0].result)
Пример #18
0
def action_parallel(self, steps, testbed, data):
    # When called run all the actions
    # below the keyword parallel concurently
    pcall_payloads = []
    with steps.start('Executing actions in parallel', continue_=True) as steps:

        for action_item in data:
            for action, action_kwargs in action_item.items():
                # for future use - Enhancement needed in pyATS
                # with steps.start("Implementing action '{a}' in parallel".format(a=actions)) as step:
                step = Steps()
                kwargs = {
                    'steps': step,
                    'testbed': testbed,
                    'data': [{
                        action: action_kwargs
                    }]
                }
                pcall_payloads.append(kwargs)
        pcall_returns = pcall(self.dispatcher, ikwargs=pcall_payloads)
        # Each action return is a dictionary containing the action name, possible saved_variable
        # Action results, and device name that action is being implemented on
        # These value would be lost when the child processor that executes the action end the process.
        # It is being implemented this way in order to add these values to the main processor.
        for each_return in pcall_returns:

            if each_return.get('saved_var'):
                saved_var_data = each_return['saved_var'][0]
                saved_var_name = each_return['saved_var'][1]
                save_variable(self, saved_var_data, saved_var_name)

            with steps.start('Executed {} on {} in parallel'.format(
                    each_return['action'], each_return['device']),
                             continue_=True) as report_step:
                getattr(report_step, str(each_return['step_result']))()
Пример #19
0
    def test_loop_maple(self):

        steps = Steps()
        data = {'maple': True, 'section': '{\n"package":"maple.plugins.user.LoopPlugins"'\
                ',\n"method":"single_iterable_loop",\n"options":[\n    {"iterable_name": "front_ports"},\n'\
                '    {"start": "0"},\n    {"stop": "1"},\n    {"step": "1"}\n    ]\n}',
                'actions': [
                  {'execute':
                    {'device': 'PE1',
                     'command': 'show interface ethernet 1/%VARIABLES{front_ports}',
                     'save': [{'variable_name': 'step-1_rule-1_match_unmatch'}]},
                     'maple_search': {
                       'search_string': '%VARIABLES{step-1_rule-1_match_unmatch}',
                       'device': 'PE1',
                       'include': ['.*o.*']}}]}

        side_effect = [{
            'loop_continue': True,
            'matchObjs': {
                'front_ports': 'b'
            }
        }, {
            'loop_continue': False
        }]

        with patch('plugins.user.LoopPlugins.single_iterable_loop',
                   side_effect=side_effect) as func:

            self.kwargs.update({'steps': steps, 'action_item': data})
            loop(**self.kwargs)
            func.assert_called()
            self.assertEqual(steps.result, Passed)
    def test_pass(self):
        steps = Steps()

        self.cls.set_configuration_register(steps=steps,
                                            device=self.device,
                                            config_register='0x2102')

        self.assertEqual(Passed, steps.details[0].result)
Пример #21
0
    def test_condition_no_function_pass(self):

        steps = Steps()
        data = yaml.safe_load(self.condition_5)
        self.kwargs.update({'steps': steps, 'action_item': data})
        self.blitz_obj.parameters['save_variable_name'] = {'execute_id': 'id1'}
        run_condition(**self.kwargs)
        self.assertEqual(steps.result, Passed)
    def test_pass(self):
        steps = Steps()

        self.cls.configure_boot_variable(steps=steps,
                                         device=self.device,
                                         images=['bootflash:image.bin'])

        self.assertEqual(Passed, steps.details[0].result)
    def test_fail_to_write_memory(self):
        steps = Steps()
        self.device.api.write_memory = Mock(side_effect=Exception)

        with self.assertRaises(TerminateStepSignal):
            self.cls.write_memory(steps=steps, device=self.device)

        self.assertEqual(Failed, steps.details[0].result)
    def test_pass(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()

        # This simulates the pass case.
        self.cls.deactivate_manual_boot(steps=steps, device=self.device)
        # Check that the result is expected
        self.assertEqual(Passed, steps.details[0].result)
Пример #25
0
    def test_condition_if_else(self):

        steps = Steps()
        data = yaml.safe_load(self.condition_10)
        self.kwargs.update({'steps': steps, 'action_item': data})
        self.blitz_obj.parameters['save_variable_name'] = {'execute_id': 'id5'}
        out = run_condition(**self.kwargs)
        self.assertEqual(steps.result, Passed)
        self.assertEqual(steps.details[0].name, 'inside else condition')
Пример #26
0
    def test_condition_eq_none_2(self):

        steps = Steps()
        data = yaml.safe_load(self.condition_9)
        self.kwargs.update({'steps': steps, 'action_item': data})
        self.blitz_obj.parameters['save_variable_name'] = {}
        out = run_condition(**self.kwargs)
        self.assertNotEqual(out['substeps'], [])
        self.assertEqual(out['run_condition_skipped'], False)
Пример #27
0
    def test_condition_no_function_parallel(self):

        steps = Steps()
        data = yaml.safe_load(self.condition_4)
        self.kwargs.update({'steps': steps, 'action_item': data})
        self.blitz_obj.parameters['save_variable_name'] = {'execute_id': 'id1'}
        out = run_condition(**self.kwargs)
        self.assertNotEqual(out['substeps'], [])
        self.assertEqual(out['run_condition_skipped'], False)
Пример #28
0
    def test_loop_with_dict_val(self):

        steps = Steps()
        data = yaml.safe_load(self.loop_with_dict_val)
        self.kwargs.update({'steps': steps, 'action_item': data})
        out = loop(**self.kwargs)
        self.assertEqual(len(out['substeps']), 2)
        self.assertEqual(out['substeps'][0]['device'], 'PE1')
        self.assertEqual(out['substeps'][1]['device'], 'PE2')
Пример #29
0
    def test_loop_with_loop_until(self):

        self.testbed.devices['PE1'].side_effect = [Exception, Exception, 'oop']
        steps = Steps()
        data = yaml.safe_load(self.loop_until)
        self.kwargs.update({'steps': steps, 'action_item': data})
        out = loop(**self.kwargs)
        self.assertEqual(out['substeps'], [])
        self.assertEqual(steps.result, Passed)
    def test_pass(self):
        # Make sure we have a unique Steps() object for result verification
        steps = Steps()

        # Call the method to be tested (clean step inside class)
        self.cls.delete_boot_variable(steps=steps, device=self.device)

        # Check that the result is expected
        self.assertEqual(Passed, steps.details[0].result)