def test_filtered_datapoint_True(self):
     """Tests if run_one_datapoint=false returns all data points"""
     settings.run_one_datapoint = False
     self.assertEqual(len(generate_strings_list()), 7)
     self.assertEqual(len(invalid_emails_list()), 8)
     self.assertEqual(len(invalid_id_list()), 4)
     self.assertEqual(len(invalid_interfaces_list()), 8)
     self.assertEqual(len(invalid_names_list()), 7)
     self.assertEqual(len(invalid_values_list()), 10)
     self.assertEqual(len(invalid_usernames_list()), 4)
     self.assertEqual(len(valid_labels_list()), 2)
     self.assertEqual(len(valid_data_list()), 7)
     self.assertEqual(len(valid_emails_list()), 8)
     self.assertEqual(len(valid_environments_list()), 4)
     self.assertEqual(len(valid_hosts_list()), 3)
     self.assertEqual(len(valid_hostgroups_list()), 7)
     self.assertEqual(len(valid_interfaces_list()), 3)
     self.assertEqual(len(valid_names_list()), 15)
     self.assertEqual(len(valid_org_names_list()), 7)
     self.assertEqual(len(valid_usernames_list()), 6)
     self.assertEqual(len((valid_cron_expressions())), 4)
     with mock.patch('robottelo.datafactory.bz_bug_is_open',
                     return_value=True):
         self.assertEqual(len(valid_docker_repository_names()), 6)
     with mock.patch('robottelo.datafactory.bz_bug_is_open',
                     return_value=False):
         self.assertEqual(len(valid_docker_repository_names()), 7)
Example #2
0
 def test_filtered_datapoint_True(self):
     """Tests if run_one_datapoint=false returns all data points"""
     settings.run_one_datapoint = False
     self.assertEqual(len(generate_strings_list()), 7)
     self.assertEqual(len(invalid_emails_list()), 8)
     self.assertEqual(len(invalid_id_list()), 4)
     self.assertEqual(len(invalid_interfaces_list()), 8)
     self.assertEqual(len(invalid_names_list()), 7)
     self.assertEqual(len(invalid_values_list()), 10)
     self.assertEqual(len(invalid_usernames_list()), 4)
     self.assertEqual(len(valid_labels_list()), 2)
     self.assertEqual(len(valid_data_list()), 7)
     self.assertEqual(len(valid_emails_list()), 8)
     self.assertEqual(len(valid_environments_list()), 4)
     self.assertEqual(len(valid_hosts_list()), 3)
     self.assertEqual(len(valid_hostgroups_list()), 7)
     self.assertEqual(len(valid_interfaces_list()), 3)
     self.assertEqual(len(valid_names_list()), 15)
     self.assertEqual(len(valid_org_names_list()), 7)
     self.assertEqual(len(valid_usernames_list()), 6)
     with mock.patch('robottelo.datafactory.bz_bug_is_open',
                     return_value=True):
         self.assertEqual(len(valid_docker_repository_names()), 6)
     with mock.patch('robottelo.datafactory.bz_bug_is_open',
                     return_value=False):
         self.assertEqual(len(valid_docker_repository_names()), 7)
Example #3
0
    def test_return_type(self):
        """This test validates return types for functions:

        1. :meth:`robottelo.datafactory.generate_strings_list`
        2. :meth:`robottelo.datafactory.invalid_emails_list`
        3. :meth:`robottelo.datafactory.invalid_names_list`
        4. :meth:`robottelo.datafactory.valid_data_list`
        5. :meth:`robottelo.datafactory.valid_emails_list`
        6. :meth:`robottelo.datafactory.valid_environments_list`
        7. :meth:`robottelo.datafactory.valid_hosts_list`
        8. :meth:`robottelo.datafactory.valid_hostgroups_list`
        9. :meth:`robottelo.datafactory.valid_labels_list`
        10. :meth:`robottelo.datafactory.valid_names_list`
        11. :meth:`robottelo.datafactory.valid_usernames_list`
        12. :meth:`robottelo.datafactory.invalid_id_list`

        """
        for item in itertools.chain(
                generate_strings_list(),
                invalid_emails_list(),
                invalid_names_list(),
                valid_data_list(),
                valid_emails_list(),
                valid_environments_list(),
                valid_hosts_list(),
                valid_hostgroups_list(),
                valid_labels_list(),
                valid_names_list(),
                valid_usernames_list(),):
            self.assertIsInstance(item, six.text_type)
        for item in invalid_id_list():
            if not (isinstance(item, (six.text_type, int)) or item is None):
                self.fail('Unexpected data type')
Example #4
0
def test_positive_update_hostgroup(
    request,
    module_puppet_org,
    env,
    puppet_content_source,
    puppet_classes,
    session_puppet_enabled_sat,
    puppet_proxy_port_range,
):
    """Update hostgroup's content source, name and puppet classes

    :id: c22218a1-4d86-4ac1-ad4b-79b10c9adcde

    :customerscenario: true

    :BZ: 1260697, 1313056

    :expectedresults: Hostgroup was successfully updated with new content
        source, name and puppet classes

    :CaseLevel: Integration
    """
    with session_puppet_enabled_sat:
        hostgroup = make_hostgroup({
            'content-source-id':
            puppet_content_source['id'],
            'organization-ids':
            module_puppet_org.id,
            'environment-id':
            env.id,
            'query-organization-id':
            module_puppet_org.id,
        })
        new_content_source = make_proxy()

        @request.addfinalizer
        def _cleanup():
            with session_puppet_enabled_sat:
                HostGroup.delete({'id': hostgroup['id']})
                capsule_cleanup(new_content_source['id'])

        assert len(hostgroup['puppetclasses']) == 0
        new_name = valid_hostgroups_list()[0]
        puppet_class_names = [puppet['name'] for puppet in puppet_classes]
        HostGroup.update({
            'new-name': new_name,
            'id': hostgroup['id'],
            'content-source-id': new_content_source['id'],
            'puppet-classes': puppet_class_names,
        })
        hostgroup = HostGroup.info({'id': hostgroup['id']})
        assert hostgroup['name'] == new_name
        assert hostgroup['content-source']['name'] == new_content_source[
            'name']
        for puppet_class_name in puppet_class_names:
            assert puppet_class_name in hostgroup['puppetclasses']
Example #5
0
 def test_filtered_datapoint(self, run_one_datapoint):
     """Tests if run_one_datapoint=false returns all data points"""
     if run_one_datapoint:
         assert len(datafactory.generate_strings_list()) == 1
         assert len(datafactory.invalid_emails_list()) == 1
         assert len(datafactory.invalid_environments_list()) == 1
         assert len(datafactory.invalid_id_list()) == 1
         assert len(datafactory.invalid_interfaces_list()) == 1
         assert len(datafactory.invalid_names_list()) == 1
         assert len(datafactory.invalid_values_list()) == 1
         assert len(datafactory.valid_data_list()) == 1
         assert len(datafactory.valid_docker_repository_names()) == 1
         assert len(datafactory.valid_emails_list()) == 1
         assert len(datafactory.valid_environments_list()) == 1
         assert len(datafactory.valid_hosts_list()) == 1
         assert len(datafactory.valid_hostgroups_list()) == 1
         assert len(datafactory.valid_interfaces_list()) == 1
         assert len(datafactory.valid_labels_list()) == 1
         assert len(datafactory.valid_names_list()) == 1
         assert len(datafactory.valid_org_names_list()) == 1
         assert len(datafactory.valid_usernames_list()) == 1
         assert len(datafactory.valid_cron_expressions()) == 1
     else:
         assert len(datafactory.generate_strings_list()) == 7
         assert len(datafactory.invalid_emails_list()) == 8
         assert len(datafactory.invalid_environments_list()) == 4
         assert len(datafactory.invalid_id_list()) == 4
         assert len(datafactory.invalid_interfaces_list()) == 8
         assert len(datafactory.invalid_names_list()) == 7
         assert len(datafactory.invalid_values_list()) == 10
         assert len(datafactory.invalid_usernames_list()) == 4
         assert len(datafactory.valid_labels_list()) == 2
         assert len(datafactory.valid_data_list()) == 7
         assert len(datafactory.valid_emails_list()) == 8
         assert len(datafactory.valid_environments_list()) == 4
         assert len(datafactory.valid_hosts_list()) == 3
         assert len(datafactory.valid_hostgroups_list()) == 7
         assert len(datafactory.valid_interfaces_list()) == 3
         assert len(datafactory.valid_names_list()) == 15
         assert len(datafactory.valid_org_names_list()) == 7
         assert len(datafactory.valid_usernames_list()) == 6
         assert len(datafactory.valid_cron_expressions()) == 4
         assert len(datafactory.valid_docker_repository_names()) == 7
