Пример #1
0
    def test_pre_scenario_remoteexecution_satellite(self):
        """Run REX job on client registered with Satellite

        :id: preupgrade-3f338475-fa69-43ef-ac86-f00f4d324b33

        :steps:
            1. Create Subnet.
            2. Create Content host.
            3. Install katello-ca package and register to Satellite host.
            4. Add rex ssh_key of Satellite on content host.
            5. Run the REX job on client vm.

        :expectedresults:
            1. It should create with pre-required details.
            2. REX job should run on it.
        """
        try:
            default_loc_id = entities.Location().search(
                query={'search': 'name="{}"'.format(DEFAULT_LOC)})[0].id
            sn = entities.Subnet(
                domain=self.vm_domain,
                gateway=self.gateway,
                ipam='DHCP',
                location=[default_loc_id],
                mask=self.netmask,
                network=self.subnet,
                organization=[self.org.id],
                remote_execution_proxy=[entities.SmartProxy(id=1)],
            ).create()
            client = VirtualMachine(distro=DISTRO_RHEL7,
                                    provisioning_server=self.libvirt_vm,
                                    bridge=self.bridge)
            client.create()
            client.install_katello_ca()
            client.register_contenthost(org=self.org.label, lce='Library')
            add_remote_execution_ssh_key(hostname=client.ip_addr)
            host = entities.Host().search(
                query={'search': 'name="{}"'.format(client.hostname)})
            host[0].subnet = sn
            host[0].update(['subnet'])
            job = entities.JobInvocation().run(
                data={
                    'job_template_id': 89,
                    'inputs': {
                        'command': "ls"
                    },
                    'targeting_type': 'static_query',
                    'search_query': "name = {0}".format(client.hostname)
                })
            self.assertEqual(job['output']['success_count'], 1)
            global_dict = {
                self.__class__.__name__: {
                    'client_name': client.hostname
                }
            }
            create_dict(global_dict)
        except Exception as exp:
            if client._created:
                self._vm_cleanup(hostname=client.hostname)
            raise Exception(exp)
Пример #2
0
 def setUpClass(cls):
     super(AnsibleREXTestCase, cls).setUpClass()
     cls.sat6_hostname = settings.server.hostname
     # register and setup a host here and tests will share the host, step 0.
     cls.org = entities.Organization().create()
     # create subnet for current org, default loc and domain
     # add rex proxy to subnet, default is internal proxy (id 1)
     # using API due BZ#1370460
     cls.sn = entities.Subnet(
         domain=[1],
         gateway=settings.vlan_networking.gateway,
         ipam='DHCP',
         location=[DEFAULT_LOC_ID],
         mask=settings.vlan_networking.netmask,
         network=settings.vlan_networking.subnet,
         organization=[cls.org.id],
         remote_execution_proxy=[entities.SmartProxy(id=1)],
     ).create()
     # Create VM and register content host
     cls.client = VirtualMachine(
         distro=DISTRO_RHEL7,
         provisioning_server=settings.compute_resources.libvirt_hostname,
         bridge=settings.vlan_networking.bridge)
     cls.addCleanup(vm_cleanup, cls.client)
     cls.client.create()
     cls.client.install_katello_ca()
     cls.client.register_contenthost(org=cls.org['label'], lce='Library')
     cls.assertTrue(cls.client.subscribed)
     Host.set_parameter({
         'host': cls.client.hostname,
         'name': 'remote_execution_connect_by_ip',
         'value': 'True',
     })
     add_remote_execution_ssh_key(cls.client.ip_addr)
Пример #3
0
    def test_positive_run_default_job_template(self):
        """Run a job template against a single host

        @id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217

        @Setup: Use pre-defined job template.

        @Steps:

        1. Navigate to an individual host and click Run Job
        2. Select the job and appropriate template
        3. Run the job

        @Assert: Verify the job was successfully ran against the host

        @CaseLevel: Integration
        """
        with VirtualMachine(distro='rhel71') as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            add_remote_execution_ssh_key(client.ip_addr)
            with Session(self.browser) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(job_category='Commands',
                                      job_template='Run Command - SSH Default',
                                      options_list=[{
                                          'name': 'command',
                                          'value': 'ls'
                                      }])
                self.assertTrue(status)
Пример #4
0
    def test_positive_run_default_job_template(self):
        """Run a job template against a single host

        @id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217

        @Setup: Use pre-defined job template.

        @Steps:

        1. Navigate to an individual host and click Run Job
        2. Select the job and appropriate template
        3. Run the job

        @Assert: Verify the job was successfully ran against the host

        @CaseLevel: Integration
        """
        with VirtualMachine(distro='rhel71') as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            add_remote_execution_ssh_key(client.ip_addr)
            with Session(self.browser) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(
                    job_category='Commands',
                    job_template='Run Command - SSH Default',
                    options_list=[{'name': 'command', 'value': 'ls'}]
                )
                self.assertTrue(status)
Пример #5
0
    def test_positive_run_default_job_template_multiple_hosts(self):
        """Run default job template against multiple hosts

        :id: 415c0156-be77-4676-918b-c0d4be810b0e

        :expectedresults: Verify the job was successfully ran against all hosts
        """
        with VirtualMachine(
            distro=DISTRO_RHEL7,
            provisioning_server=settings.compute_resources.libvirt_hostname,
            bridge=settings.vlan_networking.bridge,
        ) as client2:
            client2.install_katello_ca()
            client2.register_contenthost(
                self.org.label, lce='Library')
            add_remote_execution_ssh_key(client2.ip_addr)
            invocation_command = make_job_invocation({
                'job-template': 'Run Command - SSH Default',
                'inputs': 'command="ls"',
                'search-query': "name ~ {0} or name ~ {1}".format(
                    self.client.hostname, client2.hostname),
            })
            # collect output messages from clients
            output_msgs = []
            for vm in self.client, client2:
                output_msgs.append(
                    'host output from {0}: {1}'.format(
                        vm.hostname,
                        ' '.join(JobInvocation.get_output({
                            'id': invocation_command[u'id'],
                            'host': vm.hostname})
                        )
                    )
                )
            self.assertEqual(invocation_command['success'], u'2', output_msgs)
Пример #6
0
    def test_positive_run_default_job_template_multiple_hosts(self):
        """Run default job template against multiple hosts

        :id: 415c0156-be77-4676-918b-c0d4be810b0e

        :expectedresults: Verify the job was successfully ran against all hosts
        """
        with VirtualMachine(
            distro=DISTRO_RHEL7,
            provisioning_server=settings.compute_resources.libvirt_hostname,
            bridge=settings.vlan_networking.bridge,
        ) as client2:
            client2.install_katello_ca()
            client2.register_contenthost(
                self.org.label, lce='Library')
            add_remote_execution_ssh_key(client2.ip_addr)
            invocation_command = make_job_invocation({
                'job-template': 'Run Command - SSH Default',
                'inputs': 'command="ls"',
                'search-query': "name ~ {0} or name ~ {1}".format(
                    self.client.hostname, client2.hostname),
            })
            # collect output messages from clients
            output_msgs = []
            for vm in self.client, client2:
                output_msgs.append(
                    'host output from {0}: {1}'.format(
                        vm.hostname,
                        ' '.join(JobInvocation.get_output({
                            'id': invocation_command[u'id'],
                            'host': vm.hostname})
                        )
                    )
                )
            self.assertEqual(invocation_command['success'], u'2', output_msgs)
Пример #7
0
    def test_positive_run_custom_job_template(self):
        """Run a job template against a single host

        :id: 89b75feb-afff-44f2-a2bd-2ffe74b63ec7

        :Setup: Create a working job template.

        :Steps:

            1. Navigate to an individual host and click Run Job
            2. Select the job and appropriate template
            3. Run the job

        :expectedresults: Verify the job was successfully ran against the host

        :CaseLevel: System
        """
        jobs_template_name = gen_string('alpha')
        with VirtualMachine(
                distro=DISTRO_RHEL7,
                bridge=settings.vlan_networking.bridge
                ) as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            self.assertTrue(client.subscribed)
            add_remote_execution_ssh_key(client.ip_addr)
            Host.update({
                u'name': client.hostname,
                u'subnet-id': self.new_sub['id'],
            })
            with Session(self) as session:
                set_context(session, org=self.organization.name)
                make_job_template(
                    session,
                    name=jobs_template_name,
                    template_type='input',
                    template_content='<%= input("command") %>',
                    provider_type='SSH',
                )
                self.assertIsNotNone(
                    self.jobtemplate.search(jobs_template_name))
                self.jobtemplate.add_input(
                    jobs_template_name, 'command', required=True)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(
                    job_category='Miscellaneous',
                    job_template=jobs_template_name,
                    options_list=[{'name': 'command', 'value': 'ls'}]
                )
                # get job invocation id from the current url
                invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                self.assertTrue(
                        status,
                        'host output: {0}'.format(
                            ' '.join(JobInvocation.get_output({
                                'id': invocation_id,
                                'host': client.hostname})
                            )
                        )
                    )
