def test_success(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_cli_commands'))

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

        try:
            self.failUnless(os.path.isfile(bootstrap.startup_config))
            self.failUnless(eapi_log()[-1] == contents)
            self.failUnless(bootstrap.success())
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
示例#2
0
    def test_success(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        version = random_string()
        image = random_string()
        url = 'http://%s/%s' % (bootstrap.server, image)
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'test_action',
                      'attributes' : {
                        'url' : url,
                        'version' : version}},
                     {'action' :'startup_config_action'}])

        action = get_action('install_image')
        bootstrap.ztps.set_action_response('test_action',
                                           action)
        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())
        bootstrap.ztps.set_file_response(image, print_action())
        bootstrap.start_test()

        image_file = '%s/EOS-%s.swi' % (FLASH, version)
        try:
            self.failUnless(os.path.isfile(image_file))
            self.failUnless(bootstrap.success())
            self.failUnless(eapi_log()[-1] == 
                            'install source flash:EOS-%s.swi' % version)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            remove_file(image_file)
            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()
示例#4
0
    def test_success(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_cli_commands'))

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

        try:
            self.failUnless(os.path.isfile(bootstrap.startup_config))
            self.failUnless(eapi_log()[-1] == contents)
            self.failUnless(bootstrap.success())
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
示例#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()
示例#6
0
    def test_variables(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        config = random_string()
        url = config
        var_dict = {'a': 'A', 'b': 'A', 'xxx': '999', 'dummy': 'DUMMY'}
        bootstrap.ztps.set_definition_response(
            actions=[{
                'action': 'startup_config_action'
            }, {
                'action': 'test_action',
                'attributes': {
                    'url': url,
                    'substitution_mode': 'strict',
                    'variables': var_dict
                }
            }])

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

        contents = '$a 1234 $b 4  321 $xxx$a'
        bootstrap.ztps.set_file_response(config, contents)
        bootstrap.start_test()

        expected_contents = Template(contents).substitute(var_dict)

        try:
            self.failUnless(os.path.isfile(bootstrap.startup_config))
            self.failUnless(expected_contents == eapi_log()[-1])
            self.failUnless(bootstrap.success())
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()
示例#7
0
    def test_success(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        version = random_string()
        image = random_string()
        url = 'http://%s/%s' % (bootstrap.server, image)
        bootstrap.ztps.set_definition_response(
            actions=[{
                'action': 'test_action',
                'attributes': {
                    'url': url,
                    'version': version
                }
            }, {
                'action': 'startup_config_action'
            }])

        action = get_action('install_image')
        bootstrap.ztps.set_action_response('test_action', action)
        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())
        bootstrap.ztps.set_file_response(image, print_action())
        bootstrap.start_test()

        image_file = '%s/EOS-%s.swi' % (bootstrap.flash, version)
        try:
            self.failUnless(os.path.isfile(image_file))
            self.failUnless(bootstrap.success())
            self.failUnless(
                eapi_log()[-1] == 'install source flash:EOS-%s.swi' % version)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            remove_file(image_file)
            bootstrap.end_test()
    def test_variables(self):
        bootstrap = Bootstrap(ztps_default_config=True)
        config = random_string()
        url = config
        var_dict = { 'a' : 'A',
                     'b' : 'A',
                     'xxx' : '999',
                     'dummy': 'DUMMY'}
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'startup_config_action'},
                     {'action' : 'test_action',
                      'attributes': {'url' : url,
                                     'substitution_mode': 'strict',
                                     'variables': var_dict}}])

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

        contents = '$a 1234 $b 4  321 $xxx$a'
        bootstrap.ztps.set_file_response(config, contents)
        bootstrap.start_test()

        expected_contents = Template(contents).substitute(var_dict)

        try:
            self.failUnless(os.path.isfile(bootstrap.startup_config))
            self.failUnless(expected_contents == eapi_log()[-1])
            self.failUnless(bootstrap.success())
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise_exception(assertion)
        finally:
            bootstrap.end_test()