Example #6
0
    def test_positive_hostgroup_hooks(self):
        """Create hooks to be executed on hostgroup create, udpdate and destroy

        :id: 7e935dec-e4fe-47d8-be02-8c687a99ae7a

        :steps:
            1. Create hook directories with symlinks to logger script
            for subset of supported events: before_create, before_update,
            before_destroy
            2. Perform trigger actions (create, update and delete host group)
            3. Observe custom logs created by hook script

        :expectedresults: hook scripts are executed at proper time
        """
        hg_name = valid_hostgroups_list()[0]
        expected_msg = "Executed {0} hook on object {1}"

        # create hook destination directories with logger script
        create_event = "before_create"
        update_event = "before_update"
        destroy_event = "before_destroy"
        for event in [create_event, update_event, destroy_event]:
            hook_dir = "{0}/hostgroup/{1}".format(HOOKS_DIR, event)
            ssh.command('''mkdir -p {}'''.format(hook_dir))
            ssh.command('''ln -sf {0} {1}/'''.format(self.script_path,
                                                     hook_dir))
        result = ssh.command("systemctl restart httpd")
        self.assertEqual(result.return_code, 0)

        # create hg, check logs for hook activity
        hg = entities.HostGroup(name=hg_name, organization=[self.org]).create()
        self.assertEqual(hg.name, hg_name)
        result = ssh.command('cat {}'.format(LOGS_DIR))
        self.assertEqual(result.return_code, 0)
        self.assertIn(expected_msg.format(create_event, hg_name),
                      result.stdout[0])

        # update hg, check logs for hook activity
        new_arch = entities.Architecture().create()
        hg.architecture = new_arch
        hg = hg.update(['architecture'])
        self.assertEqual(hg.architecture.read().name, new_arch.name)
        result = ssh.command('cat {}'.format(LOGS_DIR))
        self.assertEqual(result.return_code, 0)
        self.assertIn(expected_msg.format(update_event, hg_name),
                      result.stdout[0])

        # delete hg, check logs for hook activity
        hg.delete()
        with self.assertRaises(HTTPError):
            hg.read()
        result = ssh.command('cat {}'.format(LOGS_DIR))
        self.assertEqual(result.return_code, 0)
        self.assertIn(expected_msg.format(destroy_event, hg_name),
                      result.stdout[0])
Example #7
0
    def test_positive_create_with_name(self):
        """Successfully creates an HostGroup.

        @id: f5f2056f-d090-4e0d-8fb9-d29255a47908

        @Assert: HostGroup is created.
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                self.assertEqual(hostgroup['name'], name)
Example #8
0
    def test_positive_create_with_name(self):
        """Successfully creates an HostGroup.

        @Feature: HostGroup

        @Assert: HostGroup is created.
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                self.assertEqual(hostgroup['name'], name)
    def test_positive_create_with_name(self):
        """Successfully creates an HostGroup.

        @Feature: HostGroup

        @Assert: HostGroup is created.
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                self.assertEqual(hostgroup['name'], name)
Example #10
0
    def test_positive_create_with_name(self):
        """Create a hostgroup with different names

        @id: fd5d353c-fd0c-4752-8a83-8f399b4c3416

        @assert: A hostgroup is created with expected name
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = entities.HostGroup(location=[self.loc], name=name, organization=[self.org]).create()
                self.assertEqual(name, hostgroup.name)
Example #11
0
    def test_positive_create_with_name(self):
        """Successfully creates an HostGroup.

        @id: f5f2056f-d090-4e0d-8fb9-d29255a47908

        @Assert: HostGroup is created.
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                self.assertEqual(hostgroup['name'], name)
Example #12
0
def test_positive_hostgroup_hooks(logger_hook, default_org, target_sat):
    """Create hooks to be executed on hostgroup create, udpdate and destroy

    :id: 7e935dec-e4fe-47d8-be02-8c687a99ae7a

    :steps:
        1. Create hook directories with symlinks to logger script
        for subset of supported events: before_create, before_update,
        before_destroy
        2. Perform trigger actions (create, update and delete host group)
        3. Observe custom logs created by hook script

    :expectedresults: hook scripts are executed at proper time
    """
    hg_name = valid_hostgroups_list()[0]
    expected_msg = 'Executed {0} hook on object {1}'

    # create hook destination directories with logger script
    create_event = 'before_create'
    update_event = 'before_update'
    destroy_event = 'before_destroy'
    for event in [create_event, update_event, destroy_event]:
        hook_dir = f'{HOOKS_DIR}/hostgroup/{event}'
        target_sat.execute(f'mkdir -p {hook_dir}')
        target_sat.execute(f'ln -sf {SCRIPT_PATH} {hook_dir}/')
    result = target_sat.execute('systemctl restart httpd')
    assert result.status == 0

    # create hg, check logs for hook activity
    hg = target_sat.api.HostGroup(name=hg_name,
                                  organization=[default_org.id]).create()
    assert hg.name == hg_name
    result = target_sat.execute(f'cat {LOGS_DIR}')
    assert result.status == 0
    assert expected_msg.format(create_event, hg_name) in result.stdout

    # update hg, check logs for hook activity
    new_arch = target_sat.api.Architecture().create()
    hg.architecture = new_arch
    hg = hg.update(['architecture'])
    assert hg.architecture.read().name == new_arch.name
    result = target_sat.execute(f'cat {LOGS_DIR}')
    assert result.status == 0
    assert expected_msg.format(update_event, hg_name) in result.stdout

    # delete hg, check logs for hook activity
    hg.delete()
    with pytest.raises(HTTPError):
        hg.read()
    result = target_sat.execute(f'cat {LOGS_DIR}')
    assert result.status == 0
    assert expected_msg.format(destroy_event, hg_name) in result.stdout
Example #13
0
    def test_positive_update_name(self):
        """Update a hostgroup with a new name

        @id: 8abb151f-a058-4f47-a1c1-f60a32cd7572

        @assert: A hostgroup is updated with expected name
        """
        hostgroup = entities.HostGroup(location=[self.loc], organization=[self.org]).create()
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup.name = name
                hostgroup = hostgroup.update(["name"])
                self.assertEqual(name, hostgroup.name)
    def test_positive_create_with_name(self):
        """Successfully creates an HostGroup.

        :id: f5f2056f-d090-4e0d-8fb9-d29255a47908

        :expectedresults: HostGroup is created.

        :CaseImportance: Critical
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                self.assertEqual(hostgroup['name'], name)
Example #15
0
    def test_positive_create_with_name(self):
        """Successfully creates an HostGroup.

        :id: f5f2056f-d090-4e0d-8fb9-d29255a47908

        :expectedresults: HostGroup is created.

        :CaseImportance: Critical
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                self.assertEqual(hostgroup['name'], name)
Example #16
0
    def test_positive_hostgroup_hooks(self):
        """Create hooks to be executed on hostgroup create, udpdate and destroy

        :id: 7e935dec-e4fe-47d8-be02-8c687a99ae7a

        :steps:
            1. Create hook directories with symlinks to logger script
            for subset of supported events: before_create, before_update,
            before_destroy
            2. Perform trigger actions (create, update and delete host group)
            3. Observe custom logs created by hook script

        :expectedresults: hook scripts are executed at proper time
        """
        hg_name = valid_hostgroups_list()[0]
        expected_msg = "Executed {0} hook on object {1}"

        # create hook destination directories with logger script
        create_event = "before_create"
        update_event = "before_update"
        destroy_event = "before_destroy"
        for event in [create_event, update_event, destroy_event]:
            hook_dir = "{0}/hostgroup/{1}".format(HOOKS_DIR, event)
            ssh.command('''mkdir -p {}'''.format(hook_dir))
            ssh.command('''ln -sf {0} {1}/'''.format(self.script_path, hook_dir))
        result = ssh.command("systemctl restart httpd")
        self.assertEqual(result.return_code, 0)

        # create hg, check logs for hook activity
        hg = entities.HostGroup(name=hg_name, organization=[self.org]).create()
        self.assertEqual(hg.name, hg_name)
        result = ssh.command('cat {}'.format(LOGS_DIR))
        self.assertEqual(result.return_code, 0)
        self.assertIn(expected_msg.format(create_event, hg_name), result.stdout[0])

        # update hg, check logs for hook activity
        new_arch = entities.Architecture().create()
        hg.architecture = new_arch
        hg = hg.update(['architecture'])
        self.assertEqual(hg.architecture.read().name, new_arch.name)
        result = ssh.command('cat {}'.format(LOGS_DIR))
        self.assertEqual(result.return_code, 0)
        self.assertIn(expected_msg.format(update_event, hg_name), result.stdout[0])

        # delete hg, check logs for hook activity
        hg.delete()
        with self.assertRaises(HTTPError):
            hg.read()
        result = ssh.command('cat {}'.format(LOGS_DIR))
        self.assertEqual(result.return_code, 0)
        self.assertIn(expected_msg.format(destroy_event, hg_name), result.stdout[0])
    def test_positive_delete_by_id(self):
        """Create HostGroup with valid values then delete it
        by ID

        @feature: HostGroup

        @assert: HostGroup is deleted
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                HostGroup.delete({'id': hostgroup['id']})
                with self.assertRaises(CLIReturnCodeError):
                    HostGroup.info({'id': hostgroup['id']})
