Beispiel #1
0
    def test_gen_mac_6(self):
        """
        @Test: Generate a MAC address using a number as the delimiter
        @Feature: MAC Generator
        @Assert: A MAC address is not generated using an invalid delimiter
        """

        with self.assertRaises(ValueError):
            gen_mac(delimiter=random.randint(0, 10))
Beispiel #2
0
    def test_gen_mac_5(self):
        """
        @Test: Generate a MAC address using \" \" as the delimiter
        @Feature: MAC Generator
        @Assert: A MAC address is not generated using an invalid delimiter
        """

        with self.assertRaises(ValueError):
            gen_mac(delimiter=" ")
Beispiel #3
0
    def test_gen_mac_6(self):
        """
        @Test: Generate a MAC address using a number as the delimiter
        @Feature: MAC Generator
        @Assert: A MAC address is not generated using an invalid delimiter
        """

        with self.assertRaises(ValueError):
            gen_mac(delimiter=random.randint(0, 10))
Beispiel #4
0
    def test_gen_mac_7(self):
        """
        @Test: Generate a MAC address using a letter as the delimiter
        @Feature: MAC Generator
        @Assert: A MAC address is not generated using an invalid delimiter
        """

        with self.assertRaises(ValueError):
            gen_mac(delimiter=random.choice(string.ascii_letters))
Beispiel #5
0
    def test_gen_mac_5(self):
        """
        @Test: Generate a MAC address using \" \" as the delimiter
        @Feature: MAC Generator
        @Assert: A MAC address is not generated using an invalid delimiter
        """

        with self.assertRaises(ValueError):
            gen_mac(delimiter=" ")
Beispiel #6
0
    def test_gen_mac_7(self):
        """
        @Test: Generate a MAC address using a letter as the delimiter
        @Feature: MAC Generator
        @Assert: A MAC address is not generated using an invalid delimiter
        """

        with self.assertRaises(ValueError):
            gen_mac(
                delimiter=random.choice(string.ascii_letters))
Beispiel #7
0
def create_discovered_host(name=None,
                           ip_address=None,
                           mac_address=None,
                           options=None):
    """Creates a discovered host.

    :param str name: Name of discovered host.
    :param str ip_address: A valid ip address.
    :param str mac_address: A valid mac address.
    :param dict options: additional facts to add to discovered host
    :return: dict of ``entities.DiscoveredHost`` facts.
    """
    if name is None:
        name = gen_string('alpha')
    if ip_address is None:
        ip_address = gen_ipaddr()
    if mac_address is None:
        mac_address = gen_mac(multicast=False)
    if options is None:
        options = {}
    facts = {
        'name': name,
        'discovery_bootip': ip_address,
        'discovery_bootif': mac_address,
        'interfaces': 'eth0',
        'ipaddress': ip_address,
        'ipaddress_eth0': ip_address,
        'macaddress': mac_address,
        'macaddress_eth0': mac_address,
    }
    facts.update(options)
    return entities.DiscoveredHost().facts(json={'facts': facts})
Beispiel #8
0
def create_discovered_host(name=None, ip_address=None, mac_address=None,
                           options=None):
    """Creates a discovered host.

    :param str name: Name of discovered host.
    :param str ip_address: A valid ip address.
    :param str mac_address: A valid mac address.
    :param dict options: additional facts to add to discovered host
    :returns dict of ``entities.DiscoveredHost`` facts.
    """
    if name is None:
        name = gen_string('alpha')
    if ip_address is None:
        ip_address = gen_ipaddr()
    if mac_address is None:
        mac_address = gen_mac(multicast=False)
    if options is None:
        options = {}
    facts = {
            'name': name,
            'discovery_bootip': ip_address,
            'discovery_bootif': mac_address,
            'interfaces': 'eth0',
            'ipaddress': ip_address,
            'ipaddress_eth0': ip_address,
            'macaddress': mac_address,
            'macaddress_eth0': mac_address,
        }
    facts.update(options)
    return entities.DiscoveredHost().facts(json={'facts': facts})
