def tempest(environment="autotest-precise-grizzly-glance-cf", razor_ip="198.101.133.3", log_level="error"): """ Tests an openstack cluster with tempest """ qa = rpcsqa_helper() env = Environment(environment) if 'remote_chef' in env.override_attributes: api = qa.remote_chef_client(environment) env = Environment(environment, api=api) else: api = qa.chef query = ("chef_environment:{0} AND " "(run_list:*ha-controller* OR " "run_list:*single-controller*)").format(environment) controllers = list(qa.node_search(query, api=api)) if not controllers: print "No controllers in environment" sys.exit(1) for controller in controllers: if 'recipe[tempest]' not in controller.run_list: print "Adding tempest to controller run_list" controller.run_list.append('recipe[tempest]') controller.save() print "Updating tempest cookbooks" qa.update_tempest_cookbook(env) print "Running chef-client" qa.run_chef_client(controller, num_times=2, log_level=log_level) cmd = "python /opt/tempest/tools/install_venv.py" qa.run_command_on_node(controller, cmd) qa.feature_test(controllers[0], environment)
def save(self): # Load local chef env env = ChefEnvironment(self.name, api=self.local_api) # update chef env with local object info for attr in self.__dict__: util.logger.debug("{0}: {1}".format(attr, self.__dict__[attr])) setattr(env, attr, self.__dict__[attr]) # Save local/remote env.save(self.local_api) if self.remote_api: try: env.save(self.remote_api) except Exception as e: util.logger.error("Remote env error:{0}".format(e))
def test_version_error_list(self): with test_chef_api(version='0.9.0'): with self.assertRaises(ChefAPIVersionError): Environment.list()
def test_version_error_init(self): with test_chef_api(version='0.9.0'): with self.assertRaises(ChefAPIVersionError): Environment(self.random())
def save(self): env = ChefEnvironment(self.name, api=self.local_api) env.attributes = self.__dict__ env.save(self.local_api) if self.remote_api: env.save(self.remote_api)
results = parser.parse_args() results.chef_client_pem = results.chef_client_pem.replace("~", os.getenv("HOME")) # Load chef and razor apis with ChefAPI(results.chef_url, results.chef_client_pem, results.chef_client): razor = razor_api(results.razor_ip) server = [] dashboard = [] agents = [] # Make sure environment exists, if not create one env = "%s-%s-opencenter" % (results.name, results.os) if not Search("environment").query("name:%s" % env): print "Making environment: %s " % env Environment.create(env) # Gather the servers in the environment into their roles nodes = Search("node").query("name:qa-%s-pool* AND chef_environment:%s" % (results.os, env)) for n in nodes: node = Node(n["name"]) # print "Found: %s " % node.name # print node.attributes['in_use'] if node.attributes["in_use"] == "server": server.append(node.name) elif node.attributes["in_use"] == "dashboard": dashboard.append(node.name) elif node.attributes["in_use"] == "agent": agents.append(node.name) print "Server: %s " % server print "Dashboard: %s " % dashboard
def test_version_error_create(self): with test_chef_api(version='0.9.0'): with self.assertRaises(ChefAPIVersionError): Environment.create(self.random())
def main(name="autotest", os="precise", feature_set="glance-cf", environment_branch="grizzly", tempest_version="grizzly", keystone_admin_pass="******", jenkins_build=None): local_env = qa.cluster_environment(name=name, os_distro=os, feature_set=feature_set, branch=environment_branch) if not local_env.exists: print "Error: Environment %s doesn't exist" % local_env.name sys.exit(1) if 'remote_chef' in local_env.override_attributes: api = qa.remote_chef_api(local_env) env = Environment(local_env.name, api=api) else: env = local_env api = qa.chef # Gather information from the cluster controller, ip = qa.cluster_controller(env, api) if not controller: print "Controller not found for env: %s" % env.name sys.exit(1) username = '******' password = keystone_admin_pass tenant = 'demo' cluster = { 'host': ip, 'username': username, 'password': password, 'tenant': tenant, 'alt_username': username, 'alt_password': password, 'alt_tenant': tenant, 'admin_username': "******", 'admin_password': password, 'admin_tenant': "admin", 'nova_password': controller.attributes['nova']['db']['password'] } if tempest_version == 'grizzly': # quantum is enabled, test it. if 'nova-quantum' in feature_set: cluster['api_version'] = 'v2.0' cluster['tenant_network_cidr'] = '10.0.0.128/25' cluster['tenant_network_mask_bits'] = '25' cluster['tenant_networks_reachable'] = True cluster['public_router_id'] = '' cluster['public_network_id'] = '' cluster['quantum_available'] = True else: cluster['api_version'] = 'v1.1' cluster['tenant_network_cidr'] = '10.100.0.0/16' cluster['tenant_network_mask_bits'] = '29' cluster['tenant_networks_reachable'] = False cluster['public_router_id'] = '' cluster['public_network_id'] = '' cluster['quantum_available'] = False if feature_set == "glance-cf": cluster["image_enabled"] = True else: cluster["image_enabled"] = False # Getting precise image id url = "http://%s:5000/v2.0" % ip print "##### URL: %s #####" % url compute = client.Client(cluster['admin_username'], cluster['admin_password'], cluster['admin_tenant'], url, service_type="compute") precise_id = (i.id for i in compute.images.list() if "precise" in i.name) cluster['image_id'] = next(precise_id) cluster['alt_image_id'] = cluster['image_id'] pprint(cluster) # Write the config jenkins_build = jenkins_build or "/var/lib/jenkins/jenkins-build" tempest_dir = "%s/qa/metadata/tempest/config" % jenkins_build sample_path = "%s/base_%s.conf" % (tempest_dir, tempest_version) with open(sample_path) as f: tempest_config = Template(f.read()).substitute(cluster) tempest_config_path = "/tmp/%s.conf" % env.name with open(tempest_config_path, 'w') as w: print "####### Tempest Config #######" print tempest_config_path print tempest_config w.write(tempest_config) qa.scp_to_node(node=controller, path=tempest_config_path) # Setup tempest on chef server print "## Setting up tempest on chef server ##" if os == "precise": packages = ("apt-get install python-pip python-setuptools " "libmysqlclient-dev libxml2-dev libxslt1-dev " "python2.7-dev libpq-dev git -y") else: packages = ("yum install python-setuptools python-setuptools-devel " "python-pip python-lxml gcc python-devel openssl-devel " "mysql-devel postgresql-devel git -y; easy_install pip") commands = [ packages, "rm -rf tempest", ("git clone https://github.com/openstack/tempest.git -b " "stable/%s --recursive" % tempest_version), "easy_install -U distribute", "pip install -r tempest/tools/pip-requires", "pip install -r tempest/tools/test-requires", "pip install nose-progressive" ] for command in commands: qa.run_cmd_on_node(node=controller, cmd=command) # Setup controller print "## Setting up and cleaning cluster ##" setup_cmd = ("sysctl -w net.ipv4.ip_forward=1; " "source ~/openrc; " "nova-manage floating list | grep nova > /dev/null || " "nova-manage floating create 192.168.2.0/24; " "nova-manage floating list;") qa.run_cmd_on_node(node=controller, cmd=setup_cmd) # Run tests print "## Running Tests ##" file = '%s-%s.xunit' % (time.strftime("%Y-%m-%d-%H:%M:%S", time.gmtime()), env.name) xunit_flag = '--with-xunit --xunit-file=%s' % file feature_map = { "glance-cf": ["compute/images", "images"], "glance-local": ["compute/images", "images"], "keystone-ldap": [ "compute/admin", "compute/security_groups", "compute/test_authorization.py", "identity" ], "keystone-mysql": [ "compute/admin", "compute/security_groups", "compute/test_authorization.py", "identity" ], "neutron": ["network"], "cinder-local": ["compute/volumes", "volume"], "swift": ["object_storage"] } exclude_flags = ["volume", "rescue"] # Volumes if feature_set != "glance-cf": exclude_flags.append("image") exclude_flag = ' '.join('-e {0}'.format(x) for x in exclude_flags) command = ("export TEMPEST_CONFIG_DIR=/root; " "export TEMPEST_CONFIG=%s.conf; " "python -u `which nosetests` --with-progressive %s %s " "-a type=smoke tempest/tempest/tests; " % (env.name, xunit_flag, exclude_flag)) # run tests qa.run_cmd_on_node(node=controller, cmd=command) for i in xrange(10): try: qa.scp_from_node(node=controller, path=file, destination=".") break except KeyError: print "Razor key error, trying again" continue
results.chef_client_pem = results.chef_client_pem.replace( '~', os.getenv("HOME")) # Load chef and razor apis with ChefAPI(results.chef_url, results.chef_client_pem, results.chef_client): razor = razor_api(results.razor_ip) server = [] dashboard = [] agents = [] # Make sure environment exists, if not create one env = "%s-%s-opencenter" % (results.name, results.os) if not Search("environment").query("name:%s" % env): print "Making environment: %s " % env Environment.create(env) # Gather the servers in the environment into their roles nodes = Search('node').query("name:qa-%s-pool* AND chef_environment:%s" % (results.os, env)) for n in nodes: node = Node(n['name']) #print "Found: %s " % node.name #print node.attributes['in_use'] if node.attributes['in_use'] == "server": server.append(node.name) elif node.attributes['in_use'] == "dashboard": dashboard.append(node.name) elif node.attributes['in_use'] == "agent": agents.append(node.name) print "Server: %s " % server