def test_rhel_found_via_release_file( self, mock_subprocess_check_output, mock_describe_devices, mock_report_results, mock_sh_blkid, ): """Test finding RHEL via etc release file.""" rhel_version = "7.4" mock_subprocess_check_output.return_value = RPM_RESULT_NONE runner = CliRunner() with runner.isolated_filesystem() as tempdir_path, patch( "cli.mount", helper.fake_mount(tempdir_path)), patch( "cli.INSPECT_PATH", self.inspect_path): helper.prepare_fs_empty(self.drive_path) helper.prepare_fs_rhel_release(self.partition_1) helper.prepare_fs_centos_release(self.partition_2) result = runner.invoke( main, ["-c", CLOUD_AWS, "-t", self.aws_image_id, self.drive_path]) self.assertEqual(result.exit_code, 0) self.assertRhelFound(result.output, rhel_version, self.aws_image_id) self.assertFoundReleaseFile(result.output, self.partition_1, True) self.assertFoundReleaseFile(result.output, self.partition_2, False) mock_sh_blkid.assert_called_once() mock_describe_devices.assert_called_once() mock_report_results.assert_called_once() results = mock_report_results.call_args[0][0] self.assertReportResultsStructure(results, image_ids=[self.aws_image_id]) self.assertReportResultsImageDetails( results, image_id=self.aws_image_id, rhel_found=True, rhel_signed_packages_found=False, rhel_enabled_repos_found=False, rhel_product_certs_found=False, rhel_release_files_found=True, rhel_version=rhel_version, )
def test_rhel_not_found( self, mock_subprocess_check_output, mock_describe_devices, mock_report_results, mock_sh_blkid, ): """ Test not finding RHEL via normal inspection. This exercises effectively the opposite cases of test_rhel_found_multiple_ways. This should verify not finding RHEL in all currently know ways, which includes: * release file(s) exist but do not have RHEL * release file(s) don't exist * yum repo(s) exist and are enabled but do not have RHEL * yum repo(s) exist with RHEL but are not enabled * no installed product certificate(s) * no RHEL found in the RPM database * rpm command fails to execute """ subprocess_error = CalledProcessError(1, "rpm", stderr="rpm failed.") mock_subprocess_check_output.side_effect = [ RPM_RESULT_NONE, # result for `rpm` call in partition_1 subprocess_error, # result for `rpm` call in partition_2 ] runner = CliRunner() with runner.isolated_filesystem() as tempdir_path, patch( "cli.mount", helper.fake_mount(tempdir_path)), patch( "cli.INSPECT_PATH", self.inspect_path): helper.prepare_fs_empty(self.drive_path) helper.prepare_fs_centos_release(self.partition_1) helper.prepare_fs_with_yum(self.partition_1, rhel_enabled=False, include_optional=False) helper.prepare_fs_with_yum(self.partition_2, rhel_enabled=False, include_optional=True) helper.prepare_fs_with_rpm_db(self.partition_1) result = runner.invoke( main, ["-c", CLOUD_AWS, "-t", self.aws_image_id, self.drive_path]) self.assertEqual(result.exit_code, 0) self.assertRhelNotFound(result.output, self.aws_image_id) self.assertFoundReleaseFile(result.output, self.partition_1, False) self.assertFoundEnabledRepos(result.output, self.partition_1, False) self.assertFoundProductCertificate(result.output, self.partition_1, False) self.assertFoundSignedPackages(result.output, self.partition_1, False) self.assertNoReleaseFiles(result.output, self.partition_2) self.assertFoundEnabledRepos(result.output, self.partition_2, False) self.assertFoundProductCertificate(result.output, self.partition_2, False) # Skip next assert because the RPM check quietly errors out (correctly). # self.assertFoundSignedPackages(result.output, self.partition_2, False) mock_sh_blkid.assert_called_once() mock_describe_devices.assert_called_once() mock_report_results.assert_called_once() results = mock_report_results.call_args[0][0] self.assertReportResultsStructure(results, image_ids=[self.aws_image_id]) self.assertReportResultsImageDetails( results, image_id=self.aws_image_id, rhel_found=False, rhel_signed_packages_found=False, rhel_enabled_repos_found=False, rhel_product_certs_found=False, rhel_release_files_found=False, )
def test_rhel_found_multiple_ways( self, mock_subprocess_check_output, mock_describe_devices, mock_report_results, mock_sh_blkid, ): """ Test finding RHEL via multiple ways. This should verify finding RHEL in all currently know ways, which includes: * RHEL in at least one partition's release file(s) * RHEL in at least one partition's enabled yum repo(s) * RHEL in at least one partition's installed product certificate(s) * RHEL in at least one partition's RPM database """ rhel_version = "7.4" mock_subprocess_check_output.side_effect = [ RPM_RESULT_FOUND, # result for `rpm` call in partition_1 RPM_RESULT_NONE, # result for `rpm` call in partition_2 ] runner = CliRunner() with runner.isolated_filesystem() as tempdir_path, patch( "cli.mount", helper.fake_mount(tempdir_path)), patch( "cli.INSPECT_PATH", self.inspect_path): helper.prepare_fs_empty(self.drive_path) helper.prepare_fs_rhel_release(self.partition_1) helper.prepare_fs_rhel_syspurpose(self.partition_1) helper.prepare_fs_with_yum(self.partition_1) helper.prepare_fs_with_rhel_product_certificate(self.partition_1) helper.prepare_fs_with_rpm_db(self.partition_1) helper.prepare_fs_centos_release(self.partition_2) helper.prepare_fs_with_yum(self.partition_2, include_optional=False) helper.prepare_fs_with_rpm_db(self.partition_2) result = runner.invoke( main, ["-c", CLOUD_AWS, "-t", self.aws_image_id, self.drive_path]) self.assertEqual(result.exit_code, 0) self.assertIn(f'"cloud": "{CLOUD_AWS}"', result.output) self.assertIn(f'"{self.aws_image_id}"', result.output) self.assertFoundReleaseFile(result.output, self.partition_1) self.assertFoundEnabledRepos(result.output, self.partition_1) self.assertFoundProductCertificate(result.output, self.partition_1) self.assertFoundSignedPackages(result.output, self.partition_1) self.assertFoundReleaseFile(result.output, self.partition_2, False) self.assertFoundEnabledRepos(result.output, self.partition_2) self.assertFoundProductCertificate(result.output, self.partition_2, False) self.assertFoundSignedPackages(result.output, self.partition_2, False) self.assertRhelFound(result.output, rhel_version, self.aws_image_id) self.assertIn( '{"repo": "rhel7-cdn-internal", "name": "RHEL 7 - $basearch"}', result.output, ) self.assertIn( '{"repo": "rhel7-cdn-internal-extras", "name": "RHEL 7 - $basearch"}', result.output, ) self.assertIn( '{"repo": "rhel7-cdn-internal-optional", "name": "RHEL 7 - $basearch"}', result.output, ) self.assertIn('"role": "Red Hat Enterprise Linux Server"', result.output) mock_sh_blkid.assert_called_once() mock_describe_devices.assert_called_once() mock_report_results.assert_called_once() results = mock_report_results.call_args[0][0] self.assertReportResultsStructure(results, image_ids=[self.aws_image_id]) self.assertReportResultsImageDetails( results, image_id=self.aws_image_id, rhel_found=True, rhel_signed_packages_found=True, rhel_enabled_repos_found=True, rhel_product_certs_found=True, rhel_release_files_found=True, rhel_version=rhel_version, syspurpose_role="Red Hat Enterprise Linux Server", )