Example #1
0
def subclouds_to_test(request):

    LOG.info("Gather DNS config and subcloud management info")
    sc_auth = Tenant.get('admin_platform', dc_region='SystemController')
    dns_servers = system_helper.get_dns_servers(auth_info=sc_auth)

    subcloud = ProjVar.get_var('PRIMARY_SUBCLOUD')

    def revert():
        LOG.fixture_step("Manage {} if unmanaged".format(subcloud))
        dc_helper.manage_subcloud(subcloud)

        LOG.fixture_step("Revert DNS config if changed")
        system_helper.set_dns_servers(nameservers=dns_servers,
                                      auth_info=sc_auth)

    request.addfinalizer(revert)

    managed_subclouds = dc_helper.get_subclouds(mgmt='managed', avail='online')
    if subcloud in managed_subclouds:
        managed_subclouds.remove(subcloud)

    ssh_map = ControllerClient.get_active_controllers_map()
    managed_subclouds = [
        subcloud for subcloud in managed_subclouds if subcloud in ssh_map
    ]

    return subcloud, managed_subclouds
Example #2
0
def keypair_precheck(request):

    LOG.fixture_step("Make sure all online subclouds are managed")
    unmanaged_subclouds = dc_helper.get_subclouds(mgmt='unmanaged', avail='online')
    for subcloud in unmanaged_subclouds:
        dc_helper.manage_subcloud(subcloud)

    primary_subcloud = ProjVar.get_var('PRIMARY_SUBCLOUD')
    managed_subclouds = dc_helper.get_subclouds(mgmt='managed', avail='online')
    managed_subclouds.remove(primary_subcloud)

    assert managed_subclouds, "This test needs at least two online subclouds for testing."

    central_auth = Tenant.get('admin', dc_region='SystemController')
    central_keypair = nova_helper.get_keypairs(auth_info=central_auth)

    ssh_map = ControllerClient.get_active_controllers_map()
    managed_subclouds = [subcloud for subcloud in managed_subclouds if subcloud in ssh_map]

    LOG.fixture_step("Ensure keypair are synced on {}".format(primary_subcloud))
    subcloud_auth = Tenant.get('admin', dc_region=primary_subcloud)
    subcloud_keypair = nova_helper.get_keypairs(auth_info=subcloud_auth)

    if sorted(subcloud_keypair) != sorted(central_keypair):
        dc_helper.wait_for_subcloud_keypair(primary_subcloud, expected_keypair=central_keypair)

    def revert():
        LOG.fixture_step("Manage {} if unmanaged".format(primary_subcloud))
        dc_helper.manage_subcloud(primary_subcloud)

        LOG.fixture_step("Delete new keypair on central region")
        nova_helper.delete_keypairs(keypairs=NEW_KEYPAIR, auth_info=central_auth)

        LOG.fixture_step("Wait for sync audit on {} and keypair to sync over".
                         format(primary_subcloud))
        dc_helper.wait_for_sync_audit(subclouds=primary_subcloud, filters_regex='keypair')
        dc_helper.wait_for_subcloud_keypair(primary_subcloud, expected_keypair=central_keypair, timeout=60,
                                            check_interval=10)

    request.addfinalizer(revert)

    return primary_subcloud, managed_subclouds, central_keypair
Example #3
0
def swact_precheck(request):
    LOG.info("Gather subcloud management info")
    subcloud = ProjVar.get_var('PRIMARY_SUBCLOUD')

    def revert():
        LOG.fixture_step("Manage {} if unmanaged".format(subcloud))
        dc_helper.manage_subcloud(subcloud)

    request.addfinalizer(revert)

    managed_subclouds = dc_helper.get_subclouds(
        mgmt=SubcloudStatus.MGMT_MANAGED,
        avail=SubcloudStatus.AVAIL_ONLINE,
        sync=SubcloudStatus.SYNCED)
    if subcloud in managed_subclouds:
        managed_subclouds.remove(subcloud)

    ssh_map = ControllerClient.get_active_controllers_map()
    managed_subclouds = [
        subcloud for subcloud in managed_subclouds if subcloud in ssh_map
    ]

    return subcloud, managed_subclouds
