Adoption of pre-0.5 environment API to MuranoPL format

This is transitional API with minimum possible changes from API of Murano 0.4

Change-Id: Ic29e4cdbae13c6fdc388c005719aa4235bdccfa6
Closes-bug: #1297791
This commit is contained in:
Stan Lagun 2014-03-26 15:31:22 +04:00
parent f439c60555
commit e006eaf133
14 changed files with 364 additions and 220 deletions

View File

@ -18,6 +18,7 @@ from tempest.common import rest_client
from tempest import config
from tempest import exceptions
import testtools
import uuid
CONF = config.CONF
@ -202,6 +203,10 @@ class TestCase(testtools.TestCase):
def create_demo_service(self, environment_id, session_id):
post_body = {
"?": {
"id": uuid.uuid4().hex,
"type": "io.murano.tests.demoService"
},
"availabilityZone": "nova",
"name": "demo",
"unitNamingPattern": "host",
@ -212,8 +217,7 @@ class TestCase(testtools.TestCase):
},
"units": [{}],
"flavor": "m1.small",
"configuration": "standalone",
"type": "demoService"
"configuration": "standalone"
}
return self.client.create_service(environment_id,

View File

@ -94,7 +94,7 @@ class TestServices(base.TestCase):
resp, _ = self.client.delete_service(env['id'],
sess['id'],
service['id'])
service['?']['id'])
_, services_list_ = self.client.get_services_list(env['id'],
sess['id'])
@ -139,7 +139,7 @@ class TestServices(base.TestCase):
self.client.delete_service,
None,
sess['id'],
service['id'])
service['?']['id'])
@attr(type='negative')
def test_delete_demo_service_without_session_id(self):
@ -154,7 +154,7 @@ class TestServices(base.TestCase):
self.client.delete_service,
env['id'],
"",
service['id'])
service['?']['id'])
@attr(type='negative')
def test_double_delete_service(self):
@ -165,13 +165,13 @@ class TestServices(base.TestCase):
_, service = self.create_demo_service(env['id'], sess['id'])
self.client.delete_service(env['id'], sess['id'], service['id'])
self.client.delete_service(env['id'], sess['id'], service['?']['id'])
self.assertRaises(exceptions.NotFound,
self.client.delete_service,
env['id'],
sess['id'],
service['id'])
service['?']['id'])
@attr(type='smoke')
def test_get_service(self):
@ -184,7 +184,7 @@ class TestServices(base.TestCase):
resp, service_ = self.client.get_service(env['id'],
sess['id'],
service['id'])
service['?']['id'])
self.assertEqual(resp.status, 200)
self.assertEqual(service, service_)
@ -202,7 +202,7 @@ class TestServices(base.TestCase):
self.client.get_service,
None,
sess['id'],
service['id'])
service['?']['id'])
@testtools.skip("https://bugs.launchpad.net/murano/+bug/1295573")
@attr(type='negative')
@ -218,4 +218,4 @@ class TestServices(base.TestCase):
self.client.get_service,
env['id'],
"",
service['id'])
service['?']['id'])

View File

@ -56,7 +56,7 @@ class Controller(object):
entity_ids = []
if 'services' in environment:
for service in environment['services']:
if service['id'] in service_id_set:
if service['?']['id'] in service_id_set:
id_map = utils.build_entity_map(service)
entity_ids = entity_ids + id_map.keys()
if entity_ids:

View File

@ -137,7 +137,7 @@ class Controller(object):
session = db_session.get_session()
result = {}
for service in services:
service_id = service['id']
service_id = service['?']['id']
entity_ids = utils.build_entity_map(service).keys()
last_status = session.query(models.Status). \
filter(models.Status.entity_id.in_(entity_ids)). \

View File

