Ejemplo n.º 1
0
    def test_boot_only(self, mocked_sleep, mocked_dispatch):
        CONF.set_override('inspection_dhcp_all_interfaces', False)
        mocked_dispatch.side_effect = [
            [
                hardware.NetworkInterface(name='em0',
                                          mac_addr='abcd',
                                          ipv4_address=None,
                                          has_carrier=False),
                hardware.NetworkInterface(name='em1',
                                          mac_addr='cdef',
                                          ipv4_address=None,
                                          has_carrier=False)
            ],
            [
                hardware.NetworkInterface(name='em0',
                                          mac_addr='abcd',
                                          ipv4_address=None,
                                          has_carrier=True),
                hardware.NetworkInterface(name='em1',
                                          mac_addr='cdef',
                                          ipv4_address='1.2.3.4',
                                          has_carrier=True)
            ],
        ]

        self.assertTrue(inspector.wait_for_dhcp())

        mocked_dispatch.assert_called_with('list_network_interfaces')
        self.assertEqual(1, mocked_sleep.call_count)
        self.assertEqual(2, mocked_dispatch.call_count)
Ejemplo n.º 2
0
    def test_ipv4_lookup(self, mock_get_ipv4, mock_list_net, mock_time_sleep,
                         mock_poll, mock_read):
        homeless_agent = agent.IronicPythonAgent(
            'https://fake_api.example.'
            'org:8081/', (None, 9990), ('192.0.2.1', 9999), 3, 10, None, 300,
            1, 'agent_ipmitool', False)

        mock_poll.return_value.poll.return_value = True
        mock_read.return_value = 'a'

        # Can't find network interfaces, and therefore can't find IP
        mock_list_net.return_value = []
        mock_get_ipv4.return_value = None
        self.assertRaises(errors.LookupAgentInterfaceError,
                          homeless_agent.set_agent_advertise_addr)

        # Can look up network interfaces, but not IP.  Network interface not
        # set, because no interface yields an IP.
        mock_ifaces = [
            hardware.NetworkInterface('eth0', '00:00:00:00:00:00'),
            hardware.NetworkInterface('eth1', '00:00:00:00:00:01')
        ]
        mock_list_net.return_value = mock_ifaces

        self.assertRaises(errors.LookupAgentIPError,
                          homeless_agent.set_agent_advertise_addr)
        self.assertEqual(6, mock_get_ipv4.call_count)
        self.assertEqual(None, homeless_agent.network_interface)

        # First interface eth0 has no IP, second interface eth1 has an IP
        mock_get_ipv4.side_effect = [None, '1.1.1.1']
        homeless_agent.heartbeater.run()
        self.assertEqual(('1.1.1.1', 9990), homeless_agent.advertise_address)
        self.assertEqual('eth1', homeless_agent.network_interface)
Ejemplo n.º 3
0
    def test_list_hardware_info(self):
        self.hardware.list_network_interfaces = mock.Mock()
        self.hardware.list_network_interfaces.return_value = [
            hardware.NetworkInterface('eth0', '00:0c:29:8c:11:b1'),
            hardware.NetworkInterface('eth1', '00:0c:29:8c:11:b2'),
        ]

        self.hardware.get_cpus = mock.Mock()
        self.hardware.get_cpus.return_value = hardware.CPU(
            'Awesome CPU x14 9001', 9001, 14)

        self.hardware.get_memory = mock.Mock()
        self.hardware.get_memory.return_value = hardware.Memory(1017012)

        self.hardware.list_block_devices = mock.Mock()
        self.hardware.list_block_devices.return_value = [
            hardware.BlockDevice('/dev/sdj', 'big', 1073741824, True),
            hardware.BlockDevice('/dev/hdaa', 'small', 65535, False),
        ]

        hardware_info = self.hardware.list_hardware_info()
        self.assertEqual(hardware_info['memory'], self.hardware.get_memory())
        self.assertEqual(hardware_info['cpu'], self.hardware.get_cpus())
        self.assertEqual(hardware_info['disks'],
                         self.hardware.list_block_devices())
        self.assertEqual(hardware_info['interfaces'],
                         self.hardware.list_network_interfaces())