Beispiel #9
0
def generate_system_facts(name=None):
    """Generate random system facts for registration.

    :param str name: A valid FQDN for a system. If one is not
        provided, then a random value will be generated.
    :return: A dictionary with random system facts
    :rtype: dict
    """
    if name is None:
        name = f'{gen_alpha().lower()}.example.net'

    # Make a copy of the system facts 'template'
    new_facts = copy.deepcopy(SYSTEM_FACTS)
    # Select a random RHEL version...
    distro = gen_choice(DISTRO_IDS)

    # ...and update our facts
    new_facts['distribution.id'] = distro['id']
    new_facts['distribution.version'] = distro['version']
    new_facts['dmi.bios.relase_date'] = _bios_date().strftime('%m/%d/%Y')
    new_facts['dmi.memory.maximum_capacity'] = gen_choice(MEMORY_CAPACITY)
    new_facts['dmi.memory.size'] = gen_choice(MEMORY_SIZE)
    new_facts['dmi.system.uuid'] = gen_uuid()
    new_facts['dmi.system.version'] = 'RHEL'
    new_facts['lscpu.architecture'] = distro['architecture']
    new_facts['net.interface.eth1.hwaddr'] = gen_mac(multicast=False)
    new_facts['net.interface.eth1.ipaddr'] = gen_ipaddr()
    new_facts['network.hostname'] = name
    new_facts['network.ipaddr'] = new_facts['net.interface.eth1.ipaddr']
    new_facts['uname.machine'] = distro['architecture']
    new_facts['uname.nodename'] = name
    new_facts['uname.release'] = distro['kernel']
    new_facts['virt.uuid'] = new_facts['dmi.system.uuid']

    return new_facts
def _create_discovered_host(name=None, ipaddress=None, macaddress=None):
    """Creates discovered host by uploading few fake facts.

    :param str name: Name of discovered host. If ``None`` then a random
        value will be generated.
    :param str ipaddress: A valid ip address.
        If ``None`` then then a random value will be generated.
    :param str macaddress: A valid mac address.
        If ``None`` then then a random value will be generated.
    :return: A ``dict`` of ``DiscoveredHost`` facts.
    """
    if name is None:
        name = gen_string('alpha')
    if ipaddress is None:
        ipaddress = gen_ipaddr()
    if macaddress is None:
        macaddress = gen_mac(multicast=False)
    return entities.DiscoveredHost().facts(json={
        u'facts': {
            u'name': name,
            u'discovery_bootip': ipaddress,
            u'discovery_bootif': macaddress,
            u'interfaces': 'eth0',
            u'ipaddress': ipaddress,
            u'macaddress': macaddress,
            u'macaddress_eth0': macaddress,
            u'ipaddress_eth0': ipaddress,
        }
    })
    def attach_nic(self):
        """Add a new NIC to existing host"""
        if not self._created:
            raise LibvirtGuestError(
                'The virtual guest should be created before updating it'
            )
        nic_mac = gen_mac(multicast=False, locally=True)
        command_args = [
            'virsh attach-interface',
            '--domain={vm_name}',
            '--type=bridge',
            '--source={vm_bridge}',
            '--model=virtio',
            '--mac={vm_mac}',
            '--config',
        ]
        command = u' '.join(command_args).format(
            vm_name=self.hostname,
            vm_bridge=self.bridge,
            vm_mac=nic_mac,
        )

        result = ssh.command(command, self.libvirt_server)

        if result.return_code != 0:
            raise LibvirtGuestError(
                u'Failed to run virsh attach-interface: {0}'
                .format(result.stderr))