Пример #8
0
def vm_module_streams(repos_collection_for_module_streams):
    """Virtual machine registered in satellite without katello-agent installed"""
    with VirtualMachine(distro=repos_collection_for_module_streams.distro) as vm_module_streams:
        repos_collection_for_module_streams.setup_virtual_machine(vm_module_streams,
                                                                  install_katello_agent=False)
        add_remote_execution_ssh_key(vm_module_streams.ip_addr)
        yield vm_module_streams
Пример #9
0
def test_positive_run_default_job_template_by_ip(session, module_org,
                                                 module_subnet):
    """Run a job template on a host connected by ip

    :id: 9a90aa9a-00b4-460e-b7e6-250360ee8e4d

    :Setup: Use pre-defined job template.

    :Steps:

        1. Set remote_execution_connect_by_ip on host to true
        2. Navigate to an individual host and click Run Job
        3. Select the job and appropriate template
        4. Run the job

    :expectedresults: Verify the job was successfully ran against the host

    :CaseLevel: System
    """
    with VirtualMachine(
            distro=DISTRO_RHEL6,
            provisioning_server=settings.compute_resources.libvirt_hostname,
            bridge=settings.vlan_networking.bridge,
    ) as client:
        client.install_katello_ca()
        client.register_contenthost(module_org.label, lce='Library')
        assert client.subscribed
        add_remote_execution_ssh_key(client.ip_addr)
        Host.update({
            'name': client.hostname,
            'subnet-id': module_subnet.id,
        })
        # connect to host by ip
        Host.set_parameter({
            'host': client.hostname,
            'name': 'remote_execution_connect_by_ip',
            'value': 'True',
        })
        hostname = client.hostname
        with session:
            session.organization.select(module_org.name)
            assert session.host.search(hostname)[0]['Name'] == hostname
            session.jobinvocation.run({
                'job_category':
                'Commands',
                'job_template':
                'Run Command - SSH Default',
                'search_query':
                'name ^ {}'.format(hostname),
                'template_content.command':
                'ls',
            })
            session.jobinvocation.wait_job_invocation_state(
                entity_name='Run ls', host_name=hostname)
            status = session.jobinvocation.read(entity_name='Run ls',
                                                host_name=hostname)
            assert status['overview']['hosts_table'][0]['Status'] == 'success'
Пример #10
0
    def test_positive_run_custom_job_template(self):
        """Run a job template against a single host

        :id: 89b75feb-afff-44f2-a2bd-2ffe74b63ec7

        :Setup: Create a working job template.

        :Steps:

            1. Navigate to an individual host and click Run Job
            2. Select the job and appropriate template
            3. Run the job

        :expectedresults: Verify the job was successfully ran against the host

        :CaseLevel: System
        """
        jobs_template_name = gen_string('alpha')
        with VirtualMachine(distro=DISTRO_RHEL7,
                            bridge=settings.vlan_networking.bridge) as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            self.assertTrue(client.subscribed)
            add_remote_execution_ssh_key(client.ip_addr)
            Host.update({
                u'name': client.hostname,
                u'subnet-id': self.new_sub['id'],
            })
            with Session(self) as session:
                set_context(session, org=self.organization.name)
                make_job_template(
                    session,
                    name=jobs_template_name,
                    template_type='input',
                    template_content='<%= input("command") %>',
                    provider_type='SSH',
                )
                self.assertIsNotNone(
                    self.jobtemplate.search(jobs_template_name))
                self.jobtemplate.add_input(jobs_template_name,
                                           'command',
                                           required=True)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(job_category='Miscellaneous',
                                      job_template=jobs_template_name,
                                      options_list=[{
                                          'name': 'command',
                                          'value': 'ls'
                                      }])
                # get job invocation id from the current url
                invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                self.assertTrue(
                    status, 'host output: {0}'.format(' '.join(
                        JobInvocation.get_output({
                            'id': invocation_id,
                            'host': client.hostname
                        }))))
Пример #11
0
    def test_positive_run_default_job_template_by_ip(self):
        """Run a job template on a host connected by ip

        :id: 9a90aa9a-00b4-460e-b7e6-250360ee8e4d

        :Setup: Use pre-defined job template.

        :Steps:

            1. Set remote_execution_connect_by_ip on host to true
            2. Navigate to an individual host and click Run Job
            3. Select the job and appropriate template
            4. Run the job

        :expectedresults: Verify the job was successfully ran against the host

        :CaseLevel: Integration
        """
        with VirtualMachine(
              distro=DISTRO_RHEL7,
              provisioning_server=settings.compute_resources.libvirt_hostname,
              bridge=settings.vlan_networking.bridge,
              ) as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            self.assertTrue(client.subscribed)
            add_remote_execution_ssh_key(client.ip_addr)
            Host.update({
                'name': client.hostname,
                'subnet-id': self.new_sub.id,
            })
            # connect to host by ip
            Host.set_parameter({
                'host': client.hostname,
                'name': 'remote_execution_connect_by_ip',
                'value': 'True',
            })
            with Session(self) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(
                    job_category='Commands',
                    job_template='Run Command - SSH Default',
                    options_list=[{'name': 'command', 'value': 'ls'}]
                )
                # get job invocation id from the current url
                invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                try:
                    self.assertTrue(status)
                except AssertionError:
                    result = 'host output: {0}'.format(
                            ' '.join(JobInvocation.get_output({
                                'id': invocation_id,
                                'host': client.hostname})
                            )
                        )
                    raise AssertionError(result)
Пример #12
0
    def test_positive_run_job_template_multiple_hosts(self):
        """Run a job template against multiple hosts

        :id: 7f1981cb-afcc-49b7-a565-7fef9aa8ddde

        :Setup: Create a working job template.

        :Steps:

            1. Navigate to the hosts page and select at least two hosts
            2. Click the "Select Action"
            3. Select the job and appropriate template
            4. Run the job

        :expectedresults: Verify the job was successfully ran against the hosts

        :CaseLevel: System
        """
        with VirtualMachine(distro=DISTRO_RHEL7,
                            bridge=settings.vlan_networking.bridge) as client:
            with VirtualMachine(
                    distro=DISTRO_RHEL7,
                    bridge=settings.vlan_networking.bridge) as client2:
                for vm in client, client2:
                    vm.install_katello_ca()
                    vm.register_contenthost(self.organization.label,
                                            lce='Library')
                    self.assertTrue(vm.subscribed)
                    add_remote_execution_ssh_key(vm.ip_addr)
                    Host.update({
                        u'name': vm.hostname,
                        u'subnet-id': self.new_sub['id'],
                    })
                with Session(self) as session:
                    set_context(session, org=self.organization.name)
                    self.hosts.update_host_bulkactions(
                        [client.hostname, client2.hostname],
                        action='Run Job',
                        parameters_list=[{
                            'command': 'ls'
                        }],
                    )
                    strategy, value = locators['job_invocation.status']
                    if self.job.wait_until_element(
                        (strategy, value % 'succeeded'), 240) is not None:
                        status = True
                    else:
                        status = False
                    # get job invocation id from the current url
                    invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                    self.assertTrue(
                        status, 'host output: {0}'.format(' '.join(
                            JobInvocation.get_output({
                                'id': invocation_id,
                                'host': client.hostname
                            }))))