Ejemplo n.º 4
0
 def setUp(self):
     super(TestBaseIronicPythonAgent, self).setUp()
     self.api_client = ironic_api_client.APIClient(API_URL)
     self.hardware_info = {
         'interfaces': [
             hardware.NetworkInterface('eth0',
                                       '00:0c:29:8c:11:b1',
                                       vendor='0x15b3',
                                       product='0x1014'),
             hardware.NetworkInterface('eth1',
                                       '00:0c:29:8c:11:b2',
                                       lldp=[
                                           (1, '04885a92ec5459'),
                                           (2, '0545746865726e6574312f3138')
                                       ],
                                       vendor='0x15b3',
                                       product='0x1014'),
         ],
         'cpu':
         hardware.CPU('Awesome Jay CPU x10 9001', '9001', '10', 'ARMv9'),
         'disks': [
             hardware.BlockDevice('/dev/sdj', 'small', '9001', False),
             hardware.BlockDevice('/dev/hdj', 'big', '9002', False),
         ],
         'memory':
         hardware.Memory(total='8675309', physical_mb='8675'),
     }
Ejemplo n.º 5
0
 def setUp(self):
     super(BaseDiscoverTest, self).setUp()
     self.inventory = {
         'interfaces': [
             hardware.NetworkInterface(name='em1',
                                       mac_addr='aa:bb:cc:dd:ee:ff',
                                       ipv4_address='1.1.1.1'),
             hardware.NetworkInterface(name='em2',
                                       mac_addr='11:22:33:44:55:66',
                                       ipv4_address=None),
         ],
         'cpu': hardware.CPU(model_name='generic', frequency='3000',
                             count=4, architecture='x86_64'),
         'memory': hardware.Memory(total=11998396 * 1024,
                                   physical_mb=12288),
         'disks': [
             hardware.BlockDevice(name='/dev/sdc',
                                  model='Disk 2',
                                  size=500107862016,
                                  rotational=False),
             hardware.BlockDevice(name='/dev/sda',
                                  model='Too Small Disk',
                                  size=4294967295,
                                  rotational=False),
             hardware.BlockDevice(name='/dev/sdb',
                                  model='Disk 1',
                                  size=500107862016,
                                  rotational=True)
         ],
         'bmc_address': '1.2.3.4',
         'boot': hardware.BootInfo(current_boot_mode='bios',
                                   pxe_interface='boot:if')
     }
     self.failures = utils.AccumulatedFailures()
     self.data = {}
Ejemplo n.º 6
0
    def test_list_hardware_info(self):
        self.hardware.list_network_interfaces = mock.Mock()
        self.hardware.list_network_interfaces.return_value = [
            hardware.NetworkInterface('eth0', '00:0c:29:8c:11:b1'),
            hardware.NetworkInterface('eth1', '00:0c:29:8c:11:b2'),
        ]

        self.hardware.get_cpus = mock.Mock()
        self.hardware.get_cpus.return_value = hardware.CPU(
            'Awesome CPU x14 9001',
            9001,
            14,
            'x86_64')

        self.hardware.get_memory = mock.Mock()
        self.hardware.get_memory.return_value = hardware.Memory(1017012)

        self.hardware.list_block_devices = mock.Mock()
        self.hardware.list_block_devices.return_value = [
            hardware.BlockDevice('/dev/sdj', 'big', 1073741824, True),
            hardware.BlockDevice('/dev/hdaa', 'small', 65535, False),
        ]

        self.hardware.list_physical_devices = mock.Mock()
        self.hardware.list_physical_devices.return_value = [
            arcconf.PhysicalDisk(ID='0 0',
                                 ControllerID='1',
                                 Type='SAS',
                                 Size='558.91 GB'),
            arcconf.PhysicalDisk(ID='0 1',
                                 ControllerID='1',
                                 Type='SAS',
                                 Size='558.91 GB'),
        ]

        self.hardware.get_boot_info = mock.Mock()
        self.hardware.get_boot_info.return_value = hardware.BootInfo(
            current_boot_mode='bios', pxe_interface='boot:if')

        self.hardware.get_bmc_address = mock.Mock()
        self.hardware.get_system_vendor_info = mock.Mock()

        hardware_info = self.hardware.list_hardware_info()
        self.assertEqual(self.hardware.get_memory(),
                         hardware_info['memory'])
        self.assertEqual(self.hardware.get_cpus(), hardware_info['cpu'])
        self.assertEqual(self.hardware.list_block_devices(),
                         hardware_info['disks'])
        self.assertEqual(self.hardware.list_physical_devices(),
                         hardware_info['physical_disks'])
        self.assertEqual(self.hardware.list_network_interfaces(),
                         hardware_info['interfaces'])
        self.assertEqual(self.hardware.get_boot_info(),
                         hardware_info['boot'])