Example #18
0
    def test_positive_delete_by_id(self):
        """Create HostGroup with valid values then delete it
        by ID

        @id: fe7dedd4-d7c3-4c70-b70d-c2deff357b76

        @assert: HostGroup is deleted
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                HostGroup.delete({'id': hostgroup['id']})
                with self.assertRaises(CLIReturnCodeError):
                    HostGroup.info({'id': hostgroup['id']})
    def test_positive_create_with_name(self):
        """Create a hostgroup with different names

        @feature: HostGroup

        @assert: A hostgroup is created with expected name
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = entities.HostGroup(
                    location=[self.loc],
                    name=name,
                    organization=[self.org],
                ).create()
                self.assertEqual(name, hostgroup.name)
    def test_positive_update_name(self):
        """Update a hostgroup with a new name

        :id: 8abb151f-a058-4f47-a1c1-f60a32cd7572

        :expectedresults: A hostgroup is updated with expected name

        :CaseImportance: Critical
        """
        hostgroup = entities.HostGroup(location=[self.loc], organization=[self.org]).create()
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup.name = name
                hostgroup = hostgroup.update(['name'])
                self.assertEqual(name, hostgroup.name)
Example #21
0
    def test_positive_create_with_name(self):
        """Create a hostgroup with different names

        @feature: HostGroup

        @assert: A hostgroup is created with expected name
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = entities.HostGroup(
                    location=[self.loc],
                    name=name,
                    organization=[self.org],
                ).create()
                self.assertEqual(name, hostgroup.name)
    def test_positive_create_with_name(self):
        """Create a hostgroup with different names

        :id: fd5d353c-fd0c-4752-8a83-8f399b4c3416

        :expectedresults: A hostgroup is created with expected name

        :CaseImportance: Critical
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = entities.HostGroup(
                    location=[self.loc], name=name, organization=[self.org]
                ).create()
                self.assertEqual(name, hostgroup.name)
Example #23
0
    def test_positive_update_name(self):
        """Successfully update an HostGroup.

        @id: a36e3cbe-83d9-44ce-b8f7-5fab2a2cadf9

        @Assert: HostGroup is updated.
        """
        hostgroup = make_hostgroup()
        for new_name in valid_hostgroups_list():
            with self.subTest(new_name):
                HostGroup.update({
                    'id': hostgroup['id'],
                    'new-name': new_name,
                })
                hostgroup = HostGroup.info({'id': hostgroup['id']})
                self.assertEqual(hostgroup['name'], new_name)
Example #24
0
    def test_positive_update_name(self):
        """Successfully update an HostGroup.

        @Feature: HostGroup

        @Assert: HostGroup is updated.
        """
        hostgroup = make_hostgroup()
        for new_name in valid_hostgroups_list():
            with self.subTest(new_name):
                HostGroup.update({
                    'id': hostgroup['id'],
                    'new-name': new_name,
                })
                hostgroup = HostGroup.info({'id': hostgroup['id']})
                self.assertEqual(hostgroup['name'], new_name)
Example #25
0
    def test_positive_update_name(self):
        """Successfully update an HostGroup.

        @id: a36e3cbe-83d9-44ce-b8f7-5fab2a2cadf9

        @Assert: HostGroup is updated.
        """
        hostgroup = make_hostgroup()
        for new_name in valid_hostgroups_list():
            with self.subTest(new_name):
                HostGroup.update({
                    'id': hostgroup['id'],
                    'new-name': new_name,
                })
                hostgroup = HostGroup.info({'id': hostgroup['id']})
                self.assertEqual(hostgroup['name'], new_name)
    def test_positive_update_name(self):
        """Update a hostgroup with a new name

        @feature: HostGroup

        @assert: A hostgroup is updated with expected name
        """
        hostgroup = entities.HostGroup(
            location=[self.loc],
            organization=[self.org],
        ).create()
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup.name = name
                hostgroup = hostgroup.update(['name'])
                self.assertEqual(name, hostgroup.name)
Example #27
0
    def test_positive_update_name(self):
        """Update a hostgroup with a new name

        @feature: HostGroup

        @assert: A hostgroup is updated with expected name
        """
        hostgroup = entities.HostGroup(
            location=[self.loc],
            organization=[self.org],
        ).create()
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup.name = name
                hostgroup = hostgroup.update(['name'])
                self.assertEqual(name, hostgroup.name)
Example #28
0
 def test_datacheck_True(self):
     """Tests if run_one_datapoint=false returns all data points"""
     settings.run_one_datapoint = False
     self.assertEqual(len(generate_strings_list()), 7)
     self.assertEqual(len(invalid_id_list()), 4)
     self.assertEqual(len(invalid_emails_list()), 10)
     self.assertEqual(len(invalid_names_list()), 7)
     self.assertEqual(len(invalid_values_list()), 10)
     self.assertEqual(len(valid_labels_list()), 2)
     self.assertEqual(len(valid_data_list()), 7)
     self.assertEqual(len(valid_emails_list()), 8)
     self.assertEqual(len(valid_environments_list()), 3)
     self.assertEqual(len(valid_hosts_list()), 3)
     self.assertEqual(len(valid_hostgroups_list()), 7)
     self.assertEqual(len(valid_names_list()), 15)
     self.assertEqual(len(valid_usernames_list()), 4)
Example #29
0
 def test_datacheck_False(self):
     """Tests if run_one_datapoint=True returns one data point"""
     settings.run_one_datapoint = True
     self.assertEqual(len(generate_strings_list()), 1)
     self.assertEqual(len(invalid_emails_list()), 1)
     self.assertEqual(len(invalid_id_list()), 1)
     self.assertEqual(len(invalid_names_list()), 1)
     self.assertEqual(len(invalid_values_list()), 1)
     self.assertEqual(len(valid_data_list()), 1)
     self.assertEqual(len(valid_emails_list()), 1)
     self.assertEqual(len(valid_environments_list()), 1)
     self.assertEqual(len(valid_hosts_list()), 1)
     self.assertEqual(len(valid_hostgroups_list()), 1)
     self.assertEqual(len(valid_labels_list()), 1)
     self.assertEqual(len(valid_names_list()), 1)
     self.assertEqual(len(valid_usernames_list()), 1)
Example #30
0
    def test_positive_delete_by_id(self):
        """Create HostGroup with valid values then delete it
        by ID

        :id: fe7dedd4-d7c3-4c70-b70d-c2deff357b76

        :expectedresults: HostGroup is deleted

        :CaseImportance: Critical
        """
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup = make_hostgroup({'name': name})
                HostGroup.delete({'id': hostgroup['id']})
                with self.assertRaises(CLIReturnCodeError):
                    HostGroup.info({'id': hostgroup['id']})
    def test_positive_update_name(self):
        """Successfully update an HostGroup.

        @Feature: HostGroup

        @Assert: HostGroup is updated.
        """
        hostgroup = make_hostgroup()
        for new_name in valid_hostgroups_list():
            with self.subTest(new_name):
                HostGroup.update({
                    'id': hostgroup['id'],
                    'new-name': new_name,
                })
                hostgroup = HostGroup.info({'id': hostgroup['id']})
                self.assertEqual(hostgroup['name'], new_name)
