Some refactoring
This commit is contained in:
parent
00794c8154
commit
6ebae6aee5
@ -1,18 +1,22 @@
|
||||
import logging
|
||||
from time import sleep
|
||||
import unittest
|
||||
from abc import abstractproperty
|
||||
from devops.helpers import ssh, os
|
||||
import re
|
||||
from ci_helpers import get_environment
|
||||
from helpers import load, execute, write_config, sync_time
|
||||
from helpers import load, execute, write_config, sync_time, safety_revert_nodes
|
||||
from root import root
|
||||
|
||||
class RecipeTestCase(unittest.TestCase):
|
||||
class BaseTestCase(unittest.TestCase):
|
||||
|
||||
@abstractproperty
|
||||
def ci(self):
|
||||
pass
|
||||
|
||||
def setUp(self):
|
||||
self.environment = get_environment()
|
||||
self.ci = self.ci()
|
||||
self.environment = self.ci().get_environment_or_create()
|
||||
master = self.environment.node['master']
|
||||
self.revert_snapshot()
|
||||
self.revert_snapshots()
|
||||
self.master_remote = ssh(master.ip_address, username='root', password='r00tme')
|
||||
self.upload_recipes()
|
||||
self.restart_puppet_muster()
|
||||
@ -25,10 +29,9 @@ class RecipeTestCase(unittest.TestCase):
|
||||
self.master_remote.mkdir(remote_dir)
|
||||
self.master_remote.upload(recipe_dir, remote_dir)
|
||||
|
||||
def revert_snapshot(self):
|
||||
def revert_snapshots(self):
|
||||
safety_revert_nodes(self.environment.nodes, 'empty')
|
||||
for node in self.environment.nodes:
|
||||
node.restore_snapshot('empty')
|
||||
sleep(4)
|
||||
remote=ssh(node.ip_address, username='root', password='r00tme')
|
||||
sync_time(remote.sudo.ssh)
|
||||
remote.sudo.ssh.execute('yum makecache')
|
||||
@ -68,3 +71,17 @@ class RecipeTestCase(unittest.TestCase):
|
||||
|
||||
def restart_puppet_muster(self):
|
||||
execute(self.master_remote, 'service puppetmaster restart')
|
||||
|
||||
def do(self, nodes, command):
|
||||
results = []
|
||||
for node in nodes:
|
||||
remote = ssh(node.ip_address, username='root', password='r00tme')
|
||||
results.append(execute(remote.sudo.ssh, command))
|
||||
return results
|
||||
|
||||
def validate(self, nodes, command):
|
||||
results = self.do(nodes, command)
|
||||
for result in results:
|
||||
self.assertResult(result)
|
||||
|
||||
|
208
fuel_test/ci.py
208
fuel_test/ci.py
@ -1,208 +0,0 @@
|
||||
import logging
|
||||
from time import sleep
|
||||
import traceback
|
||||
import devops
|
||||
from devops.model import Environment, Network, Node, Disk, Interface
|
||||
from devops.helpers import tcp_ping, wait, ssh, http_server, os
|
||||
from helpers import load, write_config
|
||||
from settings import controllers, computes
|
||||
from root import root
|
||||
import os
|
||||
|
||||
logger = logging.getLogger('ci')
|
||||
|
||||
class Ci:
|
||||
def __init__(self, image=None, name='recipes'):
|
||||
self.base_image = image
|
||||
self.environment = None
|
||||
self.environment_name = os.environ.get('ENV_NAME', name)
|
||||
try:
|
||||
self.environment = devops.load(self.environment_name)
|
||||
logger.info("Successfully loaded existing environment")
|
||||
except Exception, e:
|
||||
logger.info("Failed to load existing %s environment: " % self.environment_name + str(e) + "\n" + traceback.format_exc())
|
||||
pass
|
||||
|
||||
def get_environment(self):
|
||||
return self.environment
|
||||
|
||||
def add_nmap_yum(self, remote):
|
||||
remote.sudo.ssh.execute('yum -y install nmap')
|
||||
|
||||
def add_epel_repo(self, remote):
|
||||
remote.sudo.ssh.execute('rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm')
|
||||
|
||||
def add_puppetlab_repo(self, remote):
|
||||
remote.sudo.ssh.execute('rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-5.noarch.rpm')
|
||||
|
||||
def remove_puppetlab_repo(self, remote):
|
||||
remote.sudo.ssh.execute('rpm --erase puppetlabs-release-6-5.noarch')
|
||||
|
||||
def setup_puppet_client_yum(self, remote):
|
||||
self.add_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('yum -y install puppet-2.7.19')
|
||||
self.remove_puppetlab_repo(remote)
|
||||
|
||||
def start_puppet_master(self, remote):
|
||||
remote.sudo.ssh.execute('puppet resource service puppetmaster ensure=running enable=true')
|
||||
|
||||
def start_puppet_agent(self, remote):
|
||||
remote.sudo.ssh.execute('puppet resource service puppet ensure=running enable=true')
|
||||
|
||||
def sign_all_node_certificates(self, remote):
|
||||
remote.sudo.ssh.execute('puppet cert sign --all')
|
||||
|
||||
def request_cerificate(self, remote):
|
||||
remote.sudo.ssh.execute('puppet agent --waitforcert 0')
|
||||
|
||||
def switch_off_ip_tables(self, remote):
|
||||
remote.sudo.ssh.execute('iptables -F')
|
||||
|
||||
def setup_puppet_master_yum(self, remote):
|
||||
self.add_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('yum -y install puppet-server-2.7.19 mysql mysql-server mysql-devel rubygems ruby-devel make gcc')
|
||||
self.remove_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('gem install rails -v 3.0.10')
|
||||
remote.sudo.ssh.execute('gem install mysql')
|
||||
remote.sudo.ssh.execute('chkconfig mysql on')
|
||||
remote.sudo.ssh.execute('service mysqld start')
|
||||
remote.sudo.ssh.execute('mysql -u root -e "create database puppet; grant all privileges on puppet.* to puppet@localhost identified by \'password\'; "')
|
||||
remote.sudo.ssh.execute('gem uninstall activerecord')
|
||||
remote.sudo.ssh.execute('gem install activerecord -v 3.0.10')
|
||||
remote.sudo.ssh.execute('setenforce 0')
|
||||
|
||||
def change_host_name(self, remote, short, long):
|
||||
remote.sudo.ssh.execute('hostname %s' % long)
|
||||
remote.sudo.ssh.execute('echo HOSTNAME=%s >> /etc/sysconfig/network' % short)
|
||||
self.add_to_hosts(remote, '127.0.0.1', short, short)
|
||||
|
||||
def add_to_hosts(self, remote, ip, short, long):
|
||||
remote.sudo.ssh.execute('echo %s %s %s >> /etc/hosts' % (ip, long, short))
|
||||
|
||||
def get_environment_or_create(self):
|
||||
if self.get_environment():
|
||||
return self.get_environment()
|
||||
self.setup_environment()
|
||||
return self.environment
|
||||
|
||||
def describe_node(self, name, networks, memory=1024):
|
||||
node = Node(name)
|
||||
node.memory = memory
|
||||
node.vnc = True
|
||||
for network in networks:
|
||||
node.interfaces.append(Interface(network))
|
||||
# node.bridged_interfaces.append(BridgedInterface('br0'))
|
||||
node.disks.append(Disk(base_image=self.base_image, format='qcow2'))
|
||||
node.boot = ['disk']
|
||||
return node
|
||||
|
||||
def describe_environment(self):
|
||||
environment = Environment(self.environment_name)
|
||||
internal = Network(name='internal', dhcp_server=True)
|
||||
environment.networks.append(internal)
|
||||
private = Network(name='private', dhcp_server=False)
|
||||
environment.networks.append(private)
|
||||
public = Network(name='public', dhcp_server=True)
|
||||
environment.networks.append(public)
|
||||
master = self.describe_node('master', [internal, private, public])
|
||||
environment.nodes.append(master)
|
||||
for node_name in controllers:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
for node_name in computes:
|
||||
client = self.describe_node(
|
||||
node_name, [internal, private, public], memory=4096)
|
||||
environment.nodes.append(client)
|
||||
return environment
|
||||
|
||||
def get_file_as_string(self, path):
|
||||
with open(path) as f:
|
||||
return f.read()
|
||||
|
||||
def add_nodes_to_hosts(self, remote, nodes):
|
||||
for node in nodes:
|
||||
self.add_to_hosts(remote, node.ip_address, node.name, node.name)
|
||||
|
||||
def setup_mater_node(self, master_remote, nodes):
|
||||
self.setup_puppet_master_yum(master_remote)
|
||||
self.add_nmap_yum(master_remote)
|
||||
self.switch_off_ip_tables(master_remote)
|
||||
master_config = load(
|
||||
root('fuel', 'fuel_test', 'config', 'puppet.master.config'))
|
||||
write_config(master_remote, '/etc/puppet/puppet.conf', master_config)
|
||||
self.start_puppet_master(master_remote)
|
||||
self.add_nodes_to_hosts(master_remote, nodes)
|
||||
|
||||
def setup_agent_nodes(self, nodes):
|
||||
agent_config = load(
|
||||
root('fuel', 'fuel_test', 'config', 'puppet.agent.config'))
|
||||
for node in nodes:
|
||||
if node.name != 'master':
|
||||
remote = ssh(
|
||||
node.ip_address, username='root',
|
||||
password='r00tme')
|
||||
self.add_nodes_to_hosts(remote, nodes)
|
||||
self.setup_puppet_client_yum(remote)
|
||||
write_config(remote, '/etc/puppet/puppet.conf', agent_config)
|
||||
self.request_cerificate(remote)
|
||||
|
||||
def setup_environment(self):
|
||||
if not self.base_image:
|
||||
raise Exception("Base image path is missing while trying to build %s environment" % self.environment_name)
|
||||
|
||||
logger.info("Building %s environment" % self.environment_name)
|
||||
environment = self.describe_environment()
|
||||
self.environment = environment
|
||||
|
||||
# todo environment should be saved before build
|
||||
devops.build(environment)
|
||||
|
||||
devops.save(environment)
|
||||
logger.info("Environment has been saved")
|
||||
logger.info("Starting test nodes ...")
|
||||
for node in environment.nodes:
|
||||
node.start()
|
||||
for node in environment.nodes:
|
||||
logger.info("Waiting ssh... %s" % node.ip_address)
|
||||
wait(lambda: tcp_ping(node.ip_address, 22), timeout=1800)
|
||||
for node in environment.nodes:
|
||||
remote = ssh(node.ip_address, username='root', password='r00tme')
|
||||
self.change_host_name(remote, node.name, node.name)
|
||||
logger.info("Renamed %s" % node.name)
|
||||
master_node = environment.node['master']
|
||||
master_remote = ssh(master_node.ip_address, username='root', password='r00tme')
|
||||
self.setup_mater_node(master_remote, environment.nodes)
|
||||
self.setup_agent_nodes(environment.nodes)
|
||||
sleep(5)
|
||||
self.sign_all_node_certificates(master_remote)
|
||||
sleep(5)
|
||||
for node in environment.nodes:
|
||||
logger.info("Creating snapshot 'empty'")
|
||||
node.save_snapshot('empty')
|
||||
logger.info("Test node is ready at %s" % node.ip_address)
|
||||
|
||||
def destroy_environment(self):
|
||||
if self.environment:
|
||||
devops.destroy(self.environment)
|
||||
|
||||
def configure_repository(self, remote):
|
||||
repo = ("[mirantis]\n"
|
||||
"name=Mirantis repository\n"
|
||||
"baseurl=http://%s:%d\n"
|
||||
"enabled=1\n"
|
||||
"gpgcheck=0\n") % (
|
||||
self.environment.networks[0].ip_addresses[1],
|
||||
self.repository_server.port)
|
||||
write_config(remote,'/etc/yum/repos.d/mirantis.repo', repo)
|
||||
remote.execute('yum makecache')
|
||||
|
||||
def start_rpm_repository(self):
|
||||
self.repository_server = http_server(
|
||||
root("build", "packages", "centos", "Packages")
|
||||
)
|
||||
|
||||
def shutdown_rpm_repository(self):
|
||||
if hasattr(self, 'repository_server'):
|
||||
self.repository_server.stop()
|
||||
|
||||
|
1
fuel_test/ci/__init__.py
Normal file
1
fuel_test/ci/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__author__ = 'vic'
|
142
fuel_test/ci/ci_base.py
Normal file
142
fuel_test/ci/ci_base.py
Normal file
@ -0,0 +1,142 @@
|
||||
import logging
|
||||
from time import sleep
|
||||
import traceback
|
||||
from abc import abstractproperty
|
||||
import devops
|
||||
from devops.model import Node, Disk, Interface
|
||||
from devops.helpers import tcp_ping, wait, ssh
|
||||
from helpers import load, write_config, sign_all_node_certificates, change_host_name, request_cerificate, setup_puppet_client_yum, setup_puppet_master_yum, add_nmap_yum, switch_off_ip_tables, start_puppet_master, add_to_hosts
|
||||
from settings import BASE_IMAGE
|
||||
from root import root
|
||||
|
||||
|
||||
class CiBase:
|
||||
|
||||
@abstractproperty
|
||||
def env_name(self):
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
self.base_image = BASE_IMAGE
|
||||
self.environment = None
|
||||
self.environment_name = self.env_name
|
||||
try:
|
||||
self.environment = devops.load(self.environment_name)
|
||||
logging.info("Successfully loaded existing environment")
|
||||
except Exception, e:
|
||||
logging.info("Failed to load existing %s environment: " % self.environment_name + str(e) + "\n" + traceback.format_exc())
|
||||
pass
|
||||
|
||||
def get_environment(self):
|
||||
return self.environment
|
||||
|
||||
def node(self, name):
|
||||
return self.environment.node[name]
|
||||
|
||||
def get_environment_or_create(self):
|
||||
if self.get_environment():
|
||||
return self.get_environment()
|
||||
self.setup_environment()
|
||||
return self.environment
|
||||
|
||||
def describe_node(self, name, networks, memory=1024):
|
||||
node = Node(name)
|
||||
node.memory = memory
|
||||
node.vnc = True
|
||||
for network in networks:
|
||||
node.interfaces.append(Interface(network))
|
||||
# node.bridged_interfaces.append(BridgedInterface('br0'))
|
||||
node.disks.append(Disk(base_image=self.base_image, format='qcow2'))
|
||||
node.boot = ['disk']
|
||||
return node
|
||||
|
||||
def describe_environment(self):
|
||||
pass
|
||||
|
||||
def add_nodes_to_hosts(self, remote, nodes):
|
||||
for node in nodes:
|
||||
add_to_hosts(remote, node.ip_address, node.name, node.name)
|
||||
|
||||
def setup_mater_node(self, master_remote, nodes):
|
||||
setup_puppet_master_yum(master_remote)
|
||||
add_nmap_yum(master_remote)
|
||||
switch_off_ip_tables(master_remote)
|
||||
master_config = load(
|
||||
root('fuel', 'fuel_test', 'config', 'puppet.master.config'))
|
||||
write_config(master_remote, '/etc/puppet/puppet.conf', master_config)
|
||||
start_puppet_master(master_remote)
|
||||
self.add_nodes_to_hosts(master_remote, nodes)
|
||||
|
||||
def setup_agent_nodes(self, nodes):
|
||||
agent_config = load(
|
||||
root('fuel', 'fuel_test', 'config', 'puppet.agent.config'))
|
||||
for node in nodes:
|
||||
if node.name != 'master':
|
||||
remote = ssh(
|
||||
node.ip_address, username='root',
|
||||
password='r00tme')
|
||||
self.add_nodes_to_hosts(remote, nodes)
|
||||
setup_puppet_client_yum(remote)
|
||||
write_config(remote, '/etc/puppet/puppet.conf', agent_config)
|
||||
request_cerificate(remote)
|
||||
|
||||
def setup_environment(self):
|
||||
if not self.base_image:
|
||||
raise Exception("Base image path is missing while trying to build %s environment" % self.environment_name)
|
||||
|
||||
logging.info("Building %s environment" % self.environment_name)
|
||||
environment = self.describe_environment()
|
||||
self.environment = environment
|
||||
|
||||
# todo environment should be saved before build
|
||||
devops.build(environment)
|
||||
|
||||
devops.save(environment)
|
||||
logging.info("Environment has been saved")
|
||||
logging.info("Starting test nodes ...")
|
||||
for node in environment.nodes:
|
||||
node.start()
|
||||
for node in environment.nodes:
|
||||
logging.info("Waiting ssh... %s" % node.ip_address)
|
||||
wait(lambda: tcp_ping(node.ip_address, 22), timeout=1800)
|
||||
for node in environment.nodes:
|
||||
remote = ssh(node.ip_address, username='root', password='r00tme')
|
||||
change_host_name(remote, node.name, node.name)
|
||||
logging.info("Renamed %s" % node.name)
|
||||
master_node = environment.node['master']
|
||||
master_remote = ssh(master_node.ip_address, username='root', password='r00tme')
|
||||
self.setup_mater_node(master_remote, environment.nodes)
|
||||
self.setup_agent_nodes(environment.nodes)
|
||||
sleep(5)
|
||||
sign_all_node_certificates(master_remote)
|
||||
sleep(5)
|
||||
for node in environment.nodes:
|
||||
logging.info("Creating snapshot 'empty'")
|
||||
node.save_snapshot('empty')
|
||||
logging.info("Test node is ready at %s" % node.ip_address)
|
||||
|
||||
def destroy_environment(self):
|
||||
if self.environment:
|
||||
devops.destroy(self.environment)
|
||||
|
||||
def get_internal_virtual_ip(self):
|
||||
return self.environment.network['internal'].ip_addresses[-3]
|
||||
|
||||
def get_public_virtual_ip(self):
|
||||
return self.environment.network['public'].ip_addresses[-3]
|
||||
|
||||
def get_floating_network(self):
|
||||
return '.'.join(
|
||||
str(self.environment.network['public'].ip_addresses[-1]).split(
|
||||
'.')[:-1])+'.128/27'
|
||||
|
||||
def get_fixed_network(self):
|
||||
return '.'.join(
|
||||
str(self.environment.network['private'].ip_addresses[-1]).split(
|
||||
'.')[:-1])+'.128/27'
|
||||
|
||||
def get_internal_network(self):
|
||||
network = self.environment.network['internal']
|
||||
return str(network.ip_addresses[1]) +'/' + str(network.ip_addresses.prefixlen)
|
||||
|
||||
|
33
fuel_test/ci/ci_openstack.py
Normal file
33
fuel_test/ci/ci_openstack.py
Normal file
@ -0,0 +1,33 @@
|
||||
from devops.model import Environment, Network
|
||||
import os
|
||||
from ci.ci_base import CiBase
|
||||
|
||||
class CiOpenStack(CiBase):
|
||||
|
||||
controllers = ['fuel-01', 'fuel-02']
|
||||
computes = ['fuel-03', 'fuel-04']
|
||||
|
||||
def env_name(self):
|
||||
return os.environ.get('ENV_NAME', 'recipes')
|
||||
|
||||
def describe_environment(self):
|
||||
environment = Environment(self.environment_name)
|
||||
internal = Network(name='internal', dhcp_server=True)
|
||||
environment.networks.append(internal)
|
||||
private = Network(name='private', dhcp_server=False)
|
||||
environment.networks.append(private)
|
||||
public = Network(name='public', dhcp_server=True)
|
||||
environment.networks.append(public)
|
||||
master = self.describe_node('master', [internal, private, public])
|
||||
environment.nodes.append(master)
|
||||
for node_name in self.controllers:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
for node_name in self.computes:
|
||||
client = self.describe_node(
|
||||
node_name, [internal, private, public], memory=4096)
|
||||
environment.nodes.append(client)
|
||||
return environment
|
||||
|
||||
|
||||
|
@ -1,8 +1,18 @@
|
||||
from devops.model import Environment, Network
|
||||
from ci import Ci
|
||||
from settings import storages,proxies,controllers,computes
|
||||
import os
|
||||
from ci.ci_base import CiBase
|
||||
|
||||
|
||||
class CiOpenStackSwift(CiBase):
|
||||
|
||||
controllers = ['fuel-01', 'fuel-02']
|
||||
computes = ['fuel-03', 'fuel-04']
|
||||
storages = ['fuel-05', 'fuel-06', 'fuel-07']
|
||||
proxies = ['fuel-08']
|
||||
|
||||
def env_name(self):
|
||||
return os.environ.get('ENV_NAME', 'recipes-swift')
|
||||
|
||||
class CiOpenStackSwift(Ci):
|
||||
def describe_environment(self):
|
||||
environment = Environment(self.environment_name)
|
||||
internal = Network(name='internal', dhcp_server=True)
|
||||
@ -13,17 +23,17 @@ class CiOpenStackSwift(Ci):
|
||||
environment.networks.append(public)
|
||||
master = self.describe_node('master', [internal, private, public])
|
||||
environment.nodes.append(master)
|
||||
for node_name in controllers:
|
||||
for node_name in self.controllers:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
for node_name in computes:
|
||||
for node_name in self.computes:
|
||||
client = self.describe_node(
|
||||
node_name, [internal, private, public], memory=4096)
|
||||
environment.nodes.append(client)
|
||||
for node_name in storages:
|
||||
for node_name in self.storages:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
for node_name in proxies:
|
||||
for node_name in self.proxies:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
return environment
|
35
fuel_test/ci/ci_openstack_swift_compact.py
Normal file
35
fuel_test/ci/ci_openstack_swift_compact.py
Normal file
@ -0,0 +1,35 @@
|
||||
from devops.model import Environment, Network
|
||||
import os
|
||||
from ci.ci_base import CiBase
|
||||
|
||||
|
||||
class CiOpenStackSwiftCompact(CiBase):
|
||||
|
||||
controllers = ['fuel-01', 'fuel-02','fuel-03']
|
||||
computes = ['fuel-04', 'fuel-05']
|
||||
|
||||
def env_name(self):
|
||||
return os.environ.get('ENV_NAME', 'recipes-swift-compact')
|
||||
|
||||
def describe_environment(self):
|
||||
environment = Environment(self.environment_name)
|
||||
internal = Network(name='internal', dhcp_server=True)
|
||||
environment.networks.append(internal)
|
||||
private = Network(name='private', dhcp_server=False)
|
||||
environment.networks.append(private)
|
||||
public = Network(name='public', dhcp_server=True)
|
||||
environment.networks.append(public)
|
||||
master = self.describe_node('master', [internal, private, public])
|
||||
environment.nodes.append(master)
|
||||
for node_name in self.controllers:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
for node_name in self.computes:
|
||||
client = self.describe_node(
|
||||
node_name, [internal, private, public], memory=4096)
|
||||
environment.nodes.append(client)
|
||||
return environment
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,16 @@
|
||||
from devops.model import Environment, Network
|
||||
from ci import Ci
|
||||
from settings import storages,proxies,keystones
|
||||
import os
|
||||
from ci.ci_base import CiBase
|
||||
|
||||
class CiSwift(CiBase):
|
||||
|
||||
storages = ['fuel-05', 'fuel-06', 'fuel-07']
|
||||
proxies = ['fuel-08']
|
||||
keystones = ['keystone']
|
||||
|
||||
def env_name(self):
|
||||
return os.environ.get('ENV_NAME', 'swift')
|
||||
|
||||
class CiSwift(Ci):
|
||||
def describe_environment(self):
|
||||
environment = Environment(self.environment_name)
|
||||
internal = Network(name='internal', dhcp_server=True)
|
||||
@ -13,13 +21,13 @@ class CiSwift(Ci):
|
||||
environment.networks.append(public)
|
||||
master = self.describe_node('master', [internal, private, public])
|
||||
environment.nodes.append(master)
|
||||
for node_name in keystones:
|
||||
for node_name in self.keystones:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
for node_name in storages:
|
||||
for node_name in self.storages:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
for node_name in proxies:
|
||||
for node_name in self.proxies:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
return environment
|
@ -1,26 +0,0 @@
|
||||
import os
|
||||
from ci import Ci
|
||||
from ciswift import CiSwift
|
||||
from ciopenstackswift import CiOpenStackSwift
|
||||
from ciopenstackswiftcompact import Ci as CiOpenStackSwiftCompact
|
||||
|
||||
|
||||
def get_ci(image=None):
|
||||
name = os.environ.get('ENV_NAME','recipes')
|
||||
if name == 'recipes-swift':
|
||||
ci = CiSwift(image,name)
|
||||
elif name == 'recipes-openstack-swift':
|
||||
ci = CiOpenStackSwift(image,name)
|
||||
elif name == 'recipes-openstack-swift-compact':
|
||||
ci = CiOpenStackSwiftCompact(image,name)
|
||||
else:
|
||||
ci = Ci(image,name)
|
||||
return ci
|
||||
|
||||
|
||||
def get_environment_or_create(image=None):
|
||||
return get_ci(image).get_environment_or_create()
|
||||
|
||||
|
||||
def get_environment():
|
||||
return get_ci().get_environment()
|
@ -1,208 +0,0 @@
|
||||
import logging
|
||||
from time import sleep
|
||||
import traceback
|
||||
import devops
|
||||
from devops.model import Environment, Network, Node, Disk, Interface
|
||||
from devops.helpers import tcp_ping, wait, ssh, http_server, os
|
||||
from helpers import load, write_config
|
||||
from settings_compact import controllers, computes
|
||||
from root import root
|
||||
import os
|
||||
|
||||
logger = logging.getLogger('ci')
|
||||
|
||||
class Ci:
|
||||
def __init__(self, image=None, name='recipes'):
|
||||
self.base_image = image
|
||||
self.environment = None
|
||||
self.environment_name = os.environ.get('ENV_NAME', name)
|
||||
try:
|
||||
self.environment = devops.load(self.environment_name)
|
||||
logger.info("Successfully loaded existing environment")
|
||||
except Exception, e:
|
||||
logger.info("Failed to load existing %s environment: " % self.environment_name + str(e) + "\n" + traceback.format_exc())
|
||||
pass
|
||||
|
||||
def get_environment(self):
|
||||
return self.environment
|
||||
|
||||
def add_nmap_yum(self, remote):
|
||||
remote.sudo.ssh.execute('yum -y install nmap')
|
||||
|
||||
def add_epel_repo(self, remote):
|
||||
remote.sudo.ssh.execute('rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm')
|
||||
|
||||
def add_puppetlab_repo(self, remote):
|
||||
remote.sudo.ssh.execute('rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-5.noarch.rpm')
|
||||
|
||||
def remove_puppetlab_repo(self, remote):
|
||||
remote.sudo.ssh.execute('rpm --erase puppetlabs-release-6-5.noarch')
|
||||
|
||||
def setup_puppet_client_yum(self, remote):
|
||||
self.add_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('yum -y install puppet-2.7.19')
|
||||
self.remove_puppetlab_repo(remote)
|
||||
|
||||
def start_puppet_master(self, remote):
|
||||
remote.sudo.ssh.execute('puppet resource service puppetmaster ensure=running enable=true')
|
||||
|
||||
def start_puppet_agent(self, remote):
|
||||
remote.sudo.ssh.execute('puppet resource service puppet ensure=running enable=true')
|
||||
|
||||
def sign_all_node_certificates(self, remote):
|
||||
remote.sudo.ssh.execute('puppet cert sign --all')
|
||||
|
||||
def request_cerificate(self, remote):
|
||||
remote.sudo.ssh.execute('puppet agent --waitforcert 0')
|
||||
|
||||
def switch_off_ip_tables(self, remote):
|
||||
remote.sudo.ssh.execute('iptables -F')
|
||||
|
||||
def setup_puppet_master_yum(self, remote):
|
||||
self.add_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('yum -y install puppet-server-2.7.19 mysql mysql-server mysql-devel rubygems ruby-devel make gcc')
|
||||
self.remove_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('gem install rails -v 3.0.10')
|
||||
remote.sudo.ssh.execute('gem install mysql')
|
||||
remote.sudo.ssh.execute('chkconfig mysql on')
|
||||
remote.sudo.ssh.execute('service mysqld start')
|
||||
remote.sudo.ssh.execute('mysql -u root -e "create database puppet; grant all privileges on puppet.* to puppet@localhost identified by \'password\'; "')
|
||||
remote.sudo.ssh.execute('gem uninstall activerecord')
|
||||
remote.sudo.ssh.execute('gem install activerecord -v 3.0.10')
|
||||
remote.sudo.ssh.execute('setenforce 0')
|
||||
|
||||
def change_host_name(self, remote, short, long):
|
||||
remote.sudo.ssh.execute('hostname %s' % long)
|
||||
remote.sudo.ssh.execute('echo HOSTNAME=%s >> /etc/sysconfig/network' % short)
|
||||
self.add_to_hosts(remote, '127.0.0.1', short, short)
|
||||
|
||||
def add_to_hosts(self, remote, ip, short, long):
|
||||
remote.sudo.ssh.execute('echo %s %s %s >> /etc/hosts' % (ip, long, short))
|
||||
|
||||
def get_environment_or_create(self):
|
||||
if self.get_environment():
|
||||
return self.get_environment()
|
||||
self.setup_environment()
|
||||
return self.environment
|
||||
|
||||
def describe_node(self, name, networks, memory=1024):
|
||||
node = Node(name)
|
||||
node.memory = memory
|
||||
node.vnc = True
|
||||
for network in networks:
|
||||
node.interfaces.append(Interface(network))
|
||||
# node.bridged_interfaces.append(BridgedInterface('br0'))
|
||||
node.disks.append(Disk(base_image=self.base_image, format='qcow2'))
|
||||
node.boot = ['disk']
|
||||
return node
|
||||
|
||||
def describe_environment(self):
|
||||
environment = Environment(self.environment_name)
|
||||
internal = Network(name='internal', dhcp_server=True)
|
||||
environment.networks.append(internal)
|
||||
private = Network(name='private', dhcp_server=False)
|
||||
environment.networks.append(private)
|
||||
public = Network(name='public', dhcp_server=True)
|
||||
environment.networks.append(public)
|
||||
master = self.describe_node('master', [internal, private, public])
|
||||
environment.nodes.append(master)
|
||||
for node_name in controllers:
|
||||
client = self.describe_node(node_name, [internal, private, public])
|
||||
environment.nodes.append(client)
|
||||
for node_name in computes:
|
||||
client = self.describe_node(
|
||||
node_name, [internal, private, public], memory=4096)
|
||||
environment.nodes.append(client)
|
||||
return environment
|
||||
|
||||
def get_file_as_string(self, path):
|
||||
with open(path) as f:
|
||||
return f.read()
|
||||
|
||||
def add_nodes_to_hosts(self, remote, nodes):
|
||||
for node in nodes:
|
||||
self.add_to_hosts(remote, node.ip_address, node.name, node.name)
|
||||
|
||||
def setup_mater_node(self, master_remote, nodes):
|
||||
self.setup_puppet_master_yum(master_remote)
|
||||
self.add_nmap_yum(master_remote)
|
||||
self.switch_off_ip_tables(master_remote)
|
||||
master_config = load(
|
||||
root('fuel', 'fuel_test', 'config', 'puppet.master.config'))
|
||||
write_config(master_remote, '/etc/puppet/puppet.conf', master_config)
|
||||
self.start_puppet_master(master_remote)
|
||||
self.add_nodes_to_hosts(master_remote, nodes)
|
||||
|
||||
def setup_agent_nodes(self, nodes):
|
||||
agent_config = load(
|
||||
root('fuel', 'fuel_test', 'config', 'puppet.agent.config'))
|
||||
for node in nodes:
|
||||
if node.name != 'master':
|
||||
remote = ssh(
|
||||
node.ip_address, username='root',
|
||||
password='r00tme')
|
||||
self.add_nodes_to_hosts(remote, nodes)
|
||||
self.setup_puppet_client_yum(remote)
|
||||
write_config(remote, '/etc/puppet/puppet.conf', agent_config)
|
||||
self.request_cerificate(remote)
|
||||
|
||||
def setup_environment(self):
|
||||
if not self.base_image:
|
||||
raise Exception("Base image path is missing while trying to build %s environment" % self.environment_name)
|
||||
|
||||
logger.info("Building %s environment" % self.environment_name)
|
||||
environment = self.describe_environment()
|
||||
self.environment = environment
|
||||
|
||||
# todo environment should be saved before build
|
||||
devops.build(environment)
|
||||
|
||||
devops.save(environment)
|
||||
logger.info("Environment has been saved")
|
||||
logger.info("Starting test nodes ...")
|
||||
for node in environment.nodes:
|
||||
node.start()
|
||||
for node in environment.nodes:
|
||||
logger.info("Waiting ssh... %s" % node.ip_address)
|
||||
wait(lambda: tcp_ping(node.ip_address, 22), timeout=1800)
|
||||
for node in environment.nodes:
|
||||
remote = ssh(node.ip_address, username='root', password='r00tme')
|
||||
self.change_host_name(remote, node.name, node.name)
|
||||
logger.info("Renamed %s" % node.name)
|
||||
master_node = environment.node['master']
|
||||
master_remote = ssh(master_node.ip_address, username='root', password='r00tme')
|
||||
self.setup_mater_node(master_remote, environment.nodes)
|
||||
self.setup_agent_nodes(environment.nodes)
|
||||
sleep(5)
|
||||
self.sign_all_node_certificates(master_remote)
|
||||
sleep(5)
|
||||
for node in environment.nodes:
|
||||
logger.info("Creating snapshot 'empty'")
|
||||
node.save_snapshot('empty')
|
||||
logger.info("Test node is ready at %s" % node.ip_address)
|
||||
|
||||
def destroy_environment(self):
|
||||
if self.environment:
|
||||
devops.destroy(self.environment)
|
||||
|
||||
def configure_repository(self, remote):
|
||||
repo = ("[mirantis]\n"
|
||||
"name=Mirantis repository\n"
|
||||
"baseurl=http://%s:%d\n"
|
||||
"enabled=1\n"
|
||||
"gpgcheck=0\n") % (
|
||||
self.environment.networks[0].ip_addresses[1],
|
||||
self.repository_server.port)
|
||||
write_config(remote,'/etc/yum/repos.d/mirantis.repo', repo)
|
||||
remote.execute('yum makecache')
|
||||
|
||||
def start_rpm_repository(self):
|
||||
self.repository_server = http_server(
|
||||
root("build", "packages", "centos", "Packages")
|
||||
)
|
||||
|
||||
def shutdown_rpm_repository(self):
|
||||
if hasattr(self, 'repository_server'):
|
||||
self.repository_server.stop()
|
||||
|
||||
|
23
fuel_test/destroy.py
Normal file
23
fuel_test/destroy.py
Normal file
@ -0,0 +1,23 @@
|
||||
import logging
|
||||
import argparse
|
||||
import devops
|
||||
import os
|
||||
|
||||
def get_params():
|
||||
parser = argparse.ArgumentParser(description="Integration test suite")
|
||||
parser.add_argument('command', choices=('setup', 'destroy'),
|
||||
default='setup',
|
||||
help="command to execute")
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
params = get_params()
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
||||
if params.command == 'destroy':
|
||||
name = os.environ.get('ENV_NAME', 'recipes')
|
||||
devops.destroy(devops.load(name))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -5,6 +5,10 @@ from root import root
|
||||
from settings import controllers
|
||||
#from glanceclient import Client
|
||||
|
||||
def get_file_as_string(path):
|
||||
with open(path) as f:
|
||||
return f.read()
|
||||
|
||||
def execute(remote, command):
|
||||
chan, stdin, stderr, stdout = execute_async(remote, command)
|
||||
result = {
|
||||
@ -139,3 +143,67 @@ def retry(count, func, **kwargs):
|
||||
i += 1
|
||||
sleep(1)
|
||||
|
||||
|
||||
def add_nmap_yum(remote):
|
||||
remote.sudo.ssh.execute('yum -y install nmap')
|
||||
|
||||
def add_epel_repo(remote):
|
||||
remote.sudo.ssh.execute('rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm')
|
||||
|
||||
def add_puppetlab_repo(remote):
|
||||
remote.sudo.ssh.execute('rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-5.noarch.rpm')
|
||||
|
||||
def remove_puppetlab_repo(remote):
|
||||
remote.sudo.ssh.execute('rpm --erase puppetlabs-release-6-5.noarch')
|
||||
|
||||
def setup_puppet_client_yum(remote):
|
||||
add_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('yum -y install puppet-2.7.19')
|
||||
remove_puppetlab_repo(remote)
|
||||
|
||||
def start_puppet_master(remote):
|
||||
remote.sudo.ssh.execute('puppet resource service puppetmaster ensure=running enable=true')
|
||||
|
||||
def start_puppet_agent(remote):
|
||||
remote.sudo.ssh.execute('puppet resource service puppet ensure=running enable=true')
|
||||
|
||||
def sign_all_node_certificates(remote):
|
||||
remote.sudo.ssh.execute('puppet cert sign --all')
|
||||
|
||||
def request_cerificate(remote):
|
||||
remote.sudo.ssh.execute('puppet agent --waitforcert 0')
|
||||
|
||||
def switch_off_ip_tables(remote):
|
||||
remote.sudo.ssh.execute('iptables -F')
|
||||
|
||||
def setup_puppet_master_yum(remote):
|
||||
add_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('yum -y install puppet-server-2.7.19 mysql mysql-server mysql-devel rubygems ruby-devel make gcc')
|
||||
remove_puppetlab_repo(remote)
|
||||
remote.sudo.ssh.execute('gem install rails -v 3.0.10')
|
||||
remote.sudo.ssh.execute('gem install mysql')
|
||||
remote.sudo.ssh.execute('chkconfig mysql on')
|
||||
remote.sudo.ssh.execute('service mysqld start')
|
||||
remote.sudo.ssh.execute('mysql -u root -e "create database puppet; grant all privileges on puppet.* to puppet@localhost identified by \'password\'; "')
|
||||
remote.sudo.ssh.execute('gem uninstall activerecord')
|
||||
remote.sudo.ssh.execute('gem install activerecord -v 3.0.10')
|
||||
remote.sudo.ssh.execute('setenforce 0')
|
||||
|
||||
def change_host_name(remote, short, long):
|
||||
remote.sudo.ssh.execute('hostname %s' % long)
|
||||
remote.sudo.ssh.execute('echo HOSTNAME=%s >> /etc/sysconfig/network' % short)
|
||||
add_to_hosts(remote, '127.0.0.1', short, short)
|
||||
|
||||
def add_to_hosts(remote, ip, short, long):
|
||||
remote.sudo.ssh.execute('echo %s %s %s >> /etc/hosts' % (ip, long, short))
|
||||
|
||||
def safety_revert_nodes(nodes, snapsot_name = 'openstack'):
|
||||
for node in nodes:
|
||||
try:
|
||||
node.stop()
|
||||
except:
|
||||
pass
|
||||
for node in nodes:
|
||||
node.restore_snapshot(snapsot_name)
|
||||
sleep(4)
|
||||
# sync_time(ssh(node.ip_address, username='root', password='r00tme').sudo.ssh)
|
||||
|
@ -1,33 +0,0 @@
|
||||
import logging
|
||||
import argparse
|
||||
from ci_helpers import get_environment_or_create, get_ci
|
||||
|
||||
def get_params():
|
||||
parser = argparse.ArgumentParser(description="Integration test suite")
|
||||
parser.add_argument("-i", "--image", dest="image",
|
||||
help="base image path or http://url")
|
||||
parser.add_argument("-l", "--level", dest="log_level", type=str,
|
||||
help="log level", choices=["DEBUG", "INFO", "WARNING", "ERROR"],
|
||||
default="INFO", metavar="LEVEL")
|
||||
parser.add_argument('command', choices=('setup', 'destroy'),
|
||||
default='setup',
|
||||
help="command to execute")
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
params = get_params()
|
||||
|
||||
numeric_level = getattr(logging, params.log_level.upper())
|
||||
logging.basicConfig(level=numeric_level)
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(numeric_level + 1)
|
||||
|
||||
|
||||
if params.command == 'setup':
|
||||
get_environment_or_create(params.image)
|
||||
elif params.command == 'destroy':
|
||||
get_ci().destroy_environment()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
1
fuel_test/openstack/__init__.py
Normal file
1
fuel_test/openstack/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__author__ = 'vic'
|
49
fuel_test/openstack/openstack_test_case.py
Normal file
49
fuel_test/openstack/openstack_test_case.py
Normal file
@ -0,0 +1,49 @@
|
||||
import unittest
|
||||
from base_test_case import BaseTestCase
|
||||
from ci.ci_openstack import CiOpenStack
|
||||
from root import root
|
||||
|
||||
class OpenStackTestCase(BaseTestCase):
|
||||
|
||||
def ci(self):
|
||||
if self.ci:
|
||||
return self.ci
|
||||
return CiOpenStack()
|
||||
|
||||
def setUp(self):
|
||||
super(OpenStackTestCase, self).setUp()
|
||||
self.controller1 = self.environment.node[self.ci().controllers[0]]
|
||||
self.controller2 = self.environment.node[self.ci().controllers[1]]
|
||||
self.compute1 = self.environment.node[self.ci().computes[0]]
|
||||
self.compute2 = self.environment.node[self.ci().computes[1]]
|
||||
self.write_openstack_sitepp(self.controller1, self.controller2)
|
||||
|
||||
|
||||
def write_openstack_sitepp(self, node01, node02):
|
||||
self.write_site_pp_manifest(
|
||||
root('fuel', 'deployment', 'puppet', 'openstack', 'examples',
|
||||
'site.pp'),
|
||||
internal_virtual_ip="'%s'" % self.ci().get_internal_virtual_ip(),
|
||||
public_virtual_ip="'%s'" % self.ci().get_public_virtual_ip(),
|
||||
floating_range = "'%s'" % self.ci().get_floating_network(),
|
||||
fixed_range = "'%s'" % self.ci().get_fixed_network(),
|
||||
master_hostname="'%s'" % node01.name,
|
||||
controller_public_addresses="{ '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['public'],node02.name,node02.ip_address_by_network['public']),
|
||||
controller_internal_addresses="{ '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['internal'],node02.name,node02.ip_address_by_network['internal']),
|
||||
controller_hostnames = [
|
||||
"%s" % node01.name,
|
||||
"%s" % node02.name],
|
||||
public_interface="'eth2'",
|
||||
internal_interface="'eth0'",
|
||||
internal_address="$ipaddress_eth0",
|
||||
private_interface="'eth1'"
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
from devops.helpers import ssh, tcp_ping
|
||||
from django.utils.unittest.case import skip
|
||||
from base import RecipeTestCase
|
||||
from base_test_case import BaseTestCase
|
||||
from helpers import execute
|
||||
from settings import NODES
|
||||
from root import root
|
||||
@ -13,7 +13,7 @@ import unittest
|
||||
#todo async command execution with logging
|
||||
|
||||
|
||||
class MyTestCase(RecipeTestCase):
|
||||
class MyTestCase(BaseTestCase):
|
||||
|
||||
def test_apply_all_modules_with_noop(self):
|
||||
result = self.master_remote.execute("for i in `find /etc/puppet/modules/ | grep tests/.*pp`; do puppet apply --modulepath=/etc/puppet/modules/ --noop $i ; done")
|
@ -1,15 +1,12 @@
|
||||
from devops.helpers import ssh, tcp_ping
|
||||
from base import RecipeTestCase
|
||||
from helpers import udp_ping, execute
|
||||
from openstack.openstack_test_case import OpenStackTestCase
|
||||
from root import root
|
||||
from settings import NODES
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
class CobblerTestCase(RecipeTestCase):
|
||||
class CobblerTestCase(OpenStackTestCase):
|
||||
def test_deploy_cobbler(self):
|
||||
node01 = self.environment.node[NODES[0]]
|
||||
node01 = self.environment.node[self.ci.controlelrs[0]]
|
||||
self.write_site_pp_manifest(
|
||||
root('fuel', 'deployment', 'puppet', 'cobbler', 'examples', 'server_site.pp'),
|
||||
server = "'%s'" % node01.ip_address,
|
@ -1,8 +1,8 @@
|
||||
from openstack_site_pp_base import OpenStackSitePPBaseTestCase
|
||||
import unittest
|
||||
from openstack.openstack_test_case import OpenStackTestCase
|
||||
|
||||
|
||||
class NovaSubClassesTestCase(OpenStackSitePPBaseTestCase):
|
||||
class NovaSubClassesTestCase(OpenStackTestCase):
|
||||
def test_deploy_nova_compute(self):
|
||||
self.validate(
|
||||
[self.compute1, ],
|
@ -1,75 +0,0 @@
|
||||
from devops.helpers import ssh
|
||||
from base import RecipeTestCase
|
||||
from helpers import execute
|
||||
from settings import controllers, computes
|
||||
from root import root
|
||||
|
||||
import unittest
|
||||
|
||||
class OpenStackSitePPBaseTestCase(RecipeTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(OpenStackSitePPBaseTestCase, self).setUp()
|
||||
self.controller1 = self.environment.node[controllers[0]]
|
||||
self.controller2 = self.environment.node[controllers[1]]
|
||||
self.compute1 = self.environment.node[computes[0]]
|
||||
self.compute2 = self.environment.node[computes[1]]
|
||||
|
||||
def get_internal_virtual_ip(self):
|
||||
return self.environment.network['internal'].ip_addresses[-3]
|
||||
|
||||
def get_public_virtual_ip(self):
|
||||
return self.environment.network['public'].ip_addresses[-3]
|
||||
|
||||
def get_floating_network(self):
|
||||
return '.'.join(
|
||||
str(self.environment.network['public'].ip_addresses[-1]).split(
|
||||
'.')[:-1])+'.128/27'
|
||||
|
||||
def get_fixed_network(self):
|
||||
return '.'.join(
|
||||
str(self.environment.network['private'].ip_addresses[-1]).split(
|
||||
'.')[:-1])+'.128/27'
|
||||
|
||||
def get_internal_network(self):
|
||||
network = self.environment.network['internal']
|
||||
return str(network.ip_addresses[1]) +'/' + str(network.ip_addresses.prefixlen)
|
||||
|
||||
def write_openstack_sitepp(self, node01, node02):
|
||||
self.write_site_pp_manifest(
|
||||
root('fuel', 'deployment', 'puppet', 'openstack', 'examples',
|
||||
'site.pp'),
|
||||
internal_virtual_ip="'%s'" % self.get_internal_virtual_ip(),
|
||||
public_virtual_ip="'%s'" % self.get_public_virtual_ip(),
|
||||
floating_range = "'%s'" % self.get_floating_network(),
|
||||
fixed_range = "'%s'" % self.get_fixed_network(),
|
||||
master_hostname="'%s'" % node01.name,
|
||||
controller_public_addresses="{ '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['public'],node02.name,node02.ip_address_by_network['public']),
|
||||
controller_internal_addresses="{ '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['internal'],node02.name,node02.ip_address_by_network['internal']),
|
||||
controller_hostnames = [
|
||||
"%s" % node01.name,
|
||||
"%s" % node02.name],
|
||||
public_interface="'eth2'",
|
||||
internal_interface="'eth0'",
|
||||
internal_address="$ipaddress_eth0",
|
||||
private_interface="'eth1'"
|
||||
)
|
||||
|
||||
def do(self, nodes, command):
|
||||
self.write_openstack_sitepp(self.controller1, self.controller2)
|
||||
results = []
|
||||
for node in nodes:
|
||||
remote = ssh(node.ip_address, username='root', password='r00tme')
|
||||
results.append(execute(remote.sudo.ssh, command))
|
||||
return results
|
||||
|
||||
def validate(self, nodes, command):
|
||||
results = self.do(nodes, command)
|
||||
for result in results:
|
||||
self.assertResult(result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
1
fuel_test/openstack_swift/__init__.py
Normal file
1
fuel_test/openstack_swift/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__author__ = 'vic'
|
@ -0,0 +1,43 @@
|
||||
from base_test_case import BaseTestCase
|
||||
from ci.ci_openstack_swift_compact import CiOpenStackSwiftCompact
|
||||
from root import root
|
||||
|
||||
class OpenStackSwiftCompactTestCase(BaseTestCase):
|
||||
|
||||
def ci(self):
|
||||
if self.ci:
|
||||
return self.ci
|
||||
return CiOpenStackSwiftCompact()
|
||||
|
||||
def setUp(self):
|
||||
super(OpenStackSwiftCompactTestCase, self).setUp()
|
||||
self.controller1 = self.environment.node[self.ci().controllers[0]]
|
||||
self.controller2 = self.environment.node[self.ci().controllers[1]]
|
||||
self.controller3 = self.environment.node[self.ci().controllers[2]]
|
||||
self.compute1 = self.environment.node[self.ci().computes[0]]
|
||||
self.compute2 = self.environment.node[self.ci().computes[1]]
|
||||
self.write_openstack_sitepp(self.controller1, self.controller2, self.controller3)
|
||||
|
||||
def write_openstack_sitepp(self, controller1, controller2, controller3):
|
||||
self.write_site_pp_manifest(
|
||||
root('fuel', 'deployment', 'puppet', 'openstack', 'examples',
|
||||
'site_openstack_swift_compact.pp'),
|
||||
internal_virtual_ip="'%s'" % self.ci().get_internal_virtual_ip(),
|
||||
public_virtual_ip="'%s'" % self.ci().get_public_virtual_ip(),
|
||||
floating_range = "'%s'" % self.ci().get_floating_network(),
|
||||
fixed_range = "'%s'" % self.ci().get_fixed_network(),
|
||||
master_hostname="'%s'" % controller1.name,
|
||||
swift_proxy_address = "'%s'" % self.ci().get_internal_virtual_ip(),
|
||||
controller_public_addresses="{ '%s' => '%s', '%s' => '%s', '%s' => '%s' }"
|
||||
% (controller1.name,controller1.ip_address_by_network['public'],controller2.name,controller2.ip_address_by_network['public'],controller3.name,controller3.ip_address_by_network['public']),
|
||||
controller_internal_addresses="{ '%s' => '%s', '%s' => '%s', '%s' => '%s' }"
|
||||
% (controller1.name,controller1.ip_address_by_network['internal'],controller2.name,controller2.ip_address_by_network['internal'],controller3.name,controller3.ip_address_by_network['internal']),
|
||||
controller_hostnames=[
|
||||
"%s" % controller1.name,
|
||||
"%s" % controller2.name,
|
||||
"%s" % controller3.name],
|
||||
public_interface="'eth2'",
|
||||
internal_interface="'eth0'",
|
||||
internal_address="$ipaddress_eth0",
|
||||
private_interface="'eth1'"
|
||||
)
|
@ -1,10 +1,9 @@
|
||||
from openstack_swift_site_pp_base import OpenStackSwiftSitePPBaseTestCase
|
||||
from helpers import execute
|
||||
from settings import storages,proxies
|
||||
from devops.helpers import ssh
|
||||
import unittest
|
||||
from openstack_swift.openstack_swift_compact_test_case import OpenStackSwiftCompactTestCase
|
||||
|
||||
class OpenStackSwiftCase(OpenStackSwiftSitePPBaseTestCase):
|
||||
class OpenStackSwiftCase(OpenStackSwiftCompactTestCase):
|
||||
|
||||
def test_deploy_open_stack_swift(self):
|
||||
storage1 = self.environment.node[storages[0]]
|
1
fuel_test/openstack_swift_compact/__init__.py
Normal file
1
fuel_test/openstack_swift_compact/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__author__ = 'vic'
|
@ -0,0 +1,45 @@
|
||||
from base_test_case import BaseTestCase
|
||||
from ci.ci_openstack_swift import CiOpenStackSwift
|
||||
from root import root
|
||||
|
||||
class OpenStackSwiftTestCase(BaseTestCase):
|
||||
|
||||
def ci(self):
|
||||
if self.ci:
|
||||
return self.ci
|
||||
return CiOpenStackSwift()
|
||||
|
||||
def setUp(self):
|
||||
super(OpenStackSwiftTestCase, self).setUp()
|
||||
self.controller1 = self.environment.node[self.ci().controllers[0]]
|
||||
self.controller2 = self.environment.node[self.ci().controllers[1]]
|
||||
self.compute1 = self.environment.node[self.ci().computes[0]]
|
||||
self.compute2 = self.environment.node[self.ci().computes[1]]
|
||||
self.storage1 = self.environment.node[self.ci().storages[0]]
|
||||
self.storage2 = self.environment.node[self.ci().storages[1]]
|
||||
self.storage3 = self.environment.node[self.ci().storages[2]]
|
||||
self.proxy1 = self.environment.node[self.ci().proxies[0]]
|
||||
self.write_openstack_sitepp(self.controller1, self.controller2, self.proxy1)
|
||||
|
||||
def write_openstack_sitepp(self, node01, node02, node03):
|
||||
self.write_site_pp_manifest(
|
||||
root('fuel', 'deployment', 'puppet', 'openstack', 'examples',
|
||||
'site_openstack_swift_standalone.pp'),
|
||||
internal_virtual_ip="'%s'" % self.ci().get_internal_virtual_ip(),
|
||||
public_virtual_ip="'%s'" % self.ci().get_public_virtual_ip(),
|
||||
floating_range = "'%s'" % self.ci().get_floating_network(),
|
||||
fixed_range = "'%s'" % self.ci().get_fixed_network(),
|
||||
master_hostname="'%s'" % node01.name,
|
||||
swift_proxy_address = "'%s'" % node03.ip_address_by_network['internal'],
|
||||
controller_public_addresses="{ '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['public'],node02.name,node02.ip_address_by_network['public']),
|
||||
controller_internal_addresses="{ '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['internal'],node02.name,node02.ip_address_by_network['internal']),
|
||||
controller_hostnames=[
|
||||
"%s" % node01.name,
|
||||
"%s" % node02.name],
|
||||
public_interface="'eth2'",
|
||||
internal_interface="'eth0'",
|
||||
internal_address="$ipaddress_eth0",
|
||||
private_interface="'eth1'"
|
||||
)
|
@ -1,9 +1,9 @@
|
||||
from openstack_swift_compact_site_pp_base import OpenStackSwiftCompactSitePPBaseTestCase
|
||||
from helpers import execute
|
||||
from devops.helpers import ssh
|
||||
import unittest
|
||||
from openstack_swift_compact.openstack_swift_test_case import OpenStackSwiftTestCase
|
||||
|
||||
class OpenStackSwiftCompactCase(OpenStackSwiftCompactSitePPBaseTestCase):
|
||||
class OpenStackSwiftCompactCase(OpenStackSwiftTestCase):
|
||||
def test_deploy_open_stack_swift_compact(self):
|
||||
self.validate(
|
||||
[self.controller1,self.controller2,self.controller3],
|
@ -1,78 +0,0 @@
|
||||
from devops.helpers import ssh
|
||||
from base import RecipeTestCase
|
||||
from helpers import execute
|
||||
from settings_compact import controllers,computes
|
||||
from root import root
|
||||
|
||||
import unittest
|
||||
|
||||
class OpenStackSwiftCompactSitePPBaseTestCase(RecipeTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(OpenStackSwiftCompactSitePPBaseTestCase, self).setUp()
|
||||
self.controller1 = self.environment.node[controllers[0]]
|
||||
self.controller2 = self.environment.node[controllers[1]]
|
||||
self.controller3 = self.environment.node[controllers[2]]
|
||||
self.compute1 = self.environment.node[computes[0]]
|
||||
self.compute2 = self.environment.node[computes[1]]
|
||||
|
||||
def get_internal_virtual_ip(self):
|
||||
return self.environment.network['internal'].ip_addresses[-3]
|
||||
|
||||
def get_public_virtual_ip(self):
|
||||
return self.environment.network['public'].ip_addresses[-3]
|
||||
|
||||
def get_floating_network(self):
|
||||
return '.'.join(
|
||||
str(self.environment.network['public'].ip_addresses[-1]).split(
|
||||
'.')[:-1])+'.128/27'
|
||||
|
||||
def get_fixed_network(self):
|
||||
return '.'.join(
|
||||
str(self.environment.network['private'].ip_addresses[-1]).split(
|
||||
'.')[:-1])+'.128/27'
|
||||
|
||||
def get_internal_network(self):
|
||||
network = self.environment.network['internal']
|
||||
return str(network.ip_addresses[1]) +'/' + str(network.ip_addresses.prefixlen)
|
||||
|
||||
def write_openstack_sitepp(self, node01, node02, node03):
|
||||
self.write_site_pp_manifest(
|
||||
root('fuel', 'deployment', 'puppet', 'openstack', 'examples',
|
||||
'site_openstack_swift_compact.pp'),
|
||||
internal_virtual_ip="'%s'" % self.get_internal_virtual_ip(),
|
||||
public_virtual_ip="'%s'" % self.get_public_virtual_ip(),
|
||||
floating_range = "'%s'" % self.get_floating_network(),
|
||||
fixed_range = "'%s'" % self.get_fixed_network(),
|
||||
master_hostname="'%s'" % node01.name,
|
||||
swift_proxy_address = "'%s'" % self.get_internal_virtual_ip(),
|
||||
controller_public_addresses="{ '%s' => '%s', '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['public'],node02.name,node02.ip_address_by_network['public'],node03.name,node03.ip_address_by_network['public']),
|
||||
controller_internal_addresses="{ '%s' => '%s', '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['internal'],node02.name,node02.ip_address_by_network['internal'],node03.name,node03.ip_address_by_network['internal']),
|
||||
controller_hostnames=[
|
||||
"%s" % node01.name,
|
||||
"%s" % node02.name,
|
||||
"%s" % node03.name],
|
||||
public_interface="'eth2'",
|
||||
internal_interface="'eth0'",
|
||||
internal_address="$ipaddress_eth0",
|
||||
private_interface="'eth1'"
|
||||
)
|
||||
|
||||
def do(self, nodes, command):
|
||||
self.write_openstack_sitepp(self.controller1, self.controller2, self.controller3)
|
||||
results = []
|
||||
for node in nodes:
|
||||
remote = ssh(node.ip_address, username='root', password='r00tme')
|
||||
results.append(execute(remote.sudo.ssh, command))
|
||||
return results
|
||||
|
||||
def validate(self, nodes, command):
|
||||
results = self.do(nodes, command)
|
||||
for result in results:
|
||||
self.assertResult(result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -1,80 +0,0 @@
|
||||
from devops.helpers import ssh
|
||||
from base import RecipeTestCase
|
||||
from helpers import execute
|
||||
from settings import controllers,computes,storages,proxies
|
||||
from root import root
|
||||
|
||||
import unittest
|
||||
|
||||
class OpenStackSwiftSitePPBaseTestCase(RecipeTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(OpenStackSwiftSitePPBaseTestCase, self).setUp()
|
||||
self.controller1 = self.environment.node[controllers[0]]
|
||||
self.controller2 = self.environment.node[controllers[1]]
|
||||
self.compute1 = self.environment.node[computes[0]]
|
||||
self.compute2 = self.environment.node[computes[1]]
|
||||
self.storage1 = self.environment.node[storages[0]]
|
||||
self.storage2 = self.environment.node[storages[1]]
|
||||
self.storage3 = self.environment.node[storages[2]]
|
||||
self.proxy1 = self.environment.node[proxies[0]]
|
||||
|
||||
def get_internal_virtual_ip(self):
|
||||
return self.environment.network['internal'].ip_addresses[-3]
|
||||
|
||||
def get_public_virtual_ip(self):
|
||||
return self.environment.network['public'].ip_addresses[-3]
|
||||
|
||||
def get_floating_network(self):
|
||||
return '.'.join(
|
||||
str(self.environment.network['public'].ip_addresses[-1]).split(
|
||||
'.')[:-1])+'.128/27'
|
||||
|
||||
def get_fixed_network(self):
|
||||
return '.'.join(
|
||||
str(self.environment.network['private'].ip_addresses[-1]).split(
|
||||
'.')[:-1])+'.128/27'
|
||||
|
||||
def get_internal_network(self):
|
||||
network = self.environment.network['internal']
|
||||
return str(network.ip_addresses[1]) +'/' + str(network.ip_addresses.prefixlen)
|
||||
|
||||
def write_openstack_sitepp(self, node01, node02, node03):
|
||||
self.write_site_pp_manifest(
|
||||
root('fuel', 'deployment', 'puppet', 'openstack', 'examples',
|
||||
'site_openstack_swift_standalone.pp'),
|
||||
internal_virtual_ip="'%s'" % self.get_internal_virtual_ip(),
|
||||
public_virtual_ip="'%s'" % self.get_public_virtual_ip(),
|
||||
floating_range = "'%s'" % self.get_floating_network(),
|
||||
fixed_range = "'%s'" % self.get_fixed_network(),
|
||||
master_hostname="'%s'" % node01.name,
|
||||
swift_proxy_address = "'%s'" % node03.ip_address_by_network['internal'],
|
||||
controller_public_addresses="{ '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['public'],node02.name,node02.ip_address_by_network['public']),
|
||||
controller_internal_addresses="{ '%s' => '%s', '%s' => '%s' }"
|
||||
% (node01.name,node01.ip_address_by_network['internal'],node02.name,node02.ip_address_by_network['internal']),
|
||||
controller_hostnames=[
|
||||
"%s" % node01.name,
|
||||
"%s" % node02.name],
|
||||
public_interface="'eth2'",
|
||||
internal_interface="'eth0'",
|
||||
internal_address="$ipaddress_eth0",
|
||||
private_interface="'eth1'"
|
||||
)
|
||||
|
||||
def do(self, nodes, command):
|
||||
self.write_openstack_sitepp(self.controller1, self.controller2, self.proxy1)
|
||||
results = []
|
||||
for node in nodes:
|
||||
remote = ssh(node.ip_address, username='root', password='r00tme')
|
||||
results.append(execute(remote.sudo.ssh, command))
|
||||
return results
|
||||
|
||||
def validate(self, nodes, command):
|
||||
results = self.do(nodes, command)
|
||||
for result in results:
|
||||
self.assertResult(result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -1,39 +1,28 @@
|
||||
from time import sleep
|
||||
from devops.helpers import ssh
|
||||
import keystoneclient.v2_0
|
||||
from ci_helpers import get_environment
|
||||
from helpers import tempest_write_config, tempest_add_images, tempest_share_glance_images, tempest_mount_glance_images, get_auth_url, sync_time, execute, retry
|
||||
from openstack_site_pp_base import OpenStackSitePPBaseTestCase
|
||||
from helpers import tempest_write_config, tempest_add_images, tempest_share_glance_images, tempest_mount_glance_images, get_auth_url, execute, retry
|
||||
import unittest
|
||||
from settings import controllers
|
||||
from openstack.openstack_test_case import OpenStackTestCase
|
||||
|
||||
|
||||
class PrepareTempest(OpenStackSitePPBaseTestCase):
|
||||
class PrepareOpenstackForTempest(OpenStackTestCase):
|
||||
def setUp(self):
|
||||
self.environment = get_environment()
|
||||
self.controller1 = self.environment.node[controllers[0]]
|
||||
self.environment = self.ci().get_environment()
|
||||
self.controller1 = self.environment.node[self.ci().controllers[0]]
|
||||
|
||||
def make_shared_storage(self, remote):
|
||||
tempest_share_glance_images(remote, self.get_internal_network())
|
||||
tempest_share_glance_images(remote, self.ci().get_internal_network())
|
||||
execute(remote, '/etc/init.d/iptables stop')
|
||||
sleep(5)
|
||||
for name in controllers[1:]:
|
||||
for name in self.ci().controllers[1:]:
|
||||
controller = self.environment.node[name]
|
||||
remote_controller = ssh(
|
||||
controller.ip_address, username='root',
|
||||
password='r00tme').sudo.ssh
|
||||
tempest_mount_glance_images(remote_controller)
|
||||
|
||||
def safely_revert_nodes(self):
|
||||
for node in self.environment.nodes:
|
||||
try:
|
||||
node.stop()
|
||||
except:
|
||||
pass
|
||||
for node in self.environment.nodes:
|
||||
node.restore_snapshot('openstack')
|
||||
sleep(4)
|
||||
# sync_time(ssh(node.ip_address, username='root', password='r00tme').sudo.ssh)
|
||||
|
||||
|
||||
def make_tempest_objects(self, auth_host, remote):
|
||||
keystone = retry(10, keystoneclient.v2_0.client.Client,
|
||||
@ -50,7 +39,7 @@ class PrepareTempest(OpenStackSitePPBaseTestCase):
|
||||
return image_ref, image_ref_any
|
||||
|
||||
def prepare_for_tempest(self):
|
||||
self.safely_revert_nodes()
|
||||
self.safety_revert_nodes(self.environment.nodes)
|
||||
auth_host = self.get_public_virtual_ip()
|
||||
remote = ssh(
|
||||
self.controller1.ip_address, username='root',
|
||||
@ -60,7 +49,7 @@ class PrepareTempest(OpenStackSitePPBaseTestCase):
|
||||
tempest_write_config(auth_host, image_ref, image_ref_any)
|
||||
|
||||
def prepare_for_tempest_if_swift(self):
|
||||
self.safely_revert_nodes()
|
||||
self.safety_revert_nodes()
|
||||
auth_host = self.get_public_virtual_ip()
|
||||
remote = ssh(
|
||||
self.controller1.ip_address, username='root',
|
||||
|
@ -1,6 +1,2 @@
|
||||
controllers = ['fuel-01', 'fuel-02']
|
||||
computes = ['fuel-03', 'fuel-04']
|
||||
storages = ['fuel-05', 'fuel-06', 'fuel-07']
|
||||
proxies = ['fuel-08']
|
||||
keystones = ['keystone']
|
||||
NODES = controllers + computes + keystones + proxies + storages
|
||||
import os
|
||||
BASE_IMAGE = os.environ.get('BASE_IMAGE', '/var/lib/libvirt/images/vgalkin_centos-base.qcow2')
|
||||
|
@ -1,3 +0,0 @@
|
||||
controllers = ['fuel-01', 'fuel-02','fuel-03']
|
||||
computes = ['fuel-04', 'fuel-05']
|
||||
NODES = controllers + computes
|
1
fuel_test/swift/__init__.py
Normal file
1
fuel_test/swift/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__author__ = 'vic'
|
@ -1,19 +1,24 @@
|
||||
from devops.helpers import ssh
|
||||
from base import RecipeTestCase
|
||||
from base_test_case import BaseTestCase
|
||||
from ci.ci_swift import CiSwift
|
||||
from helpers import execute
|
||||
from settings import keystones,storages,proxies
|
||||
from root import root
|
||||
|
||||
import unittest
|
||||
|
||||
class SwiftCase(RecipeTestCase):
|
||||
class SwiftCase(BaseTestCase):
|
||||
|
||||
def ci(self):
|
||||
if self.ci:
|
||||
return self.ci
|
||||
return CiSwift()
|
||||
|
||||
def test_deploy_swift(self):
|
||||
keystone = self.environment.node[keystones[0]]
|
||||
storage1 = self.environment.node[storages[0]]
|
||||
storage2 = self.environment.node[storages[1]]
|
||||
storage3 = self.environment.node[storages[2]]
|
||||
proxy1 = self.environment.node[proxies[0]]
|
||||
keystone = self.environment.node[self.ci().keystones[0]]
|
||||
storage1 = self.environment.node[self.ci().storages[0]]
|
||||
storage2 = self.environment.node[self.ci().storages[1]]
|
||||
storage3 = self.environment.node[self.ci().storages[2]]
|
||||
proxy1 = self.environment.node[self.ci().proxies[0]]
|
||||
self.write_site_pp_manifest(
|
||||
root('fuel', 'deployment', 'puppet', 'swift', 'examples', 'site.pp'),
|
||||
swift_proxy_address="'%s'" % proxy1.ip_address_by_network['public'],
|
Loading…
Reference in New Issue
Block a user