From 430909f67296bb4bbc104c2e7ce0c0ff4fd4a1d8 Mon Sep 17 00:00:00 2001 From: vic Date: Thu, 11 Oct 2012 19:01:49 +0400 Subject: [PATCH] Cobbler test start --- fuel_test/base_test_case.py | 3 +- fuel_test/ci/ci_base.py | 29 ++++++----- fuel_test/ci/ci_cobbler.py | 67 ++++++++++++++++++++++++++ fuel_test/cobbler/__init__.py | 1 + fuel_test/cobbler/cobbler_test_case.py | 38 +++++++++++++++ fuel_test/node_roles.py | 5 ++ fuel_test/openstack/test_cobbler.py | 2 +- 7 files changed, 131 insertions(+), 14 deletions(-) create mode 100644 fuel_test/ci/ci_cobbler.py create mode 100644 fuel_test/cobbler/__init__.py create mode 100644 fuel_test/cobbler/cobbler_test_case.py diff --git a/fuel_test/base_test_case.py b/fuel_test/base_test_case.py index 6f1904d264..70aa679a41 100644 --- a/fuel_test/base_test_case.py +++ b/fuel_test/base_test_case.py @@ -19,7 +19,8 @@ class BaseTestCase(unittest.TestCase): self.environment = self.ci().get_environment_or_create() master = self.environment.node['master'] self.revert_snapshots() - self.master_remote = ssh(master.ip_address, username='root', + self.master_remote = ssh(master.ip_address_by_network['public'], + username='root', password='r00tme') self.upload_recipes() self.restart_puppet_muster() diff --git a/fuel_test/ci/ci_base.py b/fuel_test/ci/ci_base.py index 4a39b44465..4203839c44 100644 --- a/fuel_test/ci/ci_base.py +++ b/fuel_test/ci/ci_base.py @@ -12,7 +12,7 @@ from fuel_test.root import root from fuel_test.helpers import load -class CiBase: +class CiBase(object): @abstractproperty def env_name(self): """ @@ -74,7 +74,7 @@ class CiBase: for node in nodes: add_to_hosts(remote, node.ip_address, node.name, node.name) - def setup_mater_node(self, master_remote, nodes): + def setup_master_node(self, master_remote, nodes): setup_puppet_master_yum(master_remote) add_nmap_yum(master_remote) switch_off_ip_tables(master_remote) @@ -97,34 +97,39 @@ class CiBase: write_config(remote, '/etc/puppet/puppet.conf', agent_config) request_cerificate(remote) - def setup_environment(self): + def make_vms(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") + return environment + + def rename_nodes(self, nodes): + for node in nodes: + remote = ssh(node.ip_address, username='root', password='r00tme') + change_host_name(remote, node.name, node.name) + logging.info("Renamed %s" % node.name) + + def setup_environment(self): + environment = self.make_vms() + self.environment = environment + 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) + self.rename_nodes(environment.nodes) 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_master_node(master_remote, environment.nodes) self.setup_agent_nodes(environment.nodes) sleep(5) sign_all_node_certificates(master_remote) diff --git a/fuel_test/ci/ci_cobbler.py b/fuel_test/ci/ci_cobbler.py new file mode 100644 index 0000000000..42d345b7bb --- /dev/null +++ b/fuel_test/ci/ci_cobbler.py @@ -0,0 +1,67 @@ +import logging +from time import sleep +from devops.helpers import wait, tcp_ping, ssh +from devops.model import Environment, Network +import os +from fuel_test.ci.ci_base import CiBase +from fuel_test.helpers import sign_all_node_certificates +from fuel_test.node_roles import NodeRoles + +class CiCobbler(CiBase): + def node_roles(self): + return NodeRoles( + cobbler_names=['fuel-cobbler'], + controller_names=['fuel-01', 'fuel-02'], + compute_names=['fuel-03', 'fuel-04'] + ) + + def env_name(self): + return os.environ.get('ENV_NAME', 'cobbler') + + def describe_environment(self): + environment = Environment(self.environment_name) + internal = Network(name='internal', dhcp_server=False) + 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.node_roles().cobbler_names: + client = self.describe_node(node_name, [internal, private, public]) + environment.nodes.append(client) + for node_name in self.node_roles().controller_names: + client = self.describe_node(node_name, [internal, private, public]) + environment.nodes.append(client) + for node_name in self.node_roles().compute_names: + client = self.describe_node( + node_name, [internal, private, public], memory=4096) + environment.nodes.append(client) + return environment + + def setup_environment(self): + environment = self.make_vms() + self.environment = environment + + logging.info("Starting test nodes ...") + master_node = environment.node['master'] + start_nodes = self.nodes().cobblers + [master_node] + for node in start_nodes: + node.start() + for node in start_nodes: + logging.info("Waiting ssh... %s" % node.ip_address) + wait(lambda: tcp_ping(node.ip_address, 22), timeout=1800) + self.rename_nodes(start_nodes) + + master_remote = ssh(master_node.ip_address, username='root', + password='r00tme') + self.setup_master_node(master_remote, environment.nodes) + self.setup_agent_nodes(self.nodes().cobblers) + 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) diff --git a/fuel_test/cobbler/__init__.py b/fuel_test/cobbler/__init__.py new file mode 100644 index 0000000000..99d829940d --- /dev/null +++ b/fuel_test/cobbler/__init__.py @@ -0,0 +1 @@ +__author__ = 'vic' diff --git a/fuel_test/cobbler/cobbler_test_case.py b/fuel_test/cobbler/cobbler_test_case.py new file mode 100644 index 0000000000..b5b0941483 --- /dev/null +++ b/fuel_test/cobbler/cobbler_test_case.py @@ -0,0 +1,38 @@ +import unittest +from fuel_test.base_test_case import BaseTestCase +from fuel_test.ci.ci_cobbler import CiCobbler +from fuel_test.root import root + +class CobblerTestCase(BaseTestCase): + def ci(self): + if not hasattr(self, '_ci'): + self._ci = CiCobbler() + return self._ci + + def setUp(self): + super(CobblerTestCase, self).setUp() + + def write_cobbler_manifest(self): + cobbler = self.nodes.cobblers[0] + self.write_site_pp_manifest( + root('fuel', 'deployment', 'puppet', 'cobbler', 'examples', + 'server_site.pp'), + server="'%s'" % cobbler.ip_address, + name_server="'%s'" % cobbler.ip_address, + next_server="'%s'" % cobbler.ip_address, + dhcp_start_address="'%s'" % self.environment.network[ + 'internal'].ip_addresses[-5], + dhcp_end_address="'%s'" % + self.environment.network['internal'].ip_addresses[ + -5], + dhcp_netmask="'%s'" % '255.255.255.0', + dhcp_gateway="'%s'" % cobbler.ip_address + ) + + +if __name__ == '__main__': + unittest.main() + + + + diff --git a/fuel_test/node_roles.py b/fuel_test/node_roles.py index 6b4a1f9432..6e70d5e9fd 100644 --- a/fuel_test/node_roles.py +++ b/fuel_test/node_roles.py @@ -4,11 +4,13 @@ class NodeRoles(object): compute_names=None, storage_names=None, proxy_names=None, + cobbler_names=None, keystone_names=None): self.controller_names = controller_names or [] self.compute_names = compute_names or [] self.storage_names = storage_names or [] self.proxy_names = proxy_names or [] + self.cobbler_names = cobbler_names or [] self.keystone_names = keystone_names or [] @@ -19,6 +21,7 @@ class Nodes(object): self.storages = [] self.proxies = [] self.keystones = [] + self.cobblers = [] for node_name in node_roles.controller_names: print('asdf %s' % node_name) self.controllers.append(devops_environment.node[node_name]) @@ -28,6 +31,8 @@ class Nodes(object): self.storages.append(devops_environment.node[node_name]) for node_name in node_roles.proxy_names: self.proxies.append(devops_environment.node[node_name]) + for node_name in node_roles.cobbler_names: + self.cobblers.append(devops_environment.node[node_name]) for node_name in node_roles.keystone_names: self.keystones.append(devops_environment.node[node_name]) diff --git a/fuel_test/openstack/test_cobbler.py b/fuel_test/openstack/test_cobbler.py index 72731d2014..51b35069e4 100644 --- a/fuel_test/openstack/test_cobbler.py +++ b/fuel_test/openstack/test_cobbler.py @@ -6,7 +6,7 @@ import unittest class CobblerTestCase(OpenStackTestCase): def test_deploy_cobbler(self): - node01 = self.environment.node[self.ci().controllers[0]] + node01 = self.nodes.controllers[0] self.write_site_pp_manifest( root('fuel', 'deployment', 'puppet', 'cobbler', 'examples', 'server_site.pp'),