Пример #13
0
    def test_positive_run_job_template_multiple_hosts(self):
        """Run a job template against multiple hosts

        :id: 7f1981cb-afcc-49b7-a565-7fef9aa8ddde

        :Setup: Create a working job template.

        :Steps:

            1. Navigate to the hosts page and select at least two hosts
            2. Click the "Select Action"
            3. Select the job and appropriate template
            4. Run the job

        :expectedresults: Verify the job was successfully ran against the hosts

        :CaseLevel: System
        """
        with VirtualMachine(
                distro=DISTRO_RHEL7,
                bridge=settings.vlan_networking.bridge
                ) as client:
            with VirtualMachine(
                    distro=DISTRO_RHEL7,
                    bridge=settings.vlan_networking.bridge
                    ) as client2:
                for vm in client, client2:
                    vm.install_katello_ca()
                    vm.register_contenthost(
                        self.organization.label, lce='Library')
                    self.assertTrue(vm.subscribed)
                    add_remote_execution_ssh_key(vm.ip_addr)
                    Host.update({
                        u'name': vm.hostname,
                        u'subnet-id': self.new_sub['id'],
                    })
                with Session(self) as session:
                    set_context(session, org=self.organization.name)
                    self.hosts.update_host_bulkactions(
                        [client.hostname, client2.hostname],
                        action='Run Job',
                        parameters_list=[{'command': 'ls'}],
                    )
                    strategy, value = locators['job_invocation.status']
                    if self.job.wait_until_element(
                            (strategy, value % 'succeeded'), 240) is not None:
                        status = True
                    else:
                        status = False
                    # get job invocation id from the current url
                    invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                    self.assertTrue(status, 'host output: {0}'.format(
                        ' '.join(JobInvocation.get_output({
                             'id': invocation_id,
                             'host': client.hostname
                         }))))
Пример #14
0
def vm_rhel8(activation_key, module_org):
    with VMBroker(nick='rhel8', host_classes={'host': ContentHost}) as vm:
        vm.configure_rhai_client(
            activation_key=activation_key.name,
            org=module_org.label,
            rhel_distro=DISTRO_RHEL8,
            register=False,
        )
        add_remote_execution_ssh_key(vm.ip_addr)
        yield vm
Пример #15
0
def vm_content_hosts(module_loc, module_repos_collection, default_sat):
    distro = module_repos_collection.distro
    with VMBroker(nick=distro, host_classes={'host': ContentHost},
                  _count=2) as clients:
        for client in clients:
            module_repos_collection.setup_virtual_machine(
                client, default_sat, install_katello_agent=False)
            add_remote_execution_ssh_key(client.ip_addr)
            update_vm_host_location(client, module_loc.id)
        yield clients
Пример #16
0
    def test_pre_scenario_remoteexecution_satellite(self, request,
                                                    compute_resource_setup,
                                                    default_location,
                                                    rhel7_contenthost,
                                                    default_sat):
        """Run REX job on client registered with Satellite

        :id: preupgrade-3f338475-fa69-43ef-ac86-f00f4d324b33

        :steps:
            1. Create Subnet.
            2. Create Content host.
            3. Install katello-ca package and register to Satellite host.
            4. Add rex ssh_key of Satellite on content host.
            5. Run the REX job on client vm.

        :expectedresults:
            1. It should create with pre-required details.
            2. REX job should run on it.
        """
        sn = entities.Subnet(
            domain=self.vm_domain,
            gateway=self.gateway,
            ipam='DHCP',
            location=[default_location.id],
            mask=self.netmask,
            network=self.subnet,
            organization=[self.org.id],
            remote_execution_proxy=[entities.SmartProxy(id=1)],
        ).create()
        rhel7_contenthost.install_katello_ca(default_sat)
        rhel7_contenthost.register_contenthost(org=self.org.label,
                                               lce='Library')
        add_remote_execution_ssh_key(hostname=rhel7_contenthost.ip_addr)
        host = entities.Host().search(
            query={'search': f'name="{rhel7_contenthost.hostname}"'})
        host[0].subnet = sn
        host[0].update(['subnet'])
        job = entities.JobInvocation().run(
            data={
                'job_template_id': 89,
                'inputs': {
                    'command': 'ls'
                },
                'targeting_type': 'static_query',
                'search_query': f'name = {rhel7_contenthost.hostname}',
            })
        assert job['output']['success_count'] == 1
        global_dict = {
            self.__class__.__name__: {
                'client_name': rhel7_contenthost.hostname
            }
        }
        create_dict(global_dict)
Пример #17
0
    def test_positive_run_default_job_template_multiple_hosts_by_ip(
        self, fixture_vmsetup, fixture_org
    ):
        """Run default job template against multiple hosts by ip

        :id: 694a21d3-243b-4296-8bd0-4bad9663af15

        :expectedresults: Verify the job was successfully ran against all hosts

        :parametrized: yes
        """
        self.org = fixture_org
        self.client = fixture_vmsetup
        Host.set_parameter(
            {
                'host': self.client.hostname,
                'name': 'remote_execution_connect_by_ip',
                'value': 'True',
            }
        )
        with VirtualMachine(distro=DISTRO_RHEL7) as client2:
            client2.install_katello_ca()
            client2.register_contenthost(self.org.label, lce='Library')
            add_remote_execution_ssh_key(client2.ip_addr)
            Host.set_parameter(
                {
                    'host': client2.hostname,
                    'name': 'remote_execution_connect_by_ip',
                    'value': 'True',
                }
            )
            invocation_command = make_job_invocation(
                {
                    'job-template': 'Run Command - SSH Default',
                    'inputs': 'command="ls"',
                    'search-query': "name ~ {} or name ~ {}".format(
                        self.client.hostname, client2.hostname
                    ),
                }
            )
            # collect output messages from clients
            output_msgs = []
            for vm in self.client, client2:
                output_msgs.append(
                    'host output from {}: {}'.format(
                        vm.hostname,
                        ' '.join(
                            JobInvocation.get_output(
                                {'id': invocation_command['id'], 'host': vm.hostname}
                            )
                        ),
                    )
                )
            assert invocation_command['success'] == '2', output_msgs
Пример #18
0
def _setup_host(client, org_label):
    """Set up host for remote execution"""
    client.install_katello_ca()
    client.register_contenthost(org=org_label, lce='Library')
    assert client.subscribed
    add_remote_execution_ssh_key(client.ip_addr)
    Host.set_parameter({
        'host': client.hostname,
        'name': 'remote_execution_connect_by_ip',
        'value': 'True',
    })
Пример #19
0
    def test_pre_scenario_remoteexecution_external_capsule(self):
        """Run REX job on client registered with external capsule

        :id: preupgrade-261dd2aa-be01-4c34-b877-54b8ee346561

        :steps:
            1. Create Subnet.
            2. Create Content host.
            3. Install katello-ca package and register to Satellite host.
            4. add rex ssh_key of external capsule on content host.
            5. run the REX job on client vm.

        :expectedresults:
            1. Content host should create with pre-required details.
            2. REX job should run on it.
        """
        try:
            sn = entities.Subnet(
                domain=self.vm_domain,
                gateway=self.gateway,
                ipam='DHCP',
                location=[DEFAULT_LOC_ID],
                mask=self.netmask,
                network=self.subnet,
                organization=[self.org.id],
                remote_execution_proxy=[entities.SmartProxy(id=2)],
            ).create()
            client = VirtualMachine(
                distro=DISTRO_RHEL7,
                provisioning_server=self.libvirt_vm,
                bridge=self.bridge)
            client.create()
            client.install_capsule_katello_ca(capsule=self.proxy_name)
            client.register_contenthost(org=self.org.label, lce='Library')
            add_remote_execution_ssh_key(hostname=client.ip_addr,
                                         proxy_hostname=self.proxy_name)
            host = entities.Host().search(
                query={'search': 'name="{}"'.format(client.hostname)})
            host[0].subnet = sn
            host[0].update(['subnet'])
            job = entities.JobInvocation().run(data={
                'job_template_id': 89, 'inputs': {'command': "ls"},
                'targeting_type': 'static_query', 'search_query': "name = {0}"
                .format(client.hostname)})
            self.assertEqual(job['output']['success_count'], 1)
            global_dict = {
                self.__class__.__name__: {'client_name': client.hostname}
            }
            create_dict(global_dict)
        except Exception as exp:
            if client._created:
                self._vm_cleanup(hostname=client.hostname)
            raise Exception(exp)