Example #32
0
    def test_return_type(self):
        """This test validates return types for functions:

        1. :meth:`robottelo.datafactory.generate_strings_list`
        2. :meth:`robottelo.datafactory.invalid_emails_list`
        3. :meth:`robottelo.datafactory.invalid_names_list`
        4. :meth:`robottelo.datafactory.valid_data_list`
        5. :meth:`robottelo.datafactory.valid_docker_repository_names`
        6. :meth:`robottelo.datafactory.valid_emails_list`
        7. :meth:`robottelo.datafactory.valid_environments_list`
        8. :meth:`robottelo.datafactory.valid_hosts_list`
        9. :meth:`robottelo.datafactory.valid_hostgroups_list`
        10. :meth:`robottelo.datafactory.valid_labels_list`
        11. :meth:`robottelo.datafactory.valid_names_list`
        12. :meth:`robottelo.datafactory.valid_org_names_list`
        13. :meth:`robottelo.datafactory.valid_usernames_list`
        14. :meth:`robottelo.datafactory.invalid_id_list`
        15. :meth:`robottelo.datafactory.invalid_interfaces_list`
        16. :meth:`robottelo.datafactory.valid_interfaces_list`
        17. :meth:`robottelo.datafactory.valid_cron_expressions`

        """
        with mock.patch('robottelo.datafactory.bz_bug_is_open',
                        return_value=False):
            for item in itertools.chain(
                    generate_strings_list(),
                    invalid_emails_list(),
                    invalid_interfaces_list(),
                    invalid_names_list(),
                    valid_data_list(),
                    valid_docker_repository_names(),
                    valid_emails_list(),
                    valid_environments_list(),
                    valid_hosts_list(),
                    valid_hostgroups_list(),
                    valid_interfaces_list(),
                    valid_labels_list(),
                    valid_names_list(),
                    valid_org_names_list(),
                    valid_cron_expressions(),
                    valid_usernames_list()):
                self.assertIsInstance(item, six.text_type)
            for item in invalid_id_list():
                if not (
                        isinstance(item, (six.text_type, int)) or item is None
                        ):
                    self.fail('Unexpected data type')
 def test_filtered_datapoint_False(self):
     """Tests if run_one_datapoint=True returns one data point"""
     settings.run_one_datapoint = True
     self.assertEqual(len(generate_strings_list()), 1)
     self.assertEqual(len(invalid_emails_list()), 1)
     self.assertEqual(len(invalid_id_list()), 1)
     self.assertEqual(len(invalid_names_list()), 1)
     self.assertEqual(len(invalid_values_list()), 1)
     self.assertEqual(len(valid_data_list()), 1)
     self.assertEqual(len(valid_emails_list()), 1)
     self.assertEqual(len(valid_environments_list()), 1)
     self.assertEqual(len(valid_hosts_list()), 1)
     self.assertEqual(len(valid_hostgroups_list()), 1)
     self.assertEqual(len(valid_labels_list()), 1)
     self.assertEqual(len(valid_names_list()), 1)
     self.assertEqual(len(valid_org_names_list()), 1)
     self.assertEqual(len(valid_usernames_list()), 1)
Example #34
0
    def test_return_type(self):
        """This test validates return types for functions:

        1. :meth:`robottelo.datafactory.generate_strings_list`
        2. :meth:`robottelo.datafactory.invalid_emails_list`
        3. :meth:`robottelo.datafactory.invalid_environments_list`
        4. :meth:`robottelo.datafactory.invalid_names_list`
        5. :meth:`robottelo.datafactory.valid_data_list`
        6. :meth:`robottelo.datafactory.valid_docker_repository_names`
        7. :meth:`robottelo.datafactory.valid_emails_list`
        8. :meth:`robottelo.datafactory.valid_environments_list`
        9. :meth:`robottelo.datafactory.valid_hosts_list`
        10. :meth:`robottelo.datafactory.valid_hostgroups_list`
        11. :meth:`robottelo.datafactory.valid_labels_list`
        12. :meth:`robottelo.datafactory.valid_names_list`
        13. :meth:`robottelo.datafactory.valid_org_names_list`
        14. :meth:`robottelo.datafactory.valid_usernames_list`
        15. :meth:`robottelo.datafactory.invalid_id_list`
        16. :meth:`robottelo.datafactory.invalid_interfaces_list`
        17. :meth:`robottelo.datafactory.valid_interfaces_list`
        18. :meth:`robottelo.datafactory.valid_cron_expressions`

        """
        for item in itertools.chain(
                datafactory.generate_strings_list(),
                datafactory.invalid_emails_list(),
                datafactory.invalid_environments_list(),
                datafactory.invalid_interfaces_list(),
                datafactory.invalid_names_list(),
                datafactory.valid_data_list(),
                datafactory.valid_docker_repository_names(),
                datafactory.valid_emails_list(),
                datafactory.valid_environments_list(),
                datafactory.valid_hosts_list(),
                datafactory.valid_hostgroups_list(),
                datafactory.valid_interfaces_list(),
                datafactory.valid_labels_list(),
                datafactory.valid_names_list(),
                datafactory.valid_org_names_list(),
                datafactory.valid_cron_expressions(),
                datafactory.valid_usernames_list(),
        ):
            assert isinstance(item, str)
        for item in datafactory.invalid_id_list():
            if not (isinstance(item, (str, int)) or item is None):
                pytest.fail('Unexpected data type')
 def test_filtered_datapoint_True(self):
     """Tests if run_one_datapoint=false returns all data points"""
     settings.run_one_datapoint = False
     self.assertEqual(len(generate_strings_list()), 7)
     self.assertEqual(len(invalid_id_list()), 4)
     self.assertEqual(len(invalid_emails_list()), 10)
     self.assertEqual(len(invalid_names_list()), 7)
     self.assertEqual(len(invalid_values_list()), 10)
     self.assertEqual(len(invalid_usernames_list()), 4)
     self.assertEqual(len(valid_labels_list()), 2)
     self.assertEqual(len(valid_data_list()), 7)
     self.assertEqual(len(valid_emails_list()), 8)
     self.assertEqual(len(valid_environments_list()), 3)
     self.assertEqual(len(valid_hosts_list()), 3)
     self.assertEqual(len(valid_hostgroups_list()), 7)
     self.assertEqual(len(valid_names_list()), 15)
     self.assertEqual(len(valid_org_names_list()), 7)
     self.assertEqual(len(valid_usernames_list()), 6)
Example #36
0
    def test_positive_update_name(self):
        """Update a hostgroup with a new name

        :id: 8abb151f-a058-4f47-a1c1-f60a32cd7572

        :expectedresults: A hostgroup is updated with expected name

        :CaseImportance: Critical
        """
        hostgroup = entities.HostGroup(
            location=[self.loc],
            organization=[self.org],
        ).create()
        for name in valid_hostgroups_list():
            with self.subTest(name):
                hostgroup.name = name
                hostgroup = hostgroup.update(['name'])
                self.assertEqual(name, hostgroup.name)
Example #37
0
    def test_positive_update_hostgroup(self):
        """Update hostgroup's content source, name and puppet classes

        :id: c22218a1-4d86-4ac1-ad4b-79b10c9adcde

        :customerscenario: true

        :BZ: 1260697, 1313056

        :expectedresults: Hostgroup was successfully updated with new content
            source, name and puppet classes

        :CaseLevel: Integration
        """
        hostgroup = make_hostgroup({
            'content-source-id':
            self.content_source['id'],
            'organization-ids':
            self.org['id'],
            'environment-id':
            self.env['id'],
            'content-view-id':
            self.cv['id'],
            'query-organization-id':
            self.org['id'],
        })
        new_content_source = make_proxy()
        self.addCleanup(capsule_cleanup, new_content_source['id'])
        self.addCleanup(HostGroup.delete, {'id': hostgroup['id']})
        self.assertEqual(len(hostgroup['puppetclasses']), 0)
        new_name = valid_hostgroups_list()[0]
        puppet_classes = [puppet['name'] for puppet in self.puppet_classes]
        HostGroup.update({
            'new-name': new_name,
            'id': hostgroup['id'],
            'content-source-id': new_content_source['id'],
            'puppet-classes': puppet_classes,
        })
        hostgroup = HostGroup.info({'id': hostgroup['id']})
        self.assertEqual(hostgroup['name'], new_name)
        self.assertEqual(hostgroup['content-source']['name'],
                         new_content_source['name'])
        self.assertEqual(set(puppet_classes), set(hostgroup['puppetclasses']))
