def test_docs(): cp_aws = CloudProvider( IRPMS(context_wrap(RPMS_AWS)), DMIDecode(context_wrap(DMIDECODE_AWS)), YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)), None ) cp_azure = CloudProvider( IRPMS(context_wrap(RPMS_AZURE)), DMIDecode(context_wrap(DMIDECODE_AZURE_ASSET_TAG)), YumRepoList(context_wrap(YUM_REPOLIST_AZURE)), None ) cp_alibaba = CloudProvider( IRPMS(context_wrap(RPMS)), DMIDecode(context_wrap(DMIDECODE_ALIBABA)), YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)), None ) cp_ibm = CloudProvider( None, None, None, RHSMConf(context_wrap(IBM_RHSM_CONF)) ) env = { 'cp_aws': cp_aws, 'cp_azure': cp_azure, 'cp_alibaba': cp_alibaba, 'cp_ibm': cp_ibm } failed, total = doctest.testmod(cloud_provider, globs=env) assert failed == 0
def test_rhel_repos_empty(): with pytest.raises(SkipException) as se: YumRepoList(context_wrap('')) assert 'No repolist.' in str(se) with pytest.raises(SkipException) as se: YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_EMPTY)) assert 'No repolist.' in str(se)
def test_doc_examples(): env = { 'repolist': YumRepoList(context_wrap(YUM_REPOLIST_DOC)), 'repolist_no_reponame': YumRepoList(context_wrap(YUM_REPOLIST_DOC_NO_REPONAME)), } failed, total = doctest.testmod(yum, globs=env) assert failed == 0
def test_rhel_repos(): repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT)) assert len(repo_list.rhel_repos) == 4 assert set(repo_list.rhel_repos) == set([ 'rhel-7-server-rpms', 'rhel-7-server-satellite-6.1-rpms', 'rhel-7-server-satellite-capsule-6.1-rpms', 'rhel-server-rhscl-7-rpms' ]) repo_list = YumRepoList(context_wrap(YUM_REPOLIST_RHEL8)) assert len(repo_list.rhel_repos) == 7 assert 'satellite-tools-6.7-for-rhel-8-x86_64-rpms' in repo_list.rhel_repos
def test_rhel_repos(): repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT)) assert len(repo_list.rhel_repos) == 4 assert set(repo_list.rhel_repos) == set([ 'rhel-7-server-rpms', 'rhel-7-server-satellite-6.1-rpms', 'rhel-7-server-satellite-capsule-6.1-rpms', 'rhel-server-rhscl-7-rpms' ]) repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_MISSING_STATUS)) assert len(repo_list.rhel_repos) == 0 repo_list = YumRepoList(context_wrap('')) assert len(repo_list.rhel_repos) == 0
def test_rpm_azure(): irpms = IRPMS(context_wrap(RPMS_AZURE)) dmi = DMIDecode(context_wrap(DMIDECODE_BARE_METAL)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == 'azure' assert ret.cp_rpms.get('azure')[0] == 'WALinuxAgent-2.2.18-1.el7'
def test__yum_azure(): irpms = IRPMS(context_wrap(RPMS)) dmi = DMIDecode(context_wrap(DMIDECODE)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == 'azure' assert 'rhui-microsoft-azure-rhel7-2.2-74' in ret.cp_yum.get('azure')
def test_no_data(): irpms = IRPMS(context_wrap(RPMS)) dmi = DMIDecode(context_wrap(DMIDECODE)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl, None) assert ret.cloud_provider is None assert ret.long_name is None
def test__bios_vendor_google(): irpms = IRPMS(context_wrap(RPMS)) dmi = DMIDecode(context_wrap(DMIDECODE_GOOGLE)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == 'google' assert ret.cp_bios_vendor['google'] == 'Google'
def test__asset_tag_azure(): irpms = IRPMS(context_wrap(RPMS)) dmi = DMIDecode(context_wrap(DMIDECODE_AZURE_ASSET_TAG)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == 'azure' assert ret.cp_asset_tag['azure'] == '7783-7084-3265-9085-8269-3286-77'
def test__uuid(): irpms = IRPMS(context_wrap(RPMS)) dmi = DMIDecode(context_wrap(DMIDECODE_AWS_UUID)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == 'aws' assert ret.cp_uuid['aws'] == 'EC2F58AF-2DAD-C57E-88C0-A81CB6084290'
def test_rpm_google(): irpms = IRPMS(context_wrap(RPMS_GOOGLE)) dmi = DMIDecode(context_wrap(DMIDECODE)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == 'google' assert ret.cp_rpms.get('google')[0] == 'google-rhui-client-5.1.100-1.el7'
def test_rpm_aws(): irpms = IRPMS(context_wrap(RPMS_AWS)) dmi = DMIDecode(context_wrap(DMIDECODE)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == 'aws' assert ret.cp_rpms.get('aws')[0] == 'rh-amazon-rhui-client-2.2.124-1.el7'
def test__bios_version_aws(): irpms = IRPMS(context_wrap(RPMS)) dmi = DMIDecode(context_wrap(DMIDECODE_AWS)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == 'aws' assert ret.cp_bios_version['aws'] == '4.2.amazon'
def test_dmidecode_alibaba(): irpms = IRPMS(context_wrap(RPMS)) dmi = DMIDecode(context_wrap(DMIDECODE_ALIBABA)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl) assert ret.cloud_provider == CloudProvider.ALIBABA assert ret.cp_manufacturer[CloudProvider.ALIBABA] == 'Alibaba Cloud'
def test_rpm_aws(): irpms = IRPMS(context_wrap(RPMS_AWS)) dmi = DMIDecode(context_wrap(DMIDECODE)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl, None) assert ret.cloud_provider == CloudProvider.AWS assert ret.cp_rpms.get(CloudProvider.AWS)[0] == 'rh-amazon-rhui-client-2.2.124-1.el7' assert ret.long_name == 'Amazon Web Services'
def test__uuid_not_aws(): irpms = IRPMS(context_wrap(RPMS)) dmi = DMIDecode(context_wrap(DMIDECODE_BARE_METAL)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl, None) assert ret.cloud_provider is None assert ret.cp_uuid[ CloudProvider.AWS] == 'EC245678-1234-1234-1234-123456681234'
def test_rpm_google(): irpms = IRPMS(context_wrap(RPMS_GOOGLE)) dmi = DMIDecode(context_wrap(DMIDECODE)) yrl = YumRepoList(context_wrap(YUM_REPOLIST_NOT_AZURE)) ret = CloudProvider(irpms, dmi, yrl, None) assert ret.cloud_provider == CloudProvider.GOOGLE assert 'google-rhui-client-5.1.100-1.el7' in ret.cp_rpms.get(CloudProvider.GOOGLE) assert 'google-rhui-client-5.1.100-1.el6' in ret.cp_rpms.get(CloudProvider.GOOGLE) assert ret.long_name == 'Google Cloud'
def test_eus(): repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_EUS)) assert len(repo_list) == 2 assert repo_list[0] == { "id": "clone-6u5-server-x86_64", "name": "clone-6u5-server-x86_64", "status": "3,787" } assert repo_list.eus == ["6.2.aus"]
def test_rhel_repos_out_of_date_and_no_match_metadata(): repo_list = YumRepoList( context_wrap(YUM_REPOLIST_CONTENT_OUT_OF_DATE_AND_NOT_MATCH_METADATA)) assert len(repo_list) == 2 assert 'rhel-7-server-extras-rpms/x86_64' in repo_list assert 'rhel-7-server-rpms/7Server/x86_64' in repo_list assert "!rhel-7-server-extras-rpms/x86_64" == repo_list[ 'rhel-7-server-extras-rpms/x86_64']['id'] assert "*rhel-7-server-rpms/7Server/x86_64" == repo_list[ 'rhel-7-server-rpms/7Server/x86_64']['id']
def test_yum_repolist(): repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT)) assert len(repo_list) == 4 assert repo_list[0] == { "id": "rhel-7-server-rpms/7Server/x86_64", "name": "Red Hat Enterprise Linux", "status": "10415" } assert repo_list['rhel-7-server-rpms/7Server/x86_64'] == repo_list[0] assert repo_list.eus == []
def test_invalid_get_type(): repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT)) assert repo_list[YumRepoList] is None
def test_valueerror_in_parse(): repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_MISSING_STATUS)) assert repo_list[0]['name'] == ''
def test_rhel_repos_empty(): with pytest.raises(SkipException) as se: YumRepoList(context_wrap('')) assert 'No repolist.' in str(se)
def test_repolist_zero(): with pytest.raises(SkipException) as se: YumRepoList(context_wrap(YUM_REPOLIST_ZERO)) assert 'No repolist.' in str(se)
def test_repolist_missing_header(): with pytest.raises(ParseException) as se: YumRepoList(context_wrap(YUM_REPOLIST_MISSING_HEADER)) assert 'Failed to parser yum repolist' in str(se)
def test_rhel_repos_missing_status(): with pytest.raises(ParseException) as se: YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_MISSING_STATUS)) assert 'Incorrect line:' in str(se)
def test_rhel_repos_out_of_date(): repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_OUT_OF_DATE)) assert len(repo_list) == 2 assert set(repo_list.rhel_repos) == set( ['rhel-7-server-extras-rpms', 'rhel-7-server-rpms'])
def test_repos_without_repo_name(): repo_list = YumRepoList(context_wrap(YUM_REPO_NO_REPO_NAME)) assert 7 == len(repo_list) assert 2 == len(repo_list.rhel_repos)
def test_repos_without_ends(): repo_list = YumRepoList(context_wrap(YUM_REPOLIST_CONTENT_MISSING_END)) assert 1 == len(repo_list) assert 0 == len(repo_list.rhel_repos)