Ejemplo n.º 7
0
    def test_timeout(self, mocked_dispatch):
        CONF.set_override('inspection_dhcp_all_interfaces', True)
        CONF.set_override('inspection_dhcp_wait_timeout', 0.02)

        mocked_dispatch.return_value = [
            hardware.NetworkInterface(name='em0', mac_addr='abcd',
                                      ipv4_address=None),
            hardware.NetworkInterface(name='em1', mac_addr='abcd',
                                      ipv4_address='1.2.3.4'),
        ]

        self.assertFalse(inspector.wait_for_dhcp())

        mocked_dispatch.assert_called_with('list_network_interfaces')
Ejemplo n.º 8
0
    def test_no_network_interfaces(self):
        self.inventory['interfaces'] = [
            hardware.NetworkInterface(name='lo',
                                      mac_addr='aa:bb:cc:dd:ee:ff',
                                      ipv4_address='127.0.0.1'),
            hardware.NetworkInterface(name='local-2',
                                      mac_addr='aa:bb:cc:dd:ee:ff',
                                      ipv4_address='127.0.1.42'),
        ]

        inspector.discover_network_properties(self.inventory, self.data,
                                              self.failures)

        self.assertIn('no network interfaces found', self.failures.get_error())
        self.assertFalse(self.data['interfaces'])
Ejemplo n.º 9
0
    def test_missing(self):
        self.inventory['interfaces'] = [
            hardware.NetworkInterface(name='em1',
                                      mac_addr='aa:bb:cc:dd:ee:ff'),
            hardware.NetworkInterface(name='em2',
                                      mac_addr=None,
                                      ipv4_address='1.2.1.2'),
        ]

        inspector.discover_network_properties(self.inventory, self.data,
                                              self.failures)

        self.assertEqual({'em1': {'mac': 'aa:bb:cc:dd:ee:ff', 'ip': None}},
                         self.data['interfaces'])
        self.assertFalse(self.failures)
Ejemplo n.º 10
0
    def get_interface_info(self, interface_name):
        """Return the interface information when its Mellanox and InfiniBand

        In case of Mellanox and InfiniBand interface we do the following:
            1. Calculate the "InfiniBand  MAC" according to InfiniBand GUID
            2. Calculate the client-id according to InfiniBand GUID
        """

        address = netutils.get_mac_addr(interface_name)
        if address is None:
            raise errors.IncompatibleHardwareMethodError()
        vendor = hardware._get_device_info(interface_name, 'net', 'vendor')
        if (len(address) != netutils.INFINIBAND_ADDR_LEN
                or vendor != MLNX_VENDOR_ID):
            raise errors.IncompatibleHardwareMethodError()

        mac_addr = _infiniband_address_to_mac(address)
        client_id = _generate_client_id(address)

        return hardware.NetworkInterface(
            interface_name, mac_addr,
            ipv4_address=netutils.get_ipv4_addr(interface_name),
            has_carrier=netutils.interface_has_carrier(interface_name),
            lldp=None,
            vendor=vendor,
            product=hardware._get_device_info(interface_name, 'net', 'device'),
            client_id=client_id)