Beispiel #12
0
def _create_discovered_host(name=None, ipaddress=None, macaddress=None):
    """Creates discovered host by uploading few fake facts.

    :param str name: Name of discovered host. If ``None`` then a random
        value will be generated.
    :param str ipaddress: A valid ip address.
        If ``None`` then then a random value will be generated.
    :param str macaddress: A valid mac address.
        If ``None`` then then a random value will be generated.
    :return: A ``dict`` of ``DiscoveredHost`` facts.
    """
    if name is None:
        name = gen_string('alpha')
    if ipaddress is None:
        ipaddress = gen_ipaddr()
    if macaddress is None:
        macaddress = gen_mac(multicast=False)
    return entities.DiscoveredHost().facts(
        json={
            u'facts': {
                u'name': name,
                u'discovery_bootip': ipaddress,
                u'discovery_bootif': macaddress,
                u'interfaces': 'eth0',
                u'ipaddress': ipaddress,
                u'macaddress': macaddress,
                u'macaddress_eth0': macaddress,
                u'ipaddress_eth0': ipaddress,
            }
        })
Beispiel #13
0
def test_positive_create_and_update_mac():
    """Create host with MAC address and update it

    :id: 72e3b020-7347-4500-8669-c6ddf6dfd0b6

    :expectedresults: A host is created with MAC address updated with a new MAC address

    :CaseImportance: Critical
    """

    mac = gen_mac(multicast=False)
    host = entities.Host(mac=mac).create()
    assert host.mac == mac
    new_mac = gen_mac(multicast=False)
    host.mac = new_mac
    host = host.update(['mac'])
    assert host.mac == new_mac
Beispiel #14
0
def _gen_mac_for_libvirt():
    # fe:* MAC range is considered reserved in libvirt
    for _ in range(0, 10):
        mac = gen_mac(multicast=False, locally=True)
        if not mac.startswith('fe'):
            return mac
        mac = None
    if not mac:
        raise ValueError('Unable to generate a valid MAC address')
Beispiel #15
0
 def test_gen_mac_multicast_globally_unique(self):
     """
     @Test: Generate a multicast and globally unique MAC address
     @Feature: MAC Generator
     @Assert: A multicast and globally unique MAC address is generated
     """
     mac = gen_mac(multicast=True, locally=False)
     first_octect = int(mac.split(':', 1)[0], 16)
     mask = 0b00000011
     self.assertEqual(first_octect & mask, 1)
Beispiel #16
0
 def test_gen_mac_multicast_locally_administered(self):
     """
     @Test: Generate a multicast and locally administered MAC address
     @Feature: MAC Generator
     @Assert: A multicast and locally administered MAC address is generated
     """
     mac = gen_mac(multicast=True, locally=True)
     first_octect = int(mac.split(':', 1)[0], 16)
     mask = 0b00000011
     self.assertEqual(first_octect & mask, 3)
Beispiel #17
0
    def test_positive_update_mac(self):
        """Update a host with a new MAC address

        @id: 72e3b020-7347-4500-8669-c6ddf6dfd0b6

        @assert: A host is updated with a new MAC address
        """
        host = entities.Host().create()
        new_mac = gen_mac()
        host.mac = new_mac
        host = host.update(['mac'])
        self.assertEqual(host.mac, new_mac)
Beispiel #18
0
    def test_positive_update_mac(self):
        """Update a host with a new MAC address

        @feature: Hosts

        @assert: A host is updated with a new MAC address
        """
        host = entities.Host().create()
        new_mac = gen_mac()
        host.mac = new_mac
        host = host.update(['mac'])
        self.assertEqual(host.mac, new_mac)
Beispiel #19
0
    def test_positive_update_mac(self):
        """Update a host with a new MAC address

        @id: 72e3b020-7347-4500-8669-c6ddf6dfd0b6

        @assert: A host is updated with a new MAC address
        """
        host = entities.Host().create()
        new_mac = gen_mac()
        host.mac = new_mac
        host = host.update(['mac'])
        self.assertEqual(host.mac, new_mac)