Пример #20
0
def test_positive_run_default_job_template_by_ip(
        session, module_org, module_subnet):
    """Run a job template on a host connected by ip

    :id: 9a90aa9a-00b4-460e-b7e6-250360ee8e4d

    :Setup: Use pre-defined job template.

    :Steps:

        1. Set remote_execution_connect_by_ip on host to true
        2. Navigate to an individual host and click Run Job
        3. Select the job and appropriate template
        4. Run the job

    :expectedresults: Verify the job was successfully ran against the host

    :CaseLevel: Integration
    """
    with VirtualMachine(
        distro=DISTRO_RHEL6,
        provisioning_server=settings.compute_resources.libvirt_hostname,
        bridge=settings.vlan_networking.bridge,
    ) as client:
        client.install_katello_ca()
        client.register_contenthost(module_org.label, lce='Library')
        assert client.subscribed
        add_remote_execution_ssh_key(client.ip_addr)
        Host.update({
            'name': client.hostname,
            'subnet-id': module_subnet.id,
        })
        # connect to host by ip
        Host.set_parameter({
            'host': client.hostname,
            'name': 'remote_execution_connect_by_ip',
            'value': 'True',
        })
        hostname = client.hostname
        with session:
            session.organization.select(module_org.name)
            assert session.host.search(hostname)[0]['Name'] == hostname
            session.jobinvocation.run({
                'job_category': 'Commands',
                'job_template': 'Run Command - SSH Default',
                'search_query': 'name ^ {}'.format(hostname),
                'template_content.command': 'ls',
            })
            session.jobinvocation.wait_job_invocation_state(
                entity_name='Run ls', host_name=hostname)
            status = session.jobinvocation.read(
                entity_name='Run ls', host_name=hostname)
            assert status['overview']['hosts_table'][0]['Status'] == 'success'
Пример #21
0
 def setUpClass(cls):
     """Create an organization which can be re-used in tests."""
     super(RemoteExecutionTestCase, cls).setUpClass()
     cls.organization = make_org()
     ssh.command('''echo 'getenforce' > {0}'''.format(TEMPLATE_FILE))
     cls.client = VirtualMachine(distro=DISTRO_RHEL7)
     cls.client.create()
     cls.client.install_katello_ca()
     cls.client.register_contenthost(cls.organization['label'],
                                     lce='Library')
     cls.client.enable_repo(REPOS['rhst7']['id'])
     cls.client.install_katello_agent()
     add_remote_execution_ssh_key(cls.client.hostname)
Пример #22
0
 def setUpClass(cls):
     """Create an organization which can be re-used in tests."""
     super(RemoteExecutionTestCase, cls).setUpClass()
     cls.organization = make_org()
     ssh.command("""echo 'getenforce' > {0}""".format(TEMPLATE_FILE))
     cls.client = VirtualMachine(distro=DISTRO_RHEL7)
     cls.addCleanup(vm_cleanup, cls.client)
     cls.client.create()
     cls.client.install_katello_ca()
     cls.client.register_contenthost(cls.organization["label"], lce="Library")
     cls.client.enable_repo(REPOS["rhst7"]["id"])
     cls.client.install_katello_agent()
     add_remote_execution_ssh_key(cls.client.hostname)
Пример #23
0
    def test_positive_run_scheduled_job_template(self):
        """Schedule a job to be ran against a host

        @id: 35c8b68e-1ac5-4c33-ad62-a939b87f76fb

        @Setup: Use pre-defined job template.

        @Steps:

        1. Navigate to an individual host and click Run Job
        2. Select the job and appropriate template
        3. Select "Schedule Future Job"
        4. Enter a desired time for the job to run
        5. Click submit

        @Assert:

        1. Verify the job was not immediately ran
        2. Verify the job was successfully ran after the designated time

        @CaseLevel: System
        """
        with VirtualMachine(distro='rhel71') as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            add_remote_execution_ssh_key(client.ip_addr)
            with Session(self.browser) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                plan_time = (datetime.now() +
                             timedelta(seconds=90)).strftime("%Y-%m-%d %H:%M")
                status = self.job.run(job_category='Commands',
                                      job_template='Run Command - SSH Default',
                                      options_list=[{
                                          'name': 'command',
                                          'value': 'ls'
                                      }],
                                      schedule='future',
                                      schedule_options=[{
                                          'name': 'start_at',
                                          'value': plan_time
                                      }],
                                      result='queued')
                self.assertTrue(status)
                strategy, value = locators['job_invocation.status']
                self.job.wait_until_element_is_not_visible(
                    (strategy, value % 'queued'), 95)
                self.job.wait_until_element((strategy, value % 'succeeded'),
                                            30)
Пример #24
0
def vm_content_hosts_module_stream(module_loc,
                                   module_repos_collection_module_stream):
    distro = module_repos_collection_module_stream.distro
    with VMBroker(nick=distro, host_classes={'host': ContentHost},
                  _count=2) as clients:
        for client in clients:
            module_repos_collection_module_stream.setup_virtual_machine(
                client, install_katello_agent=False)
            add_remote_execution_ssh_key(client.ip_addr)
            update_vm_host_location(client, module_loc.id)
        smart_proxy = (entities.SmartProxy().search(
            query={'search': f'name={settings.server.hostname}'})[0].read())
        smart_proxy.location.append(entities.Location(id=module_loc.id))
        smart_proxy.update(['location'])
        yield clients
Пример #25
0
    def test_positive_run_default_job_template(self):
        """Run a job template against a single host

        :id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217

        :Setup: Use pre-defined job template.

        :Steps:

            1. Navigate to an individual host and click Run Job
            2. Select the job and appropriate template
            3. Run the job

        :expectedresults: Verify the job was successfully ran against the host

        :CaseLevel: Integration
        """
        with VirtualMachine(
                distro=DISTRO_RHEL7,
                bridge=settings.vlan_networking.bridge
                ) as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            self.assertTrue(client.subscribed)
            add_remote_execution_ssh_key(client.ip_addr)
            Host.update({
                u'name': client.hostname,
                u'subnet-id': self.new_sub['id'],
            })
            with Session(self) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(
                    job_category='Commands',
                    job_template='Run Command - SSH Default',
                    options_list=[{'name': 'command', 'value': 'ls'}]
                )
                # get job invocation id from the current url
                invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                self.assertTrue(
                        status,
                        'host output: {0}'.format(
                            ' '.join(JobInvocation.get_output({
                                'id': invocation_id,
                                'host': client.hostname})
                            )
                        )
                    )
Пример #26
0
def test_positive_install_multiple_in_host(module_org, activation_key,
                                           custom_repo, rh_repo,
                                           rhel7_contenthost):
    """For a host with multiple applicable errata install one and ensure
    the rest of errata is still available

    :id: 67b7e95b-9809-455a-a74e-f1815cc537fc

    :customerscenario: true

    :BZ: 1469800, 1528275

    :expectedresults: errata installation task succeeded, available errata
        counter decreased by one; it's possible to schedule another errata
        installation

    :CaseLevel: System
    """
    rhel7_contenthost.install_katello_ca()
    rhel7_contenthost.register_contenthost(module_org.label,
                                           activation_key.name)
    assert rhel7_contenthost.subscribed
    rhel7_contenthost.enable_repo(constants.REPOS['rhst7']['id'])
    host = rhel7_contenthost.nailgun_host
    for package in constants.FAKE_9_YUM_OUTDATED_PACKAGES:
        _install_package(module_org,
                         clients=[rhel7_contenthost],
                         host_ids=[host.id],
                         package_name=package)
    host = host.read()
    applicable_errata_count = host.content_facet_attributes['errata_counts'][
        'total']
    assert applicable_errata_count > 1
    add_remote_execution_ssh_key(rhel7_contenthost.hostname)
    for errata in constants.FAKE_9_YUM_ERRATUM[:2]:
        entities.JobInvocation().run(data={
            'feature': 'katello_errata_install',
            'inputs': {
                'errata': f'{errata}'
            },
            'targeting_type': 'static_query',
            'search_query': f'name = {rhel7_contenthost.hostname}',
            'organization_id': module_org.id,
        }, )
        host = host.read()
        applicable_errata_count -= 1
        assert host.content_facet_attributes['errata_counts'][
            'total'] == applicable_errata_count
Пример #27
0
def vm_content_hosts_module_stream(module_loc, module_repos_collection_module_stream):
    distro = module_repos_collection_module_stream.distro
    with VirtualMachine(distro=distro) as client1, VirtualMachine(distro=distro) as client2:
        clients = [client1, client2]
        for client in clients:
            module_repos_collection_module_stream.setup_virtual_machine(
                client,
                install_katello_agent=False
            )
            add_remote_execution_ssh_key(client.ip_addr)
            update_vm_host_location(client, module_loc.id)
        smart_proxy = entities.SmartProxy().search(
            query={'search': 'name={0}'.format(settings.server.hostname)})[0].read()
        smart_proxy.location.append(entities.Location(id=module_loc.id))
        smart_proxy.update(['location'])
        yield clients