Example #38
0
 def test_filtered_datapoint_False(self):
     """Tests if run_one_datapoint=True returns one data point"""
     settings.run_one_datapoint = True
     self.assertEqual(len(generate_strings_list()), 1)
     self.assertEqual(len(invalid_emails_list()), 1)
     self.assertEqual(len(invalid_id_list()), 1)
     self.assertEqual(len(invalid_interfaces_list()), 1)
     self.assertEqual(len(invalid_names_list()), 1)
     self.assertEqual(len(invalid_values_list()), 1)
     self.assertEqual(len(valid_data_list()), 1)
     self.assertEqual(len(valid_docker_repository_names()), 1)
     self.assertEqual(len(valid_emails_list()), 1)
     self.assertEqual(len(valid_environments_list()), 1)
     self.assertEqual(len(valid_hosts_list()), 1)
     self.assertEqual(len(valid_hostgroups_list()), 1)
     self.assertEqual(len(valid_interfaces_list()), 1)
     self.assertEqual(len(valid_labels_list()), 1)
     self.assertEqual(len(valid_names_list()), 1)
     self.assertEqual(len(valid_org_names_list()), 1)
     self.assertEqual(len(valid_usernames_list()), 1)
Example #39
0
def test_positive_update_hostgroup(request, module_org, content_source):
    """Update hostgroup's content source and name

    :id: c22218a1-4d86-4ac1-ad4b-79b10c9adcde

    :customerscenario: true

    :BZ: 1260697, 1313056

    :expectedresults: Hostgroup was successfully updated with new content
        source and name

    :CaseLevel: Integration
    """
    hostgroup = make_hostgroup({
        'content-source-id': content_source['id'],
        'organization-ids': module_org.id,
        'query-organization-id': module_org.id,
    })
    new_content_source = make_proxy()

    @request.addfinalizer
    def _cleanup():
        HostGroup.delete({'id': hostgroup['id']})
        capsule_cleanup(new_content_source['id'])

    assert len(hostgroup['puppetclasses']) == 0
    new_name = valid_hostgroups_list()[0]
    HostGroup.update({
        'new-name': new_name,
        'id': hostgroup['id'],
        'content-source-id': new_content_source['id'],
    })
    hostgroup = HostGroup.info({'id': hostgroup['id']})
    assert hostgroup['name'] == new_name
    assert hostgroup['content-source']['name'] == new_content_source['name']
Example #40
0
    def test_return_type(self):
        """This test validates return types for functions:

        1. :meth:`robottelo.datafactory.generate_strings_list`
        2. :meth:`robottelo.datafactory.invalid_emails_list`
        3. :meth:`robottelo.datafactory.invalid_names_list`
        4. :meth:`robottelo.datafactory.valid_data_list`
        5. :meth:`robottelo.datafactory.valid_emails_list`
        6. :meth:`robottelo.datafactory.valid_environments_list`
        7. :meth:`robottelo.datafactory.valid_hosts_list`
        8. :meth:`robottelo.datafactory.valid_hostgroups_list`
        9. :meth:`robottelo.datafactory.valid_labels_list`
        10. :meth:`robottelo.datafactory.valid_names_list`
        11. :meth:`robottelo.datafactory.valid_org_names_list`
        12. :meth:`robottelo.datafactory.valid_usernames_list`
        13. :meth:`robottelo.datafactory.invalid_id_list`
        14. :meth:`robottelo.datafactory.invalid_interfaces_list`
        15. :meth:`robottelo.datafactory.valid_interfaces_list`

        """
        for item in itertools.chain(generate_strings_list(),
                                    invalid_emails_list(),
                                    invalid_interfaces_list(),
                                    invalid_names_list(), valid_data_list(),
                                    valid_emails_list(),
                                    valid_environments_list(),
                                    valid_hosts_list(),
                                    valid_hostgroups_list(),
                                    valid_interfaces_list(),
                                    valid_labels_list(), valid_names_list(),
                                    valid_org_names_list(),
                                    valid_usernames_list()):
            self.assertIsInstance(item, six.text_type)
        for item in invalid_id_list():
            if not (isinstance(item, (six.text_type, int)) or item is None):
                self.fail('Unexpected data type')
Example #41
0
def test_positive_create_with_multiple_entities_and_delete(
        module_puppet_org, puppet_content_source, puppet_classes,
        session_puppet_enabled_sat):
    """Check if hostgroup with multiple options can be created and deleted

    :id: a3ef4f0e-971d-4307-8d0a-35103dff6586

    :expectedresults: Hostgroup should be created, has all defined
        entities assigned and deleted

    :BZ: 1395254, 1313056

    :CaseLevel: Integration

    :CaseImportance: Critical
    """
    with session_puppet_enabled_sat:
        # Common entities
        name = valid_hostgroups_list()[0]
        loc = make_location()
        org_2 = entities.Organization().create()
        orgs = [module_puppet_org, org_2]
        env = make_environment({
            'location-ids': loc['id'],
            'organization-ids': org_2.id
        })
        lce = make_lifecycle_environment({'organization-id': org_2.id})
        # Content View should be promoted to be used with LC Env
        cv = make_content_view({'organization-id': org_2.id})
        ContentView.publish({'id': cv['id']})
        cv = ContentView.info({'id': cv['id']})
        ContentView.version_promote({
            'id': cv['versions'][0]['id'],
            'to-lifecycle-environment-id': lce['id']
        })
        # Network
        domain = make_domain({
            'location-ids': loc['id'],
            'organization-ids': org_2.id
        })
        subnet = make_subnet({
            'domain-ids': domain['id'],
            'organization-ids': org_2.id
        })
        # Operating System
        arch = make_architecture()
        ptable = make_partition_table({
            'location-ids': loc['id'],
            'organization-ids': org_2.id
        })
        os = make_os({
            'architecture-ids': arch['id'],
            'partition-table-ids': ptable['id']
        })
        os_full_name = "{} {}.{}".format(os['name'], os['major-version'],
                                         os['minor-version'])
        media = make_medium({
            'operatingsystem-ids': os['id'],
            'location-ids': loc['id'],
            'organization-ids': org_2.id,
        })
        # Note: in the current hammer version there is no content source name
        # option
        make_hostgroup_params = {
            'name': name,
            'organization-ids': [org.id for org in orgs],
            'locations': loc['name'],
            'puppet-environment': env['name'],
            'lifecycle-environment-id': lce['id'],
            'puppet-proxy': puppet_content_source['name'],
            'puppet-ca-proxy': puppet_content_source['name'],
            'content-source-id': puppet_content_source['id'],
            'content-view': cv['name'],
            'domain': domain['name'],
            'subnet': subnet['name'],
            'architecture': arch['name'],
            'partition-table': ptable['name'],
            'medium': media['name'],
            'operatingsystem': os_full_name,
            'puppet-classes': puppet_classes[0]['name'],
            'query-organization': org_2.name,
        }
        hostgroup = make_hostgroup(make_hostgroup_params)
        assert hostgroup['name'] == name
        assert {org.name for org in orgs} == set(hostgroup['organizations'])
        assert loc['name'] in hostgroup['locations']
        assert env['name'] == hostgroup['puppet-environment']
        assert puppet_content_source['name'] == hostgroup[
            'puppet-master-proxy']
        assert puppet_content_source['name'] == hostgroup['puppet-ca-proxy']
        assert domain['name'] == hostgroup['network']['domain']
        assert subnet['name'] == hostgroup['network']['subnet-ipv4']
        assert arch['name'] == hostgroup['operating-system']['architecture']
        assert ptable['name'] == hostgroup['operating-system'][
            'partition-table']
        assert media['name'] == hostgroup['operating-system']['medium']
        assert os_full_name == hostgroup['operating-system'][
            'operating-system']
        assert cv['name'] == hostgroup['content-view']['name']
        assert lce['name'] == hostgroup['lifecycle-environment']['name']
        assert puppet_content_source['name'] == hostgroup['content-source'][
            'name']
        assert puppet_classes[0]['name'] in hostgroup['puppetclasses']
        # delete hostgroup
        HostGroup.delete({'id': hostgroup['id']})
        with pytest.raises(CLIReturnCodeError):
            HostGroup.info({'id': hostgroup['id']})
