示例#1
0
    def create_port(self, context, port):
        port_id = uuidutils.generate_uuid()
        tags = utils.build_v3_tags_payload(port['port'])
        port['port']['id'] = port_id
        # TODO(salv-orlando): Undo logical switch creation on failure
        with context.session.begin(subtransactions=True):
            neutron_db = super(NsxV3Plugin, self).create_port(context, port)
            port["port"].update(neutron_db)
            address_bindings = self._build_address_bindings(port['port'])
            # FIXME(arosen): we might need to pull this out of the transaction
            # here later.
            result = nsxlib.create_logical_port(
                lswitch_id=port['port']['network_id'],
                vif_uuid=port_id, name=port['port']['name'], tags=tags,
                admin_state=port['port']['admin_state_up'],
                address_bindings=address_bindings)

            # TODO(salv-orlando): The logical switch identifier in the mapping
            # object is not necessary anymore.
            nsx_db.add_neutron_nsx_port_mapping(
                context.session, neutron_db['id'],
                neutron_db['network_id'], result['id'])
            self._process_portbindings_create_and_update(context,
                                                         port['port'],
                                                         neutron_db)

            neutron_db[pbin.VNIC_TYPE] = pbin.VNIC_NORMAL
        return neutron_db
示例#2
0
    def create_port(self, context, port):
        # NOTE(salv-orlando): This method currently first performs the backend
        # operation. However it is important to note that this workflow might
        # change in the future as the backend might need parameter generated
        # from the neutron side such as port MAC address
        port_id = uuidutils.generate_uuid()
        result = nsxlib.create_logical_port(
            lswitch_id=port['port']['network_id'],
            vif_uuid=port_id)
        port['port']['id'] = port_id
        # TODO(salv-orlando): Undo logical switch creation on failure
        with context.session.begin():
            neutron_db = super(NsxV3Plugin, self).create_port(context, port)
            port["port"].update(neutron_db)
            # TODO(salv-orlando): The logical switch identifier in the mapping
            # object is not necessary anymore.
            nsx_db.add_neutron_nsx_port_mapping(
                context.session, neutron_db['id'],
                neutron_db['network_id'], result['id'])
            self._process_portbindings_create_and_update(context,
                                                         port['port'],
                                                         neutron_db)

            neutron_db[pbin.VNIC_TYPE] = pbin.VNIC_NORMAL
        return neutron_db
示例#3
0
    def test_create_logical_port(self, mock_create_resource):
        """
        Test creating a port returns the correct response and 200 status
        """
        mock_create_resource.return_value = test_constants_v3.FAKE_PORT

        result = nsxlib.create_logical_port(
            test_constants_v3.FAKE_PORT['logical_switch_id'],
            test_constants_v3.FAKE_PORT['attachment']['id'],
            tags={})

        self.assertEqual(test_constants_v3.FAKE_PORT, result)
示例#4
0
    def test_create_logical_port(self, mock_post):
        """
        Test creating a port returns the correct response and 200 status
        """
        mock_post.return_value = self._create_mock_object(
                                     test_constants_v3.FAKE_PORT)
        mock_post.return_value.status_code = requests.codes.created

        result = nsxlib.create_logical_port(
                     test_constants_v3.FAKE_PORT['logical_switch_id'],
                     test_constants_v3.FAKE_PORT['attachment']['id'],
                     tags={})

        self.assertEqual(test_constants_v3.FAKE_PORT, result)
示例#5
0
    def test_create_logical_port_admin_down(self, mock_create_resource):
        """
        Test creating port with admin_state down
        """
        fake_port = test_constants_v3.FAKE_PORT
        fake_port['admin_state'] = "DOWN"
        mock_create_resource.return_value = fake_port

        result = nsxlib.create_logical_port(
            test_constants_v3.FAKE_PORT['logical_switch_id'],
            test_constants_v3.FAKE_PORT['attachment']['id'],
            tags={}, admin_state=False)

        self.assertEqual(fake_port, result)
示例#6
0
    def test_create_logical_port_admin_down(self, mock_post):
        """
        Test creating port with admin_state down
        """
        fake_port = test_constants_v3.FAKE_PORT
        fake_port['admin_state'] = "DOWN"
        mock_post.return_value = self._create_mock_object(fake_port)
        mock_post.return_value.status_code = requests.codes.created

        result = nsxlib.create_logical_port(
                     test_constants_v3.FAKE_PORT['logical_switch_id'],
                     test_constants_v3.FAKE_PORT['attachment']['id'],
                     tags={}, admin_state=False)

        self.assertEqual(fake_port, result)