示例#1
0
    def test_compare_two_macs(self):
        equal_macs = (
            ('00-1B-77-49-54-FD', '00-1B-77-49-54-FD'),
            ('00-1B-77-49-54-FD', '00-1b-77-49-54-fd'),
            ('00-1B-77-49-54-FD', '001b:7749:54fd'),
            ('00-1B-77-49-54-FD', '1B:7749:54FD'),
            ('00-1B-77-49-54-FD', '001b774954fd'),
            ('00-1B-77-49-54-FD', netaddr.EUI('00-1B-77-49-54-FD')),
            ('aa:bb:cc:dd:ee:0f', 'aa:bb:cc:dd:ee:f'),
        )

        for mac1, mac2 in equal_macs:
            self.assertTrue(utils.is_same_mac(mac1, mac2))

        self.assertFalse(
            utils.is_same_mac('AA-BB-CC-11-22-33', '11:22:33:AA:BB:CC'))
示例#2
0
    def check_dhcp_resp(cls, **kwargs):
        """Receiver method for check_dhcp task

        For example of kwargs check FakeCheckingDhcpThread
        """
        logger.info(
            "RPC method check_dhcp_resp received: %s",
            jsonutils.dumps(kwargs)
        )
        messages = []

        result = collections.defaultdict(list)
        message_template = (
            u"Node {node_name} discovered DHCP server "
            u"via {iface} with following parameters: IP: {server_id}, "
            u"MAC: {mac}. This server will conflict with the installation.")
        task_uuid = kwargs.get('task_uuid')
        nodes = kwargs.get('nodes', [])
        error_msg = kwargs.get('error')
        status = kwargs.get('status')
        progress = kwargs.get('progress')

        nodes_uids = [node['uid'] for node in nodes]
        nodes_db = db().query(Node).filter(Node.id.in_(nodes_uids)).all()
        nodes_map = dict((str(node.id), node) for node in nodes_db)

        master_network_mac = settings.ADMIN_NETWORK['mac']
        logger.debug('Mac addr on master node %s', master_network_mac)

        for node in nodes:
            if node['status'] == 'ready':
                for row in node.get('data', []):
                    if not net_utils.is_same_mac(row['mac'],
                                                 master_network_mac):
                        node_db = nodes_map.get(node['uid'])
                        if node_db:
                            row['node_name'] = node_db.name
                            message = message_template.format(**row)
                            messages.append(message)
                            result[node['uid']].append(row)
                        else:
                            logger.warning(
                                'Received message from nonexistent node. '
                                'Message %s', row)
        status = status if not messages else "error"
        error_msg = '\n'.join(messages) if messages else error_msg
        logger.debug('Check dhcp message %s', error_msg)

        task = objects.Task.get_by_uuid(task_uuid, fail_if_not_found=True)
        objects.Task.update_verify_networks(task, status, progress,
                                            error_msg, result)
示例#3
0
    def check_dhcp_resp(cls, **kwargs):
        """Receiver method for check_dhcp task

        For example of kwargs check FakeCheckingDhcpThread
        """
        logger.info("RPC method check_dhcp_resp received: %s",
                    jsonutils.dumps(kwargs))
        messages = []

        result = collections.defaultdict(list)
        message_template = (
            u"Node {node_name} discovered DHCP server "
            u"via {iface} with following parameters: IP: {server_id}, "
            u"MAC: {mac}. This server will conflict with the installation.")
        task_uuid = kwargs.get('task_uuid')
        nodes = kwargs.get('nodes', [])
        error_msg = kwargs.get('error')
        status = kwargs.get('status')
        progress = kwargs.get('progress')

        nodes_uids = [node['uid'] for node in nodes]
        nodes_db = db().query(Node).filter(Node.id.in_(nodes_uids)).all()
        nodes_map = dict((str(node.id), node) for node in nodes_db)

        master_network_mac = settings.ADMIN_NETWORK['mac']
        logger.debug('Mac addr on master node %s', master_network_mac)

        for node in nodes:
            if node['status'] == 'ready':
                for row in node.get('data', []):
                    if not net_utils.is_same_mac(row['mac'],
                                                 master_network_mac):
                        node_db = nodes_map.get(node['uid'])
                        if node_db:
                            row['node_name'] = node_db.name
                            message = message_template.format(**row)
                            messages.append(message)
                            result[node['uid']].append(row)
                        else:
                            logger.warning(
                                'Received message from nonexistent node. '
                                'Message %s', row)
        status = status if not messages else "error"
        error_msg = '\n'.join(messages) if messages else error_msg
        logger.debug('Check dhcp message %s', error_msg)

        task = objects.Task.get_by_uuid(task_uuid, fail_if_not_found=True)
        objects.Task.update_verify_networks(task, status, progress, error_msg,
                                            result)
示例#4
0
 def test_compare_macs_raise_exception(self):
     with self.assertRaises(ValueError):
         utils.is_same_mac('QWERTY', 'ASDF')