Beispiel #20
0
    def test_gen_mac_3(self):
        """
        @Test: Generate a MAC address using \"-\" as the delimiter
        @Feature: MAC Generator
        @Assert: A MAC address is generated using \"-\" as the delimiter
        """

        result = gen_mac(delimiter="-")
        self.assertTrue(
            len(result.split("-")) == 6, "Did not generate a MAC addrss")
        self.assertIsNotNone(
            mac.match(result),
            "Did not match regular expression for MAC address")
Beispiel #21
0
    def test_gen_mac_3(self):
        """
        @Test: Generate a MAC address using \"-\" as the delimiter
        @Feature: MAC Generator
        @Assert: A MAC address is generated using \"-\" as the delimiter
        """

        result = gen_mac(delimiter="-")
        self.assertTrue(
            len(result.split("-")) == 6,
            "Did not generate a MAC addrss")
        self.assertIsNotNone(
            mac.match(result),
            "Did not match regular expression for MAC address")
Beispiel #22
0
def test_positive_discovered_host(session):
    """Check if the Discovered Host widget is working in the Dashboard UI

    :id: 74afef58-71f4-49e1-bbb6-6d4355d385f8

    :Steps:

        1. Create a Discovered Host.
        2. Navigate Monitor -> Dashboard
        3. Review the Discovered Host Status.

    :expectedresults: The widget is updated with all details.

    :CaseLevel: Integration
    """
    org = entities.Organization().create()
    loc = entities.Location(organization=[org]).create()
    ipaddress = gen_ipaddr()
    macaddress = gen_mac(multicast=False)
    model = gen_string('alpha', length=5)
    host_name = 'mac{0}'.format(macaddress.replace(':', ''))
    entities.DiscoveredHost().facts(json={
        u'facts': {
            u'name': gen_string('alpha'),
            u'discovery_bootip': ipaddress,
            u'discovery_bootif': macaddress,
            u'interfaces': 'eth0',
            u'ipaddress': ipaddress,
            u'macaddress': macaddress,
            u'macaddress_eth0': macaddress,
            u'ipaddress_eth0': ipaddress,
            u'foreman_organization': org.name,
            u'foreman_location': loc.name,
            u'model': model,
            u'memorysize_mb': 1000,
            u'physicalprocessorcount': 2,
        }
    })

    with session:
        session.organization.select(org_name=org.name)
        session.location.select(loc_name=loc.name)
        values = session.dashboard.read('DiscoveredHosts')
        assert len(values['hosts']) == 1
        assert values['hosts_count'] == '1 Discovered Host'
        assert values['hosts'][0]['Host'] == host_name
        assert values['hosts'][0]['Model'] == model
        assert values['hosts'][0]['CPUs'] == '2'
        assert values['hosts'][0]['Memory'] == '1000 MB'
Beispiel #23
0
def test_positive_discovered_host(session):
    """Check if the Discovered Host widget is working in the Dashboard UI

    :id: 74afef58-71f4-49e1-bbb6-6d4355d385f8

    :Steps:

        1. Create a Discovered Host.
        2. Navigate Monitor -> Dashboard
        3. Review the Discovered Host Status.

    :expectedresults: The widget is updated with all details.

    :CaseLevel: Integration
    """
    org = entities.Organization().create()
    loc = entities.Location(organization=[org]).create()
    ipaddress = gen_ipaddr()
    macaddress = gen_mac(multicast=False)
    model = gen_string('alpha', length=5)
    host_name = 'mac{0}'.format(macaddress.replace(':', ''))
    entities.DiscoveredHost().facts(json={
        u'facts': {
            u'name': gen_string('alpha'),
            u'discovery_bootip': ipaddress,
            u'discovery_bootif': macaddress,
            u'interfaces': 'eth0',
            u'ipaddress': ipaddress,
            u'macaddress': macaddress,
            u'macaddress_eth0': macaddress,
            u'ipaddress_eth0': ipaddress,
            u'foreman_organization': org.name,
            u'foreman_location': loc.name,
            u'model': model,
            u'memorysize_mb': 1000,
            u'physicalprocessorcount': 2,
        }
    })

    with session:
        session.organization.select(org_name=org.name)
        session.location.select(loc_name=loc.name)
        values = session.dashboard.read('DiscoveredHosts')
        assert len(values['hosts']) == 1
        assert values['hosts_count'] == '1 Discovered Host'
        assert values['hosts'][0]['Host'] == host_name
        assert values['hosts'][0]['Model'] == model
        assert values['hosts'][0]['CPUs'] == '2'
        assert values['hosts'][0]['Memory'] == '1000 MB'
