Exemplo n.º 1
0
    def setup_virtual_machine(
        self,
        vm,
        patch_os_release=False,
        install_katello_agent=True,
        enable_rh_repos=True,
        enable_custom_repos=False,
        configure_rhel_repo=False,
    ):
        """
        Setup The virtual machine basic task, eg: install katello ca,
        register vm host, enable rh repos and install katello-agent

        :param VirtualMachine vm: The Virtual machine to setup.
        :param bool patch_os_release: whether to patch the VM with os version.
        :param bool install_katello_agent: whether to install katello-agent
        :param bool enable_rh_repos: whether to enable RH repositories
        :param bool enable_custom_repos: whether to enable custom repositories
        :param bool configure_rhel_repo: Whether to configure the distro Red Hat repository,
            this is needed to configure manually RHEL custom repo url as sync time is very big
            (more than 2 hours for RHEL 7Server) and not critical for some contexts.
        """
        if not self._setup_content_data:
            raise ReposContentSetupWasNotPerformed(
                'Repos content setup was not performed')

        patch_os_release_distro = None
        if patch_os_release and self.os_repo:
            patch_os_release_distro = self.os_repo.distro
        rh_repos_id = []  # type: List[str]
        if enable_rh_repos:
            rh_repos_id = [
                getattr(repo, 'rh_repository_id') for repo in self.rh_repos
            ]
        custom_repos_label = []  # type: List[str]
        if enable_custom_repos:
            custom_repos_label = [
                repo['label'] for repo in self.custom_repos_info
            ]

        setup_virtual_machine(
            vm,
            self.organization['label'],
            rh_repos_id=rh_repos_id,
            repos_label=custom_repos_label,
            product_label=self.custom_product['label']
            if self.custom_product else None,
            activation_key=self._setup_content_data['activation_key']['name'],
            patch_os_release_distro=patch_os_release_distro,
            install_katello_agent=install_katello_agent,
        )
        if configure_rhel_repo:
            rhel_repo_option_name = 'rhel{0}_repo'.format(
                DISTROS_MAJOR_VERSION[self.distro])
            rhel_repo_url = getattr(settings, rhel_repo_option_name, None)
            if not rhel_repo_url:
                raise ValueError(
                    'Settings option "{0}" is whether not set or does not exist'
                    .format(rhel_repo_option_name))
            vm.configure_rhel_repo(rhel_repo_url)
Exemplo n.º 2
0
def test_positive_view_vdc_subscription_products(session):
    """Ensure that Virtual Datacenters subscription provided products is
    not empty and that a consumed product exist in content products.

    :id: cc4593f0-66ab-4bf6-87d1-d4bd9c89eba5

    :customerscenario: true

    :steps:
        1. Upload a manifest with Virtual Datacenters subscription
        2. Enable a products provided by Virtual Datacenters subscription,
           and synchronize the auto created repository
        3. Create content view with the product repository, and publish it
        4. Create a lifecycle environment and promote the content view to
           it.
        5. Create an activation key with the content view and lifecycle
           environment
        6. Subscribe a host to the activation key
        7. Goto Hosts -> Content hosts and select the created content host
        8. Attach VDC subscription to content host
        9. Goto Content -> Red Hat Subscription
        10. Select Virtual Datacenters subscription

    :expectedresults:
        1. assert that the provided products is not empty
        2. assert that the enabled product is in subscription Product Content

    :BZ: 1366327

    :CaseLevel: System
    """
    org = entities.Organization().create()
    lce = entities.LifecycleEnvironment(organization=org).create()
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7, repositories=[RHELAnsibleEngineRepository(cdn=True)]
    )
    product_name = repos_collection.rh_repos[0].data['product']
    repos_collection.setup_content(
        org.id, lce.id, upload_manifest=True, rh_subscriptions=[DEFAULT_SUBSCRIPTION_NAME]
    )
    with VirtualMachine() as vm:
        setup_virtual_machine(
            vm,
            org.label,
            activation_key=repos_collection.setup_content_data['activation_key']['name'],
            install_katello_agent=False,
        )
        with session:
            session.organization.select(org.name)
            session.contenthost.add_subscription(vm.hostname, VDC_SUBSCRIPTION_NAME)
            provided_products = session.subscription.provided_products(VDC_SUBSCRIPTION_NAME)
            # ensure that subscription provided products list is not empty and that the product is
            # in the provided products.
            assert provided_products and product_name in provided_products
            content_products = session.subscription.content_products(VDC_SUBSCRIPTION_NAME)
            # ensure that subscription enabled products list is not empty and that product is in
            # content products.
            assert content_products and product_name in content_products
