diff --git a/zaza/openstack/charm_tests/tempest/setup.py b/zaza/openstack/charm_tests/tempest/setup.py index 4266ddc..8e338f6 100644 --- a/zaza/openstack/charm_tests/tempest/setup.py +++ b/zaza/openstack/charm_tests/tempest/setup.py @@ -14,6 +14,7 @@ """Code for configuring and initializing tempest.""" +import jinja2 import urllib.parse import os import subprocess @@ -22,20 +23,18 @@ import zaza.utilities.deployment_env as deployment_env import zaza.openstack.utilities.juju as juju_utils import zaza.openstack.utilities.openstack as openstack_utils import zaza.openstack.charm_tests.glance.setup as glance_setup -import zaza.openstack.charm_tests.tempest.templates.tempest_v2 as tempest_v2 -import zaza.openstack.charm_tests.tempest.templates.tempest_v3 as tempest_v3 -import zaza.openstack.charm_tests.tempest.templates.accounts as accounts -SETUP_ENV_VARS = [ - 'TEST_GATEWAY', - 'TEST_CIDR_EXT', - 'TEST_FIP_RANGE', - 'TEST_NAMESERVER', - 'TEST_CIDR_PRIV', - 'TEST_SWIFT_IP', -] +SETUP_ENV_VARS = { + 'neutron': ['TEST_GATEWAY', 'TEST_CIDR_EXT', 'TEST_FIP_RANGE', + 'TEST_NAMESERVER', 'TEST_CIDR_PRIV'], + 'swift': ['TEST_SWIFT_IP'], +} + TEMPEST_FLAVOR_NAME = 'm1.tempest' TEMPEST_ALT_FLAVOR_NAME = 'm2.tempest' +TEMPEST_SVC_LIST = ['ceilometer', 'cinder', 'glance', 'heat', 'horizon', + 'ironic', 'neutron', 'nova', 'sahara', 'swift', 'trove', + 'zaqar'] def add_application_ips(ctxt): @@ -169,7 +168,20 @@ def add_keystone_config(ctxt, keystone_session): ctxt['default_domain_id'] = domain.id -def add_environment_var_config(ctxt): +def get_service_list(keystone_session): + """Add keystone config to context. + + :param keystone_session: keystoneauth1.session.Session object + :type: keystoneauth1.session.Session + :returns: None + :rtype: None + """ + keystone_client = openstack_utils.get_keystone_session_client( + keystone_session) + return [s.name for s in keystone_client.services.list() if s.enabled] + + +def add_environment_var_config(ctxt, services): """Add environment variable config to context. :param ctxt: Context dictionary @@ -178,14 +190,16 @@ def add_environment_var_config(ctxt): :rtype: None """ deploy_env = deployment_env.get_deployment_context() - for var in SETUP_ENV_VARS: - value = deploy_env.get(var) - if value: - ctxt[var.lower()] = value - else: - raise ValueError( - ("Environment variables {} must all be set to run this" - " test").format(', '.join(SETUP_ENV_VARS))) + for svc, env_vars in SETUP_ENV_VARS.items(): + if svc in services: + for var in env_vars: + value = deploy_env.get(var) + if value: + ctxt[var.lower()] = value + else: + raise ValueError( + ("Environment variables {} must all be set to run this" + " test").format(', '.join(env_vars))) def add_auth_config(ctxt): @@ -215,32 +229,42 @@ def get_tempest_context(): """ keystone_session = openstack_utils.get_overcloud_keystone_session() ctxt = {} + ctxt_funcs = { + 'nova': add_nova_config, + 'neutron': add_nova_config, + 'glance': add_keystone_config, + 'cinder': add_cinder_config, + 'keystone': add_keystone_config} + ctxt['enabled_services'] = get_service_list(keystone_session) + ctxt['disabled_services'] = list( + set(TEMPEST_SVC_LIST) - set(ctxt['enabled_services'])) add_application_ips(ctxt) - add_nova_config(ctxt, keystone_session) - add_neutron_config(ctxt, keystone_session) - add_glance_config(ctxt, keystone_session) - add_cinder_config(ctxt, keystone_session) - add_keystone_config(ctxt, keystone_session) - add_environment_var_config(ctxt) + for svc_name, ctxt_func in ctxt_funcs.items(): + if svc_name in ctxt['enabled_services']: + ctxt_func(ctxt, keystone_session) + add_environment_var_config(ctxt, ctxt['enabled_services']) add_auth_config(ctxt) return ctxt -def render_tempest_config(target_file, ctxt, template): +def render_tempest_config(target_file, ctxt, template_name): """Render tempest config for specified config file and template. :param target_file: Name of file to render config to :type target_file: str :param ctxt: Context dictionary :type ctxt: dict - :param template: Template module - :type template: module + :param template_name: Name of template file + :type template_name: str :returns: None :rtype: None """ - # TODO: switch to jinja2 and generate config based on available services + jenv = jinja2.Environment(loader=jinja2.PackageLoader( + 'zaza.openstack', + 'charm_tests/tempest/templates')) + template = jenv.get_template(template_name) with open(target_file, 'w') as f: - f.write(template.file_contents.format(**ctxt)) + f.write(template.render(ctxt)) def setup_tempest(tempest_template, accounts_template): @@ -279,7 +303,7 @@ def render_tempest_config_keystone_v2(): :returns: None :rtype: None """ - setup_tempest(tempest_v2, accounts) + setup_tempest('tempest_v2.j2', 'accounts.j2') def render_tempest_config_keystone_v3(): @@ -288,4 +312,4 @@ def render_tempest_config_keystone_v3(): :returns: None :rtype: None """ - setup_tempest(tempest_v3, accounts) + setup_tempest('tempest_v3.j2', 'accounts.j2') diff --git a/zaza/openstack/charm_tests/tempest/templates/accounts.py b/zaza/openstack/charm_tests/tempest/templates/accounts.j2 similarity index 76% rename from zaza/openstack/charm_tests/tempest/templates/accounts.py rename to zaza/openstack/charm_tests/tempest/templates/accounts.j2 index 0c5cf5a..c4dd21a 100644 --- a/zaza/openstack/charm_tests/tempest/templates/accounts.py +++ b/zaza/openstack/charm_tests/tempest/templates/accounts.j2 @@ -1,9 +1,6 @@ -# flake8: noqa -file_contents = """ - username: 'demo' tenant_name: 'demo' password: 'pass' - username: 'alt_demo' tenant_name: 'alt_demo' password: 'secret' -""" diff --git a/zaza/openstack/charm_tests/tempest/templates/tempest_v2.py b/zaza/openstack/charm_tests/tempest/templates/tempest_v2.j2 similarity index 57% rename from zaza/openstack/charm_tests/tempest/templates/tempest_v2.py rename to zaza/openstack/charm_tests/tempest/templates/tempest_v2.j2 index 8b0f939..b4f2dfc 100644 --- a/zaza/openstack/charm_tests/tempest/templates/tempest_v2.py +++ b/zaza/openstack/charm_tests/tempest/templates/tempest_v2.j2 @@ -1,5 +1,3 @@ -# flake8: noqa -file_contents = """ [DEFAULT] debug = false use_stderr = false @@ -8,16 +6,17 @@ log_file = tempest.log [auth] test_accounts_file = accounts.yaml default_credentials_domain_name = Default -admin_username = {admin_username} +admin_username = {{ admin_username }} admin_project_name = admin -admin_password = {admin_password} +admin_password = {{ admin_password }} admin_domain_name = Default +{% if 'nova' in enabled_services %} [compute] -image_ref = {image_id} -image_ref_alt = {image_alt_id} -flavor_ref = {flavor_ref} -flavor_ref_alt = {flavor_ref_alt} +image_ref = {{ image_id }} +image_ref_alt = {{ image_alt_id }} +flavor_ref = {{ flavor_ref }} +flavor_ref_alt = {{ flavor_ref_alt }} region = RegionOne min_compute_nodes = 3 @@ -31,9 +30,11 @@ resize = true live_migration = true block_migration_for_live_migration = true attach_encrypted_volume = false +{% endif %} +{% if 'keystone' in enabled_services %} [identity] -uri = {proto}://{keystone}:5000/v2.0 +uri = {proto}://{{ keystone }}:5000/v2.0 auth_version = v2 admin_role = Admin region = RegionOne @@ -42,23 +43,28 @@ disable_ssl_certificate_validation = true [identity-feature-enabled] api_v2 = true api_v3 = false +{% endif %} [image] -http_image = http://{test_swift_ip}:80/swift/v1/images/cirros-0.3.4-x86_64-uec.tar.gz +http_image = http://{{ test_swift_ip }}:80/swift/v1/images/cirros-0.3.4-x86_64-uec.tar.gz +{% if 'neutron' in enabled_services %} [network] -project_network_cidr = {test_cidr_priv} -public_network_id = {ext_net} -dns_servers = {test_nameserver} +project_network_cidr = {{ test_cidr_priv }} +public_network_id = {{ ext_net }} +dns_servers = {{ test_nameserver }} project_networks_reachable = false [network-feature-enabled] ipv6 = false +{% endif %} +{% if 'heat' in enabled_services %} [orchestration] stack_owner_role = Admin instance_type = m1.small keypair_name = testkey +{% endif %} [oslo_concurrency] lock_path = /tmp @@ -74,23 +80,19 @@ run_validation = true image_ssh_user = cirros [service_available] -ceilometer = true -cinder = true -glance = true -heat = true -horizon = true -ironic = false -neutron = true -nova = true -sahara = false -swift = true -trove = false -zaqar = false +{% for svc in enabled_services -%} +{{ svc }} = true +{% endfor -%} +{% for svc in disabled_services -%} +{{ svc }} = false +{% endfor %} +{% if 'cinder' in enabled_services %} [volume] backend_names = cinder-ceph storage_protocol = ceph -catalog_type = {catalog_type} +catalog_type = {{ catalog_type }} [volume-feature-enabled] -backup = false""" +backup = false +{% endif %} diff --git a/zaza/openstack/charm_tests/tempest/templates/tempest_v3.j2 b/zaza/openstack/charm_tests/tempest/templates/tempest_v3.j2 new file mode 100644 index 0000000..dc7d8db --- /dev/null +++ b/zaza/openstack/charm_tests/tempest/templates/tempest_v3.j2 @@ -0,0 +1,101 @@ +[DEFAULT] +debug = false +use_stderr = false +log_file = tempest.log + +[auth] +test_accounts_file = accounts.yaml +default_credentials_domain_name = {{ default_credentials_domain_name }} +admin_username = {{ admin_username }} +admin_project_name = {{ admin_project_name }} +admin_password = {{ admin_password }} +admin_domain_name = {{ admin_domain_name }} + +{% if 'nova' in enabled_services %} +[compute] +image_ref = {{ image_id }} +image_ref_alt = {{ image_alt_id }} +flavor_ref = {{ flavor_ref }} +flavor_ref_alt = {{ flavor_ref_alt }} +min_compute_nodes = 3 + +# TODO: review this as its release specific +# min_microversion = 2.2 +# max_microversion = latest + +[compute-feature-enabled] +console_output = true +resize = true +live_migration = true +block_migration_for_live_migration = true +attach_encrypted_volume = false +{% endif %} + +{% if 'keystone' in enabled_services %} +[identity] +uri = {{ proto }}://{{ keystone }}:5000/v2.0 +uri_v3 = {{ proto }}://{{ keystone }}:5000/v3 +auth_version = v3 +admin_role = Admin +region = RegionOne +default_domain_id = {{ default_domain_id }} +admin_domain_scope = true +disable_ssl_certificate_validation = true + +[identity-feature-enabled] +api_v2 = false +api_v3 = true +{% endif %} + +[image] +http_image = http://{{ test_swift_ip }}:80/swift/v1/images/cirros-0.3.4-x86_64-uec.tar.gz + +{% if 'neutron' in enabled_services %} +[network] +project_network_cidr = {{ test_cidr_priv }} +public_network_id = {{ ext_net }} +dns_servers = {{ test_nameserver }} +project_networks_reachable = false +floating_network_name = {{ ext_net }} + +[network-feature-enabled] +ipv6 = false +api_extensions = {{ neutron_api_extensions }} +{% endif %} + +{% if 'heat' in enabled_services %} +[orchestration] +stack_owner_role = Admin +instance_type = m1.small +keypair_name = testkey +{% endif %} + +[oslo_concurrency] +lock_path = /tmp + +[scenario] +img_dir = /home/ubuntu/images +img_file = cirros-0.3.4-x86_64-disk.img +img_container_format = bare +img_disk_format = qcow2 + +[validation] +run_validation = true +image_ssh_user = cirros + +[service_available] +{% for svc in enabled_services -%} +{{ svc }} = true +{% endfor -%} +{% for svc in disabled_services -%} +{{ svc }} = false +{% endfor %} + +{% if 'cinder' in enabled_services %} +[volume] +backend_names = cinder-ceph +storage_protocol = ceph +catalog_type = {{ catalog_type }} + +[volume-feature-enabled] +{% endif %} diff --git a/zaza/openstack/charm_tests/tempest/templates/tempest_v3.py b/zaza/openstack/charm_tests/tempest/templates/tempest_v3.py deleted file mode 100644 index 5140deb..0000000 --- a/zaza/openstack/charm_tests/tempest/templates/tempest_v3.py +++ /dev/null @@ -1,100 +0,0 @@ -# flake8: noqa -file_contents = """ -[DEFAULT] -debug = false -use_stderr = false -log_file = tempest.log - -[auth] -test_accounts_file = accounts.yaml -default_credentials_domain_name = {default_credentials_domain_name} -admin_username = {admin_username} -admin_project_name = {admin_project_name} -admin_password = {admin_password} -admin_domain_name = {admin_domain_name} - -[compute] -image_ref = {image_id} -image_ref_alt = {image_alt_id} -flavor_ref = {flavor_ref} -flavor_ref_alt = {flavor_ref_alt} -min_compute_nodes = 3 - -# TODO: review this as its release specific -# min_microversion = 2.2 -# max_microversion = latest - -[compute-feature-enabled] -console_output = true -resize = true -live_migration = true -block_migration_for_live_migration = true -attach_encrypted_volume = false - -[identity] -uri = {proto}://{keystone}:5000/v2.0 -uri_v3 = {proto}://{keystone}:5000/v3 -auth_version = v3 -admin_role = Admin -region = RegionOne -default_domain_id = {default_domain_id} -admin_domain_scope = true -disable_ssl_certificate_validation = true - -[identity-feature-enabled] -api_v2 = false -api_v3 = true - -[image] -http_image = http://{test_swift_ip}:80/swift/v1/images/cirros-0.3.4-x86_64-uec.tar.gz - -[network] -project_network_cidr = {test_cidr_priv} -public_network_id = {ext_net} -dns_servers = {test_nameserver} -project_networks_reachable = false -floating_network_name = {ext_net} - -[network-feature-enabled] -ipv6 = false -api_extensions = {neutron_api_extensions} - -[orchestration] -stack_owner_role = Admin -instance_type = m1.small -keypair_name = testkey - -[oslo_concurrency] -lock_path = /tmp - -[scenario] -img_dir = /home/ubuntu/images -img_file = cirros-0.3.4-x86_64-disk.img -img_container_format = bare -img_disk_format = qcow2 - -[validation] -run_validation = true -image_ssh_user = cirros - -[service_available] -ceilometer = true -cinder = true -glance = true -heat = true -horizon = true -ironic = false -neutron = true -nova = true -sahara = false -swift = true -trove = false -zaqar = false - -[volume] -backend_names = cinder-ceph -storage_protocol = ceph -catalog_type = {catalog_type} - -[volume-feature-enabled] -backup = false"""