def test_positive_create_with_inherited_params(session): """Create a new Host in organization and location with parameters :BZ: 1287223 :id: 628122f2-bda9-4aa1-8833-55debbd99072 :expectedresults: Host has inherited parameters from organization and location :CaseImportance: High """ org = entities.Organization().create() loc = entities.Location(organization=[org]).create() org_param = dict(name=gen_string('alphanumeric'), value=gen_string('alphanumeric')) loc_param = dict(name=gen_string('alphanumeric'), value=gen_string('alphanumeric')) host_template = entities.Host(organization=org, location=loc) host_template.create_missing() host_name = u'{0}.{1}'.format(host_template.name, host_template.domain.name) with session: session.organization.update(org.name, {'parameters.resources': org_param}) session.location.update(loc.name, {'parameters.resources': loc_param}) session.organization.select(org_name=org.name) session.location.select(loc_name=loc.name) create_fake_host(session, host_template) values = session.host.read(host_name, 'parameters') expected_params = {(org_param['name'], org_param['value']), (loc_param['name'], loc_param['value'])} assert expected_params.issubset( {(param['name'], param['value']) for param in values['parameters']['global_params']} )
def test_positive_create_host_with_parameters(session, module_global_params): """"Create new Host with parameters, override one global parameter and read all parameters. :id: d37be8de-77f0-46c1-a431-bbc4db0eb7f6 :expectedresults: Host is created and has expected parameters values :CaseLevel: Integration """ global_params = [ global_param.to_json_dict( lambda attr, field: attr in ['name', 'value']) for global_param in module_global_params ] host = entities.Host() host.create_missing() host_name = u'{0}.{1}'.format(host.name, host.domain.name) host_parameters = [] for _ in range(2): host_parameters.append( dict(name=gen_string('alpha'), value=gen_string('alphanumeric')) ) expected_host_parameters = copy.deepcopy(host_parameters) # override the first global parameter overridden_global_parameter = { 'name': global_params[0]['name'], 'value': gen_string('alpha') } expected_host_parameters.append(overridden_global_parameter) expected_global_parameters = copy.deepcopy(global_params) for global_param in expected_global_parameters: # update with overridden expected value if global_param['name'] == overridden_global_parameter['name']: global_param['overridden'] = True else: global_param['overridden'] = False with session: session.organization.select(org_name=host.organization.name) session.location.select(loc_name=host.location.name) create_fake_host( session, host, host_parameters=host_parameters, global_parameters=[overridden_global_parameter], ) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name) assert (_get_set_from_list_of_dict(values['parameters']['host_params']) == _get_set_from_list_of_dict(expected_host_parameters)) assert _get_set_from_list_of_dict( expected_global_parameters).issubset( _get_set_from_list_of_dict(values['parameters']['global_params']))
def test_positive_create_host_with_parameters(session, module_global_params): """"Create new Host with parameters, override one global parameter and read all parameters. :id: d37be8de-77f0-46c1-a431-bbc4db0eb7f6 :expectedresults: Host is created and has expected parameters values :CaseLevel: Integration """ global_params = [ global_param.to_json_dict( lambda attr, field: attr in ['name', 'value']) for global_param in module_global_params ] host = entities.Host() host.create_missing() host_name = u'{0}.{1}'.format(host.name, host.domain.name) host_parameters = [] for _ in range(2): host_parameters.append( dict(name=gen_string('alpha'), value=gen_string('alphanumeric'))) expected_host_parameters = copy.deepcopy(host_parameters) # override the first global parameter overridden_global_parameter = { 'name': global_params[0]['name'], 'value': gen_string('alpha') } expected_host_parameters.append(overridden_global_parameter) expected_global_parameters = copy.deepcopy(global_params) for global_param in expected_global_parameters: # update with overridden expected value if global_param['name'] == overridden_global_parameter['name']: global_param['overridden'] = True else: global_param['overridden'] = False with session: session.organization.select(org_name=host.organization.name) session.location.select(loc_name=host.location.name) create_fake_host( session, host, host_parameters=host_parameters, global_parameters=[overridden_global_parameter], ) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name) assert (_get_set_from_list_of_dict(values['parameters']['host_params']) == _get_set_from_list_of_dict(expected_host_parameters)) assert _get_set_from_list_of_dict(expected_global_parameters).issubset( _get_set_from_list_of_dict(values['parameters']['global_params']))
def test_positive_create_with_puppet_class( session, module_host_template, module_org, module_loc): """Create new Host with puppet class assigned to it :id: d883f169-1105-435c-8422-a7160055734a :expectedresults: Host is created and contains correct puppet class :CaseLevel: System """ pc_name = 'generic_1' cv = publish_puppet_module( [{'author': 'robottelo', 'name': pc_name}], CUSTOM_PUPPET_REPO, organization_id=module_org.id ) env = entities.Environment().search(query={ 'search': u'content_view="{0}" and organization_id={1}'.format( cv.name, module_org.id)})[0].read() env = entities.Environment(id=env.id, location=[module_loc]).update(['location']) with session: host_name = create_fake_host( session, module_host_template, extra_values={ 'host.puppet_environment': env.name, 'puppet_classes.classes.assigned': [pc_name] } ) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name, widget_names='puppet_classes') assert len(values['puppet_classes']['classes']['assigned']) == 1 assert values['puppet_classes']['classes']['assigned'][0] == pc_name
def test_positive_end_to_end(session, module_org, module_loc): """Perform end to end testing for hardware model component :id: 93663cc9-7c8f-4f43-8050-444be1313bed :expectedresults: All expected CRUD actions finished successfully :CaseLevel: Integration :CaseImportance: Medium :BZ:1758260 """ name = gen_string('alpha') model = gen_string('alphanumeric') vendor_class = gen_string('alpha') info = gen_string('alpha') new_name = gen_string('alpha') host_template = entities.Host(organization=module_org, location=module_loc) host_template.create_missing() with session: # Create new hardware model session.hardwaremodel.create({ 'name': name, 'hardware_model': model, 'vendor_class': vendor_class, 'info': info, }) assert session.hardwaremodel.search(name)[0]['Name'] == name hm_values = session.hardwaremodel.read(name) assert hm_values['name'] == name assert hm_values['hardware_model'] == model assert hm_values['vendor_class'] == vendor_class assert hm_values['info'] == info # Create host with associated hardware model host_name = create_fake_host( session, host_template, extra_values={'additional_information.hardware_model': name}) host_values = session.host.read(host_name, 'additional_information') assert host_values['additional_information']['hardware_model'] == name # Update hardware model with new name session.hardwaremodel.update(name, {'name': new_name}) assert session.hardwaremodel.search(new_name)[0]['Name'] == new_name host_values = session.host.read(host_name, 'additional_information') assert host_values['additional_information'][ 'hardware_model'] == new_name # Make an attempt to delete hardware model that associated with host with raises(AssertionError) as context: session.hardwaremodel.delete(new_name) assert "error: '{} is used by {}'".format(new_name, host_name) in str( context.value) session.host.update(host_name, {'additional_information.hardware_model': ''}) # Delete hardware model session.hardwaremodel.delete(new_name) assert not session.hardwaremodel.search(new_name)
def test_positive_end_to_end(session, module_org, module_loc): """Perform end to end testing for hardware model component :id: 93663cc9-7c8f-4f43-8050-444be1313bed :expectedresults: All expected CRUD actions finished successfully :CaseLevel: Integration :CaseImportance: High """ name = gen_string('alpha') model = gen_string('alphanumeric') vendor_class = gen_string('alpha') info = gen_string('alpha') new_name = gen_string('alpha') host_template = entities.Host(organization=module_org, location=module_loc) host_template.create_missing() with session: # Create new hardware model session.hardwaremodel.create({ 'name': name, 'hardware_model': model, 'vendor_class': vendor_class, 'info': info, }) assert session.hardwaremodel.search(name)[0]['Name'] == name hm_values = session.hardwaremodel.read(name) assert hm_values['name'] == name assert hm_values['hardware_model'] == model assert hm_values['vendor_class'] == vendor_class assert hm_values['info'] == info # Create host with associated hardware model host_name = create_fake_host( session, host_template, extra_values={'additional_information.hardware_model': name} ) host_values = session.host.read(host_name, 'additional_information') assert host_values['additional_information']['hardware_model'] == name # Update hardware model with new name session.hardwaremodel.update(name, {'name': new_name}) assert session.hardwaremodel.search(new_name)[0]['Name'] == new_name host_values = session.host.read(host_name, 'additional_information') assert host_values['additional_information']['hardware_model'] == new_name # Make an attempt to delete hardware model that associated with host with raises(AssertionError) as context: session.hardwaremodel.delete(new_name) assert "error: '{} is used by {}'".format( new_name, host_name) in str(context.value) session.host.update(host_name, {'additional_information.hardware_model': ''}) # Delete hardware model session.hardwaremodel.delete(new_name) assert not session.hardwaremodel.search(new_name)
def test_positive_generate_registered_hosts_report(session, module_org, module_loc): """Use provided Registered Hosts report for testing :id: b44d4cd8-a78e-47cf-9993-0bb871ac2c96 :expectedresults: The Registered Hosts report is generated (with host filter) and it contains created host with correct data :CaseLevel: Integration :CaseImportance: High """ # generate Host Status report os_name = 'comma,' + gen_string('alpha') os = entities.OperatingSystem(name=os_name).create() host_cnt = 3 host_templates = [ entities.Host(organization=module_org, location=module_loc, operatingsystem=os) for i in range(host_cnt) ] for host_template in host_templates: host_template.create_missing() with session: # create multiple hosts to test filtering host_names = [ create_fake_host(session, host_template) for host_template in host_templates ] host_name = host_names[ 1] # pick some that is not first and is not last file_path = session.reporttemplate.generate( "Registered hosts", values={'inputs': { 'Hosts filter': host_name }}) with open(file_path) as csvfile: dreader = csv.DictReader(csvfile) res = next(dreader) assert list(res.keys()) == [ 'Name', 'Ip', 'Operating System', 'Subscriptions', 'Applicable Errata', 'Owner', 'Kernel', 'Latest kernel available', ] assert res['Name'] == host_name # also tests comma in field contents assert res['Operating System'] == '{0} {1}'.format( os_name, os.major)
def test_positive_create(session, module_host_template): """Create a new Host :id: 4821444d-3c86-4f93-849b-60460e025ba0 :expectedresults: Host is created :CaseLevel: System """ with session: host_name = create_fake_host(session, module_host_template) assert session.host.search(host_name)[0]['Name'] == host_name
def test_positive_create(session, module_host_template): """Create a new Host :id: 4821444d-3c86-4f93-849b-60460e025ba0 :expectedresults: Host is created :CaseLevel: System """ with session: host_name = create_fake_host(session, module_host_template) assert session.host.search(host_name)[0]['Name'] == host_name
def test_positive_delete(session, module_host_template): """Delete a Host :id: 13735af1-f1c7-466e-a969-80618a1d854d :expectedresults: Host is delete :CaseLevel: System """ with session: host_name = create_fake_host(session, module_host_template) assert session.host.search(host_name)[0]['Name'] == host_name session.host.delete(host_name) assert not session.host.search(host_name)
def test_positive_delete(session, module_host_template): """Delete a Host :id: 13735af1-f1c7-466e-a969-80618a1d854d :expectedresults: Host is delete :CaseLevel: System """ with session: host_name = create_fake_host(session, module_host_template) assert session.host.search(host_name)[0]['Name'] == host_name session.host.delete(host_name) assert not session.host.search(host_name)
def test_positive_create_with_inherited_params(session): """Create a new Host in organization and location with parameters :BZ: 1287223 :id: 628122f2-bda9-4aa1-8833-55debbd99072 :expectedresults: Host has inherited parameters from organization and location :CaseImportance: High """ org = entities.Organization().create() loc = entities.Location(organization=[org]).create() org_param = dict(name=gen_string('alphanumeric'), value=gen_string('alphanumeric')) loc_param = dict(name=gen_string('alphanumeric'), value=gen_string('alphanumeric')) host_template = entities.Host(organization=org, location=loc) host_template.create_missing() host_name = u'{0}.{1}'.format(host_template.name, host_template.domain.name) with session: session.organization.update(org.name, {'parameters.resources': org_param}) session.location.update(loc.name, {'parameters.resources': loc_param}) session.organization.select(org_name=org.name) session.location.select(loc_name=loc.name) create_fake_host(session, host_template) values = session.host.read(host_name, 'parameters') expected_params = {(org_param['name'], org_param['value']), (loc_param['name'], loc_param['value'])} assert expected_params.issubset({ (param['name'], param['value']) for param in values['parameters']['global_params'] })
def test_positive_update_name(session, module_host_template): """Create a new Host and update its name to valid one :id: f1c19599-f613-431d-bf09-62addec1e60b :expectedresults: Host is updated successfully :CaseLevel: Integration """ new_name = gen_string('alpha').lower() new_host_name = '{0}.{1}'.format(new_name, module_host_template.domain.name) with session: host_name = create_fake_host(session, module_host_template) assert session.host.search(host_name)[0]['Name'] == host_name session.host.update(host_name, {'host.name': new_name}) assert not session.host.search(host_name) assert session.host.search(new_host_name)[0]['Name'] == new_host_name
def test_positive_update_name(session, module_host_template): """Create a new Host and update its name to valid one :id: f1c19599-f613-431d-bf09-62addec1e60b :expectedresults: Host is updated successfully :CaseLevel: Integration """ new_name = gen_string('alpha').lower() new_host_name = '{0}.{1}'.format(new_name, module_host_template.domain.name) with session: host_name = create_fake_host(session, module_host_template) assert session.host.search(host_name)[0]['Name'] == host_name session.host.update(host_name, {'host.name': new_name}) assert not session.host.search(host_name) assert session.host.search(new_host_name)[0]['Name'] == new_host_name
def test_negative_delete_primary_interface(session, module_host_template): """Attempt to delete primary interface of a host :id: bc747e2c-38d9-4920-b4ae-6010851f704e :customerscenario: true :BZ: 1417119 :expectedresults: Interface was not deleted :CaseLevel: System """ interface_id = gen_string('alpha') with session: host_name = create_fake_host(session, module_host_template, interface_id=interface_id) with pytest.raises(DisabledWidgetError) as context: session.host.delete_interface(host_name, interface_id) assert 'Interface Delete button is disabled' in str(context.value)
def test_positive_read_from_edit_page(session, module_host_template): """Create new Host and read all its content through edit page :id: 758fcab3-b363-4bfc-8f5d-173098a7e72d :expectedresults: Host is created and has expected content :CaseLevel: System """ os_name = u'{0} {1}'.format(module_host_template.operatingsystem.name, module_host_template.operatingsystem.major) interface_id = gen_string('alpha') with session: host_name = create_fake_host(session, module_host_template, interface_id) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name) assert values['host']['name'] == host_name.partition('.')[0] assert values['host'][ 'organization'] == module_host_template.organization.name assert values['host']['location'] == module_host_template.location.name assert values['host']['lce'] == ENVIRONMENT assert values['host']['content_view'] == DEFAULT_CV assert values['host'][ 'puppet_environment'] == module_host_template.environment.name assert values['operating_system'][ 'architecture'] == module_host_template.architecture.name assert values['operating_system']['operating_system'] == os_name assert values['operating_system']['media_type'] == 'All Media' assert values['operating_system'][ 'media'] == module_host_template.medium.name assert values['operating_system'][ 'ptable'] == module_host_template.ptable.name assert values['interfaces']['interfaces_list'][0][ 'Identifier'] == interface_id assert values['interfaces']['interfaces_list'][0][ 'Type'] == 'Interface physical' assert values['interfaces']['interfaces_list'][0][ 'MAC Address'] == module_host_template.mac assert values['interfaces']['interfaces_list'][0]['FQDN'] == host_name assert values['additional_information']['owned_by'] == values[ 'current_user'] assert values['additional_information']['enabled'] is True
def test_positive_update_name_with_prefix(session, module_host_template): """Create a new Host and update its name to valid one. Host should contain word 'new' in its name :id: b08cb5c9-bd2c-4dc7-97b1-d1f20d1373d7 :expectedresults: Host is updated successfully :BZ: 1419161 :CaseLevel: Integration """ new_name = 'new{0}'.format(gen_string("alpha").lower()) new_host_name = '{0}.{1}'.format(new_name, module_host_template.domain.name) with session: host_name = create_fake_host(session, module_host_template) assert session.host.search(host_name)[0]['Name'] == host_name session.host.update(host_name, {'host.name': new_name}) assert not session.host.search(host_name) assert session.host.search(new_host_name)[0]['Name'] == new_host_name
def test_positive_create_with_config_group(session, module_host_template): """Create new Host with config group assigned to it :id: 8834011e-f920-43de-8f28-1f370b2b8d69 :expectedresults: Host is created and contains correct config group :CaseLevel: System """ config_group = entities.ConfigGroup().create() with session: host_name = create_fake_host( session, module_host_template, extra_values={'puppet_classes.config_groups.assigned': [config_group.name]} ) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name, widget_names='puppet_classes') assert len(values['puppet_classes']['config_groups']['assigned']) == 1 assert values['puppet_classes']['config_groups']['assigned'][0] == config_group.name
def test_negative_delete_primary_interface(session, module_host_template): """Attempt to delete primary interface of a host :id: bc747e2c-38d9-4920-b4ae-6010851f704e :customerscenario: true :BZ: 1417119 :expectedresults: Interface was not deleted :CaseLevel: System """ interface_id = gen_string('alpha') with session: host_name = create_fake_host(session, module_host_template, interface_id=interface_id) with pytest.raises(DisabledWidgetError) as context: session.host.delete_interface(host_name, interface_id) assert 'Interface Delete button is disabled' in str(context.value)
def test_positive_update_name_with_prefix(session, module_host_template): """Create a new Host and update its name to valid one. Host should contain word 'new' in its name :id: b08cb5c9-bd2c-4dc7-97b1-d1f20d1373d7 :expectedresults: Host is updated successfully :BZ: 1419161 :CaseLevel: Integration """ new_name = 'new{0}'.format(gen_string("alpha").lower()) new_host_name = '{0}.{1}'.format(new_name, module_host_template.domain.name) with session: host_name = create_fake_host(session, module_host_template) assert session.host.search(host_name)[0]['Name'] == host_name session.host.update(host_name, {'host.name': new_name}) assert not session.host.search(host_name) assert session.host.search(new_host_name)[0]['Name'] == new_host_name
def test_positive_create_with_config_group(session, module_host_template): """Create new Host with config group assigned to it :id: 8834011e-f920-43de-8f28-1f370b2b8d69 :expectedresults: Host is created and contains correct config group :CaseLevel: System """ config_group = entities.ConfigGroup().create() with session: host_name = create_fake_host( session, module_host_template, extra_values={ 'puppet_classes.config_groups.assigned': [config_group.name] }) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name, widget_names='puppet_classes') assert len(values['puppet_classes']['config_groups']['assigned']) == 1 assert values['puppet_classes']['config_groups']['assigned'][ 0] == config_group.name
def test_positive_read_from_edit_page(session, module_host_template): """Create new Host and read all its content through edit page :id: 758fcab3-b363-4bfc-8f5d-173098a7e72d :expectedresults: Host is created and has expected content :CaseLevel: System """ os_name = u'{0} {1}'.format( module_host_template.operatingsystem.name, module_host_template.operatingsystem.major) interface_id = gen_string('alpha') with session: host_name = create_fake_host(session, module_host_template, interface_id) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name) assert values['host']['name'] == host_name.partition('.')[0] assert values['host']['organization'] == module_host_template.organization.name assert values['host']['location'] == module_host_template.location.name assert values['host']['lce'] == ENVIRONMENT assert values['host']['content_view'] == DEFAULT_CV assert values['host']['puppet_environment'] == module_host_template.environment.name assert values[ 'operating_system']['architecture'] == module_host_template.architecture.name assert values['operating_system']['operating_system'] == os_name assert values['operating_system']['media_type'] == 'All Media' assert values['operating_system']['media'] == module_host_template.medium.name assert values['operating_system']['ptable'] == module_host_template.ptable.name assert values['interfaces']['interfaces_list'][0][ 'Identifier'] == interface_id assert values['interfaces']['interfaces_list'][0][ 'Type'] == 'Interface physical' assert values['interfaces']['interfaces_list'][0][ 'MAC Address'] == module_host_template.mac assert values['interfaces']['interfaces_list'][0][ 'FQDN'] == host_name assert values['additional_information'][ 'owned_by'] == values['current_user'] assert values['additional_information']['enabled'] is True
def test_positive_create_with_puppet_class(session, module_host_template, module_org, module_loc): """Create new Host with puppet class assigned to it :id: d883f169-1105-435c-8422-a7160055734a :expectedresults: Host is created and contains correct puppet class :CaseLevel: System """ pc_name = 'generic_1' cv = publish_puppet_module([{ 'author': 'robottelo', 'name': pc_name }], CUSTOM_PUPPET_REPO, organization_id=module_org.id) env = entities.Environment().search( query={ 'search': u'content_view="{0}" and organization_id={1}'.format( cv.name, module_org.id) })[0].read() env = entities.Environment(id=env.id, location=[module_loc]).update(['location']) with session: host_name = create_fake_host(session, module_host_template, extra_values={ 'host.puppet_environment': env.name, 'puppet_classes.classes.assigned': [pc_name] }) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.read(host_name, widget_names='puppet_classes') assert len(values['puppet_classes']['classes']['assigned']) == 1 assert values['puppet_classes']['classes']['assigned'][0] == pc_name
def test_positive_read_from_details_page(session, module_host_template): """Create new Host and read all its content through details page :id: ffba5d40-918c-440e-afbb-6b910db3a8fb :expectedresults: Host is created and has expected content :CaseLevel: System """ os_name = u'{0} {1}'.format(module_host_template.operatingsystem.name, module_host_template.operatingsystem.major) interface_id = gen_string('alpha') with session: host_name = create_fake_host(session, module_host_template, interface_id) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.get_details(host_name) assert values['properties']['properties_table']['Status'] == 'OK' assert values['properties']['properties_table'][ 'Build'] == 'Pending installation' assert values['properties']['properties_table'][ 'Domain'] == module_host_template.domain.name assert values['properties']['properties_table'][ 'MAC Address'] == module_host_template.mac assert values['properties']['properties_table'][ 'Puppet Environment'] == module_host_template.environment.name assert values['properties']['properties_table'][ 'Architecture'] == module_host_template.architecture.name assert values['properties']['properties_table'][ 'Operating System'] == os_name assert values['properties']['properties_table'][ 'Location'] == module_host_template.location.name assert values['properties']['properties_table'][ 'Organization'] == module_host_template.organization.name assert values['properties']['properties_table']['Owner'] == values[ 'current_user']
def test_positive_read_from_details_page(session, module_host_template): """Create new Host and read all its content through details page :id: ffba5d40-918c-440e-afbb-6b910db3a8fb :expectedresults: Host is created and has expected content :CaseLevel: System """ os_name = u'{0} {1}'.format( module_host_template.operatingsystem.name, module_host_template.operatingsystem.major) interface_id = gen_string('alpha') with session: host_name = create_fake_host(session, module_host_template, interface_id) assert session.host.search(host_name)[0]['Name'] == host_name values = session.host.get_details(host_name) assert values['properties']['properties_table'][ 'Status'] == 'OK' assert values['properties']['properties_table'][ 'Build'] == 'Pending installation' assert values['properties']['properties_table'][ 'Domain'] == module_host_template.domain.name assert values['properties']['properties_table'][ 'MAC Address'] == module_host_template.mac assert values['properties']['properties_table'][ 'Puppet Environment'] == module_host_template.environment.name assert values['properties']['properties_table'][ 'Architecture'] == module_host_template.architecture.name assert values['properties']['properties_table'][ 'Operating System'] == os_name assert values['properties']['properties_table'][ 'Location'] == module_host_template.location.name assert values['properties']['properties_table'][ 'Organization'] == module_host_template.organization.name assert values['properties']['properties_table'][ 'Owner'] == values['current_user']