Exemple #1
0
def test_positive_generate_report_nofilter_and_with_filter():
    """Generate Host Status report without filter and with filter

    :id: 5af03399-b918-468a-9306-1c76dda6a369

    :setup: User with reporting access rights, some report template, at least two hosts

    :steps:

        0. use default report template called Host - Statuses
        1. hammer report-template generate --id ... # do not specify any filter
        2. hammer report-template generate --id ... # specify filter

    :expectedresults: nofilter - Report is generated for all hosts visible for user
                      filter   - Report is generated for the host specified by the filter

    :CaseImportance: Critical
    """
    host_name = gen_alpha()
    host1 = make_fake_host({'name': host_name})

    host_name_2 = gen_alpha()
    host2 = make_fake_host({'name': host_name_2})

    result_list = ReportTemplate.list()
    assert 'Host - Statuses' in [rt['name'] for rt in result_list]

    rt_host_statuses = ReportTemplate.info({'name': 'Host - Statuses'})
    result_no_filter = ReportTemplate.generate(
        {'name': rt_host_statuses['name']})

    assert host1['name'] in [
        item.split(',')[0] for item in result_no_filter.splitlines()
    ]
    assert host2['name'] in [
        item.split(',')[0] for item in result_no_filter.splitlines()
    ]

    result = ReportTemplate.generate({
        'name':
        rt_host_statuses['name'],
        'inputs': (rt_host_statuses['template-inputs'][0]['name'] + '=' +
                   f'name={host1["name"]}'),
    })
    assert host1['name'] in [
        item.split(',')[0] for item in result.splitlines()
    ]
    assert host2['name'] not in [
        item.split(',')[0] for item in result.splitlines()
    ]
Exemple #2
0
    def test_positive_generate_with_name_and_org(self):
        """Generate Host Status report, specifying template name and organization

        :id: 5af03399-b918-468a-1306-1c76dda6f369

        :setup: User with reporting access rights, some report template, some host

        :steps:

            0. use default report template called Host statuses
            1. hammer report-template generate --name ... --organization ...

        :expectedresults: Report successfully generated (in BZ, it results in
            "ERF42-5227 [Foreman::Exception]: unknown parent permission for
            api/v2/report_templates#generate")

        :CaseImportance: Medium

        :BZ: 1750924
        """
        host_name = gen_string('alpha')
        host = make_fake_host({'name': host_name})

        result = ReportTemplate.generate({
            'name': 'Host statuses',
            'organization': DEFAULT_ORG
        })

        self.assertIn(host['name'], [item.split(',')[0] for item in result])
    def test_positive_add_host(self):
        """Check if host can be added to Host Collection

        @id: 80824c9f-15a1-4f76-b7ac-7d9ca9f6ed9e

        @Assert: Host is added to Host Collection successfully

        @CaseLevel: System
        """
        name = gen_string('alpha')
        cv = entities.ContentView(organization=self.organization).create()
        lce = entities.LifecycleEnvironment(
            organization=self.organization).create()
        cv.publish()
        promote(cv.read().version[0], lce.id)
        new_system = make_fake_host({
            u'content-view-id': cv.id,
            u'lifecycle-environment-id': lce.id,
            u'name': gen_string('alpha'),
            u'organization-id': self.organization.id,
        })
        with Session(self.browser) as session:
            make_host_collection(
                session, org=self.organization.name, name=name)
            self.hostcollection.add_host(name, new_system['name'])
Exemple #4
0
    def test_positive_add_host(self):
        """Check if host can be added to Host Collection

        :id: 80824c9f-15a1-4f76-b7ac-7d9ca9f6ed9e

        :expectedresults: Host is added to Host Collection successfully

        :CaseLevel: System
        """
        name = gen_string('alpha')
        cv = entities.ContentView(organization=self.organization).create()
        lce = entities.LifecycleEnvironment(
            organization=self.organization).create()
        cv.publish()
        promote(cv.read().version[0], lce.id)
        new_system = make_fake_host({
            u'content-view-id': cv.id,
            u'lifecycle-environment-id': lce.id,
            u'name': gen_string('alpha'),
            u'organization-id': self.organization.id,
        })
        with Session(self.browser) as session:
            make_host_collection(session,
                                 org=self.organization.name,
                                 name=name)
            self.hostcollection.add_host(name, new_system['name'])
