ahuffman / ansible-satellite6_manage_content_views

An Ansible role to manage creation, publishing, promotion, and deletion of Satellite6 content views.
MIT License
0 stars 2 forks source link

keep_content_view_versions_count attempted to delete wrong version #4

Closed pcfe closed 5 years ago

pcfe commented 5 years ago

I have this in my playbook

          # Publish new version, promote to all lifecycle environments, remove old content view version
          - name: "cv-foobarbaz"
            publish_new_version: True
            publish_description: "Published by Ansible"
            promote_description: "Promoted by Ansible"
            keep_content_view_versions_count: 3
            promote_to:
              - "SOE Test"
              - "Engineering"
              - "Development"
              - "Quality Assurance"

and my versions are:

[root@satellite ~]# hammer content-view version list --content-view cv-foobarbaz --organization-id 1
---|-------------------|---------|---------------------------------------------------------------
ID | NAME              | VERSION | LIFECYCLE ENVIRONMENTS                                        
---|-------------------|---------|---------------------------------------------------------------
33 | cv-foobarbaz 10.0 | 10.0    | Library, Engineering, Development, Quality Assurance, SOE Test
30 | cv-foobarbaz 9.0  | 9.0     |                                                               
28 | cv-foobarbaz 8.0  | 8.0     |                                                               
17 | cv-foobarbaz 7.0  | 7.0     |                                                               
---|-------------------|---------|---------------------------------------------------------------

So I was expecting to keep 10.0, 9.0 and 8.0 and to delete 7.0

Yet it seems it tried to delete 10.0

TASK [ahuffman.satellite6_manage_content_views : Remove old content view versions, keeping 3] *************************************************************************************************************************
included: /home/pcfe/.ansible/roles/ahuffman.satellite6_manage_content_views/tasks/remove_cv_vers.yml for localhost

TASK [ahuffman.satellite6_manage_content_views : Initiate removal of cv-foobarbaz content view version 10.0] **********************************************************************************************************
fatal: [localhost]: FAILED! => {"apipie_checksum": "9d589e5a1f062c9666d496cbb5a111871486c57e", "cache_control": "no-cache", "changed": false, "connection": "close", "content": "{\"displayMessage\":\"Cannot delete version while it is in environments: Library,Engineering,Development,Quality Assurance,SOE Test\",\"errors\":[\"Cannot delete version while it is in environments: Library,Engineering,Development,Quality Assurance,SOE Test\"]}", "content_security_policy": "default-src 'self'; child-src 'self'; connect-src 'self' ws: wss:; img-src 'self' data: *.gravatar.com; script-src 'unsafe-eval' 'unsafe-inline' 'self'; style-src 'unsafe-inline' 'self'", "content_type": "application/json; charset=utf-8", "date": "Thu, 30 May 2019 17:12:15 GMT", "elapsed": 0, "foreman_api_version": "2", "foreman_version": "1.20.1.34", "json": {"displayMessage": "Cannot delete version while it is in environments: Library,Engineering,Development,Quality Assurance,SOE Test", "errors": ["Cannot delete version while it is in environments: Library,Engineering,Development,Quality Assurance,SOE Test"]}, "msg": "Status code was 500 and not [200, 202]: HTTP Error 500: Internal Server Error", "redirected": false, "server": "Apache/2.4.6 (Red Hat Enterprise Linux)", "set_cookie": "_session_id=cc3d820ae1a939c1a0c1fd19024b5e9a; path=/; secure; HttpOnly; SameSite=Lax", "status": 500, "strict_transport_security": "max-age=631139040; includeSubdomains", "transfer_encoding": "chunked", "url": "https://satellite.internal.pcfe.net/katello/api/content_view_versions/33", "x_content_type_options": "nosniff", "x_download_options": "noopen", "x_frame_options": "sameorigin", "x_permitted_cross_domain_policies": "none", "x_powered_by": "Phusion Passenger 4.0.18", "x_request_id": "29e734cf-071f-44ca-8e8d-744d0b1ad52c", "x_runtime": "0.220502", "x_xss_protection": "1; mode=block"}
ahuffman commented 5 years ago

@pcfe can you try out the dev branch? I made a minor change that may correct this issue, but need to validate for me. Let me know, thanks!

ahuffman commented 5 years ago

@pcfe I think I know why it tried deletion of 10.0. Previously I was sorting the list of versions on the name field, and switched to the id field now. The id's should theoretically always be incrementing higher. I'm thinking because the rest of the version names were single digit and the v10.0 was double-digit and starting with '1' it most likely sorted it weird. I think the change on the dev branch will take care of the issue.