Exemplo n.º 3
0
def test_positive_view_vdc_subscription_products(session):
    """Ensure that Virtual Datacenters subscription provided products is
    not empty and that a consumed product exist in content products.

    :id: cc4593f0-66ab-4bf6-87d1-d4bd9c89eba5

    :customerscenario: true

    :steps:
        1. Upload a manifest with Virtual Datacenters subscription
        2. Enable a products provided by Virtual Datacenters subscription,
           and synchronize the auto created repository
        3. Create content view with the product repository, and publish it
        4. Create a lifecycle environment and promote the content view to
           it.
        5. Create an activation key with the content view and lifecycle
           environment
        6. Subscribe a host to the activation key
        7. Goto Hosts -> Content hosts and select the created content host
        8. Attach VDC subscription to content host
        9. Goto Content -> Red Hat Subscription
        10. Select Virtual Datacenters subscription

    :expectedresults:
        1. assert that the provided products is not empty
        2. assert that the enabled product is in subscription Product Content

    :BZ: 1366327

    :CaseLevel: System
    """
    org = entities.Organization().create()
    lce = entities.LifecycleEnvironment(organization=org).create()
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7, repositories=[RHELAnsibleEngineRepository(cdn=True)])
    product_name = repos_collection.rh_repos[0].data['product']
    repos_collection.setup_content(
        org.id, lce.id, upload_manifest=True, rh_subscriptions=[DEFAULT_SUBSCRIPTION_NAME])
    with VirtualMachine() as vm:
        setup_virtual_machine(
            vm,
            org.label,
            activation_key=repos_collection.setup_content_data['activation_key']['name'],
            install_katello_agent=False
        )
        with session:
            session.organization.select(org.name)
            session.contenthost.add_subscription(vm.hostname, VDC_SUBSCRIPTION_NAME)
            provided_products = session.subscription.provided_products(VDC_SUBSCRIPTION_NAME)
            # ensure that subscription provided products list is not empty and that the product is
            # in the provided products.
            assert provided_products and product_name in provided_products
            content_products = session.subscription.content_products(VDC_SUBSCRIPTION_NAME)
            # ensure that subscription enabled products list is not empty and that product is in
            # content products.
            assert content_products and product_name in content_products
Exemplo n.º 4
0
    def setup_virtual_machine(
            self, vm, patch_os_release=False, install_katello_agent=True,
            enable_rh_repos=True, enable_custom_repos=False, configure_rhel_repo=False):
        # type: (VirtualMachine, bool, bool, bool, bool, bool) -> None
        """
        Setup The virtual machine basic task, eg: install katello ca,
        register vm host, enable rh repos and install katello-agent

        :param vm: The Virtual machine to setup.
        :param patch_os_release: whether to patch the VM with os version.
        :param install_katello_agent: whether to install katello-agent
        :param enable_rh_repos: whether to enable RH repositories
        :param enable_custom_repos: whether to enable custom repositories
        :param configure_rhel_repo: Whether to configure the distro Red Hat repository, this is
            needed to configure manually RHEL custom repo url as sync time is very big
            (more than 2 hours for RHEL 7Server) and not critical for some contexts.
        """
        if not self._setup_content_data:
            raise ReposContentSetupWasNotPerformed(
                'Repos content setup was not performed')

        patch_os_release_distro = None
        if patch_os_release and self.os_repo:
            patch_os_release_distro = self.os_repo.distro
        rh_repos_id = []  # type: List[str]
        if enable_rh_repos:
            rh_repos_id = [
                getattr(repo, 'rh_repository_id') for repo in self.rh_repos]
        custom_repos_label = []   # type: List[str]
        if enable_custom_repos:
            custom_repos_label = [
                repo['label'] for repo in self.custom_repos_info]

        setup_virtual_machine(
            vm,
            self.organization['label'],
            rh_repos_id=rh_repos_id,
            repos_label=custom_repos_label,
            product_label=self.custom_product[
                'label'] if self.custom_product else None,
            activation_key=self._setup_content_data['activation_key']['name'],
            patch_os_release_distro=patch_os_release_distro,
            install_katello_agent=install_katello_agent
        )
        if configure_rhel_repo:
            rhel_repo_option_name = 'rhel{0}_repo'.format(DISTROS_MAJOR_VERSION[self.distro])
            rhel_repo_url = getattr(settings, rhel_repo_option_name, None)
            if not rhel_repo_url:
                raise ValueError(
                    'Settings option "{0}" is whether not set or does not exist'.format(
                        rhel_repo_option_name))
            vm.configure_rhel_repo(rhel_repo_url)