Exemple #5
0
    def test_positive_generate_report_nofilter_and_with_filter(self):
        """Generate Host Status report without filter and with filter

        :id: 5af03399-b918-468a-9306-1c76dda6a369

        :setup: User with reporting access rights, some report template, at least two hosts

        :steps:

            0. use default report template called Host statuses
            1. hammer report-template generate --id ... # do not specify any filter
            2. hammer report-template generate --id ... # specify filter

        :expectedresults: nofilter - Report is generated for all hosts visible for user
                          filter   - Report is generated for the host specified by the filter

        :CaseImportance: Critical
        """
        host_name = gen_string('alpha')
        host1 = make_fake_host({'name': host_name})

        host_name_2 = gen_string('alpha')
        host2 = make_fake_host({'name': host_name_2})

        result_list = ReportTemplate.list()
        self.assertIn('Host statuses', [rt['name'] for rt in result_list])

        rt_host_statuses = ReportTemplate.info({'name': 'Host statuses'})
        result_no_filter = ReportTemplate.generate({
            'name':
            rt_host_statuses['name'],
        })

        self.assertIn(host1['name'],
                      [item.split(',')[0] for item in result_no_filter])
        self.assertIn(host2['name'],
                      [item.split(',')[0] for item in result_no_filter])

        result = ReportTemplate.generate({
            'name':
            rt_host_statuses['name'],
            'inputs': (rt_host_statuses['template-inputs'][0]['name'] + "=" +
                       'name={0}'.format(host1['name']))
        })
        self.assertIn(host1['name'], [item.split(',')[0] for item in result])
        self.assertNotIn(host2['name'],
                         [item.split(',')[0] for item in result])
 def _make_fake_host_helper(self):
     """Make a new fake host"""
     return make_fake_host({
         u'content-view-id': self.default_cv['id'],
         u'lifecycle-environment-id': self.library['id'],
         u'name': gen_string('alpha', 15),
         u'organization-id': self.org['id'],
     })
Exemple #7
0
 def _make_fake_host_helper(self):
     """Make a new fake host"""
     return make_fake_host({
         'content-view-id': self.default_cv['id'],
         'lifecycle-environment-id': self.library['id'],
         'name': gen_string('alpha', 15),
         'organization-id': self.organization['id'],
     })
Exemple #8
0
    def test_positive_generate_ansible_template(self):
        """Report template named 'Ansible Inventory' (default name is specified in settings)
        must be present in Satellite 6.7 and later in order to provide enhanced functionality
        for Ansible Tower inventory synchronization with Satellite.

        :id: f1f7adfc-9601-4498-95c8-3e82e2b36583

        :setup:
            1. A user with minimal required permissions: 'Ansible Tower Inventory Reader' role
            2. A fake host to be checked in report output

        :steps:
            1. Check settings for default Ansible Inventory template name and ensure
               the template is present
            2. Try to render the template using the user with ATIR role
            3. Check the fake host is present in the output

        :expectedresults: Report template is present, renederable and provides output

        :CaseImportance: Medium
        """
        settings = Settings.list({'search': 'name=ansible_inventory_template'})
        assert 1 == len(settings)
        template_name = settings[0]['value']

        report_list = ReportTemplate.list()
        assert template_name in [rt['name'] for rt in report_list]

        login = gen_string('alpha').lower()
        password = gen_string('alpha').lower()
        loc = Location.info({'name': DEFAULT_LOC})
        org = Org.info({'name': DEFAULT_ORG})

        user = make_user(
            {
                'login': login,
                'password': password,
                'organization-ids': org['id'],
                'location-ids': loc['id'],
            }
        )

        User.add_role({'login': user['login'], 'role': 'Ansible Tower Inventory Reader'})

        host_name = gen_string('alpha').lower()
        host = make_fake_host({'name': host_name})

        schedule = ReportTemplate.with_user(username=user['login'], password=password).schedule(
            {'name': template_name}
        )

        report_data = ReportTemplate.with_user(
            username=user['login'], password=password
        ).report_data({'id': template_name, 'job-id': schedule[0].split("Job ID: ", 1)[1]})

        assert host['name'] in [item.split(',')[1] for item in report_data if len(item) > 0]
def _make_fake_host_helper(module_org):
    """Make a new fake host"""
    library = LifecycleEnvironment.info({'organization-id': module_org.id, 'name': ENVIRONMENT})
    default_cv = ContentView.info({'organization-id': module_org.id, 'name': DEFAULT_CV})
    return make_fake_host(
        {
            'content-view-id': default_cv['id'],
            'lifecycle-environment-id': library['id'],
            'name': gen_string('alpha', 15),
            'organization-id': module_org.id,
        }
    )
Exemple #10
0
    def test_positive_generate_report_sanitized(self):
        """Generate report template where there are values in comma outputted
        which might brake CSV format

        :id: 84b577db-144e-4961-a42e-e93887464986

        :setup: User with reporting access rights, Host Statuses report,
                a host with OS that has comma in its name

        :steps:

            1. hammer report-template generate ...

        :expectedresults: Report is generated in proper CSV format (value with comma is quoted)

        :CaseImportance: Medium
        """
        os_name = gen_string('alpha') + "," + gen_string('alpha')
        architecture = make_architecture()
        partition_table = make_partition_table()
        medium = make_medium()
        os = make_os({
            'name': os_name,
            'architecture-ids': architecture['id'],
            'medium-ids': medium['id'],
            'partition-table-ids': partition_table['id'],
        })

        host_name = gen_string('alpha')
        host = make_fake_host({
            'name': host_name,
            'architecture-id': architecture['id'],
            'medium-id': medium['id'],
            'operatingsystem-id': os['id'],
            'partition-table-id': partition_table['id']
        })

        report_template = make_report_template({
            'content': REPORT_TEMPLATE_FILE,
        })

        result = ReportTemplate.generate({
            'name': report_template['name'],
        })
        self.assertIn('Name,Operating System',
                      result)  # verify header of custom template
        self.assertIn(
            '{0},"{1}"'.format(host['name'],
                               host['operating-system']['operating-system']),
            result)
