Bug 1426357

Summary: RegisterWithActivationKeys method on dbus from com.redhat.RHSM1.Register interface fails with no keys exist for this org
Product: Red Hat Enterprise Linux 7 Reporter: Sean Toner <stoner>
Component: subscription-managerAssignee: Alex Wood <awood>
Status: CLOSED ERRATA QA Contact: John Sefler <jsefler>
Severity: medium Docs Contact:
Priority: high    
Version: 7.3CC: awood, csnyder, jstavel, redakkan, skallesh
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: subscription-manager-1.19.9-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 19:21:47 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:
Attachments:
Description Flags
registering with activation key against stage
none
registering with activation key against standalone candlepin
none
logs from journalctl while making dbus registration with key none

Description Sean Toner 2017-02-23 18:32:00 UTC
Description of problem:
=======================

I tried to register with an ActivationKey using the dbus API.  This is done by calling the RegisterWithActivationKeys method from the com.redhat.RHSM1.Register interface.  If you try to register with an activation key, you will get an error like this:

Traceback (most recent call last):
    File "/usr/lib64/python2.7/site-packages/dbus/service.py", line 707, in _message_cb
      retval = candidate_method(self, *args, **keywords)
    File "/usr/lib/python2.7/site-packages/rhsmlib/dbus/objects/register.py", line 123, in RegisterWithActivationKeys
      result = self._register(org, activation_keys, options)
    File "/usr/lib/python2.7/site-packages/rhsmlib/dbus/objects/register.py", line 141, in _register
      content_tags=self.installed_mgr.tags
    File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 853, in registerConsumer
      return self.conn.request_post(url, params)
    File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 602, in request_post
      return self._request("POST", method, params, headers=headers)
    File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 514, in _request
      self.validateResponse(result, request_type, handler)
    File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 563, in validateResponse
      raise RestlibException(response['status'], error_msg, response.get('headers'))
  RestlibException: None of the activation keys specified exist for this org.


Version-Release number of selected component (if applicable):
=============================================================

[root@stoner-rhel-74 ~]# rpm -qa | grep subscription
subscription-manager-gui-1.19.1-1.git.9.908316a.el7.x86_64
subscription-manager-1.19.1-1.git.9.908316a.el7.x86_64
subscription-manager-initial-setup-addon-1.19.1-1.git.9.908316a.el7.x86_64
subscription-manager-migration-1.19.1-1.git.9.908316a.el7.x86_64
subscription-manager-migration-data-2.0.34-1.git.0.2384ef4.el7.noarch


How reproducible:
=================

Always


Steps to Reproduce:
===================

1. Create a user and account on Ethel account-manager-stage.app.eng.rdu2.redhat.com/#create

2. Run subscription-manager orgs and enter your username and password to determine your org

3. Create an ActivationKey with the following command:

curl -X POST -H "Content-Type:application/json" -k -u {user}:{password} \ "https://subscription.rhn.stage.redhat.com:443/subscription/owners/10879679/activation_keys" \
-d '{"name":"{name-of-activation-key}","autoAttach":"false"}'

4. Run the first busctl command to start the RegisterServer:

busctl call com.redhat.RHSM1 /com/redhat/RHSM1/RegisterServer com.redhat.RHSM1.RegisterServer Start

5. From the result of the above, note down the unix:abstract=/some/tmp/path 

6. Run the second command to actually register with the activation key:

busctl --address=unix:abstract={/some/temp/path} call \
com.redhat.RHSM1 \
/com/redhat/RHSM1/Register \
com.redhat.RHSM1.Register \
RegisterWithActivationKeys 'sa(s)a{ss}' {org} 1 {keyname} 0

7.  Verify that the key does exist for your org:

curl -X GET -H "Content-Type:application/json" -k -u {user}:{password} \ "https://subscription.rhn.stage.redhat.com:443/subscription/owners/10879679/activation_keys" \
-d '{"name":"{name-of-activation-key}","autoAttach":"false"}' | python -m json.tool


Actual results:
===============

