def checker(got): if len(expected) != len(got): raise AssertionError('Expected %s entries, got %s\n\n%s\n%s' % (len(expected), len(got), expected, got)) for e, g in zip(expected, got): assert_deepequal(e, g) return True
def check_command(self, commandline, expected_command_name, **kw_expected): argv = shlex.split(commandline) executioner = api.Backend.cli cmd = executioner.get_command(argv) kw_got = executioner.argv_to_keyword_arguments(cmd, argv[1:]) util.assert_deepequal(expected_command_name, cmd.name, 'Command name') util.assert_deepequal(kw_expected, kw_got)
def check_tofiles(self): """Check automountlocation_tofiles output against self.tofiles_output """ res = api.Command['automountlocation_tofiles'](self.locname) mock_ui = MockTextui() command = api.Command['automountlocation_tofiles'] command.output_for_cli(mock_ui, res, self.locname) expected_output = self.tofiles_output assert_deepequal(expected_output, u'\n'.join(mock_ui))
def check_import_roundtrip(self): """Check automountlocation_tofiles/automountlocation_import roundtrip Loads self.tofiles_output (which should correspond to automountlocation_tofiles output), then checks the resulting map against tofiles_output again. Do not use this if the test creates maps that aren't connected to auto.master -- these can't be imported successfully. """ conf_directory = tempfile.mkdtemp() # Parse the tofiles_output into individual files, replace /etc/ by # our temporary directory name current_file = None for line in self.tofiles_output.splitlines(): line = line.replace('/etc/', '%s/' % conf_directory) if line.startswith(conf_directory) and line.endswith(':'): current_file = open(line.rstrip(':'), 'w') elif '--------' in line: current_file.close() elif line.startswith('maps not connected to '): break else: current_file.write(line + '\n') current_file.close() self.failsafe_add(api.Object.automountlocation, self.locname) try: # Feed the files to automountlocation_import & check master_file = u'%s/auto.master' % conf_directory automountlocation_import = api.Command['automountlocation_import'] res = automountlocation_import(self.locname, master_file) assert_deepequal(dict( result=dict( keys=lambda k: k, maps=lambda m: m, skipped=(), duplicatemaps=(), duplicatekeys=(), )), res) self.check_tofiles() finally: res = api.Command['automountlocation_del'](self.locname)['result'] assert res assert_attr_equal(res, 'failed', '') # Success; delete the temporary directory shutil.rmtree(conf_directory)
def test_a2_automountmap_tofiles(self): """ Test the `automountlocation_tofiles` command. """ res = api.Command['automountlocation_tofiles'](self.locname) assert_deepequal(dict( result=dict( keys={'auto.direct': ()}, orphanmaps=(dict( dn=DN(('automountmapname', self.mapname), ('cn', self.locname), ('cn', 'automount'), api.env.basedn), description=(u'description of map',), automountmapname=(u'testmap',)),), orphankeys=[( dict( dn=DN(('description', self.keyname2), ('automountmapname', 'testmap'), ('cn', self.locname), ('cn', 'automount'), api.env.basedn), automountkey=(self.keyname2,), description=(self.keyname2,), automountinformation=(u'ro',), ), dict( dn=DN(('description', self.keyname_rename), ('automountmapname', 'testmap'), ('cn', self.locname), ('cn', 'automount'), api.env.basedn), automountkey=(self.keyname_rename,), description=(self.keyname_rename,), automountinformation=(u'rw',), ))], maps=( dict( dn=DN(('description', '/- auto.direct'), ('automountmapname', 'auto.master'), ('cn', self.locname), ('cn', 'automount'), api.env.basedn), automountkey=(u'/-',), description=(u'/- auto.direct',), automountinformation=(u'auto.direct',) ), ))), res) # Also check the CLI output self.check_tofiles()
def check_output(self, nice, cmd, args, options, expected, extra_check): got = api.Command[cmd](*args, **options) assert_deepequal(expected, got, nice) if extra_check and not extra_check(got): raise AssertionError('Extra check %s failed' % extra_check)
try: output = api.Command[cmd](*args, **options) except StandardError, e: pass else: raise AssertionError(EXPECTED % (cmd, name, args, options, output)) if not isinstance(e, klass): raise AssertionError( UNEXPECTED % (cmd, name, args, options, e.__class__.__name__, e)) # FIXME: the XML-RPC transport doesn't allow us to return structured # information through the exception, so we can't test the kw on the # client side. However, if we switch to using JSON-RPC for the default # transport, the exception is a free-form data structure (dict). # For now just compare the strings assert_deepequal(expected.strerror, e.strerror) def check_callable(self, nice, cmd, args, options, expected): output = dict() e = None try: output = api.Command[cmd](*args, **options) except StandardError, e: pass if not expected(e, output): raise AssertionError(UNEXPECTED % (cmd, args, options, e.__class__.__name__, e)) def check_output(self, nice, cmd, args, options, expected, extra_check): got = api.Command[cmd](*args, **options) assert_deepequal(expected, got, nice)