コード例 #1
0
 def test_edit(self, client, params):
     cdn_repo = deepcopy(CDN_REPO)
     del cdn_repo['relationships']['variants'][1]
     client.adapter.register_uri('GET',
                                 PROD + '/api/v1/cdn_repos',
                                 json={'data': [cdn_repo]})
     client.adapter.register_uri('PUT',
                                 PROD + '/api/v1/cdn_repos/11010',
                                 status_code=200)
     client.adapter.register_uri('GET',
                                 PROD + '/api/v1/cdn_repo_package_tags',
                                 json={'data': CDN_REPO_PACKAGE_TAGS})
     check_mode = False
     result = ensure_cdn_repo(client, check_mode, params)
     expected_stdout_lines = [
         "changing variants from ['8Base-RHCEPH-4.0-Tools'] to"
         " ['8Base-RHCEPH-4.0-Tools', '8Base-RHCEPH-4.1-Tools']"
     ]
     if sys.version_info.major == 2:
         expected_stdout_lines = [
             "changing variants from [u'8Base-RHCEPH-4.0-Tools'] to"
             " ['8Base-RHCEPH-4.0-Tools', '8Base-RHCEPH-4.1-Tools']"
         ]
     assert result['changed'] is True
     assert set(result['stdout_lines']) == set(expected_stdout_lines)
コード例 #2
0
 def test_unchanged(self, client, params, check_mode):
     client.adapter.register_uri('GET',
                                 PROD + '/api/v1/cdn_repos',
                                 json={'data': [CDN_REPO]})
     client.adapter.register_uri('GET',
                                 PROD + '/api/v1/cdn_repo_package_tags',
                                 json={'data': CDN_REPO_PACKAGE_TAGS})
     result = ensure_cdn_repo(client, check_mode, params)
     assert result == {'changed': False, 'stdout_lines': []}
コード例 #3
0
 def test_create_check_mode(self, client, params):
     client.adapter.register_uri('GET',
                                 PROD + '/api/v1/cdn_repos',
                                 json={'data': []})
     check_mode = True
     result = ensure_cdn_repo(client, check_mode, params)
     expected = {
         'changed': True,
         'stdout_lines': ['created redhat-rhceph-rhceph-4-rhel8']
     }
     assert result == expected
コード例 #4
0
 def test_create(self, client, params):
     client.adapter.register_uri('GET',
                                 PROD + '/api/v1/cdn_repos',
                                 json={'data': []})
     client.adapter.register_uri('POST',
                                 PROD + '/api/v1/cdn_repos',
                                 status_code=201,
                                 json={'data': CDN_REPO})
     # When we create a new cdn_repo with some package_names, the ET
     # automatically creates a new tag of "{{version}}-{{release}}" for
     # each of those. Represent that here:
     cdn_repo_package_tags = {
         "id": 13858,
         "type": "cdn_repo_package_tags",
         "attributes": {
             "tag_template": "{{version}}-{{release}}"
         },
         "relationships": {
             "cdn_repo": {
                 "id": 11010,
                 "name": "redhat-rhceph-rhceph-4-rhel8"
             },
             "package": {
                 "id": 45969,
                 "name": "rhceph-container"
             }
         }
     }
     client.adapter.register_uri('GET',
                                 PROD + '/api/v1/cdn_repo_package_tags',
                                 json={'data': [cdn_repo_package_tags]})
     client.adapter.register_uri('POST',
                                 PROD + '/api/v1/cdn_repo_package_tags',
                                 status_code=201)
     check_mode = False
     result = ensure_cdn_repo(client, check_mode, params)
     expected_stdout_lines = [
         'created redhat-rhceph-rhceph-4-rhel8',
         'adding "{{version}}" tag template to "rhceph-container"',
         ('adding "my-variant-restricted-tag" tag template'
          ' to "rhceph-container"'),
         'adding "latest" tag template to "rhceph-container"',
     ]
     assert result['changed'] is True
     assert set(result['stdout_lines']) == set(expected_stdout_lines)
コード例 #5
0
    def test_no_packages(self, client):
        params = {
            'name': 'rhceph-4-tools-for-rhel-8-x86_64-rpms',
            'release_type': 'Primary',
            'content_type': 'Binary',
            'use_for_tps': True,
            'arch': 'x86_64',
            'variants': ['8Base-RHCEPH-4.0-Tools', '8Base-RHCEPH-4.1-Tools'],
            'packages': {},
        }
        client.adapter.register_uri('GET',
                                    PROD + '/api/v1/cdn_repos',
                                    json={'data': []})
        check_mode = True
        result = ensure_cdn_repo(client, check_mode, params)
        expected = {
            'changed': True,
            'stdout_lines': ['created rhceph-4-tools-for-rhel-8-x86_64-rpms'],
            'diff': {
                'after': {
                    'arch':
                    'x86_64',
                    'content_type':
                    'Binary',
                    'name':
                    'rhceph-4-tools-for-rhel-8-x86_64-rpms',
                    'packages': {},
                    'release_type':
                    'Primary',
                    'use_for_tps':
                    True,
                    'variants':
                    ['8Base-RHCEPH-4.0-Tools', '8Base-RHCEPH-4.1-Tools']
                },
                'after_header': "New cdn repo "
                "'rhceph-4-tools-for-rhel-8-x86_64-rpms'",
                'before': {},
                'before_header': 'Not present'
            }
        }

        assert result == expected
コード例 #6
0
    def test_create_check_mode(self, client, params):
        client.adapter.register_uri('GET',
                                    PROD + '/api/v1/cdn_repos',
                                    json={'data': []})
        check_mode = True
        result = ensure_cdn_repo(client, check_mode, params)
        expected = {
            'changed': True,
            'stdout_lines': ['created redhat-rhceph-rhceph-4-rhel8'],
            'diff': {
                'after': {
                    'arch':
                    'multi',
                    'content_type':
                    'Docker',
                    'name':
                    'redhat-rhceph-rhceph-4-rhel8',
                    'packages': {
                        'rhceph-container': [
                            'latest', {
                                'my-variant-restricted-tag': {
                                    'variant': '8Base-RHCEPH-4.0-Tools'
                                }
                            }, '{{version}}', '{{version}}-{{release}}'
                        ]
                    },
                    'release_type':
                    'Primary',
                    'use_for_tps':
                    False,
                    'variants':
                    ['8Base-RHCEPH-4.0-Tools', '8Base-RHCEPH-4.1-Tools']
                },
                'after_header': "New cdn repo 'redhat-rhceph-rhceph-4-rhel8'",
                'before': {},
                'before_header': 'Not present'
            }
        }

        assert result == expected