From ab330be463a0bd4d9e01e2d85eca34237c3a8c27 Mon Sep 17 00:00:00 2001 From: Sergey Murashov Date: Wed, 21 May 2014 15:51:36 +0400 Subject: [PATCH] Add initial tests for application deployments * Tests for telnet application deployemts * Tests for apache application deployemts Change-Id: I6c36e39194cad2fc3e00f7636f4836b869646ab6 --- functionaltests/engine/__init__.py | 0 functionaltests/engine/base.py | 220 +++++++++++++++++++++++++++++ functionaltests/engine/config.conf | 5 + functionaltests/engine/config.py | 48 +++++++ functionaltests/run_tests.sh | 2 +- 5 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 functionaltests/engine/__init__.py create mode 100644 functionaltests/engine/base.py create mode 100644 functionaltests/engine/config.conf create mode 100644 functionaltests/engine/config.py diff --git a/functionaltests/engine/__init__.py b/functionaltests/engine/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/functionaltests/engine/base.py b/functionaltests/engine/base.py new file mode 100644 index 00000000..1b708cab --- /dev/null +++ b/functionaltests/engine/base.py @@ -0,0 +1,220 @@ +# Copyright (c) 2014 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import json +import requests +import testresources +import testtools +import time +import uuid + +from glanceclient import Client as gclient +from keystoneclient.v2_0 import client as ksclient + +import functionaltests.engine.config as cfg + + +CONF = cfg.cfg.CONF + + +class Client(object): + + def __init__(self, user, password, tenant, auth_url): + + self.auth = ksclient.Client(username=user, password=password, + tenant_name=tenant, auth_url=auth_url) + + self.endpoint = self.auth.service_catalog.url_for( + service_type='application_catalog', endpoint_type='publicURL') + + self.headers = { + 'X-Auth-Token': self.auth.auth_token, + 'Content-type': 'application/json' + } + + glance_endpoint = \ + self.auth.service_catalog.url_for(service_type='image', + endpoint_type='publicURL') + glance = gclient('1', endpoint=glance_endpoint, + token=self.auth.auth_token) + + for i in glance.images.list(): + if 'murano_image_info' in i.properties.keys(): + if 'linux' == json.loads( + i.properties['murano_image_info'])['type']: + self.linux = i.name + elif 'windows' in json.loads( + i.properties['murano_image_info'])['type']: + self.windows = i.name + elif 'demo' in json.loads( + i.properties['murano_image_info'])['type']: + self.demo = i.name + + def create_environment(self, name): + post_body = {'name': name} + resp = requests.post(self.endpoint + 'environments', + data=json.dumps(post_body), + headers=self.headers) + + return resp.json() + + def delete_environment(self, environment_id): + endpoint = '{0}environments/{1}'.format(self.endpoint, environment_id) + return requests.delete(endpoint, headers=self.headers) + + def get_environment(self, environment_id): + return requests.get('{0}environments/{1}'.format(self.endpoint, + environment_id), + headers=self.headers).json() + + def create_session(self, environment_id): + post_body = None + endpoint = '{0}environments/{1}/configure'.format(self.endpoint, + environment_id) + + return requests.post(endpoint, data=post_body, + headers=self.headers).json() + + def deploy_session(self, environment_id, session_id): + endpoint = '{0}environments/{1}/sessions/{2}/deploy'.format( + self.endpoint, environment_id, session_id) + + return requests.post(endpoint, data=None, headers=self.headers) + + def create_service(self, environment_id, session_id, json_data): + headers = self.headers.copy() + headers.update({'x-configuration-session': session_id}) + + endpoint = '{0}environments/{1}/services'.format(self.endpoint, + environment_id) + + return requests.post(endpoint, data=json.dumps(json_data), + headers=headers).json() + + def status_check(self, environment_id): + environment = self.get_environment(environment_id) + start_time = time.time() + while environment['status'] != 'ready': + if time.time() - start_time > 1200: + return + time.sleep(5) + environment = self.get_environment(environment_id) + return 'OK' + + def deployments_list(self, environment_id): + endpoint = '{0}environments/{1}/deployments'.format(self.endpoint, + environment_id) + + return requests.get(endpoint, + headers=self.headers).json()['deployments'] + + +class MuranoBase(testtools.TestCase, testtools.testcase.WithAttributes, + testresources.ResourcedTestCase): + + @classmethod + def setUpClass(cls): + super(MuranoBase, cls).setUpClass() + + cls.client = Client(user=CONF.murano.user, + password=CONF.murano.password, + tenant=CONF.murano.tenant, + auth_url=CONF.murano.auth_url) + + def setUp(self): + super(MuranoBase, self).setUp() + + self.environments = [] + + def tearDown(self): + + for env in self.environments: + try: + self.client.delete_environment(env) + except Exception: + pass + + def test_deploy_telnet(self): + post_body = { + "instance": { + "flavor": "m1.medium", + "image": self.client.linux, + "?": { + "type": "io.murano.resources.Instance", + "id": str(uuid.uuid4()) + }, + "name": "testMurano" + }, + "name": "teMurano", + "?": { + "_{id}".format(id=uuid.uuid4().hex): { + "name": "Telnet" + }, + "type": "io.murano.apps.linux.Telnet", + "id": str(uuid.uuid4()) + } + } + + environment = self.client.create_environment('Telnetenv') + self.environments.append(environment['id']) + + session = self.client.create_session(environment['id']) + + self.client.create_service(environment['id'], session['id'], post_body) + self.client.deploy_session(environment['id'], session['id']) + + status = self.client.status_check(environment['id']) + + self.assertEqual('OK', status) + + deployments = self.client.deployments_list(environment['id']) + for deployment in deployments: + self.assertEqual('success', deployment['state']) + + def test_deploy_apache(self): + post_body = { + "instance": { + "flavor": "m1.medium", + "image": self.client.linux, + "?": { + "type": "io.murano.resources.Instance", + "id": str(uuid.uuid4()) + }, + "name": "testMurano" + }, + "name": "teMurano", + "?": { + "_{id}".format(id=uuid.uuid4().hex): { + "name": "Apache" + }, + "type": "io.murano.apps.apache.Apache", + "id": str(uuid.uuid4()) + } + } + + environment = self.client.create_environment('Apacheenv') + self.environments.append(environment['id']) + + session = self.client.create_session(environment['id']) + + self.client.create_service(environment['id'], session['id'], post_body) + self.client.deploy_session(environment['id'], session['id']) + + status = self.client.status_check(environment['id']) + + self.assertEqual('OK', status) + + deployments = self.client.deployments_list(environment['id']) + for deployment in deployments: + self.assertEqual('success', deployment['state']) diff --git a/functionaltests/engine/config.conf b/functionaltests/engine/config.conf new file mode 100644 index 00000000..becb9904 --- /dev/null +++ b/functionaltests/engine/config.conf @@ -0,0 +1,5 @@ +[murano] +auth_url = http://127.0.0.1:5000/v2.0/ +user = admin +password = admin +tenant = admin diff --git a/functionaltests/engine/config.py b/functionaltests/engine/config.py new file mode 100644 index 00000000..c7dff233 --- /dev/null +++ b/functionaltests/engine/config.py @@ -0,0 +1,48 @@ +# Copyright (c) 2014 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os + +from oslo.config import cfg + + +murano_group = cfg.OptGroup(name='murano', title="murano") + +MuranoGroup = [ + cfg.StrOpt('auth_url', + default='http://127.0.0.1:5000/v2.0/', + help="keystone url"), + cfg.StrOpt('user', + default='admin', + help="keystone user"), + cfg.StrOpt('password', + default='pass', + help="password for keystone user"), + cfg.StrOpt('tenant', + default='admin', + help='keystone tenant') +] + + +def register_config(config, config_group, config_opts): + + config.register_group(config_group) + config.register_opts(config_opts, config_group) + +path = os.path.join("%s/config.conf" % os.getcwd()) + +if os.path.exists(path): + cfg.CONF([], project='muranointegration', default_config_files=[path]) + +register_config(cfg.CONF, murano_group, MuranoGroup) diff --git a/functionaltests/run_tests.sh b/functionaltests/run_tests.sh index b8d4af7c..c7ddca32 100755 --- a/functionaltests/run_tests.sh +++ b/functionaltests/run_tests.sh @@ -28,4 +28,4 @@ TEMPEST_DIR=${TEMPEST_DIR:-/opt/stack/new/tempest} # Add tempest source tree to PYTHONPATH export PYTHONPATH=$PYTHONPATH:$TEMPEST_DIR -nosetests -sv . +nosetests -sv api/v1