2016-02-10 13:15:29 +00:00
|
|
|
# Copyright 2016 Nokia
|
|
|
|
#
|
|
|
|
# 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.
|
2016-04-05 13:31:53 +00:00
|
|
|
|
2016-02-16 15:54:43 +00:00
|
|
|
from oslo_config import cfg
|
2016-02-10 13:15:29 +00:00
|
|
|
from oslo_log import log as logging
|
2016-03-31 17:58:59 +00:00
|
|
|
from oslotest import base
|
2016-02-10 13:15:29 +00:00
|
|
|
|
2016-03-24 09:27:13 +00:00
|
|
|
import vitrage_tempest_tests.tests.utils as utils
|
2016-02-10 13:15:29 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
2016-02-16 15:54:43 +00:00
|
|
|
CONF = cfg.CONF
|
|
|
|
logging.register_options(CONF)
|
|
|
|
logging.setup(CONF, "vitrage")
|
|
|
|
logging.set_defaults(default_log_levels=utils.extra_log_level_defaults)
|
2016-02-10 13:15:29 +00:00
|
|
|
|
|
|
|
|
2016-03-31 17:58:59 +00:00
|
|
|
class RunVitrageEnv(base.BaseTestCase):
|
2016-02-10 13:15:29 +00:00
|
|
|
"""RunVitrageEnv class. Run Vitrage env."""
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwds):
|
|
|
|
super(RunVitrageEnv, self).__init__(*args, **kwds)
|
|
|
|
|
|
|
|
def test_run_env(self):
|
|
|
|
if self._show_vitrage_processes() is True:
|
2016-02-16 15:54:43 +00:00
|
|
|
LOG.debug('The vitrage processed existed and should be removed')
|
2016-02-10 13:15:29 +00:00
|
|
|
self._stop_vitrage_processes()
|
|
|
|
|
2016-02-16 15:54:43 +00:00
|
|
|
self._get_env_params()
|
|
|
|
|
|
|
|
utils.change_terminal_dir('/home/stack/devstack')
|
2016-03-31 17:58:59 +00:00
|
|
|
utils.run_vitrage_command(". openrc " + self.user + " " +
|
|
|
|
self.user)
|
2016-02-16 15:54:43 +00:00
|
|
|
utils.run_from_terminal("openstack service create rca" +
|
|
|
|
" --name vitrage")
|
|
|
|
utils.run_from_terminal("openstack endpoint create rca" +
|
2016-03-30 11:12:39 +00:00
|
|
|
# " --os-username " + self.user +
|
|
|
|
# " --os-username " + self.user +
|
|
|
|
# " --os-password " + self.password +
|
|
|
|
# " --os-auth-url " + self.url +
|
|
|
|
# " --os-project-name admin" +
|
2016-02-16 15:54:43 +00:00
|
|
|
" --adminurl http://" + self.host +
|
|
|
|
":" + str(self.port) +
|
|
|
|
" --internalurl http://" + self.host +
|
|
|
|
":" + str(self.port) +
|
|
|
|
" --publicurl http://" + self.host +
|
|
|
|
":" + str(self.port) +
|
|
|
|
" --region RegionOne")
|
|
|
|
|
|
|
|
utils.run_from_terminal("nohup vitrage-graph > /tmp/nohup-graph.out &")
|
|
|
|
utils.run_from_terminal("nohup vitrage-api > /tmp/nohup-api.out &")
|
2016-02-10 13:15:29 +00:00
|
|
|
|
|
|
|
if self._show_vitrage_processes() is False:
|
|
|
|
LOG.error("No vitrage processes founded")
|
|
|
|
raise ValueError("No vitrage processes founded")
|
2016-02-16 15:54:43 +00:00
|
|
|
else:
|
|
|
|
LOG.info('The vitrage processes exists')
|
2016-02-10 13:15:29 +00:00
|
|
|
|
|
|
|
if self._validate_vitrage_processes() is False:
|
|
|
|
LOG.error("The vitrage processes are not correct")
|
|
|
|
self._stop_vitrage_processes()
|
|
|
|
raise ValueError("The vitrage processes are not correct")
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _show_vitrage_processes():
|
2016-02-16 15:54:43 +00:00
|
|
|
text_out = utils.get_from_terminal(
|
|
|
|
"ps -ef | grep vitrage-api | grep -v grep")
|
|
|
|
text_out2 = utils.get_from_terminal(
|
|
|
|
"ps -ef | grep vitrage-graph | grep -v grep")
|
2016-02-10 13:15:29 +00:00
|
|
|
|
|
|
|
if ("vitrage-api" in text_out) and ("vitrage-graph" in text_out2):
|
2016-02-16 15:54:43 +00:00
|
|
|
LOG.debug('The vitrage processes exists')
|
2016-02-10 13:15:29 +00:00
|
|
|
return True
|
|
|
|
elif "vitrage-api" in text_out:
|
2016-02-16 15:54:43 +00:00
|
|
|
LOG.debug('Only vitrage-api process exist')
|
2016-02-10 13:15:29 +00:00
|
|
|
return True
|
|
|
|
elif "vitrage-graph" in text_out2:
|
2016-02-16 15:54:43 +00:00
|
|
|
LOG.debug('Only vitrage-graph process exist')
|
2016-02-10 13:15:29 +00:00
|
|
|
return True
|
|
|
|
else:
|
2016-02-16 15:54:43 +00:00
|
|
|
LOG.debug('The vitrage process does not run')
|
2016-02-10 13:15:29 +00:00
|
|
|
return False
|
|
|
|
|
2016-02-16 15:54:43 +00:00
|
|
|
def _get_env_params(self):
|
|
|
|
conf = utils.get_conf()
|
|
|
|
self.port = conf.api.port
|
2016-03-30 11:12:39 +00:00
|
|
|
self.user = conf.service_credentials.user
|
|
|
|
self.password = conf.service_credentials.password
|
|
|
|
self.url = conf.service_credentials.auth_url + "/v2.0"
|
2016-02-16 15:54:43 +00:00
|
|
|
self.host = utils.get_regex_result(
|
2016-03-30 11:12:39 +00:00
|
|
|
"(\d+\.\d+\.\d+\.\d+)", self.url)
|
|
|
|
self.identity_uri = conf.keystone_authtoken.identity_uri
|
2016-02-10 13:15:29 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _stop_vitrage_processes():
|
2016-02-16 15:54:43 +00:00
|
|
|
text_out = utils.get_from_terminal("pgrep vitrage-api")
|
2016-02-10 13:15:29 +00:00
|
|
|
if text_out != '':
|
2016-02-16 15:54:43 +00:00
|
|
|
LOG.debug("The vitrage-api process exist")
|
|
|
|
utils.run_from_terminal("kill -9 " + text_out)
|
2016-02-10 13:15:29 +00:00
|
|
|
|
2016-02-16 15:54:43 +00:00
|
|
|
text_out2 = utils.get_from_terminal("pgrep vitrage-graph")
|
2016-02-10 13:15:29 +00:00
|
|
|
if text_out2 != '':
|
2016-02-16 15:54:43 +00:00
|
|
|
LOG.debug("The vitrage-graph process exist")
|
|
|
|
utils.run_from_terminal("kill -9 " + text_out2)
|
2016-02-10 13:15:29 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _validate_vitrage_processes():
|
2016-02-16 15:54:43 +00:00
|
|
|
errors_out = utils.get_from_terminal(
|
|
|
|
"grep ERROR /tmp/nohup-graph.out | " +
|
|
|
|
"grep ERROR /tmp/nohup-api.out | grep -v \'ERROR %\'")
|
|
|
|
if errors_out != '':
|
|
|
|
LOG.error("The errors are : " + errors_out)
|
2016-02-10 13:15:29 +00:00
|
|
|
return False
|
|
|
|
return True
|