Traceback (most recent call last):
    File "/usr/lib64/python2.7/site-packages/dbus/service.py", line 707, in _message_cb
      retval = candidate_method(self, *args, **keywords)
    File "/usr/lib/python2.7/site-packages/rhsmlib/dbus/objects/register.py", line 123, in RegisterWithActivationKeys
      result = self._register(org, activation_keys, options)
    File "/usr/lib/python2.7/site-packages/rhsmlib/dbus/objects/register.py", line 141, in _register
      content_tags=self.installed_mgr.tags
    File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 853, in registerConsumer
      return self.conn.request_post(url, params)
    File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 602, in request_post
      return self._request("POST", method, params, headers=headers)
    File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 514, in _request
      self.validateResponse(result, request_type, handler)
    File "/usr/lib64/python2.7/site-packages/rhsm/connection.py", line 563, in validateResponse
      raise RestlibException(response['status'], error_msg, response.get('headers'))
  RestlibException: None of the activation keys specified exist for this org.


Expected results:
=================

Registration should work


Additional info:
================

I am not able to use dbus-send, because dbus-send does not support nested containers (ie, a{ss} which is an array of dicts).

Also, I noticed a small discrepancy in the code.  In the Register method, the dbus signature is sssa{sv}, but in RegisterWithActivationKeys, the signature is sa(s)a{ss}.  The difference is the last argument for each method.  The last argument is a{sv} and a{ss} respectively, and yet, they both take the same dict type (a dictionary of options).  The a{sv} type is an array of dicts whose key is a string, but whose value varies (is a variant).  The a{ss} type is an array of dicts with key and values both of type string.

Comment 2 Alex Wood 2017-02-23 18:40:55 UTC
Note for developer: The in_signature of Register and RegisterWithActivationKey are not parallel.  The last parameter for one is "a{ss}" and for the other "a{sv}".  Make them uniform.

Comment 3 Sean Toner 2017-02-23 19:03:55 UTC
Oops, step 3 in steps to reproduce should be:

3. Create an ActivationKey with the following command:

curl -X POST -H "Content-Type:application/json" -k -u {user}:{password} \ "https://subscription.rhn.stage.redhat.com:443/subscription/owners/{org}/activation_keys" \
-d '{"name":"{name-of-activation-key}","autoAttach":"false"}'


Also, here's the output of my step 7:
====================================

curl -X GET -H "Content-Type:application/json" -k -u stoner-dbus-test:________ \
  "https://subscription.rhn.stage.redhat.com:443/subscription/owners/10879679/activation_keys" \
  -d '{"name":"stoner-dbus-test-activation-key","autoAttach":"false"}' | python -m json.tool
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  100   487    0   424  100    63    145     21  0:00:03  0:00:02  0:00:01   145
  [
      {
          "autoAttach": false,
          "contentOverrides": [],
          "created": "2017-02-22T18:39:54.000+0000",
          "description": null,
          "id": "8a99f9895a5ee06d015a671f62055e9f",
          "name": "stoner-dbus-test-activation-key",
          "owner": {
              "displayName": "10879679",
              "href": "/owners/10879679",
              "id": "8a99f9845a248553015a3e3689020e68",
              "key": "10879679"
          },
          "pools": [],
          "productIds": [],
          "releaseVer": {
              "releaseVer": null
          },
          "serviceLevel": null,
          "updated": "2017-02-22T18:39:54.000+0000"
      }
  ]

Comment 4 Alex Wood 2017-03-20 20:29:35 UTC
Pending fix: https://github.com/candlepin/subscription-manager/pull/1566

Note to QA: ***The DBus signature for RegisterWithActivationKeys has changed***.  It is now "sasa{sv}".  The new command to use will look like:

busctl --address=unix:abstract=$SOCKET call com.redhat.RHSM1 /com/redhat/RHSM1/Register com.redhat.RHSM1.Register RegisterWithActivationKeys 'sasa{sv}' admin 1 default_key 0