Beispiel #24
0
    def test_positive_update_mac_by_name(self):
        """A host can be updated with a new random MAC address. Use name
        to access the host

        @id: a422788d-5473-4846-a86b-90d8f236285a

        @assert: A host is updated and the MAC address matches
        """
        new_mac = gen_mac()
        Host.update({
            'mac': new_mac,
            'name': self.host['name'],
        })
        self.host = Host.info({'name': self.host['name']})
        self.assertEqual(self.host['network']['mac'], new_mac)
Beispiel #25
0
    def test_positive_update_mac_by_id(self):
        """A host can be updated with a new random MAC address. Use id
        to access the host

        @id: 72ed9ae8-989a-46d1-8b7d-46f5db106e75

        @assert: A host is updated and the MAC address matches
        """
        new_mac = gen_mac()
        Host.update({
            'id': self.host['id'],
            'mac': new_mac,
        })
        self.host = Host.info({'id': self.host['id']})
        self.assertEqual(self.host['network']['mac'], new_mac)
Beispiel #26
0
    def test_positive_update_mac_by_name(self):
        """A host can be updated with a new random MAC address. Use name
        to access the host

        @id: a422788d-5473-4846-a86b-90d8f236285a

        @assert: A host is updated and the MAC address matches
        """
        new_mac = gen_mac()
        Host.update({
            'mac': new_mac,
            'name': self.host['name'],
        })
        self.host = Host.info({'name': self.host['name']})
        self.assertEqual(self.host['network']['mac'], new_mac)
Beispiel #27
0
    def test_positive_update_mac_by_name(self):
        """A host can be updated with a new random MAC address. Use name
        to access the host

        @feature: Hosts

        @assert: A host is updated and the MAC address matches
        """
        new_mac = gen_mac()
        Host.update({
            'mac': new_mac,
            'name': self.host['name'],
        })
        self.host = Host.info({'name': self.host['name']})
        self.assertEqual(self.host['mac'], new_mac)
Beispiel #28
0
    def test_positive_update_mac_by_id(self):
        """A host can be updated with a new random MAC address. Use id
        to access the host

        @id: 72ed9ae8-989a-46d1-8b7d-46f5db106e75

        @assert: A host is updated and the MAC address matches
        """
        new_mac = gen_mac()
        Host.update({
            'id': self.host['id'],
            'mac': new_mac,
        })
        self.host = Host.info({'id': self.host['id']})
        self.assertEqual(self.host['network']['mac'], new_mac)
