Bug 1354462

Summary: Hammer hostgroup create insist on lifecycle environment
Product: Red Hat Satellite Reporter: Lukas Zapletal <lzap>
Component: HammerAssignee: Andrew Kofink <akofink>
Status: CLOSED ERRATA QA Contact: Jitendra Yejare <jyejare>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.2.0CC: bbuckingham, cwelton, ehelms, jyejare, mbacovsk, mmccune
Target Milestone: UnspecifiedKeywords: Regression, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: rubygem-hammer_cli_katello-0.0.22.21-1,rubygem-hammer_cli_katello-0.0.22.22-1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-07-27 11:36: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:

Description Lukas Zapletal 2016-07-11 11:40:36 UTC
*REGRESSION* (was working in pre-15 drops)

*BLOCKER* (unable to create hostgroup via CLI -> no provisioning)

Some recent change broke hammer cli command:

[root@hp-bl465cg7-01 ~]# hh hostgroup create --name "CentOS 7.0"   --architecture x86_64   --domain nested.lan   --subnet nested.lan   --operatingsystem "CentOS 7.0"   --medium mirror_centos   --partition-table "Kickstart simple"   --puppet-proxy-id 1   --puppet-ca-proxy-id 1   --environment production   --root-pass "$PASS$PASS$PASS"   --organizations "$ORG"   --locations "$LOC"
Could not create the hostgroup:
  Error: lifecycle_environment not found

This was previously working. Now, the problem is it does not respect lifecycle-environment option which was added:

[root@hp-bl465cg7-01 ~]# hh hostgroup create --name "CentOS 7.0"   --architecture x86_64   --domain nested.lan   --subnet nested.lan   --operatingsystem "CentOS 7.0"   --medium mirror_centos   --partition-table "Kickstart simple"   --puppet-proxy-id 1   --puppet-ca-proxy-id 1   --environment production   --root-pass "$PASS$PASS$PASS"   --organizations "$ORG"   --locations "$LOC"   --lifecycle-environment "TestEnv"
Could not create the hostgroup:
  Error: lifecycle_environment not found

You can't provide even numeric ID - all is ignored. Debug mode reveals that due to typo in the codebase perhaps, the CLI tries to search Katello environments via --environment (puppet) option:

[ INFO 2016-07-11 07:34:01 API] GET /katello/api/organizations/1/environments
[DEBUG 2016-07-11 07:34:01 API] Params: {
    "name" => "production"
}
[DEBUG 2016-07-11 07:34:01 API] Headers: {
    :params => {
        "name" => "production"
    }
}
[DEBUG 2016-07-11 07:34:01 API] Response: {
       "total" => 0,
    "subtotal" => 0,
        "page" => 1,
    "per_page" => 20,
       "error" => nil,
      "search" => nil,
        "sort" => {
           "by" => nil,
        "order" => nil
    },
     "results" => []
}

The query is "production" while I expect it to be "TestEnv".

This bug is unfortunate as it blocks automated CLI installation and setup of provisioning. Hostgroup is a must in provisioning setups (for activation key).

Comment 4 Andrew Kofink 2016-07-11 15:14:56 UTC
Created redmine issue http://projects.theforeman.org/issues/15647 from this bug

Comment 5 Lukas Zapletal 2016-07-18 07:21:35 UTC
I can't get it working. Do you test the patch downstream during review?

[root@dell-pem610-01 ~]# rpm -q tfm-rubygem-hammer_cli_katello
tfm-rubygem-hammer_cli_katello-0.0.22.21-1.el7sat.noarch

[root@dell-pem610-01 ~]# hh hostgroup create --name "CentOS 7.0"   --architecture x86_64   --domain nested.lan   --subnet nested.lan   --operatingsystem "CentOS 7.0"   --medium mirror_centos   --partition-table "Kickstart simple"   --puppet-proxy-id 1   --puppet-ca-proxy-id 1   --environment production   --root-pass "$PASS$PASS$PASS"   --organizations "$ORG"   --locations "$LOC"   --lifecycle-environment "TestEnv"
Could not create the hostgroup:
  Error: Options --lifecycle-environment-organization-id are required
  
  See: 'hammer hostgroup create --help'

