Exemplo n.º 1
0
 def test_caching(self):
     api = Api(os.environ['CONFINE_SERVER_API'], cache=True)
     api.nodes.retrieve()
     self.assertEqual(0, api.cache.hits)
     self.assertEqual(2, api.cache.misses)
     nodes = api.nodes.retrieve()
     self.assertEqual(1, api.cache.hits)
     self.assertEqual(2, api.cache.misses)
     for node in nodes:
         node.retrieve()
     self.assertEqual(len(nodes) + 2, api.cache.misses)
     self.assertEqual(1, api.cache.hits)
     for node in nodes:
         node.retrieve()
     self.assertEqual(len(nodes) + 1, api.cache.hits)
     self.assertEqual(len(nodes) + 2, api.cache.misses)
     api.cache.invalidate()
     self.assertEqual(0, api.stats['conditional'])
     for node in nodes:
         node.retrieve()
     self.assertEqual(len(nodes), api.stats['conditional'])
     api.cache.remove()
     for node in nodes:
         node.retrieve()
     self.assertEqual(len(nodes), api.stats['conditional'])
     self.assertEqual((2 * len(nodes)) + 1, api.cache.hits)
     self.assertEqual((2 * len(nodes)) + 2, api.cache.misses)
Exemplo n.º 2
0
 def test_retrieve_base(self):
     group = self.api.groups.retrieve()[0]
     name = 'RandomNode-%s' % random_ascii(10)
     self.test_login()
     node = self.api.nodes.create(name=name, group=group)
     controller = Api(node.uri)
     controller.retrieve()
     self.assertEqual(self.api, controller)
     self.assertEqual(self.api._data, controller._data)
Exemplo n.º 3
0
 def setUp(self):
     from orm.api import Api
     super(BaseLiveServerTestCase, self).setUp()
     self.rest = Api(self.live_server_url + '/api/')
     self.rest.enable_logging()
     self.account = self.create_account(superuser=True)
Exemplo n.º 4
0
 def setUp(self):
     self.api = Api(os.environ['CONFINE_SERVER_API'])
Exemplo n.º 5
0
def split_len(seq, length):
    """ Returns seq broken in a list of strings of length length """
    return [seq[i:i+length] for i in range(0, len(seq), length)]


def int_to_hex_str(number, digits):
    hex_str = ('%.' + str(digits) + 'x') % number
    err_msg = "Hex representation of %d doesn't fit in %s digits" % (number, digits)
    assert len(hex_str) <= digits, err_msg
    return hex_str


def ipv6_addr(node_id, slice_id, iface_nr=2):
    # Here we assume that mgmt iface.nr value is always 2
    nr = '10' + int_to_hex_str(iface_nr, 2)
    node_id = int_to_hex_str(node_id, 4)
    slice_id = int_to_hex_str(slice_id, 12)
    ipv6_words = MGMT_IPV6_PREFIX.split(':')[:3]
    ipv6_words.extend([node_id, nr])
    ipv6_words.extend(split_len(slice_id, 4))
    return ':'.join(ipv6_words)


controller = Api('https://controller.community-lab.net/api/')
MGMT_IPV6_PREFIX = controller.testbed_params.mgmt_ipv6_prefix
slivers = controller.slivers.retrieve()
slivers.retrieve_related('node', 'slice')
for sliver in slivers.filter(slice__id=249):
    print(ipv6_addr(sliver.node.id, sliver.slice.id))