Example #4
0
    def run(self):
        """
        Do not run this command. Start threads from start_thread functions
        Returns:

        """
        LOG.info("Starting {}".format(self.name))
        # run the function
        try:
            MThread.running_threads.append(self)
            LOG.info("Connecting to lab fip in new thread...")
            lab = ProjVar.get_var('lab')

            from keywords import common
            con_ssh = common.ssh_to_stx(set_client=True)

            if ProjVar.get_var('IS_DC'):
                LOG.info("Connecting to subclouds fip in new thread...")
                ControllerClient.set_active_controller(con_ssh, 'RegionOne')
                con_ssh_dict = ControllerClient.get_active_controllers_map()
                for name in con_ssh_dict:
                    if name in lab:
                        subcloud_fip = lab[name]['floating ip']
                        subcloud_ssh = SSHClient(subcloud_fip)
                        try:
                            subcloud_ssh.connect(use_current=False)
                            ControllerClient.set_active_controller(
                                subcloud_ssh, name=name)
                        except:
                            if name == ProjVar.get_var('PRIMARY_SUBCLOUD'):
                                raise
                            LOG.warning('Cannot connect to {}'.format(name))

            LOG.info("Connecting to NatBox in new thread...")
            NATBoxClient.set_natbox_client()
            if ProjVar.get_var('REMOTE_CLI'):
                RemoteCLIClient.get_remote_cli_client()

            LOG.info("Execute function {}({}, {})".format(
                self.func.__name__, self.args, self.kwargs))
            self._output = self.func(*self.args, **self.kwargs)
            LOG.info("{} returned: {}".format(self.func.__name__,
                                              self._output.__str__()))
            self._output_returned.set()
        except:
            err = traceback.format_exc()
            # LOG.error("Error found in thread call {}".format(err))
            self._err = err
            raise
        finally:
            LOG.info("Terminating thread: {}".format(self.thread_id))
            if ProjVar.get_var('IS_DC'):
                ssh_clients = ControllerClient.get_active_controllers(
                    current_thread_only=True)
                for con_ssh in ssh_clients:
                    con_ssh.close()
            else:
                ControllerClient.get_active_controller().close()

            natbox_ssh = NATBoxClient.get_natbox_client()
            if natbox_ssh:
                natbox_ssh.close()

            if ProjVar.get_var('REMOTE_CLI'):
                RemoteCLIClient.get_remote_cli_client().close()
            LOG.debug("{} has finished".format(self.name))
            MThread.running_threads.remove(self)
Example #5
0
def ntp_precheck(request, check_alarms):

    LOG.info("Gather NTP config and subcloud management info")
    central_auth = Tenant.get('admin_platform', dc_region='RegionOne')
    central_ntp = system_helper.get_ntp_servers(auth_info=central_auth)

    primary_subcloud = ProjVar.get_var('PRIMARY_SUBCLOUD')
    subcloud_auth = Tenant.get('admin_platform', dc_region=primary_subcloud)
    subcloud_ntp = system_helper.get_ntp_servers(auth_info=subcloud_auth)

    if not central_ntp == subcloud_ntp:
        dc_helper.wait_for_subcloud_ntp_config(subcloud=primary_subcloud)

    managed_subclouds = dc_helper.get_subclouds(mgmt='managed', avail='online')
    ssh_map = ControllerClient.get_active_controllers_map()
    managed_subclouds = [subcloud for subcloud in managed_subclouds if subcloud in ssh_map]

    if primary_subcloud in managed_subclouds:
        managed_subclouds.remove(primary_subcloud)

    managed_subcloud = None
    if managed_subclouds:
        managed_subcloud = managed_subclouds.pop()
        LOG.fixture_step("Leave only one subcloud besides primary subcloud to be managed: {}".format(managed_subcloud))

    subclouds_to_revert = []
    if managed_subclouds:
        LOG.info("Unmange: {}".format(managed_subclouds))
        for subcloud in managed_subclouds:
            if not system_helper.get_alarms(alarm_id=EventLogID.CONFIG_OUT_OF_DATE,
                                            auth_info=Tenant.get('admin_platform', subcloud)):
                subclouds_to_revert.append(subcloud)
                dc_helper.unmanage_subcloud(subcloud)

    def revert():
        reverted = False
        try:
            LOG.fixture_step("Manage primary subcloud {} if unmanaged".format(primary_subcloud))
            dc_helper.manage_subcloud(primary_subcloud)

            LOG.fixture_step("Revert NTP config if changed")
            res = system_helper.modify_ntp(ntp_servers=central_ntp, auth_info=central_auth, check_first=True,
                                           clear_alarm=False)[0]
            if res != -1:
                LOG.fixture_step("Lock unlock config out-of-date hosts in central region")
                system_helper.wait_and_clear_config_out_of_date_alarms(auth_info=central_auth,
                                                                       wait_with_best_effort=True)

                LOG.fixture_step("Lock unlock config out-of-date hosts in {}".format(primary_subcloud))
                dc_helper.wait_for_subcloud_ntp_config(subcloud=primary_subcloud, expected_ntp=central_ntp,
                                                       clear_alarm=True)

                if managed_subcloud:
                    LOG.fixture_step("Lock unlock config out-of-date hosts in {}".format(managed_subcloud))
                    dc_helper.wait_for_subcloud_ntp_config(subcloud=managed_subcloud, expected_ntp=central_ntp,
                                                           clear_alarm=True)

            if subclouds_to_revert:
                LOG.fixture_step("Manage unmanaged subclouds and check they are unaffected")
                for subcloud in subclouds_to_revert:
                    dc_helper.manage_subcloud(subcloud)
                    assert not system_helper.get_alarms(alarm_id=EventLogID.CONFIG_OUT_OF_DATE,
                                                        auth_info=Tenant.get('admin_platform', dc_region=subcloud))
            reverted = True

        finally:
            if not reverted:
                for subcloud in subclouds_to_revert:
                    dc_helper.manage_subcloud(subcloud)

    request.addfinalizer(revert)

    return primary_subcloud, managed_subcloud, central_ntp
Example #6
0
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)
        system_helper.delete_snmp_trapdest(ip_addrs=SNMP_TRAPDEST[1],
                                           auth_info=central_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)
        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