Beispiel #29
0
    def test_positive_update_mac_by_name(self):
        """A host can be updated with a new random MAC address. Use name
        to access the host

        @feature: Hosts

        @assert: A host is updated and the MAC address matches
        """
        new_mac = gen_mac()
        Host.update({
            'mac': new_mac,
            'name': self.host['name'],
        })
        self.host = Host.info({'name': self.host['name']})
        self.assertEqual(self.host['mac'], new_mac)
    def test_delete_discovered_host_1(self):
        """@Test: Delete the selected discovered host

        @Feature: Foreman Discovery

        @Setup: Host should already be discovered

        @Assert: Selected host should be removed successfully

        """
        mac = gen_mac(multicast=True, locally=True)
        hostname = 'mac{0}'.format(mac.replace(':', ""))
        self._pxe_boot_host(mac)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            self.discoveredhosts.delete(hostname)
    def test_host_discovery(self):
        """@Test: Discover a host via proxy by setting "proxy.type=proxy" in
        PXE default

        @Feature: Foreman Discovery

        @Setup: Provisioning should be configured

        @Steps: PXE boot a host/VM

        @Assert: Host should be successfully discovered

        """
        mac = gen_mac(multicast=True, locally=True)
        hostname = 'mac{0}'.format(mac.replace(':', ""))
        self._pxe_boot_host(mac)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            self.assertIsNotNone(self.discoveredhosts.search(hostname))
 def __init__(
         self, cpu=1, ram=1024, boot_iso=False, extra_nic=False,
         libvirt_server=None, image_dir=None, mac=None, bridge=None):
     self.cpu = cpu
     self.ram = ram
     if libvirt_server is None:
         self.libvirt_server = settings.compute_resources.libvirt_hostname
     else:
         self.libvirt_server = libvirt_server
     if self.libvirt_server is None or self.libvirt_server == '':
         raise LibvirtGuestError(
             'A libvirt server must be provided. Make sure to fill '
             '"libvirt_server" on compute_resources section of your '
             'robottelo configuration. Or provide a not None '
             'libvirt_server argument.'
         )
     if image_dir is None:
         self.image_dir = settings.compute_resources.libvirt_image_dir
     else:
         self.image_dir = image_dir
     if mac is None:
         self.mac = gen_mac(multicast=False, locally=True)
     else:
         self.mac = mac
     if bridge is None:
         self.bridge = settings.vlan_networking.bridge
     else:
         self.bridge = bridge
     if not self.bridge:
         raise LibvirtGuestError(
             'A bridge name must be provided. Make sure to fill '
             '"bridge" on vlan_networking section of your robottelo '
             'configuration. Or provide a not None bridge '
             'argument.'
         )
     self.boot_iso = boot_iso
     self.extra_nic = extra_nic
     self.hostname = None
     self.ip_addr = None
     self._domain = None
     self._created = False
     self.guest_name = 'mac{0}'.format(self.mac.replace(':', ""))
    def test_positive_upload_facts(self):
        """Upload fake facts to create a discovered host

        :id: c1f40204-bbb0-46d0-9b60-e42f00ad1649

        :Steps: POST /api/v2/discovered_hosts/facts

        :expectedresults: Host should be created successfully

        :CaseLevel: Integration
        """
        for name in valid_data_list():
            with self.subTest(name):
                mac_address = gen_mac()
                host = _create_discovered_host(name, macaddress=mac_address)
                if bz_bug_is_open(1392919):
                    host_name = 'mac{0}'.format(mac_address.replace(':', ''))
                else:
                    host_name = 'mac{0}'.format(host['mac'].replace(':', ''))
                self.assertEqual(host['name'], host_name)
    def test_positive_upload_facts(self):
        """Upload fake facts to create a discovered host

        :id: c1f40204-bbb0-46d0-9b60-e42f00ad1649

        :Steps: POST /api/v2/discovered_hosts/facts

        :expectedresults: Host should be created successfully

        :CaseLevel: Integration
        """
        for name in valid_data_list():
            with self.subTest(name):
                mac_address = gen_mac()
                host = _create_discovered_host(name, macaddress=mac_address)
                if bz_bug_is_open(1392919):
                    host_name = 'mac{0}'.format(mac_address.replace(':', ''))
                else:
                    host_name = 'mac{0}'.format(host['mac'].replace(':', ''))
                self.assertEqual(host['name'], host_name)
