def test_failure(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        config = random_string()
        url = config
        bootstrap.ztps.set_definition_response(
            actions=[{
                'action': 'startup_config_action'
            }, {
                'action': 'test_action',
                'attributes': {
                    'url': url
                }
            }])

        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())
        bootstrap.ztps.set_action_response('test_action',
                                           get_action('run_bash_script'))

        contents = '''#!/usr/bin/env python
assert False'''
        bootstrap.ztps.set_file_response(config, contents)
        bootstrap.start_test()

        try:
            self.failUnless('AssertionError' in bootstrap.output)
            self.failUnless(bootstrap.action_failure())
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
    def test_failure(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        config = random_string()
        url = config
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'startup_config_action'},
                     {'action' : 'test_action',
                      'attributes': {'url' : url}}])

        bootstrap.ztps.set_action_response(
            'startup_config_action', startup_config_action())
        bootstrap.ztps.set_action_response('test_action',
                                           get_action('run_bash_script'))

        contents = '''#!/usr/bin/env python
assert False'''
        bootstrap.ztps.set_file_response(config, contents)
        bootstrap.start_test()

        try:
            self.failUnless('AssertionError' in bootstrap.output)
            self.failUnless(bootstrap.action_failure())
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
Beispiel #3
0
    def test_bad_file_status(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        config = random_string()
        url = 'http://%s/%s' % (bootstrap.server, config)
        bootstrap.ztps.set_definition_response(actions=[{
            'action': 'test_action',
            'attributes': {
                'url': url
            }
        }])
        bootstrap.ztps.set_action_response('test_action',
                                           get_action('replace_config'))
        contents = random_string()
        bootstrap.ztps.set_file_response(config,
                                         contents,
                                         status=STATUS_NOT_FOUND)
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.action_failure())
            msg = [x for x in bootstrap.output.split('\n') if x][-1]
            self.failUnless('Unable to retrieve config from URL' in msg)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
    def test_failure(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        config = random_string()
        url = config
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'test_action',
                      'attributes': {'url' : url}}])

        bootstrap.ztps.set_action_response('test_action',
                                           get_action('run_cli_commands'))

        contents = random_string()
        bootstrap.ztps.set_file_response(config, contents)
        bootstrap.eapi.add_failing_command(contents)
        bootstrap.start_test()

        try:
            self.failUnless(eapi_log()[-1] == contents)
            self.failUnless(bootstrap.action_failure())
            self.failUnless('Running CLI commands [\'%s\'] failed' % 
                            contents in bootstrap.output)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
Beispiel #5
0
    def test_failure(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        config = random_string()
        url = config
        bootstrap.ztps.set_definition_response(actions=[{
            'action': 'test_action',
            'attributes': {
                'url': url
            }
        }])

        bootstrap.ztps.set_action_response('test_action',
                                           get_action('run_cli_commands'))

        contents = random_string()
        bootstrap.ztps.set_file_response(config, contents)
        bootstrap.eapi.add_failing_command(contents)
        bootstrap.start_test()

        try:
            self.failUnless(eapi_log()[-1] == contents)
            self.failUnless(bootstrap.action_failure())
            self.failUnless('Running CLI commands [\'%s\'] failed' %
                            contents in bootstrap.output)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
    def action_fail_test(self, action):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'test_action'}])
        bootstrap.ztps.set_action_response('test_action', action)
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.action_failure())
            self.failIf(bootstrap.error)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise assertion
        finally:
            bootstrap.end_test()
Beispiel #7
0
    def action_fail_test(self, action):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()
        bootstrap.ztps.set_definition_response(actions=[{
            'action': 'test_action'
        }])
        bootstrap.ztps.set_action_response('test_action', action)
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.action_failure())
            self.failIf(bootstrap.error)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
    def test_action_failure(self):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()

        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'test_action'}])

        flash_filename = random_string()
        bootstrap.ztps.set_action_response(
                'test_action',
                fail_flash_file_action(bootstrap.flash,
                                       flash_filename))

        open(bootstrap.rc_eos, 'w').write(random_string())
        open(bootstrap.startup_config, 'w').write(random_string())
        open(bootstrap.boot_extensions, 'w').write(random_string())
        os.mkdir(bootstrap.boot_extensions_folder)
        open('%s/my_extension' % 
             bootstrap.boot_extensions_folder, 'w').write(random_string())

        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.action_failure())
            self.failIf(bootstrap.error)
            self.failIf(os.path.isfile('%s/%s' %
                                       (bootstrap.flash,
                                        flash_filename)))
            self.failIf(os.path.isfile(bootstrap.rc_eos))
            self.failIf(os.path.isfile(bootstrap.startup_config))
            self.failIf(os.path.isfile(bootstrap.boot_extensions))
            self.failIf(os.path.isdir(bootstrap.boot_extensions_folder))
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
Beispiel #9
0
    def test_action_failure_log(self):
        log = '/tmp/ztps-log-%s-debug' % os.getpid()

        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response(logging=[
            {
                'destination': 'file:%s' % log,
                'level': 'DEBUG'
            },
        ])
        bootstrap.ztps.set_node_check_response()

        text_onstart = random_string()
        text_onsuccess = random_string()
        text_onfailure = random_string()
        bootstrap.ztps.set_definition_response(actions=[
            {
                'action': 'test_action',
                'onstart': text_onstart,
                'onsuccess': text_onsuccess,
                'onfailure': text_onfailure
            },
        ])
        bootstrap.ztps.set_action_response('test_action', fail_action())
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.action_failure())
            self.failIf(bootstrap.error)
            log = ''.join(file_log(log))
            self.failUnless('test_action: %s' % text_onstart in log)
            self.failUnless('test_action: %s' % text_onsuccess not in log)
            self.failUnless('test_action: %s' % text_onfailure in log)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
    def test_bad_file_status(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        config = random_string()
        url = 'http://%s/%s' % (bootstrap.server, config)
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'test_action',
                      'attributes': {'url' : url}}])
        bootstrap.ztps.set_action_response('test_action',
                                           get_action('replace_config'))
        contents = random_string()
        bootstrap.ztps.set_file_response(config, contents,
                                         status=STATUS_NOT_FOUND)
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.action_failure())
            msg = [x for x in bootstrap.output.split('\n') if x][-1]
            self.failUnless('return code 2' in msg)
        except AssertionError:
            raise
        finally:
            bootstrap.end_test()
    def test_action_failure_log(self):
        log = '/tmp/ztps-log-%s-debug' % os.getpid()

        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response(logging=[
                {'destination' : 'file:%s' % log,
                 'level' : 'DEBUG'},])
        bootstrap.ztps.set_node_check_response()

        text_onstart = random_string()
        text_onsuccess = random_string()
        text_onfailure = random_string()
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'test_action',
                      'onstart' : text_onstart,
                      'onsuccess' : text_onsuccess,
                      'onfailure' : text_onfailure},
                     ])
        bootstrap.ztps.set_action_response('test_action',
                                           fail_action())
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.action_failure())
            self.failIf(bootstrap.error)
            log = ''.join(file_log(log))
            self.failUnless('test_action:%s' % text_onstart in log)
            self.failUnless('test_action:%s' % text_onsuccess not in log)
            self.failUnless('test_action:%s' % text_onfailure in log)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise assertion
        finally:
            bootstrap.end_test()