def test_multiple_actions(self):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'startup_config_action'},
                     {'action' : 'print_action_1'},
                     {'action' : 'print_action_2'}])
        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())

        text_1 = random_string()
        bootstrap.ztps.set_action_response('print_action_1',
                                           print_action(text_1))
        text_2 = random_string()
        bootstrap.ztps.set_action_response('print_action_2',
                                           print_action(text_2))
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.success())
            self.failUnless(text_1 in bootstrap.output)
            self.failUnless(text_2 in bootstrap.output)
            self.failIf(bootstrap.error)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise assertion
        finally:
            bootstrap.end_test()
Esempio n. 2
0
    def test_multiple_actions(self):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()
        bootstrap.ztps.set_definition_response(
            actions=[{
                'action': 'startup_config_action'
            }, {
                'action': 'print_action_1'
            }, {
                'action': 'print_action_2'
            }])
        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())

        text_1 = random_string()
        bootstrap.ztps.set_action_response('print_action_1',
                                           print_action(text_1))
        text_2 = random_string()
        bootstrap.ztps.set_action_response('print_action_2',
                                           print_action(text_2))
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.success())
            self.failUnless(text_1 in bootstrap.output)
            self.failUnless(text_2 in bootstrap.output)
            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_attribute(self):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()
        text = random_string()
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'startup_config_action'},
                     {'action' : 'print_action',
                      'attributes' : {'print_action-attr':text}}])
        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())
        bootstrap.ztps.set_action_response('print_action',
                                           print_action(use_attribute=True))
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.success())
            self.failUnless(text in bootstrap.output)
            self.failIf(bootstrap.error)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise assertion
        finally:
            bootstrap.end_test()
    def test_duplicate_actions(self):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()
        bootstrap.ztps.set_definition_response(
            actions=[{'action' : 'startup_config_action'},
                     {'action' : 'print_action'},
                     {'action' : 'print_action'}])
        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())

        text = random_string()
        bootstrap.ztps.set_action_response('print_action',
                                           print_action(text))
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.success())
            self.failUnless(bootstrap.output.count('Downloading action '
                                                   'print_action') == 1)
            self.failUnless(bootstrap.output.count('Executing action '
                                                   'print_action') == 2)
            self.failUnless(bootstrap.output.count(text) == 2)
            self.failIf(bootstrap.error)
        except AssertionError as assertion:
            print 'Output: %s' % bootstrap.output
            print 'Error: %s' % bootstrap.error
            raise assertion
        finally:
            bootstrap.end_test()
Esempio n. 5
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()
Esempio n. 6
0
    def test_attribute(self):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()
        text = random_string()
        bootstrap.ztps.set_definition_response(
            actions=[{
                'action': 'startup_config_action'
            }, {
                'action': 'print_action',
                'attributes': {
                    'print_action-attr': text
                }
            }])
        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())
        bootstrap.ztps.set_action_response('print_action',
                                           print_action(use_attribute=True))
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.success())
            self.failUnless(text in bootstrap.output)
            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_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}}])

        boot_file = '/tmp/boot-config'
        action = get_action('install_image')
        action = action.replace('/mnt/flash/boot-config',
                                boot_file)
        bootstrap.ztps.set_action_response('test_action',
                                           action)
        bootstrap.ztps.set_file_response(image, print_action())
        bootstrap.start_test()

        image_file = '%s/%s.swi' % (FLASH, version)
        try:
            self.failUnless('! boot system flash:/%s.swi' % version
                            in file_log(STARTUP_CONFIG))
            self.failUnless(os.path.isfile(image_file))
            self.failUnless(['SWI=flash:/%s.swi' % version] ==
                            file_log(boot_file))
            self.failUnless(bootstrap.success())
        except AssertionError:
            raise
        finally:
            remove_file(image_file)
            remove_file(boot_file)
            bootstrap.end_test()
    def test_content_type(self):
        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', print_action(),
                                           content_type='test/plain')
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.unexpected_response_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()
Esempio n. 9
0
    def test_content_type(self):
        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',
                                           print_action(),
                                           content_type='test/plain')
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.unexpected_response_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()
Esempio n. 10
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()
Esempio n. 11
0
    def test_duplicate_actions(self):
        bootstrap = Bootstrap()
        bootstrap.ztps.set_config_response()
        bootstrap.ztps.set_node_check_response()
        bootstrap.ztps.set_definition_response(
            actions=[{
                'action': 'startup_config_action'
            }, {
                'action': 'print_action'
            }, {
                'action': 'print_action'
            }])
        bootstrap.ztps.set_action_response('startup_config_action',
                                           startup_config_action())

        text = random_string()
        bootstrap.ztps.set_action_response('print_action', print_action(text))
        bootstrap.start_test()

        try:
            self.failUnless(bootstrap.eapi_node_information_collected())
            self.failUnless(bootstrap.success())
            self.failUnless(
                bootstrap.output.count('Downloading action '
                                       'print_action') == 1)
            self.failUnless(
                bootstrap.output.count('Executing action '
                                       'print_action') == 2)
            self.failUnless(bootstrap.output.count(text) == 2)
            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()