diff --git a/automated-pytest-suite/testcases/functional/dc/conftest.py b/automated-pytest-suite/testcases/functional/dc/conftest.py index 5146c17..c71fa44 100644 --- a/automated-pytest-suite/testcases/functional/dc/conftest.py +++ b/automated-pytest-suite/testcases/functional/dc/conftest.py @@ -9,7 +9,7 @@ from pytest import fixture, skip from consts.proj_vars import ProjVar # Import DC fixtures for testcases to use -from testfixtures.dc_fixtures import check_central_alarms +from testfixtures.dc_fixtures import check_central_alarms_module, check_central_alarms @fixture(scope='module', autouse=True) diff --git a/automated-pytest-suite/testcases/functional/dc/test_shared_config_snmp.py b/automated-pytest-suite/testcases/functional/dc/test_shared_config_snmp.py new file mode 100644 index 0000000..f8147b7 --- /dev/null +++ b/automated-pytest-suite/testcases/functional/dc/test_shared_config_snmp.py @@ -0,0 +1,153 @@ +# +# Copyright (c) 2020 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +from pytest import fixture + +from utils.tis_log import LOG +from utils.clients.ssh import ControllerClient +from consts.proj_vars import ProjVar +from consts.auth import Tenant, TestFileServer +from keywords import dc_helper, system_helper + +SNMP_COMM = 'cgcsauto_dc_snmp_comm' +SNMP_COMM_LOCAL = 'cgcsauto_comm_local' +SNMP_TRAPDEST = ('cgcsauto_dc_snmp_trapdest', TestFileServer.SERVER) +SNMP_TRAPDEST_LOCAL = ('cgcsauto_trapdest_local', '8.8.8.8') + + +@fixture(scope='module') +def snmp_precheck(request): + LOG.info("Gather SNMP config and subcloud management info") + central_auth = Tenant.get('admin_platform', dc_region='RegionOne') + central_comms = system_helper.get_snmp_comms(auth_info=central_auth) + central_trapdests = system_helper.get_snmp_trapdests(auth_info=central_auth) + + primary_subcloud = ProjVar.get_var('PRIMARY_SUBCLOUD') + managed_subclouds = dc_helper.get_subclouds(mgmt='managed', avail='online') + if primary_subcloud in managed_subclouds: + managed_subclouds.remove(primary_subcloud) + else: + dc_helper.manage_subcloud(primary_subcloud) + + ssh_map = ControllerClient.get_active_controllers_map() + managed_subclouds = [subcloud for subcloud in managed_subclouds if subcloud in ssh_map] + + LOG.fixture_step("Ensure SNMP community strings are synced on {}".format(primary_subcloud)) + subcloud_auth = Tenant.get('admin_platform', dc_region=primary_subcloud) + subcloud_comms = system_helper.get_snmp_comms(auth_info=subcloud_auth) + + if sorted(subcloud_comms) != sorted(central_comms): + dc_helper.wait_for_subcloud_snmp_comms(primary_subcloud, expected_comms=central_comms) + + LOG.fixture_step("Ensure SNMP trapdests are synced on {}".format(primary_subcloud)) + subcloud_trapdests = system_helper.get_snmp_trapdests(auth_info=subcloud_auth) + if sorted(subcloud_trapdests) != sorted(central_trapdests): + dc_helper.wait_for_subcloud_snmp_trapdests(primary_subcloud, + expected_trapdests=central_trapdests) + + def revert(): + LOG.fixture_step("Manage {} if unmanaged".format(primary_subcloud)) + dc_helper.manage_subcloud(primary_subcloud) + + LOG.fixture_step("Delete new SNMP community string and trapdest on central region") + system_helper.delete_snmp_comm(comms=SNMP_COMM, auth_info=central_auth) + + LOG.fixture_step("Delete new SNMP community string and trapdest on subcloud") + system_helper.delete_snmp_comm(comms=SNMP_COMM_LOCAL, auth_info=subcloud_auth) + system_helper.delete_snmp_trapdest(ip_addrs=SNMP_TRAPDEST_LOCAL[1], + auth_info=subcloud_auth) + + LOG.fixture_step( + "Wait for sync audit on {} and SNMP community strings and trapdests to sync over" + .format(primary_subcloud)) + dc_helper.wait_for_sync_audit(subclouds=primary_subcloud, fail_ok=True) + dc_helper.wait_for_subcloud_snmp_comms(primary_subcloud, expected_comms=central_comms, + timeout=60, check_interval=10) + dc_helper.wait_for_subcloud_snmp_trapdests(primary_subcloud, + expected_trapdests=central_trapdests, + timeout=60, check_interval=10) + + request.addfinalizer(revert) + + return primary_subcloud, managed_subclouds, central_comms, central_trapdests + + +def test_dc_snmp(snmp_precheck): + """ + + Update DNS servers on central region and check it is propagated to subclouds + Args: + snmp_precheck: test fixture for setup/teardown + + Setups: + - Ensure primary subcloud is managed and SNMP config is synced + + Test Steps: + - Un-manage primary subcloud + - Add a SNMP community string and a trapdest on unmanaged subcloud locally + - Add a different SNMP community string and trapdest on central region + - Wait for new SNMP configs to sync over to managed online subclouds + - Ensure central SNMP configs are not updated on unmanaged primary subcloud + - Re-manage primary subcloud and ensure DNS config syncs over + - Verify nslookup works in Central Region and primary subcloud + + Teardown: + - Delete DNS servers to original value (module) + + """ + primary_subcloud, managed_subclouds, central_comms, central_trapdests = snmp_precheck + central_auth = Tenant.get('admin_platform', dc_region='RegionOne') + sub_auth = Tenant.get('admin_platform', dc_region=primary_subcloud) + + LOG.tc_step("Unmanage {}".format(primary_subcloud)) + dc_helper.unmanage_subcloud(subcloud=primary_subcloud, check_first=False) + + LOG.tc_step( + 'Add SNMP community string and trapdest to unmanaged subcloud - {}' + .format(primary_subcloud)) + system_helper.create_snmp_comm(comm_string=SNMP_COMM_LOCAL, auth_info=sub_auth) + system_helper.create_snmp_trapdest(comm_string=SNMP_TRAPDEST_LOCAL[0], + ip_addr=SNMP_TRAPDEST_LOCAL[1], + auth_info=sub_auth) + + LOG.tc_step('Add SNMP community string and trapdest to central region') + system_helper.create_snmp_comm(comm_string=SNMP_COMM, auth_info=central_auth) + + LOG.tc_step( + "Wait for new SNMP config to sync over to managed subclouds: {}".format(managed_subclouds)) + expt_comms = central_comms + [SNMP_COMM] + expt_trapdests = central_trapdests + dc_helper.wait_for_sync_audit(subclouds=managed_subclouds, fail_ok=True, timeout=660) + for managed_sub in managed_subclouds: + dc_helper.wait_for_subcloud_snmp_comms(subcloud=managed_sub, expected_comms=expt_comms, + timeout=30, check_interval=10) + dc_helper.wait_for_subcloud_snmp_trapdests(subcloud=managed_sub, + expected_trapdests=expt_trapdests, + timeout=30, check_interval=10) + + LOG.tc_step("Ensure central SNMP config is not synced to unmanaged subcloud: {}".format( + primary_subcloud)) + code_comm = dc_helper.wait_for_subcloud_snmp_comms(subcloud=primary_subcloud, + expected_comms=expt_comms, + timeout=15, check_interval=5, + fail_ok=True)[0] + code_trapdest = dc_helper.wait_for_subcloud_snmp_trapdests(subcloud=primary_subcloud, + expected_trapdests=expt_trapdests, + timeout=15, check_interval=5, + fail_ok=True)[0] + assert code_comm == 1, \ + "SNMP comm is updated unexpectedly on unmanaged subcloud {}".format(primary_subcloud) + assert code_trapdest == 1, \ + "SNMP trapdest is updated unexpectedly on unmanaged subcloud {}".format(primary_subcloud) + + LOG.tc_step('Re-manage {} and ensure DNS config syncs over'.format(primary_subcloud)) + dc_helper.manage_subcloud(subcloud=primary_subcloud, check_first=False) + all_comms = expt_comms + [SNMP_COMM_LOCAL] + all_trapdests = expt_trapdests + [SNMP_TRAPDEST_LOCAL[1]] + dc_helper.wait_for_subcloud_snmp_comms(subcloud=primary_subcloud, expected_comms=all_comms) + dc_helper.wait_for_subcloud_snmp_trapdests(subcloud=primary_subcloud, + expected_trapdests=all_trapdests, + timeout=30, check_interval=10) diff --git a/automated-pytest-suite/testcases/functional/dc/test_timezone_unshared.py b/automated-pytest-suite/testcases/functional/dc/test_timezone_unshared.py new file mode 100644 index 0000000..bc0b031 --- /dev/null +++ b/automated-pytest-suite/testcases/functional/dc/test_timezone_unshared.py @@ -0,0 +1,173 @@ +# +# Copyright (c) 2020 Wind River Systems, Inc. +# +# SPDX-License-Identifier: Apache-2.0 +# + +import time +import random + +from pytest import fixture, mark + +from utils.tis_log import LOG +from consts.auth import Tenant +from consts.stx import TIMEZONES +from consts.proj_vars import ProjVar +from keywords import system_helper, dc_helper, host_helper + + +TIMEZONES = TIMEZONES[:-1] # exclude UTC +TIMESTAMP_PATTERN = r'\d{4}-\d{2}-\d{2}[T| ]\d{2}:\d{2}:\d{2}' +DEFAULT_ZONE = 'UTC' + + +@fixture(scope='module', autouse=True) +def prev_check(request, check_central_alarms_module): + + LOG.fixture_step("(module) Ensure both central and subcloud are configured with {} timezone" + .format(DEFAULT_ZONE)) + subcloud = ProjVar.get_var('PRIMARY_SUBCLOUD') + central_auth = Tenant.get('admin_platform', dc_region='RegionOne') + sub_auth = Tenant.get('admin_platform', dc_region=subcloud) + system_helper.modify_timezone(timezone=DEFAULT_ZONE, auth_info=central_auth) + code = system_helper.modify_timezone(timezone=DEFAULT_ZONE, auth_info=sub_auth)[0] + if code == 0: + # allow sometime for change to apply + time.sleep(30) + + prev_central_time = system_helper.get_host_values(host="controller-0", fields='created_at', + auth_info=central_auth)[0] + prev_sub_time = system_helper.get_host_values(host="controller-0", fields='created_at', + auth_info=sub_auth)[0] + LOG.fixture_step("prev_time: {}.".format(prev_central_time)) + central_zone, sub_zone = __select_two_timezones(current_zone=DEFAULT_ZONE) + + def _revert(): + LOG.fixture_step("Revert timezone to {} and ensure host created timestamp also reverted" + .format(DEFAULT_ZONE)) + system_helper.modify_timezone(timezone=DEFAULT_ZONE, auth_info=central_auth) + system_helper.modify_timezone(timezone=DEFAULT_ZONE, auth_info=sub_auth) + wait_for_timestamp_update(auth_info=central_auth, expt_time=prev_central_time) + wait_for_timestamp_update(auth_info=sub_auth, expt_time=prev_sub_time) + request.addfinalizer(_revert) + + return prev_central_time, prev_sub_time, central_zone, sub_zone, central_auth, sub_auth, \ + subcloud + + +def __select_two_timezones(current_zone=None): + if not current_zone: + current_zone = system_helper.get_timezone() + + zones = list(TIMEZONES) + if current_zone in zones: + zones.remove(current_zone) + + selected_zones = random.sample(zones, 2) + LOG.info("Timezone selected to test: {}".format(selected_zones)) + return selected_zones + + +def wait_for_timestamp_update(auth_info, prev_timestamp=None, expt_time=None): + timeout = time.time() + 60 + while time.time() < timeout: + post_timestamp = system_helper.get_host_values(host='controller-0', fields='created_at', + auth_info=auth_info)[0] + if prev_timestamp and prev_timestamp != post_timestamp: + if prev_timestamp != post_timestamp: + return post_timestamp + elif expt_time: + if post_timestamp == expt_time: + return post_timestamp + + time.sleep(5) + else: + LOG.info("Timestamp for fm event did not change") + return None + + +def test_dc_modify_timezone(prev_check): + """ + Test timezone modify on system controller and subcloud. Ensure timezone change is not + propagated. + Setups: + - Ensure both central and subcloud regions are configured with UTC + - Get the timestamps for host created_at before timezone modify + + Test Steps + - Change the timezone in central region and wait until the change is applied + - Change the timezone to a different zone in subcloud and wait until the change is applied + - Verify host created_at timestamp updated according to the local timezone for the region + - Swact on subcloud and ensure timezone and host created_at timestamp persists locally + - Swact central controller and ensure timezone and host created_at timestamp persists + in central and subcloud + + Teardown + - Change timezone to UTC in both central and subcloud regions + - Ensure host created_at timestamp is reverted to original + + """ + prev_central_time, prev_sub_time, central_zone, sub_zone, central_auth, subcloud_auth, \ + subcloud = prev_check + + LOG.tc_step("Modify timezone to {} in central region".format(central_zone)) + system_helper.modify_timezone(timezone=central_zone, auth_info=central_auth) + + LOG.tc_step("Waiting for timestamp for host created_at to update in central region") + post_central_time = wait_for_timestamp_update(prev_timestamp=prev_central_time, + auth_info=central_auth) + assert post_central_time != prev_central_time, \ + "host created_at timestamp did not update after timezone changed " \ + "to {} in central region".format(central_zone) + + LOG.tc_step("Modify timezone to {} in {}".format(sub_zone, subcloud)) + system_helper.modify_timezone(timezone=sub_zone, auth_info=subcloud_auth) + + LOG.tc_step("Waiting for timestamp for same host created_at to update in {}".format(subcloud)) + post_sub_time = wait_for_timestamp_update(prev_timestamp=prev_sub_time, + auth_info=subcloud_auth) + assert post_sub_time != prev_sub_time, \ + "host created_at timestamp did not update after timezone changed to {} " \ + "in {}".format(sub_zone, subcloud) + assert post_sub_time != post_central_time, \ + "Host created_at timestamp is the same on central and {} when configured with different " \ + "timezones".format(subcloud) + + LOG.tc_step("Ensure host created_at timestamp does not change after subcloud sync audit") + dc_helper.wait_for_sync_audit(subclouds=subcloud, fail_ok=True, timeout=660) + post_sync_sub_time = system_helper.get_host_values(host='controller-0', fields='created_at', + auth_info=subcloud_auth)[0] + assert post_sub_time == post_sync_sub_time, \ + "Host created_at timestamp changed after sync audit on {}".format(subcloud) + + if not system_helper.is_aio_simplex(): + LOG.tc_step("Swact in {} region and verify timezone persists locally".format(subcloud)) + host_helper.swact_host(auth_info=subcloud_auth) + post_swact_sub_zone = system_helper.get_timezone(auth_info=subcloud_auth) + assert post_swact_sub_zone == sub_zone + + post_swact_sub_time = system_helper.get_host_values(host='controller-0', + fields='created_at', + auth_info=subcloud_auth)[0] + assert post_swact_sub_time == post_sub_time + + if system_helper.get_standby_controller_name(auth_info=central_auth): + LOG.tc_step("Swact in central region, and ensure timezone persists locally in central" + " and subcloud") + host_helper.swact_host(auth_info=central_auth) + + # Verify central timezone persists + post_swact_central_zone = system_helper.get_timezone(auth_info=central_auth) + assert post_swact_central_zone == central_zone + post_swact_central_time = system_helper.get_host_values(host='controller-0', + fields='created_at', + auth_info=central_auth)[0] + assert post_swact_central_time == post_central_time + + # Verify subcloud timezone persists + post_central_swact_sub_zone = system_helper.get_timezone(auth_info=subcloud_auth) + assert post_central_swact_sub_zone == sub_zone + post_central_swact_sub_time = system_helper.get_host_values(host='controller-0', + fields='created_at', + auth_info=subcloud_auth)[0] + assert post_central_swact_sub_time == post_sub_time diff --git a/automated-pytest-suite/testfixtures/dc_fixtures.py b/automated-pytest-suite/testfixtures/dc_fixtures.py index 9550cbd..ae02c73 100644 --- a/automated-pytest-suite/testfixtures/dc_fixtures.py +++ b/automated-pytest-suite/testfixtures/dc_fixtures.py @@ -23,6 +23,17 @@ def check_central_alarms(request): __verify_central_alarms(request=request, scope='function') +@fixture(scope='module') +def check_central_alarms_module(request): + """ + Check system alarms before and after test session. + + Args: + request: caller of this fixture. i.e., test func. + """ + __verify_central_alarms(request=request, scope='module') + + def __verify_central_alarms(request, scope): region = 'RegionOne' auth_info = Tenant.get('admin_platform', dc_region=region)