Пример #28
0
def test_positive_run_capsule_upgrade_playbook():
    """Run Capsule Upgrade playbook against an External Capsule

    :id: 9ec6903d-2bb7-46a5-8002-afc74f06d83b

    :steps:
        1. Create a Capsule VM, add REX key.
        2. Run the Capsule Upgrade Playbook.

    :expectedresults: Capsule is upgraded successfully

    :CaseImportance: Medium
    """
    with CapsuleVirtualMachine() as capsule_vm:
        template_id = (entities.JobTemplate().search(
            query={'search': 'name="Capsule Upgrade Playbook"'})[0].id)

        add_remote_execution_ssh_key(capsule_vm.ip_addr)
        job = entities.JobInvocation().run(
            synchronous=False,
            data={
                'job_template_id': template_id,
                'inputs': {
                    'target_version':
                    CAPSULE_TARGET_VERSION,
                    'whitelist_options':
                    "repositories-validate,repositories-setup",
                },
                'targeting_type': "static_query",
                'search_query': f"name = {capsule_vm.hostname}",
            },
        )
        wait_for_tasks(
            f"resource_type = JobInvocation and resource_id = {job['id']}")
        result = entities.JobInvocation(id=job['id']).read()
        assert result.succeeded == 1

        result = capsule_vm.run('foreman-maintain health check')
        assert result.return_code == 0
        for line in result.stdout:
            assert 'FAIL' not in line

        result = entities.SmartProxy(id=entities.SmartProxy(
            name=capsule_vm.hostname).search()[0].id).refresh()
        feature_list = [feat['name'] for feat in result['features']]
        assert {'Discovery', 'Dynflow', 'Ansible', 'SSH', 'Logs',
                'Pulp'}.issubset(feature_list)
Пример #29
0
    def test_positive_run_scheduled_job_template(self):
        """Schedule a job to be ran against a host

        @id: 35c8b68e-1ac5-4c33-ad62-a939b87f76fb

        @Setup: Use pre-defined job template.

        @Steps:

        1. Navigate to an individual host and click Run Job
        2. Select the job and appropriate template
        3. Select "Schedule Future Job"
        4. Enter a desired time for the job to run
        5. Click submit

        @Assert:

        1. Verify the job was not immediately ran
        2. Verify the job was successfully ran after the designated time

        @CaseLevel: System
        """
        with VirtualMachine(distro='rhel71') as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            add_remote_execution_ssh_key(client.ip_addr)
            with Session(self.browser) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                plan_time = (datetime.now() + timedelta(seconds=90)).strftime(
                    "%Y-%m-%d %H:%M")
                status = self.job.run(
                    job_category='Commands',
                    job_template='Run Command - SSH Default',
                    options_list=[{'name': 'command', 'value': 'ls'}],
                    schedule='future',
                    schedule_options=[
                        {'name': 'start_at', 'value': plan_time}],
                    result='queued'
                )
                self.assertTrue(status)
                strategy, value = locators['job_invocation.status']
                self.job.wait_until_element_is_not_visible(
                    (strategy, value % 'queued'), 95)
                self.job.wait_until_element(
                    (strategy, value % 'succeeded'), 30)
Пример #30
0
def test_positive_install_in_hc(module_org, activation_key, custom_repo,
                                rh_repo):
    """Install errata in a host-collection

    :id: 6f0242df-6511-4c0f-95fc-3fa32c63a064

    :Setup: Errata synced on satellite server.

    :Steps: PUT /api/v2/hosts/bulk/update_content

    :expectedresults: errata is installed in the host-collection.

    :CaseLevel: System
    """
    with VMBroker(nick=DISTRO_RHEL7,
                  host_classes={'host': ContentHost},
                  _count=2) as clients:
        for client in clients:
            client.install_katello_ca()
            client.register_contenthost(module_org.label, activation_key.name)
            assert client.subscribed
            client.enable_repo(constants.REPOS['rhst7']['id'])
            add_remote_execution_ssh_key(client.hostname)
        host_ids = [client.nailgun_host.id for client in clients]
        _install_package(
            module_org,
            clients=clients,
            host_ids=host_ids,
            package_name=constants.FAKE_1_CUSTOM_PACKAGE,
        )
        host_collection = entities.HostCollection(
            organization=module_org).create()
        host_ids = [client.nailgun_host.id for client in clients]
        host_collection.host_ids = host_ids
        host_collection = host_collection.update(['host_ids'])
        entities.JobInvocation().run(
            data={
                'feature': 'katello_errata_install',
                'inputs': {
                    'errata': f'{CUSTOM_REPO_ERRATA_ID}'
                },
                'targeting_type': 'static_query',
                'search_query': f'host_collection_id = {host_collection.id}',
                'organization_id': module_org.id,
            })
        _validate_package_installed(clients, constants.FAKE_2_CUSTOM_PACKAGE)
Пример #31
0
def test_negative_run_capsule_upgrade_playbook_on_satellite(default_org):
    """Run Capsule Upgrade playbook against the Satellite itself

    :id: 99462a11-5133-415d-ba64-4354da539a34

    :steps:
        1. Add REX key to the Satellite server.
        2. Run the Capsule Upgrade Playbook.
        3. Check the job output for proper failure reason.

    :expectedresults: Should fail

    :CaseImportance: Medium
    """
    sat = entities.Host().search(
        query={'search': f'name={settings.server.hostname}'})[0].read()
    template_id = (entities.JobTemplate().search(
        query={'search': 'name="Capsule Upgrade Playbook"'})[0].id)

    add_remote_execution_ssh_key(sat.name)
    with pytest.raises(TaskFailedError) as error:
        entities.JobInvocation().run(
            data={
                'job_template_id': template_id,
                'inputs': {
                    'target_version':
                    CAPSULE_TARGET_VERSION,
                    'whitelist_options':
                    "repositories-validqqate,repositories-setup",
                },
                'targeting_type': "static_query",
                'search_query': f"name = {sat.name}",
            })
    assert 'A sub task failed' in error.value.args[0]
    job = entities.JobInvocation().search(
        query={
            'search':
            f'host={sat.name},status=failed,description="Capsule Upgrade Playbook"'
        })[0]
    response = client.get(
        f'https://{sat.name}/api/job_invocations/{job.id}/hosts/{sat.id}',
        auth=get_credentials(),
        verify=False,
    )
    assert 'This playbook cannot be executed on a Satellite server.' in response.text
Пример #32
0
def fixture_vmsetup(request, module_org):
    """Create Org, Lifecycle Environment, Content View, Activation key,
    VM, install katello-ca, register it, add remote execution key
    """
    # Create VM and register content host
    with VMBroker(nick=request.param, host_classes={'host': ContentHost}) as client:
        client.install_katello_ca()
        client.register_contenthost(org=module_org.label, lce='Library')
        assert client.subscribed
        add_remote_execution_ssh_key(client.ip_addr)
        Host.set_parameter(
            {
                'host': client.hostname,
                'name': 'remote_execution_connect_by_ip',
                'value': 'True',
            }
        )
        yield client
Пример #33
0
    def test_positive_run_custom_job_template(self):
        """Run a job template against a single host

        @id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217

        @Setup: Create a working job template.

        @Steps:

        1. Navigate to an individual host and click Run Job
        2. Select the job and appropriate template
        3. Run the job

        @Assert: Verify the job was successfully ran against the host

        @CaseLevel: System
        """
        jobs_template_name = gen_string('alpha')
        with VirtualMachine(distro='rhel71') as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            add_remote_execution_ssh_key(client.ip_addr)
            with Session(self.browser) as session:
                set_context(session, org=self.organization.name)
                make_job_template(
                    session,
                    name=jobs_template_name,
                    template_type='input',
                    template_content='<%= input("command") %>',
                    provider_type='SSHExecutionProvider',
                )
                self.assertIsNotNone(
                    self.jobtemplate.search(jobs_template_name))
                self.jobtemplate.add_input(jobs_template_name,
                                           'command',
                                           required=True)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(job_category='Miscellaneous',
                                      job_template=jobs_template_name,
                                      options_list=[{
                                          'name': 'command',
                                          'value': 'ls'
                                      }])
                self.assertTrue(status)