Exemplo n.º 5
0
    def _setup_virtual_machine(self, vm):
        """Make the initial virtual machine setup

        :param VirtualMachine vm: The virtual machine setup
        """
        setup_virtual_machine(
            vm,
            self.org['label'],
            rh_repos_id=[repo['repository-id'] for repo in self.repos if repo['cdn']],
            repos_label=self.repos_info[1][0]['label'],
            lce=ENVIRONMENT,
            patch_os_release_distro=DISTRO_RHEL7,
            install_katello_agent=True,
        )
Exemplo n.º 6
0
    def setup_virtual_machine(self,
                              vm,
                              patch_os_release=False,
                              install_katello_agent=True,
                              enable_rh_repos=True,
                              enable_custom_repos=False):
        # type: (VirtualMachine, bool, bool, bool, bool)  -> None
        """
        Setup The virtual machine basic task, eg: install katello ca,
        register vm host, enable rh repos and install katello-agent

        :param vm: The Virtual machine to setup.
        :param patch_os_release: whether to patch the VM with os version.
        :param install_katello_agent: whether to install katello-agent
        :param enable_rh_repos: whether to enable RH repositories
        :param enable_custom_repos: whether to enable custom repositories
        """
        if not self._setup_content_data:
            raise ReposContentSetupWasNotPerformed(
                'Repos content setup was not performed')

        distro = None
        if patch_os_release and self.os_repo:
            distro = self.os_repo.distro
        rh_repos_id = []  # type: List[str]
        if enable_rh_repos:
            rh_repos_id = [
                getattr(repo, 'rh_repository_id') for repo in self.rh_repos
            ]
        custom_repos_label = []  # type: List[str]
        if enable_custom_repos:
            custom_repos_label = [
                repo['label'] for repo in self.custom_repos_info
            ]

        setup_virtual_machine(
            vm,
            self.organization['label'],
            rh_repos_id=rh_repos_id,
            repos_label=custom_repos_label,
            product_label=self.custom_product['label']
            if self.custom_product else None,
            activation_key=self._setup_content_data['activation_key']['name'],
            patch_os_release_distro=distro,
            install_katello_agent=install_katello_agent)
Exemplo n.º 7
0
    def test_positive_list_hosts_applicable(self):
        """Request `errata/hosts_applicable` and assert the host with no
        attached subscriptions is present.

        :id: 68ed5b10-7a45-4f2d-93ed-cffa737211d5

        :steps:

            1. Request errata/hosts_applicable for organization created on
               setUp.

        :CaseAutomation: automated

        :expectedresults:
            1. Assert the host with no attached subscription is listed to have
               access to errata content.

        :CaseImportance: Critical
        """
        with VirtualMachine(distro=DISTRO_RHEL7) as vm:
            setup_virtual_machine(
                vm,
                self.org.label,
                rh_repos_id=[
                    repo['repository-id'] for repo in self.repos if repo['cdn']
                ],
                product_label=self.custom_product['label'],
                repos_label=[
                    repo['label'] for repo in self.repos_info
                    if repo['red-hat-repository'] == 'no'
                ],
                lce=ENVIRONMENT,
                patch_os_release_distro=DISTRO_RHEL7,
                install_katello_agent=True,
            )
            host = entities.Host(name=vm.hostname,
                                 organization=self.org).search()[0].read()
            # force host to generate errata applicability
            call_entity_method_with_timeout(host.errata_applicability,
                                            timeout=600)
            erratum = host.errata()['results']
            self.assertGreater(len(erratum), 0)