Ejemplo n.º 11
0
 def setUp(self):
     super(TestBaseIronicPythonAgent, self).setUp()
     self.api_client = ironic_api_client.APIClient(API_URL, DRIVER)
     self.hardware_info = {
         'interfaces': [
             hardware.NetworkInterface('eth0', '00:0c:29:8c:11:b1'),
             hardware.NetworkInterface('eth1', '00:0c:29:8c:11:b2'),
         ],
         'cpu': hardware.CPU('Awesome Jay CPU x10 9001', '9001', '10',
                             'ARMv9'),
         'disks': [
             hardware.BlockDevice('/dev/sdj', 'small', '9001', False),
             hardware.BlockDevice('/dev/hdj', 'big', '9002', False),
         ],
         'memory': hardware.Memory(total='8675309',
                                   physical_mb='8675'),
     }
Ejemplo n.º 12
0
    def test_timeout(self, mocked_time, mocked_sleep, mocked_dispatch):
        CONF.set_override('inspection_dhcp_all_interfaces', True)
        CONF.set_override('inspection_dhcp_wait_timeout', 1)

        mocked_dispatch.return_value = [
            hardware.NetworkInterface(name='em0', mac_addr='abcd',
                                      ipv4_address=None),
            hardware.NetworkInterface(name='em1', mac_addr='abcd',
                                      ipv4_address='1.2.3.4'),
        ]

        self.assertFalse(inspector.wait_for_dhcp())
        mocked_dispatch.assert_called_with('list_network_interfaces')
        mocked_sleep.assert_called_once_with(inspector._DHCP_RETRY_INTERVAL)
        # time.time() was called 3 times explicitly in wait_for_dhcp(),
        # and 1 in LOG.warning()
        self.assertEqual(4, mocked_time.call_count)
Ejemplo n.º 13
0
    def test_all(self, mocked_sleep, mocked_dispatch):
        CONF.set_override('inspection_dhcp_all_interfaces', True)
        # We used to rely on has_carrier check, but we've found it unreliable
        # in the DIB image, so we ignore its value.
        mocked_dispatch.side_effect = [
            [hardware.NetworkInterface(name='em0', mac_addr='abcd',
                                       ipv4_address=None,
                                       has_carrier=False),
             hardware.NetworkInterface(name='em1', mac_addr='cdef',
                                       ipv4_address='1.2.3.4',
                                       has_carrier=False)],
            [hardware.NetworkInterface(name='em0', mac_addr='abcd',
                                       ipv4_address=None,
                                       has_carrier=True),
             hardware.NetworkInterface(name='em1', mac_addr='cdef',
                                       ipv4_address='1.2.3.4',
                                       has_carrier=True)],
            [hardware.NetworkInterface(name='em0', mac_addr='abcd',
                                       ipv4_address='1.1.1.1',
                                       has_carrier=True),
             hardware.NetworkInterface(name='em1', mac_addr='cdef',
                                       ipv4_address='1.2.3.4',
                                       has_carrier=True)],
        ]

        self.assertTrue(inspector.wait_for_dhcp())

        mocked_dispatch.assert_called_with('list_network_interfaces')
        self.assertEqual(2, mocked_sleep.call_count)
        self.assertEqual(3, mocked_dispatch.call_count)