Пример #34
0
    def test_positive_run_default_job_template_multiple_hosts_by_ip(self):
        """Run default job template against multiple hosts by ip

        :id: 694a21d3-243b-4296-8bd0-4bad9663af15

        :expectedresults: Verify the job was successfully ran against all hosts
        """
        Host.set_parameter({
            'host': self.client.hostname,
            'name': 'remote_execution_connect_by_ip',
            'value': 'True',
        })
        with VirtualMachine(
              distro=DISTRO_RHEL7,
              provisioning_server=settings.compute_resources.libvirt_hostname,
              bridge=settings.vlan_networking.bridge,
              ) as client2:
            client2.install_katello_ca()
            client2.register_contenthost(
                    self.org['label'], lce='Library')
            add_remote_execution_ssh_key(client2.ip_addr)
            Host.set_parameter({
                'host': client2.hostname,
                'name': 'remote_execution_connect_by_ip',
                'value': 'True',
            })
            invocation_command = make_job_invocation({
                'job-template': 'Run Command - SSH Default',
                'inputs': 'command="ls"',
                'search-query': "name ~ {0} or name ~ {1}".format(
                    self.client.hostname, client2.hostname),
            })
            # collect output messages from clients
            output_msgs = []
            for vm in self.client, client2:
                output_msgs.append('host output from {0}: {1}'.format(
                        vm.hostname,
                        ' '.join(JobInvocation.get_output({
                            'id': invocation_command[u'id'],
                            'host': vm.hostname})
                        )
                    )
                )
            self.assertEqual(invocation_command['success'], u'2', output_msgs)
Пример #35
0
    def test_positive_run_default_job_template(self):
        """Run a job template against a single host

        :id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217

        :Setup: Use pre-defined job template.

        :Steps:

            1. Navigate to an individual host and click Run Job
            2. Select the job and appropriate template
            3. Run the job

        :expectedresults: Verify the job was successfully ran against the host

        :CaseLevel: Integration
        """
        with VirtualMachine(distro=DISTRO_RHEL7,
                            bridge=settings.vlan_networking.bridge) as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            self.assertTrue(client.subscribed)
            add_remote_execution_ssh_key(client.ip_addr)
            Host.update({
                u'name': client.hostname,
                u'subnet-id': self.new_sub['id'],
            })
            with Session(self) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(job_category='Commands',
                                      job_template='Run Command - SSH Default',
                                      options_list=[{
                                          'name': 'command',
                                          'value': 'ls'
                                      }])
                # get job invocation id from the current url
                invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                self.assertTrue(
                    status, 'host output: {0}'.format(' '.join(
                        JobInvocation.get_output({
                            'id': invocation_id,
                            'host': client.hostname
                        }))))