Beispiel #35
0
 def __init__(
         self, cpu=1, ram=1024, boot_iso=False, libvirt_server=None,
         image_dir=None, mac=None, bridge=None):
     self.cpu = cpu
     self.ram = ram
     if libvirt_server is None:
         self.libvirt_server = settings.compute_resources.libvirt_hostname
     else:
         self.libvirt_server = libvirt_server
     if self.libvirt_server is None or self.libvirt_server == '':
         raise LibvirtGuestError(
             'A libvirt server must be provided. Make sure to fill '
             '"libvirt_server" on compute_resources section of your '
             'robottelo configuration. Or provide a not None '
             'libvirt_server argument.'
         )
     if image_dir is None:
         self.image_dir = settings.compute_resources.libvirt_image_dir
     else:
         self.image_dir = image_dir
     if mac is None:
         self.mac = gen_mac(multicast=False, locally=True)
     else:
         self.mac = mac
     if bridge is None:
         self.bridge = settings.vlan_networking.bridge
     else:
         self.bridge = bridge
     if not self.bridge:
         raise LibvirtGuestError(
             'A bridge name must be provided. Make sure to fill '
             '"bridge" on vlan_networking section of your robottelo '
             'configuration. Or provide a not None bridge '
             'argument.'
         )
     self.boot_iso = boot_iso
     self.hostname = None
     self.ip_addr = None
     self._domain = None
     self._created = False
     self.guest_name = 'mac{0}'.format(self.mac.replace(':', ""))
Beispiel #36
0
def _create_discovered_host(name=None, ipaddress=None, discovery_bootif=None):
    """Creates discovered host by uploading few fake facts.

    :param str name: Name of discovered host. If ``None`` then a random
        value will be generated.
    :param str ipaddress: A valid ip address.
        If ``None`` then then a random value will be generated.
    :return: A ``dict`` of ``DiscoveredHost`` facts.

    """
    if name is None:
        name = gen_string('alpha')
    if ipaddress is None:
        ipaddress = gen_ipaddr()
    if discovery_bootif is None:
        discovery_bootif = gen_mac()
    return entities.DiscoveredHost().facts(data={
        u'facts': {
            u'name': name,
            u'ipaddress': ipaddress,
            u'discovery_bootif': discovery_bootif,
        }
    })