Ejemplo n.º 14
0
    def setUp(self):
        super(TestBaseAgent, self).setUp()
        self.encoder = encoding.RESTJSONEncoder(indent=4)

        self.agent = agent.IronicPythonAgent(
            'https://fake_api.example.'
            'org:8081/', ('203.0.113.1', 9990), ('192.0.2.1', 9999), 3, 10,
            'eth0', 300, 1, 'agent_ipmitool', False)
        self.agent.ext_mgr = extension.ExtensionManager.\
            make_test_instance([extension.Extension('fake', None,
                                                    FakeExtension,
                                                    FakeExtension())])
        self.sample_nw_iface = hardware.NetworkInterface(
            "eth9", "AA:BB:CC:DD:EE:FF", "1.2.3.4", True)
Ejemplo n.º 15
0
    def list_network_interfaces(self):
        network_interfaces_list = []

        bmc_mac = self.get_ipmi_info().get('MAC Address', False)
        if bmc_mac:
            LOG.info("Adding MAC address net interfaces %s", bmc_mac)
            bmc_address = self.get_bmc_address()
            network_interfaces_list.append(hardware.NetworkInterface(
                name="BMC_INTERFACE",
                mac_addr=bmc_mac,
                ipv4_address=bmc_address,
                has_carrier=True,
                vendor="BMC",
                product="Akraino"))

        else:
            network_interfaces_list = super(BMCHardwareManager, self).list_network_interfaces()
        return network_interfaces_list
    def setUp(self):
        super(TestOnMetalVerifyPorts, self).setUp()
        self.hardware = onmetal_hardware_manager.OnMetalHardwareManager()
        self.interfaces = [
            hardware.NetworkInterface('eth0', 'aa:bb:cc:dd:ee:ff'),
            hardware.NetworkInterface('eth1', 'ff:ee:dd:cc:bb:aa')
        ]
        self.lldp_info = {
            'eth0': [
                # Chassis ID
                (1, 'switch1'),
                # Port ID
                (2, '\x05Ethernet1/1'),
                # TTL
                (3, '\x00x'),
                # Port Description
                (4, 'port1'),
                # System Name
                (5, 'switch1'),
            ],
            'eth1': [
                (1, 'switch2'),
                (2, '\x05Ethernet2/1'),
                (3, '\x00x'),
                (4, 'port2'),
                (5, 'switch2'),
            ]
        }

        self.node = {
            'extra': {
                'hardware/interfaces/0/mac_address': 'aa:bb:cc:dd:ee:ff',
                'hardware/interfaces/0/name': 'eth0',
                'hardware/interfaces/0/switch_chassis_id': 'switch1',
                'hardware/interfaces/0/switch_port_id': 'Eth1/1',
                'hardware/interfaces/1/mac_address': 'ff:ee:dd:cc:bb:aa',
                'hardware/interfaces/1/name': 'eth1',
                'hardware/interfaces/1/switch_chassis_id': 'switch2',
                'hardware/interfaces/1/switch_port_id': 'Eth2/1',
            }
        }

        self.ports = [{
            'address': 'aa:bb:cc:dd:ee:ff',
            'extra': {
                'chassis': 'switch1',
                'port': 'Eth1/1'
            }
        }, {
            'address': 'ff:ee:dd:cc:bb:aa',
            'extra': {
                'chassis': 'switch2',
                'port': 'Eth2/1'
            }
        }]

        self.netiface = {
            17: [{
                'broadcast': 'ff:ff:ff:ff:ff:ff',
                'addr': 'aa:bb:cc:dd:ee:ff'
            }],
            2: [{
                'broadcast': '10.0.0.255',
                'netmask': '255.255.255.0',
                'addr': '10.0.0.2'
            }],
            10: [{
                'netmask': 'ffff:ffff:ffff:ffff::',
                'addr': '2001:4802:7801:102:be76:4eff:fe20:67ae'
            }, {
                'netmask': 'ffff:ffff:ffff:ffff::',
                'addr': 'fe80::be76:4eff:fe20:67ae%eth0'
            }]
        }

        self.port_tuples = set([('switch2', 'eth2/1'), ('switch1', 'eth1/1')])