Пример #36
0
def _setup_vm_client_host(vm_client, org_label, subnet_id=None, by_ip=True):
    """Setup a VM host for remote execution.

    :param VMBroker vm_client: where vm_client is VMBroker instance.
    :param str org_label: The organization label.
    :param int subnet: (Optional) Nailgun subnet entity id, to be used by the vm_client host.
    :param bool by_ip: Whether remote execution will use ip or host name to access server.
    """
    vm_client.install_katello_ca()
    vm_client.register_contenthost(org_label, lce='Library')
    assert vm_client.subscribed
    add_remote_execution_ssh_key(vm_client.ip_addr)
    if subnet_id is not None:
        Host.update({'name': vm_client.hostname, 'subnet-id': subnet_id})
    if by_ip:
        # connect to host by ip
        Host.set_parameter(
            {'host': vm_client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True'}
        )
Пример #37
0
 def setUp(self):
     """Create VM, subscribe it to satellite-tools repo, install katello-ca
     and katello-agent packages, add remote execution key
     """
     super(RemoteExecutionTestCase, self).setUp()
     # Create VM and register content host
     self.client = VirtualMachine(distro=DISTRO_RHEL7)
     self.addCleanup(vm_cleanup, self.client)
     self.client.create()
     self.client.install_katello_ca()
     # Register content host, install katello-agent
     self.client.register_contenthost(
         self.org['label'],
         self.activation_key['name'],
     )
     if settings.cdn:
         self.client.enable_repo(REPOS['rhst7']['id'])
     self.client.install_katello_agent()
     add_remote_execution_ssh_key(self.client.ip_addr)
Пример #38
0
    def test_positive_run_custom_job_template(self):
        """Run a job template against a single host

        @id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217

        @Setup: Create a working job template.

        @Steps:

        1. Navigate to an individual host and click Run Job
        2. Select the job and appropriate template
        3. Run the job

        @Assert: Verify the job was successfully ran against the host

        @CaseLevel: System
        """
        jobs_template_name = gen_string('alpha')
        with VirtualMachine(distro='rhel71') as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            add_remote_execution_ssh_key(client.ip_addr)
            with Session(self.browser) as session:
                set_context(session, org=self.organization.name)
                make_job_template(
                    session,
                    name=jobs_template_name,
                    template_type='input',
                    template_content='<%= input("command") %>',
                    provider_type='SSHExecutionProvider',
                )
                self.assertIsNotNone(
                    self.jobtemplate.search(jobs_template_name))
                self.jobtemplate.add_input(
                    jobs_template_name, 'command', required=True)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(
                    job_category='Miscellaneous',
                    job_template=jobs_template_name,
                    options_list=[{'name': 'command', 'value': 'ls'}]
                )
                self.assertTrue(status)
Пример #39
0
def fixture_vmsetup(request, fixture_org):
    """Create Org, Lifecycle Environment, Content View, Activation key,
    VM, install katello-ca, register it, add remote execution key
    """
    # Create VM and register content host
    client = VirtualMachine(distro=request.param)
    try:
        client.create()
        if request.param in [DISTRO_SLES11, DISTRO_SLES12]:
            # SLES hostname in subscription-manager facts doesn't include domain
            client._hostname = client.hostname.split(".")[0]
        client.install_katello_ca()
        # Register content host
        client.register_contenthost(org=fixture_org.label, lce='Library')
        assert client.subscribed
        add_remote_execution_ssh_key(client.ip_addr)
        yield client
    finally:
        client._hostname = None
        client.destroy()
Пример #40
0
 def setUp(self):
     """Create VM, subscribe it to satellite-tools repo, install katello-ca
         and katello-agent packages, add remote execution key
     """
     super(RemoteExecutionTestCase, self).setUp()
     # Create VM and register content host
     self.client = VirtualMachine(
         distro=DISTRO_RHEL7,
         provisioning_server=settings.compute_resources.libvirt_hostname,
         bridge=settings.vlan_networking.bridge)
     self.addCleanup(vm_cleanup, self.client)
     self.client.create()
     self.client.install_katello_ca()
     # Register content host, install katello-agent
     self.client.register_contenthost(
         self.org['label'],
         self.activation_key['name'],
     )
     self.assertTrue(self.client.subscribed)
     self.client.enable_repo(REPOS['rhst7']['id'])
     self.client.install_katello_agent()
     add_remote_execution_ssh_key(self.client.ip_addr)
     # create subnet for current org, default loc and domain
     subnet_options = {
         u'domain-ids': 1,
         u'organization-ids': self.org["id"],
         u'location-ids': 2
        }
     if not bz_bug_is_open(1328322):
         subnet_options[u'remote-execution-proxy-id'] = 1
     new_sub = make_subnet(subnet_options)
     # add rex proxy to subnet, default is internal proxy (id 1)
     if bz_bug_is_open(1328322):
         subnet = entities.Subnet(id=new_sub["id"])
         subnet.remote_execution_proxy_ids = [1]
         subnet.update(["remote_execution_proxy_ids"])
     # add host to subnet
     Host.update({
         'name': self.client.hostname,
         'subnet-id': new_sub['id'],
     })
Пример #41
0
 def setUp(self):
     """Create VM, install katello-ca, register it, add remote execution key
     """
     super(RemoteExecutionTestCase, self).setUp()
     # Create VM and register content host
     self.client = VirtualMachine(
         distro=DISTRO_RHEL7,
         provisioning_server=settings.compute_resources.libvirt_hostname,
         bridge=settings.vlan_networking.bridge)
     self.addCleanup(vm_cleanup, self.client)
     self.client.create()
     self.client.install_katello_ca()
     # Register content host
     self.client.register_contenthost(org=self.org.label, lce='Library')
     self.assertTrue(self.client.subscribed)
     add_remote_execution_ssh_key(self.client.ip_addr)
     # add host to subnet
     Host.update({
         'name': self.client.hostname,
         'subnet-id': self.sn.id,
     })
Пример #42
0
def test_positive_install_in_host(
    module_org, activation_key, custom_repo, rh_repo, rhel7_contenthost
):
    """Install errata in a host

    :id: 1e6fc159-b0d6-436f-b945-2a5731c46df5

    :Setup: Errata synced on satellite server.

    :Steps: POST /api/v2/job_invocations/{hash}

    :expectedresults: errata is installed in the host.

    :CaseLevel: System

    :BZ: 1983043
    """
    rhel7_contenthost.install_katello_ca()
    rhel7_contenthost.register_contenthost(module_org.label, activation_key.name)
    assert rhel7_contenthost.subscribed
    rhel7_contenthost.enable_repo(constants.REPOS['rhst7']['id'])
    host_id = rhel7_contenthost.nailgun_host.id
    _install_package(
        module_org,
        clients=[rhel7_contenthost],
        host_ids=[host_id],
        package_name=constants.FAKE_1_CUSTOM_PACKAGE,
    )
    add_remote_execution_ssh_key(rhel7_contenthost.hostname)
    entities.JobInvocation().run(
        data={
            'feature': 'katello_errata_install',
            'inputs': {'errata': f'{CUSTOM_REPO_ERRATA_ID}'},
            'targeting_type': 'static_query',
            'search_query': f'name = {rhel7_contenthost.hostname}',
            'organization_id': module_org.id,
        },
    )
    _validate_package_installed([rhel7_contenthost], constants.FAKE_2_CUSTOM_PACKAGE)
Пример #43
0
    def test_positive_run_job_template_multiple_hosts(self):
        """Run a job template against multiple hosts

        @id: 7f1981cb-afcc-49b7-a565-7fef9aa8ddde

        @Setup: Create a working job template.

        @Steps:

        1. Navigate to the hosts page and select at least two hosts
        2. Click the "Select Action"
        3. Select the job and appropriate template
        4. Run the job

        @Assert: Verify the job was successfully ran against the hosts

        @CaseLevel: System
        """
        with VirtualMachine(distro='rhel71') as client:
            with VirtualMachine(distro='rhel71') as client2:
                for vm in client, client2:
                    vm.install_katello_ca()
                    vm.register_contenthost(self.organization.label,
                                            lce='Library')
                    add_remote_execution_ssh_key(vm.ip_addr)
                with Session(self.browser) as session:
                    set_context(session, org=self.organization.name)
                    self.hosts.navigate_to_entity()
                    self.hosts.update_host_bulkactions(
                        [client.hostname, client2.hostname],
                        action='Run Job',
                        parameters_list=[{
                            'command': 'ls'
                        }],
                    )
                    strategy, value = locators['job_invocation.status']
                    self.job.wait_until_element(
                        (strategy, value % 'succeeded'), 240)
def fixture_vmsetup(request, fixture_org):
    """Create Org, Lifecycle Environment, Content View, Activation key,
    VM, install katello-ca, register it, add remote execution key
    """
    # Create VM and register content host
    client = VirtualMachine(distro=request.param)
    try:
        client.create()
        if request.param in [DISTRO_SLES11, DISTRO_SLES12]:
            # SLES hostname in subscription-manager facts doesn't include domain
            client._hostname = client.hostname.split(".")[0]
        client.install_katello_ca()
        # Register content host
        client.register_contenthost(
            org=fixture_org.label,
            lce='Library'
        )
        assert client.subscribed
        add_remote_execution_ssh_key(client.ip_addr)
        yield client
    finally:
        client._hostname = None
        client.destroy()
Пример #45
0
    def test_positive_run_job_template_multiple_hosts(self):
        """Run a job template against multiple hosts

        @id: 7f1981cb-afcc-49b7-a565-7fef9aa8ddde

        @Setup: Create a working job template.

        @Steps:

        1. Navigate to the hosts page and select at least two hosts
        2. Click the "Select Action"
        3. Select the job and appropriate template
        4. Run the job

        @Assert: Verify the job was successfully ran against the hosts

        @CaseLevel: System
        """
        with VirtualMachine(distro='rhel71') as client:
            with VirtualMachine(distro='rhel71') as client2:
                for vm in client, client2:
                    vm.install_katello_ca()
                    vm.register_contenthost(
                        self.organization.label, lce='Library')
                    add_remote_execution_ssh_key(vm.ip_addr)
                with Session(self.browser) as session:
                    set_context(session, org=self.organization.name)
                    self.hosts.navigate_to_entity()
                    self.hosts.update_host_bulkactions(
                        [client.hostname, client2.hostname],
                        action='Run Job',
                        parameters_list=[{'command': 'ls'}],
                    )
                    strategy, value = locators['job_invocation.status']
                    self.job.wait_until_element(
                        (strategy, value % 'succeeded'), 240)
Пример #46
0
 def setUp(self):
     """Create VM, install katello-ca, register it, add remote execution key
     """
     super(RemoteExecutionTestCase, self).setUp()
     # Create VM and register content host
     self.client = VirtualMachine(
         distro=DISTRO_RHEL7,
         provisioning_server=settings.compute_resources.libvirt_hostname,
         bridge=settings.vlan_networking.bridge)
     self.addCleanup(vm_cleanup, self.client)
     self.client.create()
     self.client.install_katello_ca()
     # Register content host
     self.client.register_contenthost(
         org=self.org.label,
         lce='Library'
     )
     self.assertTrue(self.client.subscribed)
     add_remote_execution_ssh_key(self.client.ip_addr)
     # add host to subnet
     Host.update({
         'name': self.client.hostname,
         'subnet-id': self.sn.id,
     })
    def test_positive_run_job_template_multiple_hosts_by_ip(self):
        """Run a job template against multiple hosts by ip

        :id: c4439ec0-bb80-47f6-bc31-fa7193bfbeeb

        :Setup: Create a working job template.

        :Steps:

            1. Set remote_execution_connect_by_ip on hosts to true
            2. Navigate to the hosts page and select at least two hosts
            3. Click the "Select Action"
            4. Select the job and appropriate template
            5. Run the job

        :expectedresults: Verify the job was successfully ran against the hosts

        :CaseLevel: System
        """
        prov_server = settings.compute_resources.libvirt_hostname
        with VirtualMachine(
              distro=DISTRO_RHEL7,
              provisioning_server=prov_server,
              bridge=settings.vlan_networking.bridge,
              ) as client:
            with VirtualMachine(
                  distro=DISTRO_RHEL7,
                  provisioning_server=prov_server,
                  bridge=settings.vlan_networking.bridge,
                  ) as client2:
                for vm in client, client2:
                    vm.install_katello_ca()
                    vm.register_contenthost(
                        self.organization.label, lce='Library')
                    self.assertTrue(vm.subscribed)
                    add_remote_execution_ssh_key(vm.ip_addr)
                    Host.update({
                        'name': vm.hostname,
                        'subnet-id': self.new_sub.id,
                    })
                    # connect to host by ip
                    Host.set_parameter({
                        'host': vm.hostname,
                        'name': 'remote_execution_connect_by_ip',
                        'value': 'True',
                    })
                with Session(self) as session:
                    set_context(session, org=self.organization.name)
                    self.hosts.update_host_bulkactions(
                        [client.hostname, client2.hostname],
                        action='Schedule Remote Job',
                        parameters_list=[{'command': 'ls'}],
                    )
                    strategy, value = locators['job_invocation.status']
                    if self.job.wait_until_element(
                            (strategy, value % 'succeeded'), 240) is not None:
                        status = True
                    else:
                        status = False
                    # get job invocation id from the current url
                    invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                    try:
                        self.assertTrue(status)
                    except AssertionError:
                        result = 'host output: {0}'.format(
                                ' '.join(JobInvocation.get_output({
                                     'id': invocation_id,
                                     'host': client.hostname})
                                )
                            )
                        raise AssertionError(result)
    def test_positive_run_custom_job_template_by_ip(self):
        """Run a job template on a host connected by ip

        :id: e283ae09-8b14-4ce1-9a76-c1bbd511d58c

        :Setup: Create a working job template.

        :Steps:

            1. Set remote_execution_connect_by_ip on host to true
            2. Navigate to an individual host and click Run Job
            3. Select the job and appropriate template
            4. Run the job

        :expectedresults: Verify the job was successfully ran against the host

        :CaseLevel: System
        """
        jobs_template_name = gen_string('alpha')
        with VirtualMachine(
              distro=DISTRO_RHEL7,
              provisioning_server=settings.compute_resources.libvirt_hostname,
              bridge=settings.vlan_networking.bridge,
              ) as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            self.assertTrue(client.subscribed)
            add_remote_execution_ssh_key(client.ip_addr)
            Host.update({
                'name': client.hostname,
                'subnet-id': self.new_sub.id,
            })
            # connect to host by ip
            Host.set_parameter({
                'host': client.hostname,
                'name': 'remote_execution_connect_by_ip',
                'value': 'True',
            })
            with Session(self) as session:
                set_context(session, org=self.organization.name)
                make_job_template(
                    session,
                    name=jobs_template_name,
                    template_type='input',
                    template_content='<%= input("command") %>',
                    provider_type='SSH',
                )
                self.assertIsNotNone(
                    self.jobtemplate.search(jobs_template_name))
                self.jobtemplate.add_input(
                    jobs_template_name, 'command', required=True)
                self.hosts.click(self.hosts.search(client.hostname))
                status = self.job.run(
                    job_category='Miscellaneous',
                    job_template=jobs_template_name,
                    options_list=[{'name': 'command', 'value': 'ls'}]
                )
                # get job invocation id from the current url
                invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                try:
                    self.assertTrue(status)
                except AssertionError:
                    result = 'host output: {0}'.format(
                            ' '.join(JobInvocation.get_output({
                                'id': invocation_id,
                                'host': client.hostname})
                            )
                        )
                    raise AssertionError(result)
Пример #49
0
    def test_positive_run_scheduled_job_template(self):
        """Schedule a job to be ran against a host

        :id: 35c8b68e-1ac5-4c33-ad62-a939b87f76fb

        :Setup: Use pre-defined job template.

        :Steps:

            1. Navigate to an individual host and click Run Job
            2. Select the job and appropriate template
            3. Select "Schedule Future Job"
            4. Enter a desired time for the job to run
            5. Click submit

        :expectedresults:

            1. Verify the job was not immediately ran
            2. Verify the job was successfully ran after the designated time

        :CaseLevel: System
        """
        with VirtualMachine(
                distro=DISTRO_RHEL7,
                bridge=settings.vlan_networking.bridge
                ) as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            self.assertTrue(client.subscribed)
            add_remote_execution_ssh_key(client.ip_addr)
            Host.update({
                u'name': client.hostname,
                u'subnet-id': self.new_sub['id'],
            })
            with Session(self) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                plan_time = (
                        self.get_client_datetime() + timedelta(seconds=90)
                        ).strftime("%Y-%m-%d %H:%M")
                status = self.job.run(
                    job_category='Commands',
                    job_template='Run Command - SSH Default',
                    options_list=[{'name': 'command', 'value': 'ls'}],
                    schedule='future',
                    schedule_options=[
                        {'name': 'start_at', 'value': plan_time}],
                    result='queued'
                )
                self.assertTrue(status)
                strategy, value = locators['job_invocation.status']
                self.job.wait_until_element_is_not_visible(
                    (strategy, value % 'queued'), 95)
                if self.job.wait_until_element(
                        (strategy, value % 'succeeded'), 180) is not None:
                    status2 = True
                else:
                    status2 = False
                # get job invocation id from the current url
                invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                self.assertTrue(
                        status2,
                        'host output: {0}'.format(
                            ' '.join(JobInvocation.get_output({
                                'id': invocation_id,
                                'host': client.hostname})
                            )
                        )
                    )
    def test_positive_run_scheduled_job_template_by_ip(self):
        """Schedule a job to be ran against a host by ip

        :id: 4387bed9-969d-45fb-80c2-b0905bb7f1bd

        :Setup: Use pre-defined job template.

        :Steps:

            1. Set remote_execution_connect_by_ip on host to true
            2. Navigate to an individual host and click Run Job
            3. Select the job and appropriate template
            4. Select "Schedule Future Job"
            5. Enter a desired time for the job to run
            6. Click submit

        :expectedresults:

            1. Verify the job was not immediately ran
            2. Verify the job was successfully ran after the designated time

        :CaseLevel: System
        """
        with VirtualMachine(
              distro=DISTRO_RHEL7,
              provisioning_server=settings.compute_resources.libvirt_hostname,
              bridge=settings.vlan_networking.bridge,
              ) as client:
            client.install_katello_ca()
            client.register_contenthost(self.organization.label, lce='Library')
            self.assertTrue(client.subscribed)
            add_remote_execution_ssh_key(client.ip_addr)
            Host.update({
                'name': client.hostname,
                'subnet-id': self.new_sub.id,
            })
            # connect to host by ip
            Host.set_parameter({
                'host': client.hostname,
                'name': 'remote_execution_connect_by_ip',
                'value': 'True',
            })
            with Session(self) as session:
                set_context(session, org=self.organization.name)
                self.hosts.click(self.hosts.search(client.hostname))
                plan_time = (
                        self.get_client_datetime() + timedelta(seconds=180)
                        ).strftime("%Y-%m-%d %H:%M")
                status = self.job.run(
                    job_category='Commands',
                    job_template='Run Command - SSH Default',
                    options_list=[{'name': 'command', 'value': 'ls'}],
                    schedule='future',
                    schedule_options=[
                        {'name': 'start_at', 'value': plan_time}],
                    result='queued to start executing in 1 minute'
                )
                self.assertTrue(status)
                strategy, value = locators['job_invocation.status']
                self.job.wait_until_element_is_not_visible(
                    (strategy, value % 'queued'), 95)
                if self.job.wait_until_element(
                        (strategy, value % 'succeeded'), 180) is not None:
                    status2 = True
                else:
                    status2 = False
                # get job invocation id from the current url
                invocation_id = self.browser.current_url.rsplit('/', 1)[-1]
                try:
                    self.assertTrue(status2)
                except AssertionError:
                    result = 'host output: {0}'.format(
                            ' '.join(JobInvocation.get_output({
                                'id': invocation_id,
                                'host': client.hostname})
                            )
                        )
                    raise AssertionError(result)
Пример #51
0
def test_positive_run_custom_job_template_by_ip(
        session, module_org, module_subnet):
    """Run a job template on a host connected by ip

    :id: e283ae09-8b14-4ce1-9a76-c1bbd511d58c

    :Setup: Create a working job template.

    :Steps:

        1. Set remote_execution_connect_by_ip on host to true
        2. Navigate to an individual host and click Run Job
        3. Select the job and appropriate template
        4. Run the job

    :expectedresults: Verify the job was successfully ran against the host

    :CaseLevel: System
    """
    with VirtualMachine(
            distro=DISTRO_RHEL6,
            provisioning_server=settings.compute_resources.libvirt_hostname,
            bridge=settings.vlan_networking.bridge,
    ) as client:
        client.install_katello_ca()
        client.register_contenthost(module_org.label, lce='Library')
        assert client.subscribed
        add_remote_execution_ssh_key(client.ip_addr)
        Host.update({
            'name': client.hostname,
            'subnet-id': module_subnet.id,
        })
        # connect to host by ip
        Host.set_parameter({
            'host': client.hostname,
            'name': 'remote_execution_connect_by_ip',
            'value': 'True',
        })
        hostname = client.hostname
        job_template_name = gen_string('alpha')
        with session:
            session.organization.select(module_org.name)
            assert session.host.search(hostname)[0]['Name'] == hostname
            session.jobtemplate.create({
                'template.name': job_template_name,
                'template.template_editor.rendering_options': 'Input',
                'template.template_editor.editor': '<%= input("command") %>',
                'job.provider_type': 'SSH',
                'inputs': [{
                    'name': 'command',
                    'required': True,
                    'input_type': 'User input',
                }],
            })
            assert session.jobtemplate.search(
                job_template_name)[0]['Name'] == job_template_name
            session.jobinvocation.run({
                'job_category': 'Miscellaneous',
                'job_template': job_template_name,
                'search_query': 'name ^ {}'.format(hostname),
                'template_content.command': 'ls',
            })
            job_description = '{0} with inputs command="ls"'.format(
                     camelize(job_template_name.lower()))
            session.jobinvocation.wait_job_invocation_state(
                entity_name=job_description,
                host_name=hostname
            )
            status = session.jobinvocation.read(
                entity_name=job_description,
                host_name=hostname
            )
            assert status['overview']['hosts_table'][0]['Status'] == 'success'