Example #42
0
    def test_positive_create_with_multiple_entities_and_delete(self):
        """Check if hostgroup with multiple options can be created and deleted

        :id: a3ef4f0e-971d-4307-8d0a-35103dff6586

        :expectedresults: Hostgroup should be created, has all defined
            entities assigned and deleted

        :BZ: 1395254, 1313056

        :CaseLevel: Integration

        :CaseImportance: Critical
        """
        # Common entities
        name = valid_hostgroups_list()[0]
        loc = make_location()
        org = make_org()
        orgs = [org, self.org]
        env = make_environment({
            'location-ids': loc['id'],
            'organization-ids': org['id']
        })
        lce = make_lifecycle_environment({'organization-id': org['id']})
        # Content View should be promoted to be used with LC Env
        cv = make_content_view({'organization-id': org['id']})
        ContentView.publish({'id': cv['id']})
        cv = ContentView.info({'id': cv['id']})
        ContentView.version_promote({
            'id': cv['versions'][0]['id'],
            'to-lifecycle-environment-id': lce['id']
        })
        # Network
        domain = make_domain({
            'location-ids': loc['id'],
            'organization-ids': org['id']
        })
        subnet = make_subnet({
            'domain-ids': domain['id'],
            'organization-ids': org['id']
        })
        # Operating System
        arch = make_architecture()
        ptable = make_partition_table({
            'location-ids': loc['id'],
            'organization-ids': org['id']
        })
        os = make_os({
            'architecture-ids': arch['id'],
            'partition-table-ids': ptable['id']
        })
        os_full_name = "{0} {1}.{2}".format(os['name'], os['major-version'],
                                            os['minor-version'])
        media = make_medium({
            'operatingsystem-ids': os['id'],
            'location-ids': loc['id'],
            'organization-ids': org['id'],
        })
        # Note: in the current hammer version there is no content source name
        # option
        make_hostgroup_params = {
            'name': name,
            'organization-ids': [org['id'] for org in orgs],
            'locations': loc['name'],
            'environment': env['name'],
            'lifecycle-environment': lce['name'],
            'puppet-proxy': self.content_source['name'],
            'puppet-ca-proxy': self.content_source['name'],
            'content-source-id': self.content_source['id'],
            'content-view': cv['name'],
            'domain': domain['name'],
            'subnet': subnet['name'],
            'architecture': arch['name'],
            'partition-table': ptable['name'],
            'medium': media['name'],
            'operatingsystem': os_full_name,
            'puppet-classes': self.puppet_classes[0]['name'],
            'query-organization': org['name'],
        }
        hostgroup = make_hostgroup(make_hostgroup_params)
        self.assertEqual(hostgroup['name'], name)
        self.assertEqual(set(org['name'] for org in orgs),
                         set(hostgroup['organizations']))
        self.assertIn(loc['name'], hostgroup['locations'])
        self.assertEqual(env['name'], hostgroup['puppet-environment'])
        self.assertEqual(self.content_source['name'],
                         hostgroup['puppet-master-proxy'])
        self.assertEqual(self.content_source['name'],
                         hostgroup['puppet-ca-proxy'])
        self.assertEqual(domain['name'], hostgroup['network']['domain'])
        self.assertEqual(subnet['name'], hostgroup['network']['subnet-ipv4'])
        self.assertEqual(arch['name'],
                         hostgroup['operating-system']['architecture'])
        self.assertEqual(ptable['name'],
                         hostgroup['operating-system']['partition-table'])
        self.assertEqual(media['name'],
                         hostgroup['operating-system']['medium'])
        self.assertEqual(os_full_name,
                         hostgroup['operating-system']['operating-system'])
        self.assertEqual(cv['name'], hostgroup['content-view']['name'])
        self.assertEqual(lce['name'],
                         hostgroup['lifecycle-environment']['name'])
        self.assertEqual(self.content_source['name'],
                         hostgroup['content-source']['name'])
        self.assertIn(self.puppet_classes[0]['name'],
                      hostgroup['puppetclasses'])
        # delete hostgroup
        HostGroup.delete({'id': hostgroup['id']})
        with self.assertRaises(CLIReturnCodeError):
            HostGroup.info({'id': hostgroup['id']})
