def test_register_two_cluster_instances(self): nodes = REGISTRY['clusters']['cluster1']['nodes'] services = REGISTRY['clusters']['cluster1']['services'] dn = registry.instantiate(user='******', product='a', version='1.0.0', nodes=nodes, services=services) expected = registry.PREFIX + '/jlopez/a/1.0.0/1' self.assertEqual(dn, expected) dn = registry.instantiate(user='******', product='a', version='1.0.0', nodes=nodes, services=services) expected = registry.PREFIX + '/jlopez/a/1.0.0/2' self.assertEqual(dn, expected)
def launch_cluster(product, version): """Launch a new cluster instance""" app.logger.info('Request to launch a new cluster instance from user {}' .format(g.user)) username = g.user options = request.get_json() app.logger.info('Registering the cluster instance in the registry') cluster = registry.instantiate(username, product, version, options) clusterdn = cluster.dn # cluster.name has the ID number of the cluster: eg. 6 id = cluster.name cluster.status = 'registered' app.logger.info('Submitting cluster instance to Mesos') data = {'clusterdn': clusterdn} response = requests.post(MESOS_FRAMEWORK_ENDPOINT, json=data) if response.status_code != 200: app.logger.error('Mesos framework returned {}'.format(response.status_code)) app.logger.error('{}'.format(response.json())) abort(500) app.logger.info('Launching orchestrator thread') utils.launch_orchestrator_when_ready(clusterdn) return '', 201, { 'Location': url_for('api.get_cluster', username=username, product=product, version=version, id=id, _external=True)}
def test_get_optional_attributes(self): servicename = self.servicename version = "0.1.0" description = "Unit test" template = TEMPLATE templateopts = OPTIONS registry.register(servicename, version, description, template, templateopts, templatetype='json+jinja2') user = '******' options = {'slaves.number': 1} cluster = registry.instantiate(user, servicename, version, options) nodes = cluster.nodes for node in nodes: if(registry.parse_endpoint_last_element(str(node)) == "master0"): required_node = node.get("required_node") expected = None self.assertEqual(required_node, expected) custom_disks = node.get("use_custom_disks") expected = "True" self.assertEqual(custom_disks, expected) elif(registry.parse_endpoint_last_element(str(node)) == "master1"): required_node = node.get("required_node") expected = "c13-1" self.assertEqual(required_node, expected) custom_disks = node.get("use_custom_disks") expected = None self.assertEqual(custom_disks, expected) elif (registry.parse_endpoint_last_element(str(node)) == "slave0"): pass else: raise Exception("Unidentified node")
def _add_sample_service_instance(self): servicename = self.servicename version = "0.1.0" description = "Unit test" template = TEMPLATE templateopts = OPTIONS registry.register(servicename, version, description, template, templateopts) user = '******' options = {'slaves.number': 1} cluster = registry.instantiate(user, servicename, version, options) return cluster
def test_get_resources_names(self): servicename = self.servicename version = "0.1.0" description = "Unit test" template = TEMPLATE templateopts = OPTIONS registry.register(servicename, version, description, template, templateopts, templatetype='json+jinja2') user = '******' options = {'slaves.number': 1} cluster = registry.instantiate(user, servicename, version, options) nodes = cluster.nodes for node in nodes: if (registry.parse_endpoint_last_element(str(node)) == "master0"): self.assertEqual(node.name, "master0") disks = node.disks disk_names = [disk.name for disk in disks] self.assertEqual(sorted(disk_names), ["disk2", "disk3"]) networks = node.networks network_names = [network.name for network in networks] network_types = [network.networkname for network in networks] self.assertEqual(sorted(network_names), ["eth0", "eth1"]) self.assertEqual(sorted(network_types), ["admin", "storage"]) elif (registry.parse_endpoint_last_element( str(node)) == "master1"): self.assertEqual(node.name, "master1") disks = node.disks self.assertEqual(disks, "2") networks = node.networks network_names = [network.name for network in networks] network_types = [network.networkname for network in networks] self.assertEqual(sorted(network_names), ["eth0", "eth1", "eth2"]) self.assertEqual(sorted(network_types), ["admin", "heartbeat", "storage"]) elif (registry.parse_endpoint_last_element(str(node)) == "slave0"): self.assertEqual(node.name, "slave0") else: raise Exception("Unidentified node")
def test_get_cluster_instance(self): nodes = REGISTRY['clusters']['cluster1']['nodes'] services = REGISTRY['clusters']['cluster1']['services'] dn = registry.instantiate(user='******', product='a', version='1.0.0', nodes=nodes, services=services) instance = registry.get_cluster(dn=dn) expected_dn = registry.PREFIX + '/jlopez/a/1.0.0/1' expected_nodes = [ registry.Node('{}/nodes/{}'.format(expected_dn, e)) for e in nodes ] expected_services = [ registry.Service('{}/services/{}'.format(expected_dn, e)) for e in services ] self.assertEqual(sorted(instance.nodes), sorted(expected_nodes)) self.assertEqual(sorted(instance.services), sorted(expected_services))
def test_add_instance_jsontemplate(self): servicename = self.servicename version = "0.1.0" description = "Unit test" template = TEMPLATE templateopts = OPTIONS registry.register(servicename, version, description, template, templateopts, templatetype='json+jinja2') user = '******' options = {'slaves.number': 2} cluster = registry.instantiate(user, servicename, version, options) ## expected 4 nodes: 2 slaves + 2 masters self.assertEqual(len(cluster.nodes), options['slaves.number'] + 2) self.assertEqual(len(cluster.services), 2) self.assertEqual(cluster.nodes[0].networks[0].networkname, 'admin')
def test_get_resources_names(self): servicename = self.servicename version = "0.1.0" description = "Unit test" template = TEMPLATE templateopts = OPTIONS registry.register(servicename, version, description, template, templateopts, templatetype='json+jinja2') user = '******' options = {'slaves.number': 1} cluster = registry.instantiate(user, servicename, version, options) nodes = cluster.nodes for node in nodes: if (registry.parse_endpoint_last_element(str(node)) == "master0"): self.assertEqual(node.name, "master0") disks = node.disks disk_names = [disk.name for disk in disks] self.assertEqual(sorted(disk_names), ["disk2", "disk3"]) networks = node.networks network_names = [network.name for network in networks] network_types = [network.networkname for network in networks] self.assertEqual(sorted(network_names), ["eth0", "eth1"]) self.assertEqual(sorted(network_types), ["admin", "storage"]) elif (registry.parse_endpoint_last_element(str(node)) == "master1"): self.assertEqual(node.name, "master1") disks = node.disks self.assertEqual(disks, "2") networks = node.networks network_names = [network.name for network in networks] network_types = [network.networkname for network in networks] self.assertEqual(sorted(network_names), ["eth0", "eth1", "eth2"]) self.assertEqual(sorted(network_types), ["admin", "heartbeat", "storage"]) elif (registry.parse_endpoint_last_element(str(node)) == "slave0"): self.assertEqual(node.name, "slave0") else: raise Exception("Unidentified node")
def test_add_instance_yamltemplate(self): servicename = self.servicename version = "0.1.0" description = "Unit test" template = TEMPLATEYAML templateopts = OPTIONS registry.register(servicename, version, description, template, templateopts, templatetype='yaml+jinja2') user = '******' options = {'slaves.number': 2} cluster = registry.instantiate(user, servicename, version, options) ## expected 4 nodes: 2 slaves + 2 masters self.assertEqual(len(cluster.nodes), options['slaves.number'] + 2) self.assertEqual(len(cluster.services), 2) self.assertEqual(cluster.nodes[0].networks[0].networkname, 'admin')
def test_get_optional_attributes(self): servicename = self.servicename version = "0.1.0" description = "Unit test" template = TEMPLATE templateopts = OPTIONS registry.register(servicename, version, description, template, templateopts, templatetype='json+jinja2') user = '******' options = {'slaves.number': 1} cluster = registry.instantiate(user, servicename, version, options) nodes = cluster.nodes for node in nodes: if (registry.parse_endpoint_last_element(str(node)) == "master0"): required_node = node.get("required_node") expected = None self.assertEqual(required_node, expected) custom_disks = node.get("use_custom_disks") expected = "True" self.assertEqual(custom_disks, expected) elif (registry.parse_endpoint_last_element( str(node)) == "master1"): required_node = node.get("required_node") expected = "c13-1" self.assertEqual(required_node, expected) custom_disks = node.get("use_custom_disks") expected = None self.assertEqual(custom_disks, expected) elif (registry.parse_endpoint_last_element(str(node)) == "slave0"): pass else: raise Exception("Unidentified node")