Remove ClientManager class.
Change-Id: Iff3c4eb4010d01a9148c200837722bdc31784b49
This commit is contained in:
parent
6746d08357
commit
481dc75fed
@ -19,7 +19,7 @@ import logging
|
||||
import argparse
|
||||
|
||||
from oslo_log import log
|
||||
from tobiko.common import clients
|
||||
|
||||
from tobiko.common.managers import stack
|
||||
from tobiko.common.managers import ansible
|
||||
from tobiko import config
|
||||
@ -37,16 +37,13 @@ class TobikoCMD(object):
|
||||
self.parser = self.get_parser()
|
||||
self.args = (self.parser).parse_args()
|
||||
|
||||
self.clientManager = clients.ClientManager()
|
||||
curr_dir = os.path.dirname(__file__)
|
||||
self.templates_dir = os.path.join(curr_dir,
|
||||
"../tests/scenario/templates")
|
||||
self.playbooks_dir = os.path.join(curr_dir,
|
||||
"../tests/scenario/playbooks")
|
||||
self.stackManager = stack.StackManager(self.clientManager,
|
||||
self.templates_dir)
|
||||
self.ansibleManager = ansible.AnsibleManager(self.clientManager,
|
||||
self.playbooks_dir)
|
||||
self.stackManager = stack.StackManager(self.templates_dir)
|
||||
self.ansibleManager = ansible.AnsibleManager(self.playbooks_dir)
|
||||
|
||||
def get_parser(self):
|
||||
parser = argparse.ArgumentParser(add_help=True)
|
||||
@ -64,3 +61,7 @@ class TobikoCMD(object):
|
||||
for handler in root_logger.handlers:
|
||||
if isinstance(handler, logging.StreamHandler):
|
||||
handler.setLevel(level)
|
||||
self.stackManager = stack.StackManager(
|
||||
templates_dir=self.templates_dir)
|
||||
self.ansibleManager = ansible.AnsibleManager(
|
||||
playbooks_dir=self.playbooks_dir)
|
||||
|
@ -17,7 +17,6 @@ import argparse
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from tobiko.common import clients
|
||||
from tobiko.fault import executor
|
||||
|
||||
|
||||
@ -29,7 +28,6 @@ class FaultCMD(object):
|
||||
def __init__(self):
|
||||
self.parser = self.get_parser()
|
||||
self.args = self.parser.parse_args()
|
||||
self.clients = clients.ClientManager()
|
||||
|
||||
def get_parser(self):
|
||||
parser = argparse.ArgumentParser(add_help=True)
|
||||
@ -41,7 +39,7 @@ class FaultCMD(object):
|
||||
|
||||
def run(self):
|
||||
"""Run faults."""
|
||||
fault_exec = executor.FaultExecutor(clients=self.clients)
|
||||
fault_exec = executor.FaultExecutor()
|
||||
fault_exec.execute(self.args.fault)
|
||||
|
||||
|
||||
|
@ -1,60 +0,0 @@
|
||||
# Copyright 2018 Red Hat
|
||||
#
|
||||
# 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.
|
||||
from __future__ import absolute_import
|
||||
|
||||
from tobiko.openstack import keystone
|
||||
from tobiko.openstack import heat
|
||||
from tobiko.openstack import neutron
|
||||
from tobiko.openstack import nova
|
||||
|
||||
|
||||
class ClientManager(object):
|
||||
"""Manages OpenStack official Python clients."""
|
||||
|
||||
_session = None
|
||||
_heat_client = None
|
||||
_neutron_client = None
|
||||
_nova_client = None
|
||||
|
||||
def __init__(self, credentials=None):
|
||||
self.credentials = credentials
|
||||
|
||||
@property
|
||||
def session(self):
|
||||
"""Returns keystone session."""
|
||||
if self._session is None:
|
||||
self._session = keystone.get_keystone_session(
|
||||
credentials=self.credentials)
|
||||
return self._session
|
||||
|
||||
@property
|
||||
def heat_client(self):
|
||||
if self._heat_client is None:
|
||||
self._heat_client = heat.get_heat_client(session=self.session)
|
||||
return self._heat_client
|
||||
|
||||
@property
|
||||
def neutron_client(self):
|
||||
"""Returns neutron client."""
|
||||
if self._neutron_client is None:
|
||||
self._neutron_client = neutron.get_neutron_client(
|
||||
session=self.session)
|
||||
return self._neutron_client
|
||||
|
||||
@property
|
||||
def nova_client(self):
|
||||
"""Returns nova client."""
|
||||
if self._nova_client is None:
|
||||
self._nova_client = nova.get_nova_client(session=self.session)
|
||||
return self._nova_client
|
@ -13,9 +13,8 @@
|
||||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
|
||||
from collections import namedtuple
|
||||
import os
|
||||
|
||||
from ansible.executor import playbook_executor
|
||||
from ansible.inventory.manager import InventoryManager
|
||||
@ -24,6 +23,7 @@ from ansible.vars.manager import VariableManager
|
||||
from oslo_log import log
|
||||
|
||||
from tobiko.common import constants
|
||||
from tobiko.openstack import keystone
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -32,8 +32,7 @@ LOG = log.getLogger(__name__)
|
||||
class AnsibleManager(object):
|
||||
"""Manages Ansible entities."""
|
||||
|
||||
def __init__(self, client_manager, playbooks_dir):
|
||||
self.client_manager = client_manager
|
||||
def __init__(self, playbooks_dir):
|
||||
self.playbooks_dir = playbooks_dir
|
||||
self.loader = DataLoader()
|
||||
self.inventory = InventoryManager(loader=self.loader,
|
||||
@ -73,14 +72,14 @@ class AnsibleManager(object):
|
||||
"""Executes given playbook."""
|
||||
playbook_path = self.playbooks_dir + '/' + playbook
|
||||
|
||||
credentials = keystone.default_keystone_credentials()
|
||||
extra_vars = {'mode': mode,
|
||||
'auth_url': self.client_manager.credentials['auth_url'],
|
||||
'username': self.client_manager.credentials['username'],
|
||||
'project_name': self.client_manager.credentials[
|
||||
'project_name'],
|
||||
'auth_url': credentials.auth_url,
|
||||
'username': credentials.username,
|
||||
'project_name': credentials.project_name,
|
||||
'password': credentials.project_name.password,
|
||||
'image': constants.DEFAULT_PARAMS['image'],
|
||||
'flavor': constants.DEFAULT_PARAMS['flavor'],
|
||||
'password': self.client_manager.credentials['password']}
|
||||
'flavor': constants.DEFAULT_PARAMS['flavor']}
|
||||
|
||||
self.variable_manager.extra_vars = extra_vars
|
||||
|
||||
|
@ -13,19 +13,18 @@
|
||||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
from tobiko.openstack import neutron
|
||||
|
||||
|
||||
class NetworkManager(object):
|
||||
"""Manages Neutron Resources."""
|
||||
|
||||
def __init__(self, client_manager):
|
||||
self._client_manager = client_manager
|
||||
|
||||
_client = None
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = self._client_manager.network_client
|
||||
self._client = neutron.get_neutron_client()
|
||||
return self._client
|
||||
|
||||
def create_sg_rules(self, rules, sg_id):
|
||||
|
@ -23,6 +23,7 @@ import yaml
|
||||
|
||||
from tobiko.common import constants
|
||||
from tobiko.common import exceptions
|
||||
from tobiko.openstack import heat
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -40,8 +41,7 @@ DELETE_FAILED = 'DELETE_FAILED'
|
||||
class StackManager(object):
|
||||
"""Manages Heat stacks."""
|
||||
|
||||
def __init__(self, client_manager, templates_dir, wait_interval=5):
|
||||
self._client_manager = client_manager
|
||||
def __init__(self, templates_dir, wait_interval=5):
|
||||
self.templates_dir = templates_dir
|
||||
self.wait_interval = wait_interval
|
||||
|
||||
@ -50,7 +50,7 @@ class StackManager(object):
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = self._client_manager.heat_client
|
||||
self._client = heat.get_heat_client()
|
||||
return self._client
|
||||
|
||||
def load_template(self, template_path):
|
||||
|
@ -21,6 +21,7 @@ from oslo_log import log
|
||||
|
||||
from tobiko.fault import constants as fault_const
|
||||
from tobiko.common.utils import file as file_utils
|
||||
from tobiko.openstack import nova
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -33,10 +34,9 @@ class FaultConfig(object):
|
||||
DEFAULT_CONF_NAME = "os-faults.yml"
|
||||
DEFAULT_CONF_FILE = os.path.join(DEFAULT_CONF_PATH, DEFAULT_CONF_NAME)
|
||||
|
||||
def __init__(self, conf_file, clients):
|
||||
def __init__(self, conf_file):
|
||||
self.templates_dir = os.path.join(os.path.dirname(__file__),
|
||||
'templates')
|
||||
self.clients = clients
|
||||
if conf_file:
|
||||
self.conf_file = conf_file
|
||||
else:
|
||||
@ -68,6 +68,7 @@ class FaultConfig(object):
|
||||
|
||||
def get_nodes(self):
|
||||
"""Returns a list of dictonaries with nodes name and address."""
|
||||
client = nova.get_nova_client()
|
||||
return [{'name': server.name,
|
||||
'address': server.addresses['ctlplane'][0]['addr']}
|
||||
for server in self.clients.nova_client.servers.list()]
|
||||
for server in client.servers.list()]
|
||||
|
@ -25,8 +25,8 @@ LOG = log.getLogger(__name__)
|
||||
class FaultExecutor(object):
|
||||
"""Responsible for executing faults."""
|
||||
|
||||
def __init__(self, conf_file=None, clients=None):
|
||||
self.config = FaultConfig(conf_file=conf_file, clients=clients)
|
||||
def __init__(self, conf_file=None):
|
||||
self.config = FaultConfig(conf_file=conf_file)
|
||||
try:
|
||||
self.connect()
|
||||
LOG.info("os-faults connected.")
|
||||
|
@ -28,7 +28,6 @@ class TobikoCMDTest(test_base.OpenstackTest):
|
||||
def test_init(self, argv=None):
|
||||
self.patch_argv(argv=argv)
|
||||
cmd = self.command_class()
|
||||
self.assertIsNotNone(cmd.clientManager)
|
||||
self.assertTrue(os.path.isdir(cmd.templates_dir))
|
||||
self.assertIsNotNone(cmd.stackManager)
|
||||
return cmd
|
||||
|
@ -19,18 +19,16 @@ import os
|
||||
from tobiko.tests import base
|
||||
from tobiko.common.managers import stack as stack_manager
|
||||
from tobiko.common.managers import network
|
||||
from tobiko.common import clients
|
||||
from tobiko.common import constants
|
||||
|
||||
|
||||
class ScenarioTestsBase(base.TobikoTest):
|
||||
"""All scenario tests inherit from this scenario base class."""
|
||||
|
||||
clients = clients.ClientManager()
|
||||
default_params = constants.DEFAULT_PARAMS
|
||||
networks = network.NetworkManager(clients)
|
||||
networks = network.NetworkManager()
|
||||
templates_dir = os.path.join(os.path.dirname(__file__), 'templates')
|
||||
stacks = stack_manager.StackManager(clients, templates_dir)
|
||||
stacks = stack_manager.StackManager(templates_dir=templates_dir)
|
||||
stack = None
|
||||
fault = None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user