Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can't receive port.create notification when DHCP enabled network is created.

Hi all,

We are working on receiving notification from OpenStack. But when we create a network/subnet with DHCP enable, a port and a DHCP server are created, but we can not receive any notification of it. What we can receive are only network.create and subnet.create. Our code shows below:

import argparse

from kombu import Queue, Exchange
from kombu.log import get_logger
from kombu.mixins import ConsumerMixin

from discover.configuration import Configuration
from discover.event_handler import EventHandler
from discover.inventory_mgr import InventoryMgr

logger = get_logger(__name__)


class Worker(ConsumerMixin):
    event_queues = [
        Queue('notification.nova',
              Exchange('nova', 'topic', durable=False),
              durable=False, routing_key='#'),
        Queue('notifications.neutron',
              Exchange('neutron', 'topic', durable=False),
              durable=False, routing_key='#'),
        Queue('notifications.neutron',
              Exchange('openstack', 'topic', durable=False),
              durable=False, routing_key='*')
    ]

    def __init__(self, connection):
        self.connection = connection

    def set_env(self, env, inventory_collection):
        inv = InventoryMgr()
        inv.set_inventory_collection(inventory_collection)
        self.handler = EventHandler(env, inventory_collection)
        self.notification_responses = {
            "compute.instance.create.end": self.handler.instance_add,
            "compute.instance.delete.end": self.handler.instance_delete,
            "compute.instance.rebuild.end": self.handler.instance_update,
            "compute.instance.update": self.handler.instance_update,

            "servergroup.create": self.handler.region_add,
            "servergroup.delete": self.handler.region_delete,
            "servergroup.update": self.handler.region_update,
            "servergroup.addmember": self.handler.region_update,

            "compute.instance.shutdown.start": self.handler.instance_down,
            "compute.instance.power_off.start": self.handler.instance_down,
            "compute.instance.power_on.end": self.handler.instance_up,
            "compute.instance.suspend.start": self.handler.instance_down,
            "compute.instance.suspend.end": self.handler.instance_up,

            "network.create.end": self.handler.network_create,
            "network.delete.end": self.handler.network_delete,

            "subnet.create.end": self.handler.subnet_create,
            "subnet.delete.end": self.handler.subnet_delete,

            "port.create.end": self.handler.port_create,
            "port.delete.end": self.handler.port_delete,

            "router.create.end": self.handler.router_create,

            "router.update.end": self.handler.router_update,

            "router.delete.end": self.handler.router_delete,

            "router.interface.create": self.handler.router_interface_create,
            "router.interface.delete": self.handler.router_interface_delete,
        }

    def get_consumers(self, Consumer, channel):
        return [Consumer(queues=self.event_queues,
                         accept=['json'],
                         callbacks=[self.process_task])]

    def process_task(self, body, message):
        if "event_type" in body:
            self.handle_event(body["event_type"], body)
        message.ack()

    def handle_event(self, type, notification):
        print("got notification, event_type: " + type + '\n' + str(notification))
        if type not in self.notification_responses.keys():
            return ""
        return self.notification_responses[type](notification)


def get_args():
    # try to read scan plan from command line parameters
    parser = argparse.ArgumentParser()
    default_env = "Mirantis-Liberty"
    parser.add_argument("-m", "--mongo_config", nargs="?", type=str,
                        default="",
                        help="name of config file with MongoDB servr access details")
    parser.add_argument("-e", "--env", nargs="?", type=str,
                        default=default_env,
                        help="name of environment to scan \n(default: " + default_env + ")")
    parser.add_argument("-y", "--inventory", nargs="?", type=str,
                        default="inventory",
                        help="name of inventory collection \n(default: 'inventory')")
    parser.add_argument("-l", "--loglevel", nargs="?", type=str, default="INFO",
                        help="logging level \n(default: 'INFO')")
    args = parser.parse_args()
    return args


if __name__ == '__main__':
    from kombu import Connection
    from kombu.utils.debug import setup_logging

    # setup root logger
    setup_logging(loglevel='DEBUG', loggers=[''])

    args = get_args()
    conf = Configuration(args.mongo_config)
    env = args.env
    conf.use_env(env)
    amqp_config = conf.get("AMQP")
    host = amqp_config["host"]
    port = amqp_config["port"]
    user = amqp_config["user"]
    pwd = amqp_config["password"]
    connect_url = 'amqp://' + user + ':' + pwd + '@' + host + ':' + port + '//'
    with Connection(connect_url) as conn:
        try:
            print(conn)
            worker = Worker(conn)
            worker.set_env(env, args.inventory)
            worker.run()
        except KeyboardInterrupt:
            print('Stopped')