@ -42,14 +42,14 @@ class TaskProcessingEndpoint(object):
log.info('Starting processing task: {0}'.format(anyjson.dumps(s_task)))
env = environment.Environment()
env.token = task['Objects']['?']['token']
env.tenant_id = task['Objects']['?']['tenant_id']
env.token = task['token']
env.tenant_id = task['tenant_id']
cl = simple_cloader.SimpleClassLoader(config.CONF.metadata_dir)
system.register(cl, config.CONF.metadata_dir)
exc = executor.MuranoDslExecutor(cl, env)
obj = exc.load(task)
obj = exc.load(task['model'])
obj.type.invoke('deploy', exc, obj, {})

View File

@ -42,13 +42,15 @@ class ResultEndpoint(object):
LOG.debug(_('Got result from orchestration '
'engine:\n{0}'.format(secure_result)))
result_id = result['Objects']['?']['id']
if 'deleted' in result:
LOG.debug(_('Result for environment {0} is dropped. Environment '
'is deleted'.format(result['id'])))
'is deleted'.format(result_id)))
return
unit = session.get_session()
environment = unit.query(models.Environment).get(result['id'])
environment = unit.query(models.Environment).get(result_id)
if not environment:
LOG.warning(_('Environment result could not be handled, specified '

View File

@ -44,7 +44,7 @@ class StatsCollectingService(service.Service):
self.tg.add_thread(self._collect_stats_loop)
def stop(self):
self(StatsCollectingService, self).stop()
super(StatsCollectingService, self).stop()
def _collect_stats_loop(self):
period = CONF_STATS.period * 60

View File

@ -63,7 +63,11 @@ class TraverseHelper(object):
if isinstance(source, types.ListType):
idx_source = source
source = next((i for i in source if i['id'] == path), None)
iterator = (
i for i in source
if i.get('?', {}).get('id') == path
)
source = next(iterator, None)
if source is None and path.isdigit():
source = idx_source[int(path)]
elif isinstance(source, types.DictionaryType):
@ -128,7 +132,8 @@ class TraverseHelper(object):
key = path[1:].split('/')[-1]
if isinstance(node, types.ListType):
item = next((i for i in node if i['id'] == key), None)
iterator = (i for i in node if i.get('?', {}).get('id') == key)
item = next(iterator, None)
if item is None and key.isdigit():
del node[int(key)]
else:
@ -142,8 +147,8 @@ class TraverseHelper(object):
def build_entity_map(value):
def build_entity_map_recursive(value, id_map):
if isinstance(value, types.DictionaryType):
if 'id' in value:
id_map[value['id']] = value
if '?' in value and 'id' in value['?']:
id_map[value['?']['id']] = value
for k, v in value.iteritems():
build_entity_map_recursive(v, id_map)
if isinstance(value, types.ListType):

View File

@ -19,6 +19,7 @@ import socket
import json
import requests
import uuid
import novaclient.v1_1.client as nvclient
import tempest.api.murano.config as cfg
@ -225,17 +226,29 @@ class MuranoTest(tempest.test.BaseTestCase):
environment_id - ID of current environment
session_id - ID of current session
"""
post_body = {"type": "activeDirectory", "name": "ad.local",
"adminPassword": "P@ssw0rd", "domain": "ad.local",
"availabilityZone": "nova",
"unitNamingPattern": "adinstance",
"flavor": "m1.medium", "osImage":
{"type": "ws-2012-std", "name": self.windows, "title":
"Windows Server 2012 Standard"},
"configuration": "standalone",
"units": [{"isMaster": True,
"recoveryPassword": "P@ssw0rd",
"location": "west-dc"}]}
post_body = {
'?': {
'type': "io.murano.tests.activeDirectory",
'id': uuid.uuid4().hex
},
"name": "ad.local",
"adminPassword": "P@ssw0rd",
"domain": "ad.local",
"availabilityZone": "nova",
"unitNamingPattern": "adinstance",
"flavor": "m1.medium",
"osImage": {
"type": "ws-2012-std",
"name": self.windows,
"title": "Windows Server 2012 Standard"
},
"configuration": "standalone",
"units": [{
"isMaster": True,
"recoveryPassword": "P@ssw0rd",
"location": "west-dc"
}]
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
@ -255,14 +268,25 @@ class MuranoTest(tempest.test.BaseTestCase):
iis_name = "IISSERVICE"
creds = {'username': 'Administrator',
'password': 'P@ssw0rd'}
post_body = {"type": "webServer", "domain": domain_name,
"availabilityZone": "nova", "name": iis_name,
"adminPassword": "P@ssw0rd",
"unitNamingPattern": "iisinstance",
"osImage": {"type": "ws-2012-std", "name": self.windows,
"title": "Windows Server 2012 Standard"},
"units": [{}], "credentials": creds,
"flavor": "m1.medium"}
post_body = {
'?': {
'type': "io.murano.tests.webServer",
'id': uuid.uuid4().hex
},
"domain": domain_name,
"availabilityZone": "nova",
"name": iis_name,
"adminPassword": "P@ssw0rd",
"unitNamingPattern": "iisinstance",
"osImage": {
"type": "ws-2012-std",
"name": self.windows,
"title": "Windows Server 2012 Standard"
},
"units": [{}],
"credentials": creds,
"flavor": "m1.medium"
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +
@ -280,16 +304,27 @@ class MuranoTest(tempest.test.BaseTestCase):
"""
creds = {'username': 'Administrator',
'password': 'P@ssw0rd'}
post_body = {"type": "aspNetApp", "domain": domain_name,
"availabilityZone": "nova",
"name": "someasp", "repository":
"git://github.com/Mirantis/murano-mvc-demo.git",
"adminPassword": "P@ssw0rd",
"unitNamingPattern": "aspnetinstance",
"osImage": {"type": "ws-2012-std", "name": self.windows,
"title": "Windows Server 2012 Standard"},
"units": [{}], "credentials": creds,
"flavor": "m1.medium"}
repo = 'git://github.com/murano-project/murano-mvc-demo.git',
post_body = {
'?': {
'type': "io.murano.tests.aspNetApp",
'id': uuid.uuid4().hex
},
"domain": domain_name,
"availabilityZone": "nova",
"name": "someasp",
"repository": repo,
"adminPassword": "P@ssw0rd",
"unitNamingPattern": "aspnetinstance",
"osImage": {
"type": "ws-2012-std",
"name": self.windows,
"title": "Windows Server 2012 Standard"
},
"units": [{}],
"credentials": creds,
"flavor": "m1.medium"
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +
@ -306,14 +341,26 @@ class MuranoTest(tempest.test.BaseTestCase):
session_id - ID of current session
"""
creds = {'username': 'Administrator', 'password': 'P@ssw0rd'}
post_body = {"type": "webServerFarm", "domain": domain_name,
"availabilityZone": "nova", "name": "someIISFARM",
"adminPassword": "P@ssw0rd", "loadBalancerPort": 80,
"unitNamingPattern": "",
"osImage": {"type": "ws-2012-std", "name": self.windows,
"title": "Windows Server 2012 Standard"},
"units": [{}, {}],
"credentials": creds, "flavor": "m1.medium"}
post_body = {
'?': {
'type': "io.murano.tests.webServerFarm",
'id': uuid.uuid4().hex
},
"domain": domain_name,
"availabilityZone": "nova",
"name": "someIISFARM",
"adminPassword": "P@ssw0rd",
"loadBalancerPort": 80,
"unitNamingPattern": "",
"osImage": {
"type": "ws-2012-std",
"name": self.windows,
"title": "Windows Server 2012 Standard"
},
"units": [{}, {}],
"credentials": creds,
"flavor": "m1.medium"
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +
@ -330,16 +377,28 @@ class MuranoTest(tempest.test.BaseTestCase):
session_id - ID of current session
"""
creds = {'username': 'Administrator', 'password': 'P@ssw0rd'}
post_body = {"type": "aspNetAppFarm", "domain": domain_name,
"availabilityZone": "nova", "name": "SomeApsFarm",
"repository":
"git://github.com/Mirantis/murano-mvc-demo.git",
"adminPassword": "P@ssw0rd", "loadBalancerPort": 80,
"unitNamingPattern": "",
"osImage": {"type": "ws-2012-std", "name": self.windows,
"title": "Windows Server 2012 Standard"},
"units": [{}, {}],
"credentials": creds, "flavor": "m1.medium"}
repo = 'git://github.com/murano-project/murano-mvc-demo.git'
post_body = {
'?': {
'type': "io.murano.tests.aspNetAppFarm",
'id': uuid.uuid4().hex
},
"domain": domain_name,
"availabilityZone": "nova",
"name": "SomeApsFarm",
"repository": repo,
"adminPassword": "P@ssw0rd",
"loadBalancerPort": 80,
"unitNamingPattern": "",
"osImage": {
"type": "ws-2012-std",
"name": self.windows,
"title": "Windows Server 2012 Standard"
},
"units": [{}, {}],
"credentials": creds,
"flavor": "m1.medium"
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +
@ -355,17 +414,30 @@ class MuranoTest(tempest.test.BaseTestCase):
environment_id - ID of current environment
session_id - ID of current session
"""
post_body = {"type": "msSqlServer", "domain": domain_name,
"availabilityZone": "nova", "name": "SQLSERVER",
"adminPassword": "P@ssw0rd",
"unitNamingPattern": "sqlinstance",
"saPassword": "P@ssw0rd", "mixedModeAuth": True,
"osImage": {"type": "ws-2012-std", "name": self.windows,
"title": "Windows Server 2012 Standard"},
"units": [{}],
"credentials": {"username": "Administrator",
"password": "P@ssw0rd"},
"flavor": "m1.medium"}
post_body = {
'?': {
'type': "io.murano.tests.msSqlServer",
'id': uuid.uuid4().hex
},
"domain": domain_name,
"availabilityZone": "nova",
"name": "SQLSERVER",
"adminPassword": "P@ssw0rd",
"unitNamingPattern": "sqlinstance",
"saPassword": "P@ssw0rd",
"mixedModeAuth": True,
"osImage": {
"type": "ws-2012-std",
"name": self.windows,
"title": "Windows Server 2012 Standard"
},
"units": [{}],
"credentials": {
"username": "Administrator",
"password": "P@ssw0rd"
},
"flavor": "m1.medium"
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +
@ -383,28 +455,48 @@ class MuranoTest(tempest.test.BaseTestCase):
"""
AG = cfg.murano.agListnerIP
clIP = cfg.murano.clusterIP
post_body = {"domain": domain_name, "domainAdminPassword": "P@ssw0rd",
"externalAD": False,
"sqlServiceUserName": "Administrator",
"sqlServicePassword": "P@ssw0rd",
"osImage": {"type": "ws-2012-std", "name": self.windows,
"title": "Windows Server 2012 Standard"},
"agListenerName": "SomeSQL_AGListner",
"flavor": "m1.medium",
"agGroupName": "SomeSQL_AG",
"domainAdminUserName": "Administrator",
"agListenerIP": AG,
"clusterIP": clIP,
"type": "msSqlClusterServer", "availabilityZone": "nova",
"adminPassword": "P@ssw0rd",
"clusterName": "SomeSQL", "mixedModeAuth": True,
"unitNamingPattern": "",
"units": [{"isMaster": True, "name": "node1",
"isSync": True},
{"isMaster": False, "name": "node2",
"isSync": True}],
"name": "Sqlname", "saPassword": "P@ssw0rd",
"databases": ['NewDB']}
post_body = {
'?': {
'type': "io.murano.tests.msSqlClusterServer",
'id': uuid.uuid4().hex
},
"domain": domain_name,
"domainAdminPassword": "P@ssw0rd",
"externalAD": False,
"sqlServiceUserName": "Administrator",
"sqlServicePassword": "P@ssw0rd",
"osImage": {
"type": "ws-2012-std",
"name": self.windows,
"title": "Windows Server 2012 Standard"
},
"agListenerName": "SomeSQL_AGListner",
"flavor": "m1.medium",
"agGroupName": "SomeSQL_AG",
"domainAdminUserName": "Administrator",
"agListenerIP": AG,
"clusterIP": clIP,
"availabilityZone": "nova",
"adminPassword": "P@ssw0rd",
"clusterName": "SomeSQL",
"mixedModeAuth": True,
"unitNamingPattern": "",
"units": [
{
"isMaster": True,
"name": "node1",
"isSync": True
},
{
"isMaster": False,
"name": "node2",
"isSync": True
}
],
"name": "Sqlname",
"saPassword": "P@ssw0rd",
"databases": ['NewDB']
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +
@ -413,13 +505,24 @@ class MuranoTest(tempest.test.BaseTestCase):
return resp, json.loads(body)
def create_linux_telnet(self, environment_id, session_id):
post_body = {"availabilityZone": "nova", "name": "LinuxTelnet",
"deployTelnet": True, "unitNamingPattern": "telnet",
"keyPair": "murano-lb-key",
"osImage": {"type": "linux", "name": self.linux,
"title": "Linux Image"},
"units": [{}],
"flavor": "m1.small", "type": "linuxTelnetService"}
post_body = {
'?': {
'type': "io.murano.tests.linuxTelnetService",
'id': uuid.uuid4().hex
},
"availabilityZone": "nova",
"name": "LinuxTelnet",
"deployTelnet": True,
"unitNamingPattern": "telnet",
"keyPair": "murano-lb-key",
"osImage": {
"type": "linux",
"name": self.linux,
"title": "Linux Image"
},
"units": [{}],
"flavor": "m1.small"
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +
@ -428,14 +531,25 @@ class MuranoTest(tempest.test.BaseTestCase):
return resp, json.loads(body)
def create_linux_apache(self, environment_id, session_id):
post_body = {"availabilityZone": "nova", "name": "LinuxApache",
"deployApachePHP": True, "unitNamingPattern": "apache",
"keyPair": "murano-lb-key",
"instanceCount": [{}],
"osImage": {"type": "linux", "name": self.linux,
"title": "Linux Image"},
"units": [{}],
"flavor": "m1.small", "type": "linuxApacheService"}
post_body = {
'?': {
'type': "io.murano.tests.linuxApacheService",
'id': uuid.uuid4().hex
},
"availabilityZone": "nova",
"name": "LinuxApache",
"deployApachePHP": True,
"unitNamingPattern": "apache",
"keyPair": "murano-lb-key",
"instanceCount": [{}],
"osImage": {
"type": "linux",
"name": self.linux,
"title": "Linux Image"
},
"units": [{}],
"flavor": "m1.small"
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +
@ -444,12 +558,23 @@ class MuranoTest(tempest.test.BaseTestCase):
return resp, json.loads(body)
def create_demo_service(self, environment_id, session_id):
post_body = {"availabilityZone": "nova", "name": "demo",
"unitNamingPattern": "host",
"osImage": {"type": "cirros.demo", "name": self.demo,
"title": "Demo"},
"units": [{}], "flavor": "m1.small",
"configuration": "standalone", "type": "demoService"}
post_body = {
'?': {
'type': "io.murano.tests.demoService",
'id': uuid.uuid4().hex
},
"availabilityZone": "nova",
"name": "demo",
"unitNamingPattern": "host",
"osImage": {
"type": "cirros.demo",
"name": self.demo,
"title": "Demo"
},
"units": [{}],
"flavor": "m1.small",
"configuration": "standalone"
}
post_body = json.dumps(post_body)
self.client.headers.update({'X-Configuration-Session': session_id})
resp, body = self.client.post('environments/' + str(environment_id) +

View File

@ -43,10 +43,11 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
resp, infa = self.get_service_info(env['id'], sess['id'], serv['id'])
resp, infa = self.get_service_info(env['id'], sess['id'],
serv['?']['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(infa['name'], 'ad.local')
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -108,7 +109,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_AD(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -130,7 +131,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_AD(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -154,10 +155,11 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
resp, infa = self.get_service_info(env['id'], sess['id'], serv['id'])
resp, infa = self.get_service_info(env['id'], sess['id'],
serv['?']['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(infa['name'], 'IISSERVICE')
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -219,7 +221,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_IIS(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -241,7 +243,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_IIS(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -265,7 +267,7 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -327,7 +329,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_apsnet(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -349,7 +351,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_apsnet(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -373,10 +375,11 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
resp, infa = self.get_service_info(env['id'], sess['id'], serv['id'])
resp, infa = self.get_service_info(env['id'], sess['id'],
serv['?']['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(infa['name'], 'someIISFARM')
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -438,7 +441,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_IIS_farm(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -460,7 +463,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_IIS_farm(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -484,10 +487,11 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
resp, infa = self.get_service_info(env['id'], sess['id'], serv['id'])
resp, infa = self.get_service_info(env['id'], sess['id'],
serv['?']['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(infa['name'], 'SomeApsFarm')
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -549,7 +553,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_apsnet_farm(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -571,7 +575,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_apsnet_farm(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -595,10 +599,11 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
resp, infa = self.get_service_info(env['id'], sess['id'], serv['id'])
resp, infa = self.get_service_info(env['id'], sess['id'],
serv['?']['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(infa['name'], 'SQLSERVER')
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -660,7 +665,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_SQL(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -682,7 +687,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_SQL(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -703,7 +708,7 @@ class SanityMuranoTest(base.MuranoTest):
self.environments.append(env)
resp, sess = self.create_session(env['id'])
resp, serv = self.create_SQL_cluster(env['id'], sess['id'])
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -727,10 +732,11 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
resp, infa = self.get_service_info(env['id'], sess['id'], serv['id'])
resp, infa = self.get_service_info(env['id'], sess['id'],
serv['?']['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(infa['name'], 'LinuxTelnet')
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -793,7 +799,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_linux_telnet(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -815,7 +821,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_linux_telnet(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -839,10 +845,11 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
resp, infa = self.get_service_info(env['id'], sess['id'], serv['id'])
resp, infa = self.get_service_info(env['id'], sess['id'],
serv['?']['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(infa['name'], 'LinuxApache')
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -905,7 +912,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_linux_apache(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -927,7 +934,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_linux_apache(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -951,10 +958,11 @@ class SanityMuranoTest(base.MuranoTest):
_, infa = self.get_list_services(env['id'], sess['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(len(infa), 1)
resp, infa = self.get_service_info(env['id'], sess['id'], serv['id'])
resp, infa = self.get_service_info(env['id'], sess['id'],
serv['?']['id'])
self.assertEqual(resp['status'], '200')
self.assertEqual(infa['name'], 'demo')
self.delete_service(env['id'], sess['id'], serv['id'])
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -1017,7 +1025,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_demo_service(env['id'], sess['id'])
self.assertRaises(exceptions.NotFound, self.delete_service,
None, sess['id'], serv['id'])
None, sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -1039,7 +1047,7 @@ class SanityMuranoTest(base.MuranoTest):
resp, sess = self.create_session(env['id'])
resp, serv = self.create_demo_service(env['id'], sess['id'])
self.assertRaises(exceptions.Unauthorized, self.delete_service,
env['id'], "", serv['id'])
env['id'], "", serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -1176,8 +1184,8 @@ class SanityMuranoTest(base.MuranoTest):
self.environments.append(env)
resp, sess = self.create_session(env['id'])
resp, serv = self.create_AD(env['id'], sess['id'])
self.update_service(env['id'], sess['id'], serv['id'], serv)
self.delete_service(env['id'], sess['id'], serv['id'])
self.update_service(env['id'], sess['id'], serv['?']['id'], serv)
self.delete_service(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))
@ -1198,7 +1206,7 @@ class SanityMuranoTest(base.MuranoTest):
self.environments.append(env)
resp, sess = self.create_session(env['id'])
resp, serv = self.create_AD(env['id'], sess['id'])
self.get_service_info(env['id'], sess['id'], serv['id'])
self.get_service_info(env['id'], sess['id'], serv['?']['id'])
self.delete_environment(env['id'])
self.environments.pop(self.environments.index(env))

View File

@ -54,7 +54,7 @@ class CoreServices(object):
if path == '/services':
get_status = CoreServices.get_service_status
for srv in result:
srv['status'] = get_status(environment_id, srv['id'])
srv['?']['status'] = get_status(environment_id, srv['?']['id'])
return result
@ -87,8 +87,7 @@ class CoreServices(object):
env_description = get_description(environment_id, session_id)
utils.TraverseHelper.update(path, data, env_description)
if path == '/services':
data['updated'] = str(timeutils.utcnow())
env_description['?']['updated'] = str(timeutils.utcnow())
save_description(session_id, env_description)

View File

@ -14,15 +14,11 @@
import collections
import jsonschema
from muranoapi.api.v1 import schemas
from muranoapi.common import rpc
from muranoapi.common import uuidutils
from muranoapi.db import models
from muranoapi.db.services import sessions
from muranoapi.db import session as db_session
from muranoapi.openstack.common import timeutils
EnvironmentStatus = collections.namedtuple('EnvironmentStatus', [
@ -87,8 +83,19 @@ class EnvironmentServices(object):
:param tenant_id: Tenant Id
:return: Created Environment
"""
objects = {'?': {
'id': uuidutils.generate_uuid(),
}}
objects.update(environment_params)
objects['?']['type'] = 'io.murano.Environment'
environment_params['tenant_id'] = tenant_id
data = {
'Objects': objects,
'Attributes': []
}
environment = models.Environment()
environment.update(environment_params)
@ -97,7 +104,7 @@ class EnvironmentServices(object):
unit.add(environment)
#saving environment as Json to itself
environment.update({"description": environment.to_dict()})
environment.update({'description': data})
environment.save(unit)
return environment
@ -127,7 +134,8 @@ class EnvironmentServices(object):
unit.delete(environment)
@staticmethod
def get_environment_description(environment_id, session_id=None):
def get_environment_description(environment_id, session_id=None,
inner=True):
"""
Returns environment description for specified environment. If session
is specified and not in deploying state function returns modified
@ -135,6 +143,8 @@ class EnvironmentServices(object):
:param environment_id: Environment Id
:param session_id: Session Id
:param inner: return contents of environment rather than whole
Object Model structure
:return: Environment Description Object
"""
unit = db_session.get_session()
@ -156,50 +166,27 @@ class EnvironmentServices(object):
env = (unit.query(models.Environment).get(environment_id))
env_description = env.description
return env_description
if not inner:
return env_description
else:
return env_description['Objects']
@staticmethod
def save_environment_description(session_id, environment):
def save_environment_description(session_id, environment, inner=True):
"""
Saves environment description to specified session
:param session_id: Session Id
:param environment: Environment Description
:param inner: save modifications to only content of environment
rather than whole Object Model structure
"""
unit = db_session.get_session()
session = unit.query(models.Session).get(session_id)
EnvironmentServices.normalize(environment)
jsonschema.validate(environment, schemas.ENV_SCHEMA)
session.description = environment
if inner:
data = session.description.copy()
data['Objects'] = environment
session.description = data
else:
session.description = environment
session.save(unit)
@staticmethod
def normalize(environment):
if 'id' not in environment:
environment['id'] = uuidutils.generate_uuid()
if 'services' not in environment:
return
for service in environment['services']:
if 'id' not in service:
service['id'] = uuidutils.generate_uuid()
if 'created' not in service:
service['created'] = str(timeutils.utcnow())
if 'updated' not in service:
service['updated'] = str(timeutils.utcnow())
if 'units' not in service:
continue
for idx, unit in enumerate(service['units']):
if 'id' not in unit:
unit['id'] = uuidutils.generate_uuid()
if 'name' not in unit:
unit['name'] = '{srv_name}_instance_{number}'.format(
srv_name=service['name'], number=idx
)

View File

@ -121,14 +121,28 @@ class SessionServices(object):
#unit = get_session()
#Set X-Auth-Token for conductor
environment = session.description
environment['token'] = token
unit = db_session.get_session()
environment = unit.query(models.Environment).get(
session.environment_id)
data = {
'model': session.description,
'token': token,
'tenant_id': environment.tenant_id
}
data['model']['Objects']['?']['id'] = environment.id
data['model']['Objects']['applications'] = \
data['model']['Objects'].get('services', [])
if 'services' in data['model']['Objects']:
del data['model']['Objects']['services']
session.state = SessionState.deploying
deployment = models.Deployment()
deployment.environment_id = environment['id']
deployment.environment_id = session.environment_id
deployment.description = token_sanitizer.TokenSanitizer().sanitize(
dict(session.description))
dict(session.description.get('Objects')))
status = models.Status()
status.text = "Deployment scheduled"
status.level = "info"
@ -138,4 +152,4 @@ class SessionServices(object):
unit.add(session)
unit.add(deployment)
rpc.engine().handle_task(environment)
rpc.engine().handle_task(data)

View File

@ -45,16 +45,16 @@ class TraverseHelperTests(unittest.TestCase):
def test_list_item_attribute_get(self):
source = {'obj': [
{'id': '1', 'value': 1},
{'id': '2s', 'value': 2},
{'?': {'id': '1'}, 'value': 1},
{'?': {'id': '2s'}, 'value': 2},
]}
value = utils.TraverseHelper.get('/obj/2s/value', source)
self.assertEqual(value, 2)
def test_list_item_attribute_get_by_index(self):
source = {'obj': [
{'id': 'guid1', 'value': 1},
{'id': 'guid2', 'value': 2},
{'?': {'id': 'guid1'}, 'value': 1},
{'?': {'id': 'guid2'}, 'value': 2}
]}
value = utils.TraverseHelper.get('/obj/1/value', source)
self.assertEqual(value, 2)
@ -114,13 +114,13 @@ class TraverseHelperTests(unittest.TestCase):
self.assertDictEqual(value, {'attr2': True})
def test_nested_attribute_remove_from_list_by_id(self):
source = {'obj': [{'id': 'id1'}, {'id': 'id2'}]}
source = {'obj': [{'?': {'id': 'id1'}}, {'?': {'id': 'id2'}}]}
utils.TraverseHelper.remove('/obj/id1', source)
value = utils.TraverseHelper.get('/obj', source)
self.assertListEqual(value, [{'id': 'id2'}])
self.assertListEqual(value, [{'?': {'id': 'id2'}}])
def test_nested_attribute_remove_from_list_by_index(self):
source = {'obj': [{'id': 'id1'}, {'id': 'id2'}]}
source = {'obj': [{'?': {'id': 'id1'}}, {'?': {'id': 'id2'}}]}
utils.TraverseHelper.remove('/obj/0', source)
value = utils.TraverseHelper.get('/obj', source)
self.assertListEqual(value, [{'id': 'id2'}])
self.assertListEqual(value, [{'?': {'id': 'id2'}}])