def test(self): open(RC_EOS, 'w').write(random_string()) open(BOOT_EXTENSIONS, 'w').write(random_string()) os.makedirs(BOOT_EXTENSIONS_FOLDER) open('%s/%s' % (BOOT_EXTENSIONS_FOLDER, random_string()), 'w').write(random_string()) bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.missing_startup_config_failure()) self.failIf(os.path.exists(RC_EOS)) self.failIf(os.path.exists(BOOT_EXTENSIONS)) self.failIf(os.path.exists(BOOT_EXTENSIONS_FOLDER)) 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_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()
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_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(self): open(RC_EOS, 'w').write(random_string()) open(BOOT_EXTENSIONS, 'w').write(random_string()) os.makedirs(BOOT_EXTENSIONS_FOLDER) open('%s/%s' % (BOOT_EXTENSIONS_FOLDER, random_string()), 'w').write(random_string()) bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.missing_startup_config_failure()) self.failIf(os.path.exists(RC_EOS)) self.failIf(os.path.exists(BOOT_EXTENSIONS)) self.failIf(os.path.exists(BOOT_EXTENSIONS_FOLDER)) 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_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()
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(self): bootstrap = Bootstrap() open(bootstrap.rc_eos, 'w').write(random_string()) open(bootstrap.boot_extensions, 'w').write(random_string()) os.makedirs(bootstrap.boot_extensions_folder) open('%s/%s' % (bootstrap.boot_extensions_folder, random_string()), 'w').write(random_string()) bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.missing_startup_config_failure()) self.failIf(os.path.exists(bootstrap.rc_eos)) self.failIf(os.path.exists(bootstrap.boot_extensions)) self.failIf(os.path.exists(bootstrap.boot_extensions_folder)) 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(self): bootstrap = Bootstrap() open(bootstrap.rc_eos, 'w').write(random_string()) open(bootstrap.boot_extensions, 'w').write(random_string()) os.makedirs(bootstrap.boot_extensions_folder) open('%s/%s' % (bootstrap.boot_extensions_folder, random_string()), 'w').write(random_string()) bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.missing_startup_config_failure()) self.failIf(os.path.exists(bootstrap.rc_eos)) self.failIf(os.path.exists(bootstrap.boot_extensions)) self.failIf(os.path.exists(bootstrap.boot_extensions_folder)) 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(self): filenames = { 'DEBUG' : '/tmp/ztps-log-%s-debug' % os.getpid(), 'ERROR' : '/tmp/ztps-log-%s-error' % os.getpid(), 'INFO' : '/tmp/ztps-log-%s-info' % os.getpid(), 'bogus' : '/tmp/ztps-log-%s-bogus' % os.getpid() } logging = [] for level, filename in filenames.iteritems(): logging += {'destination' : 'file:%s' % filename, 'level' : level}, for filename in filenames.itervalues(): self.failIf(os.path.isfile(filename)) bootstrap = Bootstrap() bootstrap.ztps.set_config_response(logging=logging) bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.missing_startup_config_failure()) for filename in filenames.itervalues(): self.failUnless(file_log(filename)) self.assertEquals(file_log(filenames['DEBUG'], ignore_string='SyslogManager'), file_log(filenames['bogus'], ignore_string='SyslogManager')) self.assertEquals(file_log(filenames['DEBUG'], ignore_string='SyslogManager'), file_log(filenames['INFO'], ignore_string='SyslogManager')) self.failIfEqual(file_log(filenames['DEBUG'], ignore_string='SyslogManager'), file_log(filenames['ERROR'], ignore_string='SyslogManager')) self.failUnless(set(file_log(filenames['ERROR'])).issubset( set(file_log(filenames['DEBUG'])))) for filename in filenames.itervalues(): remove_file(filename) 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_definition_missing(self): bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.server_connection_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_content_type(self): bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response(content_type='text/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()
def test_node_not_found(self): bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response(status=400) bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.node_not_found_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_definition_missing(self): bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.server_connection_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()
def test(self): filenames = { 'DEBUG': '/tmp/ztps-log-%s-debug' % os.getpid(), 'ERROR': '/tmp/ztps-log-%s-error' % os.getpid(), 'INFO': '/tmp/ztps-log-%s-info' % os.getpid(), 'bogus': '/tmp/ztps-log-%s-bogus' % os.getpid() } logging = [] for level, filename in filenames.iteritems(): logging += {'destination': 'file:%s' % filename, 'level': level}, for filename in filenames.itervalues(): self.failIf(os.path.isfile(filename)) bootstrap = Bootstrap() bootstrap.ztps.set_config_response(logging=logging) bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.missing_startup_config_failure()) for filename in filenames.itervalues(): self.failUnless(file_log(filename)) self.assertEquals( file_log(filenames['DEBUG'], ignore_string='SyslogManager'), file_log(filenames['bogus'], ignore_string='SyslogManager')) self.assertEquals( file_log(filenames['DEBUG'], ignore_string='SyslogManager'), file_log(filenames['INFO'], ignore_string='SyslogManager')) self.failIfEqual( file_log(filenames['DEBUG'], ignore_string='SyslogManager'), file_log(filenames['ERROR'], ignore_string='SyslogManager')) self.failUnless( set(file_log(filenames['ERROR'])).issubset( set(file_log(filenames['DEBUG'])))) for filename in filenames.itervalues(): remove_file(filename) 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_content_type(self): bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response( content_type='text/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()
def test_topology_check(self): bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response(status=400, content_type='text/html') bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.toplogy_check_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 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()
def test_topology_check(self): bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response( status=400, content_type='text/html') bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.toplogy_check_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()
def test_action_success_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': 'startup_config_action', 'onstart': text_onstart, 'onsuccess': text_onsuccess, 'onfailure': text_onfailure, }]) bootstrap.ztps.set_action_response('startup_config_action', startup_config_action()) bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.success()) self.failIf(bootstrap.error) log = ''.join(file_log(log)) self.failUnless('startup_config_action: %s' % text_onstart in log) self.failUnless('startup_config_action: %s' % text_onsuccess in log) self.failUnless('startup_config_action: %s' % text_onfailure not in log) 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_exception(assertion) finally: bootstrap.end_test()
def test_success(self): bootstrap = Bootstrap() bootstrap.ztps.set_config_response() bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response( actions=[{'action' : 'startup_config_action'}]) bootstrap.ztps.set_action_response('startup_config_action', startup_config_action()) bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.success()) 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_status_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(), status=201, 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()
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()
def xmpp_sanity_test(self, xmpp): log = '/tmp/ztps-log-%s-debug' % os.getpid() bootstrap = Bootstrap() bootstrap.ztps.set_config_response(logging=[ {'destination' : 'file:%s' % log, 'level' : 'DEBUG'},], xmpp=xmpp) bootstrap.ztps.set_node_check_response() bootstrap.ztps.set_definition_response() bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.missing_startup_config_failure()) self.failIf(bootstrap.error) self.failIf('XmppClient' not in ''.join(file_log(log))) except AssertionError as assertion: print 'Output: %s' % bootstrap.output print 'Error: %s' % bootstrap.error raise assertion finally: bootstrap.end_test()
def test_action_success_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' : 'startup_config_action', 'onstart' : text_onstart, 'onsuccess' : text_onsuccess, 'onfailure' : text_onfailure, }]) bootstrap.ztps.set_action_response('startup_config_action', startup_config_action()) bootstrap.start_test() try: self.failUnless(bootstrap.eapi_node_information_collected()) self.failUnless(bootstrap.success()) self.failIf(bootstrap.error) log = ''.join(file_log(log)) self.failUnless('startup_config_action:%s' % text_onstart in log) self.failUnless('startup_config_action:%s' % text_onsuccess in log) self.failUnless('startup_config_action:%s' % text_onfailure not in log) 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_exception(assertion) finally: bootstrap.end_test()