Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2057615

Summary: [RFE] - Ability to use Metric role "metrics_from_mssql" option and the SQL Server roles together
Product: Red Hat Enterprise Linux 8 Reporter: Brian Smith <briasmit>
Component: pcpAssignee: Nathan Scott <nathans>
Status: CLOSED ERRATA QA Contact: Jan Kurik <jkurik>
Severity: unspecified Docs Contact: Jacob Taylor Valdez <jvaldez>
Priority: unspecified    
Version: 8.5CC: agerstmayr, jkurik, limershe, nathans, nhosoi, rmeggins, spetrosi
Target Milestone: rcKeywords: FutureFeature, Triaged
Target Release: 8.7Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: pcp-5.3.7-1.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of:
: 2058778 (view as bug list) Environment:
Last Closed: 2022-11-08 09:21:23 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2058778    

Description Brian Smith 2022-02-23 17:46:20 UTC
Description of problem:
The Metrics role provides the "metrics_from_mssql" option to gather metrics specific to SQL Server.  

The SQL Server role provides the ability to install/configure SQL Server on RHEL.  

It does not currently appear possible to use these two roles together


Version-Release number of selected component (if applicable):
rhel-system-roles-1.7.3-2.el8.noarch
ansible-collection-microsoft-sql-1.1.0-1.el8.noarch

How reproducible:
Every time

Steps to Reproduce:
1. Create playbook use SQL Server role to install/configure SQL Server on hosts
2. Use Metric role with "metrics_from_mssql" option to configure Performance co-pilot with SQL PMDA on these same hosts

Actual results:
This does not result in a working metrics configuration

Expected results:
The roles should be able to work together

Comment 3 Nathan Scott 2022-02-23 23:11:34 UTC
Hmm, these should be able to work together.  This snippet is from the metrics role README.md ...

|    metrics_from_mssql: no
| 
| Boolean flag allowing metrics from SQL Server to be made available.
| Enabling this flag requires a 'trusted' connection to SQL Server.


Is the SQL Server role setting things up to allow trusted connections or does it setup older-style username/password style connections?
There may be more diagnostic details in your /var/log/pcp/pmcd/mssql.log file for us here, Brian.

The underlying ansible-pcp and pmdamssql(1) code supports both modes, so if its the latter we'll need to tweak the metrics role.

Comment 4 Brian Smith 2022-02-24 17:03:58 UTC
I believe the SQL Server role is setting up username/password connections.  

[root@rhel8-server2 ~]# cat /var/log/pcp/pmcd/mssql.log
Log for pmdamssql on rhel8-server2.example.com started Thu Feb 24 10:02:02 2022

[Thu Feb 24 10:02:02] pmdamssql(61267) Info: Connecting to tcp:localhost as user sa
[Thu Feb 24 10:02:02] pmdamssql(61267) Error: mssql_connect: connecting using trusted connection: ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No Kerberos credentials available (default cache: KCM:) (851968) (SQLDriverConnect)')
[Thu Feb 24 10:02:03] pmdamssql(61267) Error: mssql_connect: connecting using trusted connection: ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No Kerberos credentials available (default cache: KCM:) (851968) (SQLDriverConnect)')
[Thu Feb 24 10:02:04] pmdamssql(61267) Error: mssql_connect: connecting using trusted connection: ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No Kerberos credentials available (default cache: KCM:) (851968) (SQLDriverConnect)')
[Thu Feb 24 10:02:05] pmdamssql(61267) Error: mssql_connect: connecting using trusted connection: ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No Kerberos credentials available (default cache: KCM:) (851968) (SQLDriverConnect)')
[Thu Feb 24 10:02:07] pmdamssql(61267) Error: mssql_connect: connecting using trusted connection: ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No Kerberos credentials available (default cache: KCM:) (851968) (SQLDriverConnect)')
[Thu Feb 24 10:02:08] pmdamssql(61267) Error: mssql_connect: connecting using trusted connection: ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]SSPI Provider: No Kerberos credentials available (default cache: KCM:) (851968) (SQLDriverConnect)')
[Thu Feb 24 10:02:09] pmdamssql(61267) Info: FATAL: failed to connect after 5 retries

Log finished Thu Feb 24 10:02:09 2022


[root@rhel8-server2 ~]# cat /var/lib/pcp/pmdas/mssql/mssql.conf
[connection]
driver={ODBC Driver 17 for SQL Server}
server=tcp:localhost
timeout=2

[authentication]
## General reference on authentication options:
#https://docs.microsoft.com/en-us/sql/relational-databases/security/choose-an-authentication-mode

# Option 1: Mixed mode authentication
username=sa
password=<sa account password>

# Option 2: Windows authentication
trusted=False



[root@rhel8-server2 ~]# pminfo mssql
mssql
[root@rhel8-server2 ~]#

Comment 5 Brian Smith 2022-02-24 17:06:48 UTC
If I edit /var/lib/pcp/pmdas/mssql/mssql.conf, and comment out the "trusted=" line, I can then:

[root@rhel8-server2 ~]# systemctl restart pmcd
[root@rhel8-server2 ~]# pminfo mssql | wc -l
168

[root@rhel8-server2 ~]# cat /var/log/pcp/pmcd/mssql.log
Log for pmdamssql on rhel8-server2.example.com started Thu Feb 24 10:05:10 2022