Exemple #11
0
def test_positive_generate_report_sanitized():
    """Generate report template where there are values in comma outputted
    which might brake CSV format

    :id: 84b577db-144e-4961-a42e-e93887464986

    :setup: User with reporting access rights, Host Statuses report,
            a host with OS that has comma in its name

    :steps:

        1. hammer report-template generate ...

    :expectedresults: Report is generated in proper CSV format (value with comma is quoted)

    :CaseImportance: Medium
    """
    # create a name that has a comma in it, some randomized text, and no spaces.
    os_name = gen_alpha(start='test', separator=',').replace(' ', '')
    architecture = make_architecture()
    partition_table = make_partition_table()
    medium = make_medium()
    os = make_os({
        'name': os_name,
        'architecture-ids': architecture['id'],
        'medium-ids': medium['id'],
        'partition-table-ids': partition_table['id'],
    })

    host_name = gen_alpha()
    host = make_fake_host({
        'name': host_name,
        'architecture-id': architecture['id'],
        'medium-id': medium['id'],
        'operatingsystem-id': os['id'],
        'partition-table-id': partition_table['id'],
    })

    report_template = make_report_template({'content': REPORT_TEMPLATE_FILE})

    result = ReportTemplate.generate({'name': report_template['name']})
    assert 'Name,Operating System' in result  # verify header of custom template
    assert f'{host["name"]},"{host["operating-system"]["operating-system"]}"' in result
    def test_negative_hosts_limit(self):
        """Check that Host limit actually limits usage

        @id: 57b70977-2110-47d9-be3b-461ad15c70c7

        @Steps:
        1. Create Host Collection entity that can contain only one Host (using
        Host Limit field)
        2. Create Host and add it to Host Collection. Check that it was added
        successfully
        3. Create one more Host and try to add it to Host Collection
        4. Check that expected error is shown

        @Assert: Second host is not added to Host Collection and appropriate
        error is shown

        @CaseLevel: System
        """
        name = gen_string('alpha')
        org = entities.Organization().create()
        cv = entities.ContentView(organization=org).create()
        lce = entities.LifecycleEnvironment(organization=org).create()
        cv.publish()
        promote(cv.read().version[0], lce.id)
        new_systems = [
            make_fake_host({
                u'content-view-id': cv.id,
                u'lifecycle-environment-id': lce.id,
                u'name': gen_string('alpha'),
                u'organization-id': org.id,
            })['name']
            for _ in range(2)
        ]
        with Session(self.browser) as session:
            make_host_collection(
                session, org=org.name, name=name, limit='1')
            self.hostcollection.add_host(name, new_systems[0])
            with self.assertRaises(UIError):
                self.hostcollection.add_host(name, new_systems[1])
            self.assertIsNotNone(self.hostcollection.wait_until_element(
                common_locators['alert.error_sub_form']))
Exemple #13
0
    def test_negative_hosts_limit(self):
        """Check that Host limit actually limits usage

        :id: 57b70977-2110-47d9-be3b-461ad15c70c7

        :Steps:
            1. Create Host Collection entity that can contain only one Host
                (using Host Limit field)
            2. Create Host and add it to Host Collection. Check that it was
                added successfully
            3. Create one more Host and try to add it to Host Collection
            4. Check that expected error is shown

        :expectedresults: Second host is not added to Host Collection and
            appropriate error is shown

        :CaseLevel: System
        """
        name = gen_string('alpha')
        org = entities.Organization().create()
        cv = entities.ContentView(organization=org).create()
        lce = entities.LifecycleEnvironment(organization=org).create()
        cv.publish()
        promote(cv.read().version[0], lce.id)
        new_systems = [
            make_fake_host({
                u'content-view-id': cv.id,
                u'lifecycle-environment-id': lce.id,
                u'name': gen_string('alpha'),
                u'organization-id': org.id,
            })['name']
            for _ in range(2)
        ]
        with Session(self.browser) as session:
            make_host_collection(
                session, org=org.name, name=name, limit='1')
            self.hostcollection.add_host(name, new_systems[0])
            with self.assertRaises(UIError):
                self.hostcollection.add_host(name, new_systems[1])
            self.assertIsNotNone(self.hostcollection.wait_until_element(
                common_locators['alert.error_sub_form']))