Example #43
0
class TestHostGroup:
    """Tests for host group entity."""
    @pytest.mark.upgrade
    @pytest.mark.tier3
    def test_inherit_puppetclass(self):
        """Host that created from HostGroup entity with PuppetClass
        assigned to it should inherit such puppet class information under
        'all_puppetclasses' field

        :id: 7b840f3d-413c-40bb-9a7d-cd9dad3c0737

        :expectedresults: Host inherited 'all_puppetclasses' details from
            HostGroup that was used for such Host create procedure

        :BZ: 1107708, 1222118, 1487586

        :CaseLevel: System
        """
        # Creating entities like organization, content view and lifecycle_env
        # with not utf-8 names for easier interaction with puppet environment
        # further in test
        org = entities.Organization(name=gen_string('alpha')).create()
        location = entities.Location(organization=[org]).create()
        # Creating puppet repository with puppet module assigned to it
        product = entities.Product(organization=org).create()
        puppet_repo = entities.Repository(content_type='puppet',
                                          product=product).create()
        # Working with 'ntp' module as we know for sure that it contains at
        # least few puppet classes
        with open(get_data_file(PUPPET_MODULE_NTP_PUPPETLABS), 'rb') as handle:
            puppet_repo.upload_content(files={'content': handle})

        content_view = entities.ContentView(name=gen_string('alpha'),
                                            organization=org).create()

        result = content_view.available_puppet_modules()['results']
        assert len(result) == 1
        entities.ContentViewPuppetModule(author=result[0]['author'],
                                         name=result[0]['name'],
                                         content_view=content_view).create()
        content_view.publish()
        content_view = content_view.read()
        lc_env = entities.LifecycleEnvironment(name=gen_string('alpha'),
                                               organization=org).create()
        promote(content_view.version[0], lc_env.id)
        content_view = content_view.read()
        assert len(content_view.version) == 1
        assert len(content_view.puppet_module) == 1

        # Form environment name variable for our test
        env_name = f'KT_{org.name}_{lc_env.name}_{content_view.name}_{content_view.id}'

        # Get all environments for current organization.
        # We have two environments (one created after publishing and one more
        # was created after promotion), so we need to select promoted one
        environments = entities.Environment().search(
            query={'organization_id': org.id})
        assert len(environments) == 2
        environments = [
            environment for environment in environments
            if environment.name == env_name
        ]
        assert len(environments) == 1
        environment = environments[0].read()
        environment.location = [location]
        environment.update()

        # Create a host group and it dependencies.
        mac = entity_fields.MACAddressField().gen_value()
        root_pass = entity_fields.StringField(length=(8, 30)).gen_value()
        domain = entities.Domain().create()
        architecture = entities.Architecture().create()
        ptable = entities.PartitionTable().create()
        operatingsystem = entities.OperatingSystem(architecture=[architecture],
                                                   ptable=[ptable]).create()
        medium = entities.Media(operatingsystem=[operatingsystem]).create()
        hostgroup = entities.HostGroup(
            architecture=architecture,
            domain=domain,
            environment=environment,
            location=[location.id],
            medium=medium,
            name=gen_string('alpha'),
            operatingsystem=operatingsystem,
            organization=[org.id],
            ptable=ptable,
        ).create()
        assert len(hostgroup.read_json()['all_puppetclasses']) == 0

        # Get puppet class id for ntp module
        response = client.get(
            environment.path('self') + '/puppetclasses',
            auth=get_credentials(),
            verify=False,
        )
        response.raise_for_status()
        results = response.json()['results']
        puppet_class_id = results['ntp'][0]['id']

        # Assign puppet class
        client.post(
            hostgroup.path('self') + '/puppetclass_ids',
            data={
                'puppetclass_id': puppet_class_id
            },
            auth=get_credentials(),
            verify=False,
        ).raise_for_status()
        hostgroup_attrs = hostgroup.read_json()
        assert len(hostgroup_attrs['all_puppetclasses']) == 1
        assert hostgroup_attrs['all_puppetclasses'][0]['name'] == 'ntp'

        # Create Host entity using HostGroup
        host = entities.Host(
            hostgroup=hostgroup,
            mac=mac,
            root_pass=root_pass,
            environment=environment,
            location=location,
            organization=org,
            content_facet_attributes={
                'content_view_id': content_view.id,
                'lifecycle_environment_id': lc_env.id,
            },
            name=gen_string('alpha'),
        ).create(False)
        host_attrs = host.read_json()
        assert len(host_attrs['all_puppetclasses']) == 1
        assert host_attrs['all_puppetclasses'][0]['name'] == 'ntp'

    @pytest.mark.upgrade
    @pytest.mark.tier3
    def test_rebuild_config(self, module_org, module_location, hostgroup):
        """'Rebuild orchestration config' of an existing host group

        :id: 58bf7015-18fc-4d25-9b64-7f2dd6dde425

        :expectedresults: rebuild hostgroup orchestration configs successfully.

        :CaseLevel: System
        """
        lce = entities.LifecycleEnvironment(organization=module_org).create()
        content_view = entities.ContentView(organization=module_org).create()
        content_view.publish()
        content_view = content_view.read()
        promote(content_view.version[0], environment_id=lce.id)
        entities.Host(
            hostgroup=hostgroup,
            location=module_location,
            organization=module_org,
            managed=True,
            content_facet_attributes={
                'content_view_id': content_view.id,
                'lifecycle_environment_id': lce.id,
            },
        ).create()
        # TODO: use host that can also rebuild the SSH_Nic, SSH_Host, and Content_Host_Status
        # config
        assert (hostgroup.rebuild_config(data={'only': 'DNS,DHCP,TFTP'})
                ['message'] == 'Configuration successfully rebuilt.')

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_hostgroups_list()))
    def test_positive_create_with_name(self, name, module_org,
                                       module_location):
        """Create a hostgroup with different names

        :id: fd5d353c-fd0c-4752-8a83-8f399b4c3416

        :parametrized: yes

        :expectedresults: A hostgroup is created with expected name

        :CaseImportance: Critical
        """
        hostgroup = entities.HostGroup(location=[module_location],
                                       name=name,
                                       organization=[module_org]).create()
        assert name == hostgroup.name

    @pytest.mark.tier1
    def test_positive_clone(self, hostgroup):
        """Create a hostgroup by cloning an existing one

        :id: 44ac8b3b-9cb0-4a9e-ad9b-2c67b2411922

        :expectedresults: A hostgroup is cloned with same parameters

        :CaseImportance: Critical
        """
        hostgroup_cloned_name = gen_string('alpha')
        hostgroup_cloned = entities.HostGroup(id=hostgroup.id).clone(
            data={'name': hostgroup_cloned_name})
        hostgroup_origin = hostgroup.read_json()

        # remove unset and unique values before comparison
        unique_keys = ('updated_at', 'created_at', 'title', 'id', 'name')
        hostgroup_cloned_reduced = {
            k: v
            for k, v in hostgroup_cloned.items()
            if k in hostgroup_origin and k not in unique_keys
        }

        assert hostgroup_cloned_reduced.items() <= hostgroup_origin.items()

    @pytest.mark.tier1
    def test_positive_create_with_properties(self, module_org,
                                             module_location):
        """Create a hostgroup with properties

        :id: 528afd01-356a-4082-9e88-a5b2a715a792

        :expectedresults: A hostgroup is created with expected properties,
            updated and deleted

        :CaseLevel: Integration

        :CaseImportance: High
        """
        env = entities.Environment(location=[module_location],
                                   organization=[module_org]).create()
        parent_hostgroup = entities.HostGroup(location=[module_location],
                                              organization=[module_org
                                                            ]).create()
        arch = entities.Architecture().create()
        ptable = entities.PartitionTable().create()
        os = entities.OperatingSystem(architecture=[arch],
                                      ptable=[ptable]).create()
        media = entities.Media(operatingsystem=[os],
                               location=[module_location],
                               organization=[module_org]).create()
        proxy = entities.SmartProxy().search(
            query={'search': f'url = https://{settings.server.hostname}:9090'
                   })[0]
        subnet = entities.Subnet(location=[module_location],
                                 organization=[module_org]).create()
        domain = entities.Domain(location=[module_location],
                                 organization=[module_org]).create()
        content_view = entities.ContentView(organization=module_org).create()
        content_view.publish()
        content_view = content_view.read()
        lce = entities.LifecycleEnvironment(organization=module_org).create()
        promote(content_view.version[0], lce.id)
        hostgroup = entities.HostGroup(
            architecture=arch,
            content_source=proxy,
            content_view=content_view,
            domain=domain,
            environment=env,
            lifecycle_environment=lce,
            location=[module_location],
            medium=media,
            operatingsystem=os,
            organization=[module_org],
            parent=parent_hostgroup,
            ptable=ptable,
            puppet_ca_proxy=proxy,
            puppet_proxy=proxy,
            subnet=subnet,
        ).create()
        assert hostgroup.environment.read().name == env.name
        assert hostgroup.parent.read().name == parent_hostgroup.name
        assert hostgroup.architecture.read().name == arch.name
        assert hostgroup.operatingsystem.read().name == os.name
        assert hostgroup.medium.read().name == media.name
        assert hostgroup.ptable.read().name == ptable.name
        assert hostgroup.puppet_ca_proxy.read().name == proxy.name
        assert hostgroup.subnet.read().name == subnet.name
        assert hostgroup.domain.read().name == domain.name
        assert hostgroup.puppet_proxy.read().name == proxy.name
        assert hostgroup.content_source.read().name == proxy.name
        assert hostgroup.content_view.read().name == content_view.name
        assert hostgroup.lifecycle_environment.read().name == lce.name

        # create new properties for update
        new_org = entities.Organization().create()
        new_loc = entities.Location(organization=[new_org]).create()
        new_arch = entities.Architecture().create()
        new_ptable = entities.PartitionTable().create()
        new_parent = entities.HostGroup(location=[new_loc],
                                        organization=[new_org]).create()
        new_env = entities.Environment(location=[new_loc],
                                       organization=[new_org]).create()
        new_os = entities.OperatingSystem(architecture=[new_arch],
                                          ptable=[new_ptable]).create()
        new_subnet = entities.Subnet(location=[new_loc],
                                     organization=[new_org]).create()
        new_domain = entities.Domain(location=[new_loc],
                                     organization=[new_org]).create()
        new_cv = entities.ContentView(organization=new_org).create()
        new_cv.publish()
        new_cv = new_cv.read()
        new_lce = entities.LifecycleEnvironment(organization=new_org).create()
        promote(new_cv.version[0], new_lce.id)
        new_media = entities.Media(operatingsystem=[os],
                                   location=[new_loc],
                                   organization=[new_org]).create()
        # update itself
        hostgroup.organization = [new_org]
        hostgroup.location = [new_loc]
        hostgroup.lifecycle_environment = new_lce
        hostgroup.content_view = new_cv
        hostgroup.domain = new_domain
        hostgroup.architecture = new_arch
        hostgroup.operatingsystem = new_os
        hostgroup.environment = new_env
        hostgroup.parent = new_parent
        hostgroup.ptable = new_ptable
        hostgroup.subnet = new_subnet
        hostgroup.medium = new_media
        hostgroup = hostgroup.update([
            'parent',
            'environment',
            'operatingsystem',
            'architecture',
            'ptable',
            'subnet',
            'domain',
            'content_view',
            'lifecycle_environment',
            'location',
            'organization',
            'medium',
        ])
        assert hostgroup.parent.read().name == new_parent.name
        assert hostgroup.environment.read().name == new_env.name
        assert hostgroup.operatingsystem.read().name == new_os.name
        assert hostgroup.architecture.read().name == new_arch.name
        assert hostgroup.ptable.read().name == new_ptable.name
        assert hostgroup.subnet.read().name == new_subnet.name
        assert hostgroup.domain.read().name == new_domain.name
        assert hostgroup.content_view.read().name == new_cv.name
        assert hostgroup.lifecycle_environment.read().name == new_lce.name
        assert hostgroup.location[0].read().name == new_loc.name
        assert hostgroup.organization[0].read().name == new_org.name
        assert hostgroup.medium.read().name == new_media.name

        # delete
        hostgroup.delete()
        with pytest.raises(HTTPError):
            hostgroup.read()

    @pytest.mark.stubbed(
        'Remove stub once proper infrastructure will be created')
    @pytest.mark.tier2
    def test_positive_create_with_realm(self, module_org, module_location):
        """Create a hostgroup with realm specified

        :id: 4f07ff8d-746f-4ab5-ae0b-03d629f6296c

        :expectedresults: A hostgroup is created with expected realm assigned

        :CaseLevel: Integration
        """
        realm = entities.Realm(
            location=[module_location],
            organization=[module_org],
            realm_proxy=entities.SmartProxy().search(
                query={
                    'search': f'url = https://{settings.server.hostname}:9090'
                })[0],
        ).create()
        hostgroup = entities.HostGroup(location=[module_location],
                                       organization=[module_org],
                                       realm=realm).create()
        assert hostgroup.realm.read().name == realm.name

    @pytest.mark.tier2
    def test_positive_create_with_locs(self, module_org):
        """Create a hostgroup with multiple locations specified

        :id: 0c2ee2ff-9e7a-4931-8cea-f4eecbd8c4c0

        :expectedresults: A hostgroup is created with expected multiple
            locations assigned

        :CaseLevel: Integration
        """
        locs = [
            entities.Location(organization=[module_org]).create()
            for _ in range(randint(3, 5))
        ]
        hostgroup = entities.HostGroup(location=locs,
                                       organization=[module_org]).create()
        assert {loc.name
                for loc in locs
                } == {loc.read().name
                      for loc in hostgroup.location}

    @pytest.mark.tier2
    def test_positive_create_with_orgs(self):
        """Create a hostgroup with multiple organizations specified

        :id: 09642238-cf0d-469a-a0b5-c167b1b8edf5

        :expectedresults: A hostgroup is created with expected multiple
            organizations assigned

        :CaseLevel: Integration
        """
        orgs = [entities.Organization().create() for _ in range(randint(3, 5))]
        hostgroup = entities.HostGroup(organization=orgs).create()
        assert {org.name
                for org in orgs
                }, {org.read().name
                    for org in hostgroup.organization}

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(valid_hostgroups_list()))
    def test_positive_update_name(self, name, hostgroup):
        """Update a hostgroup with a new name

        :id: 8abb151f-a058-4f47-a1c1-f60a32cd7572

        :parametrized: yes

        :expectedresults: A hostgroup is updated with expected name

        :CaseImportance: Critical
        """
        hostgroup.name = name
        hostgroup = hostgroup.update(['name'])
        assert name == hostgroup.name

    @pytest.mark.tier2
    def test_positive_update_puppet_ca_proxy(self, hostgroup):
        """Update a hostgroup with a new puppet CA proxy

        :id: fd13ab0e-1a5b-48a0-a852-3fff8306271f

        :expectedresults: A hostgroup is updated with expected puppet CA proxy

        :CaseLevel: Integration
        """
        new_proxy = entities.SmartProxy().search(
            query={'search': f'url = https://{settings.server.hostname}:9090'
                   })[0]
        hostgroup.puppet_ca_proxy = new_proxy
        hostgroup = hostgroup.update(['puppet_ca_proxy'])
        assert hostgroup.puppet_ca_proxy.read().name == new_proxy.name

    @pytest.mark.stubbed(
        'Remove stub once proper infrastructure will be created')
    @pytest.mark.tier2
    def test_positive_update_realm(self, module_org, module_location):
        """Update a hostgroup with a new realm

        :id: fd9d141f-7a71-4439-92c7-1dbc1eea4772

        :expectedresults: A hostgroup is updated with expected realm

        :CaseLevel: Integration
        """
        realm = entities.Realm(
            location=[module_location],
            organization=[module_org],
            realm_proxy=entities.SmartProxy().search(
                query={
                    'search': f'url = https://{settings.server.hostname}:9090'
                })[0],
        ).create()
        hostgroup = entities.HostGroup(location=[module_location],
                                       organization=[module_org],
                                       realm=realm).create()
        new_realm = entities.Realm(
            location=[module_location],
            organization=[module_org],
            realm_proxy=entities.SmartProxy().search(
                query={
                    'search': f'url = https://{settings.server.hostname}:9090'
                })[0],
        ).create()
        hostgroup.realm = new_realm
        hostgroup = hostgroup.update(['realm'])
        assert hostgroup.realm.read().name == new_realm.name

    @pytest.mark.tier2
    def test_positive_update_puppet_proxy(self, hostgroup):
        """Update a hostgroup with a new puppet proxy

        :id: 86eca603-2cdd-4563-b6f6-aaa5cea1a723

        :expectedresults: A hostgroup is updated with expected puppet proxy

        :CaseLevel: Integration
        """
        new_proxy = entities.SmartProxy().search(
            query={'search': f'url = https://{settings.server.hostname}:9090'
                   })[0]
        hostgroup.puppet_proxy = new_proxy
        hostgroup = hostgroup.update(['puppet_proxy'])
        assert hostgroup.puppet_proxy.read().name == new_proxy.name

    @pytest.mark.tier2
    def test_positive_update_content_source(self, hostgroup):
        """Update a hostgroup with a new puppet proxy

        :id: 02ef1340-a21e-41b7-8aa7-d6fdea196c16

        :expectedresults: A hostgroup is updated with expected puppet proxy

        :CaseLevel: Integration
        """
        new_content_source = entities.SmartProxy().search(
            query={'search': f'url = https://{settings.server.hostname}:9090'
                   })[0]
        hostgroup.content_source = new_content_source
        hostgroup = hostgroup.update(['content_source'])
        assert hostgroup.content_source.read().name == new_content_source.name

    @pytest.mark.tier2
    def test_positive_update_locs(self, module_org, hostgroup):
        """Update a hostgroup with new multiple locations

        :id: b045f7e8-d7c0-428b-a29c-8d54e53742e2

        :expectedresults: A hostgroup is updated with expected locations

        :CaseLevel: Integration
        """
        new_locs = [
            entities.Location(organization=[module_org]).create()
            for _ in range(randint(3, 5))
        ]
        hostgroup.location = new_locs
        hostgroup = hostgroup.update(['location'])
        assert {loc.name
                for loc in new_locs
                }, {loc.read().name
                    for loc in hostgroup.location}

    @pytest.mark.tier2
    def test_positive_update_orgs(self, hostgroup):
        """Update a hostgroup with new multiple organizations

        :id: 5f6bd4f9-4bd6-4d7e-9a91-de824299020e

        :expectedresults: A hostgroup is updated with expected organizations

        :CaseLevel: Integration
        """
        new_orgs = [
            entities.Organization().create() for _ in range(randint(3, 5))
        ]
        hostgroup.organization = new_orgs
        hostgroup = hostgroup.update(['organization'])
        assert {org.name
                for org in new_orgs
                } == {org.read().name
                      for org in hostgroup.organization}

    @pytest.mark.tier1
    @pytest.mark.parametrize('name', **parametrized(invalid_values_list()))
    def test_negative_create_with_name(self, name, module_org,
                                       module_location):
        """Attempt to create a hostgroup with invalid names

        :id: 3f5aa17a-8db9-4fe9-b309-b8ec5e739da1

        :parametrized: yes

        :expectedresults: A hostgroup is not created

        :CaseImportance: Critical
        """
        with pytest.raises(HTTPError):
            entities.HostGroup(location=[module_location],
                               name=name,
                               organization=[module_org]).create()

    @pytest.mark.tier1
    @pytest.mark.parametrize('new_name', **parametrized(invalid_values_list()))
    def test_negative_update_name(self, new_name, hostgroup):
        """Attempt to update a hostgroup with invalid names

        :id: 6d8c4738-a0c4-472b-9a71-27c8a3832335

        :parametrized: yes

        :expectedresults: A hostgroup is not updated

        :CaseImportance: Critical
        """
        original_name = hostgroup.name
        hostgroup.name = new_name
        with pytest.raises(HTTPError):
            hostgroup.update(['name'])
        assert hostgroup.read().name == original_name

    @pytest.mark.tier2
    def test_positive_create_with_group_parameters(self, module_org):
        """Create a hostgroup with 'group parameters' specified

        :id: 0959e2a2-d635-482b-9b2e-d33990d6f0dc

        :expectedresults: A hostgroup is created with assigned group parameters

        :customerscenario: true

        :CaseLevel: Integration

        :BZ: 1710853
        """
        group_params = {
            'name': gen_string('alpha'),
            'value': gen_string('alpha')
        }
        hostgroup = entities.HostGroup(
            organization=[module_org],
            group_parameters_attributes=[group_params]).create()
        assert group_params['name'] == hostgroup.group_parameters_attributes[
            0]['name']
        assert group_params['value'] == hostgroup.group_parameters_attributes[
            0]['value']