def test_attr(table=None, owner=None): """ Tests the Scoping rules for attributes. Called without arguments this test the global attributes. table = os | environment | appliance | host owner = osname | environmentname | appliancename | hostname """ if not table: table = '' if not owner: owner = '' attr = 'a.b.c.d' result = Call('remove %s attr' % table, ('%s attr=%s' % (owner, attr)).split()) assert ReturnCode() == 0 and result == [] value = str(random.randint(0, 100)) result = Call('set %s attr' % table, ('%s attr=%s value=%s' % (owner, attr, value)).split()) assert ReturnCode() == 0 and result == [] result = Call('list %s attr' % table, ('%s attr=%s' % (owner, attr)).split()) assert ReturnCode() == 0 and len(result) == 1 assert result[0]['attr'] == attr assert result[0]['value'] == value result = Call('remove %s attr' % table, ('%s attr=%s' % (owner, attr)).split()) assert ReturnCode() == 0 and result == []
def test_name_does_not_exist(): for o in [ 'appliance', 'box', 'cart', 'environment', 'host', 'network', 'os', 'pallet' ]: result = Call('list %s' % o, [DNE], stderr=False) assert ReturnCode() == 255
def setup_module(module): Call('add environment %s' % ENVIRONMENT) for rack in range(1000, 1000 + NUMRACKS): for rank in range(0, RACKSIZE): host = 'backend-%d-%d' % (rack, rank) Call('add host %s environment=%s' % (host, ENVIRONMENT)) Call('set environment attr %s attr=key value=value' % ENVIRONMENT) result = Call('list host %s' % ENVIRONMENT) assert ReturnCode() == 0 and len(result) == (NUMRACKS * RACKSIZE)
def setup_hosts(numHosts): rackSize = 40 t0 = time.time() rank = rack = 999 # start at rack 1000 (yeah I know this could be smarter) for i in range(0, numHosts): if rank >= rackSize: rank = 0 rack += 1 hostname = 'backend-%d-%d' % (rack, rank) Call('add host %s environment=%s' % (hostname, ENVIRONMENT)) rank += 1 t = (time.time() - t0) print('add host'.ljust(32), '%.3fs' % t) result = Call('list host e:%s' % ENVIRONMENT) assert ReturnCode() == 0 and len(result) == (numHosts)
def test_box(): """ Test list/add/remove/set box. """ # Search for a unused box name and use it for # the following tests. done = False while not done: box = 'default-%s' % str(random.randint(0, 100)) result = Call('list box', [box], stderr=False) if ReturnCode() and not result: done = True assert box # add box result = Call('add box', [box]) assert ReturnCode() == 0 and result == [] # lookup current box for host result = Call('list host', ['localhost']) assert ReturnCode() == 0 and len(result) == 1 prevBox = result[0]['box'] # set box for this host result = Call('set host box', ['localhost', 'box=%s' % box]) assert ReturnCode() == 0 # verify box was set result = Call('list host', ['localhost']) assert ReturnCode() == 0 and len(result) == 1 assert result[0]['box'] == box # restore prev setting result = Call('set host box', ['localhost', 'box=%s' % prevBox]) assert ReturnCode() == 0 # remove box result = Call('remove box', [box]) assert ReturnCode() == 0 # try to remove default # "remove box" should protect against this result = Call('remove box', ['default'], stderr=False) assert ReturnCode() == 255 # remove multiple boxes # Add the first box back result = Call('add box', [box]) assert ReturnCode() == 0 and result == [] # get a second box name done = False while not done: second_box = 'default-%s' % str(random.randint(0, 100)) result = Call('list box', [second_box], stderr=False) if ReturnCode() and not result: done = True assert second_box result = Call('add box', [second_box]) assert ReturnCode() == 0 and result == [] # remove multiple boxes result = Call('remove box', [box, second_box]) assert ReturnCode() == 0