Exemplo n.º 8
0
    def test_positive_list_hosts_applicable(self):
        """Request `errata/hosts_applicable` and assert the host with no
        attached subscriptions is present.

        :id: 68ed5b10-7a45-4f2d-93ed-cffa737211d5

        :steps:

            1. Request errata/hosts_applicable for organization created on
               setUp.

        :CaseAutomation: automated

        :expectedresults:
            1. Assert the host with no attached subscription is listed to have
               access to errata content.

        :CaseImportance: Critical
        """
        with VirtualMachine(distro=DISTRO_RHEL7) as vm:
            setup_virtual_machine(
                vm,
                self.org.label,
                rh_repos_id=[
                    repo['repository-id'] for repo in self.repos if repo['cdn']
                ],
                product_label=self.custom_product['label'],
                repos_label=[
                    repo['label'] for repo in self.repos_info
                    if repo['red-hat-repository'] == 'no'
                ],
                lce=ENVIRONMENT,
                patch_os_release_distro=DISTRO_RHEL7,
                install_katello_agent=True,
            )
            host = entities.Host(
                name=vm.hostname, organization=self.org).search()[0].read()
            # force host to generate errata applicability
            call_entity_method_with_timeout(
                host.errata_applicability, timeout=600)
            erratum = host.errata()['results']
            self.assertGreater(len(erratum), 0)
Exemplo n.º 9
0
    def _setup_virtual_machine(self, vm):
        """Make the initial virtual machine setup

        :param VirtualMachine vm: The virtual machine setup
        """
        setup_virtual_machine(
            vm,
            self.session_org.label,
            rh_repos_id=[
                repo['repository-id'] for repo in self.repos if repo['cdn']
            ],
            product_label=self.custom_product['label'],
            repos_label=[
                repo['label'] for repo in self.repos_info
                if repo['red-hat-repository'] == 'no'
            ],
            lce=ENVIRONMENT,
            patch_os_release_distro=DISTRO_RHEL7,
            install_katello_agent=True,
        )
Exemplo n.º 10
0
    def _setup_virtual_machine(self, vm):
        """Make the initial virtual machine setup

        :param VirtualMachine vm: The virtual machine setup
        """
        setup_virtual_machine(
            vm,
            self.org['label'],
            rh_repos_id=[
                repo['repository-id'] for repo in self.repos if repo['cdn']
            ],
            product_label=self.custom_product['label'],
            repos_label=[
                repo['label'] for repo in self.repos_info
                if repo['red-hat-repository'] == 'no'
            ],
            lce=ENVIRONMENT,
            patch_os_release_distro=DISTRO_RHEL7,
            install_katello_agent=True,
        )
Exemplo n.º 11
0
    def setup_virtual_machine(
            self, vm, patch_os_release=False, install_katello_agent=True,
            enable_rh_repos=True, enable_custom_repos=False):
        # type: (VirtualMachine, bool, bool, bool, bool)  -> None
        """
        Setup The virtual machine basic task, eg: install katello ca,
        register vm host, enable rh repos and install katello-agent

        :param vm: The Virtual machine to setup.
        :param patch_os_release: whether to patch the VM with os version.
        :param install_katello_agent: whether to install katello-agent
        :param enable_rh_repos: whether to enable RH repositories
        :param enable_custom_repos: whether to enable custom repositories
        """
        if not self._setup_content_data:
            raise ReposContentSetupWasNotPerformed(
                'Repos content setup was not performed')

        distro = None
        if patch_os_release and self.os_repo:
            distro = self.os_repo.distro
        rh_repos_id = []  # type: List[str]
        if enable_rh_repos:
            rh_repos_id = [
                getattr(repo, 'rh_repository_id') for repo in self.rh_repos]
        custom_repos_label = []   # type: List[str]
        if enable_custom_repos:
            custom_repos_label = [
                repo['label'] for repo in self.custom_repos_info]

        setup_virtual_machine(
            vm,
            self.organization['label'],
            rh_repos_id=rh_repos_id,
            repos_label=custom_repos_label,
            product_label=self.custom_product[
                'label'] if self.custom_product else None,
            activation_key=self._setup_content_data['activation_key']['name'],
            patch_os_release_distro=distro,
            install_katello_agent=install_katello_agent
        )