From 68dc1ebb45ae5c4e11ec79249fc7f8cc8740fdfd Mon Sep 17 00:00:00 2001 From: Georgy Dyuldin Date: Wed, 29 Mar 2017 15:50:51 +0300 Subject: [PATCH] Fix some MCP-related issues Change-Id: I9e670a03ca6169edfdb81a04b86ca7d0d1c6569b --- plugin_test/vapor/pytest.ini | 2 +- plugin_test/vapor/vapor/fixtures/contrail.py | 16 +- .../fixtures/different_tenants_resources.py | 12 +- plugin_test/vapor/vapor/fixtures/policies.py | 38 ++-- plugin_test/vapor/vapor/fixtures/subnets.py | 6 + .../vapor/vapor/helpers/contrail_status.py | 3 +- plugin_test/vapor/vapor/helpers/policy.py | 5 +- plugin_test/vapor/vapor/helpers/project.py | 19 ++ plugin_test/vapor/vapor/settings.py | 2 + .../vapor/vapor/tests/common/test_base.py | 179 +++++++++++------- .../vapor/vapor/tests/test_analytics.py | 39 +++- .../vapor/vapor/tests/test_destructive.py | 30 +++ .../vapor/vapor/tests/test_failover.py | 2 + plugin_test/vapor/vapor/tests/test_ipam.py | 5 +- plugin_test/vapor/vapor/tests/test_smoke.py | 29 --- plugin_test/vapor/vapor/tests/test_system.py | 5 +- plugin_test/vapor/vapor/tests/test_vrouter.py | 12 +- 17 files changed, 274 insertions(+), 130 deletions(-) create mode 100644 plugin_test/vapor/vapor/helpers/project.py diff --git a/plugin_test/vapor/pytest.ini b/plugin_test/vapor/pytest.ini index d195986ee..1d0eb42de 100644 --- a/plugin_test/vapor/pytest.ini +++ b/plugin_test/vapor/pytest.ini @@ -5,4 +5,4 @@ markers = performance_test: mark test as Performance. #addopts = -vv --color=yes --junit-xml=report.xml -addopts = -vv --color=yes -ra -p stepler.third_party.destructive_dispatcher -p stepler.third_party.idempotent_id +addopts = -vv --color=yes -ra -p stepler.third_party.destructive_dispatcher -p stepler.third_party.idempotent_id -p stepler.third_party.default_project diff --git a/plugin_test/vapor/vapor/fixtures/contrail.py b/plugin_test/vapor/vapor/fixtures/contrail.py index 207634e12..e177bfd6a 100644 --- a/plugin_test/vapor/vapor/fixtures/contrail.py +++ b/plugin_test/vapor/vapor/fixtures/contrail.py @@ -89,7 +89,8 @@ def contrail_api_endpoint(os_faults_steps): def contrail_vrouter_agent_endpoint(contrail_services_http_introspect_ports): """Return contrail agent endpoint.""" service_name = 'contrail-vrouter-agent' - ip = contrail_services_http_introspect_ports[service_name]['ips'][0] + ip = contrail_services_http_introspect_ports[service_name]['nodes'][0][ + 'ip'] port = contrail_services_http_introspect_ports[service_name]['port'] return {'ip': ip, 'port': port} @@ -128,7 +129,10 @@ def contrail_services_http_introspect_ports(os_faults_steps, contrail_nodes): filename = os.path.basename(path) service_name = os.path.splitext(filename)[0] if service_name in results: - results[service_name]['ips'].append(node_ip) + results[service_name]['nodes'].append({ + 'ip': node_ip, + 'fqdn': node.get_fqdns()[0] + }) continue if service_name not in default_ports: continue @@ -148,7 +152,13 @@ def contrail_services_http_introspect_ports(os_faults_steps, contrail_nodes): except configparser.NoSectionError: pass if port: - results[service_name] = {'port': port, 'ips': [node_ip]} + results[service_name] = { + 'port': port, + 'nodes': [{ + 'ip': node_ip, + 'fqdn': node.get_fqdns()[0] + }], + } return results diff --git a/plugin_test/vapor/vapor/fixtures/different_tenants_resources.py b/plugin_test/vapor/vapor/fixtures/different_tenants_resources.py index d4be57c62..37900b3e2 100644 --- a/plugin_test/vapor/vapor/fixtures/different_tenants_resources.py +++ b/plugin_test/vapor/vapor/fixtures/different_tenants_resources.py @@ -16,6 +16,8 @@ import six import stepler.config as stepler_config from stepler.third_party import utils +from vapor.helpers import project + if six.PY2: import contextlib2 as contextlib else: @@ -121,6 +123,7 @@ class ResourceManager(object): 'server': server, 'port': port, 'floating_ip': floating_ip, + 'security_group': security_group, }) @@ -144,7 +147,8 @@ def different_tenants_resources( cirros_image, sorted_hypervisors, get_network_steps, get_subnet_steps, get_server_steps, port_steps, get_floating_ip_steps, public_flavor, public_network, get_neutron_security_group_steps, - get_neutron_security_group_rule_steps, nova_availability_zone_hosts): + get_neutron_security_group_rule_steps, nova_availability_zone_hosts, + get_current_project, contrail_api_client): """Fixture to create network, subnet and server on each of 2 projects. Created subnets has same CIDR. @@ -185,11 +189,17 @@ def different_tenants_resources( project_resources = mrg.create(subnet_cidr, ips[0], cirros_image, public_flavor, host) + contrail_project = project.get_contrail_project(get_current_project(), + contrail_api_client) + project_resources.contrail_project = contrail_project projects_resources.append(project_resources) with credentials.change(project_2): project_resources = mrg.create(subnet_cidr, ips[1], cirros_image, public_flavor, host) + contrail_project = project.get_contrail_project( + get_current_project(), contrail_api_client) + project_resources.contrail_project = contrail_project projects_resources.append(project_resources) yield projects_resources diff --git a/plugin_test/vapor/vapor/fixtures/policies.py b/plugin_test/vapor/vapor/fixtures/policies.py index 159be5f0c..15591376f 100644 --- a/plugin_test/vapor/vapor/fixtures/policies.py +++ b/plugin_test/vapor/vapor/fixtures/policies.py @@ -10,8 +10,8 @@ def contrail_policies_cleanup(contrail_api_client): def _get_policies_uuids(): return { - net['uuid'] - for net in contrail_api_client.network_policys_list()[ + policy['uuid'] + for policy in contrail_api_client.network_policys_list()[ 'network-policys'] } @@ -24,15 +24,31 @@ def contrail_policies_cleanup(contrail_api_client): @pytest.fixture -def contrail_network_policy(contrail_api_client, contrail_current_project): - policy_name, = utils.generate_ids() - policy = types.NetworkPolicy( - policy_name, parent_obj=contrail_current_project) - contrail_api_client.network_policy_create(policy) +def create_network_policy(contrail_api_client, contrail_current_project): + """Fixture to create network policy.""" - yield policy + policies = [] - try: + def _create_network_policy(name=None, parent=None): + name = name or next(utils.generate_ids()) + parent = parent or contrail_current_project + policy = types.NetworkPolicy(name, parent_obj=parent) + contrail_api_client.network_policy_create(policy) + + policies.append(policy) + + return policy + + yield _create_network_policy + + for policy in policies: + try: + policy = contrail_api_client.network_policy_read(id=policy.uuid) + except exceptions.NoIdError: + continue contrail_api_client.network_policy_delete(id=policy.uuid) - except exceptions.NoIdError: - pass + + +@pytest.fixture +def contrail_network_policy(create_network_policy): + return create_network_policy() diff --git a/plugin_test/vapor/vapor/fixtures/subnets.py b/plugin_test/vapor/vapor/fixtures/subnets.py index b9c066161..8fc3dec2e 100644 --- a/plugin_test/vapor/vapor/fixtures/subnets.py +++ b/plugin_test/vapor/vapor/fixtures/subnets.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from pycontrail import exceptions import pycontrail.types as types import pytest @@ -74,6 +75,11 @@ def contrail_create_subnet(contrail_api_client, contrail_default_ipam): yield _contrail_create_subnet for network, ipam in networks: + try: + network = contrail_api_client.virtual_network_read(id=network.uuid) + ipam = contrail_api_client.network_ipam_read(id=ipam.uuid) + except exceptions.NoIdError: + continue network.del_network_ipam(ipam) contrail_api_client.virtual_network_update(network) diff --git a/plugin_test/vapor/vapor/helpers/contrail_status.py b/plugin_test/vapor/vapor/helpers/contrail_status.py index 5eb2cddb9..9058929fe 100644 --- a/plugin_test/vapor/vapor/helpers/contrail_status.py +++ b/plugin_test/vapor/vapor/helpers/contrail_status.py @@ -8,6 +8,7 @@ from stepler.third_party import waiter from vapor.helpers import asserts from vapor.helpers import nodes_steps +from vapor import settings STATUS_ACTIVE = 'active' @@ -84,7 +85,7 @@ def check_services_statuses(os_faults_steps): statuses = set(statuses) active = {x for x in statuses if x.status == STATUS_ACTIVE} - if service in ('contrail-svc-monitor', 'contrail-schema'): + if service in settings.ACTIVE_BACKUP_SERVICES: backup = {x for x in statuses if x.status == STATUS_BACKUP} broken = statuses - active - backup collector.check(active, diff --git a/plugin_test/vapor/vapor/helpers/policy.py b/plugin_test/vapor/vapor/helpers/policy.py index 1ceb0b81d..b4dd53090 100644 --- a/plugin_test/vapor/vapor/helpers/policy.py +++ b/plugin_test/vapor/vapor/helpers/policy.py @@ -13,13 +13,14 @@ import pycontrail.types as types -def make_policy_entry(protocol, src_ports_range, dst_ports_range): +def make_policy_entry(protocol, src_ports_range, dst_ports_range, + action='pass'): address = types.AddressType(virtual_network='any') src_port = types.PortType( start_port=src_ports_range[0], end_port=src_ports_range[1]) dst_port = types.PortType( start_port=dst_ports_range[0], end_port=dst_ports_range[1]) - action = types.ActionListType(simple_action='pass') + action = types.ActionListType(simple_action=action) rule = types.PolicyRuleType( protocol=protocol, direction='<>', diff --git a/plugin_test/vapor/vapor/helpers/project.py b/plugin_test/vapor/vapor/helpers/project.py new file mode 100644 index 000000000..66dfd23dc --- /dev/null +++ b/plugin_test/vapor/vapor/helpers/project.py @@ -0,0 +1,19 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import uuid + + +def get_contrail_project(os_project, contrail_api_client): + """Return contrail project by keystone project.""" + project_id = str(uuid.UUID(os_project.id)) + return contrail_api_client.project_read(id=project_id) diff --git a/plugin_test/vapor/vapor/settings.py b/plugin_test/vapor/vapor/settings.py index e7d0ad593..0d76759fa 100644 --- a/plugin_test/vapor/vapor/settings.py +++ b/plugin_test/vapor/vapor/settings.py @@ -159,6 +159,8 @@ CONTRAIL_ANALYTIC_PROCESSES = { ], } +ACTIVE_BACKUP_SERVICES = ('contrail-svc-monitor', 'contrail-schema') + HEAT_TEMPLATES_PATH = os.path.join(BASE_DIR, 'heat') VROUTER_HEADLESS_MODE_CMD = r"grep -iP '^headless_mode\s*=\s*true' /etc/contrail/contrail-vrouter-agent.conf" # noqa diff --git a/plugin_test/vapor/vapor/tests/common/test_base.py b/plugin_test/vapor/vapor/tests/common/test_base.py index 4a8a602ab..5fde6cf28 100644 --- a/plugin_test/vapor/vapor/tests/common/test_base.py +++ b/plugin_test/vapor/vapor/tests/common/test_base.py @@ -24,7 +24,7 @@ import pytest from vapor.helpers import agent_steps from vapor.helpers import asserts -from vapor.helpers import contrail_status, policy, connectivity +from vapor.helpers import contrail_status, connectivity from vapor import settings from vapor.settings import logger @@ -90,8 +90,8 @@ def test_delete_vm_with_associated_vn(contrail_network, contrail_subnet, def test_two_nets_same_name(contrail_api_client, contrail_network, contrail_subnet): - """Description: Test to validate that with the same subnet and - name provided, two different VNs cannot be created. + """Description: check creating 2 VNs with same name and parent. + Test steps: 1. Create a VN. 2. Create a second VN with the same name and subnet as the first VN. @@ -99,7 +99,9 @@ def test_two_nets_same_name(contrail_api_client, contrail_network, Pass criteria: There is a single VN created. """ - net = contrail_types.VirtualNetwork(contrail_network.name) + project = contrail_api_client.project_read(id=contrail_network.parent_uuid) + net = contrail_types.VirtualNetwork( + contrail_network.name, parent_obj=project) assert_that( calling(contrail_api_client.virtual_network_create).with_args(net), raises(exceptions.RefsExistError)) @@ -110,6 +112,7 @@ def test_metadata_service(security_group, port_steps, create_floating_ip, tiny_flavor, cirros_image, server_steps): """Description: Test to validate metadata service + Test steps: 1. Create a VN. 2. Launch a VM in this VN. @@ -118,7 +121,7 @@ def test_metadata_service(security_group, port_steps, Pass criteria: The output of the metadata script should be seen in the VM. """ - output_filename = 'output.txt' + output_filename, = utils.generate_ids('output') userdata = ( u'#!/bin/sh\n' u'echo "TestMetadataService.' @@ -227,7 +230,8 @@ def test_create_server_on_exhausted_subnet(cirros_image, flavor, network, assert_that( calling(server_steps.create_servers).with_args(**create_server_args), - raises(AssertionError, 'No valid host was found')) + raises(AssertionError, '(No valid host was found)|' + '(Exceeded maximum number of retries)')) def test_file_transfer_with_scp( @@ -254,10 +258,12 @@ def test_file_transfer_with_scp( userdata = '\n'.join([ "#!/bin/bash -v", "echo '{content}' > {path}", - "chown {user} {path}", + "chown {user}:{user} {path}", "chmod 600 {path}", + "echo {done_marker}", ]).format( - content=key_content, path=key_path, user=username) + content=key_content, path=key_path, user=username, + done_marker=stepler_config.USERDATA_DONE_MARKER) ssh_opts = ('-o UserKnownHostsFile=/dev/null ' '-o StrictHostKeyChecking=no') @@ -282,6 +288,12 @@ def test_file_transfer_with_scp( floating_ip = create_floating_ip(public_network, port=port) floating_ips.append(floating_ip) + # Wait userdata to be done + server_steps.check_server_log_contains_record( + servers[0], + stepler_config.USERDATA_DONE_MARKER, + timeout=stepler_config.USERDATA_EXECUTING_TIMEOUT) + ip = server_steps.get_fixed_ip(servers[1]) with asserts.AssertsCollector() as collector: for size in sizes: @@ -383,24 +395,30 @@ def test_create_server_on_network_without_subnet( raises(nova_exceptions.BadRequest, 'requires a subnet')) -def test_vm_multi_intf_in_same_vn_chk_ping(network, - subnet, - cirros_image, - flavor, - security_group, - server_steps, - port_steps, - create_floating_ip, - public_network): +def test_vm_multi_intf_in_same_vn_chk_ping( + network, + cirros_image, + flavor, + security_group, + server, + server_steps, + port_steps, + create_floating_ip, + public_network): """Test to validate that a multiple interfaces of the same VM can be associated to the same VN and ping is successful. """ - userdata = ( - u'#!/bin/sh\n' - u"/sbin/ifconfig -a\n" - u"/sbin/cirros-dhcpc up eth1\n") + server_port = port_steps.get_ports( + device_owner=stepler_config.PORT_DEVICE_OWNER_SERVER, + device_id=server.id)[0] - server = server_steps.create_servers( + floating_ip = create_floating_ip(public_network, port=server_port) + + userdata = (u'#!/bin/sh\n' + u"/sbin/ifconfig -a\n" + u"/sbin/cirros-dhcpc up eth1\n") + + server2 = server_steps.create_servers( userdata=userdata, image=cirros_image, flavor=flavor, @@ -409,19 +427,12 @@ def test_vm_multi_intf_in_same_vn_chk_ping(network, username=stepler_config.CIRROS_USERNAME, password=stepler_config.CIRROS_PASSWORD)[0] - server_ports = port_steps.get_ports( - device_owner=stepler_config.PORT_DEVICE_OWNER_SERVER, - device_id=server.id) - - server_port = server_ports[0] - floating_ip = create_floating_ip(public_network, port=server_port) - server_steps.check_server_ip(server, - floating_ip['floating_ip_address'], - timeout=settings.FLOATING_IP_BIND_TIMEOUT) - - server_steps.check_ping_between_servers_via_floating( - [server, server], - ip_types=(stepler_config.FIXED_IP,)) + with server_steps.get_server_ssh( + server, floating_ip['floating_ip_address']) as server_ssh: + for ip in server_steps.get_ips( + server2, ip_type=stepler_config.FIXED_IP).keys(): + server_steps.check_ping_for_ip( + ip, server_ssh, timeout=stepler_config.PING_CALL_TIMEOUT) @pytest.mark.parametrize('flavor', [dict(ram=128, disk=1)], indirect=True) @@ -462,11 +473,12 @@ def test_network_in_agent_with_server_add_delete( id=network['id']) network_fq_name = contrail_network.get_fq_name_str() - nodes = contrail_services_http_introspect_ports['contrail-vrouter-agent'] - port = nodes['port'] + service_data = contrail_services_http_introspect_ports[ + 'contrail-vrouter-agent'] + port = service_data['port'] agent_networks = [] - for ip in nodes['ips']: - agent_network = agent_steps.get_vna_vn(session, ip, port, + for node in service_data['nodes']: + agent_network = agent_steps.get_vna_vn(session, node['ip'], port, network_fq_name) if agent_network: agent_networks.append(agent_network) @@ -476,8 +488,8 @@ def test_network_in_agent_with_server_add_delete( server_steps.delete_servers([server]) agent_networks = [] - for ip in nodes['ips']: - agent_network = agent_steps.get_vna_vn(session, ip, port, + for node in service_data['nodes']: + agent_network = agent_steps.get_vna_vn(session, node['ip'], port, network_fq_name) if agent_network: agent_networks.append(agent_network) @@ -485,12 +497,10 @@ def test_network_in_agent_with_server_add_delete( assert_that(agent_networks, empty()) -def test_policy_between_vns_diff_proj(different_tenants_resources, - server_steps, - contrail_api_client, - create_contrail_security_group): - """Test to validate that policy to deny and pass under different - projects should behave accordingly. +def test_policy_between_vns_diff_proj( + different_tenants_resources, server_steps, contrail_api_client, + create_network_policy, set_network_policy): + """Check policy to deny and pass under different projects. Test steps: 1. Create 2 different projects. @@ -500,41 +510,70 @@ def test_policy_between_vns_diff_proj(different_tenants_resources, """ project1, project2 = different_tenants_resources - client = project1.server - client_floating_ip = project1.floating_ip - server_floating_ip = project2.floating_ip + project1_policy = create_network_policy(parent=project1.contrail_project) + project2_policy = create_network_policy(parent=project2.contrail_project) - prj1_conrail_sg = contrail_api_client.security_group_read( - id=project1.security_group.id) - prj2_conrail_sg = contrail_api_client.security_group_read( - id=project2.security_group.id) + project1_network = contrail_api_client.virtual_network_read( + id=project1.network['id']) + project2_network = contrail_api_client.virtual_network_read( + id=project2.network['id']) + set_network_policy(project1_network, project1_policy) + set_network_policy(project2_network, project2_policy) - client_sg_entries = prj1_conrail_sg.security_group_entries - server_sg_entries = prj2_conrail_sg.security_group_entries + # Create allow ICMP policy entries + src_address = contrail_types.AddressType( + virtual_network=project1_network.get_fq_name_str()) + dst_address = contrail_types.AddressType( + virtual_network=project2_network.get_fq_name_str()) + port = contrail_types.PortType(start_port=-1, end_port=-1) + pass_action = contrail_types.ActionListType(simple_action='pass') + allow_rule = contrail_types.PolicyRuleType( + protocol='icmp', + direction='<>', + src_addresses=[src_address], + src_ports=[port], + dst_addresses=[dst_address], + dst_ports=[port], + action_list=pass_action) + allow_icmp_policy_entries = contrail_types.PolicyEntriesType( + policy_rule=[allow_rule]) - # Add allow policy - client_sg_entries.add_policy_rule(policy.POLICY_RULE_ALLOW_EGRESS_ICMP) - client_sg_entries.add_policy_rule(policy.POLICY_RULE_ALLOW_INGRESS_ICMP) - prj1_conrail_sg.security_group_entries = client_sg_entries - contrail_api_client.security_group_update(prj1_conrail_sg) + # Create deny ICMP policy entries + deny_action = contrail_types.ActionListType(simple_action='deny') + deny_rule = contrail_types.PolicyRuleType( + protocol='icmp', + direction='<>', + src_addresses=[src_address], + src_ports=[port], + dst_addresses=[dst_address], + dst_ports=[port], + action_list=deny_action) + deny_icmp_policy_entries = contrail_types.PolicyEntriesType( + policy_rule=[deny_rule]) + + project1_policy.network_policy_entries = allow_icmp_policy_entries + contrail_api_client.network_policy_update(project1_policy) + + project2_policy.network_policy_entries = deny_icmp_policy_entries + contrail_api_client.network_policy_update(project2_policy) + + project2_server_fixed_ip = project2.server_steps.get_fixed_ip( + project2.server) with server_steps.get_server_ssh( - client, - ip=client_floating_ip['floating_ip_address']) as server_ssh: + project1.server, + ip=project1.floating_ip['floating_ip_address']) as server_ssh: connectivity.check_icmp_connection_status( - server_floating_ip['floating_ip_address'], + project2_server_fixed_ip, server_ssh, must_available=False, timeout=settings.SECURITY_GROUP_APPLY_TIMEOUT) - server_sg_entries.add_policy_rule(policy.POLICY_RULE_ALLOW_EGRESS_ICMP) - server_sg_entries.add_policy_rule( - policy.POLICY_RULE_ALLOW_INGRESS_ICMP) - prj2_conrail_sg.security_group_entries = server_sg_entries - contrail_api_client.security_group_update(prj2_conrail_sg) + project2_policy.network_policy_entries = allow_icmp_policy_entries + contrail_api_client.network_policy_update(project2_policy) connectivity.check_icmp_connection_status( - server_floating_ip['floating_ip_address'], + project2_server_fixed_ip, server_ssh, timeout=settings.SECURITY_GROUP_APPLY_TIMEOUT) diff --git a/plugin_test/vapor/vapor/tests/test_analytics.py b/plugin_test/vapor/vapor/tests/test_analytics.py index 1dc840cc8..0d1fbd903 100644 --- a/plugin_test/vapor/vapor/tests/test_analytics.py +++ b/plugin_test/vapor/vapor/tests/test_analytics.py @@ -1,3 +1,17 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import collections + import dpath.util import jmespath from hamcrest import (assert_that, is_, empty, has_key, all_of, has_length, @@ -8,6 +22,7 @@ from six.moves import filter from vapor.helpers import analytic_steps from vapor.helpers import asserts from vapor.helpers.asserts import superset_of +from vapor.helpers import contrail_status from vapor import settings @@ -27,15 +42,27 @@ def test_db_purge(client_contrail_analytics): def test_collector_generator_connections_through_uves( - session, client_contrail_analytics, + session, client_contrail_analytics, os_faults_steps, contrail_services_http_introspect_ports): """Check collector generator connections through UVES.""" with asserts.AssertsCollector() as collector: - for _, nodes in contrail_services_http_introspect_ports.items(): - port = nodes['port'] - for ip in nodes['ips']: - status = analytic_steps.get_collector_connectivity(session, ip, - port) + expected_backup_services = collections.defaultdict(set) + for node, services in contrail_status.get_services_statuses( + os_faults_steps).items(): + for service in services: + if (service['service'] in settings.ACTIVE_BACKUP_SERVICES and + service['status'] == 'backup'): + expected_backup_services[service['service']].add(node) + + for service, data in contrail_services_http_introspect_ports.items(): + port = data['port'] + for node in data['nodes']: + # Skip services with backup status + if node['fqdn'] in expected_backup_services[service]: + continue + + status = analytic_steps.get_collector_connectivity( + session, node['ip'], port) collector.check(status['status'], is_('Established')) for name in client_contrail_analytics.get_uves_generators(): diff --git a/plugin_test/vapor/vapor/tests/test_destructive.py b/plugin_test/vapor/vapor/tests/test_destructive.py index 7049a5b56..7c6430bd0 100644 --- a/plugin_test/vapor/vapor/tests/test_destructive.py +++ b/plugin_test/vapor/vapor/tests/test_destructive.py @@ -13,10 +13,12 @@ from hamcrest import assert_that, is_not import pytest from stepler import config as stepler_config +from stepler.third_party import waiter from vapor import settings from vapor.helpers.asserts import intersects_with from vapor.helpers import analytic_steps +from vapor.helpers import contrail_status pytestmark = pytest.mark.destructive @@ -230,3 +232,31 @@ def test_agent_cleanup_with_control_node_stop( for server in servers: server_steps.check_ping_to_server_floating( server, timeout=stepler_config.PING_CALL_TIMEOUT) + + +@pytest.mark.requires('contrail_control_nodes_count >= 2') +def test_contrail_services_status_after_restart_master_node(os_faults_steps): + """Verify contrail services status after master node restart. + + Steps: + #. Restart node with contrail-schema (active) + #. Wait some time + #. Check that contrail services statuses is correct + """ + services_statuses = contrail_status.get_services_statuses(os_faults_steps) + master_node_fqdn = None + for fqdn, services in services_statuses.items(): + for service in services: + if (service['service'] == 'contrail-schema' and + service['status'] == contrail_status.STATUS_ACTIVE): + master_node_fqdn = fqdn + break + assert master_node_fqdn is not None, "Can't find master node" + master_node = os_faults_steps.get_node(fqdns=[master_node_fqdn]) + os_faults_steps.reset_nodes(master_node) + + waiter.wait( + contrail_status.check_services_statuses, + args=(os_faults_steps), + expected_exceptions=AssertionError, + timeout=settings.CONTRAIL_NODE_RESET_TIMEOUT) diff --git a/plugin_test/vapor/vapor/tests/test_failover.py b/plugin_test/vapor/vapor/tests/test_failover.py index 16ab7210e..5b851e306 100644 --- a/plugin_test/vapor/vapor/tests/test_failover.py +++ b/plugin_test/vapor/vapor/tests/test_failover.py @@ -5,6 +5,8 @@ from stepler import config as stepler_config from vapor import settings +pytestmark = pytest.mark.destructive + def restart_nodes(os_faults_steps, nodes): for node in nodes: diff --git a/plugin_test/vapor/vapor/tests/test_ipam.py b/plugin_test/vapor/vapor/tests/test_ipam.py index ccde0baa3..cc849af37 100644 --- a/plugin_test/vapor/vapor/tests/test_ipam.py +++ b/plugin_test/vapor/vapor/tests/test_ipam.py @@ -66,14 +66,15 @@ def test_ipam_virtual_dns( """ # Create DNS records ip = '1.2.3.4' - name = 'test.example.com' + name = 'vapor.' + contrail_dns.virtual_DNS_data.domain_name add_dns_record(contrail_dns, r_name=name, r_data=ip) # Add DNS to IPAM + contrail_ipam.set_virtual_DNS(contrail_dns) contrail_ipam.network_ipam_mgmt = types.IpamType( ipam_dns_method='virtual-dns-server', ipam_dns_server=types.IpamDnsAddressType( - virtual_dns_server_name=':'.join(contrail_dns.fq_name))) + virtual_dns_server_name=contrail_dns.get_fq_name_str())) contrail_api_client.network_ipam_update(contrail_ipam) # Create subnet diff --git a/plugin_test/vapor/vapor/tests/test_smoke.py b/plugin_test/vapor/vapor/tests/test_smoke.py index 6152e9c9f..b3ccafa91 100644 --- a/plugin_test/vapor/vapor/tests/test_smoke.py +++ b/plugin_test/vapor/vapor/tests/test_smoke.py @@ -16,7 +16,6 @@ import jmespath import pycontrail.types as types import pytest from stepler.third_party import utils -from stepler.third_party import waiter from vapor.helpers import contrail_status from vapor.helpers import asserts @@ -176,31 +175,3 @@ def test_contrail_alarms_is_empty(client_contrail_analytics): def test_zookeeper_status(znodes_list): expected_znodes_list = settings.ZOOKEEPER_NODES assert_that(znodes_list, contains_inanyorder(*expected_znodes_list)) - - -@pytest.mark.requires('contrail_control_nodes_count >= 2') -def test_contrail_services_status_after_restart_master_node(os_faults_steps): - """Verify contrail services status after master node restart. - - Steps: - #. Restart node with contrail-schema (active) - #. Wait some time - #. Check that contrail services statuses is correct - """ - services_statuses = contrail_status.get_services_statuses(os_faults_steps) - master_node_fqdn = None - for fqdn, services in services_statuses.items(): - for service in services: - if (service['service'] == 'contrail-schema' and - service['status'] == contrail_status.STATUS_ACTIVE): - master_node_fqdn = fqdn - break - assert master_node_fqdn is not None, "Can't find master node" - master_node = os_faults_steps.get_node(fqdns=[master_node_fqdn]) - os_faults_steps.reset_nodes(master_node) - - waiter.wait( - contrail_status.check_services_statuses, - args=(os_faults_steps), - expected_exceptions=AssertionError, - timeout=settings.CONTRAIL_NODE_RESET_TIMEOUT) diff --git a/plugin_test/vapor/vapor/tests/test_system.py b/plugin_test/vapor/vapor/tests/test_system.py index df8c7fc47..46f73c7fc 100644 --- a/plugin_test/vapor/vapor/tests/test_system.py +++ b/plugin_test/vapor/vapor/tests/test_system.py @@ -319,7 +319,8 @@ def test_admin_user_can_get_user_token_info(current_project, token_steps, def test_connectivity_from_server_without_floating( - cirros_image, flavor, net_subnet_router, security_group, server_steps): + cirros_image, flavor, net_subnet_router, neutron_security_group, + server_steps): """Check connectivity via external Contrail network without floating IP. Steps: @@ -342,7 +343,7 @@ def test_connectivity_from_server_without_floating( image=cirros_image, flavor=flavor, networks=[network], - security_groups=[security_group], + security_groups=[neutron_security_group], userdata=userdata)[0] server_steps.check_server_log_contains_record( server, done, timeout=stepler_config.USERDATA_EXECUTING_TIMEOUT) diff --git a/plugin_test/vapor/vapor/tests/test_vrouter.py b/plugin_test/vapor/vapor/tests/test_vrouter.py index 5089d55af..97ba9c907 100644 --- a/plugin_test/vapor/vapor/tests/test_vrouter.py +++ b/plugin_test/vapor/vapor/tests/test_vrouter.py @@ -23,6 +23,7 @@ from vapor.helpers import vrouter_steps @pytest.mark.requires('computes_count >= 2') def test_router_table_cleanup(cirros_image, flavor, network, subnet, current_project, server_steps, + nova_availability_zone_hosts, sorted_hypervisors, port_steps, os_faults_steps, contrail_api_client, iface_route_table_create): """Check that added routes are cleaned up after servers to be deleted.""" @@ -40,11 +41,18 @@ def test_router_table_cleanup(cirros_image, flavor, network, subnet, route_table_before = vrouter_steps.get_route_table(os_faults_steps, computes) + host1 = next( + host for host in nova_availability_zone_hosts + if hypervisor1.hypervisor_hostname.startswith(host)) server1 = server_steps.create_servers( - availability_zone='nova:' + hypervisor1.hypervisor_hostname, + availability_zone='nova:' + host1, **server_create_args)[0] + + host2 = next( + host for host in nova_availability_zone_hosts + if hypervisor2.hypervisor_hostname.startswith(host)) server2 = server_steps.create_servers( - availability_zone='nova:' + hypervisor2.hypervisor_hostname, + availability_zone='nova:' + host2, **server_create_args)[0] port = port_steps.get_port( device_owner=stepler_config.PORT_DEVICE_OWNER_SERVER,