Esempio n. 1
0
if os.environ.get('CLUSTERDN'):
    CLUSTERDN = os.environ.get('CLUSTERDN')
else:
    eprint(
        red('An instance endpoint has to be provided using the CLUSTERDN environment variable'
            ))
    sys.exit(2)

if os.environ.get('REGISTRY'):
    REGISTRY = os.environ.get('REGISTRY')
else:
    REGISTRY = 'http://consul.service.int.cesga.es:8500/v1/kv'

# Retrieve info from the registry
registry.connect(REGISTRY)
cluster = registry.Cluster(CLUSTERDN)
nodes = cluster.nodes
services = cluster.services


def wait_until_node_is_running(node):
    """Wait until node is in status running: i.e. docker-executor finished"""
    name = node.name
    retry = 0
    while not node.status == 'running':
        retry += 1
        if retry > MAX_RETRIES: sys.exit(3)
        print('Waiting for node {}: {}/{}'.format(name, retry, MAX_RETRIES))
        time.sleep(DELAY)

 def test_get_cluster_status(self):
     cluster = registry.Cluster(BASEDN + '/cluster1')
     expected = REGISTRY[PREFIX][USER][PRODUCT][VERSION]['cluster1']['status']
     status = cluster.status
     self.assertEqual(status, expected)
 def test_get_cluster_services(self):
     cluster = registry.Cluster(BASEDN + '/cluster1')
     services = REGISTRY[PREFIX][USER][PRODUCT][VERSION]['cluster1']['services'].keys()
     expected = [registry.Service('{}/cluster1/services/{}'.format(BASEDN, e)) for e in services]
     self.assertEqual(sorted(cluster.services), sorted(expected))
 def test_get_cluster_instance(self):
     basedn = BASEDN + '/cluster1/nodes/master0'
     node = registry.Node(basedn)
     cluster = node.cluster
     expected = registry.Cluster(BASEDN + '/cluster1')
     self.assertEqual(cluster, expected)