Comment 6 Sean Toner 2017-05-10 14:22:36 UTC
I have tested this by trying against both a standalone candlepin test server, and the stage candlepin to make sure it is reading the rhsm.conf file properly.  It successfully registered to both candlepins (after restarting the rhsm and rhsmcertd.service to pick up the changes in the rhsm.conf file).  Shown below is a registration to the stage candlepin (the output is in the attached file actkey-register-stage.txt):

[root@stoner-rh74-test ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Unknown

[root@stoner-rh74-test ~]# curl -X GET -H "Content-Type:application/json" -k -u 'stoner-actkey-test:redHAT2017' "https://subscription.rhn.stage.redhat.com:443/subscription/owners/10947014/activation_keys" | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   404    0   404    0     0    307      0 --:--:--  0:00:01 --:--:--   307
[
    {
        "autoAttach": false,
        "contentOverrides": [],
        "created": "2017-05-10T13:58:40.000+0000",
        "description": null,
        "id": "8a99f9865bd5837d015bf2a793995793",
        "name": "actkey_test",
        "owner": {
            "displayName": "10947014",
            "href": "/owners/10947014",
            "id": "8a99f9815bd51840015bf2a162637a59",
            "key": "10947014"
        },
        "pools": [],
        "productIds": [],
        "releaseVer": {
            "releaseVer": null
        },
        "serviceLevel": null,
        "updated": "2017-05-10T13:58:40.000+0000"
    }
]

rhsm.conf values for stage
==========================

[root@stoner-rh74-test ~]# cat /etc/rhsm/rhsm.conf | grep subscription.rhn.stage
hostname=subscription.rhn.stage.redhat.com
[root@stoner-rh74-test ~]# cat /etc/rhsm/rhsm.conf | grep "port=443"
port=443
[root@stoner-rh74-test ~]# cat /etc/rhsm/rhsm.conf | grep "/subscription"
prefix=/subscription



And these are the results when running against a standalone candlepin (with the results of the dbus call in actkey-register-standalone.txt):

[root@stoner-rh74-test ~]# subscription-manager status
+-------------------------------------------+
   System Status Details
+-------------------------------------------+
Overall Status: Unknown

[root@stoner-rh74-test ~]# curl -X GET -H "Content-Type:application/json" -k -u testuser1:password "https://stoner-candle.usersys.redhat.com:8443/candlepin/activation_keys/ff8080815a112bc2015beeb689835dd7"
{
  "id" : "ff8080815a112bc2015beeb689835dd7",
  "name" : "actkey_test",
  "description" : null,
  "owner" : {
    "id" : "ff808081584c9e0401584c9fb91b0004",
    "key" : "admin",
    "displayName" : "Admin Owner",
    "href" : "/owners/admin"
  },
  "pools" : [ ],
  "products" : [ ],
  "contentOverrides" : [ ],
  "serviceLevel" : null,
  "autoAttach" : false,
  "created" : "2017-05-09T19:36:31+0000",
  "updated" : "2017-05-09T19:36:31+0000",
  "releaseVer" : {
    "releaseVer" : null
  }
}

with the following values in rhsm.conf
======================================

[root@stoner-rh74-test ~]# cat /etc/rhsm/rhsm.conf | grep stoner
hostname=stoner-candle.usersys.redhat.com
[root@stoner-rh74-test ~]# cat /etc/rhsm/rhsm.conf | grep port=8443
port=8443
[root@stoner-rh74-test ~]# cat /etc/rhsm/rhsm.conf | grep prefix=/candlepin
prefix=/candlepin

Comment 7 Sean Toner 2017-05-10 14:23:19 UTC
Created attachment 1277625 [details]
registering with activation key against stage

Comment 8 Sean Toner 2017-05-10 14:24:04 UTC
Created attachment 1277626 [details]
registering with activation key against standalone candlepin

Comment 9 Sean Toner 2017-05-10 14:26:30 UTC
Created attachment 1277628 [details]
logs from journalctl while making dbus registration with key

Comment 10 Jan Stavel 2017-05-23 09:18:41 UTC
I have written functional test for this usecase. It was passed.

Comment 12 errata-xmlrpc 2017-08-01 19:21:47 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, 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-2017:2083