Also, I didn't hit this in my test lab because all my CVs are now up to double-digits in the version names. Thanks for submitting the issue!

pcfe commented 5 years ago

LGTM

@pcfe can you try out the dev branch? sure.

$ cd .ansible/roles/ahuffman.satellite6_manage_content_views
$ git remote -v
origin  git@github.com:ahuffman/ansible-satellite6_manage_content_views.git (fetch)
origin  git@github.com:ahuffman/ansible-satellite6_manage_content_views.git (push)
$ git checkout dev
$ git pull

commit a2d6fa465993406e72fd5ec89e72b9ff7651db6b (HEAD -> dev, origin/dev)

I made a minor change that may correct this issue, but need to validate for me. Let me know, thanks!

Which commit (range), alternatively just leave a comment which released version fixes this.

  1. cv-foobarbaz is a good test candidate
[root@satellite ~]# date ; hammer content-view version list --content-view cv-foobarbaz --organization-id 1
Sa 1. Jun 13:21:28 CEST 2019
---|-------------------|---------|------------------------------------------------------
ID | NAME              | VERSION | LIFECYCLE ENVIRONMENTS                               
---|-------------------|---------|------------------------------------------------------
53 | cv-foobarbaz 12.0 | 12.0    | Library                                              
37 | cv-foobarbaz 11.0 | 11.0    | Engineering, Development, Quality Assurance, SOE Test
33 | cv-foobarbaz 10.0 | 10.0    |                                                      
30 | cv-foobarbaz 9.0  | 9.0     |                                                      
28 | cv-foobarbaz 8.0  | 8.0     |                                                      
17 | cv-foobarbaz 7.0  | 7.0     |                                                      
---|-------------------|---------|------------------------------------------------------
  1. run playbook containing the following
          - name: "cv-foobarbaz"
            publish_new_version: True
            publish_description: "Published by Ansible"
            promote_description: "Promoted by Ansible"
            keep_content_view_versions_count: 3
            promote_to:
              - "SOE Test"
              - "Engineering"
              - "Development"
              - "Quality Assurance"

playbook run reports

pcfe@karhu pcfe.net (master) $ date ; ansible-playbook satellite-CV-maintenance.yml 
Sa 1. Jun 13:22:12 CEST 2019
[...]
TASK [ahuffman.satellite6_manage_content_views : Report content view changes] *****************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "Total content views published: 1",
        "Content views published:",
        [
            "cv-foobarbaz"
        ],
        "Total composite content views published: 0",
        "Composite content views published:",
        [],
        "Total content view promotions: 4",
        "Content views promoted:",
        [
            "cv-foobarbaz was promoted to Quality Assurance, Development, Engineering, SOE Test"
        ],
        "Total composite content view component updates: 0",
        "Composite content view components updated:",
        [],
        "Total content view versions removed: 4",
        "Content view versions removed:",
        [
            "cv-foobarbaz - id: 33",
            "cv-foobarbaz - id: 30",
            "cv-foobarbaz - id: 28",
            "cv-foobarbaz - id: 17"
        ]
    ]
}

PLAY RECAP ************************************************************************************************************************************************************************************************************
localhost                  : ok=70   changed=6    unreachable=0    failed=0    skipped=43   rescued=0    ignored=0   
  1. check CV after run
[root@satellite ~]# date ; hammer content-view version list --content-view cv-foobarbaz --organization-id 1
Sa 1. Jun 13:30:06 CEST 2019
---|-------------------|---------|---------------------------------------------------------------
ID | NAME              | VERSION | LIFECYCLE ENVIRONMENTS                                        
---|-------------------|---------|---------------------------------------------------------------
54 | cv-foobarbaz 13.0 | 13.0    | Library, Engineering, Development, Quality Assurance, SOE Test
53 | cv-foobarbaz 12.0 | 12.0    |                                                               
37 | cv-foobarbaz 11.0 | 11.0    |                                                               
---|-------------------|---------|---------------------------------------------------------------

full log of the abnsible runt

pcfe commented 5 years ago

@pcfe I think I know why it tried deletion of 10.0. Previously I was sorting the list of versions on the name field, and switched to the id field now. The id's should theoretically always be incrementing higher.

I'm unsure if this is guaranteed, asked for clarification

Please hold off merging to master until it's certain the ID is always increasing. I have this nagging doubts that it just might not be the case sometimes.

pcfe commented 5 years ago

Please hold off merging to master until it's certain the ID is always increasing. I have this nagging doubts that it just might not be the case sometimes.

Goodie, I remembered wrong. It was confirmed these always increase.