and we only receive the events like this:

got notification, event_type: network.create.start
{'_unique_id': '9812b605010b4179999ce096efd9f76a', '_context_project_name': 'OSDNA-project', '_context_tenant_id': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_tenant': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_resource_uuid': None, '_context_request_id': 'req-47f5b74a-b81b-4617-9665-abee75b1f55f', 'timestamp': '2016-10-05 17:50:31.810293', '_context_auth_token': 'gAAAAABX9Tv8EkKMPol0IugLbNAkLvyLRsFDOY6NAh5aFRBbTMcHqmSA-qu5xPBRxlcleu0nP4Ip90PFCVPxWzwT_OGAaQ3wrvVGLsS2yXkyW7Hde4yLkuwHFUOqRDp4y0Co__MPmYO0DWNMlqhwdn2gNzxCnhP5ouRqxB20VeKm3SoSbPvD6VgtePHJJH-l1PMYs7GROKm5', '_context_timestamp': '2016-10-05 17:50:31.807571', '_context_user_domain': None, '_context_tenant_name': 'OSDNA-project', '_context_show_deleted': False, '_context_project_id': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_roles': ['_member_', 'admin'], 'publisher_id': 'network.node-6.cisco.com', 'message_id': '700e49d5-7c11-4126-9273-a95a1d5c4169', '_context_user_id': '13baa553aae44adca6615e711fd2f6d9', '_context_read_only': False, '_context_domain': None, '_context_project_domain': None, 'payload': {'network': {'admin_state_up': True, 'name': '3', 'tenant_id': '75c0eb79ff4a42b0ae4973c8375ddf40'}}, '_context_user': '13baa553aae44adca6615e711fd2f6d9', 'priority': 'INFO', '_context_is_admin': True, '_context_user_name': 'admin', '_context_user_identity': '13baa553aae44adca6615e711fd2f6d9 75c0eb79ff4a42b0ae4973c8375ddf40 - - -', 'event_type': 'network.create.start'}
got notification, event_type: network.create.end
{'_unique_id': 'b17c30605a234b18834737039f106004', '_context_project_name': 'OSDNA-project', '_context_tenant_id': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_tenant': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_resource_uuid': None, '_context_request_id': 'req-47f5b74a-b81b-4617-9665-abee75b1f55f', 'timestamp': '2016-10-05 17:50:32.610009', '_context_auth_token': 'gAAAAABX9Tv8EkKMPol0IugLbNAkLvyLRsFDOY6NAh5aFRBbTMcHqmSA-qu5xPBRxlcleu0nP4Ip90PFCVPxWzwT_OGAaQ3wrvVGLsS2yXkyW7Hde4yLkuwHFUOqRDp4y0Co__MPmYO0DWNMlqhwdn2gNzxCnhP5ouRqxB20VeKm3SoSbPvD6VgtePHJJH-l1PMYs7GROKm5', '_context_timestamp': '2016-10-05 17:50:31.807571', '_context_user_domain': None, '_context_tenant_name': 'OSDNA-project', '_context_show_deleted': False, '_context_project_id': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_roles': ['_member_', 'admin'], 'publisher_id': 'network.node-6.cisco.com', 'message_id': '6b1d5730-c56f-4c6a-a45c-4bde7dc257e3', '_context_user_id': '13baa553aae44adca6615e711fd2f6d9', '_context_read_only': False, '_context_domain': None, '_context_project_domain': None, 'payload': {'network': {'subnets': [], 'admin_state_up': True, 'shared': False, 'id': 'd0b068ae-a685-446b-9e62-a836a2b7b657', 'mtu': 1400, 'provider:physical_network': None, 'port_security_enabled': True, 'name': '3', 'provider:network_type': 'vxlan', 'router:external': False, 'provider:segmentation_id': 76, 'status': 'ACTIVE', 'tenant_id': '75c0eb79ff4a42b0ae4973c8375ddf40'}}, '_context_user': '13baa553aae44adca6615e711fd2f6d9', 'priority': 'INFO', '_context_is_admin': True, '_context_user_name': 'admin', '_context_user_identity': '13baa553aae44adca6615e711fd2f6d9 75c0eb79ff4a42b0ae4973c8375ddf40 - - -', 'event_type': 'network.create.end'}
network_add
got notification, event_type: subnet.create.start
{'_unique_id': 'a7b87dd215304649b3810c1035861f56', '_context_project_name': 'OSDNA-project', '_context_tenant_id': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_tenant': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_resource_uuid': None, '_context_request_id': 'req-7338a2bb-5370-46cd-9a60-6a0b53ad3bae', 'timestamp': '2016-10-05 17:50:32.647851', '_context_auth_token': 'gAAAAABX9Tv8EkKMPol0IugLbNAkLvyLRsFDOY6NAh5aFRBbTMcHqmSA-qu5xPBRxlcleu0nP4Ip90PFCVPxWzwT_OGAaQ3wrvVGLsS2yXkyW7Hde4yLkuwHFUOqRDp4y0Co__MPmYO0DWNMlqhwdn2gNzxCnhP5ouRqxB20VeKm3SoSbPvD6VgtePHJJH-l1PMYs7GROKm5', '_context_timestamp': '2016-10-05 17:50:32.644085', '_context_user_domain': None, '_context_tenant_name': 'OSDNA-project', '_context_show_deleted': False, '_context_project_id': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_roles': ['_member_', 'admin'], 'publisher_id': 'network.node-6.cisco.com', 'message_id': '056c6ce1-e971-477b-9111-f77222baa1fb', '_context_user_id': '13baa553aae44adca6615e711fd2f6d9', '_context_read_only': False, '_context_domain': None, '_context_project_domain': None, 'payload': {'subnet': {'ip_version': 4, 'gateway_ip': '172.16.11.1', 'network_id': 'd0b068ae-a685-446b-9e62-a836a2b7b657', 'cidr': '172.16.11.0/24', 'enable_dhcp': True, 'name': '3', 'tenant_id': '75c0eb79ff4a42b0ae4973c8375ddf40'}}, '_context_user': '13baa553aae44adca6615e711fd2f6d9', 'priority': 'INFO', '_context_is_admin': True, '_context_user_name': 'admin', '_context_user_identity': '13baa553aae44adca6615e711fd2f6d9 75c0eb79ff4a42b0ae4973c8375ddf40 - - -', 'event_type': 'subnet.create.start'}
got notification, event_type: subnet.create.end
{'_unique_id': '45936011d50940dd9a1e59981853029a', '_context_project_name': 'OSDNA-project', '_context_tenant_id': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_tenant': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_resource_uuid': None, '_context_request_id': 'req-7338a2bb-5370-46cd-9a60-6a0b53ad3bae', 'timestamp': '2016-10-05 17:50:33.679283', '_context_auth_token': 'gAAAAABX9Tv8EkKMPol0IugLbNAkLvyLRsFDOY6NAh5aFRBbTMcHqmSA-qu5xPBRxlcleu0nP4Ip90PFCVPxWzwT_OGAaQ3wrvVGLsS2yXkyW7Hde4yLkuwHFUOqRDp4y0Co__MPmYO0DWNMlqhwdn2gNzxCnhP5ouRqxB20VeKm3SoSbPvD6VgtePHJJH-l1PMYs7GROKm5', '_context_timestamp': '2016-10-05 17:50:32.644085', '_context_user_domain': None, '_context_tenant_name': 'OSDNA-project', '_context_show_deleted': False, '_context_project_id': '75c0eb79ff4a42b0ae4973c8375ddf40', '_context_roles': ['_member_', 'admin'], 'publisher_id': 'network.node-6.cisco.com', 'message_id': 'bde15520-3242-49a9-b60a-541bbef31a69', '_context_user_id': '13baa553aae44adca6615e711fd2f6d9', '_context_read_only': False, '_context_domain': None, '_context_project_domain': None, 'payload': {'subnet': {'dns_nameservers': [], 'host_routes': [], 'subnetpool_id': None, 'network_id': 'd0b068ae-a685-446b-9e62-a836a2b7b657', 'enable_dhcp': True, 'name': '3', 'tenant_id': '75c0eb79ff4a42b0ae4973c8375ddf40', 'ipv6_address_mode': None, 'gateway_ip': '172.16.11.1', 'allocation_pools': [{'start': '172.16.11.2', 'end': '172.16.11.254'}], 'cidr': '172.16.11.0/24', 'ipv6_ra_mode': None, 'ip_version': 4, 'id': '289b07a9-459b-46d5-8e6f-db2d35eb53e5'}}, '_context_user': '13baa553aae44adca6615e711fd2f6d9', 'priority': 'INFO', '_context_is_admin': True, '_context_user_name': 'admin', '_context_user_identity': '13baa553aae44adca6615e711fd2f6d9 75c0eb79ff4a42b0ae4973c8375ddf40 - - -', 'event_type': 'subnet.create.end'}
subnet_add

As you can see, 'enable_dhcp' is True in subnet notification, so there should be a notification about Port created. Cause we can not find any info about Port, so we can not get port description.

It seems like a BUG: https://bugs.launchpad.net/neutron/+bug/1560221

I am looking forward your reply. Thank you very much!

Cheng