def test_parse_no_add_on(self): flist = cli_mock.create_file('host1\nhost2\nleft2') ulist = cli_mock.create_file('user1\nuser2\nuser3\n') sys.argv = ['atest', '-U', ulist.name, '--kill-on-failure', '-M', flist.name] self.atest.parser.add_option('-M', '--mlist', type='string') self.atest.parser.add_option('-U', '--ulist', type='string') self.atest.parser.add_option('-u', '--user', type='string') host_info = topic_common.item_parse_info(attribute_name='hosts', filename_option='mlist', use_leftover=True) user_info = topic_common.item_parse_info(attribute_name='users', inline_option='user', filename_option='ulist') (options, leftover) = self.atest.parse([host_info, user_info]) self.assertEqualNoOrder(self.atest.hosts, ['left2', 'host1', 'host2']) self.assertEqualNoOrder(self.atest.users, ['user1', 'user2', 'user3']) self.assertEqual({'mlist': flist.name, 'ulist': ulist.name, 'user': None, 'web_server': None, 'parse': False, 'parse_delim': '|', 'kill_on_failure': True, 'verbose': False, 'debug': False}, options) self.assertEqual(leftover, []) flist.clean() ulist.clean()
def test_parse_no_add_on_2(self): flist = cli_mock.create_file('host1\nhost2\nleft2') ulist = cli_mock.create_file('user1\nuser2\nuser3\n') sys.argv = [ 'atest', '-U', ulist.name, '--kill-on-failure', '-M', flist.name ] self.atest.parser.add_option('-M', '--mlist', type='string') self.atest.parser.add_option('-U', '--ulist', type='string') self.atest.parser.add_option('-u', '--user', type='string') host_info = topic_common.item_parse_info(attribute_name='hosts', filename_option='mlist', use_leftover=True) user_info = topic_common.item_parse_info(attribute_name='users', inline_option='user', filename_option='ulist') (options, leftover) = self.atest.parse([host_info, user_info]) self.assertEqualNoOrder(self.atest.hosts, ['left2', 'host1', 'host2']) self.assertEqualNoOrder(self.atest.users, ['user1', 'user2', 'user3']) self.assertEqual( { 'mlist': flist.name, 'ulist': ulist.name, 'user': None, 'web_server': None, 'parse': False, 'parse_delim': '|', 'kill_on_failure': True, 'verbose': False, 'debug': False }, options) self.assertEqual(leftover, []) flist.clean() ulist.clean()
def test_parse_add_on(self): flist = cli_mock.create_file('host1\nhost2\nleft2') sys.argv = [ 'atest', '--web', 'fooweb', '--parse', '--kill-on-failure', 'left1', 'left2', '-M', flist.name ] self.atest.parser.add_option('-M', '--mlist', type='string') item_info = topic_common.item_parse_info(attribute_name='hosts', filename_option='mlist', use_leftover=True) (options, leftover) = self.atest.parse([item_info]) self.assertEqualNoOrder(self.atest.hosts, ['left1', 'left2', 'host1', 'host2']) self.assertEqual( { 'mlist': flist.name, 'web_server': 'fooweb', 'parse': True, 'parse_delim': '|', 'kill_on_failure': True, 'verbose': False, 'debug': False }, options) self.assertEqual(leftover, []) flist.clean()
def test_parse_list_acl(self): acl_list = acl.acl_list() afile = cli_mock.create_file("acl0\nacl3\nacl4\n") sys.argv = ["atest", "acl0", "acl1,acl2", "--alist", afile.name, "acl5", "acl6,acl7"] acl_list.parse() self.assertEqualNoOrder(["acl%s" % x for x in range(8)], acl_list.acls) afile.clean()
def test_parse_list_acl(self): acl_list = acl.acl_list() afile = cli_mock.create_file('acl0\nacl3\nacl4\n') sys.argv = ['atest', 'acl0', 'acl1,acl2', '--alist', afile.name, 'acl5', 'acl6,acl7'] acl_list.parse() self.assertEqualNoOrder(['acl%s' % x for x in range(8)], acl_list.acls) afile.clean()
def test_parse_with_users(self): ul = user.user_list() ufile = cli_mock.create_file('user0\nuser3\nuser4\n') sys.argv = ['atest', 'user1', '--ulist', ufile.name, 'user3'] (options, leftover) = ul.parse() self.assertEqualNoOrder(['user0', 'user1', 'user3', 'user4'], ul.users) self.assertEqual(leftover, []) ufile.clean()
def test_parse_list_acl(self): acl_list = acl.acl_list() afile = cli_mock.create_file('acl0\nacl3\nacl4\n') sys.argv = [ 'atest', 'acl0', 'acl1,acl2', '--alist', afile.name, 'acl5', 'acl6,acl7' ] acl_list.parse() self.assertEqualNoOrder(['acl%s' % x for x in range(8)], acl_list.acls) afile.clean()
def test_acl_delete_multiple_acl_ok(self): alist = cli_mock.create_file("acl2\nacl1") self.run_cmd( argv=["atest", "acl", "delete", "acl0", "acl1", "--alist", alist.name], rpcs=[ ("delete_acl_group", {"id": "acl0"}, True, None), ("delete_acl_group", {"id": "acl1"}, True, None), ("delete_acl_group", {"id": "acl2"}, True, None), ], out_words_ok=["acl0", "acl1", "acl2", "Deleted"], ) alist.clean()
def test_execute_list_all_with_user_verbose(self): ufile = cli_mock.create_file('user0 user1\n') self.run_cmd(argv=['atest', 'user', 'list', '--ulist', ufile.name, '-v'], rpcs=[('get_users', {'login__in': ['user0', 'user1']}, True, [{u'access_level': 2, u'login': u'user0', u'id': 3}, {u'access_level': 5, u'login': u'user1', u'id': 4}])], out_words_ok=['user0', 'user1', '3', '4', '5']) ufile.clean()
def test_acl_delete_multiple_acl_ok(self): alist = cli_mock.create_file('acl2\nacl1') self.run_cmd(argv=[ 'atest', 'acl', 'delete', 'acl0', 'acl1', '--alist', alist.name ], rpcs=[('delete_acl_group', { 'id': 'acl0' }, True, None), ('delete_acl_group', { 'id': 'acl1' }, True, None), ('delete_acl_group', { 'id': 'acl2' }, True, None)], out_words_ok=['acl0', 'acl1', 'acl2', 'Deleted']) alist.clean()
def test_acl_delete_multiple_acl_ok(self): alist = cli_mock.create_file('acl2\nacl1') self.run_cmd(argv=['atest', 'acl', 'delete', 'acl0', 'acl1', '--alist', alist.name], rpcs=[('delete_acl_group', {'id': 'acl0'}, True, None), ('delete_acl_group', {'id': 'acl1'}, True, None), ('delete_acl_group', {'id': 'acl2'}, True, None)], out_words_ok=['acl0', 'acl1', 'acl2', 'Deleted']) alist.clean()
def test_acl_delete_multiple_acl_bad(self): alist = cli_mock.create_file("acl2\nacl1") self.run_cmd( argv=["atest", "acl", "delete", "acl0", "acl1", "--alist", alist.name], rpcs=[ ("delete_acl_group", {"id": "acl0"}, True, None), ( "delete_acl_group", {"id": "acl1"}, False, "DoesNotExist: acl_group " "matching query does not exist.", ), ("delete_acl_group", {"id": "acl2"}, True, None), ], out_words_ok=["acl0", "acl2", "Deleted"], err_words_ok=["acl1", "delete_acl_group", "DoesNotExist", "acl_group", "matching"], ) alist.clean()
def test_parse_no_add_on(self): flist = cli_mock.create_file('host1\nhost2\nleft2') sys.argv = ['atest', '--web', 'fooweb', '--parse', '-g', '--kill-on-failure', 'left1', 'left2', '-M', flist.name] self.atest.parser.add_option('-M', '--mlist', type='string') item_info = topic_common.item_parse_info(attribute_name='hosts', filename_option='mlist') (options, leftover) = self.atest.parse([item_info]) self.assertEqualNoOrder(self.atest.hosts, ['left2', 'host1', 'host2']) self.assertEqual({'mlist': flist.name, 'web_server': 'fooweb', 'parse': True, 'parse_delim': '|', 'kill_on_failure': True, 'verbose': False, 'debug': True}, options) self.assertEqual(leftover, ['left1', 'left2']) flist.clean()
def test_acl_delete_multiple_acl_bad(self): alist = cli_mock.create_file('acl2\nacl1') self.run_cmd(argv=[ 'atest', 'acl', 'delete', 'acl0', 'acl1', '--alist', alist.name ], rpcs=[('delete_acl_group', { 'id': 'acl0' }, True, None), ('delete_acl_group', { 'id': 'acl1' }, False, 'DoesNotExist: acl_group ' 'matching query does not exist.'), ('delete_acl_group', { 'id': 'acl2' }, True, None)], out_words_ok=['acl0', 'acl2', 'Deleted'], err_words_ok=[ 'acl1', 'delete_acl_group', 'DoesNotExist', 'acl_group', 'matching' ]) alist.clean()
def test_acl_delete_multiple_acl_bad(self): alist = cli_mock.create_file('acl2\nacl1') self.run_cmd(argv=['atest', 'acl', 'delete', 'acl0', 'acl1', '--alist', alist.name], rpcs=[('delete_acl_group', {'id': 'acl0'}, True, None), ('delete_acl_group', {'id': 'acl1'}, False, 'DoesNotExist: acl_group ' 'matching query does not exist.'), ('delete_acl_group', {'id': 'acl2'}, True, None)], out_words_ok=['acl0', 'acl2', 'Deleted'], err_words_ok=['acl1', 'delete_acl_group', 'DoesNotExist', 'acl_group', 'matching']) alist.clean()
class opt(object): flist_obj = cli_mock.create_file('f\nc\na\n') flist = flist_obj.name inline = 'a b,c,d e'
class opt(object): flist_obj = cli_mock.create_file('a, b c\nd,e, \nf,\ng h,i ,') flist = flist_obj.name
class opt(object): flist_obj = cli_mock.create_file('a,b,c\nd,e\nf\n') flist = flist_obj.name
class opt(object): flist_obj = cli_mock.create_file('a\nb\\\\\\,c\\,d\nef\\\\,g') flist = flist_obj.name
class opt(object): flist_obj = cli_mock.create_file('a\nb\nc\n') flist = flist_obj.name
class opt(object): flist_obj = cli_mock.create_file('a b c\nd,e\nf\ng, \n, ,,') flist = flist_obj.name inline = 'a b,c,d h, , ,, '
class opt(object): flist_obj = cli_mock.create_file('a\\,b\\,c\nd,e\nf\ng') flist = flist_obj.name inline = 'a\\,b\\,c,d h'
class opt(object): flist_obj = cli_mock.create_file( 'a\\,b\\\\\\,c\nd,e\nf,ghi, ,, j,') flist = flist_obj.name inline = 'a\\,b\\\\\\,c,d h,ijk'