[Thu Feb 24 10:05:10] pmdamssql(61798) Info: Connecting to tcp:localhost as user sa
[Thu Feb 24 10:05:10] pmdamssql(61798) Info: Microsoft SQL Server 2019 (RTM-CU15) (KB5008996) - 15.0.4198.2 (X64) ; Jan 12 2022 22:30:08 ; Copyright (C) 2019 Microsoft Corporation; Enterprise Evaluation Edition (64-bit) on Linux (Red Hat Enterprise Linux 8.5 (Ootpa)) <X64>
[Thu Feb 24 10:05:10] pmdamssql(61798) Info: Setup complete

So it appears that with the "trusted=" line commented out it is able to connect.

Comment 6 Nathan Scott 2022-03-02 01:48:03 UTC
I understand the root cause and have a fix now (in the PCP mssql agent python code).
In the meantime, Louis has found the following workaround requiring no code changes:

- hosts: localhost
  roles:
    - role: rhel-system-roles.metrics
      vars:
        metrics_from_mssql: yes
        mssql_agent_trusted:
        mssql_agent_username: sa
        mssql_agent_password: RedHat123!

Overriding the 'mssql_agent_trusted' to have an empty value, and passing in the username/password (I did not realize we could pass settings through like that - neat!).  Based on my earlier discussions with SQL Server folks I suspect that strongly preferring to use 'trusted' connections as the metrics role currently does is still the right thing to do.  So I'm a little hesitant to change the docs to describe this approach.

Anyway, the code is fixed - problem was to do with python strings being cast to boolean type via bool() and this kind of behavior:

$ python3
Python 3.10.2 (main, Jan 17 2022, 00:00:00) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> foo = 'False'
>>> print(bool(foo))
True
>>> 

Ultimately, the PCP mssql agent needed to take more care with its input.  In the code fix I've kept things such that Louis' workaround (with empty mssql_agent_trusted setting) will continue to work, for both new and old versions of PCP being used by the role.

I'll leave this BZ as-is for now to give folks a chance to comment.  However, in time I think this BZ will need to move to the 'pcp' component, and we'll deliver the code fix in 8.7 and 9.1 (as reflected in BZ state already).

Comment 7 Rich Megginson 2022-03-02 03:43:14 UTC
We ran into something similar and use distutils.util.strtobool for situations like this: https://pagure.io/fork/rmeggins/standard-test-roles/blob/linux-system-roles/f/inventory/standard-inventory-qcow2#_735

bool(distutils.util.strtobool(os.environ.get("TEST_USE_BASENAME", "False")))

https://docs.python.org/3/distutils/apiref.html#distutils.util.strtobool

Comment 8 Rich Megginson 2022-03-02 03:44:06 UTC
and - in yaml

somevalue:

is equivalent to

{"somevalue": None}

in python

Comment 9 Nathan Scott 2022-03-02 04:49:44 UTC
(In reply to Rich Megginson from comment #7)
> We ran into something similar and use distutils.util.strtobool for
> situations like this:

Yep, found that too.  I initially used it but found it has recently been marked deprecated (gives a runtime warning on f35) - https://www.python.org/dev/peps/pep-0632/

Comment 10 Rich Megginson 2022-03-02 14:34:19 UTC
(In reply to Nathan Scott from comment #9)
> (In reply to Rich Megginson from comment #7)
> > We ran into something similar and use distutils.util.strtobool for
> > situations like this:
> 
> Yep, found that too.  I initially used it but found it has recently been
> marked deprecated (gives a runtime warning on f35) -
> https://www.python.org/dev/peps/pep-0632/

Hmm - there are several suggestions for "roll your own" implementations - https://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python
And the pep explicit says "you are on your own":
"For these functions, and any others not mentioned here, you will need to reimplement the functionality yourself. The legacy documentation can be found at https://docs.python.org/3.9/distutils/apiref.html:
distutils.util.strtobool
"

so I guess we'll add that to the pile of tech debt

Comment 11 Rich Megginson 2022-03-02 14:35:46 UTC
@briasmit is the workaround listed in https://bugzilla.redhat.com/show_bug.cgi?id=2057615#c6 acceptable, or do we need to get an exception/blocker for 8.6/9.0?

Comment 12 Rich Megginson 2022-03-02 14:41:18 UTC
(In reply to Rich Megginson from comment #11)
> @briasmit is the workaround listed in
> https://bugzilla.redhat.com/show_bug.cgi?id=2057615#c6 acceptable, or do we
> need to get an exception/blocker for 8.6/9.0?

Acceptable until 8.7/9.1 that is

Comment 13 Brian Smith 2022-03-02 17:22:52 UTC
(In reply to Rich Megginson from comment #12)
> (In reply to Rich Megginson from comment #11)
> > @briasmit is the workaround listed in
> > https://bugzilla.redhat.com/show_bug.cgi?id=2057615#c6 acceptable, or do we
> > need to get an exception/blocker for 8.6/9.0?
> 
> Acceptable until 8.7/9.1 that is

Yes, if we have a workaround for 8.6/9.0, lets target this BZ for 8.7/9.1.  Also discussed this with Louis and he agrees.  Thanks!

Comment 14 Nathan Scott 2022-03-02 23:05:38 UTC
Thanks all.  Switching component to 'pcp' as that's where the code change is, hence this is the package needing update.

Comment 19 errata-xmlrpc 2022-11-08 09:21:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (pcp bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7474