[root@dell-pem610-01 ~]# hh hostgroup create --name "CentOS 7.0"   --architecture x86_64   --domain nested.lan   --subnet nested.lan   --operatingsystem "CentOS 7.0"   --medium mirror_centos   --partition-table "Kickstart simple"   --puppet-proxy-id 1   --puppet-ca-proxy-id 1   --environment production   --root-pass "$PASS$PASS$PASS"   --organizations "$ORG"   --locations "$LOC"   --lifecycle-environment "TestEnv"   --lifecycle-environment-organization-id 1
Could not create the hostgroup:
  Error: found more than one environment

It looks like the cause is the one which Martin described in comment 3:

[ INFO 2016-07-18 03:20:49 API] GET /api/environments
[DEBUG 2016-07-18 03:20:49 API] Params: {
    "name" => "production"
}
[DEBUG 2016-07-18 03:20:49 API] Headers: {
    :params => {
        "name" => "production"
    }
}
[DEBUG 2016-07-18 03:20:49 API] Response: {
       "total" => 3,
    "subtotal" => 3,
        "page" => 1,
    "per_page" => 100,
      "search" => nil,
        "sort" => {
           "by" => nil,
        "order" => nil
    },
     "results" => [
        [0] {
            "created_at" => "2016-07-18 00:49:01 UTC",
            "updated_at" => "2016-07-18 00:49:01 UTC",
                  "name" => "KT_MyOrg_Library_TestCV_2",
                    "id" => 2
        },
        [1] {
            "created_at" => "2016-07-18 00:49:39 UTC",
            "updated_at" => "2016-07-18 00:49:39 UTC",
                  "name" => "KT_MyOrg_TestEnv_TestCV_2",
                    "id" => 3
        },
        [2] {
            "created_at" => "2016-07-18 00:04:51 UTC",
            "updated_at" => "2016-07-18 00:04:51 UTC",
                  "name" => "production",
                    "id" => 1
        }
    ]
}

Comment 7 Lukas Zapletal 2016-07-19 06:55:30 UTC
It works!

$ hh hostgroup create --name "CentOS 7.0"   --architecture x86_64   --domain nested.lan   --subnet nested.lan   --operatingsystem "CentOS 7.0"   --medium mirror_centos   --partition-table "Kickstart simple"   --puppet-proxy-id 1   --puppet-ca-proxy-id 1   --environment production   --root-pass "$PASS$PASS$PASS"   --organizations "$ORG"   --locations "$LOC"   --lifecycle-environment "TestEnv" --lifecycle-environment-organization-id 1
Hostgroup created

I have to say the --lifecycle-environment-organization-id is a bit clunky, but what we can do in this stage. Created feature for the future versions: http://projects.theforeman.org/issues/15730

Thanks!

Comment 8 Andrew Kofink 2016-07-19 13:33:23 UTC
Lukas,

Now, with BZ #1357557, we've opted to just use --organization-id for both CVs and LEs, since the CV and the LE must be from the same organization on a hostgroup. I hesitate to try to resolve CV/LE IDs with the --organizations/--organization-ids option since there is a chance you have identically named CVs/LEs across different organizations. The --organization-ids/--organizations option is just for assigning the hostgroup to those organizations.

Comment 9 Jitendra Yejare 2016-07-20 12:03:13 UTC
Verified !

@ Sat 6.2 snap 20.3 GA

I can see that hostgroup can be created with and without lifecycle-environment as below and is expected :

# hammer hostgroup create --name "hg3" --architecture x86_64 --domain 'rhq.lab.eng.bos.redhat.com' --subnet 'subnet1' --operatingsystem "RedHat 7.2" --medium 'Default_Organization/Library/rhel7_pro/rhel7_pro_repo' --partition-table 'Kickstart default' --puppet-proxy-id 1 --puppet-ca-proxy-id 1 --environment 'production' --root-pass "$PASS$PASS$PASS" --organization-id 1 --location-ids 2 --lifecycle-environment "DEV"
Hostgroup created

# hammer hostgroup create --name "hg4" --architecture x86_64 --domain 'rhq.lab.eng.bos.redhat.com' --subnet 'subnet1' --operatingsystem "RedHat 7.2" --medium 'Default_Organization/Library/rhel7_pro/rhel7_pro_repo' --partition-table 'Kickstart default' --puppet-proxy-id 1 --puppet-ca-proxy-id 1 --environment 'production' --root-pass "$PASS$PASS$PASS" --organization-id 1 --location-ids 2
Hostgroup created

The Hostgroup 'hg4' above is located in 'Any Context' and not in organization-id 1. If it is not the expected behavior feel free to open another bug.

Moving this bug to 'Verified' state.

Comment 10 Bryan Kearney 2016-07-27 11:36: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-2016:1501