def generate_system_facts(name=None):
    """Generate random system facts for registration.

    :param str name: A valid FQDN for a system. If one is not
        provided, then a random value will be generated.
    :return: A dictionary with random system facts
    :rtype: dict
    """
    if name is None:
        name = u'{0}.example.net'.format(
            gen_alpha().lower())

    # Make a copy of the system facts 'template'
    new_facts = copy.deepcopy(SYSTEM_FACTS)
    # Select a random RHEL version...
    distro = gen_choice(DISTRO_IDS)

    # ...and update our facts
    new_facts['distribution.id'] = distro['id']
    new_facts['distribution.version'] = distro['version']
    new_facts['dmi.bios.relase_date'] = _bios_date().strftime('%m/%d/%Y')
    new_facts['dmi.memory.maximum_capacity'] = gen_choice(
        MEMORY_CAPACITY)
    new_facts['dmi.memory.size'] = gen_choice(MEMORY_SIZE)
    new_facts['dmi.system.uuid'] = gen_uuid()
    new_facts['dmi.system.version'] = u'RHEL'
    new_facts['lscpu.architecture'] = distro['architecture']
    new_facts['net.interface.eth1.hwaddr'] = gen_mac()
    new_facts['net.interface.eth1.ipaddr'] = gen_ipaddr()
    new_facts['network.hostname'] = name
    new_facts['network.ipaddr'] = new_facts['net.interface.eth1.ipaddr']
    new_facts['uname.machine'] = distro['architecture']
    new_facts['uname.nodename'] = name
    new_facts['uname.release'] = distro['kernel']
    new_facts['virt.uuid'] = new_facts['dmi.system.uuid']

    return new_facts
    def create(self):
        """Creates a virtual machine on the libvirt server using
        virt-install

        :raises robottelo.vm.LibvirtGuestError: Whenever a virtual guest
            could not be executed.
        """
        if self._created:
            return

        command_args = [
            'virt-install',
            '--hvm',
            '--network=bridge:{vm_bridge}',
            '--mac={vm_mac}',
            '--name={vm_name}',
            '--ram={vm_ram}',
            '--vcpus={vm_cpu}',
            '--os-type=linux',
            '--os-variant=rhel7',
            '--disk path={image_name},size=8',
            '--noautoconsole',
        ]

        if not self.boot_iso:
            # Required for PXE-based host discovery
            command_args.append('--pxe')
        else:
            # Required for PXE-less host discovery, where we boot the host
            # with bootable discovery ISO
            self.boot_iso_name = settings.discovery.discovery_iso
            boot_iso_dir = u'{0}/{1}'.format(
                self.image_dir, self.boot_iso_name)
            command_args.append('--cdrom={0}'.format(boot_iso_dir))

        if self.extra_nic:
            nic_mac = gen_mac(multicast=False, locally=True)
            command_args.append('--network=bridge:{vm_bridge}')
            command_args.append('--mac={0}'.format(nic_mac))

        if self._domain is None:
            try:
                self._domain = self.libvirt_server.split('.', 1)[1]
            except IndexError:
                raise LibvirtGuestError(
                    u"Failed to fetch domain from libvirt server: {0} "
                    .format(self.libvirt_server))

        self.hostname = u'{0}.{1}'.format(self.guest_name, self._domain)
        command = u' '.join(command_args).format(
            vm_bridge=self.bridge,
            vm_mac=self.mac,
            vm_name=self.hostname,
            vm_ram=self.ram,
            vm_cpu=self.cpu,
            image_name=u'{0}/{1}.img'.format(self.image_dir, self.hostname)
        )

        result = ssh.command(command, self.libvirt_server)

        if result.return_code != 0:
            raise LibvirtGuestError(
                u'Failed to run virt-install: {0}'.format(result.stderr))

        self._created = True
Beispiel #39
0
def test_gen_mac_multicast_locally_administered():
    """Generate a multicast and locally administered MAC address."""
    mac = gen_mac(multicast=True, locally=True)
    first_octect = int(mac.split(':', 1)[0], 16)
    mask = 0b00000011
    assert first_octect & mask == 3
Beispiel #40
0
def test_gen_mac_multicast_globally_unique():
    """Generate a multicast and globally unique MAC address."""
    mac = gen_mac(multicast=True, locally=False)
    first_octect = int(mac.split(':', 1)[0], 16)
    mask = 0b00000011
    assert first_octect & mask == 1
Beispiel #41
0
def test_gen_mac_3():
    r"""Generate a MAC address using \"-\" as the delimiter."""
    result = gen_mac(delimiter='-')
    assert len(result.split('-')) == 6
    assert MAC.match(result) is not None
Beispiel #42
0
def test_gen_mac_5():
    r"""Generate a MAC address using \" \" as the delimiter."""
    with pytest.raises(ValueError):
        gen_mac(delimiter=' ')
Beispiel #43
0
def test_gen_mac_6():
    """Generate a MAC address using a number as the delimiter."""
    with pytest.raises(ValueError):
        gen_mac(delimiter=random.randint(0, 10))
Beispiel #44
0
def test_gen_mac_7():
    """Generate a MAC address using a letter as the delimiter."""
    with pytest.raises(ValueError):
        gen_mac(delimiter=random.choice(string.ascii_letters))
Beispiel #45
0
 def gen_value(self):
     """Return a value suitable for a :class:`MACAddressField`."""
     return gen_mac()
Beispiel #46
0
 def gen_value(self):
     """Return a value suitable for a :class:`MACAddressField